Martin Schulte <dtaus@ratinganwendung.de>: Corrected handling for
[infodrom/dtaus] / main.c
diff --git a/main.c b/main.c
index b3ab351..7f4a9d1 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,6 +1,6 @@
 /*
-    main.c - Datentraegeraustausch mit einer Bank
-    Copyright (c) 1996  Martin Schulze <joey@orgatech.de>
+    main.c - Belegloser Datenträgeraustausch mit einer Bank
+    Copyright (c) 1996,8,2001-4  Martin Schulze <joey@infodrom.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
 
     $Id$
  */
 
-main()
+static char version[] = "0.6";
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include "dtaus.h"
+
+char *dtaus   = "dtaus0.txt";
+char *control = "dtaus0.ctl";
+char *beleg   = "dtaus0.doc";
+char *check   = "dtaus0.sik";
+
+void help ()
 {
+  printf ("dtaus - Belegloser Datenträgeraustausch mit einer Bank\n\n");
+  printf ("  -dtaus        Erzeugt eine Bankdatei\n");
+  printf ("  -control      Liest eine Bankdatei und erzeugt die Kontrolldatei\n");
+  printf ("\n");
+  printf ("  -d <dtaus>    Bankdatei [%s]\n", dtaus);
+  printf ("  -c <control>  Steuerdatei [%s]\n", control);
+  printf ("  -b <begleit>  Begleitzettel für die Bank [%s]\n", beleg);
+  printf ("  -o <kontroll> Kontrolldatei zum Abheften [%s]\n", check);
+}
+
+#define DTAUS   1
+#define CONTROL 2
+
+int main (int argc, char **argv)
+{
+  int action = 0;
+  int i = 0;
+  struct stat sbuf;
+
+  while (argc - i > 1) {
+    i++;
+    if ( !strcmp(argv[i], "-h") ) {
+      help(); exit(0);
+    } else if ( !strcmp(argv[i], "-v") ) {
+      printf ("dtaus version %s - Copyright (c) 1997,8,2001 by Martin Schulze <joey@infodrom.org>\n", version);
+      exit (0);
+    } else if ( !strcmp(argv[i], "-d") ) {
+      if (argc - i > 1) {
+       i++;
+       dtaus = argv[i];
+      }
+    } else if ( !strcmp(argv[i], "-c") ) {
+      if (argc - i > 1) {
+       i++;
+       control = argv[i];
+      }
+    } else if ( !strcmp(argv[i], "-b") ) {
+      if (argc - i > 1) {
+       i++;
+       beleg = argv[i];
+      }
+    } else if ( !strcmp(argv[i], "-o") ) {
+      if (argc - i > 1) {
+       i++;
+       check = argv[i];
+      }
+    } else if ( !strcmp(argv[i], "-dtaus") ) {
+      action = DTAUS;
+    } else if ( !strcmp(argv[i], "-control") ) {
+      action = CONTROL;
+    } 
+  }
+
+  if (action == DTAUS) {
+    if (!strcmp("-", control) || !stat(control, &sbuf)) {
+      if (control2dtaus (control, dtaus, beleg, check) == 0)
+       exit (1);
+    }
+    else {
+      fprintf( stderr, "Can't stat %s\n", control);
+      exit (1);
+    }
+  } else if (action == CONTROL) {
+    if (!strcmp("-",dtaus) || !stat(dtaus, &sbuf))
+      dtaus2control (dtaus, control);
+    else {
+      fprintf( stderr, "Can't stat %s\n", dtaus);
+      exit (1);
+    }
+  } else {
+    printf ("Keine Routine angegeben (-dtaus bzw. -control vergessen).\n");
+    exit (1);
+  }
+  exit (0);
 }