X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=cpmcp.c;h=bf7c7262d6bd66c9a77a452eabba37e2a0207418;hb=e7957d2038ed5ba72efec92aff70352064988d13;hp=61dc65b6fd69621dc79ddf3e9277747ee5308aa8;hpb=32087c67d53a8f8058b359388f23e2dbc9436d54;p=debian%2Fcpmtools diff --git a/cpmcp.c b/cpmcp.c index 61dc65b..bf7c726 100644 --- a/cpmcp.c +++ b/cpmcp.c @@ -1,29 +1,23 @@ /* #includes */ /*{{{C}}}*//*{{{*/ -#undef _POSIX_SOURCE -#define _POSIX_SOURCE 1 -#undef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 2 - -#ifdef DMALLOC -#include "dmalloc.h" -#endif +#include "config.h" #include +#include #include #include #include #include -#include #include #include -#include "config.h" +#include -#include "getopt.h" +#include "getopt_.h" #include "cpmfs.h" /*}}}*/ const char cmd[]="cpmcp"; static int text=0; +static int preserve=0; /** * Return the user number. @@ -33,7 +27,7 @@ static int text=0; static int userNumber(const char *s) /*{{{*/ { if (isdigit(*s) && *(s+1)==':') return (*s-'0'); - if (isdigit(*s) && isdigit(*(s+1)) && *(s+2)==':') return (10*(*s-'0')+(*(s+1))); + if (isdigit(*s) && isdigit(*(s+1)) && *(s+2)==':') return (10*(*s-'0')+(*(s+1)-'0')); return -1; } /*}}}*/ @@ -50,64 +44,73 @@ static int cpmToUnix(const struct cpmInode *root, const char *src, const char *d struct cpmInode ino; int exitcode=0; - if (cpmNamei(root,src,&ino)==-1) { fprintf(stderr,"%s: can not open %s: %s\n",cmd,src,boo); exitcode=1; } - else + if (cpmNamei(root,src,&ino)==-1) { fprintf(stderr,"%s: can not open `%s': %s\n",cmd,src,boo); exitcode=1; } + else + { + struct cpmFile file; + FILE *ufp; + + cpmOpen(&ino,&file,O_RDONLY); + if ((ufp=fopen(dest,text ? "w" : "wb"))==(FILE*)0) { fprintf(stderr,"%s: can not create %s: %s\n",cmd,dest,strerror(errno)); exitcode=1; } + else + { + int crpending=0; + int ohno=0; + ssize_t res; + char buf[4096]; + + while ((res=cpmRead(&file,buf,sizeof(buf)))>0) { - struct cpmFile file; - FILE *ufp; + int j; - cpmOpen(&ino,&file,O_RDONLY); - if ((ufp=fopen(dest,text ? "w" : "wb"))==(FILE*)0) { fprintf(stderr,"%s: can not create %s: %s\n",cmd,dest,strerror(errno)); exitcode=1; } - else + for (j=0; j=argc) usage(); - image=argv[optind]; + image=argv[optind++]; - if (userNumber(argv[optind+1])>=0) /* cpm -> unix? */ /*{{{*/ + if (userNumber(argv[optind])>=0) /* cpm -> unix? */ /*{{{*/ { int i; struct stat statbuf; - for (i=optind+1; i<(argc-1); ++i) if (userNumber(argv[i])==-1) usage(); - todir=((argc-optind-1)>2); + for (i=optind; i<(argc-1); ++i) if (userNumber(argv[i])==-1) usage(); + todir=((argc-optind)>2); if (stat(argv[argc-1],&statbuf)==-1) { if (todir) usage(); } else if (S_ISDIR(statbuf.st_mode)) todir=1; else if (todir) usage(); readcpm=1; @@ -156,8 +165,8 @@ int main(int argc, char *argv[]) int i; todir=0; - for (i=optind+1; i<(argc-1); ++i) if (userNumber(argv[i])>=0) usage(); - if ((argc-optind-1)>2 && *(strchr(argv[argc-1],':')+1)!='\0') usage(); + for (i=optind; i<(argc-1); ++i) if (userNumber(argv[i])>=0) usage(); + if ((argc-optind)>2 && *(strchr(argv[argc-1],':')+1)!='\0') usage(); if (*(strchr(argv[argc-1],':')+1)=='\0') todir=1; readcpm=0; } @@ -167,64 +176,39 @@ int main(int argc, char *argv[]) /* open image file */ /*{{{*/ if ((err=Device_open(&super.dev,image,readcpm ? O_RDONLY : O_RDWR, devopts))) { - fprintf(stderr,"%s: can not open %s (%s)\n",cmd,image,err); + fprintf(stderr,"%s: cannot open %s (%s)\n",cmd,image,err); + exit(1); + } + if (cpmReadSuper(&super,&root,format,uppercase)==-1) + { + fprintf(stderr,"%s: cannot read superblock (%s)\n",cmd,boo); exit(1); } - cpmReadSuper(&super,&root,format); /*}}}*/ if (readcpm) /* copy from CP/M to UNIX */ /*{{{*/ { - int i,count,total=0; - char src[2+8+1+3+1]; - struct cpmFile dir; - struct cpmDirent dirent; - - /* expand pattern and check if we try to copy multiple files to a file */ /*{{{*/ - for (i=optind+1,total=0; i<(argc-1); ++i) - { - cpmOpendir(&root,&dir); - count=0; - while (cpmReaddir(&dir,&dirent)) if (match(dirent.name,argv[i])) ++count; - if (count==0) ++total; else total+=count; - cpmClose(&dir); - } - if (total>1 && !todir) usage(); - /*}}}*/ - - for (i=optind+1; i<(argc-1); ++i) + int i; + char *last=argv[argc-1]; + + cpmglob(optind,argc-1,argv,&root,&gargc,&gargv); + /* trying to copy multiple files to a file? */ + if (gargc>1 && !todir) usage(); + for (i=0; i