Subversion Repositories DevTools

Rev

Rev 2085 | Rev 2311 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2073 dpurdie 1
/*============================================================================
2
** Copyright (C) 1998-2012 Vix Technology, All rights reserved
3
**============================================================================
4
**
5
**  Project/Product : 
2075 dpurdie 6
**  Filename        : JatsFileUtil.c
2073 dpurdie 7
**  Author(s)       : DDP
8
**
9
**  Description     :
10
**                      The program mimics - but a lot faster a Jats Makefile fragment
11
**                      The program will:
12
**
2310 dpurdie 13
**                      Operate in 5 modes
2073 dpurdie 14
**                          CopyFile
15
**                          DeleteFile
2310 dpurdie 16
**                          Remove Files (wildcard)
17
**                          DeleteDir after deleting specified files (wildcard)
18
**                          Delete Directory Tree
2073 dpurdie 19
**
2310 dpurdie 20
**                          JatsFileUtil.exe c9 'copyFile'    aaa/bbb/ccc/dddd/file build_test.pl +w
21
**                          JatsFileUtil.exe d9 'unCopyFile'  aaa/bbb/ccc/dddd/file
22
**                          JatsFileUtil.exe r9 'deleteFile'  a1 b2 c3
23
**                          JatsFileUtil.exe D9 'DeleteFiles' src/WIN32P.OBJ *.err *.pch '*'
24
**                          JatsFileUtil.exe T9 'DeleteTree'  interface
25
**
26
**                      First two arguments are common to all
27
**                          argv[1]     - Mode specifier, Debug specifier
28
**                          argv[2]     - Display Text
29
**
2073 dpurdie 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
**
2075 dpurdie 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
**
2085 dpurdie 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
**
2310 dpurdie 53
**                        Delete directory tree
54
**                          1) Silently delete an entire directory tree
55
**                             including files and subdiretories
56
**
2073 dpurdie 57
**                      Make paths use '/'
58
**
59
**
60
**  Information     :
61
**   Compiler       : ANSI C++
62
**   Target         : 
63
**
64
***==========================================================================*/
65
 
66
#include <stdio.h>
67
#include <sys/types.h>
68
#include <sys/stat.h>
69
#include <fcntl.h>
70
#include <unistd.h>
71
#include <stdlib.h>
2085 dpurdie 72
#include <dirent.h>
2073 dpurdie 73
#include <string.h>
74
 
75
void ErrorExit (char * lpszMessage, char * lpszMessage2);
76
void createPaths ( char *path );
2075 dpurdie 77
int CopyFile ( char *src, char *dst, mode_t st_mode );
2085 dpurdie 78
void DeleteDir( int argc, char* argv[] );
2310 dpurdie 79
void DeleteDirTree( int argc, char* argv[] );
2085 dpurdie 80
int wildcmp(char *string, char *wild );
2310 dpurdie 81
char * makePath( char *base, char *path);
82
int DeleteOneFile (char * dst );
83
void DeleteOneDirectoryTree( char* baseDir );
84
void copyOneFile( int argc, char* argv[] );
2073 dpurdie 85
 
86
/*
87
**  Global
88
*/
89
char  verbose = 1;                          /* Debugging aid */
90
 
91
/*----------------------------------------------------------------------------
92
** FUNCTION           : main
93
**
94
** DESCRIPTION        : Main entry points
95
**
96
**
97
** INPUTS             : Arguments are fixed
98
**                          Mode    - ModeDebug
99
**                          Text    - Text to output
100
**                          dest    - Target Path
101
**                          file    - Source path   [Copy Only]
102
**                          fmode   - File mode     [Copy Only]
103
**
104
** RETURNS            : 0 - All is good
105
**
106
----------------------------------------------------------------------------*/
107
 
