Subversion Repositories DevTools

Rev

Rev 2310 | Rev 2313 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2310 Rev 2311
Line 4... Line 4...
4
**
4
**
5
**  Project/Product : 
5
**  Project/Product : 
6
**  Filename        : JatsFileUtil.c
6
**  Filename        : JatsFileUtil.c
7
**  Author(s)       : DDP
7
**  Author(s)       : DDP
8
**
8
**
9
**  Description     :
9
**  Description     :   Jats Build System File utility
10
**                      The program mimics - but a lot faster a Jats Makefile fragment
10
**                      Used by the generated makefiles to perform specific operations
-
 
11
**
11
**                      The program will:
12
**                      The program exists to solve problems:
-
 
13
**                          Windows: Shell is very very slow to start up
-
 
14
**                          Windows: Some commands have ~260 character path length issue
-
 
15
**                          Windows/Solaris/Linux: Compatibility issues with the 'rm' command
-
 
16
**                          All: Consistent use of '/' as a path separator
12
**
17
**
-
 
18
**                      Note: There are two flavors of this program that MUST be
13
**                      Operate in 5 modes
19
**                            kept in sync.
-
 
20
**
-
 
21
**                      The program will perform the following operations:
14
**                          CopyFile
22
**                          (c) CopyFile
15
**                          DeleteFile
23
**                          (d) DeleteFile
16
**                          Remove Files (wildcard)
24
**                          (r) Remove Files (wildcard)
17
**                          DeleteDir after deleting specified files (wildcard)
25
**                          (D) DeleteDir after deleting specified files (wildcard)
18
**                          Delete Directory Tree
26
**                          (T) Delete Directory Tree
-
 
27
**
-
 
28
**                      Example Usage
19
**
29
**
20
**                          JatsFileUtil.exe c9 'copyFile'    aaa/bbb/ccc/dddd/file build_test.pl +w
30
**                          JatsFileUtil c9 'copyFile'    aaa/bbb/ccc/dddd/file build_test.pl +w
21
**                          JatsFileUtil.exe d9 'unCopyFile'  aaa/bbb/ccc/dddd/file
31
**                          JatsFileUtil d9 'unCopyFile'  aaa/bbb/ccc/dddd/file
22
**                          JatsFileUtil.exe r9 'deleteFile'  a1 b2 c3
32
**                          JatsFileUtil r9 'deleteFile'  a1 b2 c3
23
**                          JatsFileUtil.exe D9 'DeleteFiles' src/WIN32P.OBJ *.err *.pch '*'
33
**                          JatsFileUtil D9 'DeleteFiles' src/WIN32P.OBJ *.err *.pch '*'
24
**                          JatsFileUtil.exe T9 'DeleteTree'  interface
34
**                          JatsFileUtil T9 'DeleteTree'  interface
25
**
35
**
26
**                      First two arguments are common to all
36
**                      First two arguments are common to all
27
**                          argv[1]     - Mode specifier, Debug specifier
37
**                          argv[1]     - Mode specifier, Debug specifier
28
**                          argv[2]     - Display Text
38
**                          argv[2]     - Display Text
29
**
39
**
30
**                      CopyFile (5 args)
-
 
31
**                          1) Display the ----- Text dest
-
 
32
**                          2) Error if the source is not found
-
 
33
**                          3) Create target path if not alraedy existing
-
 
34
**                          4) Copy the source to the target - overwritting the target
-
 
35
**                          5) Set File mode
-
 
36
**                          6) Test for file existence
-
 
37
**
-
 
38
**                      DeleteFile (3 args)
-
 
39
**                          1) Display the ----- Text dest
-
 
40
**                          2) Delete the target file
-
 
41
**
-
 
42
**                      RemoveFiles ( >1 arg)
-
 
43
**                          1) Silenty delete a list of files. The files may
-
 
44
**                             be readonly so the attributes will need to be fixed.
-
 
45
**
-
 
46
**                             Assumes the current directory
-
 
47
**
-
 
48
**                       DeleteDir (> 2 args)
-
 
49
**                          1) Silenty delete a list of files. The files may
-
 
50
**                             be readonly so the attributes will need to be fixed.
-
 
51
**                          2) Delete the directory if its empty
-
 
52
**
-
 
53
**                        Delete directory tree
-
 
54
**                          1) Silently delete an entire directory tree
-
 
55
**                             including files and subdiretories
-
 
56
**
-
 
57
**                      Make paths use '/'
-
 
