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)
276 char *xp; /* only to avoid a GCC warning */
278 strncpy(res, s, sizeof(res)-1);
279 res[sizeof(res)-1] = 0;
280 for (cp=res; *cp&&!(*cp == ',')&&!(*cp == '.');cp++);
282 if ((cp-res) >= (sizeof(res)-3)) {
283 /* Bail out, since the number is too large, shouldn't be possible though. */
284 fprintf (stderr, "Value %s too large.\n", res);
288 if (*cp == '.' || *cp == ',') {
290 /* 1st decimal place */
292 if (*xp && isdigit(*xp))
296 /* 2nd decimal place */
298 if (*xp && isdigit(*xp))
315 * Return the last digit of the year as character
317 char get_date_lastdigit()
322 timer = time ( NULL );
323 loctime = localtime(&timer);
324 return loctime->tm_year % 10 + '0';
327 char *string2trans (char *s)
332 if (!strcmp(s, "04000"))
333 sprintf (res, "Abbuchung");
334 else if (!strcmp(s, "05000"))
335 sprintf (res, "Einzug");
336 else if (!strcmp(s, "05005"))
337 sprintf (res, "E-Cash");
338 else if (!strcmp(s, "05006"))
339 sprintf (res, "E-Cash-A");
340 else if (!strcmp(s, "51000"))
341 sprintf (res, "Gutschrift");
342 else if (!strcmp(s, "53000"))
343 sprintf (res, "Lohn");
344 else if (!strncmp(s, "5400", 4))
345 sprintf (res, "Vermögen %c",s[4]);
346 /* else if (!strcmp(s, "56000"))
347 sprintf (res, ""); / * Überweisung öffentlicher Kassen */
351 char *trans2string (char *s)
357 if (!strcmp(s, "Abbuchung"))
358 sprintf (res, "04000");
359 else if (!strcmp(s, "Einzug"))
360 sprintf (res, "05000");
361 else if (!strcmp(s, "E-Cash"))
362 sprintf (res, "05005");
363 else if (!strcmp(s, "E-Cash-A"))
364 sprintf (res, "05006");
365 else if (!strcmp(s, "Gutschrift"))
366 sprintf (res, "51000");
367 else if (!strcmp(s, "Lohn"))
368 sprintf (res, "53000");
371 if (!strncmp(s, "Vermögen", 8))
373 if (!strncmp(s, "Vermoegen", 9))
377 fprintf (stderr, "Unbekannte Transaktion `%s'\n", res);
382 Vermögen --> 5400<heutiges Jahr>
383 Vermögen 8 -> 5400<8>
384 Vermögen 2003 -> 5400<3>
387 if (*cp) while (!isspace(*cp)) cp++;
388 while (isspace(*cp)) cp++;
390 if (!*cp || !isdigit(*cp))
391 sprintf (res, "5400%c",get_date_lastdigit());
393 while (isdigit(*cp)) cp++;
394 sprintf (res, "5400%c",*(cp-1));
397 /* else if (!strcmp(s, ""))
398 sprintf (res, "56000"); / * Überweisung öffentlicher Kassen */
402 char *string2ext (char *s)
407 if (!strcmp(s, "01"))
408 sprintf (res, "Kunde");
409 else if (!strcmp(s, "02"))
410 sprintf (res, "Text");
411 else if (!strcmp(s, "03"))
412 sprintf (res, "Auftraggeber");
416 char *ext2string (char *s)
421 if (!strcmp(s, "Kunde"))
423 else if (!strcmp(s, "Text"))
425 else if (!strcmp(s, "Auftraggeber"))
430 unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
433 char *bufp = (char *)buf;
434 static unsigned long int res;
437 memcpy(tmp, bufp, len);
439 sscanf(tmp, "%lu", &res);
444 * returns the first word in this line, returns it and shortens the
447 char *extract_ident (char *line)
450 static char word[30];
452 if (strlen(line) > 0) {
453 x = strchr (line, ' ');
454 y = strchr (line, '\t');
457 strncpy(word, line, 29);
462 /* Check which index returns the lower value, and check if the
464 if ((c = (x && x<y)?x:(y?y:x))) {
465 strncpy(word, line, c - line);
467 for (;*c == '\t' || *c == ' '; c++);
468 for (x=line; *c; c++,x++)
471 strcpy(word, downcase(word));
480 * Pads a string with zero's on the left side.
482 char *padzeroclip (char *s, int len)
486 if (strlen(s) == len) return s;
487 if (strlen(s) > len) {
495 for (p=s+strlen(s)-1;p>=s;p--)
497 for (;q>=s;) *(q--)='0';
501 int rec_index(char *ident, int type)
504 dtaus_record *rec = NULL;
507 case REC_A: rec = recA; break;
508 case REC_C: rec = recC; break;
509 case REC_E: rec = recE; break;
512 for (i=0; (rec[i].name); i++) {
513 if (!strcmp(ident, downcase(rec[i].name)))
520 size_t control_nextline (void **buf, int len, FILE *f)
527 memset (line, 0, sizeof(line));
528 memset (buf, 0, len);
531 while (!strlen(line) && (cp = fgets(line, 100, f))) {
533 if (line[0] != '#') {
534 if (line[strlen(line)-1] != '\n') {
536 while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
538 line[strlen(line)-1] = '\0';
539 if (line[strlen(line)-1] == '\r')
540 line[strlen(line)-1] = '\0';
541 for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
549 for (cp=line; *cp==' '; cp++);
552 memcpy(buf, cp, strlen(cp));
559 * Return the current date nicely formatted
567 timer = time ( NULL );
568 loctime = localtime(&timer);
569 sprintf(res, "%02d.%02d.%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
574 * Prepare a record A according to the specs.
575 * See dtaus.txt for explanation
577 void dtaus_prepareA (char *buf)
584 memset (buf, 0, 129);
585 timer = time ( NULL );
586 loctime = localtime(&timer);
593 for (i=15;i<15+8; i++) buf[i] = '0'; /* A5 */
594 sprintf(tmp, "%02d%02d%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100);
595 for (i=0; i<6; i++) buf[50+i] = tmp[i]; /* A7 (Date) */
596 for (i=56;i<56+4; i++) buf[i] = ' '; /* A8 */
597 for (i=70;i<70+10; i++) buf[i] = '0'; /* A10 */
598 for (i=80;i<80+48; i++) buf[i] = ' '; /* A11 */
600 buf[recA[A_CURR].pos] = '1'; /* A12 (Currency) */
602 buf[recA[A_CURR].pos] = ' '; /* A12 (Currency) */
606 * Prepare a record C according to the specs.
607 * See dtaus.txt for explanation
609 void dtaus_prepareC (char *buf, int normaltext, int maxtext)
614 memset (buf, 0, 257);
619 i = 187 + (appendix * 29);
621 /* Bail out if the number is too large, shouldn't be possible though */
625 buf[0] = (i/1000)+48;i-=(i/1000)*100;
626 buf[1] = (i/100)+48;i-=(i/100)*100;
627 buf[2] = (i/10)+48;i-=(i/10)*10;
631 for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */
632 buf[49] = ' '; /* C8 */
633 for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */
634 for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Betrag Euro) */
635 for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */
636 for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */
637 for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */
639 buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */
641 buf[recC[C_EURO].pos] = ' '; /* C17a (Currency) */
642 for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */
643 for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */
644 for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */
646 buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10;
647 buf[185+1] = appendix+48;
651 * Prepare a record E according to the specs.
652 * See dtaus.txt for explanation
654 void dtaus_prepareE (char *buf)
658 memset (buf, 0, 129);
664 for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */
665 for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */
666 for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */
667 for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */
670 int dtaus_writeA(FILE *f, char **values)
676 for (i=0; (recA[i].name); i++)
677 if ((recA[i].type == REQ) && !values[i]) {
678 fprintf (stderr, "Anfangsdatensatz ist nicht vollständig, kein %s.\n", recA[i].name);
681 if (!(((values[A_TRANS][0] == 'L')||(values[A_TRANS][0] == 'G'))
682 &&((values[A_TRANS][1] == 'B')||(values[A_TRANS][1] == 'K')))) {
683 fprintf (stderr, "Ungültiger Typ, nur LK, GK, LB oder GB erlaubt.\n");
687 i=A_NAME;if (values[i] && strlen(values[i]) > recA[i].len)
688 values[i][recA[i].len] = '\0';
691 buf[5] = values[A_TRANS][0];
692 buf[6] = values[A_TRANS][1];
693 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),recA[A_BLZ].len));
694 for (i=0; i<recA[A_BLZ].len; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
695 sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
696 for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
697 if (values[A_TODO]) {
698 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_TODO]),recA[A_TODO].len));
699 for (i=0; i<recA[A_TODO].len; i++) buf[recA[A_TODO].pos+i] = tmp[i];
701 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),recA[A_KTO].len));
702 for (i=0; i<recA[A_KTO].len; i++) buf[recA[A_KTO].pos+i] = tmp[i];
708 int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
718 if (text) for (maxtext=0;text[maxtext];maxtext++);
721 for (i=0; (recC[i].name); i++)
723 printf ("%s: %s\n", recC[i].name, values[i]);
726 for (i=0; (recC[i].name); i++)
727 if ((recC[i].type == REQ) && !values[i]) {
728 fprintf (stderr, "Datensatz ist nicht vollständig, kein %s.\n", recC[i].name);
731 sprintf (tmp, "%s", trans2string(values[C_TRANS]));
733 fprintf (stderr, "Ungültige Transaktion, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
737 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
738 values[i][recC[i].len-2] = '\0';
739 i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
740 values[i][recC[i].len] = '\0';
741 i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
742 values[i][recC[i].len] = '\0';
743 i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
744 values[i][recC[i].len] = '\0';
746 dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
747 for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
749 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8));
751 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_BLZ]),8));
752 for (i=0; i<recC[C_MYBLZ].len; i++) buf[5+i] = tmp[i];
753 for (i=0; i<recC[C_MYBLZ].len; i++) buf[recC[C_MYBLZ].pos+i] = tmp[i];
754 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_BLZ]),8));
755 for (i=0; i<recC[C_BLZ].len; i++) buf[recC[C_BLZ].pos+i] = tmp[i];
756 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
757 for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
758 sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
761 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
763 for (i=0; i<recC[C_EUR].len; i++) buf[recC[C_EUR].pos+i] = tmp[i];
766 for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
768 for (i=0; i<recC[C_DM].len; i++) buf[recC[C_DM].pos+i] = tmp[i];
771 sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
773 sprintf (tmp, "%s", padzeroclip (strip_nondigits (valuesA[A_KTO]),10));
774 for (i=0; i<recC[C_MYKTO].len; i++) buf[recC[C_MYKTO].pos+i] = tmp[i];
775 sprintf (tmp, "%-27.27s", upcase(values[C_NAME]));
776 for (i=0; i<recC[C_NAME].len; i++) buf[recC[C_NAME].pos+i] = tmp[i];
778 sprintf (tmp, "%-27.27s", upcase(values[C_MYNAM]));
780 sprintf (tmp, "%-27.27s", upcase(valuesA[A_NAME]));
781 for (i=0; i<recC[C_MYNAM].len; i++) buf[recC[C_MYNAM].pos+i] = tmp[i];
782 sprintf (tmp, "%-27.27s", upcase(values[C_ZWECK]));
783 for (i=0; i<recC[C_ZWECK].len; i++) buf[recC[C_ZWECK].pos+i] = tmp[i];
785 if (values[C_TEXT]) {
786 buf[recC[C_TEXT].pos+0] = '0';
787 buf[recC[C_TEXT].pos+1] = '2';
788 sprintf (tmp, "%-27.27s", upcase(values[C_TEXT]));
789 for (i=0; i<recC[C_TEXT].len-2; i++) buf[recC[C_TEXT].pos+2+i] = tmp[i];
793 buf[recC[C_EXT].pos+0] = '0';
794 buf[recC[C_EXT].pos+1] = '2';
795 sprintf (tmp, "%-27.27s", upcase(text[0]));
796 for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
801 if (text && maxtext > 1) {
803 while (fieldnr<maxtext) {
804 memset (appendix, ' ', 128);
805 appendix[128] = '\0';
806 for (k=0; k<4 && (fieldnr+k)<maxtext; k++) {
807 sprintf (tmp, "%-27.27s", upcase(text[fieldnr+k]));
808 appendix[k*29] = '0';
809 appendix[(k*29)+1] = '2';
810 for (i=0; i<recC[C_TEXT].len-2; i++) appendix[(k*29)+2+i] = tmp[i];
820 int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
828 sprintf (tmp, "%07d", count);
829 for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
830 bigint_sprintf (tmp, "%s", sum);
831 padzeroclip (tmp,13);
834 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
836 for (i=0; i<recE[E_EUR].len; i++) buf[recE[E_EUR].pos+i] = tmp[i];
839 for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
841 for (i=0; i<recE[E_DM].len; i++) buf[recE[E_DM].pos+i] = tmp[i];
843 bigint_sprintf (tmp, "%s", kto);
844 padzeroclip (tmp,17);
845 for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
846 bigint_sprintf (tmp, "%s", blz);
847 padzeroclip (tmp,17);
848 for (i=0; i<recE[E_BLZ].len; i++) buf[recE[E_BLZ].pos+i] = tmp[i];
854 void printctln(FILE *f, char *field, char *value)
856 if (strlen(field) && strlen(value))
857 fprintf(f, " %s\t%s\n", field, value);
861 * one date line, format it properly
863 void printctlndate(FILE *f, char *field, char *value)
868 if (!strlen(field) || !strlen(value))
871 for (i=0;isspace (value[i]) && i<= strlen (value); i++);
872 if (i == strlen (value))
875 memset (mydate, 0, sizeof (mydate));
876 if (strlen (value) == 6) {
877 mydate[0] = value[0];
878 mydate[1] = value[1];
880 mydate[3] = value[2];
881 mydate[4] = value[3];
883 mydate[6] = value[4];
884 mydate[7] = value[5];
885 fprintf(f, " %s\t%s\n", field, mydate);
886 } else if (strlen (value) == 8) {
887 mydate[0] = value[0];
888 mydate[1] = value[1];
890 mydate[3] = value[2];
891 mydate[4] = value[3];
893 mydate[6] = value[4];
894 mydate[7] = value[5];
895 mydate[8] = value[6];
896 mydate[9] = value[7];
897 fprintf(f, " %s\t%s\n", field, mydate);
899 fprintf (stderr, "Broken date field: %s\n", value);
900 fprintf(f, " %s\t%s\n", field, value);
906 * Third: Some high level routines
909 void dtaus2control (char *cdtaus, char *ccontrol)
911 FILE *fdtaus, *fcontrol;
921 if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
922 if (!(fdtaus = fopen("dtaus0.txt", "r")))
925 if (!strcmp (cdtaus, "-"))
928 if (!(fdtaus = fopen(cdtaus, "r")))
934 if (!strcmp (ccontrol, "-"))
937 if (!(fcontrol = fopen(ccontrol, "w")))
939 if (!(buf = (char *)malloc (512)))
945 if (dtaus_nextrec((void *)buf, fdtaus) == 1) {
946 if (dtaus_char(buf,4) == 'A') {
947 fprintf(fcontrol, "BEGIN {\n");
950 for (index=A_TRANS; index < A_LOOP; index++) {
951 bufp = buf + recA[index].pos;
952 memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
953 if (index == A_DATE || index == A_TODO)
954 printctlndate(fcontrol, recA[index].name, tmp);
956 printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
959 bufp = buf + recA[A_CURR].pos;
962 fprintf(fcontrol, " Euro\n");
965 fprintf(fcontrol, " DM\n");
968 fprintf(fcontrol, "}\n\n");
970 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz an.\n");
974 fprintf (stderr, "Der Anfangsdatensatz ist kaputt.\n");
981 if (dtaus_nextrec((void *)buf, fdtaus) == 1) {
982 while (dtaus_char(buf,4) == 'C') {
984 if (dtaus_nextrec((void *)bufp, fdtaus) != 1) {
985 fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
988 fprintf(fcontrol, "{\n");
990 for (index=C_NAME; index < C_LOOP; index++) {
992 if (use_euro && index == C_VAL)
995 if (!use_euro && index == C_VAL)
998 bufp = buf + recC[index].pos;
999 memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
1002 * C_EUR and C_DM are outside of the loop, can only be
1003 * selected for the non-default currency, but the value
1004 * should be stored in the normal record field.
1006 #ifndef DEFAULT_EURO
1011 printctln(fcontrol, recC[C_VAL].name, strip_zeros(string2real(tmp)));
1012 else if (index == C_VAL)
1013 printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
1014 else if (index == C_TRANS)
1015 printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
1017 printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
1018 #ifndef DEFAULT_EURO
1019 if (use_euro && index == C_EUR)
1022 if (!use_euro && index == C_DM)
1027 for (index=C_TEXT; index <= C_EXT; index++) {
1028 if (!(dtaus_char(buf,recC[index].pos) == ' ')) {
1029 bufp = buf + recC[index].pos;
1030 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
1031 memcpy(tmp, bufp, recC[index].len-2); tmp[recC[index].len-2] = '\0';
1032 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
1036 /* Number of extension records for this C record */
1037 extC = dtaus_int(buf, 185, 2);
1040 res = div (extC, 4);
1042 if (res.rem) extC++;
1045 if (dtaus_nextrec((void *)buf, fdtaus) != 1)
1046 memset (buf, 0, sizeof(buf));
1049 * Are there extension records that we have to check?
1051 * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
1052 * instead of 00 we should let it in so it can read its own
1053 * old files... *sigh*
1055 while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') {
1056 for (index=0; index < 4; index++) {
1057 if ((dtaus_char(buf,index*29) != ' ')) {
1058 bufp = buf + index*29;
1059 memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
1060 memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
1061 printctln(fcontrol, string2ext(x), strip_spaces(tmp));
1064 if (dtaus_nextrec((void *)buf, fdtaus) != 1)
1065 memset (buf, 0, sizeof(buf));
1068 fprintf(fcontrol, "}\n");
1074 * (gelesen ist er eigentlich schon...)
1076 if (dtaus_char(buf,4) == 'E') {
1077 if (dtaus_char(buf,4) == 'E') {
1078 fprintf(fcontrol, "\nEND {\n");
1080 for (index=E_COUNT; index <= E_BLZ; index++) {
1081 #ifndef DEFAULT_EURO
1082 if (use_euro && index == E_VAL)
1085 if (!use_euro && index == E_VAL)
1089 bufp = buf + recE[index].pos;
1090 memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
1092 #ifndef DEFAULT_EURO
1093 if (index == E_VAL || index == E_EUR)
1095 if (index == E_VAL || index == E_DM)
1097 printctln(fcontrol, recE[E_VAL].name, strip_zeros(string2real(tmp)));
1099 printctln(fcontrol, recE[index].name, strip_zeros(tmp));
1100 #ifndef DEFAULT_EURO
1101 if (use_euro && index == E_EUR)
1104 if (!use_euro && index == E_DM)
1109 fprintf(fcontrol, "}\n");
1111 fprintf (stderr, "Das ist kein Abschlußdatensatz.\n");
1115 fprintf (stderr, "Der Abschlußdatensatz ist leer oder kaputt.\n");
1122 int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
1124 FILE *fdtaus, *fcontrol, *fbeleg, *fcheck;
1129 char *valA[A_LEN], *valC[C_LEN];
1131 bigint sum_val, sum_blz, sum_kto, bi;
1137 char *currency = NULL;
1139 char ssum_val[30], ssum_kto[30], ssum_blz[30];
1142 if (!(fdtaus = fopen("dtaus0.txt", "w")))
1145 if (!strcmp (cdtaus, "-"))
1148 if (!(fdtaus = fopen(cdtaus, "w")))
1152 if (!(fcontrol = fopen("dtaus0.ctl", "r")))
1153 if (!(fcontrol = fopen("DTAUS0.CTL", "r")))
1156 if (!strcmp (ccontrol, "-"))
1159 if (!(fcontrol = fopen(ccontrol, "r")))
1163 if (!(fbeleg = fopen("dtaus0.doc", "w")))
1166 if (!(fbeleg = fopen(cbeleg, "w")))
1172 if (!(fcheck = fopen(ccheck, "w")))
1176 if (!(buf = (char *)malloc (512)))
1182 memset (valA, 0, sizeof(valA));
1183 control_nextline ((void *)line, 100, fcontrol);
1184 ident = extract_ident(line);
1185 if (!strcmp(ident, "begin") && (line[0] == '{')) {
1186 control_nextline ((void *)line, 100, fcontrol);
1187 while (strlen(line) && line[0] != '}') {
1188 ident = extract_ident(line);
1189 if ((recindex = rec_index(ident, REC_A)) != -1)
1191 if (recA[recindex].type != IGN)
1192 if ((valA[recindex] = (char *)malloc (strlen(line)+1)))
1193 strcpy(valA[recindex], line);
1195 if (! strcasecmp (ident, "euro"))
1197 if (! strcasecmp (ident, "dm"))
1200 control_nextline ((void *)line, 100, fcontrol);
1202 if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
1203 if (valA[recindex][0] == 'L')
1204 type = strdup ("Sammeleinziehungsauftrag");
1205 else if (valA[recindex][0] == 'G')
1206 type = strdup ("Sammelueberweisungsauftrag");
1208 type = strdup ("Sammelauftrag");
1211 currency = strdup ("Euro");
1213 currency = strdup ("DM");
1216 sprintf (date_todo, valA[A_TODO]);
1218 memset (date_todo, 0, sizeof (date_todo));
1220 fprintf(fbeleg, "\n\n");
1221 fprintf(fbeleg, "\n Begleitzettel\n\n");
1222 fprintf(fbeleg, "\n Belegloser Datentraegeraustausch\n\n");
1223 fprintf(fbeleg, "\n %s\n\n", type);
1224 fprintf(fbeleg, "\n VOL ........................:\n");
1225 fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date());
1227 fprintf(fbeleg, "\n Ausfuehrungsdatum ..........: %s\n", date_todo);
1229 fprintf(fbeleg, "\n Waehrung ...................: %s\n", currency);
1231 if (!dtaus_writeA(fdtaus, valA)) {
1232 fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
1236 fprintf (fcheck, "\n\n\n");
1237 if (valA[recindex][0] == 'L')
1238 fprintf (fcheck, " Sammeleinziehungsauftrag\n\n");
1239 else if (valA[recindex][0] == 'G')
1240 fprintf (fcheck, " Sammelueberweisungsauftrag\n\n");
1242 fprintf (fcheck, " Sammelauftrag\n\n");
1243 fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date());
1245 fprintf (fcheck, " Waehrung : Euro\n\n\n");
1247 fprintf (fcheck, " Waehrung : DM\n\n\n");
1248 fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
1249 fprintf (fcheck, " --------------------------------------------------------------------\n");
1251 fprintf (stderr, "Datei fängt nicht mit dem Anfangsdatensatz (BEGIN) an.\n");
1259 sum_val = bigint_int(0);
1260 sum_blz = bigint_int(0);
1261 sum_kto = bigint_int(0);
1262 memset (valC, 0, sizeof(valC));
1263 control_nextline ((void *)line, 100, fcontrol);
1264 if (line[0] == '{') {
1265 while (strlen(line) && line[0] == '{') {
1266 control_nextline ((void *)line, 100, fcontrol);
1268 for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++)
1269 free (text[textindex]);
1273 while (strlen(line) && line[0] != '}') {
1274 ident = extract_ident(line);
1275 if ((recindex = rec_index(ident, REC_C)) != -1)
1276 if (recC[recindex].type != IGN) {
1278 * Special exception to support multiple Text fields
1280 if (recindex == C_TEXT && valC[recindex]) {
1282 if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL)
1286 memset (text, 0, (MAX_TEXT+1) * sizeof (char *));
1289 if (textindex < MAX_TEXT) {
1290 if ((cp = (char *)malloc (strlen (line) + 1))) {
1292 cp[strlen (line)] = '\0';
1293 text[textindex++] = cp;
1298 if (recindex == C_VAL) {
1299 /* Convert commast to dots for later processing */
1300 for (i=0; line[i]; i++) if (line[i] == ',') line[i] = '.';
1302 if ((cp = index (line, '.')) == NULL) {
1303 if (!(valC[recindex] = (char *)malloc (strlen(line)+4)))
1305 sprintf (valC[recindex], "%s.00", line);
1306 } else if ( ((len = cp - line + 3)) < strlen (line)) {
1307 if (!(valC[recindex] = (char *)malloc (len+1)))
1309 strncpy (valC[recindex], line, len);
1310 valC[recindex][len] = '\0';
1312 if (!(valC[recindex] = (char *)malloc (strlen(line)+1)))
1314 strcpy(valC[recindex], line);
1317 if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
1318 strcpy(valC[recindex], line);
1324 control_nextline ((void *)line, 100, fcontrol);
1326 if (!dtaus_writeC(fdtaus, valA, valC, text)) {
1327 fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n");
1331 bi = bigint_string(real2string(valC[C_VAL])); sum_val = bigint_add(sum_val, bi);
1332 bi = bigint_string(valC[C_BLZ]); sum_blz = bigint_add(sum_blz, bi);
1333 bi = bigint_string(valC[C_KTO]); sum_kto = bigint_add(sum_kto, bi);
1335 fprintf (fcheck, " %10s %8s %-30s %12s\n", valC[C_KTO], valC[C_BLZ], valC[C_NAME], valC[C_VAL]);
1336 for (recindex=0; recindex<C_LEN; recindex++)
1338 free(valC[recindex]);
1339 memset (valC, 0, sizeof(valC));
1340 control_nextline ((void *)line, 100, fcontrol);
1343 fprintf (stderr, "Kein regulärer Datensatz?\n");
1350 dtaus_writeE(fdtaus, count, sum_val, sum_blz, sum_kto);
1351 fprintf (fcheck, " --------------------------------------------------------------------\n");
1352 fprintf (fbeleg, "\n Anzahl .....................: %d\n", count);
1353 bigint_sprintf (ssum_val, "%s", sum_val);
1354 recindex=strlen(ssum_val);
1355 ssum_val[recindex+1] = '\0';
1356 ssum_val[recindex] = ssum_val[recindex-1];
1357 ssum_val[recindex-1] = ssum_val[recindex-2];
1358 ssum_val[recindex-2] = '.';
1359 fprintf (fcheck, " %-52s %14s\n", "Summe", ssum_val);
1360 fprintf (fbeleg, "\n Summe ......................: %s\n", ssum_val);
1361 bigint_sprintf (ssum_kto, "%s", sum_kto);
1362 fprintf (fbeleg, "\n Kontrollsumme Kontonummern .: %s\n", ssum_kto);
1363 bigint_sprintf (ssum_blz, "%s", sum_blz);
1364 fprintf (fbeleg, "\n Kontrollsumme Bankleitzahlen: %s\n", ssum_blz);
1365 fprintf (fbeleg, "\n Unsere Kontonummer .........: %s\n", valA[A_KTO]);
1366 fprintf (fbeleg, "\n Unsere Bankleitzahl ........: %s\n", valA[A_BLZ]);
1367 fprintf (fbeleg, "\n\n\n\n\n __________________________________________________\n");
1368 fprintf (fbeleg, " Ort, Datum Unterschrift\n");
1369 for (recindex=0; recindex<A_LEN; recindex++)
1371 free(valA[recindex]);