diff options
Diffstat (limited to 'lisp/lisp.c')
-rw-r--r-- | lisp/lisp.c | 97 |
1 files changed, 51 insertions, 46 deletions
diff --git a/lisp/lisp.c b/lisp/lisp.c index 411240a..b999b8a 100644 --- a/lisp/lisp.c +++ b/lisp/lisp.c @@ -662,7 +662,7 @@ LispGetPageSize(void) } void -LispDestroy(char *fmt, ...) +LispDestroy(const char *fmt, ...) { static char Error[] = "*** "; @@ -720,7 +720,7 @@ LispDestroy(char *fmt, ...) LispTopLevel(); if (!lisp__data.running) { - static char Fatal[] = "*** Fatal: nowhere to longjmp.\n"; + static const char *Fatal = "*** Fatal: nowhere to longjmp.\n"; LispFputs(Stderr, Fatal); LispFflush(Stderr); @@ -731,11 +731,11 @@ LispDestroy(char *fmt, ...) } void -LispContinuable(char *fmt, ...) +LispContinuable(const char *fmt, ...) { va_list ap; char string[128]; - static char Error[] = "*** Error: "; + static const char *Error = "*** Error: "; if (Stderr->column) LispFputc(Stderr, '\n'); @@ -757,7 +757,7 @@ LispContinuable(char *fmt, ...) } void -LispMessage(char *fmt, ...) +LispMessage(const char *fmt, ...) { va_list ap; char string[128]; @@ -773,11 +773,11 @@ LispMessage(char *fmt, ...) } void -LispWarning(char *fmt, ...) +LispWarning(const char *fmt, ...) { va_list ap; char string[128]; - static char Warning[] = "*** Warning: "; + static const char *Warning = "*** Warning: "; if (Stderr->column) LispFputc(Stderr, '\n'); @@ -1229,7 +1229,7 @@ index_found: } char * -LispStrdup(char *str) +LispStrdup(const char *str) { char *ptr = LispMalloc(strlen(str) + 1); @@ -1264,7 +1264,7 @@ free_done: } LispObj * -LispSetVariable(LispObj *var, LispObj *val, char *fname, int eval) +LispSetVariable(LispObj *var, LispObj *val, const char *fname, int eval) { if (!SYMBOLP(var)) LispDestroy("%s: %s is not a symbol", fname, STROBJ(var)); @@ -1275,7 +1275,7 @@ LispSetVariable(LispObj *var, LispObj *val, char *fname, int eval) } int -LispRegisterOpaqueType(char *desc) +LispRegisterOpaqueType(const char *desc) { int length; LispOpaque *opaque; @@ -1317,7 +1317,7 @@ LispIntToOpaqueType(int type) } hash_key * -LispGetAtomKey(char *string, int perm) +LispGetAtomKey(const char *string, int perm) { int length; hash_entry *entry; @@ -1328,7 +1328,7 @@ LispGetAtomKey(char *string, int perm) entry = LispCalloc(1, sizeof(hash_entry)); entry->key = LispCalloc(1, sizeof(hash_key)); if (perm) - entry->key->value = string; + entry->key->value = (char *) string; else entry->key->value = LispStrdup(string); entry->key->length = length; @@ -1344,7 +1344,7 @@ LispGetAtomKey(char *string, int perm) } LispAtom * -LispDoGetAtom(char *str, int perm) +LispDoGetAtom(const char *str, int perm) { int length; LispAtom *atom; @@ -1618,13 +1618,13 @@ LispRemAtomStructProperty(LispAtom *atom) } LispAtom * -LispGetAtom(char *str) +LispGetAtom(const char *str) { return (LispDoGetAtom(str, 0)); } LispAtom * -LispGetPermAtom(char *str) +LispGetPermAtom(const char *str) { return (LispDoGetAtom(str, 1)); } @@ -1863,15 +1863,15 @@ LispListProtectedArguments(LispArgList *alist) } LispArgList * -LispCheckArguments(LispFunType type, LispObj *list, char *name, int builtin) +LispCheckArguments(LispFunType type, LispObj *list, const char *name, int builtin) { - static char *types[4] = {"LAMBDA-LIST", "FUNCTION", "MACRO", "SETF-METHOD"}; - static char *fnames[4] = {"LAMBDA", "DEFUN", "DEFMACRO", "DEFSETF"}; + static const char *types[4] = {"LAMBDA-LIST", "FUNCTION", "MACRO", "SETF-METHOD"}; + static const char *fnames[4] = {"LAMBDA", "DEFUN", "DEFMACRO", "DEFSETF"}; #define IKEY 0 #define IOPTIONAL 1 #define IREST 2 #define IAUX 3 - static char *keys[4] = {"&KEY", "&OPTIONAL", "&REST", "&AUX"}; + static const char *keys[4] = {"&KEY", "&OPTIONAL", "&REST", "&AUX"}; int rest, optional, key, aux, count; LispArgList *alist; LispObj *spec, *sform, *defval, *default_value; @@ -2633,7 +2633,7 @@ LispNew(LispObj *car, LispObj *cdr) } LispObj * -LispNewAtom(char *str, int intern) +LispNewAtom(const char *str, int intern) { LispObj *object; LispAtom *atom = LispDoGetAtom(str, 0); @@ -2661,7 +2661,7 @@ LispNewAtom(char *str, int intern) } LispObj * -LispNewStaticAtom(char *str) +LispNewStaticAtom(const char *str) { LispObj *object; LispAtom *atom = LispDoGetAtom(str, 1); @@ -2778,9 +2778,17 @@ LispNewDFloat(double value) } LispObj * -LispNewString(char *str, long length, int alloced) +LispNewString(const char *str, long length) +{ + char *cstring = LispMalloc(length + 1); + memcpy(cstring, str, length); + cstring[length] = '\0'; + return LispNewStringAlloced(cstring, length); +} + +LispObj * +LispNewStringAlloced(char *cstring, long length) { - char *cstring; LispObj *string = objseg.freeobj; if (string == NIL) @@ -2789,13 +2797,6 @@ LispNewString(char *str, long length, int alloced) objseg.freeobj = CDR(string); --objseg.nfree; } - if (alloced) - cstring = str; - else { - cstring = LispMalloc(length + 1); - memcpy(cstring, str, length); - cstring[length] = '\0'; - } LispMused(cstring); string->type = LispString_t; THESTR(string) = cstring; @@ -2976,7 +2977,7 @@ LispNewOpaque(void *data, int type) /* string argument must be static, or allocated */ LispObj * -LispNewKeyword(char *string) +LispNewKeyword(const char *string) { LispObj *keyword; @@ -3027,18 +3028,22 @@ LispNewPathname(LispObj *obj) } LispObj * -LispNewStringStream(char *string, int flags, long length, int alloced) +LispNewStringStream(const char *string, int flags, long length) +{ + char *newstring = LispMalloc(length + 1); + memcpy(newstring, string, length); + newstring[length] = '\0'; + + return LispNewStringStreamAlloced(newstring, flags, length); +} + +LispObj * +LispNewStringStreamAlloced(char *string, int flags, long length) { LispObj *stream = LispNew(NIL, NIL); SSTREAMP(stream) = LispCalloc(1, sizeof(LispString)); - if (alloced) - SSTREAMP(stream)->string = string; - else { - SSTREAMP(stream)->string = LispMalloc(length + 1); - memcpy(SSTREAMP(stream)->string, string, length); - SSTREAMP(stream)->string[length] = '\0'; - } + SSTREAMP(stream)->string = string; stream->type = LispStream_t; @@ -5012,7 +5017,7 @@ LispSignalHandler(int signum) void LispSignal(int signum) { - char *errstr; + const char *errstr; char buffer[32]; if (lisp__disable_int) { @@ -5387,15 +5392,15 @@ LispBegin(void) #ifdef LISPDIR { int length; - char *pathname = LISPDIR; + const char *pathname = LISPDIR; length = strlen(pathname); if (length && pathname[length - 1] != '/') { - pathname = LispMalloc(length + 2); + char *fixed_pathname = LispMalloc(length + 2); - strcpy(pathname, LISPDIR); - strcpy(pathname + length, "/"); - path = LSTRING2(pathname, length + 1); + strcpy(fixed_pathname, LISPDIR); + strcpy(fixed_pathname + length, "/"); + path = LSTRING2(fixed_pathname, length + 1); } else path = LSTRING(pathname, length); @@ -5447,7 +5452,7 @@ LispEnd(void) } void -LispSetPrompt(char *prompt) +LispSetPrompt(const char *prompt) { lisp__data.prompt = prompt; } |