Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fwlive.git;a=commitdiff;h=ad62a5e3df91fec8858a164a498753e35c99c86d

commit ad62a5e3df91fec8858a164a498753e35c99c86d
Author: James Buren <[email protected]>
Date:   Sat Mar 2 03:30:47 2013 -0600

import initial layout module

diff --git a/new/fwsetup/configure b/new/fwsetup/configure
index 1f4b79d..4a50cf4 100755
--- a/new/fwsetup/configure
+++ b/new/fwsetup/configure
@@ -53,7 +53,7 @@ test "$UI" = "newt" && ! pkg_config_exists "libnewt" && error 
"libnewt was not f

CFLAGS="$CFLAGS $(pkg-config --cflags pacman blkid)"
LDFLAGS="$LDFLAGS $(pkg-config --libs pacman blkid)"
-SOURCES="main.c utility.c block.c locale.c partition.c format.c install.c 
postconfig.c"
+SOURCES="main.c utility.c block.c locale.c layout.c partition.c format.c 
install.c postconfig.c"

if test "$UI" = "newt"; then
CFLAGS="$CFLAGS -DUI_NEWT $(pkg-config --cflags libnewt)"
diff --git a/new/fwsetup/layout.c b/new/fwsetup/layout.c
new file mode 100644
index 0000000..4de4775
--- /dev/null
+++ b/new/fwsetup/layout.c
@@ -0,0 +1,140 @@
+// fwsetup - flexible installer for Frugalware
+// Copyright (C) 2013 James Buren
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA.
+
+#include "local.h"
+
+struct layout
+{
+  char *kbdlayout;
+  char *xkblayout;
+  char *xkbmodel;
+  char *xkbvariant;
+  char *xkboptions;
+};
+
+static struct layout **layouts;
+
+static inline bool get_token(char *in,char **out)
+{
+  return (*out = strtok(in," \t")) != 0;
+}
+
+static inline void put_token(char *in,char **out)
+{
+  *out = (strcmp(in,"-") == 0) ? 0 : strdup(in);
+}
+
+static bool layout_setup(void)
+{
+  FILE *file = 0;
+  size_t i = 0;
+  size_t size = 4096;
+  char line[LINE_MAX] = {0};
+  char *kbdlayout = 0;
+  char *xkblayout = 0;
+  char *xkbmodel = 0;
+  char *xkbvariant = 0;
+  char *xkboptions = 0;
+  struct layout *layout = 0;
+
+  if((file = fopen("/usr/share/systemd/kbd-model-map","rb")) == 0)
+  {
+    error(strerror(errno));
+    return false;
+  }
+
+  layouts = malloc0(sizeof(struct layout *) * size);
+
+  while(fgets(line,sizeof(line),file) != 0)
+  {
+    if(
+      i == size - 1               ||
+      *line == '#'                ||
+      !get_token(line,&kbdlayout) ||
+      !get_token(0,&xkblayout)    ||
+      !get_token(0,&xkbmodel)     ||
+      !get_token(0,&xkbvariant)   ||
+      !get_token(0,&xkboptions)
+    )
+      continue;
+
+    layout = malloc0(sizeof(struct layout));
+
+    put_token(kbdlayout,&layout->kbdlayout);
+
+    put_token(xkblayout,&layout->xkblayout);
+
+    put_token(xkbmodel,&layout->xkbmodel);
+
+    put_token(xkbvariant,&layout->xkbvariant);
+
+    put_token(xkboptions,&layout->xkboptions);
+
+    layouts[i++] = layout;
+  }
+
+  layouts[i] = 0;
+
+  layouts = realloc(layouts,sizeof(struct layout *) * (i+1));
+
+  return true;
+}
+
+static bool layout_run(void)
+{
+  if(!layout_setup())
+    return true;
+
+  return true;
+}
+
+static void layout_reset(void)
+{
+  size_t i = 0;
+  struct layout *layout = 0;
+
+  if(layouts != 0)
+  {
+    for( ; layouts[i] != 0 ; ++i )
+    {
+      layout = layouts[i];
+
+      free(layout->kbdlayout);
+
+      free(layout->xkblayout);
+
+      free(layout->xkbmodel);
+
+      free(layout->xkbvariant);
+
+      free(layout->xkboptions);
+
+      free(layout);
+    }
+
+    free(layouts);
+
+    layouts = 0;
+  }
+}
+
+struct module layout_module =
+{
+  layout_run,
+  layout_reset,
+  __FILE__
+};
diff --git a/new/fwsetup/local.h b/new/fwsetup/local.h
index 1557d92..fdf8931 100644
--- a/new/fwsetup/local.h
+++ b/new/fwsetup/local.h
@@ -178,6 +178,7 @@ extern int main(int argc,char **argv);

extern struct global *g;
extern struct module locale_module;
+extern struct module layout_module;
extern struct module partition_module;
extern struct module format_module;
extern struct module install_module;
diff --git a/new/fwsetup/main.c b/new/fwsetup/main.c
index b4dd029..84d2b75 100644
--- a/new/fwsetup/main.c
+++ b/new/fwsetup/main.c
@@ -64,6 +64,7 @@ struct global *g = &local;
struct module *modules[] =
{
&locale_module,
+  &layout_module,
&partition_module,
&format_module,
&install_module,
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to