108
int main(int argc, char* argv[])
109
{
110
    /*
111
    **  Examine the first argument
112
    **  Must be a character string of
2085 dpurdie 113
    **      [0] - Mode : c or d or r or l
2073 dpurdie 114
    **      [1] - Verbose : 0 .. 9
115
    */
2310 dpurdie 116
    if ( argc > 1 && ( argv[1][1] >= '0' && argv[1][1] <= '9' ) )
2073 dpurdie 117
    {
118
            verbose = argv[1][1] - '0';
119
    }
120
 
121
    /*
122
    **  If Verbose, then display arguments
123
    */
2310 dpurdie 124
    if ( verbose > 2 )
2073 dpurdie 125
    {
126
        int ii;
127
        for ( ii = 0; ii < argc ; ii++ )
128
        {
129
            fprintf(stderr, "Arg%d: %s:\n", ii, argv[ii] );
130
        }
131
        fflush(stderr) ;
132
    }
133
 
134
    /*
2310 dpurdie 135
    **  Switch to required operation
2075 dpurdie 136
    */
2310 dpurdie 137
    switch ( argv[1][0]  )
2075 dpurdie 138
    {
2310 dpurdie 139
        case 'c':
140
            copyOneFile(argc, argv);
141
            break;
2075 dpurdie 142
 
2310 dpurdie 143
        case 'd':
144
            {
145
                if ( argc != 4 )
146
                    ErrorExit("Incorrect argument count for mode","");
2085 dpurdie 147
 
2310 dpurdie 148
                /*
149
                **  Display user text
150
                */
151
                fprintf(stderr, "---- %s %s\n", argv[2], argv[3]);
152
                fflush(stderr) ;
153
                DeleteOneFile(argv[3]);
154
            }
155
            break;
2073 dpurdie 156
 
2310 dpurdie 157
        case 'r':
158
                {
159
                    int ii;
2073 dpurdie 160
 
2310 dpurdie 161
                    if ( argc < 4 )
162
                        ErrorExit("Incorrect argument count for mode","");
2073 dpurdie 163
 
2310 dpurdie 164
                    /*
165
                    **  Display user text
166
                    */
167
                    if ( argv[2][0] )
168
                    {
169
                        fprintf(stderr, "%s\n", argv[2]);
170
                        fflush(stderr) ;
171
                    }
2073 dpurdie 172
 
2310 dpurdie 173
                    for ( ii = 3; ii < argc ; ii++ )
174
                    {
175
                        DeleteOneFile(argv[ii]);
176
                    }
177
                }
178
            break;
2073 dpurdie 179
 
2310 dpurdie 180
        case 'D':
181
            DeleteDir(argc - 2, argv + 2 );
182
            break;
2073 dpurdie 183
 
2310 dpurdie 184
        case 'T':
185
            DeleteDirTree(argc - 2, argv + 2 );
186
            break;
187
 
188
        default :
189
            ErrorExit("Unknown mode: ",argv[1]);
190
            break;
2073 dpurdie 191
    }
192
    return 0;
193
}
194
 
195
/*----------------------------------------------------------------------------
196
** FUNCTION           : createPaths
197
**
198
** DESCRIPTION        : Create the path to the target
199
**
200
**
201
** INPUTS             : path
202
**
203
** RETURNS            : Will not return in error
204
**
205
----------------------------------------------------------------------------*/
206
 
207
void createPaths ( char *path )
208
{
209
    struct stat fstat;
210
    int  rv;
211
    char *ptr = path;
212
 
213
    while ( *ptr )
214
    {
215
        if ( *ptr == '/' )
216
        {
217
            *ptr = 0;
2310 dpurdie 218
/* fprintf(stderr, "createPaths: %s\n", path); */
2073 dpurdie 219
            rv = stat( path, &fstat );
220
            if ( rv )
221
            {
222
                if ( verbose > 1 )
223
                {
224
                    fprintf(stderr, "createPaths: %s\n", path);
225
                    fflush(stderr) ;
226
                }
227
                rv = mkdir( path, 0777 );
228
                if ( rv )
229
                {
2075 dpurdie 230
                    ErrorExit("Could not create directories:", path);
2073 dpurdie 231
                }
232
            }
233
            *ptr = '/';
234
        }
235
        ptr++;
236
    }
237
}
238
 
