##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;}' > $@
#include "configuration_manager.hh"
#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
#define MAX_LINE_LENGTH 80
}
return messages;
}
+
/*!
*\brief Extract a value from a configuration file line or
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<string> configuration_manager::read_file(string filename){
+ vector<string>result;
+ 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<string> to which lots of helpful
#include <string>
#include <vector>
-#include "discard_block.hh"
#include "tape_block.hh"
+#include "discard_block.hh"
+
using namespace std;
}
-
int main(int argc, char ** args){
/* Configuration data */
&config_file_set,&config_file,
"<file-name>");
+ // 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);
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
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;
}
// 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;