2 dtaus.c - Belegloser Datenträgeraustausch mit einer Bank
3 Copyright (c) 1996,8,2001,2 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.
39 * First: Some control structures
45 unsigned short int pos;
46 unsigned short int len;
58 dtaus_record recA[] = {
60 {"Name", 23, 27, REQ},
61 {"Konto", 60, 10, REQ},
63 {"Referenz", 70, 10, OPT},
64 {"Datum", 50, 6, IGN},
65 {"Ausfuehrung", 95, 8, OPT},
66 {"Currency", 127, 1, OPT},
67 {"Euro", 127, 1, OPT},
85 dtaus_record recC[] = {
86 {"Name", 93, 27, REQ},
87 {"Konto", 21, 10, REQ},
89 {"Transaktion", 44, 5, REQ},
91 {"Betrag", 50, 11, REQ},
93 {"Betrag", 79, 11, REQ},
95 {"Zweck", 155, 27, REQ},
96 {"myName", 128, 27, OPT},
97 {"myKonto", 69, 10, OPT},
98 {"myBLZ", 61, 8, OPT},
99 {"Text", 187, 29, OPT},
100 {"Extension", 216, 29, OPT},
101 {"Currency", 182, 1, IGN},
103 {"Betrag-Euro", 79, 11, IGN},
105 {"Betrag-DM", 50, 11, IGN},
132 dtaus_record recE[] = {
133 {"Anzahl", 10, 7, IGN},
135 {"Summe", 17, 13, IGN},
137 {"Summe", 64, 13, IGN},
139 {"Kontos", 30, 17, IGN},
140 {"BLZs", 47, 17, IGN},
142 {"Summe-Euro", 64, 13, IGN},
144 {"Summe-DM", 17, 13, IGN},
161 * Second: Some low level routines
164 size_t dtaus_nextrec (void **buf, FILE *f)
166 memset (buf, 0, 128);
167 return fread(buf, 128, 1, f);
170 char *upcase(char *s)
176 for (cp=s,xp=x; *cp; cp++,xp++) {
177 if (strchr(" 0123456789.,&-/+*$%ABCDEFGHIJKLMNOPQRSTUVWXYZ",*cp)) {
179 } else if (strchr("abcdefghijklmnopqrstuvwxyz",*cp)) {
181 } else if (strchr ("üÜäÄöÖß", *cp)) {
183 case 'ü': *(xp++) = 'U'; *xp='E'; break;
184 case 'Ü': *(xp++) = 'U'; *xp='E'; break;
185 case 'ä': *(xp++) = 'A'; *xp='E'; break;
186 case 'Ä': *(xp++) = 'A'; *xp='E'; break;
187 case 'ö': *(xp++) = 'O'; *xp='E'; break;
188 case 'Ö': *(xp++) = 'O'; *xp='E'; break;
189 case 'ß': *(xp++) = 'S'; *xp='S'; break;
193 * Filter out all other characters since credit institutes won't
194 * accept the file otherwise.
203 char *downcase(char *s)
208 memset (x, 0, sizeof (x));
217 char *strip_spaces (char *s)
222 for (i=strlen(s);(s[i-1] == ' '||s[i-1] == '\t')&&i>0; i--)
224 for (p=s; *p==' '; p++);
228 char *strip_zeros (char *s)
232 for (p=s; *p=='0'; p++);
236 char *strip_nondigits (char *s)
249 char dtaus_char (void *buf, unsigned int pos)
252 char *bufp = (char *)buf;
255 memcpy(&res, bufp, 1);
259 char *string2real(char *s)
265 strncpy(res, s, strlen(s)-2);
266 res[strlen(s)-2] = '.';
267 res[strlen(s)-1] = s[strlen(s)-2];
268 res[strlen(s)] = s[strlen(s)-1];
272 char *real2string(char *s)
278 for (cp=res; *cp&&!(*cp == ',')&&!(*cp == '.');cp++);
285 char *string2trans (char *s)
290 if (!strcmp(s, "04000"))
291 sprintf (res, "Abbuchung");
292 else if (!strcmp(s, "05000"))
293 sprintf (res, "Einzug");
294 else if (!strcmp(s, "05005"))
295 sprintf (res, "E-Cash");
296 else if (!strcmp(s, "05006"))
297 sprintf (res, "E-Cash-A");
298 else if (!strcmp(s, "51000"))
299 sprintf (res, "Gutschrift");
300 else if (!strcmp(s, "53000"))
301 sprintf (res, "Lohn");
302 else if (!strncmp(s, "5400", 4))
303 sprintf (res, "Vermögen");
304 /* else if (!strcmp(s, "56000"))
305 sprintf (res, ""); / * Überweisung öffentlicher Kassen */
309 char *trans2string (char *s)
314 if (!strcmp(s, "Abbuchung"))
315 sprintf (res, "04000");
316 else if (!strcmp(s, "Einzug"))
317 sprintf (res, "05000");
318 else if (!strcmp(s, "E-Cash"))
319 sprintf (res, "05005");
320 else if (!strcmp(s, "E-Cash-A"))
321 sprintf (res, "05006");
322 else if (!strcmp(s, "Gutschrift"))
323 sprintf (res, "51000");
324 else if (!strcmp(s, "Lohn"))
325 sprintf (res, "53000");
326 else if (!strncmp(s, "Vermögen", 4))
327 sprintf (res, "5400");
328 /* else if (!strcmp(s, ""))
329 sprintf (res, "56000"); / * Überweisung öffentlicher Kassen */
333 char *string2ext (char *s)
338 if (!strcmp(s, "01"))
339 sprintf (res, "Kunde");
340 else if (!strcmp(s, "02"))
341 sprintf (res, "Text");
342 else if (!strcmp(s, "03"))
343 sprintf (res, "Auftraggeber");
347 char *ext2string (char *s)
352 if (!strcmp(s, "Kunde"))
354 else if (!strcmp(s, "Text"))
356 else if (!strcmp(s, "Auftraggeber"))
361 unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
364 char *bufp = (char *)buf;
365 static unsigned long int res;
368 memcpy(tmp, bufp, len);
370 sscanf(tmp, "%lu", &res);
375 * returns the first word in this line, returns it and shortens the
378 char *extract_ident (char *line)
381 static char word[30];
383 if (strlen(line) > 0) {
384 x = strchr (line, ' ');
385 y = strchr (line, '\t');
388 strncpy(word, line, 29);
393 /* Check which index returns the lower value, and check if the
395 if ((c = (x && x<y)?x:(y?y:x))) {
396 strncpy(word, line, c - line);
398 for (;*c == '\t' || *c == ' '; c++);
399 for (x=line; *c; c++,x++)
402 strcpy(word, downcase(word));
411 * Pads a string with zero's on the left side.
413 char *padzeroclip (char *s, int len)
417 if (strlen(s) == len) return s;
418 if (strlen(s) > len) {
426 for (p=s+strlen(s)-1;p>=s;p--)
428 for (;q>=s;) *(q--)='0';
432 int rec_index(char *ident, int type)
435 dtaus_record *rec = NULL;
438 case REC_A: rec = recA; break;
439 case REC_C: rec = recC; break;
440 case REC_E: rec = recE; break;
443 for (i=0; (rec[i].name); i++) {
444 if (!strcmp(ident, downcase(rec[i].name)))
451 size_t control_nextline (void **buf, int len, FILE *f)
458 memset (line, 0, sizeof(line));
459 memset (buf, 0, len);
462 while (!strlen(line) && (cp = fgets(line, 100, f))) {
464 if (line[0] != '#') {
465 if (line[strlen(line)-1] != '\n') {
467 while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
469 line[strlen(line)-1] = '\0';
470 if (line[strlen(line)-1] == '\r')
471 line[strlen(line)-1] = '\0';
472 for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
480 for (cp=line; *cp==' '; cp++);
483 memcpy(buf, cp, strlen(cp));
495 timer = time ( NULL );
496 loctime = localtime(&timer);
497 sprintf(res, "%02d.%02d.%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
502 * Prepare a record A according to the specs.
503 * See dtaus.txt for explanation
505 void dtaus_prepareA (char *buf)
512 memset (buf, 0, 129);
513 timer = time ( NULL );
514 loctime = localtime(&timer);
521 for (i=15;i<15+8; i++) buf[i] = '0'; /* A5 */
522 sprintf(tmp, "%02d%02d%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
523 for (i=0; i<6; i++) buf[50+i] = tmp[i]; /* A7 (Date) */
524 for (i=56;i<56+4; i++) buf[i] = ' '; /* A8 */
525 for (i=70;i<70+10; i++) buf[i] = '0'; /* A10 */
526 for (i=80;i<80+48; i++) buf[i] = ' '; /* A11 */
528 buf[recA[A_CURR].pos] = '1'; /* A12 (Currency) */
530 buf[recA[A_CURR].pos] = ' '; /* A12 (Currency) */
534 * Prepare a record C according to the specs.
535 * See dtaus.txt for explanation
537 void dtaus_prepareC (char *buf, int normaltext, int maxtext)
542 memset (buf, 0, 257);
547 i = 187 + (appendix * 29);
549 /* Bail out if the number is too large, shouldn't be possible though */
553 buf[0] = (i/1000)+48;i-=(i/1000)*100;
554 buf[1] = (i/100)+48;i-=(i/100)*100;
555 buf[2] = (i/10)+48;i-=(i/10)*10;
559 for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */
560 buf[49] = ' '; /* C8 */
561 for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */
562 for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Betrag Euro) */
563 for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */
564 for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */
565 for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */
567 buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */
569 buf[recC[C_EURO].pos] = ' '; /* C17a (Currency) */
570 for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */
571 for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */
572 for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */
574 buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10;
575 buf[185+1] = appendix+48;
579 * Prepare a record E according to the specs.
580 * See dtaus.txt for explanation
582 void dtaus_prepareE (char *buf)
586 memset (buf, 0, 129);
592 for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */
593 for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */
594 for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */
595 for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */
598 int dtaus_writeA(FILE *f, char **values)
604 for (i=0; (recA[i].name); i++)
605 if ((recA[i].type == REQ) && !values[i]) {
606 fprintf (stderr, "Anfangsdatensatz ist nicht vollständig, kein %s.\n", recA[i].name);
609 if (!(((values[A_TRANS][0] == 'L')||(values[A_TRANS][0] == 'G'))
610 &&((values[A_TRANS][1] == 'B')||(values[A_TRANS][1] == 'K')))) {
611 fprintf (stderr, "Ungültiger Typ, nur LK, GK, LB oder GB erlaubt.\n");
615 i=A_NAME;if (values[i] && strlen(values[i]) > recA[i].len)
616 values[i][recA[i].len] = '\0';
619 buf[5] = values[A_TRANS][0];
620 buf[6] = values[A_TRANS][1];
621 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),recA[A_BLZ].len));
622 for (i=0; i<recA[A_BLZ].len; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
623 sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
624 for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
625 if (values[A_TODO]) {
626 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_TODO]),recA[A_TODO].len));
627 for (i=0; i<recA[A_TODO].len; i++) buf[recA[A_TODO].pos+i] = tmp[i];
629 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),recA[A_KTO].len));
630 for (i=0; i<recA[A_KTO].len; i++) buf[recA[A_KTO].pos+i] = tmp[i];
636 int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
646 if (text) for (maxtext=0;text[maxtext];maxtext++);
649 for (i=0; (recC[i].name); i++)
651 printf ("%s: %s\n", recC[i].name, values[i]);
654 for (i=0; (recC[i].name); i++)
655 if ((recC[i].type == REQ) && !values[i]) {
656 fprintf (stderr, "Datensatz ist nicht vollständig, kein %s.\n", recC[i].name);
659 sprintf (tmp, "%s", trans2string(values[C_TRANS]));
661 fprintf (stderr, "Ungültiger Typ, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
665 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
666 values[i][recC[i].len-2] = '\0';
667 i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
668 values[i][recC[i].len] = '\0';
669 i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
670 values[i][recC[i].len] = '\0';
671 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
672 values[i][recC[i].len] = '\0';
674 dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
675 for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
677 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8));
679 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_BLZ]),8));
680 for (i=0; i<recC[C_MYBLZ].len; i++) buf[5+i] = tmp[i];
681 for (i=0; i<recC[C_MYBLZ].len; i++) buf[recC[C_MYBLZ].pos+i] = tmp[i];
682 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_BLZ]),8));
683 for (i=0; i<recC[C_BLZ].len; i++) buf[recC[C_BLZ].pos+i] = tmp[i];
684 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
685 for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
686 sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
689 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
691 for (i=0; i<recC[C_EUR].len; i++) buf[recC[C_EUR].pos+i] = tmp[i];
694 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
696 for (i=0; i<recC[C_DM].len; i++) buf[recC[C_DM].pos+i] = tmp[i];
699 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
701 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_KTO]),10));
702 for (i=0; i<recC[C_MYKTO].len; i++) buf[recC[C_MYKTO].pos+i] = tmp[i];
703 sprintf (tmp, "%-27.27s", upcase(values[C_NAME]));
704 for (i=0; i<recC[C_NAME].len; i++) buf[recC[C_NAME].pos+i] = tmp[i];
706 sprintf (tmp, "%-27.27s", upcase(values[C_MYNAM]));
708 sprintf (tmp, "%-27.27s", upcase(valuesA[A_NAME]));
709 for (i=0; i<recC[C_MYNAM].len; i++) buf[recC[C_MYNAM].pos+i] = tmp[i];
710 sprintf (tmp, "%-27.27s", upcase(values[C_ZWECK]));
711 for (i=0; i<recC[C_ZWECK].len; i++) buf[recC[C_ZWECK].pos+i] = tmp[i];
713 if (values[C_TEXT]) {
714 buf[recC[C_TEXT].pos+0] = '0';
715 buf[recC[C_TEXT].pos+1] = '2';
716 sprintf (tmp, "%-27.27s", upcase(values[C_TEXT]));
717 for (i=0; i<recC[C_TEXT].len-2; i++) buf[recC[C_TEXT].pos+2+i] = tmp[i];
721 buf[recC[C_EXT].pos+0] = '0';
722 buf[recC[C_EXT].pos+1] = '2';
723 sprintf (tmp, "%-27.27s", upcase(text[0]));
724 for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
729 if (text && maxtext > 1) {
731 while (fieldnr<maxtext) {
732 memset (appendix, ' ', 128);
733 appendix[128] = '\0';
734 for (k=0; k<4 && (fieldnr+k)<maxtext; k++) {
735 sprintf (tmp, "%-27.27s", upcase(text[fieldnr+k]));
736 appendix[k*29] = '0';
737 appendix[(k*29)+1] = '2';
738 for (i=0; i<recC[C_TEXT].len-2; i++) appendix[(k*29)+2+i] = tmp[i];
748 int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
756 sprintf (tmp, "%07d", count);
757 for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
758 bigint_sprintf (tmp, "%s", sum);
759 padzeroclip (tmp,13);
762 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
764 for (i=0; i<recE[E_EUR].len; i++) buf[recE[E_EUR].pos+i] = tmp[i];
767 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
769 for (i=0; i<recE[E_DM].len; i++) buf[recE[E_DM].pos+i] = tmp[i];
771 bigint_sprintf (tmp, "%s", kto);
772 padzeroclip (tmp,17);
773 for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
774 bigint_sprintf (tmp, "%s", blz);
775 padzeroclip (tmp,17);
776 for (i=0; i<recE[E_BLZ].len; i++) buf[recE[E_BLZ].pos+i] = tmp[i];
782 void printctln(FILE *f, char *field, char *value)
784 if (strlen(field) && strlen(value))
785 fprintf(f, " %s\t%s\n", field, value);
789 * one date line, format it properly
791 void printctlndate(FILE *f, char *field, char *value)
796 if (!strlen(field) || !strlen(value))
799 for (i=0;isspace (value[i]) && i<= strlen (value); i++);
800 if (i == strlen (value))
803 memset (mydate, 0, sizeof (mydate));
804 if (strlen (value) == 6) {
805 mydate[0] = value[0];
806 mydate[1] = value[1];
808 mydate[3] = value[2];
809 mydate[4] = value[3];
811 mydate[6] = value[4];
812 mydate[7] = value[5];
813 fprintf(f, " %s\t%s\n", field, mydate);
814 } else if (strlen (value) == 8) {
815 mydate[0] = value[0];
816 mydate[1] = value[1];
818 mydate[3] = value[2];
819 mydate[4] = value[3];
821 mydate[6] = value[4];
822 mydate[7] = value[5];
823 mydate[8] = value[6];
824 mydate[9] = value[7];
825 fprintf(f, " %s\t%s\n", field, mydate);
827 fprintf (stderr, "Broken date field: %s\n", value);
828 fprintf(f, " %s\t%s\n", field, value);
834 * Third: Some high level routines
837 void dtaus2control (char *cdtaus, char *ccontrol)
839 FILE *fdtaus, *fcontrol;
849 if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
850 if (!(fdtaus = fopen("dtaus0.txt", "r")))
853 if (!strcmp (cdtaus, "-"))
856 if (!(fdtaus = fopen(cdtaus, "r")))
862 if (!strcmp (ccontrol, "-"))
865 if (!(fcontrol = fopen(ccontrol, "w")))
867 if (!(buf = (char *)malloc (512)))
873 if (dtaus_nextrec(buf, fdtaus) == 1) {
874 if (dtaus_char(buf,4) == 'A') {
875 fprintf(fcontrol, "BEGIN {\n");
878 for (index=A_TRANS; index < A_LOOP; index++) {
879 bufp = buf + recA[index].pos;
880 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
881 if (index == A_DATE || index == A_TODO)
882 printctlndate(fcontrol, recA[index].name, tmp);
884 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
887 bufp = buf + recA[A_CURR].pos;
890 fprintf(fcontrol, " Euro\n");
893 fprintf(fcontrol, " DM\n");
896 fprintf(fcontrol, "}\n\n");
898 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz an.\n");
902 fprintf (stderr, "Der Anfangsdatensatz ist kaputt.\n");
909 if (dtaus_nextrec(buf, fdtaus) == 1) {
910 while (dtaus_char(buf,4) == 'C') {
912 if (dtaus_nextrec(bufp, fdtaus) != 1) {
913 fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
916 fprintf(fcontrol, "{\n");
918 for (index=C_NAME; index < C_LOOP; index++) {
920 if (use_euro && index == C_VAL)
923 if (!use_euro && index == C_VAL)
926 bufp = buf + recC[index].pos;
927 memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
930 * C_EUR and C_DM are outside of the loop, can only be
931 * selected for the non-default currency, but the value
932 * should be stored in the normal record field.
939 printctln(fcontrol, recC[C_VAL].name, strip_zeros(string2real(tmp)));
940 else if (index == C_VAL)
941 printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
942 else if (index == C_TRANS)
943 printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
945 printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
947 if (use_euro && index == C_EUR)
950 if (!use_euro && index == C_DM)
955 for (index=C_TEXT; index <= C_EXT; index++) {
956 if (!(dtaus_char(buf,recC[index].pos) == ' ')) {
957 bufp = buf + recC[index].pos;
958 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
959 memcpy(tmp, bufp, recC[index].len-2); tmp[recC[index].len-2] = '\0';
960 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
964 /* Number of extension records for this C record */
965 extC = dtaus_int(buf, 185, 2);
973 if (dtaus_nextrec(buf, fdtaus) != 1)
974 memset (buf, 0, sizeof(buf));
977 * Are there extension records that we have to check?
979 * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
980 * instead of 00 we should let it in so it can read its own
981 * old files... *sigh*
983 while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') {
984 for (index=0; index < 4; index++) {
985 if ((dtaus_char(buf,index*29) != ' ')) {
986 bufp = buf + index*29;
987 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
988 memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
989 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
992 if (dtaus_nextrec(buf, fdtaus) != 1)
993 memset (buf, 0, sizeof(buf));
996 fprintf(fcontrol, "}\n");
1002 * (gelesen ist er eigentlich schon...)
1004 if (dtaus_char(buf,4) == 'E') {
1005 if (dtaus_char(buf,4) == 'E') {
1006 fprintf(fcontrol, "\nEND {\n");
1008 for (index=E_COUNT; index <= E_BLZ; index++) {
1009 #ifndef DEFAULT_EURO
1010 if (use_euro && index == E_VAL)
1013 if (!use_euro && index == E_VAL)
1017 bufp = buf + recE[index].pos;
1018 memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
1020 #ifndef DEFAULT_EURO
1021 if (index == E_VAL || index == E_EUR)
1023 if (index == E_VAL || index == E_DM)
1025 printctln(fcontrol, recE[E_VAL].name, strip_zeros(string2real(tmp)));
1027 printctln(fcontrol, recE[index].name, strip_zeros(tmp));
1028 #ifndef DEFAULT_EURO
1029 if (use_euro && index == E_EUR)
1032 if (!use_euro && index == E_DM)
1037 fprintf(fcontrol, "}\n");
1039 fprintf (stderr, "Das ist kein Abschlußdatensatz.\n");
1043 fprintf (stderr, "Der Abschlußdatensatz ist leer oder kaputt.\n");
1050 int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
1052 FILE *fdtaus, *fcontrol, *fbeleg, *fcheck;
1058 char *valA[A_LEN], *valC[C_LEN];
1060 bigint sum_val, sum_blz, sum_kto, bi;
1067 if (!(fdtaus = fopen("dtaus0.txt", "w")))
1070 if (!strcmp (cdtaus, "-"))
1073 if (!(fdtaus = fopen(cdtaus, "w")))
1077 if (!(fcontrol = fopen("dtaus0.ctl", "r")))
1078 if (!(fcontrol = fopen("DTAUS0.CTL", "r")))
1081 if (!strcmp (ccontrol, "-"))
1084 if (!(fcontrol = fopen(ccontrol, "r")))
1088 if (!(fbeleg = fopen("dtaus0.doc", "w")))
1091 if (!(fbeleg = fopen(cbeleg, "w")))
1097 if (!(fcheck = fopen(ccheck, "w")))
1101 if (!(buf = (char *)malloc (512)))
1107 memset (valA, 0, sizeof(valA));
1108 control_nextline ((void *)line, 100, fcontrol);
1109 ident = extract_ident(line);
1110 if (!strcmp(ident, "begin") && (line[0] == '{')) {
1111 control_nextline ((void *)line, 100, fcontrol);
1112 while (strlen(line) && line[0] != '}') {
1113 ident = extract_ident(line);
1114 if ((recindex = rec_index(ident, REC_A)) != -1)
1116 if (recA[recindex].type != IGN)
1117 if ((valA[recindex] = (char *)malloc (strlen(line)+1)))
1118 strcpy(valA[recindex], line);
1120 if (! strcasecmp (ident, "euro"))
1122 if (! strcasecmp (ident, "dm"))
1125 control_nextline ((void *)line, 100, fcontrol);
1127 if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
1128 fprintf(fbeleg, "\n\n");
1129 fprintf(fbeleg, "\n Begleitzettel\n\n");
1130 fprintf(fbeleg, "\n Belegloser Datentraegeraustausch\n\n");
1131 if (valA[recindex][0] == 'L')
1132 fprintf(fbeleg, "\n Sammeleinziehungsauftrag\n\n");
1133 else if (valA[recindex][0] == 'G')
1134 fprintf(fbeleg, "\n Sammelueberweisungsauftrag\n\n");
1136 fprintf(fbeleg, "\n Sammelauftrag\n\n");
1137 fprintf(fbeleg, "\n VOL ........................:\n");
1138 fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date());
1140 fprintf(fbeleg, "\n Ausfuehrugsdatum ...........: %s\n", valA[A_TODO]);
1143 fprintf(fbeleg, "\n Waehrung ...................: Euro\n");
1145 fprintf(fbeleg, "\n Waehrung ...................: DM\n");
1147 if (!dtaus_writeA(fdtaus, valA)) {
1148 fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
1152 fprintf (fcheck, "\n\n\n");
1153 if (valA[recindex][0] == 'L')
1154 fprintf (fcheck, " Sammeleinziehungsauftrag\n\n");
1155 else if (valA[recindex][0] == 'G')
1156 fprintf (fcheck, " Sammelueberweisungsauftrag\n\n");
1158 fprintf (fcheck, " Sammelauftrag\n\n");
1159 fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date());
1161 fprintf (fcheck, " Waehrung : Euro\n\n\n");
1163 fprintf (fcheck, " Waehrung : DM\n\n\n");
1164 fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
1165 fprintf (fcheck, " --------------------------------------------------------------------\n");
1167 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz (BEGIN) an.\n");
1175 sum_val = bigint_int(0);
1176 sum_blz = bigint_int(0);
1177 sum_kto = bigint_int(0);
1178 memset (valC, 0, sizeof(valC));
1179 control_nextline ((void *)line, 100, fcontrol);
1180 if (line[0] == '{') {
1181 while (strlen(line) && line[0] == '{') {
1182 control_nextline ((void *)line, 100, fcontrol);
1184 for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++)
1185 free (text[textindex]);
1189 while (strlen(line) && line[0] != '}') {
1190 ident = extract_ident(line);
1191 if ((recindex = rec_index(ident, REC_C)) != -1)
1192 if (recC[recindex].type != IGN) {
1194 * Special exception to support multiple Text fields
1196 if (recindex == C_TEXT && valC[recindex]) {
1198 if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL)
1202 memset (text, 0, (MAX_TEXT+1) * sizeof (char *));
1205 if (textindex < MAX_TEXT) {
1206 if ((cp = (char *)malloc (strlen (line) + 1))) {
1208 cp[strlen (line)] = '\0';
1209 text[textindex++] = cp;
1214 if (recindex == C_VAL) {
1215 /* Convert commast to dots for later processing */
1216 for (i=0; line[i]; i++) if (line[i] == ',') line[i] = '.';
1218 if ((cp = index (line, '.')) == NULL) {
1219 if (!(valC[recindex] = (char *)malloc (strlen(line)+4)))
1221 sprintf (valC[recindex], "%s.00", line);
1222 } else if ( ((len = cp - line + 3)) < strlen (line)) {
1223 if (!(valC[recindex] = (char *)malloc (len+1)))
1225 strncpy (valC[recindex], line, len);
1226 valC[recindex][len] = '\0';
1228 if (!(valC[recindex] = (char *)malloc (strlen(line)+1)))
1230 strcpy(valC[recindex], line);
1233 if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
1234 strcpy(valC[recindex], line);
1240 control_nextline ((void *)line, 100, fcontrol);
1242 if (!dtaus_writeC(fdtaus, valA, valC, text)) {
1243 fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n");
1247 bi = bigint_string(real2string(valC[C_VAL])); sum_val = bigint_add(sum_val, bi);
1248 bi = bigint_string(valC[C_BLZ]); sum_blz = bigint_add(sum_blz, bi);
1249 bi = bigint_string(valC[C_KTO]); sum_kto = bigint_add(sum_kto, bi);
1251 fprintf (fcheck, " %10s %8s %-30s %12s\n", valC[C_KTO], valC[C_BLZ], valC[C_NAME], valC[C_VAL]);
1252 for (recindex=0; recindex<C_LEN; recindex++)
1254 free(valC[recindex]);
1255 memset (valC, 0, sizeof(valC));
1256 control_nextline ((void *)line, 100, fcontrol);
1259 fprintf (stderr, "Kein regulärer Datensatz?\n");
1266 dtaus_writeE(fdtaus, count, sum_val, sum_blz, sum_kto);
1267 fprintf (fcheck, " --------------------------------------------------------------------\n");
1268 bigint_sprintf (tmp, "%s", sum_val);
1269 fprintf (fbeleg, "\n Anzahl .....................: %d\n", count);
1270 recindex=strlen(tmp);
1271 tmp[recindex+1] = '\0';
1272 tmp[recindex] = tmp[recindex-1];
1273 tmp[recindex-1] = tmp[recindex-2];
1274 tmp[recindex-2] = '.';
1275 fprintf (fcheck, " %-52s %14s\n", "Summe", tmp);
1276 fprintf (fbeleg, "\n Summe ......................: %s\n", tmp);
1277 bigint_sprintf (tmp, "%s", sum_kto);
1278 fprintf (fbeleg, "\n Kontrollsumme Kontonummern .: %s\n", tmp);
1279 bigint_sprintf (tmp, "%s", sum_blz);
1280 fprintf (fbeleg, "\n Kontrollsumme Bankleitzahlen: %s\n", tmp);
1281 fprintf (fbeleg, "\n Unsere Kontonummer .........: %s\n", valA[A_KTO]);
1282 fprintf (fbeleg, "\n Unsere Bankleitzahl ........: %s\n", valA[A_BLZ]);
1283 fprintf (fbeleg, "\n\n\n\n\n __________________________________________________\n");
1284 fprintf (fbeleg, " Ort, Datum Unterschrift\n");
1285 for (recindex=0; recindex<A_LEN; recindex++)
1287 free(valA[recindex]);