Added legacy code to avoid GCC warnings
[infodrom/dtaus] / dtaus.c
diff --git a/dtaus.c b/dtaus.c
index bc332f8..bfb2dfb 100644 (file)
--- a/dtaus.c
+++ b/dtaus.c
@@ -1,6 +1,6 @@
 /*
     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
@@ -273,15 +273,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];
@@ -300,7 +342,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;
@@ -309,6 +351,7 @@ char *string2trans (char *s)
 char *trans2string (char *s)
 {
   static char res[30];
+  char *cp;
 
   res[0] = '\0';
   if (!strcmp(s, "Abbuchung"))
@@ -323,8 +366,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<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;
@@ -486,6 +555,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];
@@ -658,7 +730,7 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
     }
   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;
   }
 
@@ -870,7 +942,7 @@ void dtaus2control (char *cdtaus, char *ccontrol)
   /* 
    * 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;
@@ -906,10 +978,10 @@ void dtaus2control (char *cdtaus, char *ccontrol)
   /*
    * 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 {
@@ -970,7 +1042,7 @@ void dtaus2control (char *cdtaus, char *ccontrol)
          if (res.rem) extC++;
        }
       }
-      if (dtaus_nextrec(buf, fdtaus) != 1)
+      if (dtaus_nextrec((void *)buf, fdtaus) != 1)
        memset (buf, 0, sizeof(buf));
 
       /*
@@ -989,7 +1061,7 @@ void dtaus2control (char *cdtaus, char *ccontrol)
            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--;
       }
@@ -1137,7 +1209,7 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
       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");