X-Git-Url: https://git.infodrom.org/?p=infodrom%2Fdtaus;a=blobdiff_plain;f=dtaus.c;h=4a8851613dd894cc6d5ee6e369c7992e2511677d;hp=70785f64005b93deda544d898cabf4e95beaedb6;hb=9b4d285a11a61180100f2931c5dc6e5ebcca9ca4;hpb=8d1968b976c324581401cc9c977434e0cbe20849 diff --git a/dtaus.c b/dtaus.c index 70785f6..4a88516 100644 --- a/dtaus.c +++ b/dtaus.c @@ -1,6 +1,6 @@ /* dtaus.c - Belegloser Datenträgeraustausch mit einer Bank - Copyright (c) 1996,8,2001 Martin Schulze + Copyright (c) 1996,8,2001-4 Martin Schulze This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,10 +27,13 @@ #include #include #include +#include "latex.h" -/* #define DEFAULT_EURO */ +#define DEFAULT_EURO #ifndef DEFAULT_EURO int use_euro = 0; +#else +int use_euro = 1; #endif /* @@ -60,8 +63,11 @@ dtaus_record recA[] = { {"BLZ", 7, 8, REQ}, {"Referenz", 70, 10, OPT}, {"Datum", 50, 6, IGN}, + {"Ausfuehrung", 95, 8, OPT}, + {"Currency", 127, 1, OPT}, {"Euro", 127, 1, OPT}, - {NULL, 0, 0} + {"DM", 127, 1, OPT}, + {NULL, 0, 0, 0} }; #define A_TRANS 0 @@ -70,8 +76,12 @@ 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_CURR 7 +#define A_EURO 8 +#define A_DM 9 +#define A_LEN 10 +#define A_LOOP 7 dtaus_record recC[] = { {"Name", 93, 27, REQ}, @@ -87,13 +97,15 @@ dtaus_record recC[] = { {"myName", 128, 27, OPT}, {"myKonto", 69, 10, OPT}, {"myBLZ", 61, 8, OPT}, - {"Euro", 182, 1, IGN}, {"Text", 187, 29, OPT}, {"Extension", 216, 29, OPT}, + {"Currency", 182, 1, IGN}, #ifndef DEFAULT_EURO {"Betrag-Euro", 79, 11, IGN}, +#else + {"Betrag-DM", 50, 11, IGN}, #endif - {NULL, 0, 0} + {NULL, 0, 0, 0} }; #define C_NAME 0 @@ -105,15 +117,16 @@ dtaus_record recC[] = { #define C_MYNAM 6 #define C_MYKTO 7 #define C_MYBLZ 8 -#define C_EURO 9 -#define C_TEXT 10 -#define C_EXT 11 +#define C_TEXT 9 +#define C_EXT 10 +#define C_EURO 11 #ifndef DEFAULT_EURO #define C_EUR 12 -#define C_LEN 13 #else -#define C_LEN 12 +#define C_DM 12 #endif +#define C_LEN 13 +#define C_LOOP 11 #define MAX_TEXT 14 @@ -128,8 +141,10 @@ dtaus_record recE[] = { {"BLZs", 47, 17, IGN}, #ifndef DEFAULT_EURO {"Summe-Euro", 64, 13, IGN}, +#else + {"Summe-DM", 17, 13, IGN}, #endif - {NULL, 0, 0} + {NULL, 0, 0, 0} }; #define E_COUNT 0 @@ -138,7 +153,10 @@ dtaus_record recE[] = { #define E_BLZ 3 #ifndef DEFAULT_EURO #define E_EUR 4 +#else +#define E_DM 4 #endif +#define E_LEN 5 /* * Second: Some low level routines @@ -146,7 +164,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); } @@ -232,7 +250,7 @@ char *strip_nondigits (char *s) char dtaus_char (void *buf, unsigned int pos) { static char res; - char *bufp = buf; + char *bufp = (char *)buf; bufp+=pos; memcpy(&res, bufp, 1); @@ -256,15 +274,57 @@ char *real2string(char *s) { static char res[20]; char *cp; + char *xp; /* only to avoid a GCC warning */ - strcpy(res, s); + strncpy(res, s, sizeof(res)-1); + res[sizeof(res)-1] = 0; for (cp=res; *cp&&!(*cp == ',')&&!(*cp == '.');cp++); - *(cp++) = *(cp+1); - *(cp++) = *(cp+1); + + if ((cp-res) >= (sizeof(res)-3)) { + /* Bail out, since the number is too large, shouldn't be possible though. */ + fprintf (stderr, "Value %s too large.\n", res); + exit (1); + } + + if (*cp == '.' || *cp == ',') { + if (*(cp+1)) { + /* 1st decimal place */ + xp = cp+1; + if (*xp && isdigit(*xp)) + *(cp++) = *xp; + else + *(cp++) = '0'; + /* 2nd decimal place */ + xp = cp+1; + if (*xp && isdigit(*xp)) + *(cp++) = *xp; + else + *(cp++) = '0'; + } else { + *(cp++) = '0'; + *(cp++) = '0'; + } + } else { + *(cp++) = '0'; + *(cp++) = '0'; + } *cp = '\0'; return res; } +/* + * Return the last digit of the year as character + */ +char get_date_lastdigit() +{ + time_t timer; + struct tm *loctime; + + timer = time ( NULL ); + loctime = localtime(&timer); + return loctime->tm_year % 10 + '0'; +} + char *string2trans (char *s) { static char res[30]; @@ -283,7 +343,7 @@ char *string2trans (char *s) else if (!strcmp(s, "53000")) sprintf (res, "Lohn"); else if (!strncmp(s, "5400", 4)) - sprintf (res, "Vermögen"); + sprintf (res, "Vermögen %c",s[4]); /* else if (!strcmp(s, "56000")) sprintf (res, ""); / * Überweisung öffentlicher Kassen */ return res; @@ -292,6 +352,7 @@ char *string2trans (char *s) char *trans2string (char *s) { static char res[30]; + char *cp; res[0] = '\0'; if (!strcmp(s, "Abbuchung")) @@ -306,8 +367,34 @@ char *trans2string (char *s) sprintf (res, "51000"); else if (!strcmp(s, "Lohn")) sprintf (res, "53000"); - else if (!strncmp(s, "Vermögen", 4)) - sprintf (res, "5400"); + else { + cp = NULL; + if (!strncmp(s, "Vermögen", 8)) + cp = s+8; + if (!strncmp(s, "Vermoegen", 9)) + cp = s+9; + + if (!cp) { + fprintf (stderr, "Unbekannte Transaktion `%s'\n", res); + exit (1); + } + + /* + Vermögen --> 5400 + Vermögen 8 -> 5400<8> + Vermögen 2003 -> 5400<3> + */ + + if (*cp) while (!isspace(*cp)) cp++; + while (isspace(*cp)) cp++; + + if (!*cp || !isdigit(*cp)) + sprintf (res, "5400%c",get_date_lastdigit()); + else { + while (isdigit(*cp)) cp++; + sprintf (res, "5400%c",*(cp-1)); + } + } /* else if (!strcmp(s, "")) sprintf (res, "56000"); / * Überweisung öffentlicher Kassen */ return res; @@ -344,7 +431,7 @@ char *ext2string (char *s) unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len) { char tmp[30]; - char *bufp = buf; + char *bufp = (char *)buf; static unsigned long int res; bufp+=pos; @@ -364,8 +451,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); @@ -438,8 +525,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))) { @@ -450,7 +537,7 @@ size_t control_nextline (void **buf, int len, FILE *f) while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f))); } else line[strlen(line)-1] = '\0'; - if (line[strlen(line)-1] == ' ') + if (line[strlen(line)-1] == '\r') line[strlen(line)-1] = '\0'; for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--) line[i-1] = '\0'; @@ -469,6 +556,9 @@ size_t control_nextline (void **buf, int len, FILE *f) return 0; } +/* + * Return the current date nicely formatted + */ char *get_date() { static char res[10]; @@ -492,7 +582,7 @@ void dtaus_prepareA (char *buf) struct tm *loctime; char tmp[10]; - bzero (buf, 129); + memset (buf, 0, 129); timer = time ( NULL ); loctime = localtime(&timer); @@ -507,14 +597,10 @@ void dtaus_prepareA (char *buf) 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[127] = '1'; /* A12 (Currency) */ -#else if (use_euro) - buf[127] = '1'; /* A12 (Currency) */ + buf[recA[A_CURR].pos] = '1'; /* A12 (Currency) */ else - buf[127] = ' '; /* A12 (Currency) */ -#endif + buf[recA[A_CURR].pos] = ' '; /* A12 (Currency) */ } /* @@ -526,7 +612,7 @@ void dtaus_prepareC (char *buf, int normaltext, int maxtext) int i; int appendix = 0; - bzero (buf, 257); + memset (buf, 0, 257); if (normaltext) appendix = 1; @@ -546,18 +632,14 @@ void dtaus_prepareC (char *buf, int normaltext, int maxtext) 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 (Euro) */ + 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[182] = '1'; /* C17a (Currency) */ -#else if (use_euro) - buf[182] = '1'; /* C17a (Currency) */ + buf[recC[C_EURO].pos] = '1'; /* C17a (Currency) */ else - buf[182] = ' '; /* C17a (Currency) */ -#endif + buf[recC[C_EURO].pos] = ' '; /* C17a (Currency) */ 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 */ @@ -574,7 +656,7 @@ void dtaus_prepareE (char *buf) { int i; - bzero (buf, 129); + memset (buf, 0, 129); buf[0] = '0'; buf[1] = '1'; buf[2] = '2'; @@ -609,12 +691,16 @@ 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, "%s", padzeroclip (strip_nondigits (values[A_BLZ]),recA[A_BLZ].len)); + for (i=0; i