ewilts%Ins.MRC.AdhocNet.CA%Stasis.MRC.AdhocNet.CA%UNCAEDU.@CORNELLC.CCS.CORNELL.EDU.BITNET (Ed Wilts) (06/24/88)
$Part09: $ File_is="ARCMATCH.C" $ Check_Sum_is=929563875 $ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY Vstatic char *RCSid = "$Header: arcmatch.c,v 1.2 86/07/15 07:53:42 turner Exp $" X; X X/* X * $Log:`009arcmatch.c,v $ X * Hack-attack 1.3 86/12/20 01:23:45 wilhite@usceast.uucp X * `009Bludgeoned into submission for VAX 11/780 BSD4.2 X *`009(ugly code, but fewer core dumps) X * X * Revision 1.2 86/07/15 07:53:42 turner X * X * X * Revision 1.1 86/06/26 15:00:34 turner X * initial version X * X * X */ X X/* ARC - Archive utility - ARCMATCH X X$define(tag,$$segment(@1,$$index(@1,=)+1))# X$define(version,Version $tag( XTED_VERSION DB =2.17), created on $tag( XTED_DATE DB =12/17/85) at $tag( XTED_TIME DB =20:32:18))# X$undefine(tag)# X $version X X(C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED X X By: Thom Henderson X X Description: X This file contains service routines needed to maintain an archive. X X Language: X Computer Innovations Optimizing C86 X*/ X#include <stdio.h> X#include "arc.h" X XINT match(n,t) /* test name against template */ Xchar *n; /* name to test */ Xchar *t; /* template to test against */ X{ X X#if MSDOS X upper(n); upper(t); /* avoid case problems */ X#endif X#if VAXC X upper(n); upper(t); /* avoid case problems */ X#endif X X /* first match name part */ X X while((*n && *n!='.') || (*t && *t!='.')) X { if(*n!=*t && *t!='?') /* match fail? */ X { if(*t!='*') /* wildcard fail? */ X return 0; /* then no match */ X else /* else jump over wildcard */ X { while(*n && *n!='.') X n++; X while(*t && *t!='.') X t++; X break; /* name part matches wildcard */ X } X } X else /* match good for this char */ X { n++; /* advance to next char */ X t++; X } X } X X if(*n && *n=='.') n++; /* skip extension delimiters */ X if(*t && *t=='.') t++; X X /* now match name part */ X X while(*n || *t) X { if(*n!=*t && *t!='?') /* match fail? */ X { if(*t!='*') /* wildcard fail? */ X return 0; /* then no match */ X else return 1; /* else good enough */ X } X else /* match good for this char */ X { n++; /* advance to next char */ X t++; X } X } X X return 1; /* match worked */ X} X XINT rempath(nargs,arg) /* remove paths from filenames */ XINT nargs; /* number of names */ Xchar *arg[]; /* pointers to names */ X{ X char *i, *rindex(); /* string index, reverse indexer */ X INT n; /* index */ X X for(n=0; n<nargs; n++) /* for each supplied name */ X { if(!(i=rindex(arg[n],'\\'))) /* search for end of path */ X if(!(i=rindex(arg[n],'/'))) X i=rindex(arg[n],':'); X if(i) /* if path was found */ X arg[n] = i+1; /* then skip it */ X } X} X $ GoSub Convert_File $ File_is="ARCMISC.C" $ Check_Sum_is=845488246 $ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY X#include <stdio.h> X#include "arc.h" X#ifdef VMS X#include "dir.h" X#endif X X/*`009split up a file name (subroutine for makefnam) X * X * Hack-attack 1.3 86/12/20 01:23:45 wilhite@usceast.uucp X * `009Bludgeoned into submission for VAX 11/780 BSD4.2 X *`009(ugly code, but fewer core dumps) X*/ X X#ifndef VMS Xstatic INT _makefn(source,dest) Xunsigned char *source; Xunsigned char *dest; X{ X INT j; X X setmem (dest, 17, 0);`009/* clear result field */ X if (strlen (source) > 1 && source[1] == ':') X`009for (j = 0; j < 2;) X`009 dest[j++] = *source++; X for (j = 3; *source && *source != '.'; ++source) X`009if (j < 11) X`009 dest[j++] = *source; X for (j = 12; *source; ++source) X`009if (j < 16) X`009 dest[j++] = *source; X} X#endif X X/*`009make a file name using a template X*/ X Xchar *makefnam(rawfn,template,result) Xunsigned char *rawfn;`009`009`009/* the original file name */ Xunsigned char *template;`009`009/* the template data */ Xunsigned char *result;`009`009`009/* where to place the result */ X{ X#ifdef VMS X unsigned char et[STRLEN]; X X INT parsedir(); X#else X unsigned char et[17],er[17]; X#endif X X X#ifdef VMS X`009strcpy(et,rawfn);`009`009/* Copy file name */ V`009parsedir(et,template,PARSE_NODE|PARSE_DEVICE|PARSE_DIRECTORY|PARSE_NAME|PAR XSE_TYPE); X`009strcpy(result, et);`009`009/* Copy new filename back */ X#else X _makefn(template,et); X _makefn(rawfn,er); X *result=0;`009`009`009/* assure no data */ X strcat(result,er[0]?er:et); X strcat(result,er[3]?er+3:et+3); X strcat(result,er[12]?er+12:et+12); X#endif X return ((char *)&result[0]); X} X XINT freedir(dirs) Xregister struct direct **dirs; X{ X`009register INT ii; X X`009if(dirs == (struct direct **)0) X`009`009return(-1); X`009for(ii = 0; dirs[ii] != (struct direct *)0; ii++) X`009`009free(dirs[ii]); X`009free(dirs); X`009return(0); X} X X#if MSDOS X#include <dir.h> X XINT alphasort(dirptr1, dirptr2) Xstruct direct **dirptr1, **dirptr2; X{ X`009return(strcmp((*dirptr1)->d_name, (*dirptr2)->d_name)); X} X X#endif X $ GoSub Convert_File $ Goto Part10