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