1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-02-04 07:33:07 +00:00

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
This commit is contained in:
Nick Briggs
2025-10-20 14:31:18 -07:00
parent 04ad740ead
commit 67f8cc0cf0
7 changed files with 108 additions and 173 deletions

View File

@@ -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 */

View File

@@ -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)

View File

@@ -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