X-Git-Url: https://git.infodrom.org/?p=infodrom%2Fdtaus;a=blobdiff_plain;f=dtaus.c;h=e8f935e4f068e9fd4722bfc44dfcb2f09b88f92b;hp=3c5f2964ee1dffda46ba043460ab3d3f0f43bf29;hb=5c04191ccc8b40a8a78fd5dbe1b89ef00932fe89;hpb=3e348be74ca5ba074062acd47e622c1b68354a89 diff --git a/dtaus.c b/dtaus.c index 3c5f296..e8f935e 100644 --- a/dtaus.c +++ b/dtaus.c @@ -1,5 +1,5 @@ /* - dtaus.c - Datenträgeraustausch mit einer Bank + dtaus.c - Belegloser Datenträgeraustausch mit einer Bank Copyright (c) 1996,8,2001 Martin Schulze This program is free software; you can redistribute it and/or modify @@ -22,11 +22,17 @@ #include "dtaus.h" #include "bigint.h" #include +#include #include #include #include #include +/* #define DEFAULT_EURO */ +#ifndef DEFAULT_EURO +int use_euro = 0; +#endif + /* * First: Some control structures */ @@ -54,6 +60,7 @@ dtaus_record recA[] = { {"BLZ", 7, 8, REQ}, {"Referenz", 70, 10, OPT}, {"Datum", 50, 6, IGN}, + {"Ausfuehrung", 95, 8, OPT}, {"Euro", 127, 1, OPT}, {NULL, 0, 0} }; @@ -64,15 +71,20 @@ dtaus_record recA[] = { #define A_BLZ 3 #define A_REF 4 #define A_DATE 5 -#define A_EURO 6 -#define A_LEN 7 +#define A_TODO 6 +#define A_EURO 7 +#define A_LEN 8 dtaus_record recC[] = { {"Name", 93, 27, REQ}, {"Konto", 21, 10, REQ}, {"BLZ", 13, 8, REQ}, {"Transaktion", 44, 5, REQ}, +#ifndef DEFAULT_EURO {"Betrag", 50, 11, REQ}, +#else + {"Betrag", 79, 11, REQ}, +#endif {"Zweck", 155, 27, REQ}, {"myName", 128, 27, OPT}, {"myKonto", 69, 10, OPT}, @@ -80,6 +92,9 @@ dtaus_record recC[] = { {"Euro", 182, 1, IGN}, {"Text", 187, 29, OPT}, {"Extension", 216, 29, OPT}, +#ifndef DEFAULT_EURO + {"Betrag-Euro", 79, 11, IGN}, +#endif {NULL, 0, 0} }; @@ -95,13 +110,27 @@ dtaus_record recC[] = { #define C_EURO 9 #define C_TEXT 10 #define C_EXT 11 +#ifndef DEFAULT_EURO +#define C_EUR 12 +#define C_LEN 13 +#else #define C_LEN 12 +#endif + +#define MAX_TEXT 14 dtaus_record recE[] = { {"Anzahl", 10, 7, IGN}, +#ifndef DEFAULT_EURO {"Summe", 17, 13, IGN}, +#else + {"Summe", 64, 13, IGN}, +#endif {"Kontos", 30, 17, IGN}, {"BLZs", 47, 17, IGN}, +#ifndef DEFAULT_EURO + {"Summe-Euro", 64, 13, IGN}, +#endif {NULL, 0, 0} }; @@ -109,7 +138,9 @@ dtaus_record recE[] = { #define E_VAL 1 #define E_KTO 2 #define E_BLZ 3 -#define E_LEN 0 +#ifndef DEFAULT_EURO +#define E_EUR 4 +#endif /* * Second: Some low level routines @@ -117,7 +148,7 @@ dtaus_record recE[] = { size_t dtaus_nextrec (void **buf, FILE *f) { - bzero (buf, 128); + memset (buf, 0, 128); return fread(buf, 128, 1, f); } @@ -143,6 +174,10 @@ char *upcase(char *s) case 'ß': *(xp++) = 'S'; *xp='S'; break; } } else + /* + * Filter out all other characters since credit institutes won't + * accept the file otherwise. + */ *xp = ' '; } *xp = '\0'; @@ -188,7 +223,7 @@ char *strip_nondigits (char *s) char *p; char *x; - for (x=s,p=s;*x;*x++) + for (x=s,p=s;*x;x++) if (isdigit (*x)) *(p++) = *x; *(p++) = '\0'; @@ -331,8 +366,8 @@ char *extract_ident (char *line) static char word[30]; if (strlen(line) > 0) { - x = index (line, ' '); - y = index (line, '\t'); + x = strchr (line, ' '); + y = strchr (line, '\t'); if (!x && !y) { strncpy(word, line, 29); @@ -405,8 +440,8 @@ size_t control_nextline (void **buf, int len, FILE *f) char *cp; int i; - bzero (line, sizeof(line)); - bzero (buf, len); + memset (line, 0, sizeof(line)); + memset (buf, 0, len); cp = line; while (!strlen(line) && (cp = fgets(line, 100, f))) { @@ -448,14 +483,18 @@ char *get_date() return res; } -void dtaus_prepareA(char *buf) +/* + * Prepare a record A according to the specs. + * See dtaus.txt for explanation + */ +void dtaus_prepareA (char *buf) { int i; time_t timer; struct tm *loctime; char tmp[10]; - bzero (buf, 129); + memset (buf, 0, 129); timer = time ( NULL ); loctime = localtime(&timer); @@ -464,48 +503,89 @@ void dtaus_prepareA(char *buf) buf[2] = '2'; buf[3] = '8'; buf[4] = 'A'; - for (i=15;i<15+8; i++) buf[i] = '0'; + for (i=15;i<15+8; i++) buf[i] = '0'; /* A5 */ sprintf(tmp, "%02d%02d%02d", loctime->tm_mday, loctime->tm_mon+1, loctime->tm_year % 100); - for (i=0; i<6; i++) buf[50+i] = tmp[i]; - for (i=56;i<56+4; i++) buf[i] = ' '; - for (i=70;i<70+10; i++) buf[i] = '0'; - for (i=80;i<80+48; i++) buf[i] = ' '; + for (i=0; i<6; i++) buf[50+i] = tmp[i]; /* A7 (Date) */ + for (i=56;i<56+4; i++) buf[i] = ' '; /* A8 */ + for (i=70;i<70+10; i++) buf[i] = '0'; /* A10 */ + for (i=80;i<80+48; i++) buf[i] = ' '; /* A11 */ +#ifdef DEFAULT_EURO + buf[recA[A_EURO].pos] = '1'; /* A12 (Currency) */ +#else + if (use_euro) + buf[recA[A_EURO].pos] = '1'; /* A12 (Currency) */ + else + buf[recA[A_EURO].pos] = ' '; /* A12 (Currency) */ +#endif } -void dtaus_prepareC(char *buf) +/* + * Prepare a record C according to the specs. + * See dtaus.txt for explanation + */ +void dtaus_prepareC (char *buf, int normaltext, int maxtext) { int i; + int appendix = 0; - bzero (buf, 257); - buf[0] = '0'; - buf[1] = '2'; - buf[2] = '1'; - buf[3] = '6'; + memset (buf, 0, 257); + + if (normaltext) + appendix = 1; + appendix += maxtext; + i = 187 + (appendix * 29); + + /* Bail out if the number is too large, shouldn't be possible though */ + if (i >= 1000) + exit (1); + + buf[0] = (i/1000)+48;i-=(i/1000)*100; + buf[1] = (i/100)+48;i-=(i/100)*100; + buf[2] = (i/10)+48;i-=(i/10)*10; + buf[3] = i+48; buf[4] = 'C'; - for (i=31;i<31+13; i++) buf[i] = '0'; - buf[49] = ' '; - for (i=79;i<79+11; i++) buf[i] = '0'; - for (i=90;i<90+3; i++) buf[i] = ' '; - for (i=120;i<120+8; i++) buf[i] = ' '; - for (i=182;i<182+3; i++) buf[i] = ' '; - for (i=185;i<185+2; i++) buf[i] = '0'; - for (i=187;i<187+(29*2); i++) buf[i] = ' '; - for (i=245;i<245+11; i++) buf[i] = ' '; + + for (i=31;i<31+13; i++) buf[i] = '0'; /* C6 */ + buf[49] = ' '; /* C8 */ + for (i=50;i<50+11; i++) buf[i] = '0'; /* C9 (Betrag) */ + for (i=79;i<79+11; i++) buf[i] = '0'; /* C12 (Betrag Euro) */ + for (i=90;i<90+3; i++) buf[i] = ' '; /* C13 */ + for (i=93;i<90+27; i++) buf[i] = ' '; /* C14a (Kunde) */ + for (i=120;i<120+8; i++) buf[i] = ' '; /* C14b */ +#ifdef DEFAULT_EURO + buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */ +#else + if (use_euro) + buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */ + else + buf[recC[C_EURO].pos] = ' '; /* C17a (Currency) */ +#endif + for (i=183;i<183+2; i++) buf[i] = ' '; /* C17b */ + for (i=187;i<187+(29*2); i++) buf[i] = ' '; /* C19-C22 (misc text) */ + for (i=245;i<245+11; i++) buf[i] = ' '; /* C23 */ + + buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10; + buf[185+1] = appendix+48; } -void dtaus_prepareE(char *buf) +/* + * Prepare a record E according to the specs. + * See dtaus.txt for explanation + */ +void dtaus_prepareE (char *buf) { int i; - bzero (buf, 129); + memset (buf, 0, 129); buf[0] = '0'; buf[1] = '1'; buf[2] = '2'; buf[3] = '8'; buf[4] = 'E'; - for (i=5;i<5+5; i++) buf[i] = ' '; - for (i=64;i<64+13; i++) buf[i] = '0'; - for (i=77;i<77+51; i++) buf[i] = ' '; + for (i=5;i<5+5; i++) buf[i] = ' '; /* E3 */ + for (i=17;i<17+13; i++) buf[i] = '0'; /* E8 (Check Betrag) */ + for (i=64;i<64+13; i++) buf[i] = '0'; /* E8 (Check Euro) */ + for (i=77;i<77+51; i++) buf[i] = ' '; /* E9 */ } int dtaus_writeA(FILE *f, char **values) @@ -531,28 +611,38 @@ int dtaus_writeA(FILE *f, char **values) dtaus_prepareA(buf); buf[5] = values[A_TRANS][0]; buf[6] = values[A_TRANS][1]; - sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),8)); - for (i=0; i<8; i++) buf[recA[A_BLZ].pos+i] = tmp[i]; - sprintf (tmp, "%-27s", upcase(values[A_NAME])); + sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),recA[A_BLZ].len)); + for (i=0; i recC[i].len) - values[i][recC[i].len] = '\0'; + values[i][recC[i].len-2] = '\0'; i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len) values[i][recC[i].len] = '\0'; i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len) values[i][recC[i].len] = '\0'; i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len) values[i][recC[i].len] = '\0'; - i=C_EXT;if (values[i] && strlen(values[i]) > recC[i].len) - values[i][recC[i].len] = '\0'; - dtaus_prepareC(buf); - if (!values[C_TEXT]) { - buf[1] = '1'; - buf[2] = '8'; - buf[3] = '7'; - } + dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext); for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i]; if (values[C_MYBLZ]) sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYBLZ]),8)); @@ -594,34 +677,61 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values) sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10)); for (i=0; i 1) { + fieldnr=1; + while (fieldnr0?1:0; - /* FIXME: Erweiterungsfelder werden ignoriert */ - - fprintf(fcontrol, "}\n"); - } else { - fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n"); - return; + /* Number of extension records for this C record */ + extC = dtaus_int(buf, 185, 2); + extC -= 2; + if (extC > 0) { + res = div (extC, 4); + extC = res.quot; + if (res.rem) extC++; + } } if (dtaus_nextrec(buf, fdtaus) != 1) - bzero (buf, sizeof(buf)); + memset (buf, 0, sizeof(buf)); + + /* + * Are there extension records that we have to check? + * + * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01 + * instead of 00 we should let it in so it can read its own + * old files... *sigh* + */ + while (extC > 0 && dtaus_char(buf,4) != 'C' && dtaus_char(buf,4) != 'E') { + for (index=0; index < 4; index++) { + if ((dtaus_char(buf,index*29) != ' ')) { + bufp = buf + index*29; + memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2; + memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0'; + printctln(fcontrol, string2ext(x), strip_spaces(tmp)); + } + } + if (dtaus_nextrec(buf, fdtaus) != 1) + memset (buf, 0, sizeof(buf)); + extC--; + } + fprintf(fcontrol, "}\n"); } } @@ -769,15 +929,27 @@ void dtaus2control (char *cdtaus, char *ccontrol) */ if (dtaus_char(buf,4) == 'E') { if (dtaus_char(buf,4) == 'E') { - fprintf(fcontrol, "END {\n"); + fprintf(fcontrol, "\nEND {\n"); for (index=E_COUNT; index <= E_BLZ; index++) { +#ifndef DEFAULT_EURO + if (use_euro && index == E_VAL) + index = E_EUR; +#endif bufp = buf + recE[index].pos; memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0'; +#ifndef DEFAULT_EURO + if (index == E_VAL || index == E_EUR) +#else if (index == E_VAL) +#endif printctln(fcontrol, recE[index].name, strip_zeros(string2real(tmp))); else printctln(fcontrol, recE[index].name, strip_zeros(tmp)); +#ifndef DEFAULT_EURO + if (use_euro && index == E_EUR) + index = E_VAL; +#endif } fprintf(fcontrol, "}\n"); @@ -804,26 +976,38 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck) char *valA[A_LEN], *valC[C_LEN]; int count; bigint sum_val, sum_blz, sum_kto, bi; + char **text = NULL; + char *cp; + int textindex = 0; - if (!cdtaus) + if (!cdtaus) { if (!(fdtaus = fopen("dtaus0.txt", "w"))) return 0; - if (cdtaus) - if (!(fdtaus = fopen(cdtaus, "w"))) - return 0; - if (!ccontrol) + } else { + if (!strcmp (cdtaus, "-")) + fdtaus = stdout; + else + if (!(fdtaus = fopen(cdtaus, "w"))) + return 0; + } + if (!ccontrol) { if (!(fcontrol = fopen("dtaus0.ctl", "r"))) if (!(fcontrol = fopen("DTAUS0.CTL", "r"))) return 0; - if (ccontrol) - if (!(fcontrol = fopen(ccontrol, "r"))) - return 0; - if (!cbeleg) + } else { + if (!strcmp (ccontrol, "-")) + fcontrol = stdin; + else + if (!(fcontrol = fopen(ccontrol, "r"))) + return 0; + } + if (!cbeleg) { if (!(fbeleg = fopen("dtaus0.doc", "w"))) return 0; - if (cbeleg) + } else { if (!(fbeleg = fopen(cbeleg, "w"))) return 0; + } if (!ccheck) fcheck = stdout; else @@ -837,7 +1021,7 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck) /* * Record A lesen */ - bzero(valA, sizeof(valA)); + memset (valA, 0, sizeof(valA)); control_nextline ((void *)line, 100, fcontrol); ident = extract_ident(line); if (!strcmp(ident, "begin") && (line[0] == '{')) { @@ -845,9 +1029,18 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck) while (strlen(line) && line[0] != '}') { ident = extract_ident(line); if ((recindex = rec_index(ident, REC_A)) != -1) +#ifndef DEFAULT_EURO + { +#endif if (recA[recindex].type != IGN) if ((valA[recindex] = (char *)malloc (strlen(line)+1))) strcpy(valA[recindex], line); +#ifndef DEFAULT_EURO + } else { + if (! strcasecmp (ident, "euro")) + use_euro = 1; + } +#endif control_nextline ((void *)line, 100, fcontrol); } if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) { @@ -862,6 +1055,17 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck) fprintf(fbeleg, "\n Sammelauftrag\n\n"); fprintf(fbeleg, "\n VOL ........................:\n"); fprintf(fbeleg, "\n Erstellungsdatum ...........: %s\n", get_date()); + if (valA[A_TODO]) { + fprintf(fbeleg, "\n Ausfuehrugsdatum ...........: %s\n", valA[A_TODO]); + } +#ifndef DEFAULT_EURO + if (use_euro) + fprintf(fbeleg, "\n Waehrung ...................: Euro\n"); + else + fprintf(fbeleg, "\n Waehrung ...................: DM\n"); +#else + fprintf(fbeleg, "\n Waehrung ...................: Euro\n"); +#endif } if (!dtaus_writeA(fdtaus, valA)) { fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n"); @@ -869,8 +1073,21 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck) } fprintf (fcheck, "\n\n\n"); - fprintf (fcheck, " Sammeleinzeiehungsauftrag\n\n"); - fprintf (fcheck, " Erstellungsdatum : %s\n\n\n", get_date()); + if (valA[recindex][0] == 'L') + fprintf (fcheck, " Sammeleinziehungsauftrag\n\n"); + else if (valA[recindex][0] == 'G') + fprintf (fcheck, " Sammelueberweisungsauftrag\n\n"); + else + fprintf (fcheck, " Sammelauftrag\n\n"); + fprintf (fcheck, " Erstellungsdatum : %s\n\n", get_date()); +#ifndef DEFAULT_EURO + if (use_euro) + fprintf (fcheck, " Waehrung : Euro\n\n\n"); + else + fprintf (fcheck, " Waehrung : DM\n\n\n"); +#else + fprintf (fcheck, " Waehrung : Euro\n\n\n"); +#endif fprintf (fcheck, " %-10s %-8s %-30s %12s\n", "Kontonr.", "BLZ", "Name", "Betrag"); fprintf (fcheck, " --------------------------------------------------------------------\n"); } else { @@ -885,22 +1102,50 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck) sum_val = bigint_int(0); sum_blz = bigint_int(0); sum_kto = bigint_int(0); - bzero(valC, sizeof(valC)); + memset (valC, 0, sizeof(valC)); control_nextline ((void *)line, 100, fcontrol); if (line[0] == '{') { while (strlen(line) && line[0] == '{') { control_nextline ((void *)line, 100, fcontrol); + if (text) { + for (textindex=0; textindex < MAX_TEXT && text[textindex]; textindex++) + free (text[textindex]); + free (text); + text = NULL; + } while (strlen(line) && line[0] != '}') { ident = extract_ident(line); if ((recindex = rec_index(ident, REC_C)) != -1) - if (recC[recindex].type != IGN) - if ((valC[recindex] = (char *)malloc (strlen(line)+1))) - strcpy(valC[recindex], line); - else - return 0; + if (recC[recindex].type != IGN) { + /* + * Special exception to support multiple Text fields + */ + if (recindex == C_TEXT && valC[recindex]) { + if (!text) { + if ((text = (char **)malloc ((MAX_TEXT+1) * sizeof (char *))) == NULL) + return 0; + else { + textindex = 0; + memset (text, 0, (MAX_TEXT+1) * sizeof (char *)); + } + } + if (textindex < MAX_TEXT) { + if ((cp = (char *)malloc (strlen (line) + 1))) { + strcpy (cp, line); + cp[strlen (line)] = '\0'; + text[textindex++] = cp; + } + } + } else { + if ((valC[recindex] = (char *)malloc (strlen(line)+1))) + strcpy(valC[recindex], line); + else + return 0; + } + } control_nextline ((void *)line, 100, fcontrol); } - if (!dtaus_writeC(fdtaus, valA, valC)) { + if (!dtaus_writeC(fdtaus, valA, valC, text)) { fprintf (stderr, "Konnte den regulären Datensatz nicht schreiben.\n"); return 0; } @@ -913,7 +1158,7 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck) for (recindex=0; recindex