/*
dtaus.c - Belegloser Datenträgeraustausch mit einer Bank
- Copyright (c) 1996,8,2001,2 Martin Schulze <joey@infodrom.org>
+ Copyright (c) 1996,8,2001-4 Martin Schulze <joey@infodrom.org>
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
{
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];
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;
char *trans2string (char *s)
{
static char res[30];
+ char *cp;
res[0] = '\0';
if (!strcmp(s, "Abbuchung"))
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<heutiges Jahr>
+ 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;
return 0;
}
+/*
+ * Return the current date nicely formatted
+ */
char *get_date()
{
static char res[10];
}
sprintf (tmp, "%s", trans2string(values[C_TRANS]));
if (!strlen(tmp)) {
- fprintf (stderr, "Ungültiger Typ, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
+ fprintf (stderr, "Ungültige Transaktion, nur Abbuchung, Einzug, E-Cash, E-Cash-A, Gutschrift und Lohn erlaubt.\n");
return 0;
}
/*
* Record A lesen
*/
- if (dtaus_nextrec(buf, fdtaus) == 1) {
+ if (dtaus_nextrec((void *)buf, fdtaus) == 1) {
if (dtaus_char(buf,4) == 'A') {
fprintf(fcontrol, "BEGIN {\n");
bufp = buf;
/*
* Record C lesen
*/
- if (dtaus_nextrec(buf, fdtaus) == 1) {
+ if (dtaus_nextrec((void *)buf, fdtaus) == 1) {
while (dtaus_char(buf,4) == 'C') {
bufp = buf + 128;
- if (dtaus_nextrec(bufp, fdtaus) != 1) {
+ if (dtaus_nextrec((void *)bufp, fdtaus) != 1) {
fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
return;
} else {
if (res.rem) extC++;
}
}
- if (dtaus_nextrec(buf, fdtaus) != 1)
+ if (dtaus_nextrec((void *)buf, fdtaus) != 1)
memset (buf, 0, sizeof(buf));
/*
printctln(fcontrol, string2ext(x), strip_spaces(tmp));
}
}
- if (dtaus_nextrec(buf, fdtaus) != 1)
+ if (dtaus_nextrec((void *)buf, fdtaus) != 1)
memset (buf, 0, sizeof(buf));
extC--;
}
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]);
+ fprintf(fbeleg, "\n Ausfuehrungsdatum ..........: %s\n", valA[A_TODO]);
}
if (use_euro)
fprintf(fbeleg, "\n Waehrung ...................: Euro\n");