From: hachti Date: Sun, 14 Jan 2007 13:12:15 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://gitweb.hachti.de/?a=commitdiff_plain;h=50c86ded564f01101a88eb741f2a76621b30a02f;p=h316.git *** empty log message *** --- diff --git a/pc-tools/ldc2/Makefile b/pc-tools/ldc2/Makefile index 335774a..4df7df2 100644 --- a/pc-tools/ldc2/Makefile +++ b/pc-tools/ldc2/Makefile @@ -22,7 +22,7 @@ APP_SOURCES=$(foreach obj, $(APP_OBJECTS:.o=.cpp),$(SRC_DIR)/$(obj)) ##All objects depend on all headers. simple but works #*.o: $(SRC_DIR)/*.hh -%.dep : $(SRC_DIR)/%.cpp +nothing% %.dep : $(SRC_DIR)/%.cpp @ echo Building dependencies for $<. @$(SHELL) -c "g++ -M $<" | awk 'BEGIN {N=0}{if(N==0)printf("%s %s\n","$@",$$0);else printf("%s\n", $$0);N+=1;}' > $@ diff --git a/pc-tools/ldc2/src/configuration_manager.cpp b/pc-tools/ldc2/src/configuration_manager.cpp index 418beab..4184105 100644 --- a/pc-tools/ldc2/src/configuration_manager.cpp +++ b/pc-tools/ldc2/src/configuration_manager.cpp @@ -1,5 +1,7 @@ #include "configuration_manager.hh" #include +#include +#include #define MAX_LINE_LENGTH 80 @@ -225,6 +227,7 @@ vector configuration_manager::read_args(int argc, char ** args){ } return messages; } + /*! *\brief Extract a value from a configuration file line or @@ -245,6 +248,45 @@ bool configuration_manager::analyse_bool(const string & data){ return true; } +/*! + *brief Read in and parse a configuration file. + *\arg file String containing the filename + *\return Empty Vector or Vector full of strings containing + * the error message(s). + */ +vector configuration_manager::read_file(string filename){ + vectorresult; + FILE * fp=fopen(filename.c_str(),"r"); + if (! fp) { + result.insert(result.end(),"Error!"); + result.insert(result.end(),"Could not open file:"+filename); + return result; + } + + char buffer[1000]; + while(fgets(buffer,1000,fp)){ + if (strlen (buffer)){ + char*l2=buffer+strspn(buffer," \t"); + if (l2[0]!='#'){ + string line=l2; + unsigned int pos=line.find("="); + if (pos==0){ + result.insert(result.end(),"Error!"); + result.insert(result.end(),"In File:"+filename); + result.insert(result.end(),"Line beginning with '='!"); + return result; + } + + } // if not # + + } // if (strlen()) + } // while(...) + + + fclose (fp); + return result; +} + /*! *\brief Generate help. *\arg target Reference to a vector to which lots of helpful diff --git a/pc-tools/ldc2/src/discard_block.cpp b/pc-tools/ldc2/src/discard_block.cpp index ee50ec4..a854a49 100644 --- a/pc-tools/ldc2/src/discard_block.cpp +++ b/pc-tools/ldc2/src/discard_block.cpp @@ -1,8 +1,9 @@ #include #include -#include "discard_block.hh" #include "tape_block.hh" +#include "discard_block.hh" + using namespace std; diff --git a/pc-tools/ldc2/src/main.cpp b/pc-tools/ldc2/src/main.cpp index a86291b..282ce9a 100644 --- a/pc-tools/ldc2/src/main.cpp +++ b/pc-tools/ldc2/src/main.cpp @@ -24,7 +24,6 @@ int dump_vector(vector arguments){ } - int main(int argc, char ** args){ /* Configuration data */ @@ -127,11 +126,28 @@ Errors will be converted to warnings.", &config_file_set,&config_file, ""); + // Process command line first time if((dump_vector(ar.read_args(argc,args))||do_help)){ dump_vector(ar.get_help()); exit(1); } + // If user has a config file, use it. + if (config_file_set){ + if(dump_vector(ar.read_file(config_file))){ + dump_vector(ar.get_help()); + exit(1); + } + // Process command line a second time to override values from config file. + if(dump_vector(ar.read_args(argc,args))||do_help){ + dump_vector(ar.get_help()); + exit(1); + } + } + + + + if (infile_set==1){ printf("Opening file for input:%s\n",infile.c_str()); in_fd=open(infile.c_str(),O_RDONLY); diff --git a/pc-tools/ldc2/src/tape_block.cpp b/pc-tools/ldc2/src/tape_block.cpp index abba1d6..a7ae129 100644 --- a/pc-tools/ldc2/src/tape_block.cpp +++ b/pc-tools/ldc2/src/tape_block.cpp @@ -216,6 +216,7 @@ tape_block * tape_block::gen_from_fd(int fd, eot_block * n_eot_block=0; discard_block * n_discard_block=0; + //Use the private constructor which reads in the block from a file descriptor n_tape_block=new tape_block(fd,input_start,input_stop,start_stop_arg); // Retype to data_block, eot_block, discard_block - if possible @@ -231,8 +232,8 @@ tape_block * tape_block::gen_from_fd(int fd, n_discard_block = new discard_block(*n_tape_block); delete n_tape_block; return n_discard_block; - default: - return n_tape_block; + default: // Unknown block, a bad thing! + return n_tape_block; } delete n_tape_block; @@ -256,7 +257,6 @@ tape_block * tape_block::gen_from_fd(int fd, } // Here only type 0 left - switch(n_data_block_0->get_subtype()){ case 000: n_data_block_0_x=new data_block_0_0(*n_data_block_0); break; case 001: n_data_block_0_x=new data_block_0_1(*n_data_block_0); break;