Path: utzoo!utgpu!watmath!uunet!xanth!galaxia!lazlo!gizzmo!fthood!egray From: egray@fthood.UUCP Newsgroups: unix-pc.sources Subject: Arc v5.21 (6 of 6) Message-ID: <6800100@fthood> Date: 2 Jan 89 23:54:00 GMT Lines: 827 Nf-ID: #N:fthood:6800100:000:21095 Nf-From: fthood.UUCP!egray Jan 2 17:54:00 1989 This is part 6 (of 6) to the Arc v5.21 distribution package. Emmet P. Gray US Army, HQ III Corps & Fort Hood ...!uunet!uiucuxc!fthood!egray Attn: AFZF-DE-ENV Directorate of Engineering & Housing Environmental Management Office Fort Hood, TX 76544-5057 ------------------------------------------------------------------------------ #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # marc.c # memset.c # rename.c # scandir.3 # scandir.c # tmclock.c # utimes.c # This archive created: Sun Jan 1 12:48:37 1989 export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'marc.c'" '(9440 characters)' if test -f 'marc.c' then echo shar: "will not over-write existing file 'marc.c'" else sed 's/^X//' << \SHAR_EOF > 'marc.c' X/* X * $Header: marc.c,v 1.5 88/08/01 14:19:19 hyc Exp $ X */ X X/* MARC - Archive merge utility X X Version 5.21, created on 04/22/87 at 15:05:10 X X(C) COPYRIGHT 1985-87 by System Enhancement Associates; ALL RIGHTS RESERVED X X By: Thom Henderson X X Description: X This program is used to "merge" archives. That is, to move X files from one archive to another with no data conversion. X Please refer to the ARC source for a description of archives X and archive formats. X X Instructions: X Run this program with no arguments for complete instructions. X X Language: X Computer Innovations Optimizing C86 X*/ X#include X#include "arc.h" X X#if UNIX X#include X#include X#endif X XFILE *src; /* source archive */ Xchar srcname[STRLEN]; /* source archive name */ X Xstatic char **lst; /* files list */ Xstatic int lnum; /* length of files list */ X X#ifdef LOCAL Xint unix_names = 0; X#endif /* LOCAL */ X X Xmain(nargs,arg) /* system entry point */ Xint nargs; /* number of arguments */ Xchar *arg[]; /* pointers to arguments */ X{ X char *makefnam(); /* filename fixup routine */ X char *calloc(); /* memory manager */ X char *envfind(); X#if !MTS X char *arctemp2, *mktemp(); /* temp file stuff */ X#endif X#if GEMDOS X void exitpause(); X#endif X int n; /* index */ X#if UNIX X struct stat sbuf; X#endif X X X if(nargs<3) X { printf("MARC - Archive merger, Version 5.21, created on 04/22/87 at 15:05:10\n"); X/* printf("(C) COPYRIGHT 1985,86,87 by System Enhancement Associates;"); X printf(" ALL RIGHTS RESERVED\n\n"); X printf("Please refer all inquiries to:\n\n"); X printf(" System Enhancement Associates\n"); X printf(" 21 New Street, Wayne NJ 07470\n\n"); X printf("You may copy and distribute this program freely,"); X printf(" provided that:\n"); X printf(" 1) No fee is charged for such copying and"); X printf(" distribution, and\n"); X printf(" 2) It is distributed ONLY in its original,"); X printf(" unmodified state.\n\n"); X printf("If you like this program, and find it of use, then your"); X printf(" contribution will\n"); X printf("be appreciated. You may not use this product in a"); X printf(" commercial environment\n"); X printf("or a governmental organization without paying a license"); X printf(" fee of $35. Site\n"); X printf("licenses and commercial distribution licenses are"); X printf(" available. A program\n"); X printf("disk and printed documentation are available for $50.\n"); X printf("\nIf you fail to abide by the terms of this license, "); X printf(" then your conscience\n"); X printf("will haunt you for the rest of your life.\n\n"); X*/ X printf("Usage: MARC [ . . .]\n"); X printf("Where: is the archive to add files to,\n"); X printf(" is the archive to get files from, and\n"); X printf(" is zero or more file names to get.\n"); X printf("\nAdapted from MSDOS by Howard Chu\n"); X#if GEMDOS X exitpause(); X#endif X return 1; X } X X /* see where temp files go */ X#if !MTS X arctemp = calloc(1, STRLEN); X if (!(arctemp2 = envfind("ARCTEMP"))) X arctemp2 = envfind("TMPDIR"); X if (arctemp2) { X strcpy(arctemp, arctemp2); X n = strlen(arctemp); X if (arctemp[n - 1] != CUTOFF) X arctemp[n] = CUTOFF; X } X#if UNIX X else strcpy(arctemp, "/tmp/"); X#endif X#if !MSDOS X { X static char tempname[] = "AXXXXXX"; X strcat(arctemp, mktemp(tempname)); X } X#else X strcat(arctemp, "$ARCTEMP"); X#endif X#else X guinfo("SHFSEP ", gotinf); X sepchr[0] = gotinf[0]; X guinfo("SCRFCHAR", gotinf); X tmpchr[0] = gotinf[0]; X arctemp = "-$$$"; X arctemp[0] = tmpchr[0]; X#endif X X#if UNIX X if (!stat(arg[1],&sbuf)) X strcpy(arcname,arg[1]); X else X makefnam(arg[1],".arc",arcname); X if (!stat(arg[2],&sbuf)) X strcpy(srcname,arg[2]); X else X makefnam(arg[2],".arc",srcname); X#else X makefnam(arg[1],".ARC",arcname); /* fix up archive names */ X makefnam(arg[2],".ARC",srcname); X/* makefnam(".$$$",arcname,newname);*/ X sprintf(newname,"%s.arc",arctemp); X#endif X X arc = fopen(arcname,OPEN_R); /* open the archives */ X if(!(src=fopen(srcname,OPEN_R))) X abort("Cannot read source archive %s",srcname); X if(!(new=fopen(newname,OPEN_W))) X abort("Cannot create new archive %s",newname); X X if(!arc) X printf("Creating new archive %s\n",arcname); X X /* get the files list set up */ X X lnum = nargs-3; /* initial length of list */ X if(lnum<1) /* phoney for default case */ X { lnum = 1; X lst = (char **) calloc(1,sizeof(char *)); X lst[0] = "*.*"; X } X else /* else use filenames given */ X { lst = (char **) calloc(lnum,sizeof(char *)); X for(n=3; n0) X { copyfile(arc,&arch,gotarc); X gotarc = gethdr(arc,&arch); X } X X else if(strcmp(srch.name,arch.name)<0) X { copy = 0; X for(n=0; narch.date) X || (srch.date==arch.date && srch.time>arch.time)) X { for(n=0; nname; /* string index */ X int n; /* index */ X X for(n=0; nsize); /* copy over the data */ X} X Xstatic expandlst(n) /* expand an indirect reference */ Xint n; /* number of entry to expand */ X{ X FILE *lf, *fopen(); /* list file, opener */ X char *malloc(), *realloc(); /* memory managers */ X char buf[100]; /* input buffer */ X int x; /* index */ X char *p = lst[n]+1; /* filename pointer */ X X if(*p) /* use name if one was given */ X { makefnam(p,".CMD",buf); X upper(buf); X if(!(lf=fopen(buf,"r"))) X abort("Cannot read list of files in %s",buf); X } X else lf = stdin; /* else use standard input */ X X for(x=n+1; x0) /* read in the list */ X { if(!(lst=(char **) realloc(lst,(lnum+1)*sizeof(char *)))) X abort("too many file references"); X X lst[lnum] = malloc(strlen(buf)+1); X strcpy(lst[lnum],buf); /* save the name */ X lnum++; X } X X if(lf!=stdin) /* avoid closing standard input */ X fclose(lf); X} SHAR_EOF if test 9440 -ne "`wc -c < 'marc.c'`" then echo shar: "error transmitting 'marc.c'" '(should have been 9440 characters)' fi fi echo shar: "extracting 'memset.c'" '(144 characters)' if test -f 'memset.c' then echo shar: "will not over-write existing file 'memset.c'" else sed 's/^X//' << \SHAR_EOF > 'memset.c' X/* missing function X */ Xchar * Xmemset(d, n, c) X char *d; X int n; X char c; X{ X char *s = d; X X while (n > 0) { X --n; X *d++ = c; X } X return(s); X} SHAR_EOF if test 144 -ne "`wc -c < 'memset.c'`" then echo shar: "error transmitting 'memset.c'" '(should have been 144 characters)' fi fi echo shar: "extracting 'rename.c'" '(280 characters)' if test -f 'rename.c' then echo shar: "will not over-write existing file 'rename.c'" else sed 's/^X//' << \SHAR_EOF > 'rename.c' X/* X * substitute for BSD/SVR3 rename() system call, from X * Janet Walz, walz@mimsy.umd.edu & Rich Salz, rsalz@pineapple.bbn.com X */ X Xint rename(oldname,newname) Xchar *oldname,*newname; X{ X (void)unlink(newname); X if(link(oldname,newname)) X return(-1); X return(unlink(oldname)); X} SHAR_EOF if test 280 -ne "`wc -c < 'rename.c'`" then echo shar: "error transmitting 'rename.c'" '(should have been 280 characters)' fi fi echo shar: "extracting 'scandir.3'" '(2353 characters)' if test -f 'scandir.3' then echo shar: "will not over-write existing file 'scandir.3'" else sed 's/^X//' << \SHAR_EOF > 'scandir.3' X.TH SCANDIR 3 X.\" $Header: scandir.3,v 1.1 87/12/29 21:35:54 rsalz Exp $ X.SH NAME Xscandir, alphasort \- scan a directory X.SH SYNOPSIS X.nf X.ft B X#include X#include X Xint Xscandir(name, list, selector, sorter) X.in +4n Xchar *name; Xstruct dirent ***list; Xint (*selector)(); Xint (*sorter)(); X.in -4n X Xint Xalphasort(d1, d2) X.in +4n Xstruct dirent **d1; Xstruct dirent **d2; X.in -4n X.ft R X.fi X.SH DESCRIPTION X.I Scandir Xreads the directory X.I name Xand builds a NULL\-terminated array of pointers to the entries found Xin that directory. XThis array is put into the location pointed to by the X.I list Xparameter. X.PP XIf the X.I selector Xparameter is non\-NULL, it is taken to be a pointer to a function called Xwith each entry, to determine whether or not it should be included in Xthe returned list. XIf the parameter is NULL, all entries are included. X.PP XAs an added feature, the entries can be sorted (with X.IR qsort (3)) Xbefore the list is returned. XIf the X.I sorter Xparameter is non\-NULL, it is passed to qsort to use as the comparison Xfunction. XThe X.I alphasort Xroutine is provided to sort the array alphabetically. X.PP XThe array pointed to by X.I list Xand the items it points to are all space obtained through X.IR malloc (3), Xand their storage can be reclaimed as shown in the example below. X.SH "EXAMPLE" XHere is a small X.IR ls (1)\-like Xprogram: X.ne 50 X.RS X.nf X#include X#include X#include X#include X Xextern int alphasort(); X Xstatic int Xfilesonly(e) X struct dirent *e; X{ X struct stat sb; X X return(stat(e->d_name, &sb) >= 0 && (sb.st_mode & S_IFMT) == S_IFREG); X} X Xmain(ac, av) X int ac; X char *av[]; X{ X register int i; X register int j; X struct dirent **list; X X if (ac != 2) { X fprintf(stderr, "usage: %s dirname\n", av[0]); X exit(1); X } X if (chdir(av[1]) < 0) { X perror(av[1]); X exit(1); X } X if ((i = scandir(".", &list, filesonly, alphasort)) < 0) { X perror("Error reading directory"); X exit(1); X } X for (j = 0; j < i; j++) X printf("%s\n", list[j]->d_name); X for (j = 0; j < i; j++) X free((char *)list[j]); X free((char *)list); X exit(0); X} X.fi X.RE X.SH "SEE ALSO" Xdirectory(3), qsort(3) X.SH DIAGNOSTICS XReturns the number of entries in the ``list,'' or \-1 if the directory Xcould not be opened or a memory allocation failed. X.SH BUGS XThe routine can be slightly wasteful of space. SHAR_EOF if test 2353 -ne "`wc -c < 'scandir.3'`" then echo shar: "error transmitting 'scandir.3'" '(should have been 2353 characters)' fi fi echo shar: "extracting 'scandir.c'" '(2409 characters)' if test -f 'scandir.c' then echo shar: "will not over-write existing file 'scandir.c'" else sed 's/^X//' << \SHAR_EOF > 'scandir.c' X/* X** SCANDIR X** Scan a directory, collecting all (selected) items into a an array. X*/ X X#ifdef RCSID Xstatic char RCS[] = "$Header: scandir.c,v 1.1 87/12/29 21:35:56 rsalz Exp $"; X#endif /* RCSID */ X X#include X#include X#include X X#ifdef MAXNAMLEN X X#include X#define namedir(entry) (entry->d_name) X#define MAXNAME 256 X X#else X X#define dirent direct X#define DIR FILE X#define MAXNAME (DIRSIZ+2) X#define opendir(path) fopen (path, "r") X#define closedir(dirp) fclose (dirp) Xstruct direct * Xreaddir (dirp) XDIR *dirp; X { X static struct direct entry; X if (dirp == NULL) return (NULL); X for (;;) X { X if (fread (&entry, sizeof (struct direct), 1, dirp) == 0) return (NULL); X if (entry.d_ino) return (&entry); X } X } X#endif X X/* Initial guess at directory size. */ X#define INITIAL_SIZE 20 X X/* A convenient shorthand. */ Xtypedef struct dirent ENTRY; X X#define MDIRSIZ(d) (sizeof(struct dirent) + strlen(d->d_name) + 1) X X/* Linked in later. */ Xextern char *malloc(); Xextern char *realloc(); Xextern char *strcpy(); X X Xint Xscandir(Name, List, Selector, Sorter) X char *Name; X ENTRY ***List; X int (*Selector)(); X int (*Sorter)(); X{ X register ENTRY **names; X register ENTRY *E; X register DIR *Dp; X register int i; X register int size; X X /* Get initial list space and open directory. */ X size = INITIAL_SIZE; X if ((names = (ENTRY **)malloc(size * sizeof names[0])) == NULL X || (Dp = opendir(Name)) == NULL) X return(-1); X X /* Read entries in the directory. */ X for (i = 0; E = readdir(Dp); ) X if (Selector == NULL || (*Selector)(E)) { X /* User wants them all, or he wants this one. */ X if (++i >= size) { X size <<= 1; X names = (ENTRY **)realloc((char *)names, size * sizeof names[0]); X if (names == NULL) { X closedir(Dp); X return(-1); X } X } X X /* Copy the entry. */ X if ((names[i - 1] = (ENTRY *)malloc(MDIRSIZ(E))) == NULL) { X closedir(Dp); X return(-1); X } X names[i - 1]->d_ino = E->d_ino; X#ifndef SYSV X names[i - 1]->d_reclen = E->d_reclen; X /* names[i - 1]->d_namlen = E->d_namlen; */ X#endif /* SYSV */ X (void)strcpy(names[i - 1]->d_name, E->d_name); X } X X /* Close things off. */ X names[i] = NULL; X *List = names; X closedir(Dp); X X /* Sort? */ X if (i && Sorter) X qsort((char *)names, i, sizeof names[0], Sorter); X X return(i); X} SHAR_EOF if test 2409 -ne "`wc -c < 'scandir.c'`" then echo shar: "error transmitting 'scandir.c'" '(should have been 2409 characters)' fi fi echo shar: "extracting 'tmclock.c'" '(2334 characters)' if test -f 'tmclock.c' then echo shar: "will not over-write existing file 'tmclock.c'" else sed 's/^X//' << \SHAR_EOF > 'tmclock.c' X/* X * Stolen from Jef Poskanzer's tws time library, which was stolen from X * Marshall Rose's MH Message Handling system... X * X * tmclock() will convert time from a tm struct back to a clock value. X * tmjuliandate() converts a tm struct to its julian day number. X * tmsubdayclock() takes hours, minutes, and seconds from a tm struct X * and returns the number of seconds since midnight of that day. (?) X * -- Howard Chu, August 1 1988 hyc@umix.cc.umich.edu, umix!hyc X */ X X/* $Header: tmclock.c,v 1.3 88/08/02 14:15:58 hyc Exp $ */ X X/* Julian day number of the Unix* clock's origin, 01 Jan 1970. */ X#define JD1970 2440587L X#define CENTURY 19 X#if BSD X#include Xint daylight; X#else X#include X#endif X Xlong tzone; X Xlong Xtmjuliandate( tm ) Xstruct tm *tm; X { X register int mday, mon, year; X register long a, b; X double jd; X X if ( (mday = tm -> tm_mday) < 1 || mday > 31 || X (mon = tm -> tm_mon + 1) < 1 || mon > 12 || X (year = tm -> tm_year) < 1 || year > 10000 ) X return ( -1L ); X if ( year < 100 ) X year += CENTURY * 100; X X if ( mon == 1 || mon == 2 ) X { X --year; X mon += 12; X } X if ( year < 1583 ) X return ( -1L ); X a = year / 100; X b = 2 - a + a / 4; X b += (long) ( (double) year * 365.25 ); X b += (long) ( 30.6001 * ( (double) mon + 1.0 ) ); X jd = mday + b + 1720994.5; X return ( (long) jd ); X } X X Xlong Xtmsubdayclock( tm ) Xstruct tm *tm; X { X register int sec, min, hour; X register long result; X#if BSD X { X struct timeval tp; X struct timezone tzp; X X gettimeofday(&tp, &tzp); X daylight=tzp.tz_dsttime; X tzone=tzp.tz_minuteswest*(-60); X } X#else X tzset(); X tzone = -timezone; /* declared as extern in SYSV */ X#endif X if ( (sec = tm -> tm_sec) < 0 || sec > 59 || X (min = tm -> tm_min) < 0 || min > 59 || X (hour = tm -> tm_hour) < 0 || hour > 23 ) X return ( -1L ); X X result = ( hour * 60 + min ) * 60 + sec; X result -= tzone; X if ( tm->tm_isdst ) X result -= 60 * 60; X X return ( result ); X } X X Xlong Xtmclock( tm ) Xstruct tm *tm; X { X register long jd, sdc, result; X X if ( ( jd = tmjuliandate( tm ) ) == -1L ) X return ( -1L ); X if ( ( sdc = tmsubdayclock( tm ) ) == -1L ) X return ( -1L ); X X result = ( jd - JD1970 ) * 24 * 60 * 60 + sdc; X X return ( result ); X } SHAR_EOF if test 2334 -ne "`wc -c < 'tmclock.c'`" then echo shar: "error transmitting 'tmclock.c'" '(should have been 2334 characters)' fi fi echo shar: "extracting 'utimes.c'" '(399 characters)' if test -f 'utimes.c' then echo shar: "will not over-write existing file 'utimes.c'" else sed 's/^X//' << \SHAR_EOF > 'utimes.c' X X/* bsd utimes emulation for Sys V */ X/* by Jon Zeeff */ X X#include X Xstruct utimbuf { X time_t actime; X time_t modtime; X}; X Xstruct timeval { X long tv_sec; X long tv_usec; X}; X Xutimes(path,tvp) Xchar *path; Xstruct timeval tvp[2]; X{ X Xstruct utimbuf times; X Xtimes.actime = (time_t) tvp[0].tv_sec; Xtimes.modtime = (time_t) tvp[1].tv_sec; X Xreturn utime(path, ×); X X} SHAR_EOF if test 399 -ne "`wc -c < 'utimes.c'`" then echo shar: "error transmitting 'utimes.c'" '(should have been 399 characters)' fi fi exit 0 # End of shell archive