239
/*----------------------------------------------------------------------------
2310 dpurdie 240
** FUNCTION           : copyOneFile
241
**
242
** DESCRIPTION        : Copy one file to a target
243
**                      Used to package and install files
244
**
245
**
246
** INPUTS             : argc            - Argc count
247
**                      argv            - Argument list
248
**                          argv[2]     - Display text Prefix
249
**                          argv[3]     - Target path
250
**                          argv[4]     - Source Path
251
**                          argv[5]     - File attributes
252
**
253
** RETURNS            :
254
**
255
----------------------------------------------------------------------------*/
256
 
257
void copyOneFile( int argc, char* argv[] )
258
{
259
	int    rv;
260
    char * src;
261
    char * dst;
262
    struct stat fstat;
263
 
264
    if ( argc != 6 )
265
        ErrorExit("Incorrect argument count for file copy","");
266
 
267
    /*
268
    **  Display user text
269
    */
270
    fprintf(stderr, "---- %s %s\n", argv[2], argv[3]);
271
    fflush(stderr) ;
272
 
273
    dst = argv[3];
274
    src = argv[4];
275
 
276
    /*
277
    **   Check that the source is a file
278
    */
279
    if ( verbose )
280
        fprintf(stderr, "Validate Source File: %s\n", src);
281
 
282
    rv = stat( src, &fstat );
283
    if ( rv != 0 )
284
    {
285
/* Need to be a better message */
286
        fprintf(stderr, "Source: %s\n", src);
287
        ErrorExit("Source File not found: ", argv[4]);
288
    }
289
 
290
    /*
291
    **  Remove the ReadOnly attribute on the dest file
292
    */
293
    DeleteOneFile(dst);
294
 
295
    /*
296
    **  Create directories
297
    **  Use the path to the target - not the provided directory
298
    **  as the createPaths function will not create the last element
299
    */
300
    createPaths( dst );
301
 
302
    /*
303
    **   Copy the file
304
    */
305
    if ( ! CopyFile( src, dst, fstat.st_mode ) )
306
    {
307
        ErrorExit("Copy Error: ", argv[4]);
308
    }
309
 
310
    /*
311
    **  Test for files existence
312
    */
313
    if ( verbose )
314
        fprintf(stderr, "Test target was copied: %s\n", dst);
315
 
316
    rv = stat( dst, &fstat );
317
    if ( rv != 0 )
318
    {
319
/* Need to be a better message */
320
        ErrorExit("File not found after copy: ", argv[3]);
321
    }
322
 
323
    /*
324
    **  Set the files attributes
325
    **      Assume read-only
326
    */
327
    if ( strstr( argv[5], "-w" ) )
328
    {
329
        if ( verbose > 1 )
330
            fprintf(stderr, "Set target read-only: %s\n", dst);
331
        fstat.st_mode &= ~(S_IWRITE | S_IWOTH | S_IWGRP );
332
    }
333
 
334
    if ( strstr( argv[5], "+w" ) )
335
    {
336
        if ( verbose > 1 )
337
            fprintf(stderr, "Set target writable: %s\n", dst);
338
        fstat.st_mode |= (S_IWRITE | S_IWOTH | S_IWGRP );
339
    }
340
 
341
    if ( strstr( argv[5], "+x" ) )
342
    {
343
        if ( verbose > 1 )
344
            fprintf(stderr, "Set target executable: %s\n", dst);
345
        fstat.st_mode |= ( S_IXUSR | S_IXOTH | S_IXGRP );
346
    }
347
 
348
    if ( strstr( argv[5], "-x" ) )
349
    {
350
        if ( verbose > 1)
351
            fprintf(stderr, "Set target executable: %s\n", dst);
352
        fstat.st_mode &= ~( S_IXUSR | S_IXOTH | S_IXGRP );
353
    }
354
 
355
    if ( verbose )
356
        fprintf(stderr, "Set target perms: %s, 0%o\n", dst, fstat.st_mode);
357
    rv = chmod( dst, fstat.st_mode );
358
    if ( rv != 0 )
359
    {
360
        ErrorExit("Setting ReadOnly: ", argv[3]);
361
    }
362
}
363
 
