/* -*-c,save-*- */ /* * luextrct.c - LU extracters. * Robert Heller. Created: Sat Nov 8, 1986 18:31:23.19 * Last Mod: * * (c) Copyright 1986 by Robert Heller * All Rights Reserved * * */ #include /* STD I/O defs */ #include /* char type defs */ #include "ludef.h" /* ludefs */ #include "luvars.h" /* lu variables */ lu_extract(argcc,argvv) FAST int *argcc; FAST char ***argvv; { FAST int out_fd; LOCAL char outname[20]; FAST char *p, *q; FAST int i,wildp,nw,j; char *strchr(); long int offset; LOCAL char sectbuff[SECTSIZE]; FAST int nsect,isect; #ifdef CRCCHECK unsigned short int crc,calcrc(); #endif if (!lu_openp) { fprintf(stderr,"lu: library file not open!\n"); while (*argcc > 0 && ***argvv != '-') { *argcc -= 1; *argvv += 1; } return; } nw = 0; i = 1; while (*argcc > 0 && ***argvv != '-') { p = **argvv; if (strchr(p,'?') != NULL || strchr(p,'*') != NULL) wildp = TRUE; if (!wildp) { *argcc -= 1; *argvv += 1; nw = 0; i = 1; } else nw++; if ((q = strchr(p,':')) != NULL) p = q+1; for (; i= lu_slots) { if (wildp) { if (nw == 0) fprintf(stderr,"lu: no files matched: %s\n",p); *argcc -= 1; *argvv += 1; nw = 0; i = 1; } else fprintf(stderr,"lu: file not in library: %s\n",p); } else { p = lu_dire[i].lu_name; q = outname; for (j=0; j<8; j++, p++) if (*p != ' ') *q++ = *p; *q++ = '.'; for (j=0; j<3; j++, p++) if (*p != ' ') *q++ = *p; *q++ = '\0'; offset = lu_dire[i].lu_off; offset *= SECTSIZE; sprintf(sectbuff,"lu: output file (%s) open error",outname); out_fd = xcreat(outname,0777); #ifdef CRCCHECK crc = 0; #endif if (out_fd == FAILURE) { perror(sectbuff); continue; } lseek(lu_fd,offset,0); for (isect = 0; isect < lu_dire[i].lu_len; isect++) { nsect = read(lu_fd,sectbuff,SECTSIZE); if (nsect != SECTSIZE) { perror("lu: library read error"); close(out_fd); unlink(outname); return; } nsect = write(out_fd,sectbuff,SECTSIZE); if (nsect != SECTSIZE) { perror("lu: outfile write error"); fprintf(stderr,"lu: filename: %s\n",outname); close(out_fd); unlink(outname); goto next_file; } #ifdef CRCCHECK crc = calcrc(crc,sectbuff,SECTSIZE); #endif } #ifdef CRCCHECK if (crc != lu_dire[i].lu_crc && lu_dire[i].lu_crc != 0) fprintf(stderr,"lu: crc failure, file may be corupt\n"); #endif printf("%s extracted\n",outname); close(out_fd); } next_file: if (wildp) i++; } } lu_eusq(argcc,argvv) FAST int *argcc; FAST char ***argvv; { FAST int out_fd; LOCAL char outname[20],realnm[20]; FAST char *p, *q; FAST int i,wildp,nw,j; char *strchr(); long int offset; LOCAL char sectbuff[SECTSIZE]; FAST int nsect,isect; #ifdef CRCCHECK unsigned short int crc,calcrc(); #endif if (!lu_openp) { fprintf(stderr,"lu: library file not open!\n"); while (*argcc > 0 && ***argvv != '-') { *argcc -= 1; *argvv += 1; } return; } nw = 0; i = 1; while (*argcc > 0 && ***argvv != '-') { p = **argvv; if (strchr(p,'?') != NULL || strchr(p,'*') != NULL) wildp = TRUE; if (!wildp) { *argcc -= 1; *argvv += 1; nw = 0; i = 1; } else nw++; if ((q = strchr(p,':')) != NULL) p = q+1; for (; i= lu_slots) { if (wildp) { if (nw == 0) fprintf(stderr,"lu: no files matched: %s\n",p); *argcc -= 1; *argvv += 1; nw = 0; i = 1; } else fprintf(stderr,"lu: file not in library: %s\n",p); } else { p = lu_dire[i].lu_name; q = realnm; for (j=0; j<8; j++, p++) if (*p != ' ') *q++ = *p; *q++ = '.'; for (j=0; j<3; j++, p++) if (*p != ' ') *q++ = *p; *q++ = '\0'; strcpy(outname,mktemp("sqxxxxxx")); offset = lu_dire[i].lu_off; offset *= SECTSIZE; sprintf(sectbuff,"lu: output file (%s) open error",outname); out_fd = xcreat(outname,0777); #ifdef CRCCHECK crc = 0; #endif if (out_fd == FAILURE) { perror(sectbuff); continue; } lseek(lu_fd,offset,0); for (isect = 0; isect < lu_dire[i].lu_len; isect++) { nsect = read(lu_fd,sectbuff,SECTSIZE); if (nsect != SECTSIZE) { perror("lu: library read error"); close(out_fd); unlink(outname); return; } nsect = write(out_fd,sectbuff,SECTSIZE); if (nsect != SECTSIZE) { perror("lu: outfile write error"); fprintf(stderr,"lu: filename: %s\n",outname); close(out_fd); unlink(outname); goto next_file; } #ifdef CRCCHECK crc = calcrc(crc,sectbuff,SECTSIZE); #endif } #ifdef CRCCHECK if (crc != lu_dire[i].lu_crc && lu_dire[i].lu_crc != 0) fprintf(stderr,"lu: crc failure, file may be corupt\n"); #endif close(out_fd); if (!unsqueeze(outname)) rename(outname,realnm); else unlink(outname); printf("%s extracted\n",realnm); } next_file: if (wildp) i++; } }