2 dtaus.c - Belegloser Datenträgeraustausch mit einer Bank
3 Copyright (c) 1996,8,2001-4 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)))
312 * Return the last digit of the year as character
314 char get_date_lastdigit()
319 timer = time ( NULL );
320 loctime = localtime(&timer);
321 return loctime->tm_year % 10 + '0';
324 char *string2trans (char *s)
329 if (!strcmp(s, "04000"))
330 sprintf (res, "Abbuchung");
331 else if (!strcmp(s, "05000"))
332 sprintf (res, "Einzug");
333 else if (!strcmp(s, "05005"))
334 sprintf (res, "E-Cash");
335 else if (!strcmp(s, "05006"))
336 sprintf (res, "E-Cash-A");
337 else if (!strcmp(s, "51000"))
338 sprintf (res, "Gutschrift");
339 else if (!strcmp(s, "53000"))
340 sprintf (res, "Lohn");
341 else if (!strncmp(s, "5400", 4))
342 sprintf (res, "Vermögen %c",s[4]);
343 /* else if (!strcmp(s, "56000"))
344 sprintf (res, ""); / * Überweisung öffentlicher Kassen */
348 char *trans2string (char *s)
354 if (!strcmp(s, "Abbuchung"))
355 sprintf (res, "04000");
356 else if (!strcmp(s, "Einzug"))
357 sprintf (res, "05000");
358 else if (!strcmp(s, "E-Cash"))
359 sprintf (res, "05005");
360 else if (!strcmp(s, "E-Cash-A"))
361 sprintf (res, "05006");
362 else if (!strcmp(s, "Gutschrift"))
363 sprintf (res, "51000");
364 else if (!strcmp(s, "Lohn"))
365 sprintf (res, "53000");
368 if (!strncmp(s, "Vermögen", 8))
370 if (!strncmp(s, "Vermoegen", 9))
374 fprintf (stderr, "Unbekannte Transaktion `%s'\n", res);
379 Vermögen --> 5400<heutiges Jahr>
380 Vermögen 8 -> 5400<8>
381 Vermögen 2003 -> 5400<3>
384 if (*cp) while (!isspace(*cp)) cp++;
385 while (isspace(*cp)) cp++;
387 if (!*cp || !isdigit(*cp))
388 sprintf (res, "5400%c",get_date_lastdigit());
390 while (isdigit(*cp)) cp++;
391 sprintf (res, "5400%c",*(cp-1));
394 /* else if (!strcmp(s, ""))
395 sprintf (res, "56000"); / * Überweisung öffentlicher Kassen */
399 char *string2ext (char *s)
404 if (!strcmp(s, "01"))
405 sprintf (res, "Kunde");
406 else if (!strcmp(s, "02"))
407 sprintf (res, "Text");
408 else if (!strcmp(s, "03"))
409 sprintf (res, "Auftraggeber");
413 char *ext2string (char *s)
418 if (!strcmp(s, "Kunde"))
420 else if (!strcmp(s, "Text"))
422 else if (!strcmp(s, "Auftraggeber"))
427 unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
430 char *bufp = (char *)buf;
431 static unsigned long int res;
434 memcpy(tmp, bufp, len);
436 sscanf(tmp, "%lu", &res);
441 * returns the first word in this line, returns it and shortens the
444 char *extract_ident (char *line)
447 static char word[30];
449 if (strlen(line) > 0) {
450 x = strchr (line, ' ');
451 y = strchr (line, '\t');
454 strncpy(word, line, 29);
459 /* Check which index returns the lower value, and check if the
461 if ((c = (x && x<y)?x:(y?y:x))) {
462 strncpy(word, line, c - line);
464 for (;*c == '\t' || *c == ' '; c++);
465 for (x=line; *c; c++,x++)
468 strcpy(word, downcase(word));
477 * Pads a string with zero's on the left side.
479 char *padzeroclip (char *s, int len)
483 if (strlen(s) == len) return s;
484 if (strlen(s) > len) {
492 for (p=s+strlen(s)-1;p>=s;p--)
494 for (;q>=s;) *(q--)='0';
498 int rec_index(char *ident, int type)
501 dtaus_record *rec = NULL;
504 case REC_A: rec = recA; break;
505 case REC_C: rec = recC; break;
506 case REC_E: rec = recE; break;
509 for (i=0; (rec[i].name); i++) {
510 if (!strcmp(ident, downcase(rec[i].name)))
517 size_t control_nextline (void **buf, int len, FILE *f)
524 memset (line, 0, sizeof(line));
525 memset (buf, 0, len);
528 while (!strlen(line) && (cp = fgets(line, 100, f))) {
530 if (line[0] != '#') {
531 if (line[strlen(line)-1] != '\n') {
533 while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
535 line[strlen(line)-1] = '\0';
536 if (line[strlen(line)-1] == '\r')
537 line[strlen(line)-1] = '\0';
538 for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
546 for (cp=line; *cp==' '; cp++);
549 memcpy(buf, cp, strlen(cp));
556 * Return the current date nicely formatted
564 timer = time ( NULL );
565 loctime = localtime(&timer);
566 sprintf(res, "%02d.%02d.%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
571 * Prepare a record A according to the specs.
572 * See dtaus.txt for explanation
574 void dtaus_prepareA (char *buf)
581 memset (buf, 0, 129);
582 timer = time ( NULL );
583 loctime = localtime(&timer);
590 for (i=15;i<15+8; i++) buf[i] = '0'; /* A5 */
591 sprintf(tmp, "%02d%02d%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
592 for (i=0; i<6; i++) buf[50+i] = tmp[i]; /* A7 (Date) */
593 for (i=56;i<56+4; i++) buf[i] = ' '; /* A8 */
594 for (i=70;i<70+10; i++) buf[i] = '0'; /* A10 */
595 for (i=80;i<80+48; i++) buf[i] = ' '; /* A11 */
597 buf[recA[A_CURR].pos] = '1'; /* A12 (Currency) */
599 buf[recA[A_CURR].pos] = ' '; /* A12 (Currency) */
603 * Prepare a record C according to the specs.
604 * See dtaus.txt for explanation
606 void dtaus_prepareC (char *buf, int normaltext, int maxtext)
611 memset (buf, 0, 257);
616 i = 187 + (appendix * 29);
618 /* Bail out if the number is too large, shouldn't be possible though */
622 buf[0] = (i/1000)+48;i-=(i/1000)*100;
623 buf[1] = (i/100)+48;i-=(i/100)*100;
624 buf[2] = (i/10)+48;i-=(i/10)*10;
628 for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */
629 buf[49] = ' '; /* C8 */
630 for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */
631 for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Betrag Euro) */
632 for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */
633 for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */
634 for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */
636 buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */
638 buf[recC[C_EURO].pos] = ' '; /* C17a (Currency) */
639 for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */
640 for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */
641 for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */
643 buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10;
644 buf[185+1] = appendix+48;
648 * Prepare a record E according to the specs.
649 * See dtaus.txt for explanation
651 void dtaus_prepareE (char *buf)
655 memset (buf, 0, 129);
661 for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */
662 for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */
663 for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */
664 for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */
667 int dtaus_writeA(FILE *f, char **values)
673 for (i=0; (recA[i].name); i++)
674 if ((recA[i].type == REQ) && !values[i]) {
675 fprintf (stderr, "Anfangsdatensatz ist nicht vollständig, kein %s.\n", recA[i].name);
678 if (!(((values[A_TRANS][0] == 'L')||(values[A_TRANS][0] == 'G'))
679 &&((values[A_TRANS][1] == 'B')||(values[A_TRANS][1] == 'K')))) {
680 fprintf (stderr, "Ungültiger Typ, nur LK, GK, LB oder GB erlaubt.\n");
684 i=A_NAME;if (values[i] && strlen(values[i]) > recA[i].len)
685 values[i][recA[i].len] = '\0';
688 buf[5] = values[A_TRANS][0];
689 buf[6] = values[A_TRANS][1];
690 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),recA[A_BLZ].len));
691 for (i=0; i<recA[A_BLZ].len; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
692 sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
693 for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
694 if (values[A_TODO]) {
695 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_TODO]),recA[A_TODO].len));
696 for (i=0; i<recA[A_TODO].len; i++) buf[recA[A_TODO].pos+i] = tmp[i];
698 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),recA[A_KTO].len));
699 for (i=0; i<recA[A_KTO].len; i++) buf[recA[A_KTO].pos+i] = tmp[i];
705 int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
715 if (text) for (maxtext=0;text[maxtext];maxtext++);
718 for (i=0; (recC[i].name); i++)
720 printf ("%s: %s\n", recC[i].name, values[i]);
723 for (i=0; (recC[i].name); i++)
724 if ((recC[i].type == REQ) && !values[i]) {
725 fprintf (stderr, "Datensatz ist nicht vollständig, kein %s.\n", recC[i].name);
728 sprintf (tmp, "%s", trans2string(values[C_TRANS]));
730 fprintf (stderr, "Ungültige Transaktion, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
734 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
735 values[i][recC[i].len-2] = '\0';
736 i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
737 values[i][recC[i].len] = '\0';
738 i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
739 values[i][recC[i].len] = '\0';
740 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
741 values[i][recC[i].len] = '\0';
743 dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
744 for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
746 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8));
748 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_BLZ]),8));
749 for (i=0; i<recC[C_MYBLZ].len; i++) buf[5+i] = tmp[i];
750 for (i=0; i<recC[C_MYBLZ].len; i++) buf[recC[C_MYBLZ].pos+i] = tmp[i];
751 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_BLZ]),8));
752 for (i=0; i<recC[C_BLZ].len; i++) buf[recC[C_BLZ].pos+i] = tmp[i];
753 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
754 for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
755 sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
758 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
760 for (i=0; i<recC[C_EUR].len; i++) buf[recC[C_EUR].pos+i] = tmp[i];
763 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
765 for (i=0; i<recC[C_DM].len; i++) buf[recC[C_DM].pos+i] = tmp[i];
768 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
770 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_KTO]),10));
771 for (i=0; i<recC[C_MYKTO].len; i++) buf[recC[C_MYKTO].pos+i] = tmp[i];
772 sprintf (tmp, "%-27.27s", upcase(values[C_NAME]));
773 for (i=0; i<recC[C_NAME].len; i++) buf[recC[C_NAME].pos+i] = tmp[i];
775 sprintf (tmp, "%-27.27s", upcase(values[C_MYNAM]));
777 sprintf (tmp, "%-27.27s", upcase(valuesA[A_NAME]));
778 for (i=0; i<recC[C_MYNAM].len; i++) buf[recC[C_MYNAM].pos+i] = tmp[i];
779 sprintf (tmp, "%-27.27s", upcase(values[C_ZWECK]));
780 for (i=0; i<recC[C_ZWECK].len; i++) buf[recC[C_ZWECK].pos+i] = tmp[i];
782 if (values[C_TEXT]) {
783 buf[recC[C_TEXT].pos+0] = '0';
784 buf[recC[C_TEXT].pos+1] = '2';
785 sprintf (tmp, "%-27.27s", upcase(values[C_TEXT]));
786 for (i=0; i<recC[C_TEXT].len-2; i++) buf[recC[C_TEXT].pos+2+i] = tmp[i];
790 buf[recC[C_EXT].pos+0] = '0';
791 buf[recC[C_EXT].pos+1] = '2';
792 sprintf (tmp, "%-27.27s", upcase(text[0]));
793 for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
798 if (text && maxtext > 1) {
800 while (fieldnr<maxtext) {
801 memset (appendix, ' ', 128);
802 appendix[128] = '\0';
803 for (k=0; k<4 && (fieldnr+k)<maxtext; k++) {
804 sprintf (tmp, "%-27.27s", upcase(text[fieldnr+k]));
805 appendix[k*29] = '0';
806 appendix[(k*29)+1] = '2';
807 for (i=0; i<recC[C_TEXT].len-2; i++) appendix[(k*29)+2+i] = tmp[i];
817 int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
825 sprintf (tmp, "%07d", count);
826 for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
827 bigint_sprintf (tmp, "%s", sum);
828 padzeroclip (tmp,13);
831 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
833 for (i=0; i<recE[E_EUR].len; i++) buf[recE[E_EUR].pos+i] = tmp[i];
836 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
838 for (i=0; i<recE[E_DM].len; i++) buf[recE[E_DM].pos+i] = tmp[i];
840 bigint_sprintf (tmp, "%s", kto);
841 padzeroclip (tmp,17);
842 for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
843 bigint_sprintf (tmp, "%s", blz);
844 padzeroclip (tmp,17);
845 for (i=0; i<recE[E_BLZ].len; i++) buf[recE[E_BLZ].pos+i] = tmp[i];
851 void printctln(FILE *f, char *field, char *value)
853 if (strlen(field) && strlen(value))
854 fprintf(f, " %s\t%s\n", field, value);
858 * one date line, format it properly
860 void printctlndate(FILE *f, char *field, char *value)
865 if (!strlen(field) || !strlen(value))
868 for (i=0;isspace (value[i]) && i<= strlen (value); i++);
869 if (i == strlen (value))
872 memset (mydate, 0, sizeof (mydate));
873 if (strlen (value) == 6) {
874 mydate[0] = value[0];
875 mydate[1] = value[1];
877 mydate[3] = value[2];
878 mydate[4] = value[3];
880 mydate[6] = value[4];
881 mydate[7] = value[5];
882 fprintf(f, " %s\t%s\n", field, mydate);
883 } else if (strlen (value) == 8) {
884 mydate[0] = value[0];
885 mydate[1] = value[1];
887 mydate[3] = value[2];
888 mydate[4] = value[3];
890 mydate[6] = value[4];
891 mydate[7] = value[5];
892 mydate[8] = value[6];
893 mydate[9] = value[7];
894 fprintf(f, " %s\t%s\n", field, mydate);
896 fprintf (stderr, "Broken date field: %s\n", value);
897 fprintf(f, " %s\t%s\n", field, value);
903 * Third: Some high level routines
906 void dtaus2control (char *cdtaus, char *ccontrol)
908 FILE *fdtaus, *fcontrol;
918 if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
919 if (!(fdtaus = fopen("dtaus0.txt", "r")))
922 if (!strcmp (cdtaus, "-"))
925 if (!(fdtaus = fopen(cdtaus, "r")))
931 if (!strcmp (ccontrol, "-"))
934 if (!(fcontrol = fopen(ccontrol, "w")))
936 if (!(buf = (char *)malloc (512)))
942 if (dtaus_nextrec((void *)buf, fdtaus) == 1) {
943 if (dtaus_char(buf,4) == 'A') {
944 fprintf(fcontrol, "BEGIN {\n");
947 for (index=A_TRANS; index < A_LOOP; index++) {
948 bufp = buf + recA[index].pos;
949 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
950 if (index == A_DATE || index == A_TODO)
951 printctlndate(fcontrol, recA[index].name, tmp);
953 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
956 bufp = buf + recA[A_CURR].pos;
959 fprintf(fcontrol, " Euro\n");
962 fprintf(fcontrol, " DM\n");
965 fprintf(fcontrol, "}\n\n");
967 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz an.\n");
971 fprintf (stderr, "Der Anfangsdatensatz ist kaputt.\n");
978 if (dtaus_nextrec((void *)buf, fdtaus) == 1) {
979 while (dtaus_char(buf,4) == 'C') {
981 if (dtaus_nextrec((void *)bufp, fdtaus) != 1) {
982 fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
985 fprintf(fcontrol, "{\n");
987 for (index=C_NAME; index < C_LOOP; index++) {
989 if (use_euro && index == C_VAL)
992 if (!use_euro && index == C_VAL)
995 bufp = buf + recC[index].pos;
996 memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
999 * C_EUR and C_DM are outside of the loop, can only be
1000 * selected for the non-default currency, but the value
1001 * should be stored in the normal record field.
1003 #ifndef DEFAULT_EURO
1008 printctln(fcontrol, recC[C_VAL].name, strip_zeros(string2real(tmp)));
1009 else if (index == C_VAL)
1010 printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
1011 else if (index == C_TRANS)
1012 printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
1014 printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
1015 #ifndef DEFAULT_EURO
1016 if (use_euro && index == C_EUR)
1019 if (!use_euro && index == C_DM)
1024 for (index=C_TEXT; index <= C_EXT; index++) {
1025 if (!(dtaus_char(buf,recC[index].pos) == ' ')) {
1026 bufp = buf + recC[index].pos;
1027 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
1028 memcpy(tmp, bufp, recC[index].len-2); tmp[recC[index].len-2] = '\0';
1029 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
1033 /* Number of extension records for this C record */
1034 extC = dtaus_int(buf, 185, 2);
1037 res = div (extC, 4);
1039 if (res.rem) extC++;
1042 if (dtaus_nextrec((void *)buf, fdtaus) != 1)
1043 memset (buf, 0, sizeof(buf));
1046 * Are there extension records that we have to check?
1048 * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
1049 * instead of 00 we should let it in so it can read its own
1050 * old files... *sigh*
1052 while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') {
1053 for (index=0; index < 4; index++) {
1054 if ((dtaus_char(buf,index*29) != ' ')) {
1055 bufp = buf + index*29;
1056 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
1057 memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
1058 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
1061 if (dtaus_nextrec((void *)buf, fdtaus) != 1)
1062 memset (buf, 0, sizeof(buf));
1065 fprintf(fcontrol, "}\n");
1071 * (gelesen ist er eigentlich schon...)
1073 if (dtaus_char(buf,4) == 'E') {
1074 if (dtaus_char(buf,4) == 'E') {
1075 fprintf(fcontrol, "\nEND {\n");
1077 for (index=E_COUNT; index <= E_BLZ; index++) {
1078 #ifndef DEFAULT_EURO
1079 if (use_euro && index == E_VAL)
1082 if (!use_euro && index == E_VAL)
1086 bufp = buf + recE[index].pos;
1087 memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
1089 #ifndef DEFAULT_EURO
1090 if (index == E_VAL || index == E_EUR)
1092 if (index == E_VAL || index == E_DM)
1094 printctln(fcontrol, recE[E_VAL].name, strip_zeros(string2real(tmp)));
1096 printctln(fcontrol, recE[index].name, strip_zeros(tmp));
1097 #ifndef DEFAULT_EURO
1098 if (use_euro && index == E_EUR)
1101 if (!use_euro && index == E_DM)
1106 fprintf(fcontrol, "}\n");
1108 fprintf (stderr, "Das ist kein Abschlußdatensatz.\n");
1112 fprintf (stderr, "Der Abschlußdatensatz ist leer oder kaputt.\n");
1119 int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
1121 FILE *fdtaus, *fcontrol, *fbeleg, *fcheck;
1127 char *valA[A_LEN], *valC[C_LEN];
1129 bigint sum_val, sum_blz, sum_kto, bi;
1136 if (!(fdtaus = fopen("dtaus0.txt", "w")))
1139 if (!strcmp (cdtaus, "-"))
1142 if (!(fdtaus = fopen(cdtaus, "w")))
1146 if (!(fcontrol = fopen("dtaus0.ctl", "r")))
1147 if (!(fcontrol = fopen("DTAUS0.CTL", "r")))
1150 if (!strcmp (ccontrol, "-"))
1153 if (!(fcontrol = fopen(ccontrol, "r")))
1157 if (!(fbeleg = fopen("dtaus0.doc", "w")))
1160 if (!(fbeleg = fopen(cbeleg, "w")))
1166 if (!(fcheck = fopen(ccheck, "w")))
1170 if (!(buf = (char *)malloc (512)))
1176 memset (valA, 0, sizeof(valA));
1177 control_nextline ((void *)line, 100, fcontrol);
1178 ident = extract_ident(line);
1179 if (!strcmp(ident, "begin") && (line[0] == '{')) {
1180 control_nextline ((void *)line, 100, fcontrol);
1181 while (strlen(line) && line[0] != '}') {
1182 ident = extract_ident(line);
1183 if ((recindex = rec_index(ident, REC_A)) != -1)
1185 if (recA[recindex].type != IGN)
1186 if ((valA[recindex] = (char *)malloc (strlen(line)+1)))
1187 strcpy(valA[recindex], line);
1189 if (! strcasecmp (ident, "euro"))
1191 if (! strcasecmp (ident, "dm"))
1194 control_nextline ((void *)line, 100, fcontrol);
1196 if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
1197 fprintf(fbeleg, "\n\n");
1198 fprintf(fbeleg, "\n Begleitzettel\n\n");
1199 fprintf(fbeleg, "\n Belegloser Datentraegeraustausch\n\n");
1200 if (valA[recindex][0] == 'L')
1201 fprintf(fbeleg, "\n Sammeleinziehungsauftrag\n\n");
1202 else if (valA[recindex][0] == 'G')
1203 fprintf(fbeleg, "\n Sammelueberweisungsauftrag\n\n");
1205 fprintf(fbeleg, "\n Sammelauftrag\n\n");
1206 fprintf(fbeleg, "\n VOL ........................:\n");
1207 fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date());
1209 fprintf(fbeleg, "\n Ausfuehrungsdatum ..........: %s\n", valA[A_TODO]);
1212 fprintf(fbeleg, "\n Waehrung ...................: Euro\n");
1214 fprintf(fbeleg, "\n Waehrung ...................: DM\n");
1216 if (!dtaus_writeA(fdtaus, valA)) {
1217 fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
1221 fprintf (fcheck, "\n\n\n");
1222 if (valA[recindex][0] == 'L')
1223 fprintf (fcheck, " Sammeleinziehungsauftrag\n\n");
1224 else if (valA[recindex][0] == 'G')
1225 fprintf (fcheck, " Sammelueberweisungsauftrag\n\n");
1227 fprintf (fcheck, " Sammelauftrag\n\n");
1228 fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date());
1230 fprintf (fcheck, " Waehrung : Euro\n\n\n");
1232 fprintf (fcheck, " Waehrung : DM\n\n\n");
1233 fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
1234 fprintf (fcheck, " --------------------------------------------------------------------\n");
1236 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz (BEGIN) an.\n");
1244 sum_val = bigint_int(0);
1245 sum_blz = bigint_int(0);
1246 sum_kto = bigint_int(0);
1247 memset (valC, 0, sizeof(valC));
1248 control_nextline ((void *)line, 100, fcontrol);
1249 if (line[0] == '{') {
1250 while (strlen(line) && line[0] == '{') {
1251 control_nextline ((void *)line, 100, fcontrol);
1253 for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++)
1254 free (text[textindex]);
1258 while (strlen(line) && line[0] != '}') {
1259 ident = extract_ident(line);
1260 if ((recindex = rec_index(ident, REC_C)) != -1)
1261 if (recC[recindex].type != IGN) {
1263 * Special exception to support multiple Text fields
1265 if (recindex == C_TEXT && valC[recindex]) {
1267 if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL)
1271 memset (text, 0, (MAX_TEXT+1) * sizeof (char *));
1274 if (textindex < MAX_TEXT) {
1275 if ((cp = (char *)malloc (strlen (line) + 1))) {
1277 cp[strlen (line)] = '\0';
1278 text[textindex++] = cp;
1283 if (recindex == C_VAL) {
1284 /* Convert commast to dots for later processing */
1285 for (i=0; line[i]; i++) if (line[i] == ',') line[i] = '.';
1287 if ((cp = index (line, '.')) == NULL) {
1288 if (!(valC[recindex] = (char *)malloc (strlen(line)+4)))
1290 sprintf (valC[recindex], "%s.00", line);
1291 } else if ( ((len = cp - line + 3)) < strlen (line)) {
1292 if (!(valC[recindex] = (char *)malloc (len+1)))
1294 strncpy (valC[recindex], line, len);
1295 valC[recindex][len] = '\0';
1297 if (!(valC[recindex] = (char *)malloc (strlen(line)+1)))
1299 strcpy(valC[recindex], line);
1302 if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
1303 strcpy(valC[recindex], line);
1309 control_nextline ((void *)line, 100, fcontrol);
1311 if (!dtaus_writeC(fdtaus, valA, valC, text)) {
1312 fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n");
1316 bi = bigint_string(real2string(valC[C_VAL])); sum_val = bigint_add(sum_val, bi);
1317 bi = bigint_string(valC[C_BLZ]); sum_blz = bigint_add(sum_blz, bi);
1318 bi = bigint_string(valC[C_KTO]); sum_kto = bigint_add(sum_kto, bi);
1320 fprintf (fcheck, " %10s %8s %-30s %12s\n", valC[C_KTO], valC[C_BLZ], valC[C_NAME], valC[C_VAL]);
1321 for (recindex=0; recindex<C_LEN; recindex++)
1323 free(valC[recindex]);
1324 memset (valC, 0, sizeof(valC));
1325 control_nextline ((void *)line, 100, fcontrol);
1328 fprintf (stderr, "Kein regulärer Datensatz?\n");
1335 dtaus_writeE(fdtaus, count, sum_val, sum_blz, sum_kto);
1336 fprintf (fcheck, " --------------------------------------------------------------------\n");
1337 bigint_sprintf (tmp, "%s", sum_val);
1338 fprintf (fbeleg, "\n Anzahl .....................: %d\n", count);
1339 recindex=strlen(tmp);
1340 tmp[recindex+1] = '\0';
1341 tmp[recindex] = tmp[recindex-1];
1342 tmp[recindex-1] = tmp[recindex-2];
1343 tmp[recindex-2] = '.';
1344 fprintf (fcheck, " %-52s %14s\n", "Summe", tmp);
1345 fprintf (fbeleg, "\n Summe ......................: %s\n", tmp);
1346 bigint_sprintf (tmp, "%s", sum_kto);
1347 fprintf (fbeleg, "\n Kontrollsumme Kontonummern .: %s\n", tmp);
1348 bigint_sprintf (tmp, "%s", sum_blz);
1349 fprintf (fbeleg, "\n Kontrollsumme Bankleitzahlen: %s\n", tmp);
1350 fprintf (fbeleg, "\n Unsere Kontonummer .........: %s\n", valA[A_KTO]);
1351 fprintf (fbeleg, "\n Unsere Bankleitzahl ........: %s\n", valA[A_BLZ]);
1352 fprintf (fbeleg, "\n\n\n\n\n __________________________________________________\n");
1353 fprintf (fbeleg, " Ort, Datum Unterschrift\n");
1354 for (recindex=0; recindex<A_LEN; recindex++)
1356 free(valA[recindex]);