#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" },
};
static int
-pipe_open(struct decompressor *dc, lkfile_t *fp)
+pipe_open(const struct decompressor *dc, lkfile_t *fp)
{
char *pipe_cmd;
}
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;
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)
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)
}
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;
/* 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);
}
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;
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(".");
} 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 */
* 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;
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, ':');
#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)
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' },
};
int options = 0;
+ const char *const *dirpath;
+ const char *dirpath2[] = { 0, 0 };
+
struct keymap kmap;
int c, i, rc = -1;
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"
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"
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) {
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) {