summaryrefslogtreecommitdiff
path: root/support/tiny_c2l/cvt_rm.c
blob: 48f0acbf8f8cf8e778fc7d136a3c8b29a01a34e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*\c
 * cvt_rm.c - simple implementation of rm to delete multiple files.
 * This file only deletes all files supplied by the command line; the
 * return value is always 0/1 (success). 
 * 
 * If the first character of an argument is `+', this argument is
 * considered to be a file containing  a list of files to delete. This
 * feature is added to avoid too long command lines for M\$DOG \& Co. 
 *
 * For VMS, files beginning with `sys$share:' are not deleted; (this
 * entry is used for sys$share:vaxcrtl, and it should not be deleted!!)
 */

#include <stdio.h>
#include <stdlib.h>
#if VMS
#  include <string.h>
#  include <descrip.h>
   int delete_file(char *file,int all);
   int lib$delete_file();
#else
#  define delete_file(file,all) unlink(file)
#endif

main(int argc, char **argv)
{
   int i;
   FILE *input;
   char *buffer,*ptr,*ptr1;
   
   buffer=(char *)malloc(1024);
   for(i=1;i<argc;i++){
      if(*argv[i]=='+' || *argv[i]=='@'){
         strcpy(buffer,argv[i]+1);
#if VMS
         for(ptr=buffer;*ptr;ptr++)if(*ptr==';')*ptr=0;   /* no version number!! */
#endif
         if((input=fopen(buffer,"r"))!=NULL){
            while(fscanf(input,"%s",buffer)==1)delete_file(buffer,1);
            fclose(input);
            if(*argv[i]=='+'){
               strcpy(buffer,argv[i]+1);
               delete_file(buffer,1);
            }
         }
      }
      else{
#if VMS
         for(ptr=argv[i],ptr1=buffer;*ptr;ptr++){
            if(*ptr==','){
               *ptr1=0;
               delete_file(buffer,0);
               ptr1=buffer;
            }
            else
               *ptr1++= *ptr;
         }
         if(ptr1>buffer){
            *ptr1=0;
            delete_file(buffer,0);
         }
#else
         delete_file(argv[i],0);
#endif
     }
   }
#if VMS
   return 1;
#else
   return 0;
#endif
}

#if VMS
int delete_file(char *file,int all)
{
   $DESCRIPTOR(d_file,"");
   char *ptr,*ptr1,filebuffer[256];

   if(!strncmp("sys$share:",file,10))return;   /* don't remove shared libraries from opt file! */
   strcpy(filebuffer,file);
   for(ptr=filebuffer;*ptr && *ptr++!='.';);
      /* for extensions .obj/obj_x, .exe/.exe_x or .opt/.opt_x use .obj*;*,
       * .exe*;* and .opt*;* */
   if(*ptr=='o' && ((*(ptr+1)=='b' && *(ptr+2)=='j')
       || (*(ptr+1)=='p' && *(ptr+2)=='t'))
       || *ptr=='e' && *(ptr+1)=='x' && *(ptr+2)=='e'){
      *(ptr+3)='*';
      *(ptr+4)=0;
      for(ptr1=file;*ptr1 && *ptr1!=';';ptr1++);
      if(*ptr1)all=1;
   }
   if(all){
      for(ptr=filebuffer;*ptr && *ptr!=';';ptr++);
      *ptr++=';';
      *ptr++='*';
      *ptr=0;
   }
   d_file.dsc$w_length=strlen(filebuffer);
   d_file.dsc$a_pointer=filebuffer;
   return lib$delete_file(&d_file);
}
#endif