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)
507 i = 187 + (appendix * 29);
509 /* Bail out if the number is too large, shouldn't be possible though */
513 buf[0] = (i/1000)+48;i-=(i/1000)*100;
514 buf[1] = (i/100)+48;i-=(i/100)*100;
515 buf[2] = (i/10)+48;i-=(i/10)*10;
519 for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */
520 buf[49] = ' '; /* C8 */
521 for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */
522 for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Euro) */
523 for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */
524 for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */
525 for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */
527 buf[182] = '1'; /* C17a (Currency) */
529 buf[182] = ' '; /* C17a (Currency) */
531 for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */
532 for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */
533 for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */
535 buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10;
536 buf[185+1] = appendix+48;
540 * Prepare a record E according to the specs.
541 * See dtaus.txt for explanation
543 void dtaus_prepareE (char *buf)
553 for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */
554 for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */
555 for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */
556 for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */
559 int dtaus_writeA(FILE *f, char **values)
565 for (i=0; (recA[i].name); i++)
566 if ((recA[i].type == REQ) && !values[i]) {
567 fprintf (stderr, "Anfangsdatensatz ist nicht vollständig, kein %s.\n", recA[i].name);
570 if (!(((values[A_TRANS][0] == 'L')||(values[A_TRANS][0] == 'G'))
571 &&((values[A_TRANS][1] == 'B')||(values[A_TRANS][1] == 'K')))) {
572 fprintf (stderr, "Ungültiger Typ, nur LK, GK, LB oder GB erlaubt.\n");
576 i=A_NAME;if (values[i] && strlen(values[i]) > recA[i].len)
577 values[i][recA[i].len] = '\0';
580 buf[5] = values[A_TRANS][0];
581 buf[6] = values[A_TRANS][1];
582 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),8));
583 for (i=0; i<8; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
584 sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
585 for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
586 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),10));
587 for (i=0; i<10; i++) buf[recA[A_KTO].pos+i] = tmp[i];
593 int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
603 if (text) for (maxtext=0;text[maxtext];maxtext++);
606 for (i=0; (recC[i].name); i++)
608 printf ("%s: %s\n", recC[i].name, values[i]);
611 for (i=0; (recC[i].name); i++)
612 if ((recC[i].type == REQ) && !values[i]) {
613 fprintf (stderr, "Datensatz ist nicht vollständig, kein %s.\n", recC[i].name);
616 sprintf (tmp, "%s", trans2string(values[C_TRANS]));
618 fprintf (stderr, "Ungültiger Typ, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
622 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
623 values[i][recC[i].len-2] = '\0';
624 i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
625 values[i][recC[i].len] = '\0';
626 i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
627 values[i][recC[i].len] = '\0';
628 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
629 values[i][recC[i].len] = '\0';
631 dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
632 for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
634 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8));
636 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_BLZ]),8));
637 for (i=0; i<recC[C_MYBLZ].len; i++) buf[5+i] = tmp[i];
638 for (i=0; i<recC[C_MYBLZ].len; i++) buf[recC[C_MYBLZ].pos+i] = tmp[i];
639 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_BLZ]),8));
640 for (i=0; i<recC[C_BLZ].len; i++) buf[recC[C_BLZ].pos+i] = tmp[i];
641 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
642 for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
643 sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
644 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
646 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
648 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_KTO]),10));
649 for (i=0; i<recC[C_MYKTO].len; i++) buf[recC[C_MYKTO].pos+i] = tmp[i];
650 sprintf (tmp, "%-27.27s", upcase(values[C_NAME]));
651 for (i=0; i<recC[C_NAME].len; i++) buf[recC[C_NAME].pos+i] = tmp[i];
653 sprintf (tmp, "%-27.27s", upcase(values[C_MYNAM]));
655 sprintf (tmp, "%-27.27s", upcase(valuesA[A_NAME]));
656 for (i=0; i<recC[C_MYNAM].len; i++) buf[recC[C_MYNAM].pos+i] = tmp[i];
657 sprintf (tmp, "%-27.27s", upcase(values[C_ZWECK]));
658 for (i=0; i<recC[C_ZWECK].len; i++) buf[recC[C_ZWECK].pos+i] = tmp[i];
660 if (values[C_TEXT]) {
661 buf[recC[C_TEXT].pos+0] = '0';
662 buf[recC[C_TEXT].pos+1] = '2';
663 sprintf (tmp, "%-27.27s", upcase(values[C_TEXT]));
664 for (i=0; i<recC[C_TEXT].len-2; i++) buf[recC[C_TEXT].pos+2+i] = tmp[i];
668 buf[recC[C_EXT].pos+0] = '0';
669 buf[recC[C_EXT].pos+1] = '2';
670 sprintf (tmp, "%-27.27s", upcase(text[0]));
671 for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
676 if (text && maxtext > 1) {
678 while (fieldnr<maxtext) {
679 memset (appendix, ' ', 128);
680 appendix[128] = '\0';
681 for (k=0; k<4 && (fieldnr+k)<maxtext; k++) {
682 sprintf (tmp, "%-27.27s", upcase(text[fieldnr+k]));
683 appendix[k*29] = '0';
684 appendix[(k*29)+1] = '2';
685 for (i=0; i<recC[C_TEXT].len-2; i++) appendix[(k*29)+2+i] = tmp[i];
695 int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
703 sprintf (tmp, "%07d", count);
704 for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
705 bigint_sprintf (tmp, "%s", sum);
706 padzeroclip (tmp,13);
707 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].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", kto);
712 padzeroclip (tmp,17);
713 for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
714 bigint_sprintf (tmp, "%s", blz);
715 padzeroclip (tmp,17);
716 for (i=0; i<recE[E_BLZ].len; i++) buf[recE[E_BLZ].pos+i] = tmp[i];
722 void printctln(FILE *f, char *field, char *value)
724 if (strlen(field) && strlen(value))
725 fprintf(f, " %s\t%s\n", field, value);
730 * Third: Some high level routines
733 void dtaus2control (char *cdtaus, char *ccontrol)
735 FILE *fdtaus, *fcontrol;
745 if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
746 if (!(fdtaus = fopen("dtaus0.txt", "r")))
749 if (!strcmp (cdtaus, "-"))
752 if (!(fdtaus = fopen(cdtaus, "r")))
758 if (!strcmp (ccontrol, "-"))
761 if (!(fcontrol = fopen(ccontrol, "w")))
763 if (!(buf = (char *)malloc (512)))
769 if (dtaus_nextrec(buf, fdtaus) == 1) {
770 if (dtaus_char(buf,4) == 'A') {
771 fprintf(fcontrol, "BEGIN {\n");
774 for (index=A_TRANS; index < A_DATE; index++) {
775 bufp = buf + recA[index].pos;
776 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
777 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
780 index = A_DATE; bufp = buf + recA[index].pos;
781 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
782 printctln(fcontrol, recA[index].name, strip_spaces(tmp));
784 index = A_EURO; bufp = buf + recA[index].pos;
785 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
786 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
788 fprintf(fcontrol, "}\n\n");
790 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz an.\n");
794 fprintf (stderr, "Der Anfangsdatensatz ist kaputt.\n");
801 if (dtaus_nextrec(buf, fdtaus) == 1) {
802 while (dtaus_char(buf,4) == 'C') {
804 if (dtaus_nextrec(bufp, fdtaus) != 1) {
805 fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
808 fprintf(fcontrol, "{\n");
810 for (index=C_NAME; index <= C_EURO; index++) {
811 bufp = buf + recC[index].pos;
812 memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
814 printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
815 else if (index == C_TRANS)
816 printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
818 printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
821 for (index=C_TEXT; index <= C_EXT; index++) {
822 if (!(dtaus_char(buf,recC[index].pos) == ' ')) {
823 bufp = buf + recC[index].pos;
824 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
825 memcpy(tmp, bufp, recC[index].len-2); tmp[recC[index].len-2] = '\0';
826 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
830 /* Number of extension records for this C record */
831 extC = dtaus_int(buf, 185, 2);
839 if (dtaus_nextrec(buf, fdtaus) != 1)
840 bzero (buf, sizeof(buf));
843 * Are there extension records that we have to check?
845 * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
846 * instead of 00 we should let it in so it can read its own
847 * old files... *sigh*
849 while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') {
850 for (index=0; index < 4; index++) {
851 if ((dtaus_char(buf,index*29) != ' ')) {
852 bufp = buf + index*29;
853 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
854 memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
855 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
858 if (dtaus_nextrec(buf, fdtaus) != 1)
859 bzero (buf, sizeof(buf));
862 fprintf(fcontrol, "}\n");
868 * (gelesen ist er eigentlich schon...)
870 if (dtaus_char(buf,4) == 'E') {
871 if (dtaus_char(buf,4) == 'E') {
872 fprintf(fcontrol, "\nEND {\n");
874 for (index=E_COUNT; index <= E_BLZ; index++) {
875 bufp = buf + recE[index].pos;
876 memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
878 printctln(fcontrol, recE[index].name, strip_zeros(string2real(tmp)));
880 printctln(fcontrol, recE[index].name, strip_zeros(tmp));
883 fprintf(fcontrol, "}\n");
885 fprintf (stderr, "Das ist kein Abschlußdatensatz.\n");
889 fprintf (stderr, "Der Abschlußdatensatz ist leer oder kaputt.\n");
896 int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
898 FILE *fdtaus, *fcontrol, *fbeleg, *fcheck;
904 char *valA[A_LEN], *valC[C_LEN];
906 bigint sum_val, sum_blz, sum_kto, bi;
912 if (!(fdtaus = fopen("dtaus0.txt", "w")))
915 if (!strcmp (cdtaus, "-"))
918 if (!(fdtaus = fopen(cdtaus, "w")))
922 if (!(fcontrol = fopen("dtaus0.ctl", "r")))
923 if (!(fcontrol = fopen("DTAUS0.CTL", "r")))
926 if (!strcmp (ccontrol, "-"))
929 if (!(fcontrol = fopen(ccontrol, "r")))
933 if (!(fbeleg = fopen("dtaus0.doc", "w")))
936 if (!(fbeleg = fopen(cbeleg, "w")))
942 if (!(fcheck = fopen(ccheck, "w")))
946 if (!(buf = (char *)malloc (512)))
952 bzero(valA, sizeof(valA));
953 control_nextline ((void *)line, 100, fcontrol);
954 ident = extract_ident(line);
955 if (!strcmp(ident, "begin") && (line[0] == '{')) {
956 control_nextline ((void *)line, 100, fcontrol);
957 while (strlen(line) && line[0] != '}') {
958 ident = extract_ident(line);
959 if ((recindex = rec_index(ident, REC_A)) != -1)
960 if (recA[recindex].type != IGN)
961 if ((valA[recindex] = (char *)malloc (strlen(line)+1)))
962 strcpy(valA[recindex], line);
963 control_nextline ((void *)line, 100, fcontrol);
965 if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
966 fprintf(fbeleg, "\n\n");
967 fprintf(fbeleg, "\n Begleitzettel\n\n");
968 fprintf(fbeleg, "\n Belegloser Datentraegeraustausch\n\n");
969 if (valA[recindex][0] == 'L')
970 fprintf(fbeleg, "\n Sammeleinziehungsauftrag\n\n");
971 else if (valA[recindex][0] == 'G')
972 fprintf(fbeleg, "\n Sammelueberweisungsauftrag\n\n");
974 fprintf(fbeleg, "\n Sammelauftrag\n\n");
975 fprintf(fbeleg, "\n VOL ........................:\n");
976 fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date());
977 fprintf(fbeleg, "\n Waehrung ...................: DM\n");
979 if (!dtaus_writeA(fdtaus, valA)) {
980 fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
984 fprintf (fcheck, "\n\n\n");
985 if (valA[recindex][0] == 'L')
986 fprintf (fcheck, " Sammeleinziehungsauftrag\n\n");
987 else if (valA[recindex][0] == 'G')
988 fprintf (fcheck, " Sammelueberweisungsauftrag\n\n");
990 fprintf (fcheck, " Sammelauftrag\n\n");
991 fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date());
992 fprintf (fcheck, " Waehrung : DM\n\n\n");
993 fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
994 fprintf (fcheck, " --------------------------------------------------------------------\n");
996 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz (BEGIN) an.\n");
1004 sum_val = bigint_int(0);
1005 sum_blz = bigint_int(0);
1006 sum_kto = bigint_int(0);
1007 bzero(valC, sizeof(valC));
1008 control_nextline ((void *)line, 100, fcontrol);
1009 if (line[0] == '{') {
1010 while (strlen(line) && line[0] == '{') {
1011 control_nextline ((void *)line, 100, fcontrol);
1013 for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++)
1014 free (text[textindex]);
1018 while (strlen(line) && line[0] != '}') {
1019 ident = extract_ident(line);
1020 if ((recindex = rec_index(ident, REC_C)) != -1)
1021 if (recC[recindex].type != IGN) {
1023 * Special exception to support multiple Text fields
1025 if (recindex == C_TEXT && valC[recindex]) {
1027 if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL)
1031 memset (text, 0, (MAX_TEXT+1) * sizeof (char *));
1034 if (textindex < MAX_TEXT) {
1035 if ((cp = (char *)malloc (strlen (line) + 1))) {
1037 cp[strlen (line)] = '\0';
1038 text[textindex++] = cp;
1042 if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
1043 strcpy(valC[recindex], line);
1048 control_nextline ((void *)line, 100, fcontrol);
1050 if (!dtaus_writeC(fdtaus, valA, valC, text)) {
1051 fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n");
1055 bi = bigint_string(real2string(valC[C_VAL])); sum_val = bigint_add(sum_val, bi);
1056 bi = bigint_string(valC[C_BLZ]); sum_blz = bigint_add(sum_blz, bi);
1057 bi = bigint_string(valC[C_KTO]); sum_kto = bigint_add(sum_kto, bi);
1059 fprintf (fcheck, " %10s %8s %-30s %12s\n", valC[C_KTO], valC[C_BLZ], valC[C_NAME], valC[C_VAL]);
1060 for (recindex=0; recindex<C_LEN; recindex++)
1062 free(valC[recindex]);
1063 bzero(valC, sizeof(valC));
1064 control_nextline ((void *)line, 100, fcontrol);
1067 fprintf (stderr, "Kein regulärer Datensatz?\n");
1074 dtaus_writeE(fdtaus, count, sum_val, sum_blz, sum_kto);
1075 fprintf (fcheck, " --------------------------------------------------------------------\n");
1076 bigint_sprintf (tmp, "%s", sum_val);
1077 fprintf (fbeleg, "\n Anzahl .....................: %d\n", count);
1078 recindex=strlen(tmp);
1079 tmp[recindex+1] = '\0';
1080 tmp[recindex] = tmp[recindex-1];
1081 tmp[recindex-1] = tmp[recindex-2];
1082 tmp[recindex-2] = '.';
1083 fprintf (fcheck, " %-52s %14s\n", "Summe", tmp);
1084 fprintf (fbeleg, "\n Summe ......................: %s\n", tmp);
1085 bigint_sprintf (tmp, "%s", sum_kto);
1086 fprintf (fbeleg, "\n Kontrollsumme Kontonummern .: %s\n", tmp);
1087 bigint_sprintf (tmp, "%s", sum_blz);
1088 fprintf (fbeleg, "\n Kontrollsumme Bankleitzahlen: %s\n", tmp);
1089 fprintf (fbeleg, "\n Unsere Kontonummer .........: %s\n", valA[A_KTO]);
1090 fprintf (fbeleg, "\n Unsere Bankleitzahl ........: %s\n", valA[A_BLZ]);
1091 fprintf (fbeleg, "\n\n\n\n\n __________________________________________________\n");
1092 fprintf (fbeleg, " Ort, Datum Unterschrift\n");
1093 for (recindex=0; recindex<A_LEN; recindex++)
1095 free(valA[recindex]);