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