]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - src/install+setup/setup/keymap.c
Reset default keymap to us.
[people/teissler/ipfire-2.x.git] / src / install+setup / setup / keymap.c
index 5fec1e28b9199477b3aee786d31ac517718585ae..b143492a1345df4a07d3968c79cf6b972765581c 100644 (file)
-/* SmoothWall setup program.\r
- *\r
- * This program is distributed under the terms of the GNU General Public\r
- * Licence.  See the file COPYING for details.\r
- *\r
- * (c) Lawrence Manning, 2001\r
- * Stuff for setting the keymap.\r
- * \r
- * $Id: keymap.c,v 1.9.2.1 2004/04/14 22:05:41 gespinasse Exp $\r
- * \r
- */\r
-   \r
-#include "setup.h"\r
\r
-extern FILE *flog;\r
-extern char *mylog;\r
-\r
-extern char **ctr;\r
-\r
-extern int automode;\r
-\r
-#define MAX_FILENAMES 5000\r
-#define KEYMAPROOT "/usr/share/kbd/keymaps/i386/"\r
-\r
-static int filenamecount;\r
-static char *filenames[MAX_FILENAMES];\r
-static char *displaynames[MAX_FILENAMES];\r
-\r
-static int process(char *prefix, char *path);\r
-static int cmp(const void *s1, const void *s2);\r
-\r
-int handlekeymap(void)\r
-{\r
-       int c;\r
-       int choice;\r
-       char *temp;\r
-       struct keyvalue *kv = initkeyvalues();  \r
-       int rc;\r
-       int result;\r
-       char keymap[STRING_SIZE];\r
-       char commandstring[STRING_SIZE];\r
-\r
-       filenamecount = 0;      \r
-\r
-       process(KEYMAPROOT "azerty", "");               \r
-       process(KEYMAPROOT "dvorak", "");\r
-       process(KEYMAPROOT "fgGIod", "");       \r
-       process(KEYMAPROOT "qwerty", "");\r
-       process(KEYMAPROOT "qwertz", "");\r
-       filenames[filenamecount] = NULL;\r
-       qsort(filenames, filenamecount, sizeof(char *), cmp);\r
-       \r
-       for (c = 0; filenames[c]; c++)\r
-       {\r
-               displaynames[c] = malloc(STRING_SIZE);\r
-               if ((temp = strrchr(filenames[c], '/')))\r
-                       strcpy(displaynames[c], temp + 1);\r
-               else\r
-                       strcpy(displaynames[c], filenames[c]);\r
-               if ((temp = strstr(displaynames[c], ".map.gz")))\r
-                       *temp = '\0';\r
-       }\r
-       displaynames[c] = NULL;\r
-       \r
-       if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))\r
-       {\r
-               freekeyvalues(kv);\r
-               errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);\r
-               return 0;\r
-       }       \r
-       \r
-       strcpy(keymap, "/usr/share/kbd/keymaps/i386/qwertz/de.map.gz");\r
-       findkey(kv, "KEYMAP", keymap);\r
-       \r
-       choice = 0;\r
-       for (c = 0; filenames[c]; c++)\r
-       {\r
-               if (strcmp(keymap, filenames[c]) == 0)\r
-                       choice = c;\r
-       }\r
-       \r
-       rc = newtWinMenu(ctr[TR_KEYBOARD_MAPPING], ctr[TR_KEYBOARD_MAPPING_LONG], 50, 5, 5, 6, displaynames, &choice,\r
-               ctr[TR_OK], ctr[TR_CANCEL], NULL);\r
-\r
-       strcpy(keymap, filenames[choice]);\r
-       \r
-       if (rc != 2)\r
-       {\r
-               replacekeyvalue(kv, "KEYMAP", keymap);\r
-               writekeyvalues(kv, CONFIG_ROOT "/main/settings");\r
-               sprintf(commandstring, "/bin/loadkeys %s", keymap);\r
-               mysystem(commandstring);\r
-               result = 1;\r
-       }\r
-       else\r
-               result = 0;     \r
-       \r
-       for (c = 0; filenames[c]; c++)\r
-       {\r
-               free(filenames[c]);\r
-               free(displaynames[c]);\r
-       }\r
-       freekeyvalues(kv);      \r
-       \r
-       return result;\r
-}\r
-\r
-static int process(char *prefix, char *path)\r
-{\r
-       DIR *dir;\r
-       struct dirent *de;\r
-       char newpath[PATH_MAX];\r
-       \r
-       snprintf(newpath, PATH_MAX, "%s%s", prefix, path);\r
-       \r
-       if (!(dir = opendir(newpath)))\r
-       {\r
-               if (filenamecount > MAX_FILENAMES)\r
-                       return 1;\r
-               \r
-               filenames[filenamecount] = (char *) strdup(newpath);\r
-               filenamecount++;\r
-               return 0;\r
-       }\r
-                       \r
-       while ((de = readdir(dir)))\r
-       {\r
-               if (de->d_name[0] == '.') continue;\r
-               snprintf(newpath, PATH_MAX, "%s/%s", path, de->d_name);\r
-               process(prefix, newpath);\r
-       }\r
-       closedir(dir);\r
-       \r
-       return 1;\r
-}\r
-\r
-/* Small wrapper for use with qsort() to sort filename part. */                \r
-static int cmp(const void *s1, const void *s2)\r
-{\r
-       /* c1 and c2 are copies. */\r
-       char *c1 = strdup(* (char **) s1);\r
-       char *c2 = strdup(* (char **) s2);\r
-       /* point to somewhere in cN. */\r
-       char *f1, *f2;\r
-       char *temp;\r
-       int res;\r
-       \r
-       if ((temp = strrchr(c1, '/')))\r
-               f1 = temp + 1;\r
-       else\r
-               f1 = c1;\r
-       if ((temp = strrchr(c2, '/')))\r
-               f2 = temp + 1;\r
-       else\r
-               f2 = c2;\r
-       /* bang off the . */\r
-       if ((temp = strchr(f1, '.')))\r
-               *temp = '\0';\r
-       if ((temp = strchr(f2, '.')))\r
-               *temp = '\0';\r
-       \r
-       res = strcmp(f1, f2);\r
-       \r
-       free(c1); free(c2);\r
-       \r
-       return res;\r
-}\r
+/* SmoothWall setup program.
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence.  See the file COPYING for details.
+ *
+ * (c) Lawrence Manning, 2001
+ * Stuff for setting the keymap.
+ * 
+ * $Id: keymap.c,v 1.9.2.1 2004/04/14 22:05:41 gespinasse Exp $
+ * 
+ */
+   
+#include "setup.h"
+extern FILE *flog;
+extern char *mylog;
+
+extern char **ctr;
+
+extern int automode;
+
+#define MAX_FILENAMES 5000
+#define KEYMAPROOT "/lib/kbd/keymaps/i386/"
+
+static int filenamecount;
+static char *filenames[MAX_FILENAMES];
+static char *displaynames[MAX_FILENAMES];
+
+static int process(char *prefix, char *path);
+static int cmp(const void *s1, const void *s2);
+
+int handlekeymap(void)
+{
+       int c;
+       int choice;
+       char *temp;
+       struct keyvalue *kv = initkeyvalues();  
+       int rc;
+       int result;
+       char keymap[STRING_SIZE];
+       char commandstring[STRING_SIZE];
+
+       filenamecount = 0;      
+
+       process(KEYMAPROOT "azerty", "");               
+       process(KEYMAPROOT "dvorak", "");
+       process(KEYMAPROOT "fgGIod", "");       
+       process(KEYMAPROOT "qwerty", "");
+       process(KEYMAPROOT "qwertz", "");
+       filenames[filenamecount] = NULL;
+       qsort(filenames, filenamecount, sizeof(char *), cmp);
+       
+       for (c = 0; filenames[c]; c++)
+       {
+               displaynames[c] = malloc(STRING_SIZE);
+               if ((temp = strrchr(filenames[c], '/')))
+                       strcpy(displaynames[c], temp + 1);
+               else
+                       strcpy(displaynames[c], filenames[c]);
+               if ((temp = strstr(displaynames[c], ".map.gz")))
+                       *temp = '\0';
+       }
+       displaynames[c] = NULL;
+       
+       if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
+       {
+               freekeyvalues(kv);
+               errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
+               return 0;
+       }       
+       
+       strcpy(keymap, "/lib/kbd/keymaps/i386/qwerty/us.map.gz");
+       findkey(kv, "KEYMAP", keymap);
+       
+       choice = 0;
+       for (c = 0; filenames[c]; c++)
+       {
+               if (strcmp(keymap, filenames[c]) == 0)
+                       choice = c;
+       }
+       
+       rc = newtWinMenu(ctr[TR_KEYBOARD_MAPPING], ctr[TR_KEYBOARD_MAPPING_LONG], 50, 5, 5, 6, displaynames, &choice,
+               ctr[TR_OK], ctr[TR_CANCEL], NULL);
+
+       strcpy(keymap, filenames[choice]);
+       
+       if (rc != 2)
+       {
+               replacekeyvalue(kv, "KEYMAP", keymap);
+               writekeyvalues(kv, CONFIG_ROOT "/main/settings");
+               sprintf(commandstring, "/bin/loadkeys %s", keymap);
+               mysystem(commandstring);
+               result = 1;
+       }
+       else
+               result = 0;     
+       
+       for (c = 0; filenames[c]; c++)
+       {
+               free(filenames[c]);
+               free(displaynames[c]);
+       }
+       freekeyvalues(kv);      
+       
+       return result;
+}
+
+static int process(char *prefix, char *path)
+{
+       DIR *dir;
+       struct dirent *de;
+       char newpath[PATH_MAX];
+       
+       snprintf(newpath, PATH_MAX, "%s%s", prefix, path);
+       
+       if (!(dir = opendir(newpath)))
+       {
+               if (filenamecount > MAX_FILENAMES)
+                       return 1;
+               
+               filenames[filenamecount] = (char *) strdup(newpath);
+               filenamecount++;
+               return 0;
+       }
+                       
+       while ((de = readdir(dir)))
+       {
+               if (de->d_name[0] == '.') continue;
+               snprintf(newpath, PATH_MAX, "%s/%s", path, de->d_name);
+               process(prefix, newpath);
+       }
+       closedir(dir);
+       
+       return 1;
+}
+
+/* Small wrapper for use with qsort() to sort filename part. */                
+static int cmp(const void *s1, const void *s2)
+{
+       /* c1 and c2 are copies. */
+       char *c1 = strdup(* (char **) s1);
+       char *c2 = strdup(* (char **) s2);
+       /* point to somewhere in cN. */
+       char *f1, *f2;
+       char *temp;
+       int res;
+       
+       if ((temp = strrchr(c1, '/')))
+               f1 = temp + 1;
+       else
+               f1 = c1;
+       if ((temp = strrchr(c2, '/')))
+               f2 = temp + 1;
+       else
+               f2 = c2;
+       /* bang off the . */
+       if ((temp = strchr(f1, '.')))
+               *temp = '\0';
+       if ((temp = strchr(f2, '.')))
+               *temp = '\0';
+       
+       res = strcmp(f1, f2);
+       
+       free(c1); free(c2);
+       
+       return res;
+}