1212#include <limits.h> /* for NAME_MAX */
1313#include <dirent.h> /* for MAXNAMLEN */
1414#include "lispemul.h" /* for DLword */
15+ #include "commondefs.h" /* for error */
1516
1617#define FDEV_PAGE_SIZE 512 /* 1 page == 512 byte */
1718
4445 /* For getfileinfo. For WDATE&RDATE */
4546 /* 29969152 == (timer.c)LISP_UNIX_TIME_DIFF */
4647
47- #define StrNCpyFromCToLisp (lispbuf , cbuf ,len ) do { \
48- char *lf_sptr = (cbuf); \
49- char *lf_dptr = (lispbuf); \
50- for(size_t lf_i=0;lf_i<(len);lf_i++)\
51- GETBYTE(lf_dptr++) = *lf_sptr++; \
52- } while (0)
53-
54- #define StrNCpyFromLispToC (cbuf , lispbuf , len ) do { \
55- char *lf_sptr = (lispbuf); \
56- char *lf_dptr = (cbuf); \
57- for(size_t lf_i=0;lf_i<(len);lf_i++)\
58- *lf_dptr++ = GETBYTE(lf_sptr++); \
48+ /*
49+ * Copy memory between native memory locations accounting for potential
50+ * byte-swapping necessary when then destination is within Lisp memory space
51+ * though the provided destination pointer is a native address within the
52+ * Lisp space.
53+ */
54+ #define MemCpyToLispFromNative (lispbuf , cbuf , len ) \
55+ do { \
56+ char *lf_sptr = (cbuf); \
57+ char *lf_dptr = (lispbuf); \
58+ for (size_t lf_i = 0; lf_i < (len); lf_i++) *BYTEPTR(lf_dptr++) = *lf_sptr++; \
5959 } while (0)
6060
6161#define FGetNum (ptr , place ) do { \
6464 else {return(NIL);}} while (0)
6565
6666
67+ #ifndef min
68+ #define min (a , b ) (((a) <= (b))?(a):(b))
69+ #endif /* min */
70+
6771/************************************************************************/
6872/* */
6973/* L i s p S t r i n g T o C S t r i n g */
7983/* */
8084/************************************************************************/
8185#ifndef BYTESWAP
82- #define LispStringToCString (Lisp , C , MaxLen ) \
83- do { \
84- OneDArray *lf_arrayp; \
85- char *lf_base, *lf_dp; \
86- short *lf_sbase; \
87- size_t lf_length; \
88- lf_arrayp = (OneDArray *)NativeAligned4FromLAddr(Lisp); \
89- lf_length = min(MaxLen, lf_arrayp->fillpointer); \
90- switch(lf_arrayp->typenumber) \
91- { \
92- case THIN_CHAR_TYPENUMBER: \
93- lf_base = ((char *)(NativeAligned2FromLAddr(lf_arrayp->base))) \
94- + ((int)(lf_arrayp->offset)); \
95- strncpy(C, lf_base, lf_length); \
96- (C)[lf_length] = '\0'; \
97- break; \
98- \
99- case FAT_CHAR_TYPENUMBER: \
100- lf_sbase = ((short *)(NativeAligned2FromLAddr(lf_arrayp->base))) \
101- + ((int)(lf_arrayp->offset)); \
102- lf_dp = C; \
103- for(size_t lf_i=0;lf_i<(lf_length);lf_i++) \
104- *lf_dp++ = (char)(*lf_sbase++); \
105- *lf_dp = '\0'; \
106- break; \
107- default: \
108- error("LispStringToCString: Not a character array.\n"); \
109- } \
110- } while (0)
86+ static void LispStringToCString (LispPTR Lisp , char * C , size_t MaxLen ) {
87+ OneDArray * lf_arrayp ;
88+ char * lf_base , * lf_dp ;
89+ short * lf_sbase ;
90+ size_t lf_length ;
91+ lf_arrayp = (OneDArray * )NativeAligned4FromLAddr (Lisp );
92+ lf_length = min (MaxLen - 1 , lf_arrayp -> fillpointer );
93+ lf_dp = (C );
94+ switch (lf_arrayp -> typenumber ) {
95+ case THIN_CHAR_TYPENUMBER :
96+ lf_base = ((char * )(NativeAligned2FromLAddr (lf_arrayp -> base ))) + ((int )(lf_arrayp -> offset ));
97+ strncpy (lf_dp , lf_base , lf_length );
98+ lf_dp [lf_length ] = '\0' ;
99+ break ;
100+
101+ case FAT_CHAR_TYPENUMBER :
102+ lf_sbase = ((short * )(NativeAligned2FromLAddr (lf_arrayp -> base ))) + ((int )(lf_arrayp -> offset ));
103+ for (size_t lf_i = 0 ; lf_i < (lf_length ); lf_i ++ ) * lf_dp ++ = (char )(* lf_sbase ++ );
104+ * lf_dp = '\0' ;
105+ break ;
106+ default : error ("LispStringToCString: Not a character array.\n" );
107+ }
108+ }
111109#else /* BYTESWAP == T CHANGED-BY-TAKE */
112- #define LispStringToCString (Lisp , C , MaxLen ) \
113- do { \
114- OneDArray *lf_arrayp; \
115- char *lf_base, *lf_dp; \
116- short *lf_sbase; \
117- size_t lf_length; \
118- lf_arrayp = (OneDArray *)(NativeAligned4FromLAddr(Lisp)); \
119- lf_length = min(MaxLen, lf_arrayp->fillpointer); \
120- switch(lf_arrayp->typenumber) \
121- { \
122- case THIN_CHAR_TYPENUMBER: \
123- lf_base = ((char *)(NativeAligned2FromLAddr(lf_arrayp->base))) \
124- + ((int)(lf_arrayp->offset)); \
125- StrNCpyFromLispToC(C , lf_base , lf_length ); \
126- (C)[lf_length] = '\0'; \
127- break; \
128- \
129- case FAT_CHAR_TYPENUMBER: \
130- lf_sbase = ((short *)(NativeAligned2FromLAddr(lf_arrayp->base))) \
131- + ((int)(lf_arrayp->offset)); \
132- lf_dp = C; \
133- for(size_t lf_ii=0;lf_ii<(lf_length);lf_ii++,lf_sbase++) \
134- *lf_dp++ = (char)(GETWORD(lf_sbase)); \
135- *lf_dp = '\0'; \
136- break; \
137- default: \
138- error("LispStringToCString: Not a character array.\n"); \
139- } \
140- } while (0)
110+ static void LispStringToCString (LispPTR Lisp , char * C , size_t MaxLen ) {
111+ OneDArray * lf_arrayp ;
112+ char * lf_base , * lf_dp ;
113+ short * lf_sbase ;
114+ size_t lf_length ;
115+ lf_arrayp = (OneDArray * )(NativeAligned4FromLAddr (Lisp ));
116+ lf_length = min (MaxLen - 1 , lf_arrayp -> fillpointer );
117+ lf_dp = (C );
118+ switch (lf_arrayp -> typenumber ) {
119+ case THIN_CHAR_TYPENUMBER :
120+ lf_base = ((char * )(NativeAligned2FromLAddr (lf_arrayp -> base ))) + ((int )(lf_arrayp -> offset ));
121+ for (size_t lf_i = 0 ; lf_i < lf_length ; lf_i ++ ) * lf_dp ++ = GETBYTE (lf_base ++ );
122+ break ;
123+
124+ case FAT_CHAR_TYPENUMBER :
125+ lf_sbase = ((short * )(NativeAligned2FromLAddr (lf_arrayp -> base ))) + ((int )(lf_arrayp -> offset ));
126+ for (size_t lf_ii = 0 ; lf_ii < lf_length ; lf_ii ++ ) * lf_dp ++ = (char )(GETWORD (lf_sbase ++ ));
127+ break ;
128+ default : error ("LispStringToCString: Not a character array.\n" );
129+ }
130+ * lf_dp = '\0' ;
131+ }
141132
142133#endif /* BYTESWAP */
143134
@@ -189,10 +180,6 @@ do { \
189180 (cstringp) = (char *)(NativeAligned2FromLAddr(((OneDArray *)lf_naddress)->base)); \
190181 } while (0)
191182
192- #ifndef min
193- #define min (a , b ) (((a) <= (b))?(a):(b))
194- #endif /* min */
195-
196183#define LispNumToCInt (Lisp ) \
197184 ( (((Lisp) & SEGMASK) == S_POSITIVE) ? ((Lisp) & 0xFFFF) : \
198185 (((Lisp) & SEGMASK) == S_NEGATIVE) ? ((Lisp) | 0xFFFF0000) : \
@@ -299,7 +286,7 @@ do { \
299286 * Argument: char *pathname
300287 * Xerox Lisp syntax pathname.
301288 *
302- * Value: If succeed, returns 1, otherwise 0.
289+ * Value: On success returns 1, otherwise 0.
303290 *
304291 * Side Effect: The version part of pathname is destructively modified.
305292 *
@@ -312,7 +299,7 @@ do { \
312299 * code.
313300 * This macro should be called at the top of the routines which accept the
314301 * file name from lisp before converting it into UNIX file name, because
315- * locating the version part, the informations about quoted characters are needed.
302+ * locating the version part, the information about quoted characters are needed.
316303 * They might be lost in the course of the conversion.
317304 *
318305 */
@@ -337,19 +324,18 @@ do { \
337324 * If 0, versionless file is converted to version 1.
338325 * Otherwise, remains as versionless.
339326 *
340- * Value: If succeed, returns 1, otherwise 0.
327+ * Value: On success returns 1, otherwise 0.
341328 *
342329 * Side Effect: The version part of pathname is destructively modified.
343330 *
344331 * Description:
345332 *
346- * Destructively modify the version part of pathname which is following the
333+ * Destructively modifies the version part of pathname which is following the
347334 * UNIX file naming convention to Xerox Lisp one.
348335 * This macro should be called, in the routines which convert the UNIX pathname
349336 * 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
337+ * version field will append a semicolon which may confuse the routine
338+ * The file which does not have a valid version field, that is ".~##~" form, is
353339 * dealt with as version 1.
354340 */
355341
0 commit comments