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 {"Euro", 127, 1, OPT},
76 dtaus_record recC[] = {
77 {"Name", 93, 27, REQ},
78 {"Konto", 21, 10, REQ},
80 {"Transaktion", 44, 5, REQ},
82 {"Betrag", 50, 11, REQ},
84 {"Betrag", 79, 11, REQ},
86 {"Zweck", 155, 27, REQ},
87 {"myName", 128, 27, OPT},
88 {"myKonto", 69, 10, OPT},
89 {"myBLZ", 61, 8, OPT},
90 {"Euro", 182, 1, IGN},
91 {"Text", 187, 29, OPT},
92 {"Extension", 216, 29, OPT},
94 {"Betrag-Euro", 79, 11, IGN},
120 dtaus_record recE[] = {
121 {"Anzahl", 10, 7, IGN},
123 {"Summe", 17, 13, IGN},
125 {"Summe", 64, 13, IGN},
127 {"Kontos", 30, 17, IGN},
128 {"BLZs", 47, 17, IGN},
130 {"Summe-Euro", 64, 13, IGN},
144 * Second: Some low level routines
147 size_t dtaus_nextrec (void **buf, FILE *f)
150 return fread(buf, 128, 1, f);
153 char *upcase(char *s)
159 for (cp=s,xp=x; *cp; cp++,xp++) {
160 if (strchr(" 0123456789.,&-/+*$%ABCDEFGHIJKLMNOPQRSTUVWXYZ",*cp)) {
162 } else if (strchr("abcdefghijklmnopqrstuvwxyz",*cp)) {
164 } else if (strchr ("üÜäÄöÖß", *cp)) {
166 case 'ü': *(xp++) = 'U'; *xp='E'; break;
167 case 'Ü': *(xp++) = 'U'; *xp='E'; break;
168 case 'ä': *(xp++) = 'A'; *xp='E'; break;
169 case 'Ä': *(xp++) = 'A'; *xp='E'; break;
170 case 'ö': *(xp++) = 'O'; *xp='E'; break;
171 case 'Ö': *(xp++) = 'O'; *xp='E'; break;
172 case 'ß': *(xp++) = 'S'; *xp='S'; break;
176 * Filter out all other characters since credit institutes won't
177 * accept the file otherwise.
186 char *downcase(char *s)
191 memset (x, 0, sizeof (x));
200 char *strip_spaces (char *s)
205 for (i=strlen(s);(s[i-1] == ' '||s[i-1] == '\t')&&i>0; i--)
207 for (p=s; *p==' '; p++);
211 char *strip_zeros (char *s)
215 for (p=s; *p=='0'; p++);
219 char *strip_nondigits (char *s)
232 char dtaus_char (void *buf, unsigned int pos)
238 memcpy(&res, bufp, 1);
242 char *string2real(char *s)
248 strncpy(res, s, strlen(s)-2);
249 res[strlen(s)-2] = '.';
250 res[strlen(s)-1] = s[strlen(s)-2];
251 res[strlen(s)] = s[strlen(s)-1];
255 char *real2string(char *s)
261 for (cp=res; *cp&&!(*cp == ',')&&!(*cp == '.');cp++);
268 char *string2trans (char *s)
273 if (!strcmp(s, "04000"))
274 sprintf (res, "Abbuchung");
275 else if (!strcmp(s, "05000"))
276 sprintf (res, "Einzug");
277 else if (!strcmp(s, "05005"))
278 sprintf (res, "E-Cash");
279 else if (!strcmp(s, "05006"))
280 sprintf (res, "E-Cash-A");
281 else if (!strcmp(s, "51000"))
282 sprintf (res, "Gutschrift");
283 else if (!strcmp(s, "53000"))
284 sprintf (res, "Lohn");
285 else if (!strncmp(s, "5400", 4))
286 sprintf (res, "Vermögen");
287 /* else if (!strcmp(s, "56000"))
288 sprintf (res, ""); / * Überweisung öffentlicher Kassen */
292 char *trans2string (char *s)
297 if (!strcmp(s, "Abbuchung"))
298 sprintf (res, "04000");
299 else if (!strcmp(s, "Einzug"))
300 sprintf (res, "05000");
301 else if (!strcmp(s, "E-Cash"))
302 sprintf (res, "05005");
303 else if (!strcmp(s, "E-Cash-A"))
304 sprintf (res, "05006");
305 else if (!strcmp(s, "Gutschrift"))
306 sprintf (res, "51000");
307 else if (!strcmp(s, "Lohn"))
308 sprintf (res, "53000");
309 else if (!strncmp(s, "Vermögen", 4))
310 sprintf (res, "5400");
311 /* else if (!strcmp(s, ""))
312 sprintf (res, "56000"); / * Überweisung öffentlicher Kassen */
316 char *string2ext (char *s)
321 if (!strcmp(s, "01"))
322 sprintf (res, "Kunde");
323 else if (!strcmp(s, "02"))
324 sprintf (res, "Text");
325 else if (!strcmp(s, "03"))
326 sprintf (res, "Auftraggeber");
330 char *ext2string (char *s)
335 if (!strcmp(s, "Kunde"))
337 else if (!strcmp(s, "Text"))
339 else if (!strcmp(s, "Auftraggeber"))
344 unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
348 static unsigned long int res;
351 memcpy(tmp, bufp, len);
353 sscanf(tmp, "%lu", &res);
358 * returns the first word in this line, returns it and shortens the
361 char *extract_ident (char *line)
364 static char word[30];
366 if (strlen(line) > 0) {
367 x = index (line, ' ');
368 y = index (line, '\t');
371 strncpy(word, line, 29);
376 /* Check which index returns the lower value, and check if the
378 if ((c = (x && x<y)?x:(y?y:x))) {
379 strncpy(word, line, c - line);
381 for (;*c == '\t' || *c == ' '; c++);
382 for (x=line; *c; c++,x++)
385 strcpy(word, downcase(word));
394 * Pads a string with zero's on the left side.
396 char *padzeroclip (char *s, int len)
400 if (strlen(s) == len) return s;
401 if (strlen(s) > len) {
409 for (p=s+strlen(s)-1;p>=s;p--)
411 for (;q>=s;) *(q--)='0';
415 int rec_index(char *ident, int type)
418 dtaus_record *rec = NULL;
421 case REC_A: rec = recA; break;
422 case REC_C: rec = recC; break;
423 case REC_E: rec = recE; break;
426 for (i=0; (rec[i].name); i++) {
427 if (!strcmp(ident, downcase(rec[i].name)))
434 size_t control_nextline (void **buf, int len, FILE *f)
441 bzero (line, sizeof(line));
445 while (!strlen(line) && (cp = fgets(line, 100, f))) {
447 if (line[0] != '#') {
448 if (line[strlen(line)-1] != '\n') {
450 while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
452 line[strlen(line)-1] = '\0';
453 if (line[strlen(line)-1] == '
\r')
454 line[strlen(line)-1] = '\0';
455 for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
463 for (cp=line; *cp==' '; cp++);
466 memcpy(buf, cp, strlen(cp));
478 timer = time ( NULL );
479 loctime = localtime(&timer);
480 sprintf(res, "%02d.%02d.%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
485 * Prepare a record A according to the specs.
486 * See dtaus.txt for explanation
488 void dtaus_prepareA (char *buf)
496 timer = time ( NULL );
497 loctime = localtime(&timer);
504 for (i=15;i<15+8; i++) buf[i] = '0'; /* A5 */
505 sprintf(tmp, "%02d%02d%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
506 for (i=0; i<6; i++) buf[50+i] = tmp[i]; /* A7 (Date) */
507 for (i=56;i<56+4; i++) buf[i] = ' '; /* A8 */
508 for (i=70;i<70+10; i++) buf[i] = '0'; /* A10 */
509 for (i=80;i<80+48; i++) buf[i] = ' '; /* A11 */
511 buf[recA[A_EURO].pos] = '1'; /* A12 (Currency) */
514 buf[recA[A_EURO].pos] = '1'; /* A12 (Currency) */
516 buf[recA[A_EURO].pos] = ' '; /* A12 (Currency) */
521 * Prepare a record C according to the specs.
522 * See dtaus.txt for explanation
524 void dtaus_prepareC (char *buf, int normaltext, int maxtext)
534 i = 187 + (appendix * 29);
536 /* Bail out if the number is too large, shouldn't be possible though */
540 buf[0] = (i/1000)+48;i-=(i/1000)*100;
541 buf[1] = (i/100)+48;i-=(i/100)*100;
542 buf[2] = (i/10)+48;i-=(i/10)*10;
546 for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */
547 buf[49] = ' '; /* C8 */
548 for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */
549 for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Betrag Euro) */
550 for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */
551 for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */
552 for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */
554 buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */
557 buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */
559 buf[recC[C_EURO].pos] = ' '; /* C17a (Currency) */
561 for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */
562 for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */
563 for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */
565 buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10;
566 buf[185+1] = appendix+48;
570 * Prepare a record E according to the specs.
571 * See dtaus.txt for explanation
573 void dtaus_prepareE (char *buf)
583 for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */
584 for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */
585 for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */
586 for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */
589 int dtaus_writeA(FILE *f, char **values)
595 for (i=0; (recA[i].name); i++)
596 if ((recA[i].type == REQ) && !values[i]) {
597 fprintf (stderr, "Anfangsdatensatz ist nicht vollständig, kein %s.\n", recA[i].name);
600 if (!(((values[A_TRANS][0] == 'L')||(values[A_TRANS][0] == 'G'))
601 &&((values[A_TRANS][1] == 'B')||(values[A_TRANS][1] == 'K')))) {
602 fprintf (stderr, "Ungültiger Typ, nur LK, GK, LB oder GB erlaubt.\n");
606 i=A_NAME;if (values[i] && strlen(values[i]) > recA[i].len)
607 values[i][recA[i].len] = '\0';
610 buf[5] = values[A_TRANS][0];
611 buf[6] = values[A_TRANS][1];
612 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),8));
613 for (i=0; i<8; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
614 sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
615 for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
616 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),10));
617 for (i=0; i<10; i++) buf[recA[A_KTO].pos+i] = tmp[i];
623 int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
633 if (text) for (maxtext=0;text[maxtext];maxtext++);
636 for (i=0; (recC[i].name); i++)
638 printf ("%s: %s\n", recC[i].name, values[i]);
641 for (i=0; (recC[i].name); i++)
642 if ((recC[i].type == REQ) && !values[i]) {
643 fprintf (stderr, "Datensatz ist nicht vollständig, kein %s.\n", recC[i].name);
646 sprintf (tmp, "%s", trans2string(values[C_TRANS]));
648 fprintf (stderr, "Ungültiger Typ, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
652 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
653 values[i][recC[i].len-2] = '\0';
654 i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
655 values[i][recC[i].len] = '\0';
656 i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
657 values[i][recC[i].len] = '\0';
658 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
659 values[i][recC[i].len] = '\0';
661 dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
662 for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
664 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8));
666 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_BLZ]),8));
667 for (i=0; i<recC[C_MYBLZ].len; i++) buf[5+i] = tmp[i];
668 for (i=0; i<recC[C_MYBLZ].len; i++) buf[recC[C_MYBLZ].pos+i] = tmp[i];
669 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_BLZ]),8));
670 for (i=0; i<recC[C_BLZ].len; i++) buf[recC[C_BLZ].pos+i] = tmp[i];
671 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
672 for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
673 sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
676 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
678 for (i=0; i<recC[C_EUR].len; i++) buf[recC[C_EUR].pos+i] = tmp[i];
680 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
683 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
685 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_KTO]),10));
686 for (i=0; i<recC[C_MYKTO].len; i++) buf[recC[C_MYKTO].pos+i] = tmp[i];
687 sprintf (tmp, "%-27.27s", upcase(values[C_NAME]));
688 for (i=0; i<recC[C_NAME].len; i++) buf[recC[C_NAME].pos+i] = tmp[i];
690 sprintf (tmp, "%-27.27s", upcase(values[C_MYNAM]));
692 sprintf (tmp, "%-27.27s", upcase(valuesA[A_NAME]));
693 for (i=0; i<recC[C_MYNAM].len; i++) buf[recC[C_MYNAM].pos+i] = tmp[i];
694 sprintf (tmp, "%-27.27s", upcase(values[C_ZWECK]));
695 for (i=0; i<recC[C_ZWECK].len; i++) buf[recC[C_ZWECK].pos+i] = tmp[i];
697 if (values[C_TEXT]) {
698 buf[recC[C_TEXT].pos+0] = '0';
699 buf[recC[C_TEXT].pos+1] = '2';
700 sprintf (tmp, "%-27.27s", upcase(values[C_TEXT]));
701 for (i=0; i<recC[C_TEXT].len-2; i++) buf[recC[C_TEXT].pos+2+i] = tmp[i];
705 buf[recC[C_EXT].pos+0] = '0';
706 buf[recC[C_EXT].pos+1] = '2';
707 sprintf (tmp, "%-27.27s", upcase(text[0]));
708 for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
713 if (text && maxtext > 1) {
715 while (fieldnr<maxtext) {
716 memset (appendix, ' ', 128);
717 appendix[128] = '\0';
718 for (k=0; k<4 && (fieldnr+k)<maxtext; k++) {
719 sprintf (tmp, "%-27.27s", upcase(text[fieldnr+k]));
720 appendix[k*29] = '0';
721 appendix[(k*29)+1] = '2';
722 for (i=0; i<recC[C_TEXT].len-2; i++) appendix[(k*29)+2+i] = tmp[i];
732 int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
740 sprintf (tmp, "%07d", count);
741 for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
742 bigint_sprintf (tmp, "%s", sum);
743 padzeroclip (tmp,13);
746 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
748 for (i=0; i<recE[E_EUR].len; i++) buf[recE[E_EUR].pos+i] = tmp[i];
750 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
752 bigint_sprintf (tmp, "%s", kto);
753 padzeroclip (tmp,17);
754 for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
755 bigint_sprintf (tmp, "%s", blz);
756 padzeroclip (tmp,17);
757 for (i=0; i<recE[E_BLZ].len; i++) buf[recE[E_BLZ].pos+i] = tmp[i];
763 void printctln(FILE *f, char *field, char *value)
765 if (strlen(field) && strlen(value))
766 fprintf(f, " %s\t%s\n", field, value);
771 * Third: Some high level routines
774 void dtaus2control (char *cdtaus, char *ccontrol)
776 FILE *fdtaus, *fcontrol;
786 if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
787 if (!(fdtaus = fopen("dtaus0.txt", "r")))
790 if (!strcmp (cdtaus, "-"))
793 if (!(fdtaus = fopen(cdtaus, "r")))
799 if (!strcmp (ccontrol, "-"))
802 if (!(fcontrol = fopen(ccontrol, "w")))
804 if (!(buf = (char *)malloc (512)))
810 if (dtaus_nextrec(buf, fdtaus) == 1) {
811 if (dtaus_char(buf,4) == 'A') {
812 fprintf(fcontrol, "BEGIN {\n");
816 for (index=A_TRANS; index <= A_EURO; index++) {
818 for (index=A_TRANS; index < A_EURO; index++) {
820 bufp = buf + recA[index].pos;
821 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
822 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
826 if (tmp[recA[index].pos] == '1')
830 fprintf(fcontrol, "}\n\n");
832 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz an.\n");
836 fprintf (stderr, "Der Anfangsdatensatz ist kaputt.\n");
843 if (dtaus_nextrec(buf, fdtaus) == 1) {
844 while (dtaus_char(buf,4) == 'C') {
846 if (dtaus_nextrec(bufp, fdtaus) != 1) {
847 fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
850 fprintf(fcontrol, "{\n");
852 for (index=C_NAME; index < C_EURO; index++) {
854 if (use_euro && index == C_VAL)
857 bufp = buf + recC[index].pos;
858 memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
860 if (index == C_VAL || index == C_EUR)
864 printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
865 else if (index == C_TRANS)
866 printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
868 printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
870 if (use_euro && index == C_EUR)
875 for (index=C_TEXT; index <= C_EXT; index++) {
876 if (!(dtaus_char(buf,recC[index].pos) == ' ')) {
877 bufp = buf + recC[index].pos;
878 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
879 memcpy(tmp, bufp, recC[index].len-2); tmp[recC[index].len-2] = '\0';
880 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
884 /* Number of extension records for this C record */
885 extC = dtaus_int(buf, 185, 2);
893 if (dtaus_nextrec(buf, fdtaus) != 1)
894 bzero (buf, sizeof(buf));
897 * Are there extension records that we have to check?
899 * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
900 * instead of 00 we should let it in so it can read its own
901 * old files... *sigh*
903 while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') {
904 for (index=0; index < 4; index++) {
905 if ((dtaus_char(buf,index*29) != ' ')) {
906 bufp = buf + index*29;
907 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
908 memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
909 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
912 if (dtaus_nextrec(buf, fdtaus) != 1)
913 bzero (buf, sizeof(buf));
916 fprintf(fcontrol, "}\n");
922 * (gelesen ist er eigentlich schon...)
924 if (dtaus_char(buf,4) == 'E') {
925 if (dtaus_char(buf,4) == 'E') {
926 fprintf(fcontrol, "\nEND {\n");
928 for (index=E_COUNT; index <= E_BLZ; index++) {
930 if (use_euro && index == E_VAL)
933 bufp = buf + recE[index].pos;
934 memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
936 if (index == E_VAL || index == E_EUR)
940 printctln(fcontrol, recE[index].name, strip_zeros(string2real(tmp)));
942 printctln(fcontrol, recE[index].name, strip_zeros(tmp));
944 if (use_euro && index == E_EUR)
949 fprintf(fcontrol, "}\n");
951 fprintf (stderr, "Das ist kein Abschlußdatensatz.\n");
955 fprintf (stderr, "Der Abschlußdatensatz ist leer oder kaputt.\n");
962 int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
964 FILE *fdtaus, *fcontrol, *fbeleg, *fcheck;
970 char *valA[A_LEN], *valC[C_LEN];
972 bigint sum_val, sum_blz, sum_kto, bi;
978 if (!(fdtaus = fopen("dtaus0.txt", "w")))
981 if (!strcmp (cdtaus, "-"))
984 if (!(fdtaus = fopen(cdtaus, "w")))
988 if (!(fcontrol = fopen("dtaus0.ctl", "r")))
989 if (!(fcontrol = fopen("DTAUS0.CTL", "r")))
992 if (!strcmp (ccontrol, "-"))
995 if (!(fcontrol = fopen(ccontrol, "r")))
999 if (!(fbeleg = fopen("dtaus0.doc", "w")))
1002 if (!(fbeleg = fopen(cbeleg, "w")))
1008 if (!(fcheck = fopen(ccheck, "w")))
1012 if (!(buf = (char *)malloc (512)))
1018 bzero(valA, sizeof(valA));
1019 control_nextline ((void *)line, 100, fcontrol);
1020 ident = extract_ident(line);
1021 if (!strcmp(ident, "begin") && (line[0] == '{')) {
1022 control_nextline ((void *)line, 100, fcontrol);
1023 while (strlen(line) && line[0] != '}') {
1024 ident = extract_ident(line);
1025 if ((recindex = rec_index(ident, REC_A)) != -1)
1026 #ifndef DEFAULT_EURO
1029 if (recA[recindex].type != IGN)
1030 if ((valA[recindex] = (char *)malloc (strlen(line)+1)))
1031 strcpy(valA[recindex], line);
1032 #ifndef DEFAULT_EURO
1034 if (! strcasecmp (ident, "euro"))
1038 control_nextline ((void *)line, 100, fcontrol);
1040 if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
1041 fprintf(fbeleg, "\n\n");
1042 fprintf(fbeleg, "\n Begleitzettel\n\n");
1043 fprintf(fbeleg, "\n Belegloser Datentraegeraustausch\n\n");
1044 if (valA[recindex][0] == 'L')
1045 fprintf(fbeleg, "\n Sammeleinziehungsauftrag\n\n");
1046 else if (valA[recindex][0] == 'G')
1047 fprintf(fbeleg, "\n Sammelueberweisungsauftrag\n\n");
1049 fprintf(fbeleg, "\n Sammelauftrag\n\n");
1050 fprintf(fbeleg, "\n VOL ........................:\n");
1051 fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date());
1052 #ifndef DEFAULT_EURO
1054 fprintf(fbeleg, "\n Waehrung ...................: Euro\n");
1056 fprintf(fbeleg, "\n Waehrung ...................: DM\n");
1058 fprintf(fbeleg, "\n Waehrung ...................: Euro\n");
1061 if (!dtaus_writeA(fdtaus, valA)) {
1062 fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
1066 fprintf (fcheck, "\n\n\n");
1067 if (valA[recindex][0] == 'L')
1068 fprintf (fcheck, " Sammeleinziehungsauftrag\n\n");
1069 else if (valA[recindex][0] == 'G')
1070 fprintf (fcheck, " Sammelueberweisungsauftrag\n\n");
1072 fprintf (fcheck, " Sammelauftrag\n\n");
1073 fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date());
1074 #ifndef DEFAULT_EURO
1076 fprintf (fcheck, " Waehrung : Euro\n\n\n");
1078 fprintf (fcheck, " Waehrung : DM\n\n\n");
1080 fprintf (fcheck, " Waehrung : Euro\n\n\n");
1082 fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
1083 fprintf (fcheck, " --------------------------------------------------------------------\n");
1085 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz (BEGIN) an.\n");
1093 sum_val = bigint_int(0);
1094 sum_blz = bigint_int(0);
1095 sum_kto = bigint_int(0);
1096 bzero(valC, sizeof(valC));
1097 control_nextline ((void *)line, 100, fcontrol);
1098 if (line[0] == '{') {
1099 while (strlen(line) && line[0] == '{') {
1100 control_nextline ((void *)line, 100, fcontrol);
1102 for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++)
1103 free (text[textindex]);
1107 while (strlen(line) && line[0] != '}') {
1108 ident = extract_ident(line);
1109 if ((recindex = rec_index(ident, REC_C)) != -1)
1110 if (recC[recindex].type != IGN) {
1112 * Special exception to support multiple Text fields
1114 if (recindex == C_TEXT && valC[recindex]) {
1116 if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL)
1120 memset (text, 0, (MAX_TEXT+1) * sizeof (char *));
1123 if (textindex < MAX_TEXT) {
1124 if ((cp = (char *)malloc (strlen (line) + 1))) {
1126 cp[strlen (line)] = '\0';
1127 text[textindex++] = cp;
1131 if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
1132 strcpy(valC[recindex], line);
1137 control_nextline ((void *)line, 100, fcontrol);
1139 if (!dtaus_writeC(fdtaus, valA, valC, text)) {
1140 fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n");
1144 bi = bigint_string(real2string(valC[C_VAL])); sum_val = bigint_add(sum_val, bi);
1145 bi = bigint_string(valC[C_BLZ]); sum_blz = bigint_add(sum_blz, bi);
1146 bi = bigint_string(valC[C_KTO]); sum_kto = bigint_add(sum_kto, bi);
1148 fprintf (fcheck, " %10s %8s %-30s %12s\n", valC[C_KTO], valC[C_BLZ], valC[C_NAME], valC[C_VAL]);
1149 for (recindex=0; recindex<C_LEN; recindex++)
1151 free(valC[recindex]);
1152 bzero(valC, sizeof(valC));
1153 control_nextline ((void *)line, 100, fcontrol);
1156 fprintf (stderr, "Kein regulärer Datensatz?\n");
1163 dtaus_writeE(fdtaus, count, sum_val, sum_blz, sum_kto);
1164 fprintf (fcheck, " --------------------------------------------------------------------\n");
1165 bigint_sprintf (tmp, "%s", sum_val);
1166 fprintf (fbeleg, "\n Anzahl .....................: %d\n", count);
1167 recindex=strlen(tmp);
1168 tmp[recindex+1] = '\0';
1169 tmp[recindex] = tmp[recindex-1];
1170 tmp[recindex-1] = tmp[recindex-2];
1171 tmp[recindex-2] = '.';
1172 fprintf (fcheck, " %-52s %14s\n", "Summe", tmp);
1173 fprintf (fbeleg, "\n Summe ......................: %s\n", tmp);
1174 bigint_sprintf (tmp, "%s", sum_kto);
1175 fprintf (fbeleg, "\n Kontrollsumme Kontonummern .: %s\n", tmp);
1176 bigint_sprintf (tmp, "%s", sum_blz);
1177 fprintf (fbeleg, "\n Kontrollsumme Bankleitzahlen: %s\n", tmp);
1178 fprintf (fbeleg, "\n Unsere Kontonummer .........: %s\n", valA[A_KTO]);
1179 fprintf (fbeleg, "\n Unsere Bankleitzahl ........: %s\n", valA[A_BLZ]);
1180 fprintf (fbeleg, "\n\n\n\n\n __________________________________________________\n");
1181 fprintf (fbeleg, " Ort, Datum Unterschrift\n");
1182 for (recindex=0; recindex<A_LEN; recindex++)
1184 free(valA[recindex]);