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