2 dtaus.c - Belegloser Datenträgeraustausch mit einer Bank
3 Copyright (c) 1996,8,2001 Martin Schulze <joey@infodrom.org>
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.
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.
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.
31 /* #define DEFAULT_EURO */
37 * First: Some control structures
43 unsigned short int pos;
44 unsigned short int len;
56 dtaus_record recA[] = {
58 {"Name", 23, 27, REQ},
59 {"Konto", 60, 10, REQ},
61 {"Referenz", 70, 10, OPT},
62 {"Datum", 50, 6, IGN},
63 {"Ausfuehrung", 95, 8, OPT},
64 {"Euro", 127, 1, OPT},
78 dtaus_record recC[] = {
79 {"Name", 93, 27, REQ},
80 {"Konto", 21, 10, REQ},
82 {"Transaktion", 44, 5, REQ},
84 {"Betrag", 50, 11, REQ},
86 {"Betrag", 79, 11, REQ},
88 {"Zweck", 155, 27, REQ},
89 {"myName", 128, 27, OPT},
90 {"myKonto", 69, 10, OPT},
91 {"myBLZ", 61, 8, OPT},
92 {"Euro", 182, 1, IGN},
93 {"Text", 187, 29, OPT},
94 {"Extension", 216, 29, OPT},
96 {"Betrag-Euro", 79, 11, IGN},
122 dtaus_record recE[] = {
123 {"Anzahl", 10, 7, IGN},
125 {"Summe", 17, 13, IGN},
127 {"Summe", 64, 13, IGN},
129 {"Kontos", 30, 17, IGN},
130 {"BLZs", 47, 17, IGN},
132 {"Summe-Euro", 64, 13, IGN},
146 * Second: Some low level routines
149 size_t dtaus_nextrec (void **buf, FILE *f)
152 return fread(buf, 128, 1, f);
155 char *upcase(char *s)
161 for (cp=s,xp=x; *cp; cp++,xp++) {
162 if (strchr(" 0123456789.,&-/+*$%ABCDEFGHIJKLMNOPQRSTUVWXYZ",*cp)) {
164 } else if (strchr("abcdefghijklmnopqrstuvwxyz",*cp)) {
166 } else if (strchr ("üÜäÄöÖß", *cp)) {
168 case 'ü': *(xp++) = 'U'; *xp='E'; break;
169 case 'Ü': *(xp++) = 'U'; *xp='E'; break;
170 case 'ä': *(xp++) = 'A'; *xp='E'; break;
171 case 'Ä': *(xp++) = 'A'; *xp='E'; break;
172 case 'ö': *(xp++) = 'O'; *xp='E'; break;
173 case 'Ö': *(xp++) = 'O'; *xp='E'; break;
174 case 'ß': *(xp++) = 'S'; *xp='S'; break;
178 * Filter out all other characters since credit institutes won't
179 * accept the file otherwise.
188 char *downcase(char *s)
193 memset (x, 0, sizeof (x));
202 char *strip_spaces (char *s)
207 for (i=strlen(s);(s[i-1] == ' '||s[i-1] == '\t')&&i>0; i--)
209 for (p=s; *p==' '; p++);
213 char *strip_zeros (char *s)
217 for (p=s; *p=='0'; p++);
221 char *strip_nondigits (char *s)
234 char dtaus_char (void *buf, unsigned int pos)
240 memcpy(&res, bufp, 1);
244 char *string2real(char *s)
250 strncpy(res, s, strlen(s)-2);
251 res[strlen(s)-2] = '.';
252 res[strlen(s)-1] = s[strlen(s)-2];
253 res[strlen(s)] = s[strlen(s)-1];
257 char *real2string(char *s)
263 for (cp=res; *cp&&!(*cp == ',')&&!(*cp == '.');cp++);
270 char *string2trans (char *s)
275 if (!strcmp(s, "04000"))
276 sprintf (res, "Abbuchung");
277 else if (!strcmp(s, "05000"))
278 sprintf (res, "Einzug");
279 else if (!strcmp(s, "05005"))
280 sprintf (res, "E-Cash");
281 else if (!strcmp(s, "05006"))
282 sprintf (res, "E-Cash-A");
283 else if (!strcmp(s, "51000"))
284 sprintf (res, "Gutschrift");
285 else if (!strcmp(s, "53000"))
286 sprintf (res, "Lohn");
287 else if (!strncmp(s, "5400", 4))
288 sprintf (res, "Vermögen");
289 /* else if (!strcmp(s, "56000"))
290 sprintf (res, ""); / * Überweisung öffentlicher Kassen */
294 char *trans2string (char *s)
299 if (!strcmp(s, "Abbuchung"))
300 sprintf (res, "04000");
301 else if (!strcmp(s, "Einzug"))
302 sprintf (res, "05000");
303 else if (!strcmp(s, "E-Cash"))
304 sprintf (res, "05005");
305 else if (!strcmp(s, "E-Cash-A"))
306 sprintf (res, "05006");
307 else if (!strcmp(s, "Gutschrift"))
308 sprintf (res, "51000");
309 else if (!strcmp(s, "Lohn"))
310 sprintf (res, "53000");
311 else if (!strncmp(s, "Vermögen", 4))
312 sprintf (res, "5400");
313 /* else if (!strcmp(s, ""))
314 sprintf (res, "56000"); / * Überweisung öffentlicher Kassen */
318 char *string2ext (char *s)
323 if (!strcmp(s, "01"))
324 sprintf (res, "Kunde");
325 else if (!strcmp(s, "02"))
326 sprintf (res, "Text");
327 else if (!strcmp(s, "03"))
328 sprintf (res, "Auftraggeber");
332 char *ext2string (char *s)
337 if (!strcmp(s, "Kunde"))
339 else if (!strcmp(s, "Text"))
341 else if (!strcmp(s, "Auftraggeber"))
346 unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
350 static unsigned long int res;
353 memcpy(tmp, bufp, len);
355 sscanf(tmp, "%lu", &res);
360 * returns the first word in this line, returns it and shortens the
363 char *extract_ident (char *line)
366 static char word[30];
368 if (strlen(line) > 0) {
369 x = index (line, ' ');
370 y = index (line, '\t');
373 strncpy(word, line, 29);
378 /* Check which index returns the lower value, and check if the
380 if ((c = (x && x<y)?x:(y?y:x))) {
381 strncpy(word, line, c - line);
383 for (;*c == '\t' || *c == ' '; c++);
384 for (x=line; *c; c++,x++)
387 strcpy(word, downcase(word));
396 * Pads a string with zero's on the left side.
398 char *padzeroclip (char *s, int len)
402 if (strlen(s) == len) return s;
403 if (strlen(s) > len) {
411 for (p=s+strlen(s)-1;p>=s;p--)
413 for (;q>=s;) *(q--)='0';
417 int rec_index(char *ident, int type)
420 dtaus_record *rec = NULL;
423 case REC_A: rec = recA; break;
424 case REC_C: rec = recC; break;
425 case REC_E: rec = recE; break;
428 for (i=0; (rec[i].name); i++) {
429 if (!strcmp(ident, downcase(rec[i].name)))
436 size_t control_nextline (void **buf, int len, FILE *f)
443 bzero (line, sizeof(line));
447 while (!strlen(line) && (cp = fgets(line, 100, f))) {
449 if (line[0] != '#') {
450 if (line[strlen(line)-1] != '\n') {
452 while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
454 line[strlen(line)-1] = '\0';
455 if (line[strlen(line)-1] == '
\r')
456 line[strlen(line)-1] = '\0';
457 for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
465 for (cp=line; *cp==' '; cp++);
468 memcpy(buf, cp, strlen(cp));
480 timer = time ( NULL );
481 loctime = localtime(&timer);
482 sprintf(res, "%02d.%02d.%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
487 * Prepare a record A according to the specs.
488 * See dtaus.txt for explanation
490 void dtaus_prepareA (char *buf)
498 timer = time ( NULL );
499 loctime = localtime(&timer);
506 for (i=15;i<15+8; i++) buf[i] = '0'; /* A5 */
507 sprintf(tmp, "%02d%02d%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
508 for (i=0; i<6; i++) buf[50+i] = tmp[i]; /* A7 (Date) */
509 for (i=56;i<56+4; i++) buf[i] = ' '; /* A8 */
510 for (i=70;i<70+10; i++) buf[i] = '0'; /* A10 */
511 for (i=80;i<80+48; i++) buf[i] = ' '; /* A11 */
513 buf[recA[A_EURO].pos] = '1'; /* A12 (Currency) */
516 buf[recA[A_EURO].pos] = '1'; /* A12 (Currency) */
518 buf[recA[A_EURO].pos] = ' '; /* A12 (Currency) */
523 * Prepare a record C according to the specs.
524 * See dtaus.txt for explanation
526 void dtaus_prepareC (char *buf, int normaltext, int maxtext)
536 i = 187 + (appendix * 29);
538 /* Bail out if the number is too large, shouldn't be possible though */
542 buf[0] = (i/1000)+48;i-=(i/1000)*100;
543 buf[1] = (i/100)+48;i-=(i/100)*100;
544 buf[2] = (i/10)+48;i-=(i/10)*10;
548 for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */
549 buf[49] = ' '; /* C8 */
550 for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */
551 for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Betrag Euro) */
552 for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */
553 for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */
554 for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */
556 buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */
559 buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */
561 buf[recC[C_EURO].pos] = ' '; /* C17a (Currency) */
563 for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */
564 for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */
565 for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */
567 buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10;
568 buf[185+1] = appendix+48;
572 * Prepare a record E according to the specs.
573 * See dtaus.txt for explanation
575 void dtaus_prepareE (char *buf)
585 for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */
586 for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */
587 for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */
588 for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */
591 int dtaus_writeA(FILE *f, char **values)
597 for (i=0; (recA[i].name); i++)
598 if ((recA[i].type == REQ) && !values[i]) {
599 fprintf (stderr, "Anfangsdatensatz ist nicht vollständig, kein %s.\n", recA[i].name);
602 if (!(((values[A_TRANS][0] == 'L')||(values[A_TRANS][0] == 'G'))
603 &&((values[A_TRANS][1] == 'B')||(values[A_TRANS][1] == 'K')))) {
604 fprintf (stderr, "Ungültiger Typ, nur LK, GK, LB oder GB erlaubt.\n");
608 i=A_NAME;if (values[i] && strlen(values[i]) > recA[i].len)
609 values[i][recA[i].len] = '\0';
612 buf[5] = values[A_TRANS][0];
613 buf[6] = values[A_TRANS][1];
614 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),recA[A_BLZ].len));
615 for (i=0; i<recA[A_BLZ].len; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
616 sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
617 for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
618 if (values[A_TODO]) {
619 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_TODO]),recA[A_TODO].len));
620 for (i=0; i<recA[A_TODO].len; i++) buf[recA[A_TODO].pos+i] = tmp[i];
622 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),recA[A_KTO].len));
623 for (i=0; i<recA[A_KTO].len; i++) buf[recA[A_KTO].pos+i] = tmp[i];
629 int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
639 if (text) for (maxtext=0;text[maxtext];maxtext++);
642 for (i=0; (recC[i].name); i++)
644 printf ("%s: %s\n", recC[i].name, values[i]);
647 for (i=0; (recC[i].name); i++)
648 if ((recC[i].type == REQ) && !values[i]) {
649 fprintf (stderr, "Datensatz ist nicht vollständig, kein %s.\n", recC[i].name);
652 sprintf (tmp, "%s", trans2string(values[C_TRANS]));
654 fprintf (stderr, "Ungültiger Typ, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
658 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
659 values[i][recC[i].len-2] = '\0';
660 i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
661 values[i][recC[i].len] = '\0';
662 i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
663 values[i][recC[i].len] = '\0';
664 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
665 values[i][recC[i].len] = '\0';
667 dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
668 for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
670 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8));
672 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_BLZ]),8));
673 for (i=0; i<recC[C_MYBLZ].len; i++) buf[5+i] = tmp[i];
674 for (i=0; i<recC[C_MYBLZ].len; i++) buf[recC[C_MYBLZ].pos+i] = tmp[i];
675 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_BLZ]),8));
676 for (i=0; i<recC[C_BLZ].len; i++) buf[recC[C_BLZ].pos+i] = tmp[i];
677 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
678 for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
679 sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
682 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
684 for (i=0; i<recC[C_EUR].len; i++) buf[recC[C_EUR].pos+i] = tmp[i];
686 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
689 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
691 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_KTO]),10));
692 for (i=0; i<recC[C_MYKTO].len; i++) buf[recC[C_MYKTO].pos+i] = tmp[i];
693 sprintf (tmp, "%-27.27s", upcase(values[C_NAME]));
694 for (i=0; i<recC[C_NAME].len; i++) buf[recC[C_NAME].pos+i] = tmp[i];
696 sprintf (tmp, "%-27.27s", upcase(values[C_MYNAM]));
698 sprintf (tmp, "%-27.27s", upcase(valuesA[A_NAME]));
699 for (i=0; i<recC[C_MYNAM].len; i++) buf[recC[C_MYNAM].pos+i] = tmp[i];
700 sprintf (tmp, "%-27.27s", upcase(values[C_ZWECK]));
701 for (i=0; i<recC[C_ZWECK].len; i++) buf[recC[C_ZWECK].pos+i] = tmp[i];
703 if (values[C_TEXT]) {
704 buf[recC[C_TEXT].pos+0] = '0';
705 buf[recC[C_TEXT].pos+1] = '2';
706 sprintf (tmp, "%-27.27s", upcase(values[C_TEXT]));
707 for (i=0; i<recC[C_TEXT].len-2; i++) buf[recC[C_TEXT].pos+2+i] = tmp[i];
711 buf[recC[C_EXT].pos+0] = '0';
712 buf[recC[C_EXT].pos+1] = '2';
713 sprintf (tmp, "%-27.27s", upcase(text[0]));
714 for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
719 if (text && maxtext > 1) {
721 while (fieldnr<maxtext) {
722 memset (appendix, ' ', 128);
723 appendix[128] = '\0';
724 for (k=0; k<4 && (fieldnr+k)<maxtext; k++) {
725 sprintf (tmp, "%-27.27s", upcase(text[fieldnr+k]));
726 appendix[k*29] = '0';
727 appendix[(k*29)+1] = '2';
728 for (i=0; i<recC[C_TEXT].len-2; i++) appendix[(k*29)+2+i] = tmp[i];
738 int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
746 sprintf (tmp, "%07d", count);
747 for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
748 bigint_sprintf (tmp, "%s", sum);
749 padzeroclip (tmp,13);
752 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
754 for (i=0; i<recE[E_EUR].len; i++) buf[recE[E_EUR].pos+i] = tmp[i];
756 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
758 bigint_sprintf (tmp, "%s", kto);
759 padzeroclip (tmp,17);
760 for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
761 bigint_sprintf (tmp, "%s", blz);
762 padzeroclip (tmp,17);
763 for (i=0; i<recE[E_BLZ].len; i++) buf[recE[E_BLZ].pos+i] = tmp[i];
769 void printctln(FILE *f, char *field, char *value)
771 if (strlen(field) && strlen(value))
772 fprintf(f, " %s\t%s\n", field, value);
777 * Third: Some high level routines
780 void dtaus2control (char *cdtaus, char *ccontrol)
782 FILE *fdtaus, *fcontrol;
792 if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
793 if (!(fdtaus = fopen("dtaus0.txt", "r")))
796 if (!strcmp (cdtaus, "-"))
799 if (!(fdtaus = fopen(cdtaus, "r")))
805 if (!strcmp (ccontrol, "-"))
808 if (!(fcontrol = fopen(ccontrol, "w")))
810 if (!(buf = (char *)malloc (512)))
816 if (dtaus_nextrec(buf, fdtaus) == 1) {
817 if (dtaus_char(buf,4) == 'A') {
818 fprintf(fcontrol, "BEGIN {\n");
822 for (index=A_TRANS; index <= A_EURO; index++) {
824 for (index=A_TRANS; index < A_EURO; index++) {
826 bufp = buf + recA[index].pos;
827 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
828 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
832 if (tmp[recA[index].pos] == '1')
836 fprintf(fcontrol, "}\n\n");
838 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz an.\n");
842 fprintf (stderr, "Der Anfangsdatensatz ist kaputt.\n");
849 if (dtaus_nextrec(buf, fdtaus) == 1) {
850 while (dtaus_char(buf,4) == 'C') {
852 if (dtaus_nextrec(bufp, fdtaus) != 1) {
853 fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
856 fprintf(fcontrol, "{\n");
858 for (index=C_NAME; index < C_EURO; index++) {
860 if (use_euro && index == C_VAL)
863 bufp = buf + recC[index].pos;
864 memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
866 if (index == C_VAL || index == C_EUR)
870 printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
871 else if (index == C_TRANS)
872 printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
874 printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
876 if (use_euro && index == C_EUR)
881 for (index=C_TEXT; index <= C_EXT; index++) {
882 if (!(dtaus_char(buf,recC[index].pos) == ' ')) {
883 bufp = buf + recC[index].pos;
884 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
885 memcpy(tmp, bufp, recC[index].len-2); tmp[recC[index].len-2] = '\0';
886 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
890 /* Number of extension records for this C record */
891 extC = dtaus_int(buf, 185, 2);
899 if (dtaus_nextrec(buf, fdtaus) != 1)
900 bzero (buf, sizeof(buf));
903 * Are there extension records that we have to check?
905 * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
906 * instead of 00 we should let it in so it can read its own
907 * old files... *sigh*
909 while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') {
910 for (index=0; index < 4; index++) {
911 if ((dtaus_char(buf,index*29) != ' ')) {
912 bufp = buf + index*29;
913 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
914 memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
915 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
918 if (dtaus_nextrec(buf, fdtaus) != 1)
919 bzero (buf, sizeof(buf));
922 fprintf(fcontrol, "}\n");
928 * (gelesen ist er eigentlich schon...)
930 if (dtaus_char(buf,4) == 'E') {
931 if (dtaus_char(buf,4) == 'E') {
932 fprintf(fcontrol, "\nEND {\n");
934 for (index=E_COUNT; index <= E_BLZ; index++) {
936 if (use_euro && index == E_VAL)
939 bufp = buf + recE[index].pos;
940 memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
942 if (index == E_VAL || index == E_EUR)
946 printctln(fcontrol, recE[index].name, strip_zeros(string2real(tmp)));
948 printctln(fcontrol, recE[index].name, strip_zeros(tmp));
950 if (use_euro && index == E_EUR)
955 fprintf(fcontrol, "}\n");
957 fprintf (stderr, "Das ist kein Abschlußdatensatz.\n");
961 fprintf (stderr, "Der Abschlußdatensatz ist leer oder kaputt.\n");
968 int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
970 FILE *fdtaus, *fcontrol, *fbeleg, *fcheck;
976 char *valA[A_LEN], *valC[C_LEN];
978 bigint sum_val, sum_blz, sum_kto, bi;
984 if (!(fdtaus = fopen("dtaus0.txt", "w")))
987 if (!strcmp (cdtaus, "-"))
990 if (!(fdtaus = fopen(cdtaus, "w")))
994 if (!(fcontrol = fopen("dtaus0.ctl", "r")))
995 if (!(fcontrol = fopen("DTAUS0.CTL", "r")))
998 if (!strcmp (ccontrol, "-"))
1001 if (!(fcontrol = fopen(ccontrol, "r")))
1005 if (!(fbeleg = fopen("dtaus0.doc", "w")))
1008 if (!(fbeleg = fopen(cbeleg, "w")))
1014 if (!(fcheck = fopen(ccheck, "w")))
1018 if (!(buf = (char *)malloc (512)))
1024 bzero(valA, sizeof(valA));
1025 control_nextline ((void *)line, 100, fcontrol);
1026 ident = extract_ident(line);
1027 if (!strcmp(ident, "begin") && (line[0] == '{')) {
1028 control_nextline ((void *)line, 100, fcontrol);
1029 while (strlen(line) && line[0] != '}') {
1030 ident = extract_ident(line);
1031 if ((recindex = rec_index(ident, REC_A)) != -1)
1032 #ifndef DEFAULT_EURO
1035 if (recA[recindex].type != IGN)
1036 if ((valA[recindex] = (char *)malloc (strlen(line)+1)))
1037 strcpy(valA[recindex], line);
1038 #ifndef DEFAULT_EURO
1040 if (! strcasecmp (ident, "euro"))
1044 control_nextline ((void *)line, 100, fcontrol);
1046 if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
1047 fprintf(fbeleg, "\n\n");
1048 fprintf(fbeleg, "\n Begleitzettel\n\n");
1049 fprintf(fbeleg, "\n Belegloser Datentraegeraustausch\n\n");
1050 if (valA[recindex][0] == 'L')
1051 fprintf(fbeleg, "\n Sammeleinziehungsauftrag\n\n");
1052 else if (valA[recindex][0] == 'G')
1053 fprintf(fbeleg, "\n Sammelueberweisungsauftrag\n\n");
1055 fprintf(fbeleg, "\n Sammelauftrag\n\n");
1056 fprintf(fbeleg, "\n VOL ........................:\n");
1057 fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date());
1059 fprintf(fbeleg, "\n Ausfuehrugsdatum ...........: %s\n", valA[A_TODO]);
1061 #ifndef DEFAULT_EURO
1063 fprintf(fbeleg, "\n Waehrung ...................: Euro\n");
1065 fprintf(fbeleg, "\n Waehrung ...................: DM\n");
1067 fprintf(fbeleg, "\n Waehrung ...................: Euro\n");
1070 if (!dtaus_writeA(fdtaus, valA)) {
1071 fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
1075 fprintf (fcheck, "\n\n\n");
1076 if (valA[recindex][0] == 'L')
1077 fprintf (fcheck, " Sammeleinziehungsauftrag\n\n");
1078 else if (valA[recindex][0] == 'G')
1079 fprintf (fcheck, " Sammelueberweisungsauftrag\n\n");
1081 fprintf (fcheck, " Sammelauftrag\n\n");
1082 fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date());
1083 #ifndef DEFAULT_EURO
1085 fprintf (fcheck, " Waehrung : Euro\n\n\n");
1087 fprintf (fcheck, " Waehrung : DM\n\n\n");
1089 fprintf (fcheck, " Waehrung : Euro\n\n\n");
1091 fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
1092 fprintf (fcheck, " --------------------------------------------------------------------\n");
1094 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz (BEGIN) an.\n");
1102 sum_val = bigint_int(0);
1103 sum_blz = bigint_int(0);
1104 sum_kto = bigint_int(0);
1105 bzero(valC, sizeof(valC));
1106 control_nextline ((void *)line, 100, fcontrol);
1107 if (line[0] == '{') {
1108 while (strlen(line) && line[0] == '{') {
1109 control_nextline ((void *)line, 100, fcontrol);
1111 for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++)
1112 free (text[textindex]);
1116 while (strlen(line) && line[0] != '}') {
1117 ident = extract_ident(line);
1118 if ((recindex = rec_index(ident, REC_C)) != -1)
1119 if (recC[recindex].type != IGN) {
1121 * Special exception to support multiple Text fields
1123 if (recindex == C_TEXT && valC[recindex]) {
1125 if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL)
1129 memset (text, 0, (MAX_TEXT+1) * sizeof (char *));
1132 if (textindex < MAX_TEXT) {
1133 if ((cp = (char *)malloc (strlen (line) + 1))) {
1135 cp[strlen (line)] = '\0';
1136 text[textindex++] = cp;
1140 if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
1141 strcpy(valC[recindex], line);
1146 control_nextline ((void *)line, 100, fcontrol);
1148 if (!dtaus_writeC(fdtaus, valA, valC, text)) {
1149 fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n");
1153 bi = bigint_string(real2string(valC[C_VAL])); sum_val = bigint_add(sum_val, bi);
1154 bi = bigint_string(valC[C_BLZ]); sum_blz = bigint_add(sum_blz, bi);
1155 bi = bigint_string(valC[C_KTO]); sum_kto = bigint_add(sum_kto, bi);
1157 fprintf (fcheck, " %10s %8s %-30s %12s\n", valC[C_KTO], valC[C_BLZ], valC[C_NAME], valC[C_VAL]);
1158 for (recindex=0; recindex<C_LEN; recindex++)
1160 free(valC[recindex]);
1161 bzero(valC, sizeof(valC));
1162 control_nextline ((void *)line, 100, fcontrol);
1165 fprintf (stderr, "Kein regulärer Datensatz?\n");
1172 dtaus_writeE(fdtaus, count, sum_val, sum_blz, sum_kto);
1173 fprintf (fcheck, " --------------------------------------------------------------------\n");
1174 bigint_sprintf (tmp, "%s", sum_val);
1175 fprintf (fbeleg, "\n Anzahl .....................: %d\n", count);
1176 recindex=strlen(tmp);
1177 tmp[recindex+1] = '\0';
1178 tmp[recindex] = tmp[recindex-1];
1179 tmp[recindex-1] = tmp[recindex-2];
1180 tmp[recindex-2] = '.';
1181 fprintf (fcheck, " %-52s %14s\n", "Summe", tmp);
1182 fprintf (fbeleg, "\n Summe ......................: %s\n", tmp);
1183 bigint_sprintf (tmp, "%s", sum_kto);
1184 fprintf (fbeleg, "\n Kontrollsumme Kontonummern .: %s\n", tmp);
1185 bigint_sprintf (tmp, "%s", sum_blz);
1186 fprintf (fbeleg, "\n Kontrollsumme Bankleitzahlen: %s\n", tmp);
1187 fprintf (fbeleg, "\n Unsere Kontonummer .........: %s\n", valA[A_KTO]);
1188 fprintf (fbeleg, "\n Unsere Bankleitzahl ........: %s\n", valA[A_BLZ]);
1189 fprintf (fbeleg, "\n\n\n\n\n __________________________________________________\n");
1190 fprintf (fbeleg, " Ort, Datum Unterschrift\n");
1191 for (recindex=0; recindex<A_LEN; recindex++)
1193 free(valA[recindex]);