1f88b11e1c1b266f0f4fea4f80c04e1537f9c08e
[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 "dtaus.h"
28
29 void help ()
30 {
31   printf ("dtaus - Belegloser Datenträgeraustausch mit einer Bank\n\n");
32   printf ("  -dtaus        Erzeugt eine Bankdatei\n");
33   printf ("  -control      Liest eine Bankdatei und erzeugt die Kontrolldatei\n");
34   printf ("\n");
35   printf ("  -d <dtaus>    Bankdatei [dtaus0.txt]\n");
36   printf ("  -c <control>  Steuerdatei [dtaus0.ctl]\n");
37   printf ("  -b <begleit>  Begleitzettel fĂ¼r die Bank dtaus0.doc]\n");
38   printf ("  -o <kontroll> Kontrolldatei zum Abheften [dtaus0.sik]\n");
39 }
40
41 #define DTAUS   1
42 #define CONTROL 2
43
44 int main (int argc, char **argv)
45 {
46   char *dtaus[60];
47   char *control[60];
48   char *beleg[60];
49   char *check[60];
50   int action = 0;
51   int i = 0;
52   struct stat sbuf;
53
54   strcpy ((char *)dtaus, "dtaus0.txt");
55   strcpy ((char *)control, "dtaus0.ctl");
56   strcpy ((char *)beleg, "dtaus0.doc");
57   strcpy ((char *)check, "dtaus0.sik");
58
59   while (argc - i > 1) {
60     i++;
61     if ( !strcmp(argv[i], "-h") ) {
62       help(); exit(0);
63     } else if ( !strcmp(argv[i], "-v") ) {
64       printf ("dtaus version %s - Copyright (c) 1997,8,2001 by Martin Schulze <joey@infodrom.org>\n", version);
65       exit (0);
66     } else if ( !strcmp(argv[i], "-d") ) {
67       if (argc - i > 1) {
68         i++;
69         strcpy ((char *)dtaus, argv[i]);
70       }
71     } else if ( !strcmp(argv[i], "-c") ) {
72       if (argc - i > 1) {
73         i++;
74         strcpy ((char *)control, argv[i]);
75       }
76     } else if ( !strcmp(argv[i], "-b") ) {
77       if (argc - i > 1) {
78         i++;
79         strcpy ((char *)beleg, argv[i]);
80       }
81     } else if ( !strcmp(argv[i], "-o") ) {
82       if (argc - i > 1) {
83         i++;
84         strcpy ((char *)check, argv[i]);
85       }
86     } else if ( !strcmp(argv[i], "-dtaus") ) {
87       action = DTAUS;
88     } else if ( !strcmp(argv[i], "-control") ) {
89       action = CONTROL;
90     } 
91   }
92
93   if (action == DTAUS) {
94     if (!stat((char *)control, &sbuf)) {
95       if (control2dtaus ((char *)control, (char *)dtaus, (char *)beleg, (char *)check) == 0)
96         exit (1);
97     }
98     else exit (1);
99   } else if (action == CONTROL) {
100     if (!stat((char *)dtaus, &sbuf))
101       dtaus2control ((char *)dtaus, (char *)control);
102     else exit (1);
103   } else {
104     printf ("Keine Routine angegeben (-dtaus bzw. -control vergessen).\n");
105     exit (1);
106   }
107   exit (0);
108 }