Skip to content

Commit 5a1ab15

Browse files
committed
Improves UnixVersionToLispVersion, LispVersionToUnixVersion and separate_version
* converts UnixVersionToLispVersion and LispVersionToUnixVersion from macros to procedures * recodes version parsing to work backwards from the end of the name/version instead of forwards touching every character in the name. * adds storage size parameters where necessary for string copies to be checked for overflow, and updates call sites and comments * obsoletes inc/lispver1.h and inc/lispver2.h and updates make dependencies
1 parent 2b909ff commit 5a1ab15

File tree

9 files changed

+167
-319
lines changed

9 files changed

+167
-319
lines changed

bin/makefile-dos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SRCFILES = conspage.c gcoflow.c shift.c dbgtool.c gcr.c gcrcell.c llstk.
1818
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)
1919

2020

21-
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
21+
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 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
2222

2323

2424

bin/makefile-tail

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ $(OBJECTDIR)car-cdr.o: $(SRCDIR)car-cdr.c $(REQUIRED-INCS) \
340340
$(OBJECTDIR)chardev.o: $(SRCDIR)chardev.c $(REQUIRED-INCS) \
341341
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
342342
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)timeout.h \
343-
$(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dbprint.h \
343+
$(INCDIR)locfile.h $(INCDIR)dbprint.h \
344344
$(INCDIR)chardevdefs.h $(INCDIR)byteswapdefs.h $(INCDIR)commondefs.h \
345345
$(INCDIR)perrnodefs.h
346346
$(CC) $(RFLAGS) $(SRCDIR)chardev.c -o $(OBJECTDIR)chardev.o
@@ -505,7 +505,7 @@ $(OBJECTDIR)dsk.o: $(SRCDIR)dsk.c $(REQUIRED-INCS) \
505505
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
506506
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h \
507507
$(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)arith.h $(INCDIR)stream.h \
508-
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)lispver2.h \
508+
$(INCDIR)timeout.h $(INCDIR)locfile.h \
509509
$(INCDIR)dbprint.h $(INCDIR)dskdefs.h $(INCDIR)byteswapdefs.h \
510510
$(INCDIR)car-cdrdefs.h $(INCDIR)cell.h $(INCDIR)commondefs.h \
511511
$(INCDIR)ufsdefs.h
@@ -515,15 +515,15 @@ $(OBJECTDIR)ufs.o: $(SRCDIR)ufs.c $(REQUIRED-INCS) \
515515
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
516516
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h \
517517
$(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)arith.h $(INCDIR)stream.h \
518-
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dbprint.h \
518+
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)dbprint.h \
519519
$(INCDIR)ufsdefs.h $(INCDIR)commondefs.h $(INCDIR)dskdefs.h
520520
$(CC) $(RFLAGS) $(SRCDIR)ufs.c -o $(OBJECTDIR)ufs.o
521521

