Subversion Repositories DevTools

Rev

Rev 2449 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2449 Rev 2650
Line 23... Line 23...
23
**                          (d) DeleteFile
23
**                          (d) DeleteFile
24
**                          (r) Remove Files (wildcard)
24
**                          (r) Remove Files (wildcard)
25
**                          (D) DeleteDir after deleting specified files (wildcard)
25
**                          (D) DeleteDir after deleting specified files (wildcard)
26
**                          (T) Delete Directory Trees
26
**                          (T) Delete Directory Trees
27
**                          (R) Remove Files and Empty Directories
27
**                          (R) Remove Files and Empty Directories
-
 
28
**                          (P) Print Arguments
28
**
29
**
29
**                      Example Usage
30
**                      Example Usage
30
**
31
**
31
**                          JatsFileUtil c9 'copyFile'    aaa/bbb/ccc/dddd/file build_test.pl +w
32
**                          JatsFileUtil c9 'copyFile'    aaa/bbb/ccc/dddd/file build_test.pl +w
32
**                          JatsFileUtil d9 'unCopyFile'  aaa/bbb/ccc/dddd/file
33
**                          JatsFileUtil d9 'unCopyFile'  aaa/bbb/ccc/dddd/file
Line 59... Line 60...
59
void copyOneFile( int argc, _TCHAR* argv[] );
60
void copyOneFile( int argc, _TCHAR* argv[] );
60
void RmItem( int argc, _TCHAR* argv[] );
61
void RmItem( int argc, _TCHAR* argv[] );
61
int DeleteOneFile (_TCHAR * dst );
62
int DeleteOneFile (_TCHAR * dst );
62
void DeleteOneDirectory (_TCHAR *path );
63
void DeleteOneDirectory (_TCHAR *path );
63
void stdCheck( char *name, int argBad, _TCHAR *txt );
64
void stdCheck( char *name, int argBad, _TCHAR *txt );
-
 
65
void url_decode(_TCHAR *str);
64
 
66
 
65
/*
67
/*
66
**  Global
68
**  Global
67
*/
69
*/
68
char  verbose = 1;                          /* Debugging aid */
70
char  verbose = 1;                          /* Debugging aid */
Line 78... Line 80...
78
         "      c9 copyFile     dstPath srcPath chmod\n"
80
         "      c9 copyFile     dstPath srcPath chmod\n"
79
         "      d9 unCopyFile   dstPath\n"
81
         "      d9 unCopyFile   dstPath\n"
80
         "      r9 RmFile       file+\n"
82
         "      r9 RmFile       file+\n"
81
         "      D9 DeleteFiles  dstDir file+ - supports (?*)\n"
83
         "      D9 DeleteFiles  dstDir file+ - supports (?*)\n"
82
         "      T9 DeleteTree   dstDir+\n"
84
         "      T9 DeleteTree   dstDir+\n"
83
         "      R9 RmItem       (dir|file)+\n";
85
         "      R9 RmItem       (dir|file)+\n"
-
 
86
         "      P9 PrintArgs    ...\n";
84
 
87
 
85
/*----------------------------------------------------------------------------
88
/*----------------------------------------------------------------------------
86
** FUNCTION           : main
89
** FUNCTION           : main
87
**
90
**
88
** DESCRIPTION        : Main entry points
91
** DESCRIPTION        : Main entry points
Line 116... Line 119...
116
    **      [1] - Verbose : 0 .. 9
119
    **      [1] - Verbose : 0 .. 9
117
    */
120
    */
118
    if ( argc > 1 && ( argv[1][1] >= '0' && argv[1][1] <= '9' ) )
121
    if ( argc > 1 && ( argv[1][1] >= '0' && argv[1][1] <= '9' ) )
119
    {
122
    {
120
        verbose = argv[1][1] - '0';
123
        verbose = argv[1][1] - '0';
-
 
124
    }
121
 
125
 
-
 
126
    /*
-
 
127
    **  URL Decode most arguments
-
 
128
    **  To get past the stupidities of shells and make the arguments
-
 
129
    **  will have been URL(modified) encoded
-
 
130
    **
-
 
131
    **  Decode all args in place
-
 
132
    */
-
 
133
    for ( ii = 2; ii < argc ; ii++ )
-
 
134
    {
-
 
135
        url_decode(argv[ii]);
122
        /*
136
        /*
123
        **  If Verbose, then display arguments
137
        **  If Verbose, then display arguments
124
        */
138
        */
125
        if ( verbose > 2 )
139
        if ( verbose > 2 )
126
        {
-
 
127
            for ( ii = 0; ii < argc ; ii++ )
-
 
128
            {
-
 
129
                fprintf(stderr, "Arg%d: %ls:\n", ii, argv[ii] );
140
            fprintf(stderr, "Arg%d: %ls:\n", ii, argv[ii] );
130
            }
-
 
131
            fflush(stderr) ;
-
 
132
        }
-
 
133
    }
141
    }
