From 469a09b80b7016b579f895de11e0b62c7de4e5e7 Mon Sep 17 00:00:00 2001 From: gdr Date: Tue, 3 Sep 1996 03:55:00 +0000 Subject: [PATCH] - Fixed error when -d flag specified with volume name -- now ignored. - Ran sources through indent(1). - Separated out library routines. --- usr.bin/install/README | 16 ++ usr.bin/install/basename.c | 70 ------ usr.bin/install/c2gs.c | 37 --- usr.bin/install/copyfile.c | 284 --------------------- usr.bin/install/errnoGS.c | 125 ---------- usr.bin/install/expandpath.c | 53 ---- usr.bin/install/inst.c | 461 ++++++++++++++++++----------------- usr.bin/install/install.h | 26 +- usr.bin/install/makefile.mk | 27 +- usr.bin/install/stringGS.c | 78 ------ 10 files changed, 265 insertions(+), 912 deletions(-) create mode 100644 usr.bin/install/README delete mode 100644 usr.bin/install/basename.c delete mode 100644 usr.bin/install/c2gs.c delete mode 100644 usr.bin/install/copyfile.c delete mode 100644 usr.bin/install/errnoGS.c delete mode 100644 usr.bin/install/expandpath.c delete mode 100644 usr.bin/install/stringGS.c diff --git a/usr.bin/install/README b/usr.bin/install/README new file mode 100644 index 0000000..c3e4225 --- /dev/null +++ b/usr.bin/install/README @@ -0,0 +1,16 @@ +$Id: README,v 1.1 1996/09/03 03:54:55 gdr Exp $ + +As the describe file says, install(1) is a utility similar to cp(1), +except that it does a few more things and is intended for use in +makefiles and scripts. + +To install install, type "dmake doinstall". By default, it places the +binary in /usr/bin and the man page in /usr/man/man1. If you don't +like these locations, either modify the makefile or copy the two files +by hand. There are no support files. + +As usual, please email me or post to comp.sys.apple2.gno if you +encounter problems or bugs. + +Devin Reade +March 1996 diff --git a/usr.bin/install/basename.c b/usr.bin/install/basename.c deleted file mode 100644 index bc15b0f..0000000 --- a/usr.bin/install/basename.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 1996 Devin Reade . - * All rights reserved. - * - * For copying and distribution information, see the file "COPYING" - * accompanying this file. - * - * $Id: basename.c,v 1.1 1996/03/31 23:38:30 gdr Exp $ - */ - -#include -#include -#include "install.h" - -/* - * basename - * - * returns the filename component of . If contains colons, - * they are assumed to be the directory separators, otherwise any '/' is - * assumed to be a directory separator. - * - * If no directory separators are found, then the full path is returned. - * - * No check is done as to whether the pathname is valid on the any - * given filesystem. - */ - -char * -basename (char *path) -{ - char delim, *p; - - delim = strchr(path,':') ? ':' : '/'; - p = strrchr(path,delim); - return p ? p+1 : path; -} - -/* - * dirname - * - * Returns a pointer to an internal buffer that contains a string that - * matches the directory component - * of . If contains at least one ':', then it is assumed - * that colons are directory separators, otherwise any '/' character - * is treated as a directory separator. - * - * If contains no pathname separators, then dirname() will - * return an empty (zero-length) string. - * - * No check is done as to whether the pathname is valid on the any - * given filesystem. - */ - -char * -dirname (char *path) -{ - char delim, *p; - static char dir[FILENAME_MAX]; - - strncpy(dir,path,FILENAME_MAX-1); - dir[FILENAME_MAX-1] = '\0'; - delim = strchr(dir,':') ? ':' : '/'; - p = strchr(dir,delim); - if (p == NULL) { - *dir = '\0'; - } else { - *p = '\0'; - } - return dir; -} diff --git a/usr.bin/install/c2gs.c b/usr.bin/install/c2gs.c deleted file mode 100644 index ae715ef..0000000 --- a/usr.bin/install/c2gs.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 1996 Devin Reade . - * All rights reserved. - * - * For copying and distribution information, see the file "COPYING" - * accompanying this file. - * - * $Id: c2gs.c,v 1.1 1996/03/31 23:38:31 gdr Exp $ - */ - -#include -#include -#include -#include "install.h" - -/* - * __C2GS - * - * Converts a null-terminated C string into a class 1 GS/OS string. - * Space for the GS/OS string must already be allocated, and the - * length of s must not be more than 255 chars. - * - * If the s is too long, __C2GS will return NULL, otherwise it will - * return the GS/OS string g. - */ - -GSString255Ptr -__C2GS(char *s, GSString255Ptr g) -{ - size_t len; - - len = strlen(s); - if (len > 255) return NULL; /* the string won't fit */ - g->length = len; - strncpy(g->text,s,255); - return g; -} diff --git a/usr.bin/install/copyfile.c b/usr.bin/install/copyfile.c deleted file mode 100644 index 596e537..0000000 --- a/usr.bin/install/copyfile.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright 1996 Devin Reade . - * All rights reserved. - * - * For copying and distribution information, see the file "COPYING" - * accompanying this file. - * - * $Id: copyfile.c,v 1.1 1996/03/31 23:38:31 gdr Exp $ - */ - -#include -#include -#include -#include -#include -#include "install.h" - -/* the chunk size in which we copy files */ -#define COPY_BUFFER_SIZE 1024 - -/* - * copyfile - * - * copy a file from the pathname to the location , which - * may be a directory. Ensure that file types and other information - * (except for the backup bit) is matched. - * - * Returns NULL and sets errno on failure. On success, returns a - * pointer to an internal buffer containing the final pathname. - * - * +++ THIS ROUTINE IS NOT REENTRANT +++ - */ - -char * -copyfile (char *from, char *to) -{ - static char buffer[COPY_BUFFER_SIZE]; - static FileInfoRecGS inforec; - static OpenRecGS openrec; - static ExpandPathRecGS expandrec; - static ResultBuf255 resultbuf; - static struct { - Word pCount; - Word refNum; - Longword dataBuffer; - Longword requestCount; - Longword transferCount; - Word cachePriority; - } iobuf; - static struct { - Word pCount; - Word refNum; - } closerec; - static GSString255 fromGS, toGS; - static char *result = NULL; /* we only use this if our path is */ - /* exactly 255 chars long */ - size_t len1, len2; - Word refNumIn, refNumOut; /* GS/OS ref numbers for I/O */ - int isDir, i, j, k, done; - char *p, *q, *r; - - /* concheck and convert filenames to GSString255 type */ - if (!from || !to || - ((len1 = strlen(from)) > 254) || - ((len2 = strlen(to)) > 254) ) - { - errno = EINVAL; - return NULL; - } - fromGS.length = len1; - toGS.length = len2; - strcpy(fromGS.text,from); - strcpy(toGS.text,to); - - /* expand the original file name */ - expandrec.pCount = 3; - expandrec.inputPath = &fromGS; - expandrec.outputPath = &resultbuf; - expandrec.flags = 0x0000; - resultbuf.bufSize = 255; - ExpandPathGS(&expandrec); - if ((i = toolerror()) != 0) { - errno = _mapErr(i); - return NULL; - } - strcpyGSString255(&fromGS,&(resultbuf.bufString)); - - /* expand the destination name */ - expandrec.pCount = 3; - expandrec.inputPath = &toGS; - expandrec.outputPath = &resultbuf; - expandrec.flags = 0x0000; - resultbuf.bufSize = 255; - ExpandPathGS(&expandrec); - if ((i = toolerror()) != 0) { - errno = _mapErr(i); - return NULL; - } - strcpyGSString255(&toGS,&(resultbuf.bufString)); - - /* find out if is a directory */ - inforec.pCount = 5; - inforec.pathname = &toGS; - GetFileInfoGS(&inforec); - i = toolerror(); - switch(i) { - case 0: - isDir = ((inforec.storageType == 0x0D) || - (inforec.storageType == 0x0F)) ? 1 : 0; - break; - case fileNotFound: - isDir = 0; - break; - default: - errno = _mapErr(i); - return NULL; - } - - /* it's a directory? tack on the file name */ - if (isDir) { - - /* expand the directory name */ - expandrec.pCount = 3; - expandrec.inputPath = &toGS; - expandrec.outputPath = &resultbuf; - expandrec.flags = 0x0000; - resultbuf.bufSize = 255; - ExpandPathGS(&expandrec); - if ((i = toolerror()) != 0) { - errno = _mapErr(i); - return NULL; - } - - /* tack on the final component */ - p = basename(from); - len1 = strlen(p); - if (len1 + toGS.length + 1 > 255) { - errno = EINVAL; - return NULL; - } - q = &(toGS.text[toGS.length]); - r = p; - *q++ = ':'; - for (i=0; i. - * All rights reserved. - * - * For copying and distribution information, see the file "COPYING" - * accompanying this file. - * - * $Id: errnoGS.c,v 1.1 1996/03/31 23:38:31 gdr Exp $ - */ - -#include -#include -#include -#include "install.h" - -#pragma lint -1 -#pragma debug 0 -#pragma optimize -1 - -#define NONE "no error" -#define UNKNOWN "unknown error" - -segment "errnoGS___"; - -typedef struct errEntry { - unsigned short num; - char *str; -} errEntry; - -static errEntry -sys_errlistGS[] = { - { badSystemCall, "bad system call number" }, - { invalidPcount, "invalid parameter count" }, - { gsosActive, "GS/OS already active" }, - { devNotFound, "device not found" }, - { invalidDevNum, "invalid device number" }, - { drvrBadReq, "bad request or command" }, - { drvrBadCode, "bad control or status code" }, - { drvrBadParm, "bad call parameter" }, - { drvrNotOpen, "character device not open" }, - { drvrPriorOpen, "character device already open" }, - { irqTableFull, "interrupt table full" }, - { drvrNoResrc, "resources not available" }, - { drvrIOError, "I/O error" }, - { drvrNoDevice, "device not connected" }, - { drvrBusy, "call aborted; driver is busy" }, - { drvrWrtProt, "device is write protected" }, - { drvrBadCount, "invalid byte count" }, - { drvrBadBlock, "invalid block address" }, - { drvrDiskSwitch, "disk has been switched" }, - { drvrOffLine, "device off line/ no media present" }, - { badPathSyntax, "invalid pathname syntax" }, - { tooManyFilesOpen, "too many files open on server volume" }, - { invalidRefNum, "invalid reference number" }, - { pathNotFound, "subdirectory does not exist" }, - { volNotFound, "volume not found" }, - { fileNotFound, "file not found" }, - { dupPathname, "create or rename with existing name" }, - { volumeFull, "volume full error" }, - { volDirFull, "volume directory full" }, - { badFileFormat, "version error (incompatible file format)" }, - { badStoreType, "unsupported (or incorrect) storage type" }, - { eofEncountered, "end-of-file encountered" }, - { outOfRange, "position out of range" }, - { invalidAccess, "access not allowed" }, - { buffTooSmall, "buffer too small" }, - { fileBusy, "file is already open" }, - { dirError, "directory error" }, - { unknownVol, "unknown volume type" }, - { paramRangeErr, "parameter out of range" }, - { outOfMem, "out of memory" }, - { dupVolume, "duplicate volume name" }, - { notBlockDev, "not a block device" }, - { invalidLevel, "specifield level outside legal range" }, - { damagedBitMap, "block number too large" }, - { badPathNames, "invalid pathnames for ChangePath" }, - { notSystemFile, "not an executable file" }, - { osUnsupported, "Operating System not supported" }, - { stackOverflow, "too many applications on stack" }, - { dataUnavail, "data unavailable" }, - { endOfDir, "end of directory has been reached" }, - { invalidClass, "invalid FST call class" }, - { resForkNotFound, "file does not contain required resource" }, - { invalidFSTID, "error - FST ID is invalid" }, - { invalidFSTop, "invalid FST operation" }, - { fstCaution, "FST handled call, but result is weird" }, - { devNameErr, "device exists with same name as replacement name" }, - { defListFull, "device list is full" }, - { supListFull, "supervisor list is full" }, - { fstError, "generic FST error" }, - { resExistsErr, "cannot expand file, resource already exists" }, - { resAddErr, "cannot add resource fork to this type file" }, - { networkError, "generic network error" }, - { 0, NONE } /* we shouldn't see this */ -}; - -unsigned short errnoGS = 0; - -char * -strerrorGS(unsigned short num) -{ - int i; - - if (num == 0) return NONE; - i = 0; - while (sys_errlistGS[i].num) { - if (sys_errlistGS[i].num == num) { - return sys_errlistGS[i].str; - } - i++; - } - return UNKNOWN; -} - -void -perrorGS(char *format, ...) -{ - va_list ap; - - va_start(ap,format); - vfprintf(stderr,format,ap); - fprintf(stderr,": %s\n",strerrorGS(errnoGS)); - va_end(ap); - return; -} diff --git a/usr.bin/install/expandpath.c b/usr.bin/install/expandpath.c deleted file mode 100644 index 4040955..0000000 --- a/usr.bin/install/expandpath.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 1996 Devin Reade . - * All rights reserved. - * - * For copying and distribution information, see the file "COPYING" - * accompanying this file. - * - * $Id: expandpath.c,v 1.1 1996/03/31 23:38:32 gdr Exp $ - */ - -#include -#include -#include -#include -#include "install.h" - -/* - * expandpath - * - * Uses the GS/OS facilities to expand the pathname . On - * success, returns a pointer to the malloc'd expanded path. On - * failure it will return NULL and set errno. - * - * Note that in using this function, all directory separators will - * be converted to colons. - * - * Unfortunately, this routine uses a little over 0.5k of stack space ... - */ - -char * -expandpath (char *path) -{ - ExpandPathRecGS expand; - GSString255 inStr; - ResultBuf255 outBuf; - int i; - - if (__C2GS(path,&inStr) == NULL) { - errno = EINVAL; - return NULL; - } - expand.pCount = 3; - expand.inputPath = &inStr; - expand.outputPath = &outBuf; - expand.flags = 0x0000; - outBuf.bufSize = 255; - ExpandPathGS(&expand); - if ((i = toolerror()) != 0) { - errno = _mapErr(i); - return NULL; - } - return __GS2CMALLOC(&(outBuf.bufString)); -} diff --git a/usr.bin/install/inst.c b/usr.bin/install/inst.c index 734ec97..b107e6e 100644 --- a/usr.bin/install/inst.c +++ b/usr.bin/install/inst.c @@ -5,7 +5,7 @@ * For copying and distribution information, see the file "COPYING" * accompanying this file. * - * $Id: inst.c,v 1.1 1996/03/31 23:38:33 gdr Exp $ + * $Id: inst.c,v 1.2 1996/09/03 03:54:58 gdr Exp $ */ #include @@ -16,9 +16,14 @@ #include #include #include +#include #include #include -#include "install.h" +#include + +extern int _mapErr(int); + +#include "contrib.h" /* actions */ #define NOCHANGE 0 @@ -44,12 +49,12 @@ #define EMAIL "" char *versionMsg = "Version %s by Devin Reade %s\n"; -int dFlag; +int dFlag; extern int mkdir(const char *); extern int needsgno(void); extern void begin_stack_check(void); -extern int end_stack_check(void); +extern int end_stack_check(void); /* * usage @@ -58,21 +63,21 @@ extern int end_stack_check(void); */ void -usage (void) +usage(void) { - fputs("Usage: install [-cdhsv] [-o owner] [-g group] [-m mode] ",stderr); - fputs("source [...] dest\n\n",stderr); - fputs("Options:\n",stderr); - fputs("\t-c Ignored. (Backwards Unix compatibility)\n",stderr); - fputs("\t-d Create the specified directories\n",stderr); - fputs("\t-g group Specify group id (not implemented)\n",stderr); - fputs("\t-h Show usage information and exit.\n",stderr); - fputs("\t-m mode Specify (Unix) access mode\n",stderr); - fputs("\t-o owner Specify owner id (not implemented)\n",stderr); - fputs("\t-s Strip binary (not implemented)\n",stderr); - fputs("\t-v Show version number\n\n",stderr); - fprintf(stderr,versionMsg,VERSION,EMAIL); - exit(1); + fputs("Usage: install [-cdhsv] [-o owner] [-g group] [-m mode] ", stderr); + fputs("source [...] dest\n\n", stderr); + fputs("Options:\n", stderr); + fputs("\t-c Ignored. (Backwards Unix compatibility)\n", stderr); + fputs("\t-d Create the specified directories\n", stderr); + fputs("\t-g group Specify group id (not implemented)\n", stderr); + fputs("\t-h Show usage information and exit.\n", stderr); + fputs("\t-m mode Specify (Unix) access mode\n", stderr); + fputs("\t-o owner Specify owner id (not implemented)\n", stderr); + fputs("\t-s Strip binary (not implemented)\n", stderr); + fputs("\t-v Show version number\n\n", stderr); + fprintf(stderr, versionMsg, VERSION, EMAIL); + exit(1); } /* @@ -93,9 +98,9 @@ usage (void) */ int -getmode (char *str, unsigned long *mode, int *action) +getmode(char *str, unsigned long *mode, int *action) { - unsigned long who = 0L; + unsigned long who = 0L; unsigned long perm = 0L; char *p, *q; @@ -103,47 +108,48 @@ getmode (char *str, unsigned long *mode, int *action) if (isdigit(*str)) { *action = ASSIGN; errno = 0; - *mode = strtoul(str,NULL,8); + *mode = strtoul(str, NULL, 8); return errno; } - /* it's not an absolute octal; treat as a string */ - if (((p = strchr(str,'+')) == NULL) && - ((p = strchr(str,'-')) == NULL) && - ((p = strchr(str,'=')) == NULL)) { + if (((p = strchr(str, '+')) == NULL) && + ((p = strchr(str, '-')) == NULL) && + ((p = strchr(str, '=')) == NULL)) { errno = EINVAL; return errno; } switch (*p) { - case '+': *action = ADD; break; - case '-': *action = REMOVE; break; - case '=': *action = ASSIGN; break; - default: assert(0); + case '+': *action = ADD; break; + case '-': *action = REMOVE; break; + case '=': *action = ASSIGN; break; + default: assert(0); } /* * this condition should really be deduced from the umask, if it * were supported. */ - if (str == p) who |= S_USER; + if (str == p) { + who |= S_USER; + } - for (q = str; q 2) { - - /* find out if argv[argc-1] is a directory */ - if (__C2GS(argv[argc-1], &filenameGS) == NULL) { - errno = EINVAL; - perror("destination path too long"); - return errno; - } - inforec.pCount = 5; - inforec.pathname = &filenameGS; - GetFileInfoGS(&inforec); - if ((errnoGS = toolerror()) != 0) { - perrorGS("%s",argv[argc-1]); - errno = _mapErr(errnoGS); + /* find out if argv[argc-1] is a directory */ + + if (__C2GS(argv[argc - 1], &filenameGS) == NULL) { + errno = EINVAL; + perror("destination path too long"); + return errno; + } + inforec.pCount = 5; + inforec.pathname = &filenameGS; + GetFileInfoGS(&inforec); + if ((errnoGS = toolerror()) != 0) { + perrorGS("%s", argv[argc - 1]); + errno = _mapErr(errnoGS); return -1; - } - if ((inforec.storageType != 0x0D) && (inforec.storageType != 0x0F)) { - errno = ENOTDIR; - perror(argv[argc-1]); - return errno; - } - } - + } + if ((inforec.storageType != 0x0D) && (inforec.storageType != 0x0F)) { + errno = ENOTDIR; + perror(argv[argc - 1]); + return errno; + } + } --argc; - for (i=0; i. - * All rights reserved. - * - * For copying and distribution information, see the file "COPYING" - * accompanying this file. - * - * $Id: stringGS.c,v 1.1 1996/03/31 23:38:34 gdr Exp $ - */ - -#include -#include "install.h" - -/* - * strcpyGSString255 - * - * copies the GSString255 pointed to by to that pointed - * to by - */ - -void -strcpyGSString255 (GSString255Ptr to, GSString255Ptr from) -{ - int i; - - char *p = from->text; - char *q = to->text; - for (i=0; ilength; i++) *q++ = *p++; - to->length = from->length; - return; -} - -/* - * strcatGSString255 - * - * concatenates the string onto , to a maximum of 255 - * chars total in . - */ - -void -strcatGSString255 (GSString255Ptr to, GSString255Ptr from) -{ - int i, count; - - char *p = from->text; - char *q = to->text; - q+= to->length; - count = from->length; - if (count > 255 - to->length) count = 255 - to->length; - for (i=0; ilength += count; - return; -} - -/* - * like strcmp(3), but for GSString255Ptr args. - */ - -int -strcmpGSString255 (GSString255Ptr a, GSString255Ptr b) -{ - int i, count; - char *p, *q; - - count = a->length - b->length; - if (count) return count; - - p = a->text; - q = b->text; - for (i=0; i *q) return 1; - else return -1; - } - return 0; -}