*** empty log message ***
authorhachti <hachti>
Mon, 20 Nov 2006 05:27:32 +0000 (05:27 +0000)
committerhachti <hachti>
Mon, 20 Nov 2006 05:27:32 +0000 (05:27 +0000)
19 files changed:
pc-tools/ldc2/src/argread.cpp [new file with mode: 0644]
pc-tools/ldc2/src/argread.hh [new file with mode: 0644]
pc-tools/ldc2/src/data_block_0_64.cpp [new file with mode: 0644]
pc-tools/ldc2/src/data_block_0_64.hh [new file with mode: 0644]
pc-tools/ldc2/src/data_block_1.cpp [new file with mode: 0644]
pc-tools/ldc2/src/data_block_1.hh [new file with mode: 0644]
pc-tools/ldc2/src/data_block_2.cpp [new file with mode: 0644]
pc-tools/ldc2/src/data_block_2.hh [new file with mode: 0644]
pc-tools/ldc2/src/data_block_3.cpp [new file with mode: 0644]
pc-tools/ldc2/src/data_block_3.hh [new file with mode: 0644]
pc-tools/ldc2/src/data_block_4.cpp [new file with mode: 0644]
pc-tools/ldc2/src/data_block_4.hh [new file with mode: 0644]
pc-tools/ldc2/src/data_block_5.cpp [new file with mode: 0644]
pc-tools/ldc2/src/data_block_5.hh [new file with mode: 0644]
pc-tools/ldc2/src/data_block_6.cpp [new file with mode: 0644]
pc-tools/ldc2/src/data_block_6.hh [new file with mode: 0644]
pc-tools/ldc2/src/data_block_7.cpp [new file with mode: 0644]
pc-tools/ldc2/src/data_block_7.hh [new file with mode: 0644]
pc-tools/ldc2/src/main.cpp

