findfile: Mark as "const" read only arguments
authorAlexey Gladkov <gladkov.alexey@gmail.com>
Mon, 24 Sep 2012 15:05:57 +0000 (19:05 +0400)
committerAlexey Gladkov <gladkov.alexey@gmail.com>
Mon, 24 Sep 2012 15:05:57 +0000 (19:05 +0400)
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
src/findfile.c
src/findfile.h
src/loadkeys.analyze.l
src/loadkeys.c
src/loadunimap.c
src/mapscrn.c
src/resizecons.c
src/setfont.c

index 2feb8a2..c2c3eee 100644 (file)
@@ -23,8 +23,8 @@ void fpclose(lkfile_t *fp)
 #define SIZE(a) (sizeof(a)/sizeof(a[0]))
 
 static struct decompressor {
-       char *ext;              /* starts with `.', has no other dots */
-       char *cmd;
+       const char *ext; /* starts with `.', has no other dots */
+       const char *cmd;
 } decompressors[] = {
        { ".gz", "gzip -d -c" },
        { ".bz2", "bzip2 -d -c" },
@@ -32,7 +32,7 @@ static struct decompressor {
 };
 
 static int
-pipe_open(struct decompressor *dc, lkfile_t *fp)
+pipe_open(const struct decompressor *dc, lkfile_t *fp)
 {
        char *pipe_cmd;
 
@@ -82,9 +82,9 @@ maybe_pipe_open(lkfile_t *fp)
 }
 
 static int
-findfile_by_fullname(const char *fnam, char **suffixes, lkfile_t *fp)
+findfile_by_fullname(const char *fnam, const char *const *suffixes, lkfile_t *fp)
 {
-       char **sp;
+       int i;
        struct stat st;
        struct decompressor *dc;
        size_t fnam_len, sp_len;
@@ -92,16 +92,16 @@ findfile_by_fullname(const char *fnam, char **suffixes, lkfile_t *fp)
        fp->pipe = 0;
        fnam_len = strlen(fnam);
 
-       for (sp = suffixes; *sp; sp++) {
-               if (*sp == 0)
+       for (i = 0; suffixes[i]; i++) {
+               if (suffixes[i] == 0)
                        continue; /* we tried it already */
 
-               sp_len = strlen(*sp);
+               sp_len = strlen(suffixes[i]);
 
                if (fnam_len + sp_len + 1 > sizeof(fp->pathname))
                        continue;
 
-               sprintf(fp->pathname, "%s%s", fnam, *sp);
+               sprintf(fp->pathname, "%s%s", fnam, suffixes[i]);
 
                if(stat(fp->pathname, &st) == 0
                   && S_ISREG(st.st_mode)
@@ -112,7 +112,7 @@ findfile_by_fullname(const char *fnam, char **suffixes, lkfile_t *fp)
                        if (fnam_len + sp_len + strlen(dc->ext) + 1 > sizeof(fp->pathname))
                                continue;
 
-                       sprintf(fp->pathname, "%s%s%s", fnam, *sp, dc->ext);
+                       sprintf(fp->pathname, "%s%s%s", fnam, suffixes[i], dc->ext);
 
                        if (stat(fp->pathname, &st) == 0
                            && S_ISREG(st.st_mode)
@@ -125,13 +125,14 @@ findfile_by_fullname(const char *fnam, char **suffixes, lkfile_t *fp)
 }
 
 static int
-findfile_in_dir(char *fnam, char *dir, int recdepth, char **suf, lkfile_t *fp)
+findfile_in_dir(const char *fnam, const char *dir, const int recdepth, const char *const *suf, lkfile_t *fp)
 {
        DIR *d;
        struct dirent *de;
-       char *ff, *fdir, *p, *q, **sp;
+       char *ff, *fdir, *p;
+       const char *q;
        struct decompressor *dc;
-       int rc = -1, secondpass = 0;
+       int i, rc = -1, secondpass = 0;
        size_t dir_len;
 
        fp->fd = NULL;
@@ -214,16 +215,16 @@ StartScan:
 
            /* Does tail consist of a known suffix and possibly
               a compression suffix? */
-           for(sp = suf; *sp; sp++) {
+           for(i = 0; suf[i]; i++) {
                    size_t l;
 
-                   if (!strcmp(p, *sp)) {
+                   if (!strcmp(p, suf[i])) {
                        rc = maybe_pipe_open(fp);
                        goto EndScan;
                    }
 
-                   l = strlen(*sp);
-                   if (!strncmp(p, *sp, l)) {
+                   l = strlen(suf[i]);
+                   if (!strncmp(p, suf[i], l)) {
                        for (dc = &decompressors[0]; dc->cmd; dc++)
                            if (strcmp(p+l, dc->ext) == 0) {
                                rc = pipe_open(dc, fp);
@@ -247,10 +248,10 @@ EndScan:
 }
 
 int
-findfile(char *fnam, char **dirpath, char **suffixes, lkfile_t *fp)
+findfile(const char *fnam, const char *const *dirpath, const char *const *suffixes, lkfile_t *fp)
 {
-       char **dp, *dir;
-       int dl, recdepth, rc;
+       char *dir;
+       int dl, recdepth, rc, i;
 
        fp->fd = NULL;
        fp->pipe = 0;
@@ -268,20 +269,20 @@ findfile(char *fnam, char **dirpath, char **suffixes, lkfile_t *fp)
                return 0;
 
        /* Search a list of directories and directory hierarchies */
-       for (dp = dirpath; *dp; dp++) {
+       for (i = 0; dirpath[i]; i++) {
                recdepth = 0;
-               dl = strlen(*dp);
+               dl = strlen(dirpath[i]);
 
                /* trailing stars denote recursion */
-               while (dl && (*dp)[dl-1] == '*')
+               while (dl && dirpath[i][dl-1] == '*')
                        dl--, recdepth++;
 
                /* delete trailing slashes */
-               while (dl && (*dp)[dl-1] == '/')
+               while (dl && dirpath[i][dl-1] == '/')
                        dl--;
 
                if (dl)
-                       dir = strndup(*dp, dl);
+                       dir = strndup(dirpath[i], dl);
                else
                        dir = strdup(".");
 
index fc6a8c8..f1663eb 100644 (file)
@@ -10,6 +10,6 @@ typedef struct lkfile {
 } lkfile_t;
 
 extern void fpclose(lkfile_t *fp);
-extern int findfile(char *fnam, char **dirpath, char **suffixes, lkfile_t *fp);
+extern int findfile(const char *fnam, const char *const *dirpath, const char *const *suffixes, lkfile_t *fp);
 
 #endif /* _FINDFILE_H */
index 95051f3..8cd9014 100644 (file)
@@ -96,20 +96,20 @@ stack_pop(struct keymap *kmap, void *scanner)
  * and afterwards use only "loadkeys /fullpath/mykeymap", where no
  * lookups are required.
  */
-static char *include_dirpath0[] = { "", 0 };
-static char *include_dirpath1[] = { "", "../include/", "../../include/", 0 };
-static char *include_dirpath2[] = { 0, 0, 0, 0 };
-static char *include_dirpath3[] = {
+static const char *const include_dirpath0[] = { "", 0 };
+static const char *const include_dirpath1[] = { "", "../include/", "../../include/", 0 };
+static const char *const include_dirpath3[] = {
        DATADIR "/" KEYMAPDIR "/include/",
        DATADIR "/" KEYMAPDIR "/i386/include/",
        DATADIR "/" KEYMAPDIR "/mac/include/", 0
 };
 
-static char *include_suffixes[] = { "", ".inc", 0 };
+static const char *const include_suffixes[] = { "", ".inc", 0 };
 
 static int
 find_incl_file_near_fn(struct keymap *kmap, char *s, char *fn, lkfile_t *fp)
 {
+       const char *include_dirpath2[] = { 0, 0, 0, 0 };
        char *t, *te, *t1, *t2;
        int len, rc = 1;
 
@@ -206,7 +206,7 @@ find_incl_file(struct keymap *kmap, char *s, lkfile_t *fp)
 
        if ((ev = getenv("LOADKEYS_INCLUDE_PATH")) != NULL) {
                /* try user-specified path */
-               char *user_dir[2] = { 0, 0 };
+               const char *user_dir[2] = { 0, 0 };
                while (ev) {
                        int rc;
                        char *t = strchr(ev, ':');
index 10a581f..433c48b 100644 (file)
 
 #include "loadkeys.keymap.h"
 
-const char *progname;
-
-char **dirpath;
-char *dirpath1[] = { "", DATADIR "/" KEYMAPDIR "/**", KERNDIR "/", 0 };
-char *dirpath2[] = { 0, 0 };
-char *suffixes[] = { "", ".kmap", ".map", 0 };
+static const char *progname = NULL;
+static const char *const dirpath1[] = { "", DATADIR "/" KEYMAPDIR "/**", KERNDIR "/", 0 };
+static const char *const suffixes[] = { "", ".kmap", ".map", 0 };
 
 static void attr_noreturn
 usage(void)
@@ -69,8 +66,8 @@ set_progname(const char *name)
 int
 main(int argc, char *argv[])
 {
-       const char *short_opts = "abcC:dhmsuqvV";
-       const struct option long_opts[] = {
+       const char *const short_opts = "abcC:dhmsuqvV";
+       const struct option const long_opts[] = {
                { "console", required_argument, NULL, 'C'},
                { "ascii",              no_argument, NULL, 'a' },
                { "bkeymap",            no_argument, NULL, 'b' },
@@ -95,6 +92,9 @@ main(int argc, char *argv[])
        };
        int options = 0;
 
+       const char *const *dirpath;
+       const char *dirpath2[] = { 0, 0 };
+
        struct keymap kmap;
 
        int c, i, rc = -1;
index b9dee6b..ccbdb68 100644 (file)
@@ -28,8 +28,8 @@
 extern char *progname;
 extern int force;
 
-static char *unidirpath[] = { "", DATADIR "/" UNIMAPDIR "/", 0 };
-static char *unisuffixes[] = { "", ".uni", ".sfm", 0 };
+static const char *const unidirpath[] = { "", DATADIR "/" UNIMAPDIR "/", 0 };
+static const char *const unisuffixes[] = { "", ".uni", ".sfm", 0 };
 
 #ifdef MAIN
 #include "version.h"
index 8a00bf1..40d297f 100644 (file)
@@ -25,8 +25,8 @@ void loadnewmap(int fd, char *mfil);
 static int ctoi (char *);
 
 /* search for the map file in these directories (with trailing /) */
-static char *mapdirpath[] = { "", DATADIR "/" TRANSDIR "/", 0 };
-static char *mapsuffixes[] = { "", ".trans", "_to_uni.trans", ".acm", 0 };
+static const char *const mapdirpath[] = { "", DATADIR "/" TRANSDIR "/", 0 };
+static const char *const mapsuffixes[] = { "", ".trans", "_to_uni.trans", ".acm", 0 };
 
 #ifdef MAIN
 #include "getfd.h"
index f681fa9..f0ddad4 100644 (file)
@@ -105,8 +105,8 @@ static int vga_get_fontheight(void);
 static void vga_set_cursor(int, int);
 static void vga_set_verticaldisplayend_lowbyte(int);
 
-char *dirpath[] = { "", DATADIR "/" VIDEOMODEDIR "/", 0};
-char *suffixes[] = { "", 0 };
+const char *const dirpath[] = { "", DATADIR "/" VIDEOMODEDIR "/", 0};
+const char *const suffixes[] = { "", 0 };
 
 int
 main(int argc, char **argv) {
index 58d9c34..7d4f473 100644 (file)
@@ -51,11 +51,11 @@ int force = 0;
 int debug = 0;
 
 /* search for the font in these directories (with trailing /) */
-char *fontdirpath[] = { "", DATADIR "/" FONTDIR "/", 0 };
-char *fontsuffixes[] = { "", ".psfu", ".psf", ".cp", ".fnt", 0 };
+const char *const fontdirpath[] = { "", DATADIR "/" FONTDIR "/", 0 };
+const char *const fontsuffixes[] = { "", ".psfu", ".psf", ".cp", ".fnt", 0 };
 /* hide partial fonts a bit - loading a single one is a bad idea */
-char *partfontdirpath[] = { "", DATADIR "/" FONTDIR "/" PARTIALDIR "/", 0 };
-char *partfontsuffixes[] = { "", 0 };
+const char *const partfontdirpath[] = { "", DATADIR "/" FONTDIR "/" PARTIALDIR "/", 0 };
+const char *const partfontsuffixes[] = { "", 0 };
 
 static inline int
 findfont(char *fnam, lkfile_t *fp) {