home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * arcmisc.c 1.1
- *
- * Author: Thom Henderson
- * Original System V port: Mike Stump
- * Enhancements, Bug fixes, and cleanup: Chris Seaman
- * Date: Fri Mar 20 09:57:02 1987
- * Last Mod. 3/21/87
- *
- */
-
- /*
- * ARC - Archive utility - ARCMISC
- *
- * Description:
- * This file contains miscellaneous routines for string
- * management, file management, and program control.
- */
-
- #include "arc.h"
- #include <ctype.h>
-
- INT rempath(nargs,arg) /* remove paths from filenames */
- INT nargs; /* number of names */
- char *arg[]; /* pointers to names */
- {
- char *i, *strrchr(); /* string index, reverse indexer */
- INT n; /* index */
-
- for(n=0; n<nargs; n++) /* for each supplied name */
- {
- i=strrchr(arg[n],'/'); /* search for end of path */
- if(i) /* if path was found */
- arg[n] = i+1; /* then skip it */
- }
- }
-
- /* make a file name using a template */
- char *makefnam(rawfn,template,result)
- char *rawfn; /* the original file name */
- char *template; /* the template data */
- char *result; /* where to place the result */
- {
- char *arc_ext; /* possible existing extension */
- char *i, *strrchr(); /* string indexing stuff */
-
- arc_ext = ".arc";
- i = strrchr(rawfn,'.'); /* strip 'arc' extension from filename */
- if (i)
- *i = '\0';
-
- strncpy(result,rawfn,10); /* rebuild it using supplied template */
- strcat(result,template);
- return result;
- }
-
- /* convert a string to upper case */
- upper(s)
- register char *s;
- {
- while (*s = toupper(*s)) ++s;
- }
-
- setmem(dest,size,c)
- char *dest,c;
- INT size;
- {
- register i;
-
- for (i = 0; i < size; dest[i] = c, i++);
- }
-
- abort(s,arg1,arg2,arg3) /* something went wrong...QUIT!! */
- char *s;
- {
- char tname1[STRLEN], tname2[STRLEN];
-
- sprintf(tname1,"%s.crn",arctemp);
- sprintf(tname2,"%s.cvt",arctemp);
-
- unlink(bakname); /* remove all possible temp files */
- unlink(newname);
- unlink(tname1);
- unlink(tname2);
-
- fprintf(stderr,"arc: "); /* explain things to the user */
- fprintf(stderr,s,arg1,arg2,arg3);
- fprintf(stderr,"\n");
- exit(1); /* quit */
- }
-
- #ifndef CPM68K
- rename(o, n)
- char *o, *n;
- {
- char ofcb[36], nfcb[36];
- struct {
- char *f;
- char *s;
- } as;
-
- as.f = ofcb;
- as.s = o;
- bdosp(70,&as); /* get fcb for old name */
- as.f = nfcb;
- as.s = n;
- bdosp(70,&as); /* get correct format of newname */
- strcpy(&ofcb[16],nfcb);
- bdosp(23,ofcb);
- return 0;
- /*
- printf("rename not implemented. Archive name is %s\n",o);
- return(link(o, n) || unlink(o));
- */
- }
- #endif
-
- makenames(rawfn)
- char *rawfn;
- {
- char pathtemp[STRLEN]; /* temporary path holder */
- char nametemp[STRLEN]; /* temporary arcname holder */
- char *buf; /* temporary pointer */
- char *strrchr(); /* string indexing junk */
- long getpid(); /* process id function */
-
- strcpy(pathtemp,rawfn);
- if (buf = strrchr(rawfn,'/')) /* if names are part of paths */
- { /* lots to do */
- buf++;
- pathtemp[strlen(rawfn)-strlen(buf)] = 0;
- makefnam(buf,".arc",nametemp); /* make 'arcname' */
- makefnam(buf,".bak",nametemp); /* make 'bakname' */
- sprintf(arcname,"%s%s",pathtemp,nametemp);
- sprintf(bakname,"%s%s",pathtemp,nametemp);
- sprintf(arctemp,"%s.A%ld",pathtemp,getpid());
- }
- else /* not so much to do */
- {
- makefnam(rawfn,".arc",arcname);
- makefnam(rawfn,".bak",bakname);
- sprintf(arctemp,"Arc%ld",getpid());
- }
- sprintf(newname,"%s.arc",arctemp);
- }
-
- onintr() /* SIGNAL was caught */
- {
- abort("User Requested Abort");
- }
-
- /*
- * This function sorts the command line file arguments. Needed since
- * the add, update, etc., function does no sorting, and could result in
- * multiple archive entries for the same file name.
- */
- sortarg(num,arg) /* sort argument list, remove dups */
- int num;
- char *arg[];
- {
- char *temp; /* temporary pointer */
- INT top, seek; /* placeholders for sorting */
- INT dups; /* how many duplicates are there */
- char *strrchr(), *i; /* string indexing stuff */
- char *buf1, *buf2; /* pointers for strcmp to use */
-
- /* sort the arguments, ignoring pathnames */
-
- dups = 0;
- for (top = 0; top<(num-1); top++)
- for (seek=top+1; seek<num; seek++) {
- buf1 = arg[top];
- if (i = strrchr(arg[top],'/'))
- buf1 = i + 1;
-
- buf2 = arg[seek];
- if (i = strrchr(arg[seek],'/'))
- buf2 = i + 1;
-
- if (strcmp(buf1,buf2) > 0) {
- temp = arg[top];
- arg[top] = arg[seek];
- arg[seek] = temp;
- }
- }
-
- /* find any occurences of 'arcname', and remove them */
-
- for (top=0; top<num; top++) {
- while (strcmp(arg[top],arcname) == 0) {
- for (seek=top; seek<num; seek++)
- arg[seek] = arg[seek + 1];
- arg[--num] = '\0';
- dups++;
- }
- }
- /* find any other duplicate arguments (ignoring pathnames), */
- /* and remove the second and subsequent occurences */
-
- for (top = 0;top < num-1;top++) {
- buf1 = arg[top];
- buf2 = arg[top + 1];
- if (i = strrchr(arg[top],'/'))
- buf1 = i + 1;
- if (i = strrchr(arg[top + 1],'/'))
- buf2 = i + 1;
- while (strcmp(buf1,buf2) == 0) {
- for (seek=top+1; seek<num; seek++)
- arg[seek] = arg[seek+1];
- arg[--num] = '\0';
- buf2 = arg[top + 1];
- if (i = strrchr(arg[top + 1],'/'))
- buf2 = i + 1;
- dups++;
- }
- }
- return(dups); /* tell main() how many we found */
- }
-