364
/*----------------------------------------------------------------------------
2073 dpurdie 365
** FUNCTION           : CopyFile
366
**
367
** DESCRIPTION        : Just copy a file
368
**
369
**
370
** INPUTS             : src - source path - already exists
371
**                      dst - path. Dirs already exist
372
**                      st_mode - Creation  mode. Copied from source file
373
**
374
** RETURNS            : false - Error
375
**
376
----------------------------------------------------------------------------*/
377
 
378
#define COPYSIZE  1024
379
int CopyFile ( char *src, char *dst, mode_t st_mode )
380
{
381
 
382
     ssize_t rlen = 0 ;
383
     ssize_t wlen = 0 ;
384
     int in;
385
     int out;
386
     int ferror = 0;
387
    char buffer[COPYSIZE] = { '\0' } ;
388
 
389
    if ( verbose )
390
    {
391
        fprintf(stderr, "CopyFile: Output Mode: 0%o\n", st_mode);
392
        fflush(stderr) ;
393
    }
394
 
395
    in = open( src, O_RDONLY ) ;
396
    if ( in < 0 )
2075 dpurdie 397
        ErrorExit("Could not open source:", src);
2073 dpurdie 398
 
399
    out = open( dst, O_WRONLY | O_CREAT, st_mode | S_IWRITE );
400
    if ( out < 0 )
2075 dpurdie 401
        ErrorExit("Could not open dst:", dst);
2073 dpurdie 402
 
403
    while( (rlen = read( in, buffer, COPYSIZE )) > 0 )
404
    {
405
        wlen = write( out, buffer, rlen ) ;
406
        if ( wlen != rlen )
407
        {
408
            ferror = 1;
409
            break;
410
        }
411
    }
412
 
413
    close(in) ;
414
    close(out) ;
415
 
416
    /*
417
    **  File error
418
    **  Delete target
419
    */
420
    if ( ferror || rlen < 0 )
421
    {
422
        unlink(dst) ;
423
        return 0;
424
    }
425
    return 1;
426
}
427
 
2075 dpurdie 428
/*----------------------------------------------------------------------------
2085 dpurdie 429
** FUNCTION           : DeleteDir
430
**
431
** DESCRIPTION        : Delete a list of files in a specified directory
432
**                      Ensure files are writable
433
**                      Wilcarding is supported
434
**
435
**                      Then delete the directory - if its empty
436
**
437
**
438
** INPUTS             : argc    - count of args
439
**                      argv    - list of files to delete
440
**                                [0]:  Text to display
441
**                                [1]:  Base directory
2310 dpurdie 442
**                                [2]+  Files in dir to delete
2085 dpurdie 443
**
2310 dpurdie 444
** RETURNS            : Will not return on error
2085 dpurdie 445
**
446
----------------------------------------------------------------------------*/
2075 dpurdie 447
 
