diff --git a/libdispatch/Makefile.am b/libdispatch/Makefile.am index e1d072083..a4f3e00c4 100755 --- a/libdispatch/Makefile.am +++ b/libdispatch/Makefile.am @@ -44,9 +44,22 @@ endif # BUILD_V2 EXTRA_DIST=CMakeLists.txt ncsettings.hdr +# Build ncsettings.c as follows: +# 1. copy ncsettings.hdr to ncsettings.c +# 2. append libnetcdf.settings to ncsettings.c after +# processing it as follows: +# 1. convert tabs and cr to blanks +# 2. convert embedded double quote (") to escaped form (\"). +# 3. append newline (\n) to each line +# 4. surround each line with double quotes. +# 3. finally, add a semicolon to the end of ncsettings.c +# to complete the string constant. + ncsettings.c: $(top_srcdir)/libnetcdf.settings ncsettings.hdr rm -f ncsettings.c cat ncsettings.hdr > ncsettings.c - sed -e 's/"/\\"/g' <$(top_srcdir)/libnetcdf.settings | sed -e 's/\(.*\)/"\1\\n"/' >> ncsettings.c + tr '\t\r' ' ' <${top_srcdir}/libnetcdf.settings | \ + sed -e 's/"/\\"/g' | \ + sed -e 's/\(.*\)/\"\1\\n\"/' | \ + cat >> ncsettings.c echo ';' >> ncsettings.c - diff --git a/libdispatch/ncsettings.hdr b/libdispatch/ncsettings.hdr index 8c63a9623..1a3103034 100644 --- a/libdispatch/ncsettings.hdr +++ b/libdispatch/ncsettings.hdr @@ -1,36 +1,245 @@ /********************************************************************* - * Copyright 2014, UCAR/Unidata - * See netcdf/COPYRIGHT file for copying and redistribution conditions. - *********************************************************************/ + * Copyright 2014, UCAR/Unidata + * See netcdf/COPYRIGHT file for copying and redistribution conditions. + *********************************************************************/ #include "config.h" #include +#include +#include -static const char* ncsettings; +/* General rule +try to avoid any obscure string functions. +We currently use +- strcasecmp +- strchr +- strndup +- strlen +*/ +#undef DEBUG + +/* Define the legal leading key characters */ +#define KEYCHARS1 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_." + +/*forward*/ +static const char* ncsettings_text; + +static char** lines; +static int nlines; +static char* dup; static char** map = NULL; + +/*forward*/ static void parse(); +static int parseline(const char* line, int keypos); +static int iskeyline(const char* line); +static void preprocess(); const char* nc_settings(const char* key) { char** mapp; - int keylen = strlen(key); if(map == NULL) parse(); for(mapp=map;*mapp != NULL;mapp+=2) { /* Note this assumes that no key is a prefix of another */ - if(strncmp(*mapp,key,keylen)==0) { + if(strcasecmp(*mapp,key)==0) { return mapp[1]; } } return NULL; } -static void parse() +const char** +nc_settings_all() { + if(map == NULL) + parse(); + return (const char**)map; } -static const char* ncsettings = +const char* +nc_settings_text() +{ + return ncsettings_text; +} +static void +parse() +{ + int i,keypos; + int nkeys; + const char** line; + preprocess(); + + nkeys = 0; + /* Count # of key lines */ + for(i=0;i