From fdf0d8d918a735b142683cdee451deb4a3c31ce5 Mon Sep 17 00:00:00 2001 From: gdr-ftp Date: Wed, 11 Mar 1998 02:56:04 +0000 Subject: [PATCH] Initial checkin; these sources should correspond to those used to build the GNO v2.0.4 version of this util. --- bin/time/Makefile | 5 ++ bin/time/time.c | 32 +++++++++++ bin/touch/touch.c | 126 ++++++++++++++++++++++++++++++++++++++++++++ bin/touch/touch.man | 41 ++++++++++++++ 4 files changed, 204 insertions(+) create mode 100644 bin/time/Makefile create mode 100644 bin/time/time.c create mode 100644 bin/touch/touch.c create mode 100644 bin/touch/touch.man diff --git a/bin/time/Makefile b/bin/time/Makefile new file mode 100644 index 0000000..d09ea79 --- /dev/null +++ b/bin/time/Makefile @@ -0,0 +1,5 @@ +time.a: time.c + compile time.c keep=time + +time: time.a + link time keep=time diff --git a/bin/time/time.c b/bin/time/time.c new file mode 100644 index 0000000..75001e0 --- /dev/null +++ b/bin/time/time.c @@ -0,0 +1,32 @@ +/* time.c + * return process execution time of command + * 1.1 5/7/92 modified to use times() for higher accuracy + * 1.0 jb + */ + +#pragma optimize -1 +#pragma stacksize 1024 + +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ +struct tms t; +time_t start,end; + + if (argc < 2) { + fprintf(stderr,"usage: time [command]\n\r"); + exit(1); + } + + start = time(NULL); + system(commandline()+strlen(argv[0])+1); + end = time(NULL); + times(&t); + fprintf(stderr," %8ld real %7.2f user %7.2f sys\n", + end-start,t.tms_cutime/60.0,t.tms_cstime/60.0); +} diff --git a/bin/touch/touch.c b/bin/touch/touch.c new file mode 100644 index 0000000..d204f7e --- /dev/null +++ b/bin/touch/touch.c @@ -0,0 +1,126 @@ +/* Touch - GS version of UNIX touch. If file exists, sets mod. date to + current date. If file does not exist, creates a text file with that name. + + Copyright 1993 by Leslie M. Barstow III. + Placed in the Public Domain with the following condition: + Please maintain original Copyright in source, program, and manpage. +*/ + +#pragma debug 0 +#pragma optimize -1 +#pragma stacksize 1024 + +#include +#include +#include +#include +#include + +typedef struct GSString { + Word length; + char string[1]; +} GSString; + +typedef struct FileInfoRecGS { + Word pCount; + GSString *pathname; + Word access; + Word fileType; + LongWord auxType; + Word storageType; /* must be 0 for SetFileInfo */ + TimeRec createDateTime; + TimeRec modDateTime; +} FileInfoRecGS; + +typedef struct CreateRecGS { + Word pCount; + GSString *pathname; + Word access; + Word fileType; + } CreateRecGS; + +#ifndef NULL +#define NULL 0L +#endif + +extern TimeRec ReadTimeHex(); + +#ifndef stackEntry + #define stackEntry 0xE100B0 +#endif + +#ifndef PDosInt +extern pascal void PDosInt(); +#endif + +#define GetFileInfoGS(pBlockPtr) PDosInt(0x2006,pBlockPtr) +#define SetFileInfoGS(pBlockPtr) PDosInt(0x2005,pBlockPtr) +#define CreateGS(pBlockPtr) PDosInt(0x2001,pBlockPtr) + +int main(int argc, char **argv) +{int i,j; + GSString *filnam=(GSString *)NULL; + CreateRecGS crtspace; + FileInfoRecGS infospace; + + infospace.pCount = 7; + crtspace.pCount = 3; + crtspace.access = 0x00e3; + crtspace.fileType = 0x0004; + + if (argc == 1) + {fputs("Usage: touch file1 [file2 ...]\n", stdout); + fputs("GS touch: Copyright 1993 by Leslie M. Barstow III\n",stdout); + exit(-1); + } + + for(i = 1; i < argc; i++) + {j=strlen(argv[i]); + if ((filnam=(GSString *)malloc(3+j)) == (GSString *)NULL) + {fputs("touch - Error allocating string memory\n", stdout); + return(-1); + } + filnam->length = j; + strcpy(filnam->string,argv[i]); + infospace.pathname=filnam; + GetFileInfoGS(&infospace); + if (j = toolerror()) + {switch (j) + {case 0x46: crtspace.pathname = filnam; + CreateGS(&crtspace); + if (j = toolerror()) + {fputs("touch - unable to create file: ", stdout); + fputs(argv[i], stdout); + fputs(".\n", stdout); + exit(-1); + } + break; + case 0x40: + case 0x44: + case 0x45: + case 0x52: + case 0x58: fputs("touch - Invalid filename:", stdout); + fputs(argv[i], stdout); + fputs(".\n", stdout); + exit(-1); + break; + case 0x27: fputs("touch - Disk I/O Error for file: ", stdout); + fputs(argv[i], stdout); + fputs(".\n", stdout); + exit(-1); + break; + default: fputs("touch - internal error.\n", stdout); + exit(-1); + break; + } + } + else + {infospace.modDateTime = ReadTimeHex(); + infospace.storageType = 0; + infospace.access |=0x20; + infospace.modDateTime.extra = (Byte)0; + SetFileInfoGS(&infospace); + } + free(filnam); + } +} diff --git a/bin/touch/touch.man b/bin/touch/touch.man new file mode 100644 index 0000000..5487995 --- /dev/null +++ b/bin/touch/touch.man @@ -0,0 +1,41 @@ +TOUCH(1) TOUCH(1) + + +NAME + + touch - update modification date of existing file or create new file. + + +SYNOPSIS + + touch file1 [file2 ...] + + +DESCRIPTION + + touch checks each file in the argument list and processes each as follows: + + o If the file exists, touch sets the modification time and date to + the current time/date. It also sets the backup-needed flag. + + o If the file does not exist, it creates an empty text file of that + name. The file is unlocked, with the backup-needed flag set. + + Wildcard expansion is not supported outside of GNO/ME, which does its own. + + Invalid filenames cause touch to exit with return code -1, printing the + offending filename before exitting. + + +CAVEATS + + The ORCA editor does not seem to like files with length 0. It appears to + attempt to re-create the file, which already exists and is open. Use vi or + echo " " > filename. Otherwise, the file may be manipulated normally. + + +OTHER + + This program is Copyright 1993 by Leslie M. Barstow III. + It may be distributed freely, provided this manpage accompanies it. + touch uses routines from the ORCA libraries, Copyright by ByteWorks, Inc.