diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-04-11 23:06:30 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-04-11 23:06:30 +0000 |
commit | 3874129d283ec7f4cd62adf121abdb115f31a967 (patch) | |
tree | d4535a88c1a8836428551104634a90bfaa1dc8f0 /nuttx/tools | |
parent | 7d770cc270d1e3f73899309ca4a2ac9a1739ffcc (diff) | |
download | px4-nuttx-3874129d283ec7f4cd62adf121abdb115f31a967.tar.gz px4-nuttx-3874129d283ec7f4cd62adf121abdb115f31a967.tar.bz2 px4-nuttx-3874129d283ec7f4cd62adf121abdb115f31a967.zip |
Add tools/cmpconfig.c to compare to configuration files
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4592 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/tools')
-rw-r--r-- | nuttx/tools/Makefile.host | 9 | ||||
-rwxr-xr-x | nuttx/tools/README.txt | 31 | ||||
-rw-r--r-- | nuttx/tools/cfgparser.c | 4 | ||||
-rw-r--r-- | nuttx/tools/cmpconfig.c | 323 | ||||
-rw-r--r-- | nuttx/tools/mkconfig.c | 2 |
5 files changed, 353 insertions, 16 deletions
diff --git a/nuttx/tools/Makefile.host b/nuttx/tools/Makefile.host index 2384697b2..cf421aa3b 100644 --- a/nuttx/tools/Makefile.host +++ b/nuttx/tools/Makefile.host @@ -1,8 +1,8 @@ ############################################################################ # Makefile.host # -# Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -46,6 +46,11 @@ CFLAGS = -O2 -Wall -I. mkconfig: mkconfig.c cfgparser.c @gcc $(CFLAGS) -o mkconfig mkconfig.c cfgparser.c +# cmpconfig - Compare the contents of two configuration files + +cmpconfig: cmpconfig.c + @gcc $(CFLAGS) -o cmpconfig cmpconfig.c + # mkversion - Convert a .version file into a C version.h file mkversion: mkconfig.c cfgparser.c diff --git a/nuttx/tools/README.txt b/nuttx/tools/README.txt index e859e8735..b4368aff9 100755 --- a/nuttx/tools/README.txt +++ b/nuttx/tools/README.txt @@ -19,7 +19,7 @@ configure.sh mkconfig.c, cfgparser.c, and cfgparser.h - This is C file that is used to build mkconfig program. The mkconfig + These are Cs file that are used to build mkconfig program. The mkconfig program is used during the initial NuttX build. When you configure NuttX, you will copy a configuration file called .config @@ -31,6 +31,11 @@ mkconfig.c, cfgparser.c, and cfgparser.h into include/nuttx/config.h. config.h is a another version of the NuttX configuration that can be included by C files. +cmdconfig.c + + This C file can be used to build a utility for comparing two NuttX + configuration files. + mkexport.sh and Makefile.export These implement part of the top-level Makefile's 'export' target. That @@ -136,10 +141,10 @@ bdf-convert.c genfontsources: ifeq ($(CONFIG_NXFONT_SANS23X27),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=1 EXTRADEFINES=$(EXTRADEFINES) + @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=1 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_MYFONT),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=2 EXTRADEFINES=$(EXTRADEFINES) + @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=2 EXTRADEFINES=$(EXTRADEFINES) endif 6. nuttx/graphics/nxfonts/Make.defs. Set the make variable NXFSET_CSRCS. @@ -147,10 +152,10 @@ bdf-convert.c NXFONTS_FONTID=2: ifeq ($(CONFIG_NXFONT_SANS23X27),y) - NXFSET_CSRCS += nxfonts_bitmaps_sans23x27.c + NXFSET_CSRCS += nxfonts_bitmaps_sans23x27.c endif ifeq ($(CONFIG_NXFONT_MYFONT),y) - NXFSET_CSRCS += nxfonts_bitmaps_myfont.c + NXFSET_CSRCS += nxfonts_bitmaps_myfont.c endif 7. nuttx/graphics/nxfonts/Makefile.sources. This is the Makefile used @@ -161,12 +166,12 @@ bdf-convert.c was used in nuttx/graphics/nxfonts/Make.defs): ifeq ($(NXFONTS_FONTID),1) - NXFONTS_PREFIX := g_sans23x27_ - GEN_CSRC = nxfonts_bitmaps_sans23x27.c + NXFONTS_PREFIX := g_sans23x27_ + GEN_CSRC = nxfonts_bitmaps_sans23x27.c endif ifeq ($(NXFONTS_FONTID),2) - NXFONTS_PREFIX := g_myfont_ - GEN_CSRC = nxfonts_bitmaps_myfont.c + NXFONTS_PREFIX := g_myfont_ + GEN_CSRC = nxfonts_bitmaps_myfont.c endif 8. graphics/nxfonts/nxfonts_bitmaps.c. This is the file that contains @@ -212,8 +217,12 @@ bdf-convert.c Makefile.host This is the makefile that is used to make the mkconfig program from - the mkconfig.c C file, the mkversion program from the mkconfig.c C file, - or the mksyscall program from the mksyscall.c file. + the mkconfig.c C file, the cmpconfig program from cmpconfig.c C file + the mkversion program from the mkconfig.c C file, or the mksyscall + program from the mksyscall.c file. Usage: + + cd tools/ + make -f Makefile.host <program> mkromfsimg.sh diff --git a/nuttx/tools/cfgparser.c b/nuttx/tools/cfgparser.c index 2917a2f60..655fac573 100644 --- a/nuttx/tools/cfgparser.c +++ b/nuttx/tools/cfgparser.c @@ -1,8 +1,8 @@ /**************************************************************************** * tools/cfgpaser.c * - * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/tools/cmpconfig.c b/nuttx/tools/cmpconfig.c new file mode 100644 index 000000000..1c4cbfe1b --- /dev/null +++ b/nuttx/tools/cmpconfig.c @@ -0,0 +1,323 @@ +/**************************************************************************** + * tools/cmpconfig.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <errno.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct variable_s +{ + struct variable_s *flink; + char *var; + char *val; + char storage[1]; +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void show_usage(const char *progname) +{ + fprintf(stderr, "USAGE: %s <config1> <config2>\n", 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 (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; + char *varval2; + + while (list1 || list2) + { + if (list1->val) + { + varval1 = list1->val; + } + else + { + varval1 = "<NULL>"; + } + + if (list2->val) + { + varval2 = list2->val; + } + else + { + varval2 = "<NULL>"; + } + + if (!list1) + { + printf("file1:\n"); + printf("file2: %s=%s\n\n", list2->var, varval2); + list2 = list2->flink; + } + else if (!list2) + { + printf("file1: %s=%s\n", list1->var, varval1); + printf("file2:\n\n"); + list1 = list1->flink; + } + else + { + int result = strcmp(list1->var, list2->var); + if (result < 0) + { + printf("file1: %s=%s\n", list1->var, varval1); + printf("file2:\n\n"); + list1 = list1->flink; + } + else if (result > 0) + { + printf("file1:\n"); + printf("file2: %s=%s\n\n", list2->var, varval2); + list2 = list2->flink; + } + else + { + int result = strcmp(varval1, varval2); + if (result != 0) + { + printf("file1: %s=%s\n", list1->var, varval1); + printf("file2: %s=%s\n\n", list2->var, varval2); + } + + list1 = list1->flink; + list2 = list2->flink; + } + } + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char **argv, char **envp) +{ + struct variable_s *list1 = 0; + struct variable_s *list2 = 0; + FILE *stream1; + FILE *stream2; + + if (argc != 3) + { + fprintf(stderr, "Unexpected number of arguments: %d\n\n", argc); + show_usage(argv[0]); + } + + stream1 = fopen(argv[1], "r"); + if (!stream1) + { + fprintf(stderr, "Failed to open %s for reading: %s\n\n", + argv[1], strerror(errno)); + show_usage(argv[0]); + } + + stream2 = fopen(argv[2], "r"); + if (!stream2) + { + fprintf(stderr, "Failed to open %s for reading: %s\n\n", + argv[2], strerror(errno)); + show_usage(argv[0]); + } + + parse_file(stream1, &list1); + parse_file(stream2, &list2); + + fclose(stream1); + fclose(stream2); + + printf("Comparing:\n\n"); + printf(" file1 = %s\n", argv[1]); + printf(" file2 = %s\n\n", argv[2]); + compare_variables(list1, list2); + return EXIT_SUCCESS; +} diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c index 7e3162b8f..5bacb24a6 100644 --- a/nuttx/tools/mkconfig.c +++ b/nuttx/tools/mkconfig.c @@ -88,7 +88,7 @@ int main(int argc, char **argv, char **envp) exit(2); } - stream= fopen(filepath, "r"); + stream = fopen(filepath, "r"); if (!stream) { fprintf(stderr, "open %s failed: %s\n", filepath, strerror(errno)); |