Re: [RFC] kconfig: a new command line tool to set configs

2016-01-26 Thread Dan Carpenter
On Mon, Jun 15, 2015 at 02:55:46PM +0200, Michal Marek wrote:
> On 2015-05-12 12:31, Dan Carpenter wrote:
> > This is an ugly hack job I made last night and it barely works.  It
> > does two things:
> > 
> > 1)  Sometimes I want to search for a config so I have to load
> > menuconfig, then search for the config entry, then exit.  With
> > this script I simply run:
> > 
> > ./scripts/kconfig/kconfig search COMEDI
> > 
> > 2)  I quite often try to enable something by doing:
> > 
> > echo CONFIG_FOO=y >> .config
> > make oldconfig
> > grep CONFIG_FOO .config
> > 
> > The grep is to see if the setting worked.  Now I can do:
> > 
> > ./scripts/kconfig/kconfig set CONFIG_FOO=y
> 
> The second use-case is provided by scripts/config already. It's is a lot
> simpler shell script, but it's maybe good enough for such task.

The scripts/config file doesn't check that the config is valid.  It's
the same as doing "echo CONFIG_FOO=y >> .config" which I was trying to
fix.

regards,
dan carpenter



Re: [RFC] kconfig: a new command line tool to set configs

2016-01-26 Thread Dan Carpenter
On Mon, Jun 15, 2015 at 02:55:46PM +0200, Michal Marek wrote:
> On 2015-05-12 12:31, Dan Carpenter wrote:
> > This is an ugly hack job I made last night and it barely works.  It
> > does two things:
> > 
> > 1)  Sometimes I want to search for a config so I have to load
> > menuconfig, then search for the config entry, then exit.  With
> > this script I simply run:
> > 
> > ./scripts/kconfig/kconfig search COMEDI
> > 
> > 2)  I quite often try to enable something by doing:
> > 
> > echo CONFIG_FOO=y >> .config
> > make oldconfig
> > grep CONFIG_FOO .config
> > 
> > The grep is to see if the setting worked.  Now I can do:
> > 
> > ./scripts/kconfig/kconfig set CONFIG_FOO=y
> 
> The second use-case is provided by scripts/config already. It's is a lot
> simpler shell script, but it's maybe good enough for such task.

The scripts/config file doesn't check that the config is valid.  It's
the same as doing "echo CONFIG_FOO=y >> .config" which I was trying to
fix.

regards,
dan carpenter



Re: [RFC] kconfig: a new command line tool to set configs

2015-06-15 Thread Michal Marek
On 2015-05-12 12:31, Dan Carpenter wrote:
> This is an ugly hack job I made last night and it barely works.  It
> does two things:
> 
> 1)  Sometimes I want to search for a config so I have to load
> menuconfig, then search for the config entry, then exit.  With
> this script I simply run:
> 
>   ./scripts/kconfig/kconfig search COMEDI
> 
> 2)  I quite often try to enable something by doing:
> 
>   echo CONFIG_FOO=y >> .config
>   make oldconfig
>   grep CONFIG_FOO .config
> 
> The grep is to see if the setting worked.  Now I can do:
> 
>   ./scripts/kconfig/kconfig set CONFIG_FOO=y

The second use-case is provided by scripts/config already. It's is a lot
simpler shell script, but it's maybe good enough for such task.

Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC] kconfig: a new command line tool to set configs

2015-06-15 Thread Michal Marek
On 2015-05-12 12:31, Dan Carpenter wrote:
 This is an ugly hack job I made last night and it barely works.  It
 does two things:
 
 1)  Sometimes I want to search for a config so I have to load
 menuconfig, then search for the config entry, then exit.  With
 this script I simply run:
 
   ./scripts/kconfig/kconfig search COMEDI
 
 2)  I quite often try to enable something by doing:
 
   echo CONFIG_FOO=y  .config
   make oldconfig
   grep CONFIG_FOO .config
 
 The grep is to see if the setting worked.  Now I can do:
 
   ./scripts/kconfig/kconfig set CONFIG_FOO=y

