Corrected a typo, found by Dirk Jagdmann <doj@cubic.org>
[infodrom/dtaus] / main.c
1 /*
2     main.c - Belegloser Datenträgeraustausch mit einer Bank
3     Copyright (c) 1996,8,2001  Martin Schulze <joey@infodrom.org>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
18
19     $Id$
20  */
21
22 static char version[] = "0.5";
23
24 #include <stdio.h>
25 #include <sys/stat.h>
26 #include <unistd.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include "dtaus.h"
30
31 void help ()
32 {
33   printf ("dtaus - Belegloser Datenträgeraustausch mit einer Bank\n\n");
34   printf ("  -dtaus        Erzeugt eine Bankdatei\n");
35   printf ("  -control      Liest eine Bankdatei und erzeugt die Kontrolldatei\n");
36   printf ("\n");
37   printf ("  -d <dtaus>    Bankdatei [dtaus0.txt]\n");
38   printf ("  -c <control>  Steuerdatei [dtaus0.ctl]\n");
39   printf ("  -b <begleit>  Begleitzettel fĂ¼r die Bank dtaus0.doc]\n");
40   printf ("  -o <kontroll> Kontrolldatei zum Abheften [dtaus0.sik]\n");
41 }
42
43 #define DTAUS   1
44 #define CONTROL 2
45
46 int main (int argc, char **argv)
47 {
48   char *dtaus[60];
49   char *control[60];
50   char *beleg[60];
51   char *check[60];
52   int action = 0;
53   int i = 0;
54   struct stat sbuf;
55
56   strcpy ((char *)dtaus, "dtaus0.txt");
57   strcpy ((char *)control, "dtaus0.ctl");
58   strcpy ((char *)beleg, "dtaus0.doc");
59   strcpy ((char *)check, "dtaus0.sik");
60
61   while (argc - i > 1) {
62     i++;
63     if ( !strcmp(argv[i], "-h") ) {
64       help(); exit(0);
65     } else if ( !strcmp(argv[i], "-v") ) {
66       printf ("dtaus version %s - Copyright (c) 1997,8,2001 by Martin Schulze <joey@infodrom.org>\n", version);
67       exit (0);
68     } else if ( !strcmp(argv[i], "-d") ) {
69       if (argc - i > 1) {
70         i++;
71         strcpy ((char *)dtaus, argv[i]);
72       }
73     } else if ( !strcmp(argv[i], "-c") ) {
74       if (argc - i > 1) {
75         i++;
76         strcpy ((char *)control, argv[i]);
77       }
78     } else if ( !strcmp(argv[i], "-b") ) {
79       if (argc - i > 1) {
80         i++;
81         strcpy ((char *)beleg, argv[i]);
82       }
83     } else if ( !strcmp(argv[i], "-o") ) {
84       if (argc - i > 1) {
85         i++;
86         strcpy ((char *)check, argv[i]);
87       }
88     } else if ( !strcmp(argv[i], "-dtaus") ) {
89       action = DTAUS;
90     } else if ( !strcmp(argv[i], "-control") ) {
91       action = CONTROL;
92     } 
93   }
94
95   if (action == DTAUS) {
96     if (!stat((char *)control, &sbuf)) {
97       if (control2dtaus ((char *)control, (char *)dtaus, (char *)beleg, (char *)check) == 0)
98         exit (1);
99     }
100     else exit (1);
101   } else if (action == CONTROL) {
102     if (!stat((char *)dtaus, &sbuf))
103       dtaus2control ((char *)dtaus, (char *)control);
104     else exit (1);
105   } else {
106     printf ("Keine Routine angegeben (-dtaus bzw. -control vergessen).\n");
107     exit (1);
108   }
109   exit (0);
110 }