diff --git a/dataobj/tabfile.cc b/dataobj/tabfile.cc index 828955297..f162e2d09 100644 --- a/dataobj/tabfile.cc +++ b/dataobj/tabfile.cc @@ -24,6 +24,7 @@ bool tabfile_t::open(const char *filename) { close(); + substitute_map.clear(); file = dr_fopen(filename, "r"); current_line_number = 0; return file != NULL; @@ -36,6 +37,7 @@ void tabfile_t::close() fclose(file); file = NULL; } + substitute_map.clear(); } @@ -295,177 +297,220 @@ bool tabfile_t::read(tabfileobj_t &objinfo, FILE *fp) { bool lines = false; char line[LINEBUFFER_SIZE]; - char line_expand[LINEBUFFER_SIZE]; char delim_expand[LINEBUFFER_SIZE]; char buffer[LINEBUFFER_SIZE]; char *param[10]; char *expansion[10]; + + bool in_sub_block = false; + const char *ENDSUB = "sub-end"; + const char *STARTSUB = "substart"; + const char DEFAULT = '#'; + char substitution = DEFAULT; current_line_number = 0; objinfo.clear(); - + do { while(read_line(line, sizeof(line)) && *line != '-') { - char *delim = strchr(line, '='); - - if(delim) { - *delim++ = '\0'; - format_key(line); - if (line[0] == 0) { - return false; + // This part of the code handles substitution blocks. Lines get stored in the substitution_map, unless it's the end of the block. + if(in_sub_block) { + if(!strcmp(line, ENDSUB)){ + in_sub_block = false; } - - int parameters = 0; - int expansions = 0; - /* - @line, the whole parameter text (everything before =) - @delim, the whole value text (everything after =) - @parameters, number of fields enclosed by square brackets [] - @expansions, number of expansions included in the value (text inside angle brackets <>) - @param, array containing the text inside each [] field - @expansion, array containing the text inside each <> field - */ - if(find_parameter_expansion(line, delim, ¶meters, &expansions, param, expansion) > 0) { - int parameter_value[10][256]; - int parameter_length[10]; - int parameter_values[10]; // number of possible 'values' inside each [] field | e.g. [0-4]=5 / [n,s,w]=3 - char parameter_name[256][6]; // non-numeric ribis strings for all parameter fields consecutively - bool parameter_ribi[10]; // true if parameters are ribi strings - - int combinations=1; - int names = 0; // total number of ribi parameters - - // analyse and obtain all parameter expansions - for(int i=0; i) + @param, array containing the text inside each [] field + @expansion, array containing the text inside each <> field + */ + if(find_parameter_expansion(line, delim, ¶meters, &expansions, param, expansion) > 0) { + int parameter_value[10][256]; + int parameter_length[10]; + int parameter_values[10]; // number of possible 'values' inside each [] field | e.g. [0-4]=5 / [n,s,w]=3 + char parameter_name[256][6]; // non-numeric ribis strings for all parameter fields consecutively + bool parameter_ribi[10]; // true if parameters are ribi strings + + int combinations=1; + int names = 0; // total number of ribi parameters + + // analyse and obtain all parameter expansions + for(int i=0; i= 256) { + dbg->fatal("tabfile_t::read", "Invalid number range %d-%d (Max range %d values) in line %d", start_range, end_range, 256 - parameter_values[i], current_line_number); + } + + for(int range=start_range; range= 256) { - dbg->fatal("tabfile_t::read", "Invalid number range %d-%d (Max range %d values) in line %d", start_range, end_range, 256 - parameter_values[i], current_line_number); + // start expansion of the parameter + for(int c=0; c0) { + // warp values around the number of parameters the expansion has + for(int j=0; j0) { - // warp values around the number of parameters the expansion has - for(int j=0; j0) { - int expansion_length[10]; - int expansion_value[10]; + // expand the value + if(expansions>0) { + int expansion_length[10]; + int expansion_value[10]; - for(int i=0; i")-1; - sprintf(buffer, "%.*s", expansion_length[i]+1, expansion[i]); + for(int i=0; i")-1; + sprintf(buffer, "%.*s", expansion_length[i]+1, expansion[i]); - expansion_value[i] = calculate(buffer, parameter_value, parameters, combination); - } + expansion_value[i] = calculate(buffer, parameter_value, parameters, combination); + } + + sprintf(delim_expand, "%.*s%d", (int)(expansion[0]-delim), delim, expansion_value[0]); + for(int i=1; iwarning( "tabfile_t::read", "No data in \"%s\"", line ); } } - lines = true; - } - else if( *line ) { - dbg->warning( "tabfile_t::read", "No data in \"%s\"", line ); } } } while(!lines && !feof(file)); // skip empty objects diff --git a/dataobj/tabfile.h b/dataobj/tabfile.h index 83239a566..881d04c5b 100644 --- a/dataobj/tabfile.h +++ b/dataobj/tabfile.h @@ -8,6 +8,8 @@ #include +#include +#include #include "../simcolor.h" #include "../tpl/stringhashtable_tpl.h" @@ -47,7 +49,7 @@ class tabfile_t public: tabfile_t() : file(NULL) {} ~tabfile_t() { close(); } - + std::map> substitute_map; // keeps substitution lines public: bool open(const char *filename);