/* ARC - Archive utility - ARCADD (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" 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 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 *alloc(), *realloc(); /* memory allocators */ int m, n; /* indices */ unsigned int coreleft(); /* remaining memory reporter */ if(num<1) /* if no files named */ { num = 1; /* then fake one */ arg[0] = "*.*"; /* add everything */ } 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); 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); 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); } 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 */ }