522522
$(OBJECTDIR)dir.o: $(SRCDIR)dir.c $(REQUIRED-INCS) \
523523
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
524524
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)lspglob.h \
525525
$(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)timeout.h \
526-
$(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dirdefs.h \
526+
$(INCDIR)locfile.h $(INCDIR)dirdefs.h \
527527
$(INCDIR)commondefs.h $(INCDIR)dskdefs.h $(INCDIR)ufsdefs.h
528528
$(CC) $(RFLAGS) $(SRCDIR)dir.c -o $(OBJECTDIR)dir.o
529529

@@ -640,7 +640,7 @@ $(OBJECTDIR)inet.o: $(SRCDIR)inet.c $(REQUIRED-INCS) \
640640
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
641641
$(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)emlglob.h $(INCDIR)lspglob.h \
642642
$(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h $(INCDIR)adr68k.h \
643-
$(INCDIR)dbprint.h $(INCDIR)locfile.h $(INCDIR)lispver2.h \
643+
$(INCDIR)dbprint.h $(INCDIR)locfile.h \
644644
$(INCDIR)inetdefs.h $(INCDIR)byteswapdefs.h $(INCDIR)commondefs.h \
645645
$(INCDIR)mkcelldefs.h
646646
$(CC) $(RFLAGS) $(SRCDIR)inet.c -o $(OBJECTDIR)inet.o
@@ -758,7 +758,7 @@ $(OBJECTDIR)osmsg.o: $(SRCDIR)osmsg.c $(REQUIRED-INCS) \
758758
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
759759
$(INCDIR)adr68k.h $(INCDIR)lsptypes.h $(INCDIR)arith.h $(INCDIR)stream.h \
760760
$(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h \
761-
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)osmsgprint.h \
761+
$(INCDIR)timeout.h $(INCDIR)locfile.h $(INCDIR)osmsgprint.h \
762762
$(INCDIR)dbprint.h $(INCDIR)commondefs.h $(INCDIR)osmsgdefs.h
763763
$(CC) $(RFLAGS) $(SRCDIR)osmsg.c -o $(OBJECTDIR)osmsg.o
764764

@@ -865,7 +865,7 @@ $(OBJECTDIR)unixcomm.o: $(SRCDIR)unixcomm.c $(REQUIRED-INCS) \
865865
$(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h $(INCDIR)miscstat.h \
866866
$(INCDIR)cell.h $(INCDIR)stack.h $(INCDIR)arith.h $(INCDIR)dbprint.h \
867867
$(INCDIR)timeout.h $(INCDIR)unixcommdefs.h $(INCDIR)byteswapdefs.h \
868-
$(INCDIR)commondefs.h $(INCDIR)locfile.h $(INCDIR)lispver2.h
868+
$(INCDIR)commondefs.h $(INCDIR)locfile.h
869869
$(CC) $(RFLAGS) $(SRCDIR)unixcomm.c -o $(OBJECTDIR)unixcomm.o
870870

871871
$(OBJECTDIR)unixfork.o: $(SRCDIR)unixfork.c $(REQUIRED-INCS) \
@@ -888,7 +888,7 @@ $(OBJECTDIR)rpc.o: $(SRCDIR)rpc.c $(REQUIRED-INCS) \
888888
$(INCDIR)lispemul.h $(INCDIR)lispmap.h \
889889
$(INCDIR)lsptypes.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h \
890890
$(INCDIR)miscstat.h $(INCDIR)emlglob.h $(INCDIR)adr68k.h $(INCDIR)arith.h \
891-
$(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)rpcdefs.h \
891+
$(INCDIR)locfile.h $(INCDIR)rpcdefs.h \
892892
$(INCDIR)commondefs.h
893893
$(CC) $(RFLAGS) $(SRCDIR)rpc.c -o $(OBJECTDIR)rpc.o
894894

@@ -909,7 +909,7 @@ $(OBJECTDIR)vmemsave.o: $(SRCDIR)vmemsave.c $(REQUIRED-INCS) \
909909
$(INCDIR)lispemul.h \
910910
$(INCDIR)lispmap.h $(INCDIR)lspglob.h $(INCDIR)ifpage.h $(INCDIR)iopage.h \
911911
$(INCDIR)miscstat.h $(INCDIR)timeout.h $(INCDIR)adr68k.h \
912-
$(INCDIR)lsptypes.h $(INCDIR)locfile.h $(INCDIR)lispver2.h $(INCDIR)dbprint.h \
912+
$(INCDIR)lsptypes.h $(INCDIR)locfile.h $(INCDIR)dbprint.h \
913913
$(INCDIR)devif.h $(INCDIR)vmemsavedefs.h $(INCDIR)byteswapdefs.h $(INCDIR)commondefs.h \
914914
$(INCDIR)dskdefs.h $(INCDIR)initkbddefs.h $(INCDIR)perrnodefs.h \
915915
$(INCDIR)ufsdefs.h

inc/lispver1.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

inc/lispver2.h

Lines changed: 0 additions & 74 deletions
This file was deleted.

inc/locfile.h

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -281,135 +281,6 @@ do { \
281281

282282
#define SPECIALFILEMARK (-1)
283283

284-
#define NumericStringP(str, truetag, falsetag) do { \
285-
char *lfn_cp; \
286-
\
287-
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
288-
if (*(str) == '\0') goto falsetag; \
289-
\
290-
for(lfn_cp = str; *lfn_cp!='\0'; ++lfn_cp) \
291-
if(*lfn_cp < '0' || '9' < *lfn_cp) \
292-
goto falsetag; /* NOLINT(bugprone-macro-parentheses) */ \
293-
goto truetag; /* NOLINT(bugprone-macro-parentheses) */ \
294-
} while (0)
295-
296-
/*
297-
* Name: LispVersionToUnixVersion
298-
*
299-
* Argument: char *pathname
300-
* Xerox Lisp syntax pathname.
301-
*
302-
* Value: If succeed, returns 1, otherwise 0.
303-
*
304-
* Side Effect: The version part of pathname is destructively modified.
305-
*
306-
* Description:
307-
*
308-
* Destructively modify the version part of pathname which is following the
309-
* Xerox Lisp file naming convention to UNIX one.
310-
* If the file name which is passed from Lisp has the version part, it must be
311-
* a valid one (i.e. constructed with only number). This is guaranteed by Lisp
312-
* code.
313-
* This macro should be called at the top of the routines which accept the
314-
* file name from lisp before converting it into UNIX file name, because
315-
* locating the version part, the informations about quoted characters are needed.
316-
* They might be lost in the course of the conversion.
317-
*
318-
*/
319-
#ifdef DOS
320-
321-
/* DOS version of LispVersionToUnixVersion */
322-
/* * * * * This is done this way because DOS can't handle the non-DOS version -- */
323-
/* * * * * it gave "Too many characters in a character constant" errors! */
324-
#include "lispver1.h"
325-
#else /* DOS */
326-
/* NON-DOS version of the macro LispVersionToUnixVersion */
327-
#include "lispver2.h"
328-
#endif /* DOS */
329-
330-
331-
/*
332-
* Name: UnixVersionToLispVersion
333-
*
334-
* Argument: char *pathname
335-
* UNIX syntax pathname.
336-
* int vlessp
337-
* If 0, versionless file is converted to version 1.
338-
* Otherwise, remains as versionless.
339-
*
340-
* Value: If succeed, returns 1, otherwise 0.
341-
*
342-
* Side Effect: The version part of pathname is destructively modified.
343-
*
344-
* Description:
345-
*
346-
* Destructively modify the version part of pathname which is following the
347-
* UNIX file naming convention to Xerox Lisp one.
348-
* This macro should be called, in the routines which convert the UNIX pathname
349-
* to Lisp one, just before it returns the result to Lisp, because converting
350-
* version field will append a semicolon and it might make the routine be
351-
* confused.
352-
* The file which has not a valid version field, that is ".~##~" form, is
353-
* dealt with as version 1.
354-
*/
355-
356-
#define UnixVersionToLispVersion(pathname, vlessp) do { \
357-
\
358-
char *start; \
359-
char *end; \
360-
char *lf_cp; \
361-
int ver_no; \
362-
size_t len; \
363-
char ver_buf[VERSIONLEN]; \
364-
\
365-
if ((start = strchr(pathname, '~')) != NULL) { \
366-
/* First of all, find the version field in pathname. */ \
367-
end = start; \
368-
lf_cp = start + 1; \
369-
while (*lf_cp) { \
370-
if (*lf_cp == '~') { \
371-
start = end; \
372-
end = lf_cp; \
373-
lf_cp++; \
374-
} else { \
375-
lf_cp++; \
376-
} \
377-
} \
378-
\
379-
if (start != end && *(start - 1) == '.' && end == (lf_cp - 1)) { \
380-
/* \
381-
* pathname ends in the form ".~###~". But we \
382-
* check ### is a valid number or not. \
383-
*/ \
384-
len = (end - start) - 1; \
385-
strncpy(ver_buf, start + 1, len); \
386-
ver_buf[len] = '\0'; \
387-
NumericStringP(ver_buf, YES, NO); \
388-
YES: \
389-
*(start - 1) = ';'; \
390-
*start = '\0'; \
391-
*end = '\0'; \
392-
/* call strtoul() to eliminate leading 0s. */ \
393-
ver_no = strtoul(start + 1, (char **)NULL, 10); \
394-
sprintf(ver_buf, "%u", ver_no); \
395-
strcat(pathname, ver_buf); \
396-
goto CONT; \
397-
\
398-
NO: \
399-
/* Dealt with as version 1 unless vlessp */ \
400-
if (!(vlessp)) strcat(pathname, ";1"); \
401-
CONT: \
402-
lf_cp--; /* Just for label */ \
403-
} else { \
404-
/* Dealt with as version 1 unless vlessp. */ \
405-
if (!(vlessp)) strcat(pathname, ";1"); \
406-
} \
407-
} else { \
408-
/* Dealt with as version 1 unless vlessp. */ \
409-
if (!(vlessp)) strcat(pathname, ";1"); \
410-
} \
411-
} while (0)
412-
413284
#define VERSIONLEN 16
414285

415286
#define MAXVERSION 999999999

inc/ufsdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LispPTR UFS_getfilename(LispPTR *args);
55
LispPTR UFS_deletefile(LispPTR *args);
66
LispPTR UFS_renamefile(LispPTR *args);
77
LispPTR UFS_directorynamep(LispPTR *args);
8+
void UnixVersionToLispVersion(char *pathname, size_t pathsize, int vlessp);
89
#ifdef DOS
910
int unixpathname(char *src, char *dst, int dstlen, int versionp, int genp, char *drive, int *extlenptr, char *rawname);
1011
#else

src/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static int quote_fname(char *file, size_t filesize)
310310
} else {
311311
strlcpy(namebuf, fbuf, sizeof(namebuf));
312312
}
313-
UnixVersionToLispVersion(namebuf, 1);
313+
UnixVersionToLispVersion(namebuf, sizeof(namebuf), 1);
314314
strlcpy(file, namebuf, filesize);
315315
return (1);
316316
}

0 commit comments

Comments
 (0)