summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-04 16:50:15 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-04 16:50:15 +0000
commit3f81b4dd94a7ad8cf65490fc12248e16f718f31d (patch)
tree80cf7a3db778ceaf0241bea6a2f6352304e15fe8
parente2a52b6973fc9cbc6f751d62c8ce31de5968cf32 (diff)
downloadnuttx-3f81b4dd94a7ad8cf65490fc12248e16f718f31d.tar.gz
nuttx-3f81b4dd94a7ad8cf65490fc12248e16f718f31d.tar.bz2
nuttx-3f81b4dd94a7ad8cf65490fc12248e16f718f31d.zip
Working on configure.c
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5477 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/tools/Makefile.host4
-rw-r--r--nuttx/tools/cfgdefine.c2
-rw-r--r--nuttx/tools/cfgdefine.h2
-rw-r--r--nuttx/tools/cfgparser.c165
-rw-r--r--nuttx/tools/cfgparser.h15
-rw-r--r--nuttx/tools/cmpconfig.c154
6 files changed, 91 insertions, 251 deletions
diff --git a/nuttx/tools/Makefile.host b/nuttx/tools/Makefile.host
index 663ff29c7..73352aae3 100644
--- a/nuttx/tools/Makefile.host
+++ b/nuttx/tools/Makefile.host
@@ -89,8 +89,8 @@ endif
# cmpconfig - Compare the contents of two configuration files
-cmpconfig$(HOSTEXEEXT): cmpconfig.c
- $(Q) $(HOSTCC) $(HOSTCFLAGS) -o cmpconfig$(HOSTEXEEXT) cmpconfig.c
+cmpconfig$(HOSTEXEEXT): cmpconfig.c cfgparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o cmpconfig$(HOSTEXEEXT) cmpconfig.c cfgparser.c
ifdef HOSTEXEEXT
cmpconfig: cmpconfig$(HOSTEXEEXT)
diff --git a/nuttx/tools/cfgdefine.c b/nuttx/tools/cfgdefine.c
index 00dd11c20..ee1dd4003 100644
--- a/nuttx/tools/cfgdefine.c
+++ b/nuttx/tools/cfgdefine.c
@@ -76,7 +76,7 @@ static const char *dequote_list[] =
NULL /* Marks the end of the list */
};
- /****************************************************************************
+/****************************************************************************
* Private Functions
****************************************************************************/
diff --git a/nuttx/tools/cfgdefine.h b/nuttx/tools/cfgdefine.h
index 04817b719..f76ba73fb 100644
--- a/nuttx/tools/cfgdefine.h
+++ b/nuttx/tools/cfgdefine.h
@@ -59,6 +59,6 @@ extern char line[LINESIZE+1];
* Public Functions
****************************************************************************/
-extern void generate_definitions(FILE *stream);
+void generate_definitions(FILE *stream);
#endif /* __TOOLS_CFGDEFINE_H */
diff --git a/nuttx/tools/cfgparser.c b/nuttx/tools/cfgparser.c
index 1a35f7857..cb4ab4c52 100644
--- a/nuttx/tools/cfgparser.c
+++ b/nuttx/tools/cfgparser.c
@@ -38,7 +38,9 @@
****************************************************************************/
#include <string.h>
+#include <stdlib.h>
#include <ctype.h>
+
#include "cfgparser.h"
/****************************************************************************
@@ -55,28 +57,7 @@ char line[LINESIZE+1];
* Private Data
****************************************************************************/
-/* These are configuration variable name that are quoted by configuration tool
- * but which must be unquoted when used in C code.
- */
-
-static const char *dequote_list[] =
-{
- /* NuttX */
-
- "CONFIG_USER_ENTRYPOINT", /* Name of entry point function */
-
- /* NxWidgets/NxWM */
-
- "CONFIG_NXWM_BACKGROUND_IMAGE", /* Name of bitmap image class */
- "CONFIG_NXWM_STARTWINDOW_ICON", /* Name of bitmap image class */
- "CONFIG_NXWM_NXCONSOLE_ICON", /* Name of bitmap image class */
- "CONFIG_NXWM_CALIBRATION_ICON", /* Name of bitmap image class */
- "CONFIG_NXWM_HEXCALCULATOR_ICON", /* Name of bitmap image class */
-
- NULL /* Marks the end of the list */
-};
-
- /****************************************************************************
+/****************************************************************************
* Private Functions
****************************************************************************/
@@ -203,69 +184,15 @@ static void parse_line(char *ptr, char **varname, char **varval)
}
}
-static char *dequote_value(const char *varname, char *varval)
-{
- const char **dqnam;
- char *dqval = varval;
- int len;
-
- if (dqval)
- {
- /* Check if the variable name is in the list of strings to be dequoated */
-
- for (dqnam = dequote_list; *dqnam; dqnam++)
- {
- if (strcmp(*dqnam, varname) == 0)
- {
- break;
- }
- }
-
- /* Did we find the variable name in the list of configuration variables
- * to be dequoated?
- */
-
- if (*dqnam)
- {
- /* Yes... Check if there is a traiing quote */
-
- len = strlen(dqval);
- if (dqval[len-1] == '"')
- {
- /* Yes... replace it with a terminator */
-
- dqval[len-1] = '\0';
- len--;
- }
-
- /* Is there a leading quote? */
-
- if (dqval[0] == '"')
- {
- /* Yes.. skip over the leading quote */
-
- dqval++;
- len--;
- }
-
- /* Handle the case where nothing is left after dequoting */
-
- if (len <= 0)
- {
- dqval = NULL;
- }
- }
- }
-
- return dqval;
-}
-
/****************************************************************************
* Public Functions
****************************************************************************/
-void parse_file(FILE *stream)
+void parse_file(FILE *stream, struct variable_s **list)
{
+ struct variable_s *curr;
+ struct variable_s *prev;
+ struct variable_s *next;
char *varname;
char *varval;
char *ptr;
@@ -283,40 +210,90 @@ void parse_file(FILE *stream)
parse_line(ptr, &varname, &varval);
- /* Was a variable name found? */
+ /* If the variable has not value (or the special value 'n'), then
+ * ignore it.
+ */
- if (varname)
+ if (!varval || strcmp(varval, "n") == 0)
{
- /* Yes.. dequote the value if necessary */
+ continue;
+ }
+
+ /* Make sure that a variable name was found. */
- varval = dequote_value(varname, varval);
+ if (varname)
+ {
+ int varlen = strlen(varname) + 1;
+ int vallen = 0;
- /* If no value was provided or if the special value 'n' was provided,
- * then undefine the configuration variable.
+ /* Get the size of the value, including the NUL terminating
+ * character.
*/
- if (!varval || strcmp(varval, "n") == 0)
+ if (varval)
{
- printf("#undef %s\n", varname);
+ vallen = strlen(varval) + 1;
}
- /* Simply define the configuration variable if it has the special
- * value "y"
+ /* Allocate memory to hold the struct variable_s with the
+ * variable name and the value.
*/
- else if (strcmp(varval, "y") == 0)
+ curr = (struct variable_s *)malloc(sizeof(struct variable_s) + varlen + vallen - 1);
+ if (curr)
{
- printf("#define %s 1\n", varname);
+ /* Add the variable to the list */
+
+ curr->var = &curr->storage[0];
+ strcpy(curr->var, varname);
+
+ curr->val = NULL;
+ if (varval)
+ {
+ curr->val = &curr->storage[varlen];
+ strcpy(curr->val, varval);
+ }
}
- /* Otherwise, use the value as provided */
+ prev = 0;
+ next = *list;
+ while (next && strcmp(next->var, curr->var) <= 0)
+ {
+ prev = next;
+ next = next->flink;
+ }
+ if (prev)
+ {
+ prev->flink = curr;
+ }
else
{
- printf("#define %s %s\n", varname, varval);
+ *list = curr;
}
+
+ curr->flink = next;
}
}
}
while (ptr);
}
+
+struct variable_s *find_variable(const char *varname, struct variable_s *list)
+{
+ char *varval1;
+ char *varval2;
+
+ while (list)
+ {
+ if (strcmp(varname, list->var) == 0)
+ {
+ return list;
+ }
+
+ list = list->flink;
+ }
+
+ return NULL;
+}
+
diff --git a/nuttx/tools/cfgparser.h b/nuttx/tools/cfgparser.h
index b1c4bae76..b1f421a68 100644
--- a/nuttx/tools/cfgparser.h
+++ b/nuttx/tools/cfgparser.h
@@ -50,6 +50,18 @@
#define LINESIZE ( PATH_MAX > 256 ? PATH_MAX : 256 )
/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct variable_s
+{
+ struct variable_s *flink;
+ char *var;
+ char *val;
+ char storage[1];
+};
+
+/****************************************************************************
* Public Data
****************************************************************************/
@@ -59,6 +71,7 @@ extern char line[LINESIZE+1];
* Public Functions
****************************************************************************/
-extern void parse_file(FILE *stream);
+void parse_file(FILE *stream, struct variable_s **list);
+struct variable_s *find_variable(const char *varname, struct variable_s *list);
#endif /* __TOOLS_CFGPARSER_H */
diff --git a/nuttx/tools/cmpconfig.c b/nuttx/tools/cmpconfig.c
index 2958acdc7..08b7dab3f 100644
--- a/nuttx/tools/cmpconfig.c
+++ b/nuttx/tools/cmpconfig.c
@@ -43,6 +43,8 @@
#include <ctype.h>
#include <errno.h>
+#include "cfgparser.h"
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -51,14 +53,6 @@
* Private Types
****************************************************************************/
-struct variable_s
-{
- struct variable_s *flink;
- char *var;
- char *val;
- char storage[1];
-};
-
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -69,150 +63,6 @@ static void show_usage(const char *progname)
exit(EXIT_FAILURE);
}
-static char *skip_space(char *ptr)
-{
- while (*ptr && isspace((int)*ptr)) ptr++;
- return ptr;
-}
-
-static char *read_line(FILE *stream, char *line, int len)
-{
- char *ptr;
-
- for (;;)
- {
- line[len-1] = '\0';
- if (!fgets(line, len, stream))
- {
- return NULL;
- }
- else
- {
- ptr = skip_space(line);
- if (*ptr && *ptr != '#' && *ptr != '\n')
- {
- return ptr;
- }
- }
- }
-}
-
-static char *find_name_end(char *ptr)
-{
- while (*ptr && (isalnum((int)*ptr) || *ptr == '_')) ptr++;
- return ptr;
-}
-
-static char *find_value_end(char *ptr)
-{
- while (*ptr && !isspace((int)*ptr))
- {
- if (*ptr == '"')
- {
- do ptr++; while (*ptr && *ptr != '"');
- if (*ptr) ptr++;
- }
- else
- {
- do ptr++; while (*ptr && !isspace((int)*ptr) && *ptr != '"');
- }
- }
- return ptr;
-}
-
-static void parse_line(char *ptr, char **varname, char **varval)
-{
- *varname = ptr;
- *varval = NULL;
-
- ptr = find_name_end(ptr);
- if (*ptr && *ptr != '=')
- {
- *ptr = '\0';
- ptr = skip_space(ptr + 1);
- }
-
- if (*ptr == '=')
- {
- *ptr = '\0';
- ptr = skip_space(ptr + 1);
- if (*ptr)
- {
- *varval = ptr;
- ptr = find_value_end(ptr);
- *ptr = '\0';
- }
- }
-}
-
-static void parse_file(FILE *stream, struct variable_s **list)
-{
- char line[10242];
- struct variable_s *curr;
- struct variable_s *prev;
- struct variable_s *next;
- char *varname;
- char *varval;
- char *ptr;
-
- do
- {
- ptr = read_line(stream, line, 1024);
- if (ptr)
- {
- parse_line(ptr, &varname, &varval);
- if (!varval || strcmp(varval, "n") == 0)
- {
- continue;
- }
-
- if (varname)
- {
- int varlen = strlen(varname) + 1;
- int vallen = 0;
-
- if (varval)
- {
- vallen = strlen(varval) + 1;
- }
-
- curr = (struct variable_s *)malloc(sizeof(struct variable_s) + varlen + vallen - 1);
- if (curr)
- {
- curr->var = &curr->storage[0];
- strcpy(curr->var, varname);
-
- curr->val = NULL;
- if (varval)
- {
- curr->val = &curr->storage[varlen];
- strcpy(curr->val, varval);
- }
- }
-
- prev = 0;
- next = *list;
- while (next && strcmp(next->var, curr->var) <= 0)
- {
- prev = next;
- next = next->flink;
- }
-
- if (prev)
- {
- prev->flink = curr;
- }
- else
- {
- *list = curr;
- }
- curr->flink = next;
- }
- }
- }
- while (ptr);
-}
-
static void compare_variables(struct variable_s *list1, struct variable_s *list2)
{
char *varval1;