*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / main.cpp
index 36cb22ed22c06fb9b1463f4e176cfb3073154f29..3e1244b19e98690c7456d1682e49238ebf4321bb 100644 (file)
@@ -1,39 +1,97 @@
+/* ldc2 preliminary main program */
+
+#include <vector>
+#include <string>
 
 #include <stdio.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include "tape_block.hh"
-#include "data_block.hh"
+#include "argument_reader.hh"
 
-void tape_start(void* m){
-  printf("tape_start\n");
-}
+using namespace std;
 
-void tape_stop(void* m){
-  printf("tape_stop\n");
+int dump_vector(vector<string> arguments){
+  int res=0;
+  for (vector<string>::iterator iter=arguments.begin();iter<arguments.end();iter++){
+    printf("%s\n",(*iter).c_str());
+    res=1;
+  }
+  return res;
 }
 
-int main(){
-  tape_block * myblock=0;
-  do{
-    if (myblock) delete myblock;
-    myblock=tape_block::gen_from_fd(0);
-
-    vector<string> desc=myblock->get_description();
-    for (vector<string>::iterator iter=desc.begin();
-        iter!=desc.end();iter++)
-      printf("%s\n",(*iter).c_str());
-
-
-//     if ((myblock->get_type()==0)&&(myblock->get_subtype()==050)){
-//       data_block * dp=(data_block *)myblock;
-//       printf ("0-50 symbol name: %s\n",dp->extract_string(4).c_str());
-//       printf ("0-50 symbol name: %s\n",dp->extract_string(11).c_str());
-//       printf ("Block size:%i\n",dp->get_word_size());
-//     }
-  } while (myblock->get_state()==tape_block::TBS_OK);
-  printf("---");
-  printf("State:%i\n",myblock->get_state());
-  printf("raw size:%i\n",myblock->get_raw_size());
-    return 0;
-}
+
+
+int main(int argc, char ** args){
+  
+  string infile, outfile;
+  int infile_set, outfile_set;
+  int help_wanted;
+  
+  int greet_want;
+  string greetings;
+  
+  int in_fd, out_fd;
+
+  in_fd=0;  //stdin   {O _ \ 
+  out_fd=1; //stdout  {O ^ /
+
+  argument_reader ar("ldc2");
+  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("<input-file>","File from where data is read",&infile_set,&infile);
+  ar.add_argument("<output-file>","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_block*> 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;
+  }
+
+  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()
+