58
**
-
 
59
**
-
 
60
**  Information     :
40
**  Information     :
61
**   Compiler       : ANSI C++
41
**   Compiler       : ANSI C
62
**   Target         : 
42
**   Target         : Windows 2000+, Linux, Solaris8+
63
**
43
**
64
***==========================================================================*/
44
***==========================================================================*/
65
 
45
 
66
#include <stdio.h>
46
#include <stdio.h>
67
#include <sys/types.h>
47
#include <sys/types.h>
Line 72... Line 52...
72
#include <dirent.h>
52
#include <dirent.h>
73
#include <string.h>
53
#include <string.h>
74
 
54
 
75
void ErrorExit (char * lpszMessage, char * lpszMessage2);
55
void ErrorExit (char * lpszMessage, char * lpszMessage2);
76
void createPaths ( char *path );
56
void createPaths ( char *path );
77
int CopyFile ( char *src, char *dst, mode_t st_mode );
-
 
78
void DeleteDir( int argc, char* argv[] );
57
void DeleteDir( int argc, char* argv[] );
79
void DeleteDirTree( int argc, char* argv[] );
58
void DeleteDirTree( int argc, char* argv[] );
80
int wildcmp(char *string, char *wild );
-
 
81
char * makePath( char *base, char *path);
59
char * makePath( char *base, char *path);
82
int DeleteOneFile (char * dst );
60
int DeleteOneFile (char * dst );
83
void DeleteOneDirectoryTree( char* baseDir );
61
void DeleteOneDirectoryTree( char* baseDir );
84
void copyOneFile( int argc, char* argv[] );
62
void copyOneFile( int argc, char* argv[] );
-
 
63
int CopyFile ( char *src, char *dst, mode_t st_mode );
-
 
64
int wildcmp(char *string, char *wild );
85
 
65
 
86
/*
66
/*
87
**  Global
67
**  Global
88
*/
68
*/
89
char  verbose = 1;                          /* Debugging aid */
69
char  verbose = 1;                          /* Debugging aid */
Line 92... Line 72...
92
** FUNCTION           : main
72
** FUNCTION           : main
93
**
73
**
94
** DESCRIPTION        : Main entry points
74
** DESCRIPTION        : Main entry points
95
**
75
**
96
**
76
**
97
** INPUTS             : Arguments are fixed
-
 
98
**                          Mode    - ModeDebug
-
 
99
**                          Text    - Text to output
77
** INPUTS             : argc            - Argument Count
100
**                          dest    - Target Path
78
**                      argv            - Argument Vector
101
**                          file    - Source path   [Copy Only]
-
 
102
**                          fmode   - File mode     [Copy Only]
-
 
103
**
79
**
104
** RETURNS            : 0 - All is good
80
** RETURNS            : 0 - All is good
105
**
81
**
106
----------------------------------------------------------------------------*/
82
----------------------------------------------------------------------------*/
107
 
83
 