The second use-case is provided by scripts/config already. It's is a lot
simpler shell script, but it's maybe good enough for such task.

Michal
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC] kconfig: a new command line tool to set configs

2015-05-12 Thread Dan Carpenter
This is an ugly hack job I made last night and it barely works.  It
does two things:

1)  Sometimes I want to search for a config so I have to load
menuconfig, then search for the config entry, then exit.  With
this script I simply run:

./scripts/kconfig/kconfig search COMEDI

2)  I quite often try to enable something by doing:

echo CONFIG_FOO=y >> .config
make oldconfig
grep CONFIG_FOO .config

The grep is to see if the setting worked.  Now I can do:

./scripts/kconfig/kconfig set CONFIG_FOO=y

Parsing dependencies barely works, but that's just a matter of writing
some more code in expr_parse().

The main questions I have at this point are:

1)  If I have a symbol pointer, is it possible to get a help text from
that?

2)  For some reason, when I do sym_set_tristate_value() it doesn't
actually set anything until I write the config file so I have to do:

if (sym_set_tristate_value(sym, newval)) {
/* FIXME: if I don't write it doesn't save */
conf_write(NULL);
return 1;
}

It makes the output really messy.

Signed-off-by: Dan Carpenter 

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index d9b1fef..ae338a5 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -33,6 +33,9 @@ config: $(obj)/conf
 nconfig: $(obj)/nconf
$< $(silent) $(Kconfig)
 
+lconfig: $(obj)/lconf
+   $< $(silent) $(Kconfig)
+
 silentoldconfig: $(obj)/conf
$(Q)mkdir -p include/config include/generated
$< $(silent) --$@ $(Kconfig)
@@ -169,12 +172,13 @@ lxdialog += lxdialog/textbox.o lxdialog/yesno.o 
lxdialog/menubox.o
 conf-objs  := conf.o  zconf.tab.o
 mconf-objs := mconf.o zconf.tab.o $(lxdialog)
 nconf-objs := nconf.o zconf.tab.o nconf.gui.o
+lconf-objs := lconf.o zconf.tab.o
 kxgettext-objs := kxgettext.o zconf.tab.o
 qconf-cxxobjs  := qconf.o
 qconf-objs := zconf.tab.o
 gconf-objs := gconf.o zconf.tab.o
 
-hostprogs-y := conf nconf mconf kxgettext qconf gconf
+hostprogs-y := conf nconf mconf kxgettext qconf gconf lconf
 
 clean-files:= qconf.moc .tmp_qtcheck .tmp_gtkcheck
 clean-files+= zconf.tab.c zconf.lex.c zconf.hash.c gconf.glade.h
