From ad324d29d885b9af1608a6e9c1f978bdcd202eb7 Mon Sep 17 00:00:00 2001 From: hachti Date: Wed, 29 Nov 2006 02:48:02 +0000 Subject: [PATCH] *** empty log message *** --- pc-tools/ldc2/doc/appendix.tex | 7 +- pc-tools/ldc2/doc/main.tex | 1 + pc-tools/ldc2/doc/req_spec.tex | 97 ++++--- pc-tools/ldc2/src/argument_reader.cpp | 90 ++++--- pc-tools/ldc2/src/argument_reader.hh | 41 +-- pc-tools/ldc2/src/configuration_manager.cpp | 264 ++++++++++++++++++++ pc-tools/ldc2/src/configuration_manager.hh | 80 ++++++ pc-tools/ldc2/src/eot_block.cpp | 2 +- pc-tools/ldc2/src/main.cpp | 128 +++++----- 9 files changed, 544 insertions(+), 166 deletions(-) create mode 100644 pc-tools/ldc2/src/configuration_manager.cpp create mode 100644 pc-tools/ldc2/src/configuration_manager.hh diff --git a/pc-tools/ldc2/doc/appendix.tex b/pc-tools/ldc2/doc/appendix.tex index c043177..aa4a826 100644 --- a/pc-tools/ldc2/doc/appendix.tex +++ b/pc-tools/ldc2/doc/appendix.tex @@ -1,10 +1,9 @@ \section{Appendix} % \clearpage % \addcontentsline{toc}{section}{dddde} -\bibliography{literature} -The mentioned Honeywell documents can be found on -\verb|http://www.series16.adrianwise.co.uk|. -\newpage \listoftables \listoffigures +\bibliography{literature} +The mentioned Honeywell documents can be found on +\verb|http://www.series16.adrianwise.co.uk|. diff --git a/pc-tools/ldc2/doc/main.tex b/pc-tools/ldc2/doc/main.tex index d97e374..77d163b 100644 --- a/pc-tools/ldc2/doc/main.tex +++ b/pc-tools/ldc2/doc/main.tex @@ -8,6 +8,7 @@ \bibliographystyle{unsrt} \sffamily + \pagestyle{empty} \pagenumbering{roman} diff --git a/pc-tools/ldc2/doc/req_spec.tex b/pc-tools/ldc2/doc/req_spec.tex index 7ca7c1b..4559aad 100644 --- a/pc-tools/ldc2/doc/req_spec.tex +++ b/pc-tools/ldc2/doc/req_spec.tex @@ -1,4 +1,4 @@ -\section{Requirements Specification} +\section{Functional Specification} %******************************************************************************* \subsection{Data input processing} @@ -15,8 +15,8 @@ The tape data shall be checked against the Honeywell tape block specification found in \cite{ser16:progref:bformats}. -\rd{chk001}{Block completeness check}{ - Every data block's completeness shall be checked by the means of +\rd{chk001}{Block integrity check}{ + Every data block's integrity shall be checked by the means of detecting unexpected end of file while reading in the block. } @@ -48,6 +48,14 @@ found in \cite{ser16:progref:bformats}. } %******************************************************************************* +\subsection{Additional features} + +\rd{h001}{Print help message}{ + A help message is output to standard error. +} + +%******************************************************************************* +\newpage \subsection{Data analysis} \rd{da001}{List tape contents}{ @@ -85,6 +93,7 @@ found in \cite{ser16:progref:bformats}. } %******************************************************************************* +\newpage \subsection{Data processing} \rd{dp001}{Split into object files}{ @@ -101,18 +110,13 @@ found in \cite{ser16:progref:bformats}. a zero-padded three digit number and EOT blocks are not suppressed. } -%******************************************************************************* -\subsection{Additional features} - -\rd{h001}{Print help message}{ - A help message shall be output to standard error. -} - %******************************************************************************* +\newpage \subsection{Program configuration} \rd{cfg001}{Configuration process}{ - The following sequence shall be used to acquire the working configuration: + The following sequence shall be used to acquire the working + configuration: \begin{enumerate} \item Configuration file according to environment variable:\\ If the environment variable LDC\_CONFIG is set, that @@ -122,8 +126,8 @@ found in \cite{ser16:progref:bformats}. file is found, the specified configuration file is parsed.\\ Any values in this configuration file - override values found in the previously read configuration - file. + override values found in the previously read + configuration file. \item Configuration parameters passed via the command line:\\ Parameters passed on the command line will override values from previously read configuration files. @@ -134,34 +138,46 @@ found in \cite{ser16:progref:bformats}. The program shall accept two types of parameters: \begin{itemize} \item Switches:\\ - A switch is a binary value which can have the value true or false. + A switch is a binary value which can have the value true or + false. \item Strings:\\ A string parameter is a parameter requiring a string value.\\ A typical use would be a file name for input or output. \end{itemize} } +\newpage \rd{cfg003}{Switch parameters}{ The following switch parameters shall be accepted: \begin{table}[H]\begin{center} - \begin{tabular}{|r|p{2.5em}|l|} + \begin{tabular}{|r|p{2.5em}|p{23em}|} \hline \bf Long Form & \bf Short form & \bf Description\\ \hline help & h & Show help message (\req{h001})\\ - output\_info & a & Output data info according to \req{da005}.\\ - output\_called & c & Output a list of called symbols (\req{dp003}).\\ - output\_exported & e & Output a list of exported symbols (\req{dp002}).\\ - output\_unsatisfied & u & Output a list of unsatisfied dependencies (\req{dp004}).\\ - split\_objects & s & Split into object files (\req{dp006}.\\ - split\_objects\_numbered & S & Split into numbered object files (\req{dp007}).\\ - ignore\_block\_errors & b & Ignore block integrity errors (\req{err001}).\\ - ignore\_checksum\_errors & k & Ignore Checksum errors (\req{err001}).\\ - pause\_on\_checksum\_error & p & Wait for user input on checksum error (\req{err003}).\\ - ignore\_unknown\_block\_errors & n & Ignore errors causes by datablocks of - unknown type (\req{err001}).\\ - ignore\_object\_integrity\_errors & g & Ignore errors caused by objects without - proper end block (\req{err001}.)\\ + output\_info & a & Output data info (\req{da005}) .\\ + output\_called & c & Output a list of called symbols + (\req{da003}).\\ + output\_exported & e & Output a list of exported symbols + (\req{da002}).\\ + output\_unsatisfied & u & Output a list of unsatisfied + dependencies (\req{da004}).\\ + split\_objects & s & Split into object files + (\req{dp001}).\\ + split\_objects\_numbered & S & Split into numbered object files + (\req{dp002}).\\ + ignore\_block\_errors & b & Ignore block integrity errors + (\req{err001},\req{chk001}).\\ + ignore\_checksum\_errors & k & Ignore Checksum errors + (\req{err001}\req{chk002}).\\ + pause\_on\_checksum\_error & p & Wait for user input on checksum error + (\req{chk005}).\\ + ignore\_unknown\_block\_errors & n & Ignore errors causes by + datablocks of unknown type + (\req{err001}\req{chk003}).\\ + ignore\_object\_integrity\_errors & g & Ignore errors caused by objects + without proper end block + (\req{err001}\req{chk004}).\\ \hline \end{tabular}\end{center} \caption{Configuration switches} @@ -175,15 +191,15 @@ found in \cite{ser16:progref:bformats}. \hline \bf Long Form & \bf Short form & \bf Description\\ \hline - in\_file & i & Set input file (\req{inp001}) \\ - out\_file & o & Set output file for text output.(\req{dp008})\\ + in\_file & i & Set input file (\req{inp001}). \\ + out\_file & o & Set output file for text output(\req{dp008}).\\ \hline \end{tabular}\end{center} \caption{Configuration strings} \end{table} } - +\newpage \rd{cfg005}{Configuration file syntax}{ The configuration file must comply two the following grammar, given in EBNF: } @@ -205,9 +221,9 @@ ConfigurationLine = SwitchLine | StringLine | CommentLine ; String = { ? Every character except newline ?} ; TrueStr = "yes" | "1" | "true" ; FalseStr = | "no" | "0" | "false" ; - \end{verbatim}; + \end{verbatim} -\rd{cfg006}{Commandline syntax}{ +\rd{cfg006}{Command Line syntax}{ The command line must comply to the following grammar, given in EBNF: } \begin{verbatim} @@ -223,18 +239,20 @@ ShortSwitch = "-" SwShort ; LongSwitch = "--" SwLong [ "=" BoolValue ] ; ShortParam = "-" StrShort String ; LongParam = "--" StrLong "=" String ; - SwShort = "a" | "c" | "e" | "u" | "s" | "S" + SwShort = "h" | "a" | "c" | "e" | "u" | "s" | "S" | "b" | "k" | "p" | "n" | "g" ; - SwLong = "output_info" | "ouput_called" | "output_exported" + SwLong = "help" + | "output_info" | "ouput_called" | "output_exported" | "output_unsatisfied" | "split_objects" [ _"numbered" ] - | "ignore_block_errors" | "ignore_checksum_errors + | "ignore_block_errors" | "ignore_checksum_errors" | "pause_on_checksum_error" | "ignore_unknown_block_errors" | "ignore_object_integrity" ; - StrShort = "o"; + StrShort = "o" ; StrLong = "out_file" ; \end{verbatim} +\newpage \rd{cfg007}{Configuration implications}{ \begin{itemize} \item pause\_on\_checksum\_errors implies ignore\_checksum\_errors. @@ -256,6 +274,7 @@ ShortSwitch = "-" SwShort ; } %******************************************************************************* +\newpage \subsection{Error handling} @@ -289,7 +308,7 @@ ShortSwitch = "-" SwShort ; Caused by failed check according to \req{chk004}.\\ \esup \item Usage error:\\ - Error caused by errors in the program configuration i.e.wrong + Error caused by errors in the program configuration i.e. wrong parameters or impossible combinations of parameters.\\ \enosup \\ Additionally, the help (\req{h001}) message is output. @@ -340,7 +359,7 @@ ShortSwitch = "-" SwShort ; Checksum error & Block checksum wrong!\\ Unknown block type & Unknown block type!\\ Object integrity & Object integrity check failed!\\ - Usage error & $<$Error message describing the problem$>$\\ + Usage error & $<$Specific message describing the problem$>$\\ \hline \end{tabular} \end{center} diff --git a/pc-tools/ldc2/src/argument_reader.cpp b/pc-tools/ldc2/src/argument_reader.cpp index e927a37..f9241c1 100644 --- a/pc-tools/ldc2/src/argument_reader.cpp +++ b/pc-tools/ldc2/src/argument_reader.cpp @@ -5,11 +5,11 @@ *\brief Constructor. * * This constructor makes a new argument_reader ready to use. - *\arg app_name Name of the application as mentioned in the + *\arg name Name of the application as mentioned in the * "Use: ..." help message. */ -argument_reader::argument_reader(string app_name){ - progname=app_name; +argument_reader::argument_reader(string name){ + app_name=app_name; } @@ -31,8 +31,8 @@ void argument_reader::add_param (string shortname, string longname, string description, int * status, string * target, string placeholder){ - if(status!=NULL) arguments.insert(arguments.end(), - parameter(shortname,longname, description, + if(status!=NULL) opt_v.insert(opt_v.end(), + opt_t(shortname,longname, description, status,target,placeholder) ); } @@ -52,13 +52,13 @@ void argument_reader::add_param (string shortname, string longname, */ void argument_reader::add_argument(string placeholder, string description, int * status, string * target){ if (target!=NULL) if(status!=NULL) - free_arguments.insert(free_arguments.end(),free_parameter(placeholder,description,status,target)); + arg_v.insert(arg_v.end(),arg_t(placeholder,description,status,target)); } /*! - * Read in the args passed to main(). - *\returns empty vector on success or the error messages to be output. + *\Read in the args passed to main(). + *\returns empty vector on success or the error messages to be output. */ vector argument_reader::read_args(int argc, char ** args){ vector result; @@ -71,7 +71,7 @@ vector argument_reader::read_args(int argc, char ** args){ // Look for long argument if ((akt_p->substr(0,2)=="--")&&(free_parms_count==0)){ int found=0; - for (vector::iterator parm_p=arguments.begin();parm_p::iterator parm_p=opt_v.begin();parm_psubstr(2,parm_p->longname.length())==parm_p->longname){ found=1; *(parm_p->status)=1; @@ -96,7 +96,7 @@ vector argument_reader::read_args(int argc, char ** args){ int stop_char_loop=0; for (unsigned int pos=1; poslength()&& !stop_char_loop ;pos++){ int found=0; - for (vector::iterator parm_p=arguments.begin();parm_p::iterator parm_p=opt_v.begin();parm_pshortname[0]==(*akt_p)[pos]){ found=1; (*parm_p->status)=1; @@ -120,21 +120,19 @@ vector argument_reader::read_args(int argc, char ** args){ } // char loop }// switch found else{ // no switch found - if (free_parms_countfree_arguments.size()) result.insert(result.begin(),"Too many arguments!"); + if (free_parms_count>arg_v.size()) result.insert(result.begin(),"Too many arguments!"); if (!result.empty()){ result.insert(result.begin(),"Error!"); result.insert(result.begin(),""); } -// if (!result.empty()){ -// get_help(result); -// } return result; } @@ -143,34 +141,33 @@ vector argument_reader::read_args(int argc, char ** args){ *\arg target Reference to a vector to which lots of helpful * strings are appended. */ -void argument_reader::get_help(vector & result){ - - result.insert(result.end(),""); - string line="Usage: "+progname; - for (vector::iterator parm_p=arguments.begin();parm_p & target){ + target.insert(target.end(),""); + string line="Usage: "+app_name; + for (vector::iterator parm_p=opt_v.begin();parm_pshortname; if (parm_p->target!=0) addstr+=parm_p->placeholder; addstr+="]"; if (line.length()+addstr.length()>79){ - result.insert(result.end(),line); - line=string(7+progname.length(),' '); + target.insert(target.end(),line); + line=string(7+app_name.length(),' '); } line+=addstr; } - for (vector::iterator parm_p=free_arguments.begin();parm_p::iterator parm_p=arg_v.begin();parm_pplaceholder.length()>79){ - result.insert(result.end(),line); - line=string(7+progname.length(),' '); + target.insert(target.end(),line); + line=string(7+app_name.length(),' '); } line+=" ["+parm_p->placeholder+"]"; } - result.insert(result.end(),line); + target.insert(target.end(),line); /*******************************/ vector left,right; - for (vector::iterator parm_p=arguments.begin();parm_p::iterator parm_p=opt_v.begin();parm_pdescription; string st2=" -"+parm_p->shortname; if (parm_p->target)st2+=" "+parm_p->placeholder; @@ -180,7 +177,7 @@ void argument_reader::get_help(vector & result){ right.insert(right.end(),line); } - for (vector::iterator parm_p=free_arguments.begin();parm_p::iterator parm_p=arg_v.begin();parm_pdescription; st2+=" "+parm_p->placeholder; @@ -188,36 +185,35 @@ void argument_reader::get_help(vector & result){ right.insert(right.end(),line); } - if (arguments.size()){ - result.insert(result.end(),""); - result.insert(result.end(),"Options:"); + if (opt_v.size()){ + target.insert(target.end(),""); + target.insert(target.end(),"Options:"); } unsigned int max_width=0; - for (unsigned int c=0; cmax_width) max_width=left[c].length(); - for (unsigned int c=0; c80){ // Too long??? int limit=nl.find_last_of(' ',80); - printf("limit:%i\n",limit); - result.insert(result.end(),nl.substr(0,limit)); + target.insert(target.end(),nl.substr(0,limit)); nl=string(max_width+2,' ')+nl.substr(limit+1); } - result.insert(result.end(),nl); + target.insert(target.end(),nl); } - if (free_arguments.size()){ - result.insert(result.end(),""); - result.insert(result.end(),"Arguments:"); + if (arg_v.size()){ + target.insert(target.end(),""); + target.insert(target.end(),"Arguments:"); } max_width=0; - for (unsigned int c=arguments.size(); cmax_width) max_width=left[c].length(); - for (unsigned int c=arguments.size(); c & result){ while (nl.length()>80){ // Too long??? int limit=nl.find_last_of(' ',80); printf("limit:%i\n",limit); - result.insert(result.end(),nl.substr(0,limit)); + target.insert(target.end(),nl.substr(0,limit)); nl=string(max_width+2,' ')+nl.substr(limit+1); } - result.insert(result.end(),nl); + target.insert(target.end(),nl); } - result.insert(result.end(),""); + target.insert(target.end(),""); } /*! @@ -247,7 +243,7 @@ vector argument_reader::get_help(){ /**************************************************/ -argument_reader::parameter::parameter(string n_shortname, string n_longname,string n_description, int * n_status, +argument_reader::opt_t::opt_t(string n_shortname, string n_longname,string n_description, int * n_status, string * n_target, string n_placeholder){ shortname=n_shortname; longname=n_longname; @@ -258,7 +254,7 @@ argument_reader::parameter::parameter(string n_shortname, string n_longname,stri if (status) *status=0; } -argument_reader::free_parameter::free_parameter( string n_placeholder, string n_description, +argument_reader::arg_t::arg_t( string n_placeholder, string n_description, int * n_status, string * n_target){ description=n_description; status=n_status; diff --git a/pc-tools/ldc2/src/argument_reader.hh b/pc-tools/ldc2/src/argument_reader.hh index 1222176..d88d3dd 100644 --- a/pc-tools/ldc2/src/argument_reader.hh +++ b/pc-tools/ldc2/src/argument_reader.hh @@ -15,23 +15,23 @@ using namespace std; * - Create an instance. * - Add Parameters/switches with add_param(). * - Add Arguments with add_argument(). - * - Call read_args() with your main routine's arguments.\ - * The vector returned by read_args() contains all error \ + * - Call read_args() with your main routine's arguments. + * The vector returned by read_args() contains all error * messages. When it's empty, everything is fine! - * - Call get_help() if you want nice formatted help output. \ + * - Call get_help() if you want nice formatted help output. * (You want!!!) * Sould be easy to use..... Enjoy. */ class argument_reader{ public: - argument_reader(string n_name); + argument_reader(string name); - void add_param (string shortname, - string longname, - string description, - int * status, - string * target=NULL, + void add_param (string shortname, + string longname, + string description, + int *status, + string *target=NULL, string placeholder=string("") ); @@ -43,9 +43,12 @@ public: void add_argument(string placeholder, string description, int * status, string * target); private: - class parameter{ + /*! + *\brief Container for one command line option. + */ + class opt_t{ public: - parameter (string shortname, string longname,string description, int * status, + opt_t (string shortname, string longname,string description, int * status, string * target=NULL, string placeholder=string("")); string shortname; string longname; @@ -55,21 +58,23 @@ private: string placeholder; }; - class free_parameter{ + /*! + *\brief Container for one command line argument. + */ + class arg_t{ public: - free_parameter (string placeholder,string description, + arg_t (string placeholder,string description, int * status, string * target); int * status; string * target; string description; string placeholder; }; + vectoropt_v; + vectorarg_v; + string app_name; - vectorarguments; - vectorfree_arguments; - - string progname; -}; +}; // class argument_reader #endif diff --git a/pc-tools/ldc2/src/configuration_manager.cpp b/pc-tools/ldc2/src/configuration_manager.cpp new file mode 100644 index 0000000..f9241c1 --- /dev/null +++ b/pc-tools/ldc2/src/configuration_manager.cpp @@ -0,0 +1,264 @@ +#include "argument_reader.hh" +#include + +/*! + *\brief Constructor. + * + * This constructor makes a new argument_reader ready to use. + *\arg name Name of the application as mentioned in the + * "Use: ..." help message. + */ +argument_reader::argument_reader(string name){ + app_name=app_name; +} + + +/*! + *\brief Add a new parameter to be searched for. + *\param shortname A character for the short form. + * For example the 'h' in -h + *\param longname The double dash longname. For example + * "input_file=" in --input_file= or + * "ignore_errors" in --ignore--errors + *\param description A detailed parameter description. + *\param status Pointer to an integer. Will be set to 1 if arg found. + *\target Pointer to a value should be read. + * If no value is needed, pass NULL. + *\placeholder A placeholder for the documentation. + * For example "" in -f + */ +void argument_reader::add_param (string shortname, string longname, + string description, int * status, + string * target, string placeholder){ + + if(status!=NULL) opt_v.insert(opt_v.end(), + opt_t(shortname,longname, description, + status,target,placeholder) + ); +} + + +/*! + *\brief Add an accepted argument to the argument reader. + *\param placeholder Something like "". + *\param description Text describing the argument. + *\param status A pointer to a status variable. Will be set to 0 immediately. + * If the argument is filled in, it will be set to 1. + *\param target A pointer to a c++ string where the argument goes to. + * + *\note Arguments are filled in the order of adding them to the + * argument reader. + * There would be no other way to determine the order. + */ +void argument_reader::add_argument(string placeholder, string description, int * status, string * target){ + if (target!=NULL) if(status!=NULL) + arg_v.insert(arg_v.end(),arg_t(placeholder,description,status,target)); +} + + +/*! + *\Read in the args passed to main(). + *\returns empty vector on success or the error messages to be output. + */ +vector argument_reader::read_args(int argc, char ** args){ + vector result; + vector argv; + for (char ** akt=args; *akt ;akt++) argv.insert(argv.end(),string(*akt)); + + unsigned int free_parms_count=0; + for (vector::iterator akt_p=argv.begin()+1;akt_psubstr(0,2)=="--")&&(free_parms_count==0)){ + int found=0; + for (vector::iterator parm_p=opt_v.begin();parm_psubstr(2,parm_p->longname.length())==parm_p->longname){ + found=1; + *(parm_p->status)=1; + if (parm_p->target){ + if (akt_p->length()>2+parm_p->longname.length()){ + *(parm_p->target)=akt_p->substr(2+parm_p->longname.length()); + + } else // Word not long enough + if (akt_p+1status)=1; + *(parm_p->target)=*(++akt_p); + } else { // No next word :-( + result.insert(result.end(), + "Parameter --"+parm_p->longname+parm_p->placeholder+" needs an Argument!"); + } + } // arg needed + } + } // search for loop + if (!found) result.insert(result.end(),"Unknown parameter: "+*akt_p); + } else { // No -- param, now look for switches + if (((*akt_p)[0]=='-')&&(free_parms_count==0)){ + int stop_char_loop=0; + for (unsigned int pos=1; poslength()&& !stop_char_loop ;pos++){ + int found=0; + for (vector::iterator parm_p=opt_v.begin();parm_pshortname[0]==(*akt_p)[pos]){ + found=1; + (*parm_p->status)=1; + if (parm_p->target){ // Need argument + if (akt_p->length()>pos+1){ + *(parm_p->target)=akt_p->substr(pos+1); + stop_char_loop=1; + } else { // Word not long enough + if (akt_p+1target)=*(++akt_p); + stop_char_loop=1; + } else { // No next word :-( + result.insert(result.end(), + "Parameter --"+parm_p->longname+parm_p->placeholder+" needs an Argument!"); + } + } + } // arg needed + } //if match + } //args loop + if (!found) result.insert(result.end(),"Unknown switch: "+akt_p->substr(pos,1)); + } // char loop + }// switch found + else{ // no switch found + if (free_parms_countarg_v.size()) result.insert(result.begin(),"Too many arguments!"); + if (!result.empty()){ + result.insert(result.begin(),"Error!"); + result.insert(result.begin(),""); + } + return result; +} + +/*! + *\brief Generate help. + *\arg target Reference to a vector to which lots of helpful + * strings are appended. + */ +void argument_reader::get_help(vector & target){ + target.insert(target.end(),""); + string line="Usage: "+app_name; + for (vector::iterator parm_p=opt_v.begin();parm_pshortname; + if (parm_p->target!=0) addstr+=parm_p->placeholder; + addstr+="]"; + if (line.length()+addstr.length()>79){ + target.insert(target.end(),line); + line=string(7+app_name.length(),' '); + } + line+=addstr; + } + + for (vector::iterator parm_p=arg_v.begin();parm_pplaceholder.length()>79){ + target.insert(target.end(),line); + line=string(7+app_name.length(),' '); + } + line+=" ["+parm_p->placeholder+"]"; + } + target.insert(target.end(),line); + + /*******************************/ + + vector left,right; + for (vector::iterator parm_p=opt_v.begin();parm_pdescription; + string st2=" -"+parm_p->shortname; + if (parm_p->target)st2+=" "+parm_p->placeholder; + st2+=", --"+parm_p->longname; + if (parm_p->target)st2+=parm_p->placeholder; + left.insert(left.end(),st2); + right.insert(right.end(),line); + } + + for (vector::iterator parm_p=arg_v.begin();parm_pdescription; + st2+=" "+parm_p->placeholder; + left.insert(left.end(),st2); + right.insert(right.end(),line); + } + + if (opt_v.size()){ + target.insert(target.end(),""); + target.insert(target.end(),"Options:"); + } + + unsigned int max_width=0; + for (unsigned int c=0; cmax_width) max_width=left[c].length(); + for (unsigned int c=0; c80){ // Too long??? + int limit=nl.find_last_of(' ',80); + target.insert(target.end(),nl.substr(0,limit)); + nl=string(max_width+2,' ')+nl.substr(limit+1); + } + target.insert(target.end(),nl); + } + + if (arg_v.size()){ + target.insert(target.end(),""); + target.insert(target.end(),"Arguments:"); + } + + max_width=0; + for (unsigned int c=opt_v.size(); cmax_width) max_width=left[c].length(); + for (unsigned int c=opt_v.size(); c80){ // Too long??? + int limit=nl.find_last_of(' ',80); + printf("limit:%i\n",limit); + target.insert(target.end(),nl.substr(0,limit)); + nl=string(max_width+2,' ')+nl.substr(limit+1); + } + + target.insert(target.end(),nl); + } + target.insert(target.end(),""); +} + +/*! + *\brief Generate help. + *\return A vector containing many helpful strings for the user. + */ +vector argument_reader::get_help(){ + vector result; + get_help(result); + return result; +} + + +/**************************************************/ + +argument_reader::opt_t::opt_t(string n_shortname, string n_longname,string n_description, int * n_status, + string * n_target, string n_placeholder){ + shortname=n_shortname; + longname=n_longname; + description=n_description; + status=n_status; + target=n_target; + placeholder=n_placeholder; + if (status) *status=0; +} + +argument_reader::arg_t::arg_t( string n_placeholder, string n_description, + int * n_status, string * n_target){ + description=n_description; + status=n_status; + target=n_target; + placeholder=n_placeholder; + if (status) *status=0; +} diff --git a/pc-tools/ldc2/src/configuration_manager.hh b/pc-tools/ldc2/src/configuration_manager.hh new file mode 100644 index 0000000..d88d3dd --- /dev/null +++ b/pc-tools/ldc2/src/configuration_manager.hh @@ -0,0 +1,80 @@ +#ifndef ARGUMENT_READER_H +#define ARGUMENT_READER_H + +#include +#include + +using namespace std; + +/*! + *\brief Hachti's wonderful commandline parser. + * + * This class is designed to do all the work with the parameters passed to + * the main() routine of a program.\n + * Usage:\n + * - Create an instance. + * - Add Parameters/switches with add_param(). + * - Add Arguments with add_argument(). + * - Call read_args() with your main routine's arguments. + * The vector returned by read_args() contains all error + * messages. When it's empty, everything is fine! + * - Call get_help() if you want nice formatted help output. + * (You want!!!) + * Sould be easy to use..... Enjoy. + */ +class argument_reader{ + +public: + argument_reader(string name); + + void add_param (string shortname, + string longname, + string description, + int *status, + string *target=NULL, + string placeholder=string("") + ); + + vector read_args(int argc, char ** args); + + void get_help(vector & target); + vector get_help(); + + void add_argument(string placeholder, string description, int * status, string * target); + +private: + /*! + *\brief Container for one command line option. + */ + class opt_t{ + public: + opt_t (string shortname, string longname,string description, int * status, + string * target=NULL, string placeholder=string("")); + string shortname; + string longname; + int * status; + string * target; + string description; + string placeholder; + }; + + /*! + *\brief Container for one command line argument. + */ + class arg_t{ + public: + arg_t (string placeholder,string description, + int * status, string * target); + int * status; + string * target; + string description; + string placeholder; + }; + vectoropt_v; + vectorarg_v; + string app_name; + +}; // class argument_reader + + +#endif diff --git a/pc-tools/ldc2/src/eot_block.cpp b/pc-tools/ldc2/src/eot_block.cpp index 756515e..4377225 100644 --- a/pc-tools/ldc2/src/eot_block.cpp +++ b/pc-tools/ldc2/src/eot_block.cpp @@ -21,7 +21,7 @@ eot_block::eot_block(eot_block & org){ */ vector eot_block:: get_description(){ vector result; - string r_string=" (EOT) End of Tape mark"; + string r_string="***********(EOT)*****End of Tape mark **********************"; result.insert(result.end(),r_string); return result; } diff --git a/pc-tools/ldc2/src/main.cpp b/pc-tools/ldc2/src/main.cpp index 0c9cea8..3e1244b 100644 --- a/pc-tools/ldc2/src/main.cpp +++ b/pc-tools/ldc2/src/main.cpp @@ -5,79 +5,93 @@ #include #include +#include +#include +#include #include "tape_block.hh" -#include "data_block.hh" - #include "argument_reader.hh" using namespace std; -void tape_start(void* m){ - printf("tape_start\n"); -} - -void tape_stop(void* m){ - printf("tape_stop\n"); -} - -void dump_vector(vector arguments){ +int dump_vector(vector arguments){ + int res=0; for (vector::iterator iter=arguments.begin();iter"); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name Gelaber Gelaber Gelaber Gelaber M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_param("n","name=","Enter other name",&name_set,&name,""); - ar.add_argument("","File to read data from",&file_set,&filename); - - dump_vector(ar.read_args(argc,args)); - - if (help_needed){ + ar.add_param("h","help","Output this help text.",&help_wanted); + ar.add_param("g","greet","Wonderful bla bla. It is here only to test the output\ +capabilities of the arg_reader.",&greet_want); + + ar.add_argument("","File from where data is read",&infile_set,&infile); + ar.add_argument("","File to where output is redirected",&outfile_set,&outfile); + + + if((dump_vector(ar.read_args(argc,args))||help_wanted)){ dump_vector(ar.get_help()); exit(1); } + if(greet_want)printf("Hallo!\n"); + + if (infile_set==1){ + printf("Opening file for input:%s\n",infile.c_str()); + in_fd=open(infile.c_str(),O_RDONLY); + if (in_fd<0){ + printf("Error: could not open file:%s\n",infile.c_str()); + exit (3); + } + } + + vector tape; + + + tape_block * block=0; + while(1){ + block=tape_block::gen_from_fd(in_fd); + if (block->get_state()==tape_block::TBS_OK){ + tape.insert(tape.end(),block); + dump_vector(block->get_description()); + } + else break; + } - printf("\n\n\nHallo %s!\n",name.c_str()); - exit(0); - tape_block * myblock=0; - do{ - if (myblock) delete myblock; - myblock=tape_block::gen_from_fd(0); - - vector desc=myblock->get_description(); - for (vector::iterator iter=desc.begin(); - iter!=desc.end();iter++) - printf("%s\n",(*iter).c_str()); - } while (myblock->get_state()==tape_block::TBS_OK); - return 0; -} + switch(block->get_state()){ + case tape_block::TBS_EOF_LEGAL: printf("File successfully read.\n"); + break; + case tape_block::TBS_EOF_ILLEGAL: printf("EOF while in block!\n"); + break; + case tape_block::TBS_CHECKSUM: + printf("Checksum error!\n"); + break; + case tape_block::TBS_DEFAULT: + printf("TBS_DEFAULT encountered ->> SEVERY INTERNAL ERROR!\n"); + exit(88); + case tape_block::TBS_IOERR: + printf("I/O Error... Why?\n"); + exit (43); + } + + return 0; +} // main() -- 2.32.0