2085 dpurdie 448
void DeleteDir( int argc, char* argv[] )
449
{
450
	int rv;
451
    struct stat fstat;
452
    char* baseDir;
453
    DIR *dir;
454
    struct dirent *dirent;
2310 dpurdie 455
    char *target;
2085 dpurdie 456
 
457
    if ( argc < 3 )
458
        ErrorExit("Insuffiecient arguments for DeleteDir","");
2310 dpurdie 459
 
2085 dpurdie 460
    /*
461
    **  Display the user message
462
    **      Supress display if the message is empty
463
    */
464
    if ( argv[0][0] )
465
    {
466
        fprintf(stderr, "%s\n", argv[0]);
467
        fflush(stderr) ;
468
    }
469
 
470
    /*
471
    **  Extract the base directory from the argument list
472
    **  This must be a directory
473
    */
474
    baseDir = argv[1];
475
    argc -= 2;
476
    argv+=2;
477
 
478
    /*
479
    **  Ensure that the base directory exists
480
    */
481
    rv = stat( baseDir, &fstat );
482
    if ( rv != 0 )
483
    {
484
        /*
485
        **  Directory does not exists
486
        **  Assume its aleady deleted
487
        */
488
        if ( verbose > 1 )
489
            fprintf(stderr, "Base dir does not exist: %s\n", baseDir);
490
        return;
491
    }
492
 
493
    if ( !(fstat.st_mode & S_IFDIR))
494
    {
495
        /*
496
        **  Target is not a directory
497
        **  Don't do anything
498
        */
499
        if ( verbose > 1 )
500
            fprintf(stderr, "Base dir is not a directory: %s\n", baseDir);
501
        return;
502
    }
503
 
504
    /*
505
    **  Process all the suffixes
506
    **  They may contain a wild card
507
    */
508
    dir = opendir( baseDir );
509
    if ( dir == NULL )
510
    {
511
        /*
512
        **  Target is not a directory
513
        **  Don't do anything
514
        */
515
        if ( verbose > 1 )
516
            fprintf(stderr, "Base dir is not a directory: %s\n", baseDir);
517
        return;
518
    }
519
 
520
    /*
521
    **  Read next directory entry
522
    */
523
    while ( (dirent = readdir(dir)) != NULL )
524
    {
525
        int ii;
526
        if ( verbose > 2 )
527
            fprintf(stderr, "Directory Entry:%s,%s\n", baseDir, dirent->d_name );
528
 
529
        if ( strcmp( ".", dirent->d_name ) == 0 )
530
            continue;
531
 
532
        if ( strcmp( "..", dirent->d_name ) == 0 )
533
            continue;
534
 
535
        /*
536
        **  Compare against each item in the user list
537
        */
538
        for ( ii = 0; ii < argc ; ii++)
539
        {
540
 
541
            if ( wildcmp(dirent->d_name, argv[ii] )  )
542
            {
543
                if ( verbose > 1 )
544
                    fprintf(stderr, "Matching: %s, %s --- Found\n", dirent->d_name, argv[ii] );
2310 dpurdie 545
 
2085 dpurdie 546
                /*
547
                **  Matching file found
548
                */
2310 dpurdie 549
                target = makePath( baseDir, dirent->d_name);
550
                DeleteOneFile(target);
551
                free(target);
2085 dpurdie 552
            }
553
        }
554
    }
555
    closedir(dir);
556
 
557
    /*
558
    **  Finally delete the diretory
559
    **      Unless its '.'
560
    */
561
    if ( strcmp( ".", baseDir) != 0 )
562
    {
563
        if ( verbose > 1 )
564
            fprintf(stderr, "Delete Directory: %s\n", baseDir);
2310 dpurdie 565
 
2085 dpurdie 566
        if ( rmdir (baseDir ) )
567
        {
568
            if ( verbose )
569
                fprintf(stderr, "Directory not deleted: %s\n", baseDir);
570
        }
571
    }
572
}
573
 
2073 dpurdie 574
/*----------------------------------------------------------------------------
2310 dpurdie 575
** FUNCTION           : DeleteDirTree
576
**
577
** DESCRIPTION        : Delete an entire directory tree(s)
578
**
579
** INPUTS             : argc    - count of args
580
**                      argv    - list of files to delete
581
**                                [0]:  Text to display
582
**                                [1]+  Base directory
583
**
584
** RETURNS            : Will not return on error
585
**
586
----------------------------------------------------------------------------*/
587
 