diff --git a/scripts/kconfig/kconfig b/scripts/kconfig/kconfig
new file mode 100755
index 000..beab8fc
--- /dev/null
+++ b/scripts/kconfig/kconfig
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+usage() {
+   echo "kconfig [search|set] string"
+   exit 1;
+}
+
+if [ "$1" = "" ] ; then
+   usage
+fi
+
+if [ "$1" = "search" ] ; then
+
+   search=$2
+   NCONFIG_MODE=kconfig_search SEARCH=${search} make lconfig
+
+elif [ "$1" = "set" ] ; then
+
+   config=$2
+   setting=$3
+
+   if [ $config = "" ] ; then
+   echo "nothing to set"
+   exit 1
+   fi
+
+   NCONFIG_MODE=kconfig_set CONFIG=${config} SETTING=${setting} make 
lconfig
+
+else
+   usage
+fi
+
+
diff --git a/scripts/kconfig/lconf.c b/scripts/kconfig/lconf.c
new file mode 100644
index 000..aa8551e
--- /dev/null
+++ b/scripts/kconfig/lconf.c
@@ -0,0 +1,314 @@
+/*
+ * Copyright (C) 2015 Oracle
+ * Released under the terms of the GNU GPL v2.0.
+ *
+ */
+#define _GNU_SOURCE
+#include 
+#include 
+
+#include "lkc.h"
+#include "nconf.h"
+#include 
+
+static int indent;
+static char line[128];
+
+static int get_depends(struct symbol *sym);
+
+static void strip(char *str)
+{
+   char *p = str;
+   int l;
+
+   while ((isspace(*p)))
+   p++;
+   l = strlen(p);
+   if (p != str)
+   memmove(str, p, l + 1);
+   if (!l)
+   return;
+   p = str + l - 1;
+   while ((isspace(*p)))
+   *p-- = 0;
+}
+
+static void xfgets(char *str, int size, FILE *in)
+{
+   if (fgets(str, size, in) == NULL)
+   fprintf(stderr, "\nError in reading or end of file.\n");
+}
+
+static int conf_askvalue(struct symbol *sym, const char *def)
+{
+   enum symbol_type type = sym_get_type(sym);
+
+   if (!sym_has_value(sym))
+   printf(_("(NEW) "));
+
+   line[0] = '\n';
+   line[1] = 0;
+
+   if (!sym_is_changable(sym)) {
+   printf("%s\n", def);
+   line[0] = '\n';
+   line[1] = 0;
+   return 0;
+   }
+
+   fflush(stdout);
+   xfgets(line, 128, stdin);
+
+   switch (type) {
+   case S_INT:
+   case S_HEX:
+   case S_STRING:
+   printf("%s\n", def);
+   return 1;
+   default:
+   ;
+   }
+   printf("%s", line);
+   return 1;
+}
+
+static struct property *get_symbol_prop(struct symbol *sym)
+{
+   struct property *prop = NULL;
+
+   for_all_properties(sym, prop, P_SYMBOL)
+   break;
+   return prop;
+}
+
+static int conf_sym(struct symbol *sym)
+{
+   tristate oldval, newval;
+   struct 

[RFC] kconfig: a new command line tool to set configs

2015-05-12 Thread Dan Carpenter
This is an ugly hack job I made last night and it barely works.  It
does two things:

1)  Sometimes I want to search for a config so I have to load
menuconfig, then search for the config entry, then exit.  With
this script I simply run:

./scripts/kconfig/kconfig search COMEDI

2)  I quite often try to enable something by doing:

echo CONFIG_FOO=y  .config
make oldconfig
grep CONFIG_FOO .config

The grep is to see if the setting worked.  Now I can do:

./scripts/kconfig/kconfig set CONFIG_FOO=y

Parsing dependencies barely works, but that's just a matter of writing
some more code in expr_parse().

The main questions I have at this point are:

1)  If I have a symbol pointer, is it possible to get a help text from
that?

2)  For some reason, when I do sym_set_tristate_value() it doesn't
actually set anything until I write the config file so I have to do:

if (sym_set_tristate_value(sym, newval)) {
/* FIXME: if I don't write it doesn't save */
conf_write(NULL);
return 1;
}

It makes the output really messy.

Signed-off-by: Dan Carpenter dan.carpen...@oracle.com

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index d9b1fef..ae338a5 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -33,6 +33,9 @@ config: $(obj)/conf
 nconfig: $(obj)/nconf
$ $(silent) $(Kconfig)
 
+lconfig: $(obj)/lconf
+   $ $(silent) $(Kconfig)
+
 silentoldconfig: $(obj)/conf
$(Q)mkdir -p include/config include/generated
$ $(silent) --$@ $(Kconfig)
@@ -169,12 +172,13 @@ lxdialog += lxdialog/textbox.o lxdialog/yesno.o 
lxdialog/menubox.o
 conf-objs  := conf.o  zconf.tab.o
 mconf-objs := mconf.o zconf.tab.o $(lxdialog)
 nconf-objs := nconf.o zconf.tab.o nconf.gui.o
+lconf-objs := lconf.o zconf.tab.o
 kxgettext-objs := kxgettext.o zconf.tab.o
 qconf-cxxobjs  := qconf.o
 qconf-objs := zconf.tab.o
 gconf-objs := gconf.o zconf.tab.o
 
-hostprogs-y := conf nconf mconf kxgettext qconf gconf
+hostprogs-y := conf nconf mconf kxgettext qconf gconf lconf
 
 clean-files:= qconf.moc .tmp_qtcheck .tmp_gtkcheck
 clean-files+= zconf.tab.c zconf.lex.c zconf.hash.c gconf.glade.h
diff --git a/scripts/kconfig/kconfig b/scripts/kconfig/kconfig
new file mode 100755
index 000..beab8fc
--- /dev/null
+++ b/scripts/kconfig/kconfig
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+usage() {
+   echo kconfig [search|set] string
+   exit 1;
+}
+
+if [ $1 =  ] ; then
+   usage
+fi
+
+if [ $1 = search ] ; then
+
+   search=$2
+   NCONFIG_MODE=kconfig_search SEARCH=${search} make lconfig
+
+elif [ $1 = set ] ; then
+
+   config=$2
+   setting=$3
+
+   if [ $config =  ] ; then
+   echo nothing to set
+   exit 1
+   fi
+
+   NCONFIG_MODE=kconfig_set CONFIG=${config} SETTING=${setting} make 
lconfig
+
+else
+   usage
+fi
+
+
diff --git a/scripts/kconfig/lconf.c b/scripts/kconfig/lconf.c
new file mode 100644
index 000..aa8551e
--- /dev/null
+++ b/scripts/kconfig/lconf.c
@@ -0,0 +1,314 @@
+/*
+ * Copyright (C) 2015 Oracle
+ * Released under the terms of the GNU GPL v2.0.
+ *
+ */
+#define _GNU_SOURCE
+#include string.h
+#include stdlib.h
+
+#include lkc.h
+#include nconf.h
+#include ctype.h
+
+static int indent;
+static char line[128];
+
+static int get_depends(struct symbol *sym);
+
+static void strip(char *str)
+{
+   char *p = str;
+   int l;
+
+   while ((isspace(*p)))
+   p++;
+   l = strlen(p);
+   if (p != str)
+   memmove(str, p, l + 1);
+   if (!l)
+   return;
+   p = str + l - 1;
+   while ((isspace(*p)))
+   *p-- = 0;
+}
+
+static void xfgets(char *str, int size, FILE *in)
+{
+   if (fgets(str, size, in) == NULL)
+   fprintf(stderr, \nError in reading or end of file.\n);
+}
+
+static int conf_askvalue(struct symbol *sym, const char *def)
+{
+   enum symbol_type type = sym_get_type(sym);
+
+   if (!sym_has_value(sym))
+   printf(_((NEW) ));
+
+   line[0] = '\n';
+   line[1] = 0;
+
+   if (!sym_is_changable(sym)) {
+   printf(%s\n, def);
+   line[0] = '\n';
+   line[1] = 0;
+   return 0;
+   }
+
+   fflush(stdout);
+   xfgets(line, 128, stdin);
+
+   switch (type) {
+   case S_INT:
+   case S_HEX:
+   case S_STRING:
+   printf(%s\n, def);
+   return 1;
+   default:
+   ;
+   }
+   printf(%s, line);
+   return 1;
+}
+
+static struct property *get_symbol_prop(struct symbol *sym)
+{
+   struct property *prop = NULL;
+
+   for_all_properties(sym, prop, P_SYMBOL)
+   break;
+   return prop;
+}
+
+static int conf_sym(struct symbol *sym)
+{
+   tristate oldval, newval;
+