Imported Upstream version 2.4
[debian/cpmtools] / cpmrm.c
1 /* #includes */ /*{{{C}}}*//*{{{*/
2 #include <ctype.h>
3 #include <errno.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include "config.h"
8 #include "getopt.h"
9 #include "cpmfs.h"
10 /*}}}*/
11
12 const char cmd[]="cpmrm";
13
14 int main(int argc, char *argv[]) /*{{{*/
15 {
16   /* variables */ /*{{{*/
17   const char *err;
18   const char *image;
19   const char *format=FORMAT;
20   const char *devopts=NULL;
21   int c,i,usage=0,exitcode=0;
22   struct cpmSuperBlock drive;
23   struct cpmInode root;
24   int gargc;
25   char **gargv;
26   /*}}}*/
27
28   /* parse options */ /*{{{*/
29   while ((c=getopt(argc,argv,"T:f:h?"))!=EOF) switch(c)
30   {
31     case 'T': devopts=optarg; break;
32     case 'f': format=optarg; break;
33     case 'h':
34     case '?': usage=1; break;
35   }
36
37   if (optind>=(argc-1)) usage=1;
38   else image=argv[optind];
39
40   if (usage)
41   {
42     fprintf(stderr,"Usage: %s [-f format] [-T dsktype] image pattern ...\n",cmd);
43     exit(1);
44   }
45   /*}}}*/
46   /* open image */ /*{{{*/
47   if ((err=Device_open(&drive.dev, image, O_RDWR, devopts)))
48   {
49     fprintf(stderr,"%s: can not open %s (%s)\n",cmd,image,err);
50     exit(1);
51   }
52   cpmReadSuper(&drive,&root,format);
53   /*}}}*/
54   cpmglob(optind,argc,argv,&root,&gargc,&gargv);
55   for (i=0; i<gargc; ++i)
56   {
57     if (cpmUnlink(&root,gargv[i])==-1)
58     {
59       fprintf(stderr,"%s: can not erase %s: %s\n",cmd,gargv[i],boo);
60       exitcode=1;
61     }
62   }
63   exit(exitcode);
64 }
65 /*}}}*/