-
 
142
     fflush(stderr) ;
134
    
143
    
135
    /*
144
    /*
136
    **  Switch to required operation
145
    **  Switch to required operation
137
    */
146
    */
138
    switch( argv[1][0] )
147
    switch( argv[1][0] )
Line 212... Line 221...
212
        */
221
        */
213
        case 'R':
222
        case 'R':
214
            stdCheck( "RmItem", argc < 3, argv[2] );
223
            stdCheck( "RmItem", argc < 3, argv[2] );
215
            RmItem(argc, argv );
224
            RmItem(argc, argv );
216
            break;
225
            break;
-
 
226
 
-
 
227
        /*
-
 
228
        **  Print arguments with a space betweenn them
-
 
229
        **  All on the same line
-
 
230
        **      argv[2]+ - Text
-
 
231
        */
-
 
232
        case 'P':
-
 
233
            for ( ii = 2; ii < argc ; ii++ )
-
 
234
            {
-
 
235
                if ( ii > 2 )
-
 
236
                    fprintf(stderr, " ");
-
 
237
                fprintf(stderr, "%ls", argv[ii] );
217
            
238
            }
-
 
239
            fprintf(stderr, "\n");
-
 
240
            break;
218
            
241
            
219
        default :
242
        default :
220
            ErrorExit("Unknown mode: ",argv[1]);
243
            ErrorExit("Unknown mode: ",argv[1]);
221
            break;
244
            break;
222
    }
245
    }
Line 885... Line 908...
885
 
908
 
886
    return data;
909
    return data;
887
}
910
}
888
 
911
 
889
/*----------------------------------------------------------------------------
912
/*----------------------------------------------------------------------------
-
 
913
** FUNCTION           : from_hex
-
 
914
**
-
 
915
** DESCRIPTION        : Converts a hex character to its integer value
-
 
916
**                      Expects well formed HEX
-
 
917
**
-
 
918
**
-
 
919
** INPUTS             : Character to convert
-
 
920
**
-
 
921
** RETURNS            : Character
-
 
922
**
-
 
923
----------------------------------------------------------------------------*/
-
 
924
_TCHAR from_hex(_TCHAR ch)
-
 
925
{
-
 
926
    if ( ch >= '0' && ch <= '9' )
-
 
927
    {
-
 
928
        return ch - '0';
-
 
929
    }
-
 
930
 
-
 
931
    if ( ch >= 'A' && ch <= 'F' )
-
 
932
    {
-
 
933
        return ch - 'A' + 10;
-
 
934
    }
-
 
935
 
-
 
936
    if ( ch >= 'a' && ch <= 'f' )
-
 
937
    {
-
 
938
        return ch - 'f' + 10;
-
 
939
    }
-
 
940
 
-
 
941
    return 0;
-
 
942
}
-
 
943
 
-
 
944
/*----------------------------------------------------------------------------
-
 
945
** FUNCTION           : url_decode
-
 
946
**
-
 
947
** DESCRIPTION        : Perform (modified) URL decoding of a string
-
 
948
**                      Only support %nn stuff
-
 
949
**                      Its done inplace
-
 
950
**
-
 
951
**
-
 
952
** INPUTS             : str             - String to process
-
 
953
**
-
 
954
** RETURNS            : Nothing
-
 
955
**
-
 
956
----------------------------------------------------------------------------*/
-
 
957
 
-
 
958
void url_decode(_TCHAR *str)
-
 
959
{
-
 
960
  _TCHAR *pstr = str;
-
 
961
  _TCHAR *pbuf = str;
-
 
962
 
-
 
963
    while (*pstr)
-
 
964
    {
-
 
965
        if (*pstr == '%')
-
 
966
        {
-
 
967
            if (pstr[1] && pstr[2])
-
 
968
            {
-
 
969
                *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]);
-
 
970
                pstr += 2;
-
 
971
            }
-
 
972
/*        } */
-
 
973
/*      } else if (*pstr == '+') {  */
-
 
974
/*              *pbuf++ = ' '; */
-
 
975
    }
-
 
976
    else
-
 
977
    {
-
 
978
        *pbuf++ = *pstr;
-
 
979
    }
-
 
980
        pstr++;
-
 
981
    }
-
 
982
    *pbuf = '\0';
-
 
983
}
-
 
984
 
-
 
985
/*----------------------------------------------------------------------------
890
** FUNCTION           : ErrorExit
986
** FUNCTION           : ErrorExit
891
**
987
**
892
** DESCRIPTION        : Error processing
988
** DESCRIPTION        : Error processing
893
**                      Report an error and terminate process
989
**                      Report an error and terminate process
894
**
990
**