]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/setup/keymap.c
1 /* SmoothWall setup program.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Stuff for setting the keymap.
9 * $Id: keymap.c,v 1.9.2.1 2004/04/14 22:05:41 gespinasse Exp $
15 #define _(x) dgettext("setup", x)
24 #define MAX_FILENAMES 5000
25 #define KEYMAPROOT "/lib/kbd/keymaps/i386/"
27 static int filenamecount
;
28 static char *filenames
[MAX_FILENAMES
];
29 static char *displaynames
[MAX_FILENAMES
];
31 static int process(char *prefix
, char *path
);
32 static int cmp(const void *s1
, const void *s2
);
34 int handlekeymap(void)
39 struct keyvalue
*kv
= initkeyvalues();
42 char keymap
[STRING_SIZE
];
43 char commandstring
[STRING_SIZE
];
47 process(KEYMAPROOT
"azerty", "");
48 process(KEYMAPROOT
"dvorak", "");
49 process(KEYMAPROOT
"fgGIod", "");
50 process(KEYMAPROOT
"qwerty", "");
51 process(KEYMAPROOT
"qwertz", "");
52 filenames
[filenamecount
] = NULL
;
53 qsort(filenames
, filenamecount
, sizeof(char *), cmp
);
55 for (c
= 0; filenames
[c
]; c
++)
57 displaynames
[c
] = malloc(STRING_SIZE
);
58 if ((temp
= strrchr(filenames
[c
], '/')))
59 strcpy(displaynames
[c
], temp
+ 1);
61 strcpy(displaynames
[c
], filenames
[c
]);
62 if ((temp
= strstr(displaynames
[c
], ".map.gz")))
65 displaynames
[c
] = NULL
;
67 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/main/settings")))
70 errorbox(_("Unable to open settings file"));
74 strcpy(keymap
, "/lib/kbd/keymaps/i386/qwerty/us.map.gz");
75 findkey(kv
, "KEYMAP", keymap
);
78 for (c
= 0; filenames
[c
]; c
++)
80 if (strcmp(keymap
, filenames
[c
]) == 0)
84 rc
= newtWinMenu(_("Keyboard mapping"),
85 _("Choose the type of keyboard you are using from the list below."),
86 50, 5, 5, 6, displaynames
, &choice
, _("OK"), _("Cancel"), NULL
);
88 strcpy(keymap
, filenames
[choice
]);
92 replacekeyvalue(kv
, "KEYMAP", keymap
);
93 writekeyvalues(kv
, CONFIG_ROOT
"/main/settings");
94 sprintf(commandstring
, "/bin/loadkeys %s", keymap
);
95 mysystem(NULL
, commandstring
);
101 for (c
= 0; filenames
[c
]; c
++)
104 free(displaynames
[c
]);
111 static int process(char *prefix
, char *path
)
115 char newpath
[PATH_MAX
];
117 snprintf(newpath
, PATH_MAX
, "%s%s", prefix
, path
);
119 if (!(dir
= opendir(newpath
)))
121 if (filenamecount
> MAX_FILENAMES
)
124 filenames
[filenamecount
] = (char *) strdup(newpath
);
129 while ((de
= readdir(dir
)))
131 if (de
->d_name
[0] == '.') continue;
132 snprintf(newpath
, PATH_MAX
, "%s/%s", path
, de
->d_name
);
133 process(prefix
, newpath
);
140 /* Small wrapper for use with qsort() to sort filename part. */
141 static int cmp(const void *s1
, const void *s2
)
143 /* c1 and c2 are copies. */
144 char *c1
= strdup(* (char **) s1
);
145 char *c2
= strdup(* (char **) s2
);
146 /* point to somewhere in cN. */
151 if ((temp
= strrchr(c1
, '/')))
155 if ((temp
= strrchr(c2
, '/')))
160 if ((temp
= strchr(f1
, '.')))
162 if ((temp
= strchr(f2
, '.')))
165 res
= strcmp(f1
, f2
);