[prev in list] [next in list] [prev in thread] [next in thread]
List: ipcop-svn
Subject: [Ipcop-svn] SF.net SVN: ipcop: [593] ipcop/trunk/src/installer
From: owes () users ! sourceforge ! net
Date: 2007-10-29 12:53:37
Message-ID: E1ImU7d-0006BH-6R () sc8-pr-svn4 ! sourceforge ! net
[Download RAW message or body]
Revision: 593
http://ipcop.svn.sourceforge.net/ipcop/?rev=593&view=rev
Author: owes
Date: 2007-10-29 05:53:36 -0700 (Mon, 29 Oct 2007)
Log Message:
-----------
Add keyboard selection to installer & setup
Add find_kv_default helper function
Modified Paths:
--------------
ipcop/trunk/src/installer/Makefile
ipcop/trunk/src/installer/common.h
ipcop/trunk/src/installer/helper.c
ipcop/trunk/src/installer/setup.c
Added Paths:
-----------
ipcop/trunk/src/installer/keymap.c
Modified: ipcop/trunk/src/installer/Makefile
===================================================================
--- ipcop/trunk/src/installer/Makefile 2007-10-29 11:24:37 UTC (rev 592)
+++ ipcop/trunk/src/installer/Makefile 2007-10-29 12:53:36 UTC (rev 593)
@@ -6,7 +6,7 @@
HEADERS = common.h
OBJS_INST = installer.o helper.o hardware.o language.o partition.o passwords.c
LIBS_INST = -lhd_tiny -lsysfs -lnewt -lslang
-OBJS_SETUP = setup.o helper.o hardware.o host_domain.o language.o passwords.o
+OBJS_SETUP = setup.o helper.o hardware.o host_domain.o keymap.o language.o \
passwords.o LIBS_SETUP = -lhd_tiny -lsysfs -lnewt -lslang
all: installer setup
Modified: ipcop/trunk/src/installer/common.h
===================================================================
--- ipcop/trunk/src/installer/common.h 2007-10-29 11:24:37 UTC (rev 592)
+++ ipcop/trunk/src/installer/common.h 2007-10-29 12:53:36 UTC (rev 593)
@@ -75,6 +75,8 @@
void add_kv (NODEKV **kvhead, char *key, char *value);
char* find_kv(NODEKV *p, char *key);
+/* value must be STRING_SIZE and can be a default value */
+int find_kv_default(NODEKV *p, char *key, char *value);
void update_kv (NODEKV **p, char *key, char *value);
void free_kv (NODEKV **p);
void read_kv_from_line(NODEKV **list, char *line);
Modified: ipcop/trunk/src/installer/helper.c
===================================================================
--- ipcop/trunk/src/installer/helper.c 2007-10-29 11:24:37 UTC (rev 592)
+++ ipcop/trunk/src/installer/helper.c 2007-10-29 12:53:36 UTC (rev 593)
@@ -142,6 +142,24 @@
return NULL;
}
+/* caller has already space reserved and maybe filled with a default value */
+int find_kv_default(NODEKV *p, char *key, char *value)
+{
+ while (p != NULL)
+ {
+ if (strcmp(p->item.key, key) == 0)
+ {
+ strncpy(value, p->item.value, STRING_SIZE);
+ value[STRING_SIZE-1] = '\0';
+ return 1;
+ }
+
+ p = p->next;
+ }
+
+ return 0;
+}
+
/* Update a key or insert it */
void update_kv (NODEKV **p, char *key, char *value)
{
Added: ipcop/trunk/src/installer/keymap.c
===================================================================
--- ipcop/trunk/src/installer/keymap.c (rev 0)
+++ ipcop/trunk/src/installer/keymap.c 2007-10-29 12:53:36 UTC (rev 593)
@@ -0,0 +1,170 @@
+/*
+ * keymap.c: set the keyboard
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence. See the file COPYING for details.
+ *
+ * (c) 2007, the IPCop team
+ *
+ * $Id$
+ *
+ */
+
+
+#include <dirent.h>
+#include <malloc.h>
+#include <newt.h>
+#include <stdlib.h>
+#include <string.h>
+#include "common.h"
+
+
+#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;
+ NODEKV *kv = NULL;
+ 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 ( !(read_kv_from_file(&kv, CONFIG_ROOT "/main/settings")) )
+ {
+ free_kv(&kv);
+ errorbox(gettext("TR_UNABLE_TO_OPEN_SETTINGS_FILE"));
+ return 0;
+ }
+
+ strcpy(keymap, "/usr/share/kbd/keymaps/i386/qwerty/us.map.gz");
+ find_kv_default(kv, "KEYMAP", keymap);
+
+ choice = 0;
+ for (c = 0; filenames[c]; c++)
+ {
+ if (strcmp(keymap, filenames[c]) == 0)
+ choice = c;
+ }
+
+ rc = newtWinMenu(gettext("TR_KEYBOARD_MAPPING"), \
gettext("TR_KEYBOARD_MAPPING_LONG"), 50, 5, 5, 6, displaynames, &choice, \
+ gettext("TR_OK"), gettext("TR_CANCEL"), NULL); +
+ strcpy(keymap, filenames[choice]);
+
+ if ( rc != 2 )
+ {
+ update_kv(&kv, "KEYMAP", keymap);
+ write_kv_to_file(&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]);
+ }
+ free_kv(&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;
+}
Property changes on: ipcop/trunk/src/installer/keymap.c
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ipcop/trunk/src/installer/setup.c
===================================================================
--- ipcop/trunk/src/installer/setup.c 2007-10-29 11:24:37 UTC (rev 592)
+++ ipcop/trunk/src/installer/setup.c 2007-10-29 12:53:36 UTC (rev 593)
@@ -76,6 +76,7 @@
if ( flag_installer )
{
/* all settings in a row, no main menu */
+ handlekeymap();
handlehostname();
handledomainname();
password("root");
@@ -99,8 +100,7 @@
switch ( choice )
{
case 0:
- /* not yet finished */
-// handlekeymap();
+ handlekeymap();
break;
case 1:
/* not yet finished */
This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Ipcop-svn mailing list
Ipcop-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipcop-svn
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic