]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
Merge branch 'message-callback' into kbuild/kconfig
authorMichal Marek <mmarek@suse.cz>
Wed, 27 Oct 2010 22:54:25 +0000 (00:54 +0200)
committerMichal Marek <mmarek@suse.cz>
Wed, 27 Oct 2010 22:54:25 +0000 (00:54 +0200)
Conflicts:
scripts/kconfig/nconf.c

1  2 
scripts/kconfig/confdata.c
scripts/kconfig/lkc_proto.h
scripts/kconfig/nconf.c

index 96110ea41cf3f0854911d8233c23b9d9a7aeb490,c07060ab7820c572876a7d0005247d0a8dc87a8f..9df80114b47b6555d4401d2968ee3d5602409d62
@@@ -19,6 -19,9 +19,9 @@@
  static void conf_warning(const char *fmt, ...)
        __attribute__ ((format (printf, 1, 2)));
  
+ static void conf_message(const char *fmt, ...)
+       __attribute__ ((format (printf, 1, 2)));
  static const char *conf_filename;
  static int conf_lineno, conf_warnings, conf_unsaved;
  
@@@ -35,6 -38,29 +38,29 @@@ static void conf_warning(const char *fm
        conf_warnings++;
  }
  
+ static void conf_default_message_callback(const char *fmt, va_list ap)
+ {
+       printf("#\n# ");
+       vprintf(fmt, ap);
+       printf("\n#\n");
+ }
+ static void (*conf_message_callback) (const char *fmt, va_list ap) =
+       conf_default_message_callback;
+ void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap))
+ {
+       conf_message_callback = fn;
+ }
+ static void conf_message(const char *fmt, ...)
+ {
+       va_list ap;
+       va_start(ap, fmt);
+       if (conf_message_callback)
+               conf_message_callback(fmt, ap);
+ }
  const char *conf_get_configname(void)
  {
        char *name = getenv("KCONFIG_CONFIG");
@@@ -184,9 -210,8 +210,8 @@@ int conf_read_simple(const char *name, 
                        name = conf_expand_value(prop->expr->left.sym->name);
                        in = zconf_fopen(name);
                        if (in) {
-                               printf(_("#\n"
-                                        "# using defaults found in %s\n"
-                                        "#\n"), name);
+                               conf_message(_("using defaults found in %s"),
+                                        name);
                                goto load;
                        }
                }
@@@ -221,23 -246,24 +246,23 @@@ load
        while (fgets(line, sizeof(line), in)) {
                conf_lineno++;
                sym = NULL;
 -              switch (line[0]) {
 -              case '#':
 -                      if (memcmp(line + 2, "CONFIG_", 7))
 +              if (line[0] == '#') {
 +                      if (memcmp(line + 2, CONFIG_, strlen(CONFIG_)))
                                continue;
 -                      p = strchr(line + 9, ' ');
 +                      p = strchr(line + 2 + strlen(CONFIG_), ' ');
                        if (!p)
                                continue;
                        *p++ = 0;
                        if (strncmp(p, "is not set", 10))
                                continue;
                        if (def == S_DEF_USER) {
 -                              sym = sym_find(line + 9);
 +                              sym = sym_find(line + 2 + strlen(CONFIG_));
                                if (!sym) {
                                        sym_add_change_count(1);
 -                                      break;
 +                                      goto setsym;
                                }
                        } else {
 -                              sym = sym_lookup(line + 9, 0);
 +                              sym = sym_lookup(line + 2 + strlen(CONFIG_), 0);
                                if (sym->type == S_UNKNOWN)
                                        sym->type = S_BOOLEAN;
                        }
                        default:
                                ;
                        }
 -                      break;
 -              case 'C':
 -                      if (memcmp(line, "CONFIG_", 7)) {
 -                              conf_warning("unexpected data");
 -                              continue;
 -                      }
 -                      p = strchr(line + 7, '=');
 +              } else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) {
 +                      p = strchr(line + strlen(CONFIG_), '=');
                        if (!p)
                                continue;
                        *p++ = 0;
                                        *p2 = 0;
                        }
                        if (def == S_DEF_USER) {
 -                              sym = sym_find(line + 7);
 +                              sym = sym_find(line + strlen(CONFIG_));
                                if (!sym) {
                                        sym_add_change_count(1);
 -                                      break;
 +                                      goto setsym;
                                }
                        } else {
 -                              sym = sym_lookup(line + 7, 0);
 +                              sym = sym_lookup(line + strlen(CONFIG_), 0);
                                if (sym->type == S_UNKNOWN)
                                        sym->type = S_OTHER;
                        }
                        }
                        if (conf_set_sym_val(sym, def, def_flags, p))
                                continue;
 -                      break;
 -              case '\r':
 -              case '\n':
 -                      break;
 -              default:
 -                      conf_warning("unexpected data");
 +              } else {
 +                      if (line[0] != '\r' && line[0] != '\n')
 +                              conf_warning("unexpected data");
                        continue;
                }
 +setsym:
                if (sym && sym_is_choice_value(sym)) {
                        struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
                        switch (sym->def[def].tri) {
@@@ -398,9 -431,9 +423,9 @@@ static void conf_write_string(bool head
  {
        int l;
        if (headerfile)
 -              fprintf(out, "#define CONFIG_%s \"", name);
 +              fprintf(out, "#define %s%s \"", CONFIG_, name);
        else
 -              fprintf(out, "CONFIG_%s=\"", name);
 +              fprintf(out, "%s%s=\"", CONFIG_, name);
  
        while (1) {
                l = strcspn(str, "\"\\");
@@@ -426,14 -459,13 +451,14 @@@ static void conf_write_symbol(struct sy
                switch (sym_get_tristate_value(sym)) {
                case no:
                        if (write_no)
 -                              fprintf(out, "# CONFIG_%s is not set\n", sym->name);
 +                              fprintf(out, "# %s%s is not set\n",
 +                                  CONFIG_, sym->name);
                        break;
                case mod:
 -                      fprintf(out, "CONFIG_%s=m\n", sym->name);
 +                      fprintf(out, "%s%s=m\n", CONFIG_, sym->name);
                        break;
                case yes:
 -                      fprintf(out, "CONFIG_%s=y\n", sym->name);
 +                      fprintf(out, "%s%s=y\n", CONFIG_, sym->name);
                        break;
                }
                break;
        case S_HEX:
        case S_INT:
                str = sym_get_string_value(sym);
 -              fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
 +              fprintf(out, "%s%s=%s\n", CONFIG_, sym->name, str);
                break;
        case S_OTHER:
        case S_UNKNOWN:
@@@ -535,7 -567,7 +560,7 @@@ int conf_write(const char *name
        struct menu *menu;
        const char *basename;
        const char *str;
 -      char dirname[128], tmpname[128], newname[128];
 +      char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];
        enum symbol_type type;
        time_t now;
        int use_timestamp = 1;
        if (!out)
                return 1;
  
 -      sym = sym_lookup("KERNELVERSION", 0);
 -      sym_calc_value(sym);
        time(&now);
        env = getenv("KCONFIG_NOTIMESTAMP");
        if (env && *env)
  
        fprintf(out, _("#\n"
                       "# Automatically generated make config: don't edit\n"
 -                     "# Linux kernel version: %s\n"
 +                     "# %s\n"
                       "%s%s"
                       "#\n"),
 -                   sym_get_string_value(sym),
 +                   rootmenu.prompt->text,
                     use_timestamp ? "# " : "",
                     use_timestamp ? ctime(&now) : "");
  
@@@ -642,9 -676,7 +667,7 @@@ next
                        return 1;
        }
  
-       printf(_("#\n"
-                "# configuration written to %s\n"
-                "#\n"), newname);
+       conf_message(_("configuration written to %s"), newname);
  
        sym_set_change_count(0);
  
  static int conf_split_config(void)
  {
        const char *name;
 -      char path[128];
 +      char path[PATH_MAX+1];
        char *s, *d, c;
        struct symbol *sym;
        struct stat sb;
@@@ -796,23 -828,25 +819,23 @@@ int conf_write_autoconf(void
                return 1;
        }
  
 -      sym = sym_lookup("KERNELVERSION", 0);
 -      sym_calc_value(sym);
        time(&now);
        fprintf(out, "#\n"
                     "# Automatically generated make config: don't edit\n"
 -                   "# Linux kernel version: %s\n"
 +                   "# %s\n"
                     "# %s"
                     "#\n",
 -                   sym_get_string_value(sym), ctime(&now));
 +                   rootmenu.prompt->text, ctime(&now));
        fprintf(tristate, "#\n"
                          "# Automatically generated - do not edit\n"
                          "\n");
        fprintf(out_h, "/*\n"
                       " * Automatically generated C config: don't edit\n"
 -                     " * Linux kernel version: %s\n"
 +                     " * %s\n"
                       " * %s"
                       " */\n"
                       "#define AUTOCONF_INCLUDED\n",
 -                     sym_get_string_value(sym), ctime(&now));
 +                     rootmenu.prompt->text, ctime(&now));
  
        for_all_symbols(i, sym) {
                sym_calc_value(sym);
                        case no:
                                break;
                        case mod:
 -                              fprintf(tristate, "CONFIG_%s=M\n", sym->name);
 -                              fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name);
 +                              fprintf(tristate, "%s%s=M\n",
 +                                  CONFIG_, sym->name);
 +                              fprintf(out_h, "#define %s%s_MODULE 1\n",
 +                                  CONFIG_, sym->name);
                                break;
                        case yes:
                                if (sym->type == S_TRISTATE)
 -                                      fprintf(tristate, "CONFIG_%s=Y\n",
 -                                                      sym->name);
 -                              fprintf(out_h, "#define CONFIG_%s 1\n", sym->name);
 +                                      fprintf(tristate,"%s%s=Y\n",
 +                                          CONFIG_, sym->name);
 +                              fprintf(out_h, "#define %s%s 1\n",
 +                                  CONFIG_, sym->name);
                                break;
                        }
                        break;
                case S_HEX:
                        str = sym_get_string_value(sym);
                        if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
 -                              fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str);
 +                              fprintf(out_h, "#define %s%s 0x%s\n",
 +                                  CONFIG_, sym->name, str);
                                break;
                        }
                case S_INT:
                        str = sym_get_string_value(sym);
 -                      fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str);
 +                      fprintf(out_h, "#define %s%s %s\n",
 +                          CONFIG_, sym->name, str);
                        break;
                default:
                        break;
