forked from espressif/esp-idf
tools: support rsource in MSYS config
This commit is contained in:
@@ -259,6 +259,7 @@ end a menu entry:
|
|||||||
- menu/endmenu
|
- menu/endmenu
|
||||||
- if/endif
|
- if/endif
|
||||||
- source
|
- source
|
||||||
|
- rsource
|
||||||
The first five also start the definition of a menu entry.
|
The first five also start the definition of a menu entry.
|
||||||
|
|
||||||
config:
|
config:
|
||||||
@@ -333,6 +334,14 @@ source:
|
|||||||
|
|
||||||
This reads the specified configuration file. This file is always parsed.
|
This reads the specified configuration file. This file is always parsed.
|
||||||
|
|
||||||
|
rsource:
|
||||||
|
|
||||||
|
"rsource" <prompt>
|
||||||
|
|
||||||
|
This reads the specified configuration file relative to the current file. This file is always parsed.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mainmenu:
|
mainmenu:
|
||||||
|
|
||||||
"mainmenu" <prompt>
|
"mainmenu" <prompt>
|
||||||
|
@@ -72,10 +72,11 @@ void zconfdump(FILE *out);
|
|||||||
void zconf_starthelp(void);
|
void zconf_starthelp(void);
|
||||||
FILE *zconf_fopen(const char *name);
|
FILE *zconf_fopen(const char *name);
|
||||||
void zconf_initscan(const char *name);
|
void zconf_initscan(const char *name);
|
||||||
void zconf_nextfile(const char *name);
|
void zconf_nextfile(const char *name, bool relative);
|
||||||
void zconf_nextfiles(const char *name);
|
void zconf_nextfiles(const char *name, bool relative);
|
||||||
int zconf_lineno(void);
|
int zconf_lineno(void);
|
||||||
const char *zconf_curname(void);
|
const char *zconf_curname(void);
|
||||||
|
const char *zconf_curdir(void);
|
||||||
|
|
||||||
/* confdata.c */
|
/* confdata.c */
|
||||||
const char *conf_get_configname(void);
|
const char *conf_get_configname(void);
|
||||||
@@ -112,7 +113,7 @@ void menu_finalize(struct menu *parent);
|
|||||||
void menu_set_type(int type);
|
void menu_set_type(int type);
|
||||||
|
|
||||||
/* util.c */
|
/* util.c */
|
||||||
struct file *file_lookup(const char *name);
|
struct file *file_lookup(const char *name, bool relative);
|
||||||
int file_write_dep(const char *name);
|
int file_write_dep(const char *name);
|
||||||
void *xmalloc(size_t size);
|
void *xmalloc(size_t size);
|
||||||
void *xcalloc(size_t nmemb, size_t size);
|
void *xcalloc(size_t nmemb, size_t size);
|
||||||
|
@@ -8,13 +8,28 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include "lkc.h"
|
#include "lkc.h"
|
||||||
|
|
||||||
/* file already present in list? If not add it */
|
/* file already present in list? If not add it */
|
||||||
struct file *file_lookup(const char *name)
|
struct file *file_lookup(const char *name, bool relative)
|
||||||
{
|
{
|
||||||
struct file *file;
|
struct file *file;
|
||||||
const char *file_name = sym_expand_string_value(name);
|
char fullname[PATH_MAX + 1] = { 0 };
|
||||||
|
|
||||||
|
if (relative) {
|
||||||
|
char *last_bslash = strrchr(zconf_curname(), '\\');
|
||||||
|
char *last_fslash = strrchr(zconf_curname(), '/');
|
||||||
|
char *last_slash = last_bslash ? last_bslash : last_fslash;
|
||||||
|
strncpy(fullname, zconf_curname(), last_slash - zconf_curname());
|
||||||
|
strcat(fullname, last_bslash ? "\\" : "/");
|
||||||
|
strcat(fullname, name);
|
||||||
|
} else {
|
||||||
|
sprintf(fullname, "%s", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *file_name = sym_expand_string_value(fullname);
|
||||||
|
|
||||||
for (file = file_list; file; file = file->next) {
|
for (file = file_list; file; file = file->next) {
|
||||||
if (!strcmp(name, file->name)) {
|
if (!strcmp(name, file->name)) {
|
||||||
|
@@ -14,6 +14,7 @@ mainmenu, T_MAINMENU, TF_COMMAND
|
|||||||
menu, T_MENU, TF_COMMAND
|
menu, T_MENU, TF_COMMAND
|
||||||
endmenu, T_ENDMENU, TF_COMMAND
|
endmenu, T_ENDMENU, TF_COMMAND
|
||||||
source, T_SOURCE, TF_COMMAND
|
source, T_SOURCE, TF_COMMAND
|
||||||
|
rsource, T_RSOURCE, TF_COMMAND
|
||||||
choice, T_CHOICE, TF_COMMAND
|
choice, T_CHOICE, TF_COMMAND
|
||||||
endchoice, T_ENDCHOICE, TF_COMMAND
|
endchoice, T_ENDCHOICE, TF_COMMAND
|
||||||
comment, T_COMMENT, TF_COMMAND
|
comment, T_COMMENT, TF_COMMAND
|
||||||
|
@@ -281,6 +281,7 @@ FILE *zconf_fopen(const char *name)
|
|||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
f = fopen(name, "r");
|
f = fopen(name, "r");
|
||||||
|
|
||||||
if (!f && name != NULL && name[0] != '/') {
|
if (!f && name != NULL && name[0] != '/') {
|
||||||
env = getenv(SRCTREE);
|
env = getenv(SRCTREE);
|
||||||
if (env) {
|
if (env) {
|
||||||
@@ -302,14 +303,14 @@ void zconf_initscan(const char *name)
|
|||||||
current_buf = xmalloc(sizeof(*current_buf));
|
current_buf = xmalloc(sizeof(*current_buf));
|
||||||
memset(current_buf, 0, sizeof(*current_buf));
|
memset(current_buf, 0, sizeof(*current_buf));
|
||||||
|
|
||||||
current_file = file_lookup(name);
|
current_file = file_lookup(name, false);
|
||||||
current_file->lineno = 1;
|
current_file->lineno = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zconf_nextfile(const char *name)
|
void zconf_nextfile(const char *name, bool relative)
|
||||||
{
|
{
|
||||||
struct file *iter;
|
struct file *iter;
|
||||||
struct file *file = file_lookup(name);
|
struct file *file = file_lookup(name, relative);
|
||||||
struct buffer *buf = xmalloc(sizeof(*buf));
|
struct buffer *buf = xmalloc(sizeof(*buf));
|
||||||
memset(buf, 0, sizeof(*buf));
|
memset(buf, 0, sizeof(*buf));
|
||||||
|
|
||||||
@@ -348,7 +349,7 @@ void zconf_nextfile(const char *name)
|
|||||||
current_file = file;
|
current_file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zconf_nextfiles(const char *expression)
|
void zconf_nextfiles(const char *expression, bool relative)
|
||||||
{
|
{
|
||||||
/* Expand environment variables in 'expression' */
|
/* Expand environment variables in 'expression' */
|
||||||
char* str = expand_environment(expression, zconf_curname(), zconf_lineno());
|
char* str = expand_environment(expression, zconf_curname(), zconf_lineno());
|
||||||
@@ -364,13 +365,13 @@ void zconf_nextfiles(const char *expression)
|
|||||||
if(*pos == ' ') {
|
if(*pos == ' ') {
|
||||||
*pos = '\0'; // split buffer into multiple c-strings
|
*pos = '\0'; // split buffer into multiple c-strings
|
||||||
if (strlen(pos + 1)) {
|
if (strlen(pos + 1)) {
|
||||||
zconf_nextfile(pos + 1);
|
zconf_nextfile(pos + 1, relative);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(str)) { // re-check as first character may have been a space
|
if (strlen(str)) { // re-check as first character may have been a space
|
||||||
zconf_nextfile(str);
|
zconf_nextfile(str, relative);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,4 +402,4 @@ int zconf_lineno(void)
|
|||||||
const char *zconf_curname(void)
|
const char *zconf_curname(void)
|
||||||
{
|
{
|
||||||
return current_pos.file ? current_pos.file->name : "<none>";
|
return current_pos.file ? current_pos.file->name : "<none>";
|
||||||
}
|
}
|
@@ -48,6 +48,7 @@ static struct menu *current_menu, *current_entry;
|
|||||||
%token <id>T_MENU
|
%token <id>T_MENU
|
||||||
%token <id>T_ENDMENU
|
%token <id>T_ENDMENU
|
||||||
%token <id>T_SOURCE
|
%token <id>T_SOURCE
|
||||||
|
%token <id>T_RSOURCE
|
||||||
%token <id>T_CHOICE
|
%token <id>T_CHOICE
|
||||||
%token <id>T_ENDCHOICE
|
%token <id>T_ENDCHOICE
|
||||||
%token <id>T_COMMENT
|
%token <id>T_COMMENT
|
||||||
@@ -135,6 +136,7 @@ common_stmt:
|
|||||||
| config_stmt
|
| config_stmt
|
||||||
| menuconfig_stmt
|
| menuconfig_stmt
|
||||||
| source_stmt
|
| source_stmt
|
||||||
|
| rsource_stmt
|
||||||
;
|
;
|
||||||
|
|
||||||
option_error:
|
option_error:
|
||||||
@@ -395,7 +397,13 @@ menu_block:
|
|||||||
source_stmt: T_SOURCE prompt T_EOL
|
source_stmt: T_SOURCE prompt T_EOL
|
||||||
{
|
{
|
||||||
printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
|
printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
|
||||||
zconf_nextfiles($2);
|
zconf_nextfiles($2, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
rsource_stmt: T_RSOURCE prompt T_EOL
|
||||||
|
{
|
||||||
|
printd(DEBUG_PARSE, "%s:%d:rsource %s\n", zconf_curname(), zconf_lineno(), $2);
|
||||||
|
zconf_nextfiles($2, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* comment entry */
|
/* comment entry */
|
||||||
|
Reference in New Issue
Block a user