/****************************************************************************** * * rmv.lbl - remove Pick tape labels * * Module %M% Version %I% Date %H% * * (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved * This is unpublished proprietary source code of Ardent Software Inc. * The copyright notice above does not evidence any actual or intended * publication of such source code. * ******************************************************************************* * * Maintenence log - insert most recent change descriptions at top * * Date.... GTAR# WHO Description......................................... * 10/22/98 23801 SAP Change company name to Ardent * 10/14/98 23801 SAP Change copyrights. * 11/13/96 18242 DTM Code cleanup (nt) * 11/11/96 18242 DTM Code cleanup * 04/22/96 18242 DTM Code Cleanup, Phase I * 08/10/92 10004 TMC define __ISMAIN__ * 10/04/90 7207 JSM Added GENMSG logic * 08/01/90 7207 JSM Message text changes * 05/30/90 7140 TMC arg count > 1 in while not just argc-- * ******************************************************************************/ #define __MODULE__ "%M%" #define __SCCSID__ "%I%" #ifdef ARDENT #include "uv.h" #include FCNTL_H #else #include #include #endif #define GENMSG(xxxx) ( ( (xxxx) > lblmax ) ?\ ( sprintf(defmsg,"Message[LBL%04d]\n",(xxxx)), defmsg ) :\ ( lblmsg[(xxxx-1)] != 0 ?\ lblmsg[(xxxx-1)] :\ ( sprintf(defmsg,"Message[LBL%04d]\n",(xxxx)),\ defmsg ))) extern void initmsg(); static int lblmax = 0; static char **lblmsg = 0; static char defmsg[17]; #ifndef MSWIN EXTERN int strncmp(); EXTERN int atoi(); EXTERN int close(); EXTERN char *mktemp(); #endif #ifndef ARDENT #define DMAX 7 static char *dmsgs[DMAX] = { "help", "Usage: rmv.lbl {-iinputfile} {-ooutputfile} {-s#}\n", "\"rmv.lbl.c\" must be modified to handle labels greater than 16k\n", "Unable to open file \"%s\"\n", "Unable to create file \"%s\"\n", "Unable to read label from input file\n", "Processing complete.\n" }; #endif #define UC (unsigned char) int main(argc,argv) int argc; char *argv[]; { /* set default for input file, output file and label size */ int infile = 0,outfile = 1,lblsiz = 80; int lblcnt,len; int argno = 1; char buffer[16384]; #ifndef ARDENT int x; #endif #ifdef ARDENT (void) initmsg("LBL",&lblmsg,&lblmax); #else lblmsg=(char**)malloc(lblmsg,DMAX*sizeof(char*)); for(x=0; x<=DMAX-1; x++) (lblmsg)[x] = dmsgs[x]; lblmax = DMAX; #endif if (argc>4 || (argc>1 && !strcmp(argv[1],GENMSG(1)))) { /* usgage error */ fprintf(stderr,GENMSG(2)); exit(1); } while(argc-- > 1) { if (!strncmp(argv[argno],"-s",2)) { lblsiz = atoi((argv[argno]+2)); if (lblsiz > 16384) { /* label error */ fprintf(stderr,GENMSG(3)); exit(2); } } else if (!strncmp(argv[argno],"-i",2)) { if((infile = open(argv[argno]+2,O_RDONLY)) == -1) { /* cant open file */ fprintf(stderr,GENMSG(4),argv[argno]+2); exit(3); } } else if (!strncmp(argv[argno],"-o",2)) { outfile = open(argv[argno]+2,O_RDWR|O_CREAT|O_EXCL,0666); if(outfile == -1) { /* cant create file */ fprintf(stderr,GENMSG(5),argv[argno]+2); exit(4); } } argno++; } /* try to read in label */ lblcnt = read(infile,buffer,lblsiz); if (lblcnt <= 0) { /* read error */ fprintf(stderr,GENMSG(6)); exit(5); } /* check for Pick tape label */ /* and write to output file if data is not a Pick tape label */ if(!((UC buffer[0] == UC '\377') && (UC buffer[1] == UC 'L'))) { write(outfile,buffer,lblcnt); } /* write out the rest of the file */ while ((len = read(infile,buffer,512)) > 0) { write(outfile,buffer,len); } /* processing complete */ fprintf(stderr,GENMSG(7)); close(outfile); exit(0); return(0); }