diff options
Diffstat (limited to 'scripts/kconfig/symbol.c')
| -rw-r--r-- | scripts/kconfig/symbol.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 3d7877afc..31d5fbbfc 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c | |||
| @@ -6,8 +6,10 @@ | |||
| 6 | #include <ctype.h> | 6 | #include <ctype.h> |
| 7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | #ifndef __MINGW32__ | ||
| 9 | #include <regex.h> | 10 | #include <regex.h> |
| 10 | #include <sys/utsname.h> | 11 | #include <sys/utsname.h> |
| 12 | #endif | ||
| 11 | 13 | ||
| 12 | #define LKC_DIRECT_LINK | 14 | #define LKC_DIRECT_LINK |
| 13 | #include "lkc.h" | 15 | #include "lkc.h" |
| @@ -44,7 +46,9 @@ void sym_add_default(struct symbol *sym, const char *def) | |||
| 44 | void sym_init(void) | 46 | void sym_init(void) |
| 45 | { | 47 | { |
| 46 | struct symbol *sym; | 48 | struct symbol *sym; |
| 49 | #ifndef __MINGW32__ | ||
| 47 | struct utsname uts; | 50 | struct utsname uts; |
| 51 | #endif | ||
| 48 | char *p; | 52 | char *p; |
| 49 | static bool inited = false; | 53 | static bool inited = false; |
| 50 | 54 | ||
| @@ -52,7 +56,9 @@ void sym_init(void) | |||
| 52 | return; | 56 | return; |
| 53 | inited = true; | 57 | inited = true; |
| 54 | 58 | ||
| 59 | #ifndef __MINGW32__ | ||
| 55 | uname(&uts); | 60 | uname(&uts); |
| 61 | #endif | ||
| 56 | 62 | ||
| 57 | sym = sym_lookup("ARCH", 0); | 63 | sym = sym_lookup("ARCH", 0); |
| 58 | sym->type = S_STRING; | 64 | sym->type = S_STRING; |
| @@ -71,7 +77,11 @@ void sym_init(void) | |||
| 71 | sym = sym_lookup("UNAME_RELEASE", 0); | 77 | sym = sym_lookup("UNAME_RELEASE", 0); |
| 72 | sym->type = S_STRING; | 78 | sym->type = S_STRING; |
| 73 | sym->flags |= SYMBOL_AUTO; | 79 | sym->flags |= SYMBOL_AUTO; |
| 80 | #ifdef __MINGW32__ | ||
| 81 | sym_add_default(sym, "UNKNOWN"); | ||
| 82 | #else | ||
| 74 | sym_add_default(sym, uts.release); | 83 | sym_add_default(sym, uts.release); |
| 84 | #endif | ||
| 75 | } | 85 | } |
| 76 | 86 | ||
| 77 | enum symbol_type sym_get_type(struct symbol *sym) | 87 | enum symbol_type sym_get_type(struct symbol *sym) |
| @@ -718,24 +728,43 @@ struct symbol *sym_find(const char *name) | |||
| 718 | return symbol; | 728 | return symbol; |
| 719 | } | 729 | } |
| 720 | 730 | ||
| 731 | #if !defined HAVE_RE && !defined __MINGW32__ | ||
| 732 | #define HAVE_RE 1 | ||
| 733 | #endif | ||
| 734 | |||
| 721 | struct symbol **sym_re_search(const char *pattern) | 735 | struct symbol **sym_re_search(const char *pattern) |
| 722 | { | 736 | { |
| 723 | struct symbol *sym, **sym_arr = NULL; | 737 | struct symbol *sym, **sym_arr = NULL; |
| 724 | int i, cnt, size; | 738 | int i, cnt, size; |
| 739 | #if HAVE_RE | ||
| 725 | regex_t re; | 740 | regex_t re; |
| 741 | #else | ||
| 742 | /* without re support use: strstr(sym->name, upper(pattern)) */ | ||
| 743 | /* sym->name is a config, e.g. "SHELL_ASH" or "FEATURE_UTMP" */ | ||
| 744 | char upat[256] = {0}; | ||
| 745 | for (i = 0; i < 255 && pattern[i]; ++i) | ||
| 746 | upat[i] = toupper(pattern[i]); | ||
| 747 | #endif | ||
| 726 | 748 | ||
| 727 | cnt = size = 0; | 749 | cnt = size = 0; |
| 728 | /* Skip if empty */ | 750 | /* Skip if empty */ |
| 729 | if (strlen(pattern) == 0) | 751 | if (strlen(pattern) == 0) |
| 730 | return NULL; | 752 | return NULL; |
| 753 | #if HAVE_RE | ||
| 731 | if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE)) | 754 | if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE)) |
| 732 | return NULL; | 755 | return NULL; |
| 756 | #endif | ||
| 733 | 757 | ||
| 734 | for_all_symbols(i, sym) { | 758 | for_all_symbols(i, sym) { |
| 735 | if (sym->flags & SYMBOL_CONST || !sym->name) | 759 | if (sym->flags & SYMBOL_CONST || !sym->name) |
| 736 | continue; | 760 | continue; |
| 761 | #if HAVE_RE | ||
| 737 | if (regexec(&re, sym->name, 0, NULL, 0)) | 762 | if (regexec(&re, sym->name, 0, NULL, 0)) |
| 738 | continue; | 763 | continue; |
| 764 | #else | ||
| 765 | if (!strstr(sym->name, upat)) | ||
| 766 | continue; | ||
| 767 | #endif | ||
| 739 | if (cnt + 1 >= size) { | 768 | if (cnt + 1 >= size) { |
| 740 | void *tmp = sym_arr; | 769 | void *tmp = sym_arr; |
| 741 | size += 16; | 770 | size += 16; |
| @@ -749,7 +778,9 @@ struct symbol **sym_re_search(const char *pattern) | |||
| 749 | } | 778 | } |
| 750 | if (sym_arr) | 779 | if (sym_arr) |
| 751 | sym_arr[cnt] = NULL; | 780 | sym_arr[cnt] = NULL; |
| 781 | #if HAVE_RE | ||
| 752 | regfree(&re); | 782 | regfree(&re); |
| 783 | #endif | ||
| 753 | 784 | ||
| 754 | return sym_arr; | 785 | return sym_arr; |
| 755 | } | 786 | } |
