Be more explicit for malloc() calls
[infodrom/dtaus] / latex.c
1 /*
2     latex.c - Belegloser Datenträgeraustausch mit einer Bank
3     Copyright (c) 2004  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 #include <stdio.h>
23 #include "bigint.h"
24
25 #define LATEX_HEADER    "%% Automatically generated by dtaus, requires dtaus.cls from the\n\
26 %% source distribution or derivative class.\n\
27 %%\n\
28 \\documentclass{dtaus}\n\
29 \n\
30 \\begin{document}\n\
31 \n\
32 \\header\n\
33 \n\
34 \\headline{Begleitzettel}\n\
35 \n\
36 \\subheadline{Belegloser Datenträgeraustausch}\n\
37 "
38
39 #define LATEX_FOOTER    "\\vfill\n\
40 \n\
41 \\signature\n\
42 \n\
43 \\footer\n\
44 \n\
45 \\end{document}\n\
46 "
47
48 #define LATEX_TYPE      "\\subheadline{%s}\n\n"
49
50 #define LATEX_TAB_BEGIN "\\begin{tabular}{l@{ : }l}\n"
51 #define LATEX_TAB_END   "\\end{tabular}\n\n"
52 #define LATEX_TAB_ROW   "\\tabline{%s}{%s}\n"
53
54 void generate_latex_receipt (
55                              char *fname,
56                              char *type,
57                              char *created,
58                              char *todo,
59                              char *currency,
60                              int quantity,
61                              char *sum_val,
62                              char *sum_kto,
63                              char *sum_blz,
64                              char *kto,
65                              char *blz
66                              )
67 {
68   FILE *f;
69   char tmp[10];
70
71   if (!(f = fopen(fname, "w"))) {
72     fprintf (stderr, "Cannot open LaTeX output file %s, ignoring.\n", fname);
73     return;
74   }
75
76   /* fopen() */
77   fprintf (f, LATEX_HEADER);
78   fprintf (f, LATEX_TYPE, type);
79
80   fprintf (f, LATEX_TAB_BEGIN);
81   fprintf (f, LATEX_TAB_ROW, "VOL", "");
82   fprintf (f, LATEX_TAB_ROW, "Erstellungsdatum", created);
83   if (todo)
84     fprintf (f, LATEX_TAB_ROW, "Ausführugsdatum", todo);
85   fprintf (f, LATEX_TAB_ROW, "Währung", currency);
86   snprintf (tmp, sizeof (tmp), "%d", quantity);
87   fprintf (f, LATEX_TAB_ROW, "Anzahl", tmp);
88   fprintf (f, LATEX_TAB_ROW, "Summe", sum_val);
89   fprintf (f, LATEX_TAB_ROW, "Kontrollsumme Kontonummern", sum_kto);
90   fprintf (f, LATEX_TAB_ROW, "Kontrollsumme Bankleitzahlen", sum_blz);
91   fprintf (f, LATEX_TAB_ROW, "Unsere Kontonummer", kto);
92   fprintf (f, LATEX_TAB_ROW, "Unsere Bankleitzahl", blz);
93   fprintf (f, LATEX_TAB_END);
94
95   fprintf (f, LATEX_FOOTER);
96
97   fclose (f);
98 }
99
100 /* --------------------
101 \subheadline{Sammeleinziehungsauftrag}
102
103 \begin{tabular}{l@{ : }l}
104 \tabline{VOL}{}
105 \tabline{Erstellungsdatum}{05.08.04}
106 \tabline{Ausführugsdatum}{24.12.2001}
107 \tabline{Währung}{Euro}
108 \tabline{Anzahl}{2}
109 \tabline{Summe}{50.00}
110 \tabline{Kontrollsumme Kontonummern}{2469134}
111 \tabline{Kontrollsumme Bankleitzahlen}{94221630}
112 \tabline{Unsere Kontonummer}{0000123545}
113 \tabline{Unsere Bankleitzahl}{02004002}
114 \end{tabular}
115 -------------------- */
116