altos/scheme: apply const to places taking const strings.
authorKeith Packard <keithp@keithp.com>
Wed, 13 Dec 2017 01:54:03 +0000 (17:54 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 13 Dec 2017 02:09:11 +0000 (18:09 -0800)
Mostly printf and friends.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/scheme/ao_scheme.h
src/scheme/ao_scheme_builtin.c
src/scheme/ao_scheme_error.c
src/scheme/ao_scheme_make_builtin
src/scheme/ao_scheme_make_const.c

index db4417e5249ed3ffabac3622f0edaf0580d44648..7e4b36973af6db382a162e219e586221b4463161 100644 (file)
@@ -63,7 +63,7 @@ extern uint8_t ao_scheme_const[AO_SCHEME_POOL_CONST] __attribute__((aligned(4)))
 #define ao_scheme_pool ao_scheme_const
 #define AO_SCHEME_POOL AO_SCHEME_POOL_CONST
 
-#define _atom(n) ao_scheme_atom_poly(ao_scheme_atom_intern(n))
+#define _atom(n) ao_scheme_atom_poly(ao_scheme_atom_intern((char *) n))
 #define _bool(v) ao_scheme_bool_poly(ao_scheme_bool_get(v))
 
 #define _ao_scheme_bool_true   _bool(1)
@@ -940,19 +940,19 @@ ao_scheme_stack_eval(void);
 /* error */
 
 void
-ao_scheme_vprintf(char *format, va_list args);
+ao_scheme_vprintf(const char *format, va_list args);
 
 void
-ao_scheme_printf(char *format, ...);
+ao_scheme_printf(const char *format, ...);
 
 void
-ao_scheme_error_poly(char *name, ao_poly poly, ao_poly last);
+ao_scheme_error_poly(const char *name, ao_poly poly, ao_poly last);
 
 void
-ao_scheme_error_frame(int indent, char *name, struct ao_scheme_frame *frame);
+ao_scheme_error_frame(int indent, const char *name, struct ao_scheme_frame *frame);
 
 ao_poly
-ao_scheme_error(int error, char *format, ...);
+ao_scheme_error(int error, const char *format, ...);
 
 /* builtins */
 
index c0f636fa78b58a5592ff97d655d509976a47e8ac..4def57045bbea9c56d77a34936941c644cf5805f 100644 (file)
@@ -52,7 +52,7 @@ char *ao_scheme_args_name(uint8_t args) {
        case AO_SCHEME_FUNC_LAMBDA: return ao_scheme_poly_atom(_ao_scheme_atom_lambda)->name;
        case AO_SCHEME_FUNC_NLAMBDA: return ao_scheme_poly_atom(_ao_scheme_atom_nlambda)->name;
        case AO_SCHEME_FUNC_MACRO: return ao_scheme_poly_atom(_ao_scheme_atom_macro)->name;
-       default: return "???";
+       default: return (char *) "???";
        }
 }
 #else
@@ -64,7 +64,7 @@ static char *
 ao_scheme_builtin_name(enum ao_scheme_builtin_id b) {
        if (b < _builtin_last)
                return ao_scheme_poly_atom(builtin_names[b])->name;
-       return "???";
+       return (char *) "???";
 }
 
 static const ao_poly ao_scheme_args_atoms[] = {
@@ -79,7 +79,7 @@ ao_scheme_args_name(uint8_t args)
        args &= AO_SCHEME_FUNC_MASK;
        if (args < sizeof ao_scheme_args_atoms / sizeof ao_scheme_args_atoms[0])
                return ao_scheme_poly_atom(ao_scheme_args_atoms[args])->name;
-       return "(unknown)";
+       return (char *) "(unknown)";
 }
 #endif
 
index d580a2c0a9e643968429b750c3084538406f04be..c015c76a186d1de4d25ff6369871e1eff98a3c7c 100644 (file)
@@ -16,7 +16,7 @@
 #include <stdarg.h>
 
 void
-ao_scheme_error_poly(char *name, ao_poly poly, ao_poly last)
+ao_scheme_error_poly(const char *name, ao_poly poly, ao_poly last)
 {
        int first = 1;
        printf("\t\t%s(", name);
@@ -50,7 +50,7 @@ static void tabs(int indent)
 }
 
 void
-ao_scheme_error_frame(int indent, char *name, struct ao_scheme_frame *frame)
+ao_scheme_error_frame(int indent, const char *name, struct ao_scheme_frame *frame)
 {
        int                     f;
 
@@ -83,7 +83,7 @@ ao_scheme_error_frame(int indent, char *name, struct ao_scheme_frame *frame)
 }
 
 void
-ao_scheme_vprintf(char *format, va_list args)
+ao_scheme_vprintf(const char *format, va_list args)
 {
        char c;
 
@@ -112,7 +112,7 @@ ao_scheme_vprintf(char *format, va_list args)
 }
 
 void
-ao_scheme_printf(char *format, ...)
+ao_scheme_printf(const char *format, ...)
 {
        va_list args;
        va_start(args, format);
@@ -121,7 +121,7 @@ ao_scheme_printf(char *format, ...)
 }
 
 ao_poly
-ao_scheme_error(int error, char *format, ...)
+ao_scheme_error(int error, const char *format, ...)
 {
        va_list args;
 
index 78f97789de4eddd08763f0a27e923dbede6d73c9..a4d8326ff904c332624e16e92178e8b764b9f68d 100644 (file)
@@ -101,7 +101,7 @@ dump_casename(builtin_t[*] builtins) {
                               builtins[i].c_name, builtins[i].lisp_names[0]);
                        dump_endif(builtins[i]);
                }
-       printf("\tdefault: return \"???\";\n");
+       printf("\tdefault: return (char *) \"???\";\n");
        printf("\t}\n");
        printf("}\n");
        printf("#endif /* AO_SCHEME_BUILTIN_CASENAME */\n");
index 6bd552f5aed29d2dc71addc2aca258c1a5883558..d0a51ec8e9554846f8b5733bf16ff0845e2644c7 100644 (file)
@@ -30,15 +30,15 @@ ao_scheme_make_builtin(enum ao_scheme_builtin_id func, int args) {
 }
 
 struct builtin_func {
-       char    *feature;
-       char    *name;
-       int     args;
+       const char      *feature;
+       const char      *name;
+       int             args;
        enum ao_scheme_builtin_id       func;
 };
 
 struct builtin_atom {
-       char    *feature;
-       char    *name;
+       const char      *feature;
+       const char      *name;
 };
 
 #define AO_SCHEME_BUILTIN_CONSTS
@@ -306,8 +306,8 @@ ao_scheme_add_feature(struct feature **list, char *name)
        *list = feature;
 }
 
-bool
-ao_scheme_has_feature(struct feature *list, char *name)
+static bool
+ao_scheme_has_feature(struct feature *list, const char *name)
 {
        while (list) {
                if (!strcmp(list->name, name))
@@ -317,17 +317,20 @@ ao_scheme_has_feature(struct feature *list, char *name)
        return false;
 }
 
-void
-ao_scheme_add_features(struct feature **list, char *names)
+static void
+ao_scheme_add_features(struct feature **list, const char *names)
 {
        char    *saveptr = NULL;
        char    *name;
+       char    *copy = strdup(names);
+       char    *save = copy;
 
-       while ((name = strtok_r(names, ",", &saveptr)) != NULL) {
-               names = NULL;
+       while ((name = strtok_r(copy, ",", &saveptr)) != NULL) {
+               copy = NULL;
                if (!ao_scheme_has_feature(*list, name))
                        ao_scheme_add_feature(list, name);
        }
+       free(save);
 }
 
 int
@@ -407,7 +410,7 @@ main(int argc, char **argv)
                                 */
                                func_map[prev_func] = target_func++;
                        }
-                       a = ao_scheme_atom_intern(funcs[f].name);
+                       a = ao_scheme_atom_intern((char *) funcs[f].name);
                        ao_scheme_atom_def(ao_scheme_atom_poly(a),
                                           ao_scheme_builtin_poly(b));
                }
@@ -474,32 +477,33 @@ main(int argc, char **argv)
        fprintf(out, "#define _ao_scheme_bool_true 0x%04x\n", ao_scheme_bool_poly(ao_scheme_true));
 
        for (a = ao_scheme_atoms; a; a = ao_scheme_poly_atom(a->next)) {
-               char    *n = a->name, c;
+               const char      *n = a->name;
+               char            ch;
                fprintf(out, "#define _ao_scheme_atom_");
-               while ((c = *n++)) {
-                       if (isalnum(c))
-                               fprintf(out, "%c", c);
+               while ((ch = *n++)) {
+                       if (isalnum(ch))
+                               fprintf(out, "%c", ch);
                        else
-                               fprintf(out, "%02x", c);
+                               fprintf(out, "%02x", ch);
                }
                fprintf(out, "  0x%04x\n", ao_scheme_atom_poly(a));
        }
        fprintf(out, "#ifdef AO_SCHEME_CONST_BITS\n");
        fprintf(out, "const uint8_t ao_scheme_const[AO_SCHEME_POOL_CONST] __attribute((aligned(4))) = {");
        for (o = 0; o < ao_scheme_top; o++) {
-               uint8_t c;
+               uint8_t ch;
                if ((o & 0xf) == 0)
                        fprintf(out, "\n\t");
                else
                        fprintf(out, " ");
-               c = ao_scheme_const[o];
+               ch = ao_scheme_const[o];
                if (!in_atom)
                        in_atom = is_atom(o);
                if (in_atom) {
-                       fprintf(out, " '%c',", c);
+                       fprintf(out, " '%c',", ch);
                        in_atom--;
                } else {
-                       fprintf(out, "0x%02x,", c);
+                       fprintf(out, "0x%02x,", ch);
                }
        }
        fprintf(out, "\n};\n");