static char *RCSid = "$Header: arcadd.c,v 1.2 86/07/15 07:52:37 turner Exp $"; /* * $Log: arcadd.c,v $ * Hack-attack 1.3 86/12/20 01:23:45 wilhite@usceast.uucp * Bludgeoned into submission for VAX 11/780 BSD4.2 * (ugly code, but fewer core dumps) * * Revision 1.2 86/07/15 07:52:37 turner * * * Revision 1.1 86/06/26 14:59:37 turner * initial version * * */ /* ARC - Archive utility - ARCADD $define(tag,$$segment(@1,$$index(@1,=)+1))# $define(version,Version $tag( TED_VERSION DB =3.39), created on $tag( TED_DATE DB =02/05/86) at $tag( TED_TIME DB =22:21:53))# $undefine(tag)# $version (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED By: Thom Henderson Description: This file contains the routines used to add files to an archive. Language: Computer Innovations Optimizing C86 */ #include #include "arc.h" #ifdef VAXC #include "dir.h" #endif VAXC INT addarc(num,arg,move,update,fresh) /* add files to archive */ INT num; /* number of arguments */ char *arg[]; /* pointers to arguments */ INT move; /* true if moving file */ INT update; /* true if updating */ INT fresh; /* true if freshening */ { char *d, *dir(); /* directory junk */ char *NameList; /* Any pointer. Used to pass file names around */ char buf[STRLEN]; /* pathname buffer */ char **path = NULL; /* pointer to pointers to paths */ char **name = NULL; /* pointer to pointers to names */ INT nfiles = 0; /* number of files in lists */ INT notemp; /* true until a template works */ INT nowork = 1; /* true until files are added */ char *i, *rindex(); /* string indexing junk */ char *malloc(), *realloc(); /* memory allocators */ INT m, n; /* indices */ unsigned INT coreleft(); /* remaining memory reporter */ INT addbunch(); if(num<1) /* if no files named */ { num = 1; /* then fake one */ arg[0] = "*.*"; /* add everything */ printf("%%ARC-I-NOSPEC, File not specfied. Defaulting to *.*\n"); } for(n=0; n0) { d = path[n]; path[n] = path[m]; path[m] = d; d = name[n]; name[n] = name[m]; name[m] = d; } } } for(n=0; n=0) break; /* found our spot */ writehdr(&ohdr,new); /* entry preceeds update; keep it */ filecopy(arc,new,ohdr.size); starts = ftell(arc); /* now where are we? */ } if(upd) /* if an update */ { if(note) { printf("Updating file: %-12s ",name); fflush(stdout);} fseek(arc,ohdr.size,1); } else if(fresh) /* else if freshening */ { fseek(arc,starts,0); /* then do not add files */ fclose(f); return; } else /* else adding a new file */ { if(note) { printf("Adding file: %-12s ",name); fflush(stdout);} fseek(arc,starts,0); /* reset for next time */ } } else /* no existing archive */ { if(fresh) /* cannot freshen nothing */ { fclose(f); return; } else if(note) /* else adding a file */ { printf("Adding file: %-12s ",name); fflush(stdout);} } starts = ftell(new); /* note where header goes */ hdrver = ARCVER; /* anything but end marker */ writehdr(&nhdr,new); /* write out header skeleton */ pack(f,new,&nhdr); /* pack file into archive */ fseek(new,starts,0); /* move back to header skeleton */ writehdr(&nhdr,new); /* write out real header */ fseek(new,nhdr.size,1); /* skip over data to next header */ fclose(f); /* all done with the file */ }