Subversion Repositories DevTools

Rev

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

Rev 2354 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 64... Line 65...
64
void RmItem( int argc, char* argv[] );
65
void RmItem( int argc, char* argv[] );
65
int wildcmp(char *string, char *wild );
66
int wildcmp(char *string, char *wild );
66
int DeleteOneFile (char * dst );
67
int DeleteOneFile (char * dst );
67
void DeleteOneDirectory (char *path );
68
void DeleteOneDirectory (char *path );
68
void stdCheck( char *name, int argBad, char *txt );
69
void stdCheck( char *name, int argBad, char *txt );
-
 
70
void url_decode(char *str);
69
 
71
 
70
/*
72
/*
71
**  Global
73
**  Global
72
*/
74
*/
73
char  verbose = 1;                          /* Debugging aid */
75
char  verbose = 1;                          /* Debugging aid */
Line 83... Line 85...
83
         "      c9 copyFile     dstPath srcPath chmod\n"
85
         "      c9 copyFile     dstPath srcPath chmod\n"
84
         "      d9 unCopyFile   dstPath\n"
86
         "      d9 unCopyFile   dstPath\n"
85
         "      r9 RmFile       file+\n"
87
         "      r9 RmFile       file+\n"
86
         "      D9 DeleteFiles  dstDir file+ - supports (?*)\n"
88
         "      D9 DeleteFiles  dstDir file+ - supports (?*)\n"
87
         "      T9 DeleteTree   dstDir+\n"
89
         "      T9 DeleteTree   dstDir+\n"
88
         "      R9 RmItem       (dir|file)+\n";
90
         "      R9 RmItem       (dir|file)+\n"
-
 
91
         "      P9 PrintArgs    ...\n";
89
 
92
 
90
/*----------------------------------------------------------------------------
93
/*----------------------------------------------------------------------------
91
** FUNCTION           : main
94
** FUNCTION           : main
92
**
95
**
93
** DESCRIPTION        : Main entry points
96
** DESCRIPTION        : Main entry points
Line 120... Line 123...
120
    **      [1] - Verbose : 0 .. 9
123
    **      [1] - Verbose : 0 .. 9
121
    */
124
    */
122
    if ( argc > 1 && ( argv[1][1] >= '0' && argv[1][1] <= '9' ) )
125
    if ( argc > 1 && ( argv[1][1] >= '0' && argv[1][1] <= '9' ) )
123
    {
126
    {
124
        verbose = argv[1][1] - '0';
127
        verbose = argv[1][1] - '0';
-
 
128
    }
125
 
129
 
-
 
130
    /*
-
 
131
    **  URL Decode most arguments
-
 
132
    **  To get past the stupidities of shells and make the arguments
-
 
133
    **  will have been URL(modified) encoded
-
 
134
    **
-
 
135
    **  Decode all args in place
-
 
136
    */
-
 
137
    for ( ii = 2; ii < argc ; ii++ )
-
 
138
    {
-
 
139
        url_decode(argv[ii]);
126
        /*
140
        /*
127
        **  If Verbose, then display arguments
141
        **  If Verbose, then display arguments
128
        */
142
        */
129
        if ( verbose > 2 )
143
        if ( verbose > 2 )
130
        {
-
 
131
            for ( ii = 0; ii < argc ; ii++ )
-
 
132
            {
-
 
133
                fprintf(stderr, "Arg%d: %s:\n", ii, argv[ii] );
144
            fprintf(stderr, "Arg%d: %s:\n", ii, argv[ii] );
134
            }
-
 
135
            fflush(stderr) ;
-
 
136
        }
-
 
137
    }
145
    }
-
 
146
     fflush(stderr) ;
138
    
147
    
139
    /*
148
    /*
140
    **  Switch to required operation
149
    **  Switch to required operation
141
    */
150
    */
142
    switch( argv[1][0] )
151
    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, "%s", 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 920... Line 943...
920
    }
943
    }
921
 
944
 
922
    return !*wild;
945
    return !*wild;
923
}
946
}
924
 
947
 
-
 
948
/*----------------------------------------------------------------------------
-
 
949
** FUNCTION           : from_hex
-
 
950
**
-
 
951
** DESCRIPTION        : Converts a hex character to its integer value
-
 
952
**                      Expects well formed HEX
-
 
953
**
-
 
954
**
-
 
955
** INPUTS             : Character to convert
-
 
956
**
-
 
957
** RETURNS            : Character
-
 
958
**
-
 
959
----------------------------------------------------------------------------*/
-
 
960
char from_hex(char ch)
-
 
961
{
-
 
962
    if ( ch >= '0' && ch <= '9' )
-
 
963
    {
-
 
964
        return ch - '0';
-
 
965
    }
-
 
966
 
-
 
967
    if ( ch >= 'A' && ch <= 'F' )
-
 
968
    {
-
 
969
        return ch - 'A' + 10;
-
 
970
    }
-
 
971
 
-
 
972
    if ( ch >= 'a' && ch <= 'f' )
-
 
973
    {
-
 
974
        return ch - 'f' + 10;
-
 
975
    }
-
 
976
 
-
 
977
    return 0;
-
 
978
}
-
 
979
 
-
 
980
/*----------------------------------------------------------------------------
-
 
981
** FUNCTION           : url_decode
-
 
982
**
-
 
983
** DESCRIPTION        : Perform (modified) URL decoding of a string
-
 
984
**                      Only support %nn stuff
-
 
985
**                      Its done inplace
-
 
986
**
-
 
987
**
-
 
988
** INPUTS             : str             - String to process
-
 
989
**
-
 
990
** RETURNS            : Nothing
-
 
991
**
-
 
992
----------------------------------------------------------------------------*/
925
 
993
 
-
 
994
void url_decode(char *str)
-
 
995
{
-
 
996
  char *pstr = str;
-
 
997
  char *pbuf = str;
926
 
998
 
-
 
999
    while (*pstr)
-
 
1000
    {
-
 
1001
        if (*pstr == '%')
-
 
1002
        {
-
 
1003
            if (pstr[1] && pstr[2])
-
 
1004
            {
-
 
1005
                *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]);
-
 
1006
                pstr += 2;
-
 
1007
            }
-
 
1008
/*        } */
-
 
1009
/*      } else if (*pstr == '+') {  */
-
 
1010
/*              *pbuf++ = ' '; */
-
 
1011
    }
-
 
1012
    else
-
 
1013
    {
-
 
1014
        *pbuf++ = *pstr;
-
 
1015
    }
-
 
1016
        pstr++;
-
 
1017
    }
-
 
1018
    *pbuf = '\0';
-
 
1019
}
927
 
1020
 
928
/*----------------------------------------------------------------------------
1021
/*----------------------------------------------------------------------------
929
** FUNCTION           : ErrorExit
1022
** FUNCTION           : ErrorExit
930
**
1023
**
931
** DESCRIPTION        : Error processing
1024
** DESCRIPTION        : Error processing