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.
32 * First: Some control structures
38 unsigned short int pos;
39 unsigned short int len;
51 dtaus_record recA[] = {
53 {"Name", 23, 27, REQ},
54 {"Konto", 60, 10, REQ},
56 {"Referenz", 70, 10, OPT},
57 {"Datum", 50, 6, IGN},
58 {"Euro", 127, 1, OPT},
71 dtaus_record recC[] = {
72 {"Name", 93, 27, REQ},
73 {"Konto", 21, 10, REQ},
75 {"Transaktion", 44, 5, REQ},
76 {"Betrag", 50, 11, REQ},
77 {"Zweck", 155, 27, REQ},
78 {"myName", 128, 27, OPT},
79 {"myKonto", 69, 10, OPT},
80 {"myBLZ", 61, 8, OPT},
81 {"Euro", 182, 1, IGN},
82 {"Text", 187, 29, OPT},
83 {"Extension", 216, 29, OPT},
103 dtaus_record recE[] = {
104 {"Anzahl", 10, 7, IGN},
105 {"Summe", 17, 13, IGN},
106 {"Kontos", 30, 17, IGN},
107 {"BLZs", 47, 17, IGN},
118 * Second: Some low level routines
121 size_t dtaus_nextrec (void **buf, FILE *f)
124 return fread(buf, 128, 1, f);
127 char *upcase(char *s)
133 for (cp=s,xp=x; *cp; cp++,xp++) {
134 if (strchr(" 0123456789.,&-/+*$%ABCDEFGHIJKLMNOPQRSTUVWXYZ",*cp)) {
136 } else if (strchr("abcdefghijklmnopqrstuvwxyz",*cp)) {
138 } else if (strchr ("üÜäÄöÖß", *cp)) {
140 case 'ü': *(xp++) = 'U'; *xp='E'; break;
141 case 'Ü': *(xp++) = 'U'; *xp='E'; break;
142 case 'ä': *(xp++) = 'A'; *xp='E'; break;
143 case 'Ä': *(xp++) = 'A'; *xp='E'; break;
144 case 'ö': *(xp++) = 'O'; *xp='E'; break;
145 case 'Ö': *(xp++) = 'O'; *xp='E'; break;
146 case 'ß': *(xp++) = 'S'; *xp='S'; break;
150 * Filter out all other characters since credit institutes won't
151 * accept the file otherwise.
160 char *downcase(char *s)
165 memset (x, 0, sizeof (x));
174 char *strip_spaces (char *s)
179 for (i=strlen(s);(s[i-1] == ' '||s[i-1] == '\t')&&i>0; i--)
181 for (p=s; *p==' '; p++);
185 char *strip_zeros (char *s)
189 for (p=s; *p=='0'; p++);
193 char *strip_nondigits (char *s)
206 char dtaus_char (void *buf, unsigned int pos)
212 memcpy(&res, bufp, 1);
216 char *string2real(char *s)
222 strncpy(res, s, strlen(s)-2);
223 res[strlen(s)-2] = '.';
224 res[strlen(s)-1] = s[strlen(s)-2];
225 res[strlen(s)] = s[strlen(s)-1];
229 char *real2string(char *s)
235 for (cp=res; *cp&&!(*cp == ',')&&!(*cp == '.');cp++);
242 char *string2trans (char *s)
247 if (!strcmp(s, "04000"))
248 sprintf (res, "Abbuchung");
249 else if (!strcmp(s, "05000"))
250 sprintf (res, "Einzug");
251 else if (!strcmp(s, "05005"))
252 sprintf (res, "E-Cash");
253 else if (!strcmp(s, "05006"))
254 sprintf (res, "E-Cash-A");
255 else if (!strcmp(s, "51000"))
256 sprintf (res, "Gutschrift");
257 else if (!strcmp(s, "53000"))
258 sprintf (res, "Lohn");
259 else if (!strncmp(s, "5400", 4))
260 sprintf (res, "Vermögen");
261 /* else if (!strcmp(s, "56000"))
262 sprintf (res, ""); / * Überweisung öffentlicher Kassen */
266 char *trans2string (char *s)
271 if (!strcmp(s, "Abbuchung"))
272 sprintf (res, "04000");
273 else if (!strcmp(s, "Einzug"))
274 sprintf (res, "05000");
275 else if (!strcmp(s, "E-Cash"))
276 sprintf (res, "05005");
277 else if (!strcmp(s, "E-Cash-A"))
278 sprintf (res, "05006");
279 else if (!strcmp(s, "Gutschrift"))
280 sprintf (res, "51000");
281 else if (!strcmp(s, "Lohn"))
282 sprintf (res, "53000");
283 else if (!strncmp(s, "Vermögen", 4))
284 sprintf (res, "5400");
285 /* else if (!strcmp(s, ""))
286 sprintf (res, "56000"); / * Überweisung öffentlicher Kassen */
290 char *string2ext (char *s)
295 if (!strcmp(s, "01"))
296 sprintf (res, "Kunde");
297 else if (!strcmp(s, "02"))
298 sprintf (res, "Text");
299 else if (!strcmp(s, "03"))
300 sprintf (res, "Auftraggeber");
304 char *ext2string (char *s)
309 if (!strcmp(s, "Kunde"))
311 else if (!strcmp(s, "Text"))
313 else if (!strcmp(s, "Auftraggeber"))
318 unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
322 static unsigned long int res;
325 memcpy(tmp, bufp, len);
327 sscanf(tmp, "%lu", &res);
332 * returns the first word in this line, returns it and shortens the
335 char *extract_ident (char *line)
338 static char word[30];
340 if (strlen(line) > 0) {
341 x = index (line, ' ');
342 y = index (line, '\t');
345 strncpy(word, line, 29);
350 /* Check which index returns the lower value, and check if the
352 if ((c = (x && x<y)?x:(y?y:x))) {
353 strncpy(word, line, c - line);
355 for (;*c == '\t' || *c == ' '; c++);
356 for (x=line; *c; c++,x++)
359 strcpy(word, downcase(word));
368 * Pads a string with zero's on the left side.
370 char *padzeroclip (char *s, int len)
374 if (strlen(s) == len) return s;
375 if (strlen(s) > len) {
383 for (p=s+strlen(s)-1;p>=s;p--)
385 for (;q>=s;) *(q--)='0';
389 int rec_index(char *ident, int type)
392 dtaus_record *rec = NULL;
395 case REC_A: rec = recA; break;
396 case REC_C: rec = recC; break;
397 case REC_E: rec = recE; break;
400 for (i=0; (rec[i].name); i++) {
401 if (!strcmp(ident, downcase(rec[i].name)))
408 size_t control_nextline (void **buf, int len, FILE *f)
415 bzero (line, sizeof(line));
419 while (!strlen(line) && (cp = fgets(line, 100, f))) {
421 if (line[0] != '#') {
422 if (line[strlen(line)-1] != '\n') {
424 while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
426 line[strlen(line)-1] = '\0';
427 if (line[strlen(line)-1] == '
\r')
428 line[strlen(line)-1] = '\0';
429 for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
437 for (cp=line; *cp==' '; cp++);
440 memcpy(buf, cp, strlen(cp));
452 timer = time ( NULL );
453 loctime = localtime(&timer);
454 sprintf(res, "%02d.%02d.%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
459 * Prepare a record A according to the specs.
460 * See dtaus.txt for explanation
462 void dtaus_prepareA (char *buf)
470 timer = time ( NULL );
471 loctime = localtime(&timer);
478 for (i=15;i<15+8; i++) buf[i] = '0'; /* A5 */
479 sprintf(tmp, "%02d%02d%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
480 for (i=0; i<6; i++) buf[50+i] = tmp[i]; /* A7 (Date) */
481 for (i=56;i<56+4; i++) buf[i] = ' '; /* A8 */
482 for (i=70;i<70+10; i++) buf[i] = '0'; /* A10 */
483 for (i=80;i<80+48; i++) buf[i] = ' '; /* A11 */
484 buf[127] = ' '; /* A12 (Currency) */
488 * Prepare a record C according to the specs.
489 * See dtaus.txt for explanation
491 void dtaus_prepareC (char *buf, int normaltext, int maxtext)
503 res = div (maxtext-1, 4);
504 appendix += res.quot;
505 if (res.rem) appendix++;
507 i = 187 + (appendix * 29);
509 /* Bail out if the number is too large, shouldn't be possible though */
513 buf[1] = (i/100)+48;i-=(i/100)*100;
514 buf[2] = (i/10)+48;i-=(i/10)*10;
518 for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */
519 buf[49] = ' '; /* C8 */
520 for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */
521 for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Euro) */
522 for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */
523 for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */
524 for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */
525 buf[182] = ' '; /* C17a (Currency) */
526 for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */
527 for (i=185;i<185+2; i++) buf[i] = '0'; /* C18 (#Extension) */
528 for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */
529 for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */
533 * Prepare a record E according to the specs.
534 * See dtaus.txt for explanation
536 void dtaus_prepareE (char *buf)
546 for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */
547 for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */
548 for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */
549 for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */
552 int dtaus_writeA(FILE *f, char **values)
558 for (i=0; (recA[i].name); i++)
559 if ((recA[i].type == REQ) && !values[i]) {
560 fprintf (stderr, "Anfangsdatensatz ist nicht vollständig, kein %s.\n", recA[i].name);
563 if (!(((values[A_TRANS][0] == 'L')||(values[A_TRANS][0] == 'G'))
564 &&((values[A_TRANS][1] == 'B')||(values[A_TRANS][1] == 'K')))) {
565 fprintf (stderr, "Ungültiger Typ, nur LK, GK, LB oder GB erlaubt.\n");
569 i=A_NAME;if (values[i] && strlen(values[i]) > recA[i].len)
570 values[i][recA[i].len] = '\0';
573 buf[5] = values[A_TRANS][0];
574 buf[6] = values[A_TRANS][1];
575 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),8));
576 for (i=0; i<8; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
577 sprintf (tmp, "%-27s", upcase(values[A_NAME]));
578 for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
579 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),10));
580 for (i=0; i<10; i++) buf[recA[A_KTO].pos+i] = tmp[i];
586 int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
597 for (maxtext=0;text[maxtext];maxtext++);
600 for (i=0; (recC[i].name); i++)
602 printf ("%s: %s\n", recC[i].name, values[i]);
605 for (i=0; (recC[i].name); i++)
606 if ((recC[i].type == REQ) && !values[i]) {
607 fprintf (stderr, "Datensatz ist nicht vollständig, kein %s.\n", recC[i].name);
610 sprintf (tmp, "%s", trans2string(values[C_TRANS]));
612 fprintf (stderr, "Ungültiger Typ, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
616 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
617 values[i][recC[i].len] = '\0';
618 i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
619 values[i][recC[i].len] = '\0';
620 i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
621 values[i][recC[i].len] = '\0';
622 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
623 values[i][recC[i].len] = '\0';
624 i=C_EXT;if (values[i] && strlen(values[i]) > recC[i].len)
625 values[i][recC[i].len] = '\0';
627 dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
628 for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
630 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8));
632 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_BLZ]),8));
633 for (i=0; i<recC[C_MYBLZ].len; i++) buf[5+i] = tmp[i];
634 for (i=0; i<recC[C_MYBLZ].len; i++) buf[recC[C_MYBLZ].pos+i] = tmp[i];
635 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_BLZ]),8));
636 for (i=0; i<recC[C_BLZ].len; i++) buf[recC[C_BLZ].pos+i] = tmp[i];
637 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
638 for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
639 sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
640 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
642 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
644 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_KTO]),10));
645 for (i=0; i<recC[C_MYKTO].len; i++) buf[recC[C_MYKTO].pos+i] = tmp[i];
646 sprintf (tmp, "%-27s", upcase(values[C_NAME]));
647 for (i=0; i<recC[C_NAME].len; i++) buf[recC[C_NAME].pos+i] = tmp[i];
649 sprintf (tmp, "%-27s", upcase(values[C_MYNAM]));
651 sprintf (tmp, "%-27s", upcase(valuesA[A_NAME]));
652 for (i=0; i<recC[C_MYNAM].len; i++) buf[recC[C_MYNAM].pos+i] = tmp[i];
653 sprintf (tmp, "%-27s", upcase(values[C_ZWECK]));
654 for (i=0; i<recC[C_ZWECK].len; i++) buf[recC[C_ZWECK].pos+i] = tmp[i];
656 if (values[C_TEXT]) {
657 buf[recC[C_TEXT].pos+0] = '0';
658 buf[recC[C_TEXT].pos+1] = '2';
659 sprintf (tmp, "%-27s", upcase(values[C_TEXT]));
660 for (i=0; i<recC[C_TEXT].len-2; i++) buf[recC[C_TEXT].pos+2+i] = tmp[i];
664 buf[recC[C_EXT].pos+0] = '0';
665 buf[recC[C_EXT].pos+1] = '2';
666 sprintf (tmp, "%-27s", upcase(text[0]));
667 for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
669 res = div (maxtext-1, 4);
673 buf[185+0] = (i/10)+48;i-=(i/10)*10;
679 if (text && maxtext > 1) {
681 while (fieldnr<maxtext) {
682 memset (appendix, ' ', 128);
683 appendix[128] = '\0';
684 for (k=0; k<4 && (fieldnr+k)<maxtext; k++) {
685 sprintf (tmp, "%-27s", upcase(text[fieldnr+k]));
686 appendix[k*29] = '0';
687 appendix[(k*29)+1] = '2';
688 for (i=0; i<recC[C_TEXT].len-2; i++) appendix[(k*29)+2+i] = tmp[i];
698 int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
706 sprintf (tmp, "%07d", count);
707 for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
708 bigint_sprintf (tmp, "%s", sum);
709 padzeroclip (tmp,13);
710 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
711 bigint_sprintf (tmp, "%s", sum);
712 padzeroclip (tmp,13);
713 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
714 bigint_sprintf (tmp, "%s", kto);
715 padzeroclip (tmp,17);
716 for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
717 bigint_sprintf (tmp, "%s", blz);
718 padzeroclip (tmp,17);
719 for (i=0; i<recE[E_BLZ].len; i++) buf[recE[E_BLZ].pos+i] = tmp[i];
725 void printctln(FILE *f, char *field, char *value)
727 if (strlen(field) && strlen(value))
728 fprintf(f, " %s\t%s\n", field, value);
733 * Third: Some high level routines
736 void dtaus2control (char *cdtaus, char *ccontrol)
738 FILE *fdtaus, *fcontrol;
747 if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
748 if (!(fdtaus = fopen("dtaus0.txt", "r")))
751 if (!strcmp (cdtaus, "-"))
754 if (!(fdtaus = fopen(cdtaus, "r")))
760 if (!strcmp (ccontrol, "-"))
763 if (!(fcontrol = fopen(ccontrol, "w")))
765 if (!(buf = (char *)malloc (512)))
771 if (dtaus_nextrec(buf, fdtaus) == 1) {
772 if (dtaus_char(buf,4) == 'A') {
773 fprintf(fcontrol, "BEGIN {\n");
776 for (index=A_TRANS; index < A_DATE; index++) {
777 bufp = buf + recA[index].pos;
778 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
779 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
782 index = A_DATE; bufp = buf + recA[index].pos;
783 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
784 printctln(fcontrol, recA[index].name, strip_spaces(tmp));
786 index = A_EURO; bufp = buf + recA[index].pos;
787 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
788 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
790 fprintf(fcontrol, "}\n\n");
792 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz an.\n");
796 fprintf (stderr, "Der Anfangsdatensatz ist kaputt.\n");
803 if (dtaus_nextrec(buf, fdtaus) == 1) {
804 while (dtaus_char(buf,4) == 'C') {
806 if (dtaus_nextrec(bufp, fdtaus) != 1) {
807 fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
810 fprintf(fcontrol, "{\n");
812 for (index=C_NAME; index <= C_EURO; index++) {
813 bufp = buf + recC[index].pos;
814 memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
816 printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
817 else if (index == C_TRANS)
818 printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
820 printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
823 for (index=C_TEXT; index <= C_EXT; index++) {
824 if (!(dtaus_char(buf,recC[index].pos) == ' ')) {
825 bufp = buf + recC[index].pos;
826 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
827 memcpy(tmp, bufp, recC[index].len-2); tmp[recC[index].len-2] = '\0';
828 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
832 /* Number of extension records for this C record */
833 extC = dtaus_int(buf, 185, 2);
836 if (dtaus_nextrec(buf, fdtaus) != 1)
837 bzero (buf, sizeof(buf));
840 * Are there extension records that we have to check?
842 * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
843 * instead of 00 we should let it in so it can read its own
844 * old files... *sigh*
846 while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') {
847 for (index=0; index < 4; index++) {
848 if ((dtaus_char(buf,index*29) != ' ')) {
849 bufp = buf + index*29;
850 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
851 memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
852 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
855 if (dtaus_nextrec(buf, fdtaus) != 1)
856 bzero (buf, sizeof(buf));
859 fprintf(fcontrol, "}\n");
865 * (gelesen ist er eigentlich schon...)
867 if (dtaus_char(buf,4) == 'E') {
868 if (dtaus_char(buf,4) == 'E') {
869 fprintf(fcontrol, "\nEND {\n");
871 for (index=E_COUNT; index <= E_BLZ; index++) {
872 bufp = buf + recE[index].pos;
873 memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
875 printctln(fcontrol, recE[index].name, strip_zeros(string2real(tmp)));
877 printctln(fcontrol, recE[index].name, strip_zeros(tmp));
880 fprintf(fcontrol, "}\n");
882 fprintf (stderr, "Das ist kein Abschlußdatensatz.\n");
886 fprintf (stderr, "Der Abschlußdatensatz ist leer oder kaputt.\n");
893 int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
895 FILE *fdtaus, *fcontrol, *fbeleg, *fcheck;
901 char *valA[A_LEN], *valC[C_LEN];
903 bigint sum_val, sum_blz, sum_kto, bi;
909 if (!(fdtaus = fopen("dtaus0.txt", "w")))
912 if (!strcmp (cdtaus, "-"))
915 if (!(fdtaus = fopen(cdtaus, "w")))
919 if (!(fcontrol = fopen("dtaus0.ctl", "r")))
920 if (!(fcontrol = fopen("DTAUS0.CTL", "r")))
923 if (!strcmp (ccontrol, "-"))
926 if (!(fcontrol = fopen(ccontrol, "r")))
930 if (!(fbeleg = fopen("dtaus0.doc", "w")))
933 if (!(fbeleg = fopen(cbeleg, "w")))
939 if (!(fcheck = fopen(ccheck, "w")))
943 if (!(buf = (char *)malloc (512)))
949 bzero(valA, sizeof(valA));
950 control_nextline ((void *)line, 100, fcontrol);
951 ident = extract_ident(line);
952 if (!strcmp(ident, "begin") && (line[0] == '{')) {
953 control_nextline ((void *)line, 100, fcontrol);
954 while (strlen(line) && line[0] != '}') {
955 ident = extract_ident(line);
956 if ((recindex = rec_index(ident, REC_A)) != -1)
957 if (recA[recindex].type != IGN)
958 if ((valA[recindex] = (char *)malloc (strlen(line)+1)))
959 strcpy(valA[recindex], line);
960 control_nextline ((void *)line, 100, fcontrol);
962 if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
963 fprintf(fbeleg, "\n\n");
964 fprintf(fbeleg, "\n Begleitzettel\n\n");
965 fprintf(fbeleg, "\n Belegloser Datentraegeraustausch\n\n");
966 if (valA[recindex][0] == 'L')
967 fprintf(fbeleg, "\n Sammeleinziehungsauftrag\n\n");
968 else if (valA[recindex][0] == 'G')
969 fprintf(fbeleg, "\n Sammelueberweisungsauftrag\n\n");
971 fprintf(fbeleg, "\n Sammelauftrag\n\n");
972 fprintf(fbeleg, "\n VOL ........................:\n");
973 fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date());
974 fprintf(fbeleg, "\n Waehrung ...................: DM\n");
976 if (!dtaus_writeA(fdtaus, valA)) {
977 fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
981 fprintf (fcheck, "\n\n\n");
982 if (valA[recindex][0] == 'L')
983 fprintf (fcheck, " Sammeleinziehungsauftrag\n\n");
984 else if (valA[recindex][0] == 'G')
985 fprintf (fcheck, " Sammelueberweisungsauftrag\n\n");
987 fprintf (fcheck, " Sammelauftrag\n\n");
988 fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date());
989 fprintf (fcheck, " Waehrung : DM\n\n\n");
990 fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
991 fprintf (fcheck, " --------------------------------------------------------------------\n");
993 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz (BEGIN) an.\n");
1001 sum_val = bigint_int(0);
1002 sum_blz = bigint_int(0);
1003 sum_kto = bigint_int(0);
1004 bzero(valC, sizeof(valC));
1005 control_nextline ((void *)line, 100, fcontrol);
1006 if (line[0] == '{') {
1007 while (strlen(line) && line[0] == '{') {
1008 control_nextline ((void *)line, 100, fcontrol);
1010 for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++)
1011 free (text[textindex]);
1015 while (strlen(line) && line[0] != '}') {
1016 ident = extract_ident(line);
1017 if ((recindex = rec_index(ident, REC_C)) != -1)
1018 if (recC[recindex].type != IGN) {
1020 * Special exception to support multiple Text fields
1022 if (recindex == C_TEXT && valC[recindex]) {
1024 if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL)
1028 memset (text, 0, (MAX_TEXT+1) * sizeof (char *));
1031 if (textindex < MAX_TEXT) {
1032 if ((cp = (char *)malloc (strlen (line) + 1))) {
1034 cp[strlen (line)] = '\0';
1035 text[textindex++] = cp;
1039 if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
1040 strcpy(valC[recindex], line);
1045 control_nextline ((void *)line, 100, fcontrol);
1047 if (!dtaus_writeC(fdtaus, valA, valC, text)) {
1048 fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n");
1052 bi = bigint_string(real2string(valC[C_VAL])); sum_val = bigint_add(sum_val, bi);
1053 bi = bigint_string(valC[C_BLZ]); sum_blz = bigint_add(sum_blz, bi);
1054 bi = bigint_string(valC[C_KTO]); sum_kto = bigint_add(sum_kto, bi);
1056 fprintf (fcheck, " %10s %8s %-30s %12s\n", valC[C_KTO], valC[C_BLZ], valC[C_NAME], valC[C_VAL]);
1057 for (recindex=0; recindex<C_LEN; recindex++)
1059 free(valC[recindex]);
1060 bzero(valC, sizeof(valC));
1061 control_nextline ((void *)line, 100, fcontrol);
1064 fprintf (stderr, "Kein regulärer Datensatz?\n");
1071 dtaus_writeE(fdtaus, count, sum_val, sum_blz, sum_kto);
1072 fprintf (fcheck, " --------------------------------------------------------------------\n");
1073 bigint_sprintf (tmp, "%s", sum_val);
1074 fprintf (fbeleg, "\n Anzahl .....................: %d\n", count);
1075 recindex=strlen(tmp);
1076 tmp[recindex+1] = '\0';
1077 tmp[recindex] = tmp[recindex-1];
1078 tmp[recindex-1] = tmp[recindex-2];
1079 tmp[recindex-2] = '.';
1080 fprintf (fcheck, " %-52s %14s\n", "Summe", tmp);
1081 fprintf (fbeleg, "\n Summe ......................: %s\n", tmp);
1082 bigint_sprintf (tmp, "%s", sum_kto);
1083 fprintf (fbeleg, "\n Kontrollsumme Kontonummern .: %s\n", tmp);
1084 bigint_sprintf (tmp, "%s", sum_blz);
1085 fprintf (fbeleg, "\n Kontrollsumme Bankleitzahlen: %s\n", tmp);
1086 fprintf (fbeleg, "\n Unsere Kontonummer .........: %s\n", valA[A_KTO]);
1087 fprintf (fbeleg, "\n Unsere Bankleitzahl ........: %s\n", valA[A_BLZ]);
1088 fprintf (fbeleg, "\n\n\n\n\n __________________________________________________\n");
1089 fprintf (fbeleg, " Ort, Datum Unterschrift\n");
1090 for (recindex=0; recindex<A_LEN; recindex++)
1092 free(valA[recindex]);