Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Mar 25, 2024
1 parent 21054af commit d599fc4
Show file tree
Hide file tree
Showing 17 changed files with 466 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .gitpicker.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"user": "torvalds",
"repo": "linux",
"branch": "741e9d668aa50c91e4f681511ce0e408d55dd7ce",
"branch": "4cece764965020c22cff7665b18a012006359095",
"root": "scripts/kconfig",
"file": [
"lxdialog/checklist.c",
Expand Down
96 changes: 18 additions & 78 deletions confdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
#include <time.h>
#include <unistd.h>

#include "internal.h"
#include "lkc.h"

struct gstr autoconf_cmd;

/* return true if 'path' exists, false otherwise */
static bool is_present(const char *path)
{
Expand Down Expand Up @@ -293,63 +296,12 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
return 0;
}

#define LINE_GROWTH 16
static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
{
size_t new_size = slen + 1;

if (new_size > *n) {
new_size += LINE_GROWTH - 1;
new_size *= 2;
*lineptr = xrealloc(*lineptr, new_size);
*n = new_size;
}

(*lineptr)[slen] = c;

return 0;
}

static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream)
{
char *line = *lineptr;
size_t slen = 0;

for (;;) {
int c = getc(stream);

switch (c) {
case '\n':
if (add_byte(c, &line, slen, n) < 0)
goto e_out;
slen++;
/* fall through */
case EOF:
if (add_byte('\0', &line, slen, n) < 0)
goto e_out;
*lineptr = line;
if (slen == 0)
return -1;
return slen;
default:
if (add_byte(c, &line, slen, n) < 0)
goto e_out;
slen++;
}
}

e_out:
line[slen-1] = '\0';
*lineptr = line;
return -1;
}