index 4531badb3fe19ec9f2f0237c5f833c7e4b98ff59,481d4849d0f0a7158aa9eff8ab9a942ee55f4055..17342fef38b94b877f0b5e93481314c27211d093
@@@ -1,3 -1,4 +1,4 @@@
+ #include <stdarg.h>
  
  /* confdata.c */
  P(conf_parse,void,(const char *name));
@@@ -8,6 -9,7 +9,7 @@@ P(conf_write,int,(const char *name))
  P(conf_write_autoconf,int,(void));
  P(conf_get_changed,bool,(void));
  P(conf_set_changed_callback, void,(void (*fn)(void)));
+ P(conf_set_message_callback, void,(void (*fn)(const char *fmt, va_list ap)));
  
  /* menu.c */
  P(rootmenu,struct menu,);
@@@ -28,7 -30,6 +30,7 @@@ P(symbol_hash,struct symbol *,[SYMBOL_H
  
  P(sym_lookup,struct symbol *,(const char *name, int flags));
  P(sym_find,struct symbol *,(const char *name));
 +P(sym_expand_string_value,const char *,(const char *in));
  P(sym_re_search,struct symbol **,(const char *pattern));
  P(sym_type_name,const char *,(enum symbol_type type));
  P(sym_calc_value,void,(struct symbol *sym));
diff --combined scripts/kconfig/nconf.c
index a2969fdc66b4a9a3c4679e59a98dbe99feb65b34,16233a9382c85e958891d121599ae2b850217325..272a987f23e0bc56040c0931a363277395c511f1
  static const char nconf_readme[] = N_(
  "Overview\n"
  "--------\n"
 -"Some kernel features may be built directly into the kernel.\n"
 -"Some may be made into loadable runtime modules.  Some features\n"
 -"may be completely removed altogether.  There are also certain\n"
 -"kernel parameters which are not really features, but must be\n"
 -"entered in as decimal or hexadecimal numbers or possibly text.\n"
 +"This interface let you select features and parameters for the build.\n"
 +"Features can either be built-in, modularized, or ignored. Parameters\n"
 +"must be entered in as decimal or hexadecimal numbers or text.\n"
  "\n"
  "Menu items beginning with following braces represent features that\n"
  "  [ ] can be built in or removed\n"
@@@ -93,7 -95,7 +93,7 @@@
  "-----------------------------\n"
  "nconfig supports the use of alternate configuration files for\n"
  "those who, for various reasons, find it necessary to switch\n"
 -"between different kernel configurations.\n"
 +"between different configurations.\n"
  "\n"
  "At the end of the main menu you will find two options.  One is\n"
  "for saving the current configuration to a file of your choosing.\n"
  "\n"
  "Optional personality available\n"
  "------------------------------\n"
 -"If you prefer to have all of the kernel options listed in a single\n"
 -"menu, rather than the default multimenu hierarchy, run the nconfig\n"
 -"with NCONFIG_MODE environment variable set to single_menu. Example:\n"
 +"If you prefer to have all of the options listed in a single menu, rather\n"
 +"than the default multimenu hierarchy, run the nconfig with NCONFIG_MODE\n"
 +"environment variable set to single_menu. Example:\n"
  "\n"
  "make NCONFIG_MODE=single_menu nconfig\n"
  "\n"
@@@ -183,19 -185,19 +183,19 @@@ setmod_text[] = N_
  "has been configured as a module.\n"
  "As a result, this feature will be built as a module."),
  nohelp_text[] = N_(
 -"There is no help available for this kernel option.\n"),
 +"There is no help available for this option.\n"),
  load_config_text[] = N_(
  "Enter the name of the configuration file you wish to load.\n"
  "Accept the name shown to restore the configuration you\n"
  "last retrieved.  Leave blank to abort."),
  load_config_help[] = N_(
  "\n"
 -"For various reasons, one may wish to keep several different kernel\n"
 +"For various reasons, one may wish to keep several different\n"
  "configurations available on a single machine.\n"
  "\n"
  "If you have saved a previous configuration in a file other than the\n"
 -"kernel's default, entering the name of the file here will allow you\n"
 -"to modify that configuration.\n"
 +"default one, entering its name here will allow you to modify that\n"
 +"configuration.\n"
  "\n"
  "If you are uncertain, then you have probably never used alternate\n"
  "configuration files.  You should therefor leave this blank to abort.\n"),
@@@ -204,8 -206,8 +204,8 @@@ save_config_text[] = N_
  "as an alternate.  Leave blank to abort."),
  save_config_help[] = N_(
  "\n"
 -"For various reasons, one may wish to keep different kernel\n"
 -"configurations available on a single machine.\n"
 +"For various reasons, one may wish to keep different configurations\n"
 +"available on a single machine.\n"
  "\n"
  "Entering a file name here will allow you to later retrieve, modify\n"
  "and use the current configuration as an alternate to whatever\n"
  "leave this blank.\n"),
  search_help[] = N_(
  "\n"
 -"Search for CONFIG_ symbols and display their relations.\n"
 -"Regular expressions are allowed.\n"
 +"Search for symbols and display their relations. Regular expressions\n"
 +"are allowed.\n"
  "Example: search for \"^FOO\"\n"
  "Result:\n"
  "-----------------------------------------------------------------\n"
  "Selected by: BAR\n"
  "-----------------------------------------------------------------\n"
  "o The line 'Prompt:' shows the text used in the menu structure for\n"
 -"  this CONFIG_ symbol\n"
 +"  this symbol\n"
  "o The 'Defined at' line tell at what file / line number the symbol\n"
  "  is defined\n"
  "o The 'Depends on:' line tell what symbols needs to be defined for\n"
  "Only relevant lines are shown.\n"
  "\n\n"
  "Search examples:\n"
 -"Examples: USB   = > find all CONFIG_ symbols containing USB\n"
 -"          ^USB => find all CONFIG_ symbols starting with USB\n"
 -"          USB$ => find all CONFIG_ symbols ending with USB\n"
 +"Examples: USB   = > find all symbols containing USB\n"
 +"          ^USB => find all symbols starting with USB\n"
 +"          USB$ => find all symbols ending with USB\n"
  "\n");
  
  struct mitem {
@@@ -633,9 -635,13 +633,9 @@@ static char menu_backtitle[PATH_MAX+128
  static const char *set_config_filename(const char *config_filename)
  {
        int size;
 -      struct symbol *sym;
  
 -      sym = sym_lookup("KERNELVERSION", 0);
 -      sym_calc_value(sym);
        size = snprintf(menu_backtitle, sizeof(menu_backtitle),
 -                      _("%s - Linux Kernel v%s Configuration"),
 -                      config_filename, sym_get_string_value(sym));
 +                      "%s - %s", config_filename, rootmenu.prompt->text);
        if (size >= sizeof(menu_backtitle))
                menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
  
        return menu_backtitle;
  }
  
- /* command = 0 is supress, 1 is restore */
- static void supress_stdout(int command)
- {
-       static FILE *org_stdout;
-       static FILE *org_stderr;
-       if (command == 0) {
-               org_stdout = stdout;
-               org_stderr = stderr;
-               stdout = fopen("/dev/null", "a");
-               stderr = fopen("/dev/null", "a");
-       } else {
-               fclose(stdout);
-               fclose(stderr);
-               stdout = org_stdout;
-               stderr = org_stderr;
-       }
- }
  /* return = 0 means we are successful.
   * -1 means go on doing what you were doing
   */
@@@ -675,7 -662,8 +656,7 @@@ static int do_exit(void
                return 0;
        }
        res = btn_dialog(main_window,
 -                      _("Do you wish to save your "
 -                              "new kernel configuration?\n"
 +                      _("Do you wish to save your new configuration?\n"
                                "<ESC> to cancel and resume nconfig."),
                        2,
                        "   <save>   ",
        /* if we got here, the user really wants to exit */
        switch (res) {
        case 0:
-               supress_stdout(0);
                res = conf_write(filename);
-               supress_stdout(1);
                if (res)
                        btn_dialog(
                                main_window,
 -                              _("Error during writing of the kernel "
 -                                "configuration.\n"
 -                                "Your kernel configuration "
 -                                "changes were NOT saved."),
 +                              _("Error during writing of configuration.\n"
 +                                "Your configuration changes were NOT saved."),
                                  1,
                                  "<OK>");
-               else {
-                       char buf[1024];
-                       snprintf(buf, 1024,
-                               _("Configuration written to %s\n"
-                                 "End of the configuration.\n"
-                                 "Execute 'make' to start the build or try"
-                                 " 'make help'."), filename);
-                       btn_dialog(
-                               main_window,
-                               buf,
-                               1,
-                               "<OK>");
-               }
                break;
        default:
                btn_dialog(
                        main_window,
 -                      _("Your kernel configuration changes were NOT saved."),
 +                      _("Your configuration changes were NOT saved."),
                        1,
                        "<OK>");
                break;
@@@ -735,8 -710,8 +701,8 @@@ static void search_conf(void
  again:
        dres = dialog_inputbox(main_window,
                        _("Search Configuration Parameter"),
 -                      _("Enter CONFIG_ (sub)string to search for "
 -                              "(with or without \"CONFIG\")"),
 +                      _("Enter " CONFIG_ " (sub)string to search for "
 +                              "(with or without \"" CONFIG_ "\")"),
                        "", dialog_input_result, 99);
        switch (dres) {
        case 0:
                return;
        }
  
 -      /* strip CONFIG_ if necessary */
 +      /* strip the prefix if necessary */
        dialog_input = dialog_input_result;
 -      if (strncasecmp(dialog_input_result, "CONFIG_", 7) == 0)
 -              dialog_input += 7;
 +      if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
 +              dialog_input += strlen(CONFIG_);
  
        sym_arr = sym_re_search(dialog_input);
        res = get_relations_str(sym_arr);
@@@ -1246,18 -1221,24 +1212,26 @@@ static void conf(struct menu *menu
        }
  }
  
+ static void conf_message_callback(const char *fmt, va_list ap)
+ {
+       char buf[1024];
+       vsnprintf(buf, sizeof(buf), fmt, ap);
+       btn_dialog(main_window, buf, 1, "<OK>");
+ }
  static void show_help(struct menu *menu)
  {
        struct gstr help = str_new();
  
        if (menu && menu->sym && menu_has_help(menu)) {
                if (menu->sym->name) {
 -                      str_printf(&help, "CONFIG_%s:\n\n", menu->sym->name);
 +                      str_printf(&help, "%s%s:\n\n", CONFIG_, menu->sym->name);
                        str_append(&help, _(menu_get_help(menu)));
                        str_append(&help, "\n");
                        get_symbol_str(&help, menu->sym);
 +              } else {
 +                      str_append(&help, _(menu_get_help(menu)));
                }
        } else {
                str_append(&help, nohelp_text);
@@@ -1470,16 -1451,8 +1444,8 @@@ static void conf_save(void
                case 0:
                        if (!dialog_input_result[0])
                                return;
-                       supress_stdout(0);
                        res = conf_write(dialog_input_result);
-                       supress_stdout(1);
                        if (!res) {
-                               char buf[1024];
-                               sprintf(buf, "%s %s",
-                                       _("configuration file saved to: "),
-                                       dialog_input_result);
-                               btn_dialog(main_window,
-                                          buf, 1, "<OK>");
                                set_config_filename(dialog_input_result);
                                return;
                        }
@@@ -1572,6 -1545,7 +1538,7 @@@ int main(int ac, char **av
                                _(menu_no_f_instructions));
        }
  
+       conf_set_message_callback(conf_message_callback);
        /* do the work */
        while (!global_exit) {
                conf(&rootmenu);