2 dtaus.c - Belegloser Datenträgeraustausch mit einer Bank
3 Copyright (c) 1996,8,2001,2,3 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)
277 strncpy(res, s, sizeof(res)-1);
278 res[sizeof(res)-1] = 0;
279 for (cp=res; *cp&&!(*cp == ',')&&!(*cp == '.');cp++);
281 if ((cp-res) >= (sizeof(res)-3)) {
282 /* Bail out, since the number is too large, shouldn't be possible though. */
283 fprintf (stderr, "Value %s too large.\n", res);
287 if (*cp == '.' || *cp == ',') {
289 /* 1st decimal place */
290 if (isdigit(*(cp+1)))
294 /* 2nd decimal place */
295 if (*(cp+1) && isdigit(*(cp+1)))
311 char *string2trans (char *s)
316 if (!strcmp(s, "04000"))
317 sprintf (res, "Abbuchung");
318 else if (!strcmp(s, "05000"))
319 sprintf (res, "Einzug");
320 else if (!strcmp(s, "05005"))
321 sprintf (res, "E-Cash");
322 else if (!strcmp(s, "05006"))
323 sprintf (res, "E-Cash-A");
324 else if (!strcmp(s, "51000"))
325 sprintf (res, "Gutschrift");
326 else if (!strcmp(s, "53000"))
327 sprintf (res, "Lohn");
328 else if (!strncmp(s, "5400", 4))
329 sprintf (res, "Vermögen");
330 /* else if (!strcmp(s, "56000"))
331 sprintf (res, ""); / * Überweisung öffentlicher Kassen */
335 char *trans2string (char *s)
340 if (!strcmp(s, "Abbuchung"))
341 sprintf (res, "04000");
342 else if (!strcmp(s, "Einzug"))
343 sprintf (res, "05000");
344 else if (!strcmp(s, "E-Cash"))
345 sprintf (res, "05005");
346 else if (!strcmp(s, "E-Cash-A"))
347 sprintf (res, "05006");
348 else if (!strcmp(s, "Gutschrift"))
349 sprintf (res, "51000");
350 else if (!strcmp(s, "Lohn"))
351 sprintf (res, "53000");
352 else if (!strncmp(s, "Vermögen", 4))
353 sprintf (res, "5400");
354 /* else if (!strcmp(s, ""))
355 sprintf (res, "56000"); / * Überweisung öffentlicher Kassen */
359 char *string2ext (char *s)
364 if (!strcmp(s, "01"))
365 sprintf (res, "Kunde");
366 else if (!strcmp(s, "02"))
367 sprintf (res, "Text");
368 else if (!strcmp(s, "03"))
369 sprintf (res, "Auftraggeber");
373 char *ext2string (char *s)
378 if (!strcmp(s, "Kunde"))
380 else if (!strcmp(s, "Text"))
382 else if (!strcmp(s, "Auftraggeber"))
387 unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
390 char *bufp = (char *)buf;
391 static unsigned long int res;
394 memcpy(tmp, bufp, len);
396 sscanf(tmp, "%lu", &res);
401 * returns the first word in this line, returns it and shortens the
404 char *extract_ident (char *line)
407 static char word[30];
409 if (strlen(line) > 0) {
410 x = strchr (line, ' ');
411 y = strchr (line, '\t');
414 strncpy(word, line, 29);
419 /* Check which index returns the lower value, and check if the
421 if ((c = (x && x<y)?x:(y?y:x))) {
422 strncpy(word, line, c - line);
424 for (;*c == '\t' || *c == ' '; c++);
425 for (x=line; *c; c++,x++)
428 strcpy(word, downcase(word));
437 * Pads a string with zero's on the left side.
439 char *padzeroclip (char *s, int len)
443 if (strlen(s) == len) return s;
444 if (strlen(s) > len) {
452 for (p=s+strlen(s)-1;p>=s;p--)
454 for (;q>=s;) *(q--)='0';
458 int rec_index(char *ident, int type)
461 dtaus_record *rec = NULL;
464 case REC_A: rec = recA; break;
465 case REC_C: rec = recC; break;
466 case REC_E: rec = recE; break;
469 for (i=0; (rec[i].name); i++) {
470 if (!strcmp(ident, downcase(rec[i].name)))
477 size_t control_nextline (void **buf, int len, FILE *f)
484 memset (line, 0, sizeof(line));
485 memset (buf, 0, len);
488 while (!strlen(line) && (cp = fgets(line, 100, f))) {
490 if (line[0] != '#') {
491 if (line[strlen(line)-1] != '\n') {
493 while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
495 line[strlen(line)-1] = '\0';
496 if (line[strlen(line)-1] == '\r')
497 line[strlen(line)-1] = '\0';
498 for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
506 for (cp=line; *cp==' '; cp++);
509 memcpy(buf, cp, strlen(cp));
521 timer = time ( NULL );
522 loctime = localtime(&timer);
523 sprintf(res, "%02d.%02d.%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
528 * Prepare a record A according to the specs.
529 * See dtaus.txt for explanation
531 void dtaus_prepareA (char *buf)
538 memset (buf, 0, 129);
539 timer = time ( NULL );
540 loctime = localtime(&timer);
547 for (i=15;i<15+8; i++) buf[i] = '0'; /* A5 */
548 sprintf(tmp, "%02d%02d%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
549 for (i=0; i<6; i++) buf[50+i] = tmp[i]; /* A7 (Date) */
550 for (i=56;i<56+4; i++) buf[i] = ' '; /* A8 */
551 for (i=70;i<70+10; i++) buf[i] = '0'; /* A10 */
552 for (i=80;i<80+48; i++) buf[i] = ' '; /* A11 */
554 buf[recA[A_CURR].pos] = '1'; /* A12 (Currency) */
556 buf[recA[A_CURR].pos] = ' '; /* A12 (Currency) */
560 * Prepare a record C according to the specs.
561 * See dtaus.txt for explanation
563 void dtaus_prepareC (char *buf, int normaltext, int maxtext)
568 memset (buf, 0, 257);
573 i = 187 + (appendix * 29);
575 /* Bail out if the number is too large, shouldn't be possible though */
579 buf[0] = (i/1000)+48;i-=(i/1000)*100;
580 buf[1] = (i/100)+48;i-=(i/100)*100;
581 buf[2] = (i/10)+48;i-=(i/10)*10;
585 for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */
586 buf[49] = ' '; /* C8 */
587 for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */
588 for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Betrag Euro) */
589 for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */
590 for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */
591 for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */
593 buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */
595 buf[recC[C_EURO].pos] = ' '; /* C17a (Currency) */
596 for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */
597 for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */
598 for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */
600 buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10;
601 buf[185+1] = appendix+48;
605 * Prepare a record E according to the specs.
606 * See dtaus.txt for explanation
608 void dtaus_prepareE (char *buf)
612 memset (buf, 0, 129);
618 for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */
619 for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */
620 for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */
621 for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */
624 int dtaus_writeA(FILE *f, char **values)
630 for (i=0; (recA[i].name); i++)
631 if ((recA[i].type == REQ) && !values[i]) {
632 fprintf (stderr, "Anfangsdatensatz ist nicht vollständig, kein %s.\n", recA[i].name);
635 if (!(((values[A_TRANS][0] == 'L')||(values[A_TRANS][0] == 'G'))
636 &&((values[A_TRANS][1] == 'B')||(values[A_TRANS][1] == 'K')))) {
637 fprintf (stderr, "Ungültiger Typ, nur LK, GK, LB oder GB erlaubt.\n");
641 i=A_NAME;if (values[i] && strlen(values[i]) > recA[i].len)
642 values[i][recA[i].len] = '\0';
645 buf[5] = values[A_TRANS][0];
646 buf[6] = values[A_TRANS][1];
647 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),recA[A_BLZ].len));
648 for (i=0; i<recA[A_BLZ].len; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
649 sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
650 for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
651 if (values[A_TODO]) {
652 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_TODO]),recA[A_TODO].len));
653 for (i=0; i<recA[A_TODO].len; i++) buf[recA[A_TODO].pos+i] = tmp[i];
655 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),recA[A_KTO].len));
656 for (i=0; i<recA[A_KTO].len; i++) buf[recA[A_KTO].pos+i] = tmp[i];
662 int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
672 if (text) for (maxtext=0;text[maxtext];maxtext++);
675 for (i=0; (recC[i].name); i++)
677 printf ("%s: %s\n", recC[i].name, values[i]);
680 for (i=0; (recC[i].name); i++)
681 if ((recC[i].type == REQ) && !values[i]) {
682 fprintf (stderr, "Datensatz ist nicht vollständig, kein %s.\n", recC[i].name);
685 sprintf (tmp, "%s", trans2string(values[C_TRANS]));
687 fprintf (stderr, "Ungültiger Typ, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
691 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
692 values[i][recC[i].len-2] = '\0';
693 i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
694 values[i][recC[i].len] = '\0';
695 i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
696 values[i][recC[i].len] = '\0';
697 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
698 values[i][recC[i].len] = '\0';
700 dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
701 for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
703 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8));
705 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_BLZ]),8));
706 for (i=0; i<recC[C_MYBLZ].len; i++) buf[5+i] = tmp[i];
707 for (i=0; i<recC[C_MYBLZ].len; i++) buf[recC[C_MYBLZ].pos+i] = tmp[i];
708 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_BLZ]),8));
709 for (i=0; i<recC[C_BLZ].len; i++) buf[recC[C_BLZ].pos+i] = tmp[i];
710 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
711 for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
712 sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
715 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
717 for (i=0; i<recC[C_EUR].len; i++) buf[recC[C_EUR].pos+i] = tmp[i];
720 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
722 for (i=0; i<recC[C_DM].len; i++) buf[recC[C_DM].pos+i] = tmp[i];
725 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
727 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_KTO]),10));
728 for (i=0; i<recC[C_MYKTO].len; i++) buf[recC[C_MYKTO].pos+i] = tmp[i];
729 sprintf (tmp, "%-27.27s", upcase(values[C_NAME]));
730 for (i=0; i<recC[C_NAME].len; i++) buf[recC[C_NAME].pos+i] = tmp[i];
732 sprintf (tmp, "%-27.27s", upcase(values[C_MYNAM]));
734 sprintf (tmp, "%-27.27s", upcase(valuesA[A_NAME]));
735 for (i=0; i<recC[C_MYNAM].len; i++) buf[recC[C_MYNAM].pos+i] = tmp[i];
736 sprintf (tmp, "%-27.27s", upcase(values[C_ZWECK]));
737 for (i=0; i<recC[C_ZWECK].len; i++) buf[recC[C_ZWECK].pos+i] = tmp[i];
739 if (values[C_TEXT]) {
740 buf[recC[C_TEXT].pos+0] = '0';
741 buf[recC[C_TEXT].pos+1] = '2';
742 sprintf (tmp, "%-27.27s", upcase(values[C_TEXT]));
743 for (i=0; i<recC[C_TEXT].len-2; i++) buf[recC[C_TEXT].pos+2+i] = tmp[i];
747 buf[recC[C_EXT].pos+0] = '0';
748 buf[recC[C_EXT].pos+1] = '2';
749 sprintf (tmp, "%-27.27s", upcase(text[0]));
750 for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
755 if (text && maxtext > 1) {
757 while (fieldnr<maxtext) {
758 memset (appendix, ' ', 128);
759 appendix[128] = '\0';
760 for (k=0; k<4 && (fieldnr+k)<maxtext; k++) {
761 sprintf (tmp, "%-27.27s", upcase(text[fieldnr+k]));
762 appendix[k*29] = '0';
763 appendix[(k*29)+1] = '2';
764 for (i=0; i<recC[C_TEXT].len-2; i++) appendix[(k*29)+2+i] = tmp[i];
774 int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
782 sprintf (tmp, "%07d", count);
783 for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
784 bigint_sprintf (tmp, "%s", sum);
785 padzeroclip (tmp,13);
788 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
790 for (i=0; i<recE[E_EUR].len; i++) buf[recE[E_EUR].pos+i] = tmp[i];
793 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
795 for (i=0; i<recE[E_DM].len; i++) buf[recE[E_DM].pos+i] = tmp[i];
797 bigint_sprintf (tmp, "%s", kto);
798 padzeroclip (tmp,17);
799 for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
800 bigint_sprintf (tmp, "%s", blz);
801 padzeroclip (tmp,17);
802 for (i=0; i<recE[E_BLZ].len; i++) buf[recE[E_BLZ].pos+i] = tmp[i];
808 void printctln(FILE *f, char *field, char *value)
810 if (strlen(field) && strlen(value))
811 fprintf(f, " %s\t%s\n", field, value);
815 * one date line, format it properly
817 void printctlndate(FILE *f, char *field, char *value)
822 if (!strlen(field) || !strlen(value))
825 for (i=0;isspace (value[i]) && i<= strlen (value); i++);
826 if (i == strlen (value))
829 memset (mydate, 0, sizeof (mydate));
830 if (strlen (value) == 6) {
831 mydate[0] = value[0];
832 mydate[1] = value[1];
834 mydate[3] = value[2];
835 mydate[4] = value[3];
837 mydate[6] = value[4];
838 mydate[7] = value[5];
839 fprintf(f, " %s\t%s\n", field, mydate);
840 } else if (strlen (value) == 8) {
841 mydate[0] = value[0];
842 mydate[1] = value[1];
844 mydate[3] = value[2];
845 mydate[4] = value[3];
847 mydate[6] = value[4];
848 mydate[7] = value[5];
849 mydate[8] = value[6];
850 mydate[9] = value[7];
851 fprintf(f, " %s\t%s\n", field, mydate);
853 fprintf (stderr, "Broken date field: %s\n", value);
854 fprintf(f, " %s\t%s\n", field, value);
860 * Third: Some high level routines
863 void dtaus2control (char *cdtaus, char *ccontrol)
865 FILE *fdtaus, *fcontrol;
875 if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
876 if (!(fdtaus = fopen("dtaus0.txt", "r")))
879 if (!strcmp (cdtaus, "-"))
882 if (!(fdtaus = fopen(cdtaus, "r")))
888 if (!strcmp (ccontrol, "-"))
891 if (!(fcontrol = fopen(ccontrol, "w")))
893 if (!(buf = (char *)malloc (512)))
899 if (dtaus_nextrec((void *)buf, fdtaus) == 1) {
900 if (dtaus_char(buf,4) == 'A') {
901 fprintf(fcontrol, "BEGIN {\n");
904 for (index=A_TRANS; index < A_LOOP; index++) {
905 bufp = buf + recA[index].pos;
906 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
907 if (index == A_DATE || index == A_TODO)
908 printctlndate(fcontrol, recA[index].name, tmp);
910 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
913 bufp = buf + recA[A_CURR].pos;
916 fprintf(fcontrol, " Euro\n");
919 fprintf(fcontrol, " DM\n");
922 fprintf(fcontrol, "}\n\n");
924 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz an.\n");
928 fprintf (stderr, "Der Anfangsdatensatz ist kaputt.\n");
935 if (dtaus_nextrec((void *)buf, fdtaus) == 1) {
936 while (dtaus_char(buf,4) == 'C') {
938 if (dtaus_nextrec((void *)bufp, fdtaus) != 1) {
939 fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
942 fprintf(fcontrol, "{\n");
944 for (index=C_NAME; index < C_LOOP; index++) {
946 if (use_euro && index == C_VAL)
949 if (!use_euro && index == C_VAL)
952 bufp = buf + recC[index].pos;
953 memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
956 * C_EUR and C_DM are outside of the loop, can only be
957 * selected for the non-default currency, but the value
958 * should be stored in the normal record field.
965 printctln(fcontrol, recC[C_VAL].name, strip_zeros(string2real(tmp)));
966 else if (index == C_VAL)
967 printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
968 else if (index == C_TRANS)
969 printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
971 printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
973 if (use_euro && index == C_EUR)
976 if (!use_euro && index == C_DM)
981 for (index=C_TEXT; index <= C_EXT; index++) {
982 if (!(dtaus_char(buf,recC[index].pos) == ' ')) {
983 bufp = buf + recC[index].pos;
984 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
985 memcpy(tmp, bufp, recC[index].len-2); tmp[recC[index].len-2] = '\0';
986 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
990 /* Number of extension records for this C record */
991 extC = dtaus_int(buf, 185, 2);
999 if (dtaus_nextrec((void *)buf, fdtaus) != 1)
1000 memset (buf, 0, sizeof(buf));
1003 * Are there extension records that we have to check?
1005 * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
1006 * instead of 00 we should let it in so it can read its own
1007 * old files... *sigh*
1009 while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') {
1010 for (index=0; index < 4; index++) {
1011 if ((dtaus_char(buf,index*29) != ' ')) {
1012 bufp = buf + index*29;
1013 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
1014 memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
1015 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
1018 if (dtaus_nextrec((void *)buf, fdtaus) != 1)
1019 memset (buf, 0, sizeof(buf));
1022 fprintf(fcontrol, "}\n");
1028 * (gelesen ist er eigentlich schon...)
1030 if (dtaus_char(buf,4) == 'E') {
1031 if (dtaus_char(buf,4) == 'E') {
1032 fprintf(fcontrol, "\nEND {\n");
1034 for (index=E_COUNT; index <= E_BLZ; index++) {
1035 #ifndef DEFAULT_EURO
1036 if (use_euro && index == E_VAL)
1039 if (!use_euro && index == E_VAL)
1043 bufp = buf + recE[index].pos;
1044 memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
1046 #ifndef DEFAULT_EURO
1047 if (index == E_VAL || index == E_EUR)
1049 if (index == E_VAL || index == E_DM)
1051 printctln(fcontrol, recE[E_VAL].name, strip_zeros(string2real(tmp)));
1053 printctln(fcontrol, recE[index].name, strip_zeros(tmp));
1054 #ifndef DEFAULT_EURO
1055 if (use_euro && index == E_EUR)
1058 if (!use_euro && index == E_DM)
1063 fprintf(fcontrol, "}\n");
1065 fprintf (stderr, "Das ist kein Abschlußdatensatz.\n");
1069 fprintf (stderr, "Der Abschlußdatensatz ist leer oder kaputt.\n");
1076 int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
1078 FILE *fdtaus, *fcontrol, *fbeleg, *fcheck;
1084 char *valA[A_LEN], *valC[C_LEN];
1086 bigint sum_val, sum_blz, sum_kto, bi;
1093 if (!(fdtaus = fopen("dtaus0.txt", "w")))
1096 if (!strcmp (cdtaus, "-"))
1099 if (!(fdtaus = fopen(cdtaus, "w")))
1103 if (!(fcontrol = fopen("dtaus0.ctl", "r")))
1104 if (!(fcontrol = fopen("DTAUS0.CTL", "r")))
1107 if (!strcmp (ccontrol, "-"))
1110 if (!(fcontrol = fopen(ccontrol, "r")))
1114 if (!(fbeleg = fopen("dtaus0.doc", "w")))
1117 if (!(fbeleg = fopen(cbeleg, "w")))
1123 if (!(fcheck = fopen(ccheck, "w")))
1127 if (!(buf = (char *)malloc (512)))
1133 memset (valA, 0, sizeof(valA));
1134 control_nextline ((void *)line, 100, fcontrol);
1135 ident = extract_ident(line);
1136 if (!strcmp(ident, "begin") && (line[0] == '{')) {
1137 control_nextline ((void *)line, 100, fcontrol);
1138 while (strlen(line) && line[0] != '}') {
1139 ident = extract_ident(line);
1140 if ((recindex = rec_index(ident, REC_A)) != -1)
1142 if (recA[recindex].type != IGN)
1143 if ((valA[recindex] = (char *)malloc (strlen(line)+1)))
1144 strcpy(valA[recindex], line);
1146 if (! strcasecmp (ident, "euro"))
1148 if (! strcasecmp (ident, "dm"))
1151 control_nextline ((void *)line, 100, fcontrol);
1153 if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
1154 fprintf(fbeleg, "\n\n");
1155 fprintf(fbeleg, "\n Begleitzettel\n\n");
1156 fprintf(fbeleg, "\n Belegloser Datentraegeraustausch\n\n");
1157 if (valA[recindex][0] == 'L')
1158 fprintf(fbeleg, "\n Sammeleinziehungsauftrag\n\n");
1159 else if (valA[recindex][0] == 'G')
1160 fprintf(fbeleg, "\n Sammelueberweisungsauftrag\n\n");
1162 fprintf(fbeleg, "\n Sammelauftrag\n\n");
1163 fprintf(fbeleg, "\n VOL ........................:\n");
1164 fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date());
1166 fprintf(fbeleg, "\n Ausfuehrugsdatum ...........: %s\n", valA[A_TODO]);
1169 fprintf(fbeleg, "\n Waehrung ...................: Euro\n");
1171 fprintf(fbeleg, "\n Waehrung ...................: DM\n");
1173 if (!dtaus_writeA(fdtaus, valA)) {
1174 fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
1178 fprintf (fcheck, "\n\n\n");
1179 if (valA[recindex][0] == 'L')
1180 fprintf (fcheck, " Sammeleinziehungsauftrag\n\n");
1181 else if (valA[recindex][0] == 'G')
1182 fprintf (fcheck, " Sammelueberweisungsauftrag\n\n");
1184 fprintf (fcheck, " Sammelauftrag\n\n");
1185 fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date());
1187 fprintf (fcheck, " Waehrung : Euro\n\n\n");
1189 fprintf (fcheck, " Waehrung : DM\n\n\n");
1190 fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
1191 fprintf (fcheck, " --------------------------------------------------------------------\n");
1193 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz (BEGIN) an.\n");
1201 sum_val = bigint_int(0);
1202 sum_blz = bigint_int(0);
1203 sum_kto = bigint_int(0);
1204 memset (valC, 0, sizeof(valC));
1205 control_nextline ((void *)line, 100, fcontrol);
1206 if (line[0] == '{') {
1207 while (strlen(line) && line[0] == '{') {
1208 control_nextline ((void *)line, 100, fcontrol);
1210 for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++)
1211 free (text[textindex]);
1215 while (strlen(line) && line[0] != '}') {
1216 ident = extract_ident(line);
1217 if ((recindex = rec_index(ident, REC_C)) != -1)
1218 if (recC[recindex].type != IGN) {
1220 * Special exception to support multiple Text fields
1222 if (recindex == C_TEXT && valC[recindex]) {
1224 if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL)
1228 memset (text, 0, (MAX_TEXT+1) * sizeof (char *));
1231 if (textindex < MAX_TEXT) {
1232 if ((cp = (char *)malloc (strlen (line) + 1))) {
1234 cp[strlen (line)] = '\0';
1235 text[textindex++] = cp;
1240 if (recindex == C_VAL) {
1241 /* Convert commast to dots for later processing */
1242 for (i=0; line[i]; i++) if (line[i] == ',') line[i] = '.';
1244 if ((cp = index (line, '.')) == NULL) {
1245 if (!(valC[recindex] = (char *)malloc (strlen(line)+4)))
1247 sprintf (valC[recindex], "%s.00", line);
1248 } else if ( ((len = cp - line + 3)) < strlen (line)) {
1249 if (!(valC[recindex] = (char *)malloc (len+1)))
1251 strncpy (valC[recindex], line, len);
1252 valC[recindex][len] = '\0';
1254 if (!(valC[recindex] = (char *)malloc (strlen(line)+1)))
1256 strcpy(valC[recindex], line);
1259 if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
1260 strcpy(valC[recindex], line);
1266 control_nextline ((void *)line, 100, fcontrol);
1268 if (!dtaus_writeC(fdtaus, valA, valC, text)) {
1269 fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n");
1273 bi = bigint_string(real2string(valC[C_VAL])); sum_val = bigint_add(sum_val, bi);
1274 bi = bigint_string(valC[C_BLZ]); sum_blz = bigint_add(sum_blz, bi);
1275 bi = bigint_string(valC[C_KTO]); sum_kto = bigint_add(sum_kto, bi);
1277 fprintf (fcheck, " %10s %8s %-30s %12s\n", valC[C_KTO], valC[C_BLZ], valC[C_NAME], valC[C_VAL]);
1278 for (recindex=0; recindex<C_LEN; recindex++)
1280 free(valC[recindex]);
1281 memset (valC, 0, sizeof(valC));
1282 control_nextline ((void *)line, 100, fcontrol);
1285 fprintf (stderr, "Kein regulärer Datensatz?\n");
1292 dtaus_writeE(fdtaus, count, sum_val, sum_blz, sum_kto);
1293 fprintf (fcheck, " --------------------------------------------------------------------\n");
1294 bigint_sprintf (tmp, "%s", sum_val);
1295 fprintf (fbeleg, "\n Anzahl .....................: %d\n", count);
1296 recindex=strlen(tmp);
1297 tmp[recindex+1] = '\0';
1298 tmp[recindex] = tmp[recindex-1];
1299 tmp[recindex-1] = tmp[recindex-2];
1300 tmp[recindex-2] = '.';
1301 fprintf (fcheck, " %-52s %14s\n", "Summe", tmp);
1302 fprintf (fbeleg, "\n Summe ......................: %s\n", tmp);
1303 bigint_sprintf (tmp, "%s", sum_kto);
1304 fprintf (fbeleg, "\n Kontrollsumme Kontonummern .: %s\n", tmp);
1305 bigint_sprintf (tmp, "%s", sum_blz);
1306 fprintf (fbeleg, "\n Kontrollsumme Bankleitzahlen: %s\n", tmp);
1307 fprintf (fbeleg, "\n Unsere Kontonummer .........: %s\n", valA[A_KTO]);
1308 fprintf (fbeleg, "\n Unsere Bankleitzahl ........: %s\n", valA[A_BLZ]);
1309 fprintf (fbeleg, "\n\n\n\n\n __________________________________________________\n");
1310 fprintf (fbeleg, " Ort, Datum Unterschrift\n");
1311 for (recindex=0; recindex<A_LEN; recindex++)
1313 free(valA[recindex]);