1
0
mirror of git://projects.qi-hardware.com/openwrt-xburst.git synced 2024-12-01 20:55:19 +02:00

add wildcard support to menuconfig

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@1493 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
nbd 2005-07-17 22:50:05 +00:00
parent 5f8cbd6c03
commit 8d16fb08b8
2 changed files with 84 additions and 42 deletions

View File

@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <glob.h>
/* end standard C headers. */ /* end standard C headers. */
@ -3622,14 +3623,33 @@ void zconf_initscan(const char *name)
void zconf_nextfile(const char *name) void zconf_nextfile(const char *name)
{ {
struct file *file = file_lookup(name); size_t i;
struct buffer *buf = malloc(sizeof(*buf)); int retval;
memset(buf, 0, sizeof(*buf)); glob_t files;
char *filename;
struct file *file;
struct buffer *buf;
retval = glob(name, GLOB_ERR | GLOB_MARK, NULL, &files);
if (retval == GLOB_NOSPACE || retval == GLOB_ABORTED || retval == GLOB_NOMATCH) {
printf("%s:%d: glob failed: %s \"%s\"\n", zconf_curname(), zconf_lineno(),
retval == GLOB_NOSPACE ? "failed to allocate memory" :
retval == GLOB_ABORTED ? "read error" : "no match",
name);
exit(1);
}
for (i = files.gl_pathc-1; i != (size_t)-1; --i) {
filename = files.gl_pathv[i];
file = file_lookup(filename);
buf = malloc(sizeof(*buf));
memset(buf, 0, sizeof(*buf));
current_buf->state = YY_CURRENT_BUFFER; current_buf->state = YY_CURRENT_BUFFER;
zconfin = zconf_fopen(name); zconfin = zconf_fopen(filename);
if (!zconfin) { if (!zconfin) {
printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name); printf("%s:%d: can't open file \"%s\"\n",
zconf_curname(), zconf_lineno(), filename);
exit(1); exit(1);
} }
zconf_switch_to_buffer(zconf_create_buffer(zconfin,YY_BUF_SIZE)); zconf_switch_to_buffer(zconf_create_buffer(zconfin,YY_BUF_SIZE));
@ -3637,11 +3657,11 @@ void zconf_nextfile(const char *name)
current_buf = buf; current_buf = buf;
if (file->flags & FILE_BUSY) { if (file->flags & FILE_BUSY) {
printf("recursive scan (%s)?\n", name); printf("recursive scan (%s)?\n", filename);
exit(1); exit(1);
} }
if (file->flags & FILE_SCANNED) { if (file->flags & FILE_SCANNED) {
printf("file %s already scanned?\n", name); printf("file %s already scanned?\n", filename);
exit(1); exit(1);
} }
file->flags |= FILE_BUSY; file->flags |= FILE_BUSY;
@ -3649,6 +3669,7 @@ void zconf_nextfile(const char *name)
file->parent = current_file; file->parent = current_file;
current_file = file; current_file = file;
} }
}
static struct buffer *zconf_endfile(void) static struct buffer *zconf_endfile(void)
{ {

View File

@ -12,6 +12,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <glob.h>
#define LKC_DIRECT_LINK #define LKC_DIRECT_LINK
#include "lkc.h" #include "lkc.h"
@ -301,26 +302,45 @@ void zconf_initscan(const char *name)
void zconf_nextfile(const char *name) void zconf_nextfile(const char *name)
{ {
struct file *file = file_lookup(name); size_t i;
struct buffer *buf = malloc(sizeof(*buf)); int retval;
memset(buf, 0, sizeof(*buf)); glob_t files;
char *filename;
struct file *file;
struct buffer *buf;
current_buf->state = YY_CURRENT_BUFFER; retval = glob(name, GLOB_ERR | GLOB_MARK, NULL, &files);
yyin = zconf_fopen(name); if (retval == GLOB_NOSPACE || retval == GLOB_ABORTED || retval == GLOB_NOMATCH) {
if (!yyin) { printf("%s:%d: glob failed: %s \"%s\"\n", zconf_curname(), zconf_lineno(),
printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name); retval == GLOB_NOSPACE ? "failed to allocate memory" :
retval == GLOB_ABORTED ? "read error" : "no match",
name);
exit(1); exit(1);
} }
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
for (i = files.gl_pathc-1; i != (size_t)-1; --i) {
filename = files.gl_pathv[i];
file = file_lookup(filename);
buf = malloc(sizeof(*buf));
memset(buf, 0, sizeof(*buf));
current_buf->state = YY_CURRENT_BUFFER;
zconfin = zconf_fopen(filename);
if (!zconfin) {
printf("%s:%d: can't open file \"%s\"\n",
zconf_curname(), zconf_lineno(), filename);
exit(1);
}
zconf_switch_to_buffer(zconf_create_buffer(zconfin,YY_BUF_SIZE));
buf->parent = current_buf; buf->parent = current_buf;
current_buf = buf; current_buf = buf;
if (file->flags & FILE_BUSY) { if (file->flags & FILE_BUSY) {
printf("recursive scan (%s)?\n", name); printf("recursive scan (%s)?\n", filename);
exit(1); exit(1);
} }
if (file->flags & FILE_SCANNED) { if (file->flags & FILE_SCANNED) {
printf("file %s already scanned?\n", name); printf("file %s already scanned?\n", filename);
exit(1); exit(1);
} }
file->flags |= FILE_BUSY; file->flags |= FILE_BUSY;
@ -328,6 +348,7 @@ void zconf_nextfile(const char *name)
file->parent = current_file; file->parent = current_file;
current_file = file; current_file = file;
} }
}
static struct buffer *zconf_endfile(void) static struct buffer *zconf_endfile(void)
{ {