108
int main(int argc, char* argv[])
84
int main(int argc, char* argv[])
109
{
85
{
110
    /*
86
    /*
111
    **  Examine the first argument
87
    **  Examine the first argument
112
    **  Must be a character string of
88
    **  Must be a character string of
113
    **      [0] - Mode : c or d or r or l
89
    **      [0] - Mode : One character
114
    **      [1] - Verbose : 0 .. 9
90
    **      [1] - Verbose : 0 .. 9
115
    */
91
    */
116
    if ( argc > 1 && ( argv[1][1] >= '0' && argv[1][1] <= '9' ) )
92
    if ( argc > 1 && ( argv[1][1] >= '0' && argv[1][1] <= '9' ) )
117
    {
93
    {
118
            verbose = argv[1][1] - '0';
94
        verbose = argv[1][1] - '0';
119
    }
-
 
120
 
95
 
121
    /*
96
        /*
122
    **  If Verbose, then display arguments
97
        **  If Verbose, then display arguments
123
    */
98
        */
124
    if ( verbose > 2 )
99
        if ( verbose > 2 )
125
    {
-
 
126
        int ii;
-
 
127
        for ( ii = 0; ii < argc ; ii++ )
-
 
128
        {
100
        {
-
 
101
            int ii;
-
 
102
            for ( ii = 0; ii < argc ; ii++ )
-
 
103
            {
129
            fprintf(stderr, "Arg%d: %s:\n", ii, argv[ii] );
104
                fprintf(stderr, "Arg%d: %s:\n", ii, argv[ii] );
-
 
105
            }
-
 
106
            fflush(stderr) ;
130
        }
107
        }
131
        fflush(stderr) ;
-
 
132
    }
108
    }
133
 
109
    
134
    /*
110
    /*
135
    **  Switch to required operation
111
    **  Switch to required operation
136
    */
112
    */
137
    switch ( argv[1][0]  )
113
    switch( argv[1][0] )
138
    {
114
    {
-
 
115
        /*
-
 
116
        **  CopyFile
-
 
117
        **      argv[2] - Text
-
 
118
        **      argv[3] - target path
-
 
119
        **      argv[4] - Source path
-
 
120
        **      argv[5] - File attributes
-
 
121
        */
139
        case 'c':
122
        case 'c':
140
            copyOneFile(argc, argv);
123
            copyOneFile(argc, argv);
141
            break;
124
            break;
142
 
125
 
-
 
126
        /*
-
 
127
        **  UnCopy a file
-
 
128
        **      argv[2] - Text
-
 
129
        **      argv[3] - target path
-
 
130
        */
143
        case 'd':
131
        case 'd':
144
            {
132
            {
145
                if ( argc != 4 )
133
                if ( argc != 4 )
146
                    ErrorExit("Incorrect argument count for mode","");
134
                    ErrorExit("Incorrect argument count for mode","");
147
 
135
 
Line 152... Line 140...
152
                fflush(stderr) ;
140
                fflush(stderr) ;
153
                DeleteOneFile(argv[3]);
141
                DeleteOneFile(argv[3]);
154
            }
142
            }
155
            break;
143
            break;
156
 
144
 
-
 
145
        /*
-
 
146
        **  Remove named files
-
 
147
        **      argv[2]     - Text
-
 
148
        **      argv[3]+    - target path
-
 
149
        */
157
        case 'r':
150
        case 'r':
158
                {
151
                {
159
                    int ii;
152
                    int ii;
160
 
153
 
161
                    if ( argc < 4 )
154
                    if ( argc < 4 )
Line 175... Line 168...
175
                        DeleteOneFile(argv[ii]);
168
                        DeleteOneFile(argv[ii]);
176
                    }
169
                    }
177
                }
170
                }
178
            break;
171
            break;
179
 
172
 
-
 
173
        /*
-
 
174
        **  Delete files in directory - with wildcards
-
 
175
        **      argv[2]     - Text
-
 
176
        **      argv[3]     - Base directory
-
 
177
        **      argv[4]+    - Files in dir to delete.
-
 
178
        */
180
        case 'D':
179
        case 'D':
181
            DeleteDir(argc - 2, argv + 2 );
180
            DeleteDir(argc - 2, argv + 2 );
182
            break;
181
            break;
183
 
182
 
-
 
183
        /*
-
 
184
        **  Delete files recursively
-
 
185
        **      argv[2] - Text
-
 
186
        **      argv[3]+  Base directory
-
 
187
        */
184
        case 'T':
188
        case 'T':
185
            DeleteDirTree(argc - 2, argv + 2 );
189
            DeleteDirTree(argc - 2, argv + 2 );
186
            break;
190
            break;
187
            
191
            
188
        default :
192
        default :
Line 453... Line 457...
453
    DIR *dir;
457
    DIR *dir;
454
    struct dirent *dirent;
458
    struct dirent *dirent;
455
    char *target;
459
    char *target;
456
 
460
 
457
    if ( argc < 3 )
461
    if ( argc < 3 )
458
        ErrorExit("Insuffiecient arguments for DeleteDir","");
462
        ErrorExit("Insufficient arguments for DeleteDir","");
459
 
463
 
460
    /*
464
    /*
461
    **  Display the user message
465
    **  Display the user message
462
    **      Supress display if the message is empty
466
    **      Supress display if the message is empty
463
    */
467
    */
Line 588... Line 592...
588
void DeleteDirTree( int argc, char* argv[] )
592
void DeleteDirTree( int argc, char* argv[] )
589
{
593
{
590
    int ii;
594
    int ii;
591
 
595
 
592
    if ( argc < 2 )
596
    if ( argc < 2 )
593
        ErrorExit("Insuffiecient arguments for DeleteDir","");
597
        ErrorExit("Insufficient arguments for DeleteDirTree","");
594
        
598
        
595
    /*
599
    /*
596
    **  Display the user message
600
    **  Display the user message
597
    **      Supress display if the message is empty
601
    **      Supress display if the message is empty
598
    */
602
    */