2 dtaus.c - 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 */
34 * First: Some control structures
40 unsigned short int pos;
41 unsigned short int len;
53 dtaus_record recA[] = {
55 {"Name", 23, 27, REQ},
56 {"Konto", 60, 10, REQ},
58 {"Referenz", 70, 10, OPT},
59 {"Datum", 50, 6, IGN},
60 {"Euro", 127, 1, OPT},
73 dtaus_record recC[] = {
74 {"Name", 93, 27, REQ},
75 {"Konto", 21, 10, REQ},
77 {"Transaktion", 44, 5, REQ},
78 {"Betrag", 50, 11, REQ},
79 {"Zweck", 155, 27, REQ},
80 {"myName", 128, 27, OPT},
81 {"myKonto", 69, 10, OPT},
82 {"myBLZ", 61, 8, OPT},
83 {"Euro", 182, 1, IGN},
84 {"Text", 187, 29, OPT},
85 {"Extension", 216, 29, OPT},
105 dtaus_record recE[] = {
106 {"Anzahl", 10, 7, IGN},
107 {"Summe", 17, 13, IGN},
108 {"Kontos", 30, 17, IGN},
109 {"BLZs", 47, 17, IGN},
120 * Second: Some low level routines
123 size_t dtaus_nextrec (void **buf, FILE *f)
126 return fread(buf, 128, 1, f);
129 char *upcase(char *s)
135 for (cp=s,xp=x; *cp; cp++,xp++) {
136 if (strchr(" 0123456789.,&-/+*$%ABCDEFGHIJKLMNOPQRSTUVWXYZ",*cp)) {
138 } else if (strchr("abcdefghijklmnopqrstuvwxyz",*cp)) {
140 } else if (strchr ("üÜäÄöÖß", *cp)) {
142 case 'ü': *(xp++) = 'U'; *xp='E'; break;
143 case 'Ü': *(xp++) = 'U'; *xp='E'; break;
144 case 'ä': *(xp++) = 'A'; *xp='E'; break;
145 case 'Ä': *(xp++) = 'A'; *xp='E'; break;
146 case 'ö': *(xp++) = 'O'; *xp='E'; break;
147 case 'Ö': *(xp++) = 'O'; *xp='E'; break;
148 case 'ß': *(xp++) = 'S'; *xp='S'; break;
152 * Filter out all other characters since credit institutes won't
153 * accept the file otherwise.
162 char *downcase(char *s)
167 memset (x, 0, sizeof (x));
176 char *strip_spaces (char *s)
181 for (i=strlen(s);(s[i-1] == ' '||s[i-1] == '\t')&&i>0; i--)
183 for (p=s; *p==' '; p++);
187 char *strip_zeros (char *s)
191 for (p=s; *p=='0'; p++);
195 char *strip_nondigits (char *s)
208 char dtaus_char (void *buf, unsigned int pos)
214 memcpy(&res, bufp, 1);
218 char *string2real(char *s)
224 strncpy(res, s, strlen(s)-2);
225 res[strlen(s)-2] = '.';
226 res[strlen(s)-1] = s[strlen(s)-2];
227 res[strlen(s)] = s[strlen(s)-1];
231 char *real2string(char *s)
237 for (cp=res; *cp&&!(*cp == ',')&&!(*cp == '.');cp++);
244 char *string2trans (char *s)
249 if (!strcmp(s, "04000"))
250 sprintf (res, "Abbuchung");
251 else if (!strcmp(s, "05000"))
252 sprintf (res, "Einzug");
253 else if (!strcmp(s, "05005"))
254 sprintf (res, "E-Cash");
255 else if (!strcmp(s, "05006"))
256 sprintf (res, "E-Cash-A");
257 else if (!strcmp(s, "51000"))
258 sprintf (res, "Gutschrift");
259 else if (!strcmp(s, "53000"))
260 sprintf (res, "Lohn");
261 else if (!strncmp(s, "5400", 4))
262 sprintf (res, "Vermögen");
263 /* else if (!strcmp(s, "56000"))
264 sprintf (res, ""); / * Überweisung öffentlicher Kassen */
268 char *trans2string (char *s)
273 if (!strcmp(s, "Abbuchung"))
274 sprintf (res, "04000");
275 else if (!strcmp(s, "Einzug"))
276 sprintf (res, "05000");
277 else if (!strcmp(s, "E-Cash"))
278 sprintf (res, "05005");
279 else if (!strcmp(s, "E-Cash-A"))
280 sprintf (res, "05006");
281 else if (!strcmp(s, "Gutschrift"))
282 sprintf (res, "51000");
283 else if (!strcmp(s, "Lohn"))
284 sprintf (res, "53000");
285 else if (!strncmp(s, "Vermögen", 4))
286 sprintf (res, "5400");
287 /* else if (!strcmp(s, ""))
288 sprintf (res, "56000"); / * Überweisung öffentlicher Kassen */
292 char *string2ext (char *s)
297 if (!strcmp(s, "01"))
298 sprintf (res, "Kunde");
299 else if (!strcmp(s, "02"))
300 sprintf (res, "Text");
301 else if (!strcmp(s, "03"))
302 sprintf (res, "Auftraggeber");
306 char *ext2string (char *s)
311 if (!strcmp(s, "Kunde"))
313 else if (!strcmp(s, "Text"))
315 else if (!strcmp(s, "Auftraggeber"))
320 unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
324 static unsigned long int res;
327 memcpy(tmp, bufp, len);
329 sscanf(tmp, "%lu", &res);
334 * returns the first word in this line, returns it and shortens the
337 char *extract_ident (char *line)
340 static char word[30];
342 if (strlen(line) > 0) {
343 x = index (line, ' ');
344 y = index (line, '\t');
347 strncpy(word, line, 29);
352 /* Check which index returns the lower value, and check if the
354 if ((c = (x && x<y)?x:(y?y:x))) {
355 strncpy(word, line, c - line);
357 for (;*c == '\t' || *c == ' '; c++);
358 for (x=line; *c; c++,x++)
361 strcpy(word, downcase(word));
370 * Pads a string with zero's on the left side.
372 char *padzeroclip (char *s, int len)
376 if (strlen(s) == len) return s;
377 if (strlen(s) > len) {
385 for (p=s+strlen(s)-1;p>=s;p--)
387 for (;q>=s;) *(q--)='0';
391 int rec_index(char *ident, int type)
394 dtaus_record *rec = NULL;
397 case REC_A: rec = recA; break;
398 case REC_C: rec = recC; break;
399 case REC_E: rec = recE; break;
402 for (i=0; (rec[i].name); i++) {
403 if (!strcmp(ident, downcase(rec[i].name)))
410 size_t control_nextline (void **buf, int len, FILE *f)
417 bzero (line, sizeof(line));
421 while (!strlen(line) && (cp = fgets(line, 100, f))) {
423 if (line[0] != '#') {
424 if (line[strlen(line)-1] != '\n') {
426 while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
428 line[strlen(line)-1] = '\0';
429 if (line[strlen(line)-1] == '
\r')
430 line[strlen(line)-1] = '\0';
431 for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
439 for (cp=line; *cp==' '; cp++);
442 memcpy(buf, cp, strlen(cp));
454 timer = time ( NULL );
455 loctime = localtime(&timer);
456 sprintf(res, "%02d.%02d.%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
461 * Prepare a record A according to the specs.
462 * See dtaus.txt for explanation
464 void dtaus_prepareA (char *buf)
472 timer = time ( NULL );
473 loctime = localtime(&timer);
480 for (i=15;i<15+8; i++) buf[i] = '0'; /* A5 */
481 sprintf(tmp, "%02d%02d%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
482 for (i=0; i<6; i++) buf[50+i] = tmp[i]; /* A7 (Date) */
483 for (i=56;i<56+4; i++) buf[i] = ' '; /* A8 */
484 for (i=70;i<70+10; i++) buf[i] = '0'; /* A10 */
485 for (i=80;i<80+48; i++) buf[i] = ' '; /* A11 */
487 buf[127] = '1'; /* A12 (Currency) */
489 buf[127] = ' '; /* A12 (Currency) */
494 * Prepare a record C according to the specs.
495 * See dtaus.txt for explanation
497 void dtaus_prepareC (char *buf, int normaltext, int maxtext)
509 res = div (maxtext-1, 4);
510 appendix += res.quot;
511 if (res.rem) appendix++;
513 i = 187 + (appendix * 29);
515 /* Bail out if the number is too large, shouldn't be possible though */
519 buf[1] = (i/100)+48;i-=(i/100)*100;
520 buf[2] = (i/10)+48;i-=(i/10)*10;
524 for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */
525 buf[49] = ' '; /* C8 */
526 for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */
527 for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Euro) */
528 for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */
529 for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */
530 for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */
532 buf[182] = '1'; /* C17a (Currency) */
534 buf[182] = ' '; /* C17a (Currency) */
536 for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */
537 for (i=185;i<185+2; i++) buf[i] = '0'; /* C18 (#Extension) */
538 for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */
539 for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */
543 * Prepare a record E according to the specs.
544 * See dtaus.txt for explanation
546 void dtaus_prepareE (char *buf)
556 for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */
557 for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */
558 for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */
559 for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */
562 int dtaus_writeA(FILE *f, char **values)
568 for (i=0; (recA[i].name); i++)
569 if ((recA[i].type == REQ) && !values[i]) {
570 fprintf (stderr, "Anfangsdatensatz ist nicht vollständig, kein %s.\n", recA[i].name);
573 if (!(((values[A_TRANS][0] == 'L')||(values[A_TRANS][0] == 'G'))
574 &&((values[A_TRANS][1] == 'B')||(values[A_TRANS][1] == 'K')))) {
575 fprintf (stderr, "Ungültiger Typ, nur LK, GK, LB oder GB erlaubt.\n");
579 i=A_NAME;if (values[i] && strlen(values[i]) > recA[i].len)
580 values[i][recA[i].len] = '\0';
583 buf[5] = values[A_TRANS][0];
584 buf[6] = values[A_TRANS][1];
585 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),8));
586 for (i=0; i<8; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
587 sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
588 for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
589 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),10));
590 for (i=0; i<10; i++) buf[recA[A_KTO].pos+i] = tmp[i];
596 int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
607 for (maxtext=0;text[maxtext];maxtext++);
610 for (i=0; (recC[i].name); i++)
612 printf ("%s: %s\n", recC[i].name, values[i]);
615 for (i=0; (recC[i].name); i++)
616 if ((recC[i].type == REQ) && !values[i]) {
617 fprintf (stderr, "Datensatz ist nicht vollständig, kein %s.\n", recC[i].name);
620 sprintf (tmp, "%s", trans2string(values[C_TRANS]));
622 fprintf (stderr, "Ungültiger Typ, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
626 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
627 values[i][recC[i].len] = '\0';
628 i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
629 values[i][recC[i].len] = '\0';
630 i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
631 values[i][recC[i].len] = '\0';
632 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
633 values[i][recC[i].len] = '\0';
634 i=C_EXT;if (values[i] && strlen(values[i]) > recC[i].len)
635 values[i][recC[i].len] = '\0';
637 dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
638 for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
640 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8));
642 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_BLZ]),8));
643 for (i=0; i<recC[C_MYBLZ].len; i++) buf[5+i] = tmp[i];
644 for (i=0; i<recC[C_MYBLZ].len; i++) buf[recC[C_MYBLZ].pos+i] = tmp[i];
645 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_BLZ]),8));
646 for (i=0; i<recC[C_BLZ].len; i++) buf[recC[C_BLZ].pos+i] = tmp[i];
647 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
648 for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
649 sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
650 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
652 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
654 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_KTO]),10));
655 for (i=0; i<recC[C_MYKTO].len; i++) buf[recC[C_MYKTO].pos+i] = tmp[i];
656 sprintf (tmp, "%-27.27s", upcase(values[C_NAME]));
657 for (i=0; i<recC[C_NAME].len; i++) buf[recC[C_NAME].pos+i] = tmp[i];
659 sprintf (tmp, "%-27.27s", upcase(values[C_MYNAM]));
661 sprintf (tmp, "%-27.27s", upcase(valuesA[A_NAME]));
662 for (i=0; i<recC[C_MYNAM].len; i++) buf[recC[C_MYNAM].pos+i] = tmp[i];
663 sprintf (tmp, "%-27.27s", upcase(values[C_ZWECK]));
664 for (i=0; i<recC[C_ZWECK].len; i++) buf[recC[C_ZWECK].pos+i] = tmp[i];
666 if (values[C_TEXT]) {
667 buf[recC[C_TEXT].pos+0] = '0';
668 buf[recC[C_TEXT].pos+1] = '2';
669 sprintf (tmp, "%-27.27s", upcase(values[C_TEXT]));
670 for (i=0; i<recC[C_TEXT].len-2; i++) buf[recC[C_TEXT].pos+2+i] = tmp[i];
674 buf[recC[C_EXT].pos+0] = '0';
675 buf[recC[C_EXT].pos+1] = '2';
676 sprintf (tmp, "%-27.27s", upcase(text[0]));
677 for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
679 res = div (maxtext-1, 4);
683 buf[185+0] = (i/10)+48;i-=(i/10)*10;
689 if (text && maxtext > 1) {
691 while (fieldnr<maxtext) {
692 memset (appendix, ' ', 128);
693 appendix[128] = '\0';
694 for (k=0; k<4 && (fieldnr+k)<maxtext; k++) {
695 sprintf (tmp, "%-27.27s", upcase(text[fieldnr+k]));
696 appendix[k*29] = '0';
697 appendix[(k*29)+1] = '2';
698 for (i=0; i<recC[C_TEXT].len-2; i++) appendix[(k*29)+2+i] = tmp[i];
708 int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
716 sprintf (tmp, "%07d", count);
717 for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
718 bigint_sprintf (tmp, "%s", sum);
719 padzeroclip (tmp,13);
720 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
721 bigint_sprintf (tmp, "%s", sum);
722 padzeroclip (tmp,13);
723 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
724 bigint_sprintf (tmp, "%s", kto);
725 padzeroclip (tmp,17);
726 for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
727 bigint_sprintf (tmp, "%s", blz);
728 padzeroclip (tmp,17);
729 for (i=0; i<recE[E_BLZ].len; i++) buf[recE[E_BLZ].pos+i] = tmp[i];
735 void printctln(FILE *f, char *field, char *value)
737 if (strlen(field) && strlen(value))
738 fprintf(f, " %s\t%s\n", field, value);
743 * Third: Some high level routines
746 void dtaus2control (char *cdtaus, char *ccontrol)
748 FILE *fdtaus, *fcontrol;
757 if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
758 if (!(fdtaus = fopen("dtaus0.txt", "r")))
761 if (!strcmp (cdtaus, "-"))
764 if (!(fdtaus = fopen(cdtaus, "r")))
770 if (!strcmp (ccontrol, "-"))
773 if (!(fcontrol = fopen(ccontrol, "w")))
775 if (!(buf = (char *)malloc (512)))
781 if (dtaus_nextrec(buf, fdtaus) == 1) {
782 if (dtaus_char(buf,4) == 'A') {
783 fprintf(fcontrol, "BEGIN {\n");
786 for (index=A_TRANS; index < A_DATE; index++) {
787 bufp = buf + recA[index].pos;
788 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
789 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
792 index = A_DATE; bufp = buf + recA[index].pos;
793 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
794 printctln(fcontrol, recA[index].name, strip_spaces(tmp));
796 index = A_EURO; bufp = buf + recA[index].pos;
797 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
798 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
800 fprintf(fcontrol, "}\n\n");
802 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz an.\n");
806 fprintf (stderr, "Der Anfangsdatensatz ist kaputt.\n");
813 if (dtaus_nextrec(buf, fdtaus) == 1) {
814 while (dtaus_char(buf,4) == 'C') {
816 if (dtaus_nextrec(bufp, fdtaus) != 1) {
817 fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
820 fprintf(fcontrol, "{\n");
822 for (index=C_NAME; index <= C_EURO; index++) {
823 bufp = buf + recC[index].pos;
824 memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
826 printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
827 else if (index == C_TRANS)
828 printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
830 printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
833 for (index=C_TEXT; index <= C_EXT; index++) {
834 if (!(dtaus_char(buf,recC[index].pos) == ' ')) {
835 bufp = buf + recC[index].pos;
836 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
837 memcpy(tmp, bufp, recC[index].len-2); tmp[recC[index].len-2] = '\0';
838 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
842 /* Number of extension records for this C record */
843 extC = dtaus_int(buf, 185, 2);
846 if (dtaus_nextrec(buf, fdtaus) != 1)
847 bzero (buf, sizeof(buf));
850 * Are there extension records that we have to check?
852 * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
853 * instead of 00 we should let it in so it can read its own
854 * old files... *sigh*
856 while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') {
857 for (index=0; index < 4; index++) {
858 if ((dtaus_char(buf,index*29) != ' ')) {
859 bufp = buf + index*29;
860 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
861 memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
862 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
865 if (dtaus_nextrec(buf, fdtaus) != 1)
866 bzero (buf, sizeof(buf));
869 fprintf(fcontrol, "}\n");
875 * (gelesen ist er eigentlich schon...)
877 if (dtaus_char(buf,4) == 'E') {
878 if (dtaus_char(buf,4) == 'E') {
879 fprintf(fcontrol, "\nEND {\n");
881 for (index=E_COUNT; index <= E_BLZ; index++) {
882 bufp = buf + recE[index].pos;
883 memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
885 printctln(fcontrol, recE[index].name, strip_zeros(string2real(tmp)));
887 printctln(fcontrol, recE[index].name, strip_zeros(tmp));
890 fprintf(fcontrol, "}\n");
892 fprintf (stderr, "Das ist kein Abschlußdatensatz.\n");
896 fprintf (stderr, "Der Abschlußdatensatz ist leer oder kaputt.\n");
903 int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
905 FILE *fdtaus, *fcontrol, *fbeleg, *fcheck;
911 char *valA[A_LEN], *valC[C_LEN];
913 bigint sum_val, sum_blz, sum_kto, bi;
919 if (!(fdtaus = fopen("dtaus0.txt", "w")))
922 if (!strcmp (cdtaus, "-"))
925 if (!(fdtaus = fopen(cdtaus, "w")))
929 if (!(fcontrol = fopen("dtaus0.ctl", "r")))
930 if (!(fcontrol = fopen("DTAUS0.CTL", "r")))
933 if (!strcmp (ccontrol, "-"))
936 if (!(fcontrol = fopen(ccontrol, "r")))
940 if (!(fbeleg = fopen("dtaus0.doc", "w")))
943 if (!(fbeleg = fopen(cbeleg, "w")))
949 if (!(fcheck = fopen(ccheck, "w")))
953 if (!(buf = (char *)malloc (512)))
959 bzero(valA, sizeof(valA));
960 control_nextline ((void *)line, 100, fcontrol);
961 ident = extract_ident(line);
962 if (!strcmp(ident, "begin") && (line[0] == '{')) {
963 control_nextline ((void *)line, 100, fcontrol);
964 while (strlen(line) && line[0] != '}') {
965 ident = extract_ident(line);
966 if ((recindex = rec_index(ident, REC_A)) != -1)
967 if (recA[recindex].type != IGN)
968 if ((valA[recindex] = (char *)malloc (strlen(line)+1)))
969 strcpy(valA[recindex], line);
970 control_nextline ((void *)line, 100, fcontrol);
972 if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
973 fprintf(fbeleg, "\n\n");
974 fprintf(fbeleg, "\n Begleitzettel\n\n");
975 fprintf(fbeleg, "\n Belegloser Datentraegeraustausch\n\n");
976 if (valA[recindex][0] == 'L')
977 fprintf(fbeleg, "\n Sammeleinziehungsauftrag\n\n");
978 else if (valA[recindex][0] == 'G')
979 fprintf(fbeleg, "\n Sammelueberweisungsauftrag\n\n");
981 fprintf(fbeleg, "\n Sammelauftrag\n\n");
982 fprintf(fbeleg, "\n VOL ........................:\n");
983 fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date());
984 fprintf(fbeleg, "\n Waehrung ...................: DM\n");
986 if (!dtaus_writeA(fdtaus, valA)) {
987 fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
991 fprintf (fcheck, "\n\n\n");
992 if (valA[recindex][0] == 'L')
993 fprintf (fcheck, " Sammeleinziehungsauftrag\n\n");
994 else if (valA[recindex][0] == 'G')
995 fprintf (fcheck, " Sammelueberweisungsauftrag\n\n");
997 fprintf (fcheck, " Sammelauftrag\n\n");
998 fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date());
999 fprintf (fcheck, " Waehrung : DM\n\n\n");
1000 fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
1001 fprintf (fcheck, " --------------------------------------------------------------------\n");
1003 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz (BEGIN) an.\n");
1011 sum_val = bigint_int(0);
1012 sum_blz = bigint_int(0);
1013 sum_kto = bigint_int(0);
1014 bzero(valC, sizeof(valC));
1015 control_nextline ((void *)line, 100, fcontrol);
1016 if (line[0] == '{') {
1017 while (strlen(line) && line[0] == '{') {
1018 control_nextline ((void *)line, 100, fcontrol);
1020 for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++)
1021 free (text[textindex]);
1025 while (strlen(line) && line[0] != '}') {
1026 ident = extract_ident(line);
1027 if ((recindex = rec_index(ident, REC_C)) != -1)
1028 if (recC[recindex].type != IGN) {
1030 * Special exception to support multiple Text fields
1032 if (recindex == C_TEXT && valC[recindex]) {
1034 if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL)
1038 memset (text, 0, (MAX_TEXT+1) * sizeof (char *));
1041 if (textindex < MAX_TEXT) {
1042 if ((cp = (char *)malloc (strlen (line) + 1))) {
1044 cp[strlen (line)] = '\0';
1045 text[textindex++] = cp;
1049 if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
1050 strcpy(valC[recindex], line);
1055 control_nextline ((void *)line, 100, fcontrol);
1057 if (!dtaus_writeC(fdtaus, valA, valC, text)) {
1058 fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n");
1062 bi = bigint_string(real2string(valC[C_VAL])); sum_val = bigint_add(sum_val, bi);
1063 bi = bigint_string(valC[C_BLZ]); sum_blz = bigint_add(sum_blz, bi);
1064 bi = bigint_string(valC[C_KTO]); sum_kto = bigint_add(sum_kto, bi);
1066 fprintf (fcheck, " %10s %8s %-30s %12s\n", valC[C_KTO], valC[C_BLZ], valC[C_NAME], valC[C_VAL]);
1067 for (recindex=0; recindex<C_LEN; recindex++)
1069 free(valC[recindex]);
1070 bzero(valC, sizeof(valC));
1071 control_nextline ((void *)line, 100, fcontrol);
1074 fprintf (stderr, "Kein regulärer Datensatz?\n");
1081 dtaus_writeE(fdtaus, count, sum_val, sum_blz, sum_kto);
1082 fprintf (fcheck, " --------------------------------------------------------------------\n");
1083 bigint_sprintf (tmp, "%s", sum_val);
1084 fprintf (fbeleg, "\n Anzahl .....................: %d\n", count);
1085 recindex=strlen(tmp);
1086 tmp[recindex+1] = '\0';
1087 tmp[recindex] = tmp[recindex-1];
1088 tmp[recindex-1] = tmp[recindex-2];
1089 tmp[recindex-2] = '.';
1090 fprintf (fcheck, " %-52s %14s\n", "Summe", tmp);
1091 fprintf (fbeleg, "\n Summe ......................: %s\n", tmp);
1092 bigint_sprintf (tmp, "%s", sum_kto);
1093 fprintf (fbeleg, "\n Kontrollsumme Kontonummern .: %s\n", tmp);
1094 bigint_sprintf (tmp, "%s", sum_blz);
1095 fprintf (fbeleg, "\n Kontrollsumme Bankleitzahlen: %s\n", tmp);
1096 fprintf (fbeleg, "\n Unsere Kontonummer .........: %s\n", valA[A_KTO]);
1097 fprintf (fbeleg, "\n Unsere Bankleitzahl ........: %s\n", valA[A_BLZ]);
1098 fprintf (fbeleg, "\n\n\n\n\n __________________________________________________\n");
1099 fprintf (fbeleg, " Ort, Datum Unterschrift\n");
1100 for (recindex=0; recindex<A_LEN; recindex++)
1102 free(valA[recindex]);