/* like getline(), but the newline character is stripped away */
static ssize_t getline_stripped(char **lineptr, size_t *n, FILE *stream)
{
ssize_t len;

len = compat_getline(lineptr, n, stream);
len = getline(lineptr, n, stream);

if (len > 0 && (*lineptr)[len - 1] == '\n') {
len--;
Expand All @@ -371,7 +323,7 @@ int conf_read_simple(const char *name, int def)
size_t line_asize = 0;
char *p, *val;
struct symbol *sym;
int i, def_flags;
int def_flags;
const char *warn_unknown, *sym_name;

warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
Expand Down Expand Up @@ -429,7 +381,7 @@ int conf_read_simple(const char *name, int def)
conf_warnings = 0;

def_flags = SYMBOL_DEF << def;
for_all_symbols(i, sym) {
for_all_symbols(sym) {
sym->flags |= SYMBOL_CHANGED;
sym->flags &= ~(def_flags|SYMBOL_VALID);
if (sym_is_choice(sym))
Expand Down Expand Up @@ -538,7 +490,6 @@ int conf_read(const char *name)
{
struct symbol *sym;
int conf_unsaved = 0;
int i;

conf_set_changed(false);

Expand All @@ -549,7 +500,7 @@ int conf_read(const char *name)

sym_calc_value(modules_sym);

for_all_symbols(i, sym) {
for_all_symbols(sym) {
sym_calc_value(sym);
if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE))
continue;
Expand All @@ -573,7 +524,7 @@ int conf_read(const char *name)
/* maybe print value in verbose mode... */
}

for_all_symbols(i, sym) {
for_all_symbols(sym) {
if (sym_has_value(sym) && !sym_is_choice_value(sym)) {
/* Reset values of generates values, so they'll appear
* as new, if they should become visible, but that
Expand Down Expand Up @@ -848,10 +799,7 @@ int conf_write_defconfig(const char *filename)
while (menu != NULL)
{
sym = menu->sym;
if (sym == NULL) {
if (!menu_is_visible(menu))
goto next_menu;
} else if (!sym_is_choice(sym)) {
if (sym && !sym_is_choice(sym)) {
sym_calc_value(sym);
if (!(sym->flags & SYMBOL_WRITE))
goto next_menu;
Expand Down Expand Up @@ -911,7 +859,6 @@ int conf_write(const char *name)
const char *str;
char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1];
char *env;
int i;
bool need_newline = false;

if (!name)
Expand Down Expand Up @@ -995,7 +942,7 @@ int conf_write(const char *name)
}
fclose(out);

for_all_symbols(i, sym)
for_all_symbols(sym)
sym->flags &= ~SYMBOL_WRITTEN;

if (*tmpname) {
Expand Down Expand Up @@ -1023,7 +970,6 @@ int conf_write(const char *name)
static int conf_write_autoconf_cmd(const char *autoconf_name)
{
char name[PATH_MAX], tmp[PATH_MAX];
struct file *file;
FILE *out;
int ret;

Expand All @@ -1044,15 +990,9 @@ static int conf_write_autoconf_cmd(const char *autoconf_name)
return -1;
}

fprintf(out, "deps_config := \\\n");
for (file = file_list; file; file = file->next)
fprintf(out, "\t%s \\\n", file->name);

fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name);
fprintf(out, "autoconfig := %s\n", autoconf_name);

env_write_dep(out, autoconf_name);

fprintf(out, "\n$(deps_config): ;\n");
fputs(str_get(&autoconf_cmd), out);

fflush(out);
ret = ferror(out); /* error check for all fprintf() calls */
Expand All @@ -1072,7 +1012,7 @@ static int conf_touch_deps(void)
{
const char *name, *tmp;
struct symbol *sym;
int res, i;
int res;

name = conf_get_autoconfig_name();
tmp = strrchr(name, '/');
Expand All @@ -1086,7 +1026,7 @@ static int conf_touch_deps(void)
conf_read_simple(name, S_DEF_AUTO);
sym_calc_value(modules_sym);

for_all_symbols(i, sym) {
for_all_symbols(sym) {
sym_calc_value(sym);
if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name)
continue;
Expand Down Expand Up @@ -1152,7 +1092,7 @@ static int __conf_write_autoconf(const char *filename,
char tmp[PATH_MAX];
FILE *file;
struct symbol *sym;
int ret, i;
int ret;

if (make_parent_dir(filename))
return -1;
Expand All @@ -1169,7 +1109,7 @@ static int __conf_write_autoconf(const char *filename,

conf_write_heading(file, comment_style);

for_all_symbols(i, sym)
for_all_symbols(sym)
if ((sym->flags & SYMBOL_WRITE) && sym->name)
print_symbol(file, sym);

Expand All @@ -1192,7 +1132,7 @@ int conf_write_autoconf(int overwrite)
{
struct symbol *sym;
const char *autoconf_name = conf_get_autoconfig_name();
int ret, i;
int ret;

if (!overwrite && is_present(autoconf_name))
return 0;
Expand All @@ -1204,7 +1144,7 @@ int conf_write_autoconf(int overwrite)
if (conf_touch_deps())
return 1;

for_all_symbols(i, sym)
for_all_symbols(sym)
sym_calc_value(sym);

ret = __conf_write_autoconf(conf_get_autoheader_name(),
Expand Down
29 changes: 11 additions & 18 deletions expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ extern "C" {

#include <assert.h>
#include <stdio.h>
#include "list.h"
#include "list_types.h"
#ifndef __cplusplus
#include <stdbool.h>
#endif

struct file {
struct file *next;
struct file *parent;
const char *name;
int lineno;
};
#include "list_types.h"

typedef enum tristate {
no, mod, yes
Expand Down Expand Up @@ -81,8 +76,8 @@ enum {
* SYMBOL_CHOICE bit set in 'flags'.
*/
struct symbol {
/* The next symbol in the same bucket in the symbol hash table */
struct symbol *next;
/* link node for the hash table */
struct hlist_node node;

/* The name of the symbol, e.g. "FOO" for 'config FOO' */
char *name;
Expand Down Expand Up @@ -113,6 +108,9 @@ struct symbol {
*/
tristate visible;

/* config entries associated with this symbol */
struct list_head menus;

/* SYMBOL_* flags */
int flags;

Expand All @@ -131,8 +129,6 @@ struct symbol {
struct expr_value implied;
};

#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next)

#define SYMBOL_CONST 0x0001 /* symbol is const */
#define SYMBOL_CHECK 0x0008 /* used during dependency checking */
#define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */
Expand All @@ -157,7 +153,6 @@ struct symbol {
#define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000

#define SYMBOL_MAXLENGTH 256
#define SYMBOL_HASHSIZE 9973

/* A property represent the config options that can be associated
* with a config "symbol".
Expand Down Expand Up @@ -195,7 +190,7 @@ struct property {
struct menu *menu; /* the menu the property are associated with
* valid for: P_SELECT, P_RANGE, P_CHOICE,
* P_PROMPT, P_DEFAULT, P_MENU, P_COMMENT */
struct file *file; /* what file was this property defined */
const char *filename; /* what file was this property defined */
int lineno; /* what lineno was this property defined */
};

Expand Down Expand Up @@ -230,6 +225,8 @@ struct menu {
*/
struct symbol *sym;

struct list_head link; /* link to symbol::menus */

/*
* The prompt associated with the node. This holds the prompt for a
* symbol as well as the text for a menu or comment, along with the
Expand All @@ -256,7 +253,7 @@ struct menu {
char *help;

/* The location where the menu node appears in the Kconfig files */
struct file *file;
const char *filename;
int lineno;

/* For use by front ends that need to store auxiliary data */
Expand All @@ -277,10 +274,6 @@ struct jump_key {
struct menu *target;
};

extern struct file *file_list;
extern struct file *current_file;
struct file *lookup_file(const char *name);

extern struct symbol symbol_yes, symbol_no, symbol_mod;
extern struct symbol *modules_sym;
extern int cdebug;
Expand Down
12 changes: 12 additions & 0 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@
#ifndef INTERNAL_H
#define INTERNAL_H

#include "hashtable.h"

#define SYMBOL_HASHSIZE (1U << 14)

extern HASHTABLE_DECLARE(sym_hashtable, SYMBOL_HASHSIZE);

#define for_all_symbols(sym) \
hash_for_each(sym_hashtable, sym, node)

struct menu;

extern struct menu *current_menu, *current_entry;

extern const char *cur_filename;
extern int cur_lineno;

#endif /* INTERNAL_H */
Loading

0 comments on commit d599fc4

Please sign in to comment.