diff --git a/pc-tools/ldc2/src/argread.cpp b/pc-tools/ldc2/src/argread.cpp
new file mode 100644 (file)
index 0000000..116dbb8
--- /dev/null
@@ -0,0 +1,136 @@
+#include "argread.hh"
+#include <stdio.h>
+
+argreader::argreader(string  n_name){
+  progname=n_name;
+}
+
+void argreader::add_param (string shortname, string longname,
+                        string description, int * status, 
+                        string * target, string placeholder){
+  if (target!=NULL) if(status!=NULL)
+  arguments.insert(arguments.end(),parameter(shortname,longname,description,status,target,placeholder));
+}
+
+void argreader::add_free_param(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));
+}
+
+vector<string> argreader::read_args(int argc, char ** args){
+  vector<string> result;
+  vector<string> argv;
+  for (char ** akt=args; *akt ;akt++) argv.insert(argv.end(),string(*akt));
+
+  unsigned int free_parms_count=0;
+  for (vector<string>::iterator akt_p=argv.begin()+1;akt_p<argv.end();akt_p++){ //Argument loop
+
+    // Look for long argument
+    if ((akt_p->substr(0,2)=="--")&&(free_parms_count==0)){
+      int found=0;
+      for (vector<parameter>::iterator parm_p=arguments.begin();parm_p<arguments.end();parm_p++){
+       if (akt_p->substr(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+1<argv.end()) { // If next word existend
+               *(parm_p->status)=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; pos<akt_p->length()&& !stop_char_loop ;pos++){
+         int found=0;
+         for (vector<parameter>::iterator parm_p=arguments.begin();parm_p<arguments.end();parm_p++){
+           if (parm_p->shortname[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
+                 printf("s word next\n");
+                 if (akt_p+1<argv.end()) { // If next word existend
+                   *(parm_p->target)=*(++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_count<free_arguments.size()){
+         *(free_arguments[free_parms_count].target)=*akt_p;
+       } 
+       free_parms_count++;
+      }
+    } //looking for not -- args
+  } // argv loop
+  if (free_parms_count>free_arguments.size()) result.insert(result.begin(),"Too many arguments!");
+  if (!result.empty()) get_help(result);
+  return result;
+}
+
+
+void argreader::get_help(vector<string> & result){
+  result.insert(result.end(),"Usage:");
+  string line="      "+progname+" ";
+  for (vector<parameter>::iterator parm_p=arguments.begin();parm_p<arguments.end();parm_p++){
+    line+="[-"+parm_p->shortname;
+    if (parm_p->target!=0) line+=parm_p->placeholder;
+    line+="] ";
+  }
+  result.insert(result.end(),line);
+}
+
+vector<string> argreader::get_help(){
+  vector<string> result;
+  get_help(result);
+  return result;
+}
+
+
+/**************************************************/
+
+argreader::parameter::parameter(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;
+}
+
+argreader::free_parameter::free_parameter( 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/argread.hh b/pc-tools/ldc2/src/argread.hh
new file mode 100644 (file)
index 0000000..7cd3aff
--- /dev/null
@@ -0,0 +1,76 @@
+#ifndef ARGREAD_H
+#define ARGREAD_H
+
+#include <vector>
+#include <string>
+
+using namespace std;
+
+#ifndef NULL
+#define NULL (void*)0
+#endif
+
+class argreader{
+public:
+  argreader(string  n_name);
+
+  /*!
+   *\brief add a parameter to be looked 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 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 "<filename>" in -f<filename>
+   */
+  void add_param (string shortname, string longname, string description, int * status, 
+                 string * target=NULL, string  placeholder=string("<string>"));
+  
+  /*!
+   * Read in the args passed to main().
+   *\returns empty vector  on success or the error messages to be output.
+   */
+  vector<string> read_args(int argc, char ** args);
+    
+  
+  vector<string> & get_free_args();
+
+  void get_help(vector<string> & );
+  vector<string>  get_help();
+  
+  void add_free_param(string placeholder, string description, int * status, string * target);
+
+  
+  
+private:
+  class parameter{
+  public:
+    parameter (string shortname, string longname,string description, int * status, 
+              string * target=NULL, string placeholder=string("<string>"));
+    string shortname;
+    string longname;
+    int * status;
+    string * target;    
+    string description;
+    string placeholder;
+  };
+
+  class free_parameter{
+  public:
+    free_parameter (string placeholder,string description,
+                   int * status, string * target);
+    int * status;
+    string * target;    
+    string description;
+    string placeholder;
+  };
+
+  vector<parameter>arguments;
+  vector<free_parameter>free_arguments;
+
+  string progname;
+};
+
+
+#endif
diff --git a/pc-tools/ldc2/src/data_block_0_64.cpp b/pc-tools/ldc2/src/data_block_0_64.cpp
new file mode 100644 (file)
index 0000000..629b034
--- /dev/null
@@ -0,0 +1,21 @@
+#include "data_block_0_64.hh"
+
+#include <stdio.h>
+
+/*!
+ *\brief Parent class copy constructor.
+ */
+data_block_0_64::data_block_0_64(data_block_0 & org)
+  :data_block_0(org)
+{}
+
+/*!
+ *\brief Describe the block.
+ *\return A vector of text lines describing this block.
+ */
+vector<string> data_block_0_64::get_description(){
+  vector<string> result;
+  result.insert(result.end(),"           "+get_typestring()+"Set Base Sector");
+  return result;
+}
+
diff --git a/pc-tools/ldc2/src/data_block_0_64.hh b/pc-tools/ldc2/src/data_block_0_64.hh
new file mode 100644 (file)
index 0000000..41b9f8f
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DATA_BLOCK_0_64_H
+#define DATA_BLOCK_0_64_H
+
+#include <vector>
+#include <string>
+
+#include "data_block_0.hh"
+
+/*!
+ *\brief Class for block type (0-0).
+ */
+class data_block_0_64
+  : public data_block_0
+{
+  friend tape_block * tape_block::gen_from_fd(int,void(*)(void*),
+                                             void(*)(void*),void*);
+public:
+  vector<string> get_description();
+
+protected:
+  data_block_0_64(data_block_0&);
+  
+
+};
+
+#endif
diff --git a/pc-tools/ldc2/src/data_block_1.cpp b/pc-tools/ldc2/src/data_block_1.cpp
new file mode 100644 (file)
index 0000000..b6b0efa
--- /dev/null
@@ -0,0 +1,22 @@
+#include "data_block_1.hh"
+
+/*!
+ *\brief Specialisation constructor.
+ */
+data_block_1::data_block_1(data_block & org)
+  :data_block(org)
+{}
+
+/*!
+ *\brief Describe the block.
+ *\return A vector of text lines describing this block.
+ */
+vector<string> data_block_1::get_description(){
+  vector<string> result;
+  result.insert(result.end(),"           "+get_typestring()+"Absolute program words");
+  return result;
+}
+
+
+
+
diff --git a/pc-tools/ldc2/src/data_block_1.hh b/pc-tools/ldc2/src/data_block_1.hh
new file mode 100644 (file)
index 0000000..b1b1c9b
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DATA_BLOCK_1_H
+#define DATA_BLOCK_1_H
+
+#include <vector>
+#include <string>
+
+#include "data_block.hh"
+
+/*!
+ *\brief Class for block type (1).
+ */
+class data_block_1
+  : public data_block
+{
+  friend tape_block * tape_block::gen_from_fd(int,void(*)(void*),
+                                             void(*)(void*),void*);
+protected:
+  data_block_1(data_block&);
+
+public:  
+  vector<string> get_description();
+};
+
+#endif
+
+
diff --git a/pc-tools/ldc2/src/data_block_2.cpp b/pc-tools/ldc2/src/data_block_2.cpp
new file mode 100644 (file)
index 0000000..8fad9ee
--- /dev/null
@@ -0,0 +1,21 @@
+#include "data_block_2.hh"
+
+/*!
+ *\brief Specialisation constructor.
+ */
+data_block_2::data_block_2(data_block & org)
+  :data_block(org){}
+
+/*!
+ *\brief Describe the block.
+ *\return A vector of text lines describing this block.
+ */
+vector<string> data_block_2::get_description(){
+  vector<string> result;
+  result.insert(result.end(),"           "+get_typestring()+"Relative program words");
+  return result;
+}
+
+
+
+
diff --git a/pc-tools/ldc2/src/data_block_2.hh b/pc-tools/ldc2/src/data_block_2.hh
new file mode 100644 (file)
index 0000000..2c8b919
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DATA_BLOCK_2_H
+#define DATA_BLOCK_2_H
+
+#include <vector>
+#include <string>
+
+#include "data_block.hh"
+
+/*!
+ *\brief Class for block type (2).
+ */
+class data_block_2
+  : public data_block
+{
+  friend tape_block * tape_block::gen_from_fd(int,void(*)(void*),
+                                             void(*)(void*),void*);
+protected:
+  data_block_2(data_block&);
+
+public:  
+  vector<string> get_description();
+};
+
+#endif
+
+
diff --git a/pc-tools/ldc2/src/data_block_3.cpp b/pc-tools/ldc2/src/data_block_3.cpp
new file mode 100644 (file)
index 0000000..3ae67a9
--- /dev/null
@@ -0,0 +1,22 @@
+#include "data_block_3.hh"
+
+/*!
+ *\brief Specialisation constructor.
+ */
+data_block_3::data_block_3(data_block & org)
+  :data_block(org)
+{}
+
+/*!
+ *\brief Describe the block.
+ *\return A vector of text lines describing this block.
+ */
+vector<string> data_block_3::get_description(){
+  vector<string> result;
+  result.insert(result.end(),"           "+get_typestring()+"End Jump, absolute address");
+  return result;
+}
+
+
+
+
diff --git a/pc-tools/ldc2/src/data_block_3.hh b/pc-tools/ldc2/src/data_block_3.hh
new file mode 100644 (file)
index 0000000..7a5b902
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DATA_BLOCK_3_H
+#define DATA_BLOCK_3_H
+
+#include <vector>
+#include <string>
+
+#include "data_block.hh"
+
+/*!
+ *\brief Class for block type (3).
+ */
+class data_block_3
+  : public data_block
+{
+  friend tape_block * tape_block::gen_from_fd(int,void(*)(void*),
+                                             void(*)(void*),void*);
+protected:
+  data_block_3(data_block&);
+
+public:  
+  vector<string> get_description();
+};
+
+#endif
+
+
diff --git a/pc-tools/ldc2/src/data_block_4.cpp b/pc-tools/ldc2/src/data_block_4.cpp
new file mode 100644 (file)
index 0000000..b325ed7
--- /dev/null
@@ -0,0 +1,22 @@
+#include "data_block_4.hh"
+
+/*!
+ *\brief Specialisation constructor.
+ */
+data_block_4::data_block_4(data_block & org)
+  :data_block(org)
+{}
+
+/*!
+ *\brief Describe the block.
+ *\return A vector of text lines describing this block.
+ */
+vector<string> data_block_4::get_description(){
+  vector<string> result;
+  result.insert(result.end(),"           "+get_typestring()+"End Jump, relative address");
+  return result;
+}
+
+
+
+
diff --git a/pc-tools/ldc2/src/data_block_4.hh b/pc-tools/ldc2/src/data_block_4.hh
new file mode 100644 (file)
index 0000000..702f33d
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DATA_BLOCK_4_H
+#define DATA_BLOCK_4_H
+
+#include <vector>
+#include <string>
+
+#include "data_block.hh"
+
+/*!
+ *\brief Class for block type (4).
+ */
+class data_block_4
+  : public data_block
+{
+  friend tape_block * tape_block::gen_from_fd(int,void(*)(void*),
+                                             void(*)(void*),void*);
+protected:
+  data_block_4(data_block&);
+
+public:  
+  vector<string> get_description();
+};
+
+#endif
+
+
diff --git a/pc-tools/ldc2/src/data_block_5.cpp b/pc-tools/ldc2/src/data_block_5.cpp
new file mode 100644 (file)
index 0000000..408759a
--- /dev/null
@@ -0,0 +1,22 @@
+#include "data_block_5.hh"
+
+/*!
+ *\brief Specialisation constructor.
+ */
+data_block_5::data_block_5(data_block & org)
+  :data_block(org)
+{}
+
+/*!
+ *\brief Describe the block.
+ *\return A vector of text lines describing this block.
+ */
+vector<string> data_block_5::get_description(){
+  vector<string> result;
+  result.insert(result.end(),extract_label(3)+"     "+get_typestring()+"Subroutine call");
+  return result;
+}
+
+
+
+
diff --git a/pc-tools/ldc2/src/data_block_5.hh b/pc-tools/ldc2/src/data_block_5.hh
new file mode 100644 (file)
index 0000000..83faa06
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DATA_BLOCK_5_H
+#define DATA_BLOCK_5_H
+
+#include <vector>
+#include <string>
+
+#include "data_block.hh"
+
+/*!
+ *\brief Class for block type (5).
+ */
+class data_block_5
+  : public data_block
+{
+  friend tape_block * tape_block::gen_from_fd(int,void(*)(void*),
+                                             void(*)(void*),void*);
+protected:
+  data_block_5(data_block&);
+
+public:  
+  vector<string> get_description();
+};
+
+#endif
+
+
diff --git a/pc-tools/ldc2/src/data_block_6.cpp b/pc-tools/ldc2/src/data_block_6.cpp
new file mode 100644 (file)
index 0000000..f4124af
--- /dev/null
@@ -0,0 +1,22 @@
+#include "data_block_6.hh"
+
+/*!
+ *\brief Specialisation constructor.
+ */
+data_block_6::data_block_6(data_block & org)
+  :data_block(org)
+{}
+
+/*!
+ *\brief Describe the block.
+ *\return A vector of text lines describing this block.
+ */
+vector<string> data_block_6::get_description(){
+  vector<string> result;
+  result.insert(result.end(),extract_label(3)+"     "+get_typestring()+"Subroutine or Common Block Definition");
+  return result;
+}
+
+
+
+
diff --git a/pc-tools/ldc2/src/data_block_6.hh b/pc-tools/ldc2/src/data_block_6.hh
new file mode 100644 (file)
index 0000000..4d5afbe
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DATA_BLOCK_6_H
+#define DATA_BLOCK_6_H
+
+#include <vector>
+#include <string>
+
+#include "data_block.hh"
+
+/*!
+ *\brief Class for block type (6).
+ */
+class data_block_6
+  : public data_block
+{
+  friend tape_block * tape_block::gen_from_fd(int,void(*)(void*),
+                                             void(*)(void*),void*);
+protected:
+  data_block_6(data_block&);
+
+public:  
+  vector<string> get_description();
+};
+
+#endif
+
+
diff --git a/pc-tools/ldc2/src/data_block_7.cpp b/pc-tools/ldc2/src/data_block_7.cpp
new file mode 100644 (file)
index 0000000..9481bee
--- /dev/null
@@ -0,0 +1,22 @@
+#include "data_block_7.hh"
+
+/*!
+ *\brief Specialisation constructor.
+ */
+data_block_7::data_block_7(data_block & org)
+  :data_block(org)
+{}
+
+/*!
+ *\brief Describe the block.
+ *\return A vector of text lines describing this block.
+ */
+vector<string> data_block_7::get_description(){
+  vector<string> result;
+  result.insert(result.end(),extract_label(3)+"     "+get_typestring()+"Reference to Item In Common");
+  return result;
+}
+
+
+
+
diff --git a/pc-tools/ldc2/src/data_block_7.hh b/pc-tools/ldc2/src/data_block_7.hh
new file mode 100644 (file)
index 0000000..59446f8
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DATA_BLOCK_7_H
+#define DATA_BLOCK_7_H
+
+#include <vector>
+#include <string>
+
+#include "data_block.hh"
+
+/*!
+ *\brief Class for block type (7).
+ */
+class data_block_7
+  : public data_block
+{
+  friend tape_block * tape_block::gen_from_fd(int,void(*)(void*),
+                                             void(*)(void*),void*);
+protected:
+  data_block_7(data_block&);
+
+public:  
+  vector<string> get_description();
+};
+
+#endif
+
+
index e8f60928c49f014875596080354676f270bdc243..f8274103d6d8db868da086181623cc8d94043dd3 100644 (file)
@@ -1,16 +1,18 @@
-/*
-$Id: main.cpp,v 1.3 2006/11/20 01:19:48 hachti Exp $
-$Log: main.cpp,v $
-Revision 1.3  2006/11/20 01:19:48  hachti
-Another revision
+/* ldc2 preliminary main program */
+
+#include <vector>
+#include <string>
 
-*/
 #include <stdio.h>
 #include <unistd.h>
 
 #include "tape_block.hh"
 #include "data_block.hh"
 
+#include "argread.hh"
+
+using namespace std;
+
 void tape_start(void* m){
   printf("tape_start\n");
 }
@@ -19,7 +21,35 @@ void tape_stop(void* m){
   printf("tape_stop\n");
 }
 
-int main(){
+
+
+
+void dump_vector(vector<string> arguments){
+  for (vector<string>::iterator iter=arguments.begin();iter<arguments.end();iter++){
+    printf("%s\n",(*iter).c_str());
+  }
+}
+
+int main(int argc, char ** args){
+  int help_needed;
+  int name_set;
+  int file_set;
+  string name="Philipp";
+  string filename;
+
+  argreader ar("ldc2");
+  ar.add_param("n","name=","Enter other name",&name_set,&name,"<name>");
+  ar.add_param("h","help","Give help",&help_needed);
+  ar.add_free_param("<file>","File to read data from",&file_set,&filename);
+
+   
+                  
+  dump_vector(ar.read_args(argc,args));
+
+ if (help_needed==1) dump_vector(ar.get_help());
+
+  printf("Hallo %s!\n",name.c_str());
+  exit(0);
   tape_block * myblock=0;
   do{
     if (myblock) delete myblock;
@@ -32,3 +62,4 @@ int main(){
   } while (myblock->get_state()==tape_block::TBS_OK);
     return 0;
 }
+