From 67f8cc0cf0f74e5a8fbb994f31779f083f206998 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Mon, 20 Oct 2025 14:31:18 -0700 Subject: [PATCH] Cleanup UnixVersionToLispVersion and LispVersionToUnixVersion * implements these as functions rather than #define macros * moves definitions to ufs.c * adds parameter to UnixVersionToLispVersion for the storage size of the buffer being passed * removes inc/lispver2.h * adjusts makefile-dos an makefile-tail to update dependencies --- bin/makefile-dos | 2 +- bin/makefile-tail | 18 ++++----- inc/lispver2.h | 74 ------------------------------------- inc/locfile.h | 88 +------------------------------------------- inc/ufsdefs.h | 2 + src/dir.c | 3 +- src/ufs.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 108 insertions(+), 173 deletions(-) delete mode 100644 inc/lispver2.h diff --git a/bin/makefile-dos b/bin/makefile-dos index 9866836..a842195 100644 --- a/bin/makefile-dos +++ b/bin/makefile-dos @@ -18,7 +18,7 @@ SRCFILES = conspage.c gcoflow.c shift.c dbgtool.c gcr.c gcrcell.c llstk. OFILES = conspage.obj gcoflow.obj shift.obj dbgtool.obj gcr.obj gcrcell.obj llstk.obj gcscan.obj loopsops.obj storage.obj allocmds.obj dir.obj gvar2.obj lowlev1.obj subr.obj arithops.obj lowlev2.obj subr0374.obj doscomm.obj hardrtn.obj lsthandl.obj sxhash.obj draw.obj main.obj testtool.obj array.obj dsk.obj inet.obj misc7.obj timer.obj array2.obj dspif.obj initdsp.obj miscn.obj typeof.obj array3.obj initkbd.obj ubf1.obj array4.obj dspsubrs.obj initsout.obj mkatom.obj ubf2.obj array5.obj eqf.obj intcall.obj mkcell.obj ubf3.obj array6.obj ether.obj ufn.obj atom.obj findkey.obj kbdsubrs.obj mouseif.obj ufs.obj bbtsub.obj foreign.obj keyevent.obj unixcomm.obj bin.obj fp.obj binds.obj fvar.obj mvs.obj unwind.obj bitblt.obj gc.obj uraid.obj blt.obj gc2.obj kprint.obj osmsg.obj usrsubr.obj byteswap.obj gcarray.obj perrno.obj uutils.obj carcdr.obj asmbbt.obj gccode.obj vars3.obj gcfinal.obj ldsout.obj return.obj vmemsave.obj chardev.obj gchtfind.obj lineblt8.obj rpc.obj xc.obj common.obj gcmain3.obj lisp2c.obj rplcons.obj z2.obj vdate.obj $(COLORFILES) $(ARCHFILES) $(LPFILES) -HFILES = address.h adr68k.h arithopsdefs.h arith.h cell.h dbprint.h display.h dspif.h ifpage.h iopage.h lispemul.h lispmap.h lsptypes.h miscstat.h lspglob.h array.h bb.h bbtmacro.h debug.h devconf.h dspdata.h fast_dsp.h gcdata.h initatms.h inlinec.h keyboard.h lispver1.h lispver2.h lldsp.h locfile.h medleyfp.h mouseif.h my.h opcodes.h osmsgprint.h pilotbbt.h print.h retmacro.h stack.h stream.h subrs.h timeout.h tos1defs.h tosfns.h tosret.h xdefs.h xbitmaps.h xkeymap.h +HFILES = address.h adr68k.h arithopsdefs.h arith.h cell.h dbprint.h display.h dspif.h ifpage.h iopage.h lispemul.h lispmap.h lsptypes.h miscstat.h lspglob.h array.h bb.h bbtmacro.h debug.h devconf.h dspdata.h fast_dsp.h gcdata.h initatms.h inlinec.h keyboard.h lispver1.h lldsp.h locfile.h medleyfp.h mouseif.h my.h opcodes.h osmsgprint.h pilotbbt.h print.h retmacro.h stack.h stream.h subrs.h timeout.h tos1defs.h tosfns.h tosret.h xdefs.h xbitmaps.h xkeymap.h diff --git a/bin/makefile-tail b/bin/makefile-tail index ee098bb..80bc258 100644 --- a/bin/makefile-tail +++ b/bin/makefile-tail @@ -340,7 +340,7 @@ $(OBJECTDIR)car-cdr.o: $(SRCDIR)car-cdr.c $(REQUIRED-INCS) \ $(OBJECTDIR)chardev.o: $(SRCDIR)chardev.c $(REQUIRED-INCS) \ $(INCDIR)lispemul.h $(INCDIR)lispmap.h \ $(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)timeout.h \ - $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dbprint.h \ + $(INCDIR)locfile.h $(INCDIR)dbprint.h \ $(INCDIR)chardevdefs.h $(INCDIR)byteswapdefs.h $(INCDIR)commondefs.h \ $(INCDIR)perrnodefs.h $(CC) $(RFLAGS) $(SRCDIR)chardev.c -o $(OBJECTDIR)chardev.o @@ -505,7 +505,7 @@ $(OBJECTDIR)dsk.o: $(SRCDIR)dsk.c $(REQUIRED-INCS) \ $(INCDIR)lispemul.h $(INCDIR)lispmap.h \ $(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h \ $(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)arith.h $(INCDIR)stream.h \ - $(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)lispver2.h \ + $(INCDIR)timeout.h $(INCDIR)locfile.h \ $(INCDIR)dbprint.h $(INCDIR)dskdefs.h $(INCDIR)byteswapdefs.h \ $(INCDIR)car-cdrdefs.h $(INCDIR)cell.h $(INCDIR)commondefs.h \ $(INCDIR)ufsdefs.h @@ -515,7 +515,7 @@ $(OBJECTDIR)ufs.o: $(SRCDIR)ufs.c $(REQUIRED-INCS) \ $(INCDIR)lispemul.h $(INCDIR)lispmap.h \ $(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h \ $(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)arith.h $(INCDIR)stream.h \ - $(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dbprint.h \ + $(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)dbprint.h \ $(INCDIR)ufsdefs.h $(INCDIR)commondefs.h $(INCDIR)dskdefs.h $(CC) $(RFLAGS) $(SRCDIR)ufs.c -o $(OBJECTDIR)ufs.o @@ -523,7 +523,7 @@ $(OBJECTDIR)dir.o: $(SRCDIR)dir.c $(REQUIRED-INCS) \ $(INCDIR)lispemul.h $(INCDIR)lispmap.h \ $(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)lspglob.h \ $(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)timeout.h \ - $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dirdefs.h \ + $(INCDIR)locfile.h $(INCDIR)dirdefs.h \ $(INCDIR)commondefs.h $(INCDIR)dskdefs.h $(INCDIR)ufsdefs.h $(CC) $(RFLAGS) $(SRCDIR)dir.c -o $(OBJECTDIR)dir.o @@ -640,7 +640,7 @@ $(OBJECTDIR)inet.o: $(SRCDIR)inet.c $(REQUIRED-INCS) \ $(INCDIR)lispemul.h $(INCDIR)lispmap.h \ $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)emlglob.h $(INCDIR)lspglob.h \ $(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)adr68k.h \ - $(INCDIR)dbprint.h $(INCDIR)locfile.h $(INCDIR)lispver2.h \ + $(INCDIR)dbprint.h $(INCDIR)locfile.h \ $(INCDIR)inetdefs.h $(INCDIR)byteswapdefs.h $(INCDIR)commondefs.h \ $(INCDIR)mkcelldefs.h $(CC) $(RFLAGS) $(SRCDIR)inet.c -o $(OBJECTDIR)inet.o @@ -758,7 +758,7 @@ $(OBJECTDIR)osmsg.o: $(SRCDIR)osmsg.c $(REQUIRED-INCS) \ $(INCDIR)lispemul.h $(INCDIR)lispmap.h \ $(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)stream.h \ $(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h \ - $(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)osmsgprint.h \ + $(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)osmsgprint.h \ $(INCDIR)dbprint.h $(INCDIR)commondefs.h $(INCDIR)osmsgdefs.h $(CC) $(RFLAGS) $(SRCDIR)osmsg.c -o $(OBJECTDIR)osmsg.o @@ -865,7 +865,7 @@ $(OBJECTDIR)unixcomm.o: $(SRCDIR)unixcomm.c $(REQUIRED-INCS) \ $(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h \ $(INCDIR)cell.h $(INCDIR)stack.h $(INCDIR)arith.h $(INCDIR)dbprint.h \ $(INCDIR)timeout.h $(INCDIR)unixcommdefs.h $(INCDIR)byteswapdefs.h \ - $(INCDIR)commondefs.h $(INCDIR)locfile.h $(INCDIR)lispver2.h + $(INCDIR)commondefs.h $(INCDIR)locfile.h $(CC) $(RFLAGS) $(SRCDIR)unixcomm.c -o $(OBJECTDIR)unixcomm.o $(OBJECTDIR)unixfork.o: $(SRCDIR)unixfork.c $(REQUIRED-INCS) \ @@ -888,7 +888,7 @@ $(OBJECTDIR)rpc.o: $(SRCDIR)rpc.c $(REQUIRED-INCS) \ $(INCDIR)lispemul.h $(INCDIR)lispmap.h \ $(INCDIR)lsptypes.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h \ $(INCDIR)miscstat.h $(INCDIR)emlglob.h $(INCDIR)adr68k.h $(INCDIR)arith.h \ - $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)rpcdefs.h \ + $(INCDIR)locfile.h $(INCDIR)rpcdefs.h \ $(INCDIR)commondefs.h $(CC) $(RFLAGS) $(SRCDIR)rpc.c -o $(OBJECTDIR)rpc.o @@ -909,7 +909,7 @@ $(OBJECTDIR)vmemsave.o: $(SRCDIR)vmemsave.c $(REQUIRED-INCS) \ $(INCDIR)lispemul.h \ $(INCDIR)lispmap.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h \ $(INCDIR)miscstat.h $(INCDIR)timeout.h $(INCDIR)adr68k.h \ - $(INCDIR)lsptypes.h $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dbprint.h \ + $(INCDIR)lsptypes.h $(INCDIR)locfile.h $(INCDIR)dbprint.h \ $(INCDIR)devif.h $(INCDIR)vmemsavedefs.h $(INCDIR)byteswapdefs.h $(INCDIR)commondefs.h \ $(INCDIR)dskdefs.h $(INCDIR)initkbddefs.h $(INCDIR)perrnodefs.h \ $(INCDIR)ufsdefs.h diff --git a/inc/lispver2.h b/inc/lispver2.h deleted file mode 100644 index 7e18009..0000000 --- a/inc/lispver2.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef LISPVER2_H -#define LISPVER2_H 1 -/* $Id: lispver2.h,v 1.2 1999/01/03 02:06:09 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved */ - -/* non-DOS version of LispVersionToUnixVersion */ - -#define LispVersionToUnixVersion(pathname) do { \ - \ - char *lv_cp; \ - char *lv_vp; \ - unsigned lv_ver; \ - char lv_ver_buf[VERSIONLEN]; \ - \ - lv_cp = pathname; \ - lv_vp = NULL; \ - while (*lv_cp) { \ - switch (*lv_cp) { \ - \ - case ';': \ - lv_vp = lv_cp; \ - lv_cp++; \ - break; \ - \ - case '\'': \ - if (*(lv_cp + 1) != 0) lv_cp += 2; \ - else lv_cp++; \ - break; \ - \ - default: \ - lv_cp++; \ - break; \ - } \ - } \ - \ - if (lv_vp != NULL) { \ - /* \ - * A semicolon which is not quoted has been found. \ - */ \ - if (*(lv_vp + 1) == 0) { \ - /* \ - * The empty version field. \ - * This is regarded as a versionless file. \ - */ \ - *lv_vp = 0; \ - } else { \ - NumericStringP((lv_vp + 1), YES, NO); \ - YES: \ - /* \ - * Convert the remaining field to digit. \ - */ \ - lv_ver = strtoul(lv_vp + 1, (char **)NULL, 10); \ - if (lv_ver == 0) { \ - /* versionless */ \ - *lv_vp = 0; \ - } else { \ - sprintf(lv_ver_buf, ".~%u~", lv_ver); \ - *lv_vp = 0; \ - strcat(pathname, lv_ver_buf); \ - } \ - goto CONT; \ - \ - NO: \ - strcpy(lv_ver_buf, lv_vp + 1); \ - strcat(lv_ver_buf, "~"); \ - *lv_vp++ = '.'; \ - *lv_vp++ = '~'; \ - *lv_vp = 0; \ - strcat(pathname, lv_ver_buf); \ - CONT: \ - lv_vp--; /* Just for label */ \ - } \ - } \ -} while (0) -#endif /* LISPVER2_H */ diff --git a/inc/locfile.h b/inc/locfile.h index 5dc8b2c..59de1d6 100644 --- a/inc/locfile.h +++ b/inc/locfile.h @@ -312,94 +312,10 @@ do { \ /* * * * * it gave "Too many characters in a character constant" errors! */ #include "lispver1.h" #else /* DOS */ -/* NON-DOS version of the macro LispVersionToUnixVersion */ -#include "lispver2.h" +/* NON-DOS version is inline in ufs.c */ #endif /* DOS */ - -/* - * Name: UnixVersionToLispVersion - * - * Argument: char *pathname - * UNIX syntax pathname. - * int vlessp - * If 0, versionless file is converted to version 1. - * Otherwise, remains as versionless. - * - * Value: On success returns 1, otherwise 0. - * - * Side Effect: The version part of pathname is destructively modified. - * - * Description: - * - * Destructively modifies the version part of pathname which is following the - * UNIX file naming convention to Xerox Lisp one. - * This macro should be called, in the routines which convert the UNIX pathname - * to Lisp one, just before it returns the result to Lisp, because converting - * version field will append a semicolon which may confuse the routine - * The file which does not have a valid version field, that is ".~##~" form, is - * dealt with as version 1. - */ - -#define UnixVersionToLispVersion(pathname, vlessp) do { \ - \ - char *start; \ - char *end; \ - char *lf_cp; \ - int ver_no; \ - size_t len; \ - char ver_buf[VERSIONLEN]; \ - \ - if ((start = strchr(pathname, '~')) != NULL) { \ - /* First of all, find the version field in pathname. */ \ - end = start; \ - lf_cp = start + 1; \ - while (*lf_cp) { \ - if (*lf_cp == '~') { \ - start = end; \ - end = lf_cp; \ - lf_cp++; \ - } else { \ - lf_cp++; \ - } \ - } \ - \ - if (start != end && *(start - 1) == '.' && end == (lf_cp - 1)) { \ - /* \ - * pathname ends in the form ".~###~". But we \ - * check ### is a valid number or not. \ - */ \ - len = (end - start) - 1; \ - strncpy(ver_buf, start + 1, len); \ - ver_buf[len] = '\0'; \ - NumericStringP(ver_buf, YES, NO); \ - YES: \ - *(start - 1) = ';'; \ - *start = '\0'; \ - *end = '\0'; \ - /* call strtoul() to eliminate leading 0s. */ \ - ver_no = strtoul(start + 1, (char **)NULL, 10); \ - sprintf(ver_buf, "%u", ver_no); \ - strcat(pathname, ver_buf); \ - goto CONT; \ - \ - NO: \ - /* Dealt with as version 1 unless vlessp */ \ - if (!(vlessp)) strcat(pathname, ";1"); \ - CONT: \ - lf_cp--; /* Just for label */ \ - } else { \ - /* Dealt with as version 1 unless vlessp. */ \ - if (!(vlessp)) strcat(pathname, ";1"); \ - } \ - } else { \ - /* Dealt with as version 1 unless vlessp. */ \ - if (!(vlessp)) strcat(pathname, ";1"); \ - } \ - } while (0) - -#define VERSIONLEN 16 - +#define VERSIONLEN 24 #define MAXVERSION 999999999 #define LASTVERSIONARRAY ((unsigned) -1) diff --git a/inc/ufsdefs.h b/inc/ufsdefs.h index c08c44e..d2ce722 100644 --- a/inc/ufsdefs.h +++ b/inc/ufsdefs.h @@ -5,6 +5,8 @@ LispPTR UFS_getfilename(LispPTR *args); LispPTR UFS_deletefile(LispPTR *args); LispPTR UFS_renamefile(LispPTR *args); LispPTR UFS_directorynamep(LispPTR *args); +void UnixVersionToLispVersion(char *pathname, size_t pathsize, int vlessp); +void LispVersionToUnixVersion(char *pathname, size_t pathsize); #ifdef DOS int unixpathname(char *src, char *dst, int dstlen, int versionp, int genp, char *drive, int *extlenptr, char *rawname); #else diff --git a/src/dir.c b/src/dir.c index aa189cf..ac4019a 100644 --- a/src/dir.c +++ b/src/dir.c @@ -216,6 +216,7 @@ int make_old_version(char *old, size_t oldsize, char *file) /******** E N D O F P A T T E R N - M A T C H I N G C O D E *******/ /************************************************************************/ + /************************************************************************/ /************** B E G I N O F Q U O T I N G C O D E ****************/ /************************************************************************/ @@ -310,7 +311,7 @@ static int quote_fname(char *file, size_t filesize) } else { strlcpy(namebuf, fbuf, sizeof(namebuf)); } - UnixVersionToLispVersion(namebuf, 1); + UnixVersionToLispVersion(namebuf, sizeof(namebuf), 1); strlcpy(file, namebuf, filesize); return (1); } diff --git a/src/ufs.c b/src/ufs.c index 5e2432a..7259cc8 100644 --- a/src/ufs.c +++ b/src/ufs.c @@ -9,6 +9,7 @@ #include "version.h" +#include #include #include #include @@ -428,6 +429,95 @@ LispPTR UFS_directorynamep(LispPTR *args) return (GetSmallp(len)); } +/* + * Name: UnixVersionToLispVersion + * + * Argument: char *pathname + * size_t pathsize + * int vlessp + * + * Description: + * + * Converts the Unix version in pathname to a Lisp syntax version. + * If there is no recognizable version present, and vlessp is not + * true then a Lisp version 1 (";1") will be added to the name. + * + * Initially only the "standard" .~nnn~ form of a version is recognized. + * It may be possible in the future to recognize IFS "!nnn" + */ + +void UnixVersionToLispVersion(char *pathname, size_t pathsize, int vlessp) { + char *ep = &pathname[strlen(pathname) - 1]; + char *uvp; + +#ifdef IFSVERSION + if (isdigit(*ep)) goto maybeifsversion; /* possibly foo!## */ +#endif + if (*ep-- != '~') goto noversion; /* definitely not .~###~ */ + if (!isdigit(*ep)) goto noversion; /* requires at least one digit */ + while (isdigit(*ep)) ep--; /* consume all digits */ + if (*ep-- != '~') goto noversion; /* definitely not .~###~ */ + if (*ep != '.') goto noversion; + /* must end .~###~ and ep points at the dot */ + *ep++ = ';'; /* smash . to ; and point to ~ where version will go*/ + for (uvp = ep + 1; *uvp == '0' && *(uvp + 1) != '~'; uvp++); /* skip leading zeroes */ + while (*uvp != '~') *ep++ = *uvp++; /* shift version back */ + *ep = '\0'; /* terminate the string */ + return; + noversion: + if (!vlessp) strlcat(pathname, ";1", pathsize); + return; +#ifdef IFSVERSION + maybeifsversion: + while (isdigit(*ep)) ep--; /* consume all digits */ + if (*ep != '!') goto noversion; + *ep = ';'; + return; +#endif +} + +/* + * Name: LispVersionToUnixVersion + * + * Arguments: char *pathname Xerox Lisp style pathname + * size_t pathsize Length of pathname buffer + * + * Helper procedure used by unixpathname to convert from a Lisp style path + * with ";version" style version number to the ".~version~" format used in + * the underlying host file system. + * If a syntactically correct version (all numeric, starting at the rightmost + * unescaped (') semicolon) is found it will be replaced by the host version, + * otherwise the procedure will return the pathname unchanged. + * + */ +void LispVersionToUnixVersion(char *pathname, size_t pathsize) { + char version[VERSIONLEN] = {0}; + char *vp = NULL; + char *ep = &pathname[strlen(pathname) - 1]; /* from the end */ + while (ep >= pathname) { /* until the beginning */ + if (*ep == ';' && /* found a semicolon */ + (ep == pathname || *(ep - 1) != '\'')) {/* at the beginning or not quoted */ + vp = ep; /* version starts at unquoted semicolon */ + break; /* stop when found version */ + } + ep--; /* previous character */ + } + + if (vp == NULL) return; /* there was no version field */ + + *vp++ = '\0'; /* end name at the semicolon */ + if (*vp == '\0') return; /* empty version field */ + + while (*vp == '0') vp++; /* skip leading zeros */ + if (*vp == '\0') return; /* all zero version is no version */ + version[0] = '.'; /* leading version marker */ + version[1] = '~'; /* leading version marker */ + strlcat(version, vp, VERSIONLEN); /* the trimmed version from the source */ + strlcat(version, "~", VERSIONLEN); /* trailing version marker */ + strlcat(pathname, version, pathsize); /* concatenate version to pathname */ + return; +} + /* * Name: unixpathname * @@ -511,7 +601,7 @@ int unixpathname(char *src, char *dst, size_t dstlen, int versionp, int genp) #ifdef DOS if (versionp) LispVersionToUnixVersion(lfname, version); else version = -1; #else - if (versionp) LispVersionToUnixVersion(lfname); + if (versionp) LispVersionToUnixVersion(lfname, sizeof(lfname)); #endif /* DOS */ cp = lfname; @@ -1099,7 +1189,7 @@ int lisppathname(char *fullname, char *lispname, size_t lispnamesize, int dirp, /* * Now, it's time to convert the version field. */ - if (!dirp && versionp) UnixVersionToLispVersion(namebuf, 0); + if (!dirp && versionp) UnixVersionToLispVersion(namebuf, sizeof(namebuf), 0); strlcpy(lispname, namebuf, lispnamesize); return (1);