588
void DeleteDirTree( int argc, char* argv[] )
589
{
590
    int ii;
591
 
592
    if ( argc < 2 )
593
        ErrorExit("Insuffiecient arguments for DeleteDir","");
594
 
595
    /*
596
    **  Display the user message
597
    **      Supress display if the message is empty
598
    */
599
    if ( argv[0][0] )
600
    {
601
        fprintf(stderr, "%s\n", argv[0]);
602
        fflush(stderr) ;
603
    }
604
 
605
    for ( ii = 1; ii < argc ; ii++)
606
    {
607
        DeleteOneDirectoryTree( argv[ii] );
608
    }
609
}
610
 
611
/*----------------------------------------------------------------------------
612
** FUNCTION           : DeleteOneDirectoryTree
613
**
614
** DESCRIPTION        : Delete an entire directory tree(s)
615
**
616
** INPUTS             : path    - Dir to delete
617
**
618
** RETURNS            : Will not return on error
619
**
620
----------------------------------------------------------------------------*/
621
 
622
void DeleteOneDirectoryTree( char* baseDir )
623
{
624
    struct stat fstat;
625
    DIR *dir;
626
    struct dirent *dirent;
627
    char *target;
628
    int rv;
629
 
630
    /*
631
    **  A bit of a sanity test
632
    */
633
    if ( strcmp( ".", baseDir) == 0 || strcmp( "..", baseDir) == 0 )
634
    {
635
        fprintf(stderr, "DeleteOneDirectoryTree will not delete '.' or '..'\n");
636
        return;
637
    }
638
 
639
    /*
640
    **  Process all entries
641
    */
642
    dir = opendir( baseDir );
643
    if ( dir == NULL )
644
    {
645
        /*
646
        **  Target is not a directory
647
        **  Don't do anything
648
        */
649
        if ( verbose > 1 )
650
            fprintf(stderr, "Base dir is not a directory: %s\n", baseDir);
651
        return;
652
    }
653
 
654
    /*
655
    **  Read next directory entry
656
    */
657
    while ( (dirent = readdir(dir)) != NULL )
658
    {
659
        if ( verbose > 2 )
660
            fprintf(stderr, "Directory Entry:%s,%s\n", baseDir, dirent->d_name );
661
 
662
        if ( strcmp( ".", dirent->d_name ) == 0 )
663
            continue;
664
 
665
        if ( strcmp( "..", dirent->d_name ) == 0 )
666
            continue;
667
 
668
        target = makePath( baseDir, dirent->d_name);
669
        rv = stat( target, &fstat );
670
        if ( rv == 0 )
671
        {
672
            if ( fstat.st_mode & S_IFDIR )
673
            {
674
                DeleteOneDirectoryTree( target );
675
            }
676
            else
677
            {
678
                DeleteOneFile (target);
679
            }
680
        }
681
        free(target);
682
    }
683
    closedir(dir);
684
 
685
    /*
686
    **  Finally delete the directory
687
    */
688
    if ( verbose )
689
        fprintf(stderr, "Delete Directory: %s\n", baseDir);
690
 
691
    if ( rmdir (baseDir ) )
692
    {
693
        if ( verbose )
694
            fprintf(stderr, "Directory not deleted: %s\n", baseDir);
695
    }
696
}
697
 
698
/*----------------------------------------------------------------------------
699
** FUNCTION           : DeleteOneFile
700
**
701
** DESCRIPTION        : Delete a file
702
**                      Force it writable before deletion
703
**
704
** INPUTS             : path        - path to the file
705
**
706
** RETURNS            : 0           - OK (file deleted or not present)
707
**
708
----------------------------------------------------------------------------*/
709
 
710
int DeleteOneFile (char * dst )
711
{
712
	int rv;
713
    struct stat fstat;
714
    int result = 0;
715
 
716
    if ( verbose > 1)
717
        fprintf(stderr, "Delete File: %s\n", dst);
718
 
719
    rv = stat( dst, &fstat );
720
    if ( rv == 0 )
721
    {
722
        if ( verbose )
723
            fprintf(stderr, "Delete file: %s : Attr: 0%o\n", dst, fstat.st_mode);
724
        if ( !(fstat.st_mode & S_IWRITE) )
725
        {
726
            fstat.st_mode |= S_IWRITE;
727
            rv = chmod( dst, fstat.st_mode );
728
            if ( rv != 0 )
729
            {
730
                fprintf(stderr, "Warning: Attempt to allow write access: %s\n", dst);
731
            }
732
        }
733
 
734
        if ( unlink(dst) )
735
        {
736
            fprintf(stderr, "Warning: Did not remove file: %s\n", dst);
737
            result = 1;
738
        }
739
    }
740
    return result;
741
}
742
 
743
/*----------------------------------------------------------------------------
744
** FUNCTION           : makePath
745
**
746
** DESCRIPTION        : Create a path from two elements
747
**                      Allocate memory
748
**
749
**
750
** INPUTS             : base        - Part 1
751
**                      file        - Part 2
752
**
753
** RETURNS            :
754
**
755
----------------------------------------------------------------------------*/
756
 
757
char * makePath( char *base, char *path)
758
{
759
    int len1 = strlen(base);
760
    int len2 = strlen(path);
761
    char *data;
762
 
763
    data = (char *)malloc(len1 + len2 + 10);
764
    if ( data == NULL )
765
    {
766
        ErrorExit ("Malloc error:makePath","");
767
    }
768
 
769
    strcpy( data,base);
770
    strcpy( data + len1, "/");
771
    strcpy( data + len1 + 1, path);
772
 
773
    return data;
774
}
775
 
776
/*----------------------------------------------------------------------------
2085 dpurdie 777
** FUNCTION           : wildcmp
778
**
779
** DESCRIPTION        : Wildcard comparision
780
**
781
**
782
** INPUTS             : string          - String
783
**                      wild            - Wildcard template
784
**
785
** RETURNS            : TRUE - Match
786
**
787
----------------------------------------------------------------------------*/
788
 
789
int wildcmp(char *string, char *wild )
790
{
791
    char *cp, *mp;
792
    while ((*string) && (*wild != '*'))
793
    {
794
        if ((*wild != *string) && (*wild != '?'))
795
        {
796
            return 0;
797
        }
798
         wild++;
799
         string++;
800
    }
801
 
802
    while (*string)
803
    {
804
        if (*wild == '*')
805
        {
806
            if (!*++wild)
807
            {
808
                return 1;
809
            }
810
            mp = wild;
811
            cp = string+1;
812
        }
813
        else if ((*wild == *string) || (*wild == '?'))
814
        {
815
            wild++;
816
            string++;
817
        }
818
        else
819
        {
820
            wild = mp;
821
            string = cp++;
822
        }
823
    }
824
 
825
    while (*wild == '*')
826
    {
827
        wild++;
828
    }
829
 
830
    return !*wild;
831
}
832
 
833
 
834
 
835
 
836
/*----------------------------------------------------------------------------
2073 dpurdie 837
** FUNCTION           : ErrorExit
838
**
839
** DESCRIPTION        : Error processing
840
**                      Report an error and terminate process
841
**
842
**
843
** INPUTS             : lpszMessage     - Message to display
844
**
845
** RETURNS            : Does't return
846
**                      Will exit with bad code
847
**
848
----------------------------------------------------------------------------*/
849
 
850
void ErrorExit (char * lpszMessage, char * lpszMessage2)
851
{ 
2075 dpurdie 852
   fprintf(stderr, "JatsFileUtil:Error: %s%s\n", lpszMessage,lpszMessage2);
2073 dpurdie 853
   fflush(stderr) ;
854
   exit(-1);
855
} 
856