Properly added DM support back and properly implemented Euro support.
authorJoey Schulze <joey@infodrom.org>
Sun, 25 May 2003 19:56:58 +0000 (19:56 +0000)
committerJoey Schulze <joey@infodrom.org>
Sun, 25 May 2003 19:56:58 +0000 (19:56 +0000)
There are special cases to take care about if the default currency is
DM or Euro but the selected currency is the other one.  This patch
implements this by switching index values forth and back, quite
kludgy, though.

Broken DM support after support for Euro was noticed by
Stefan Beckert <becki@web.de>

dtaus.c

diff --git a/dtaus.c b/dtaus.c
index f3fc082..bc332f8 100644 (file)
--- a/dtaus.c
+++ b/dtaus.c
@@ -31,6 +31,8 @@
 #define DEFAULT_EURO
 #ifndef DEFAULT_EURO
 int use_euro = 0;
+#else
+int use_euro = 1;
 #endif
 
 /*
@@ -61,7 +63,9 @@ dtaus_record recA[] = {
   {"Referenz", 70, 10, OPT},
   {"Datum", 50, 6, IGN},
   {"Ausfuehrung", 95, 8, OPT},
+  {"Currency", 127, 1, OPT},
   {"Euro", 127, 1, OPT},
+  {"DM", 127, 1, OPT},
   {NULL, 0, 0}
 };
 
@@ -72,8 +76,11 @@ dtaus_record recA[] = {
 #define A_REF  4
 #define A_DATE 5
 #define A_TODO 6
-#define A_EURO 7
-#define A_LEN  8
+#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},
@@ -89,11 +96,13 @@ 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}
 };
@@ -107,15 +116,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
 
@@ -130,6 +140,8 @@ 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}
 };
@@ -140,7 +152,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
@@ -509,14 +524,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[recA[A_EURO].pos] = '1';                         /* A12 (Currency) */
-#else
   if (use_euro)
-    buf[recA[A_EURO].pos] = '1';                               /* A12 (Currency) */
+    buf[recA[A_CURR].pos] = '1';                               /* A12 (Currency) */
   else
-    buf[recA[A_EURO].pos] = ' ';                               /* A12 (Currency) */
-#endif
+    buf[recA[A_CURR].pos] = ' ';                               /* A12 (Currency) */
 }
 
 /*
@@ -552,14 +563,10 @@ void dtaus_prepareC (char *buf, int normaltext, int maxtext)
   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 */
@@ -683,7 +690,10 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
   else
     for (i=0; i<recC[C_EUR].len; i++) buf[recC[C_EUR].pos+i] = tmp[i];
 #else
-  for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
+  if (use_euro)
+    for (i=0; i<recC[C_VAL].len; i++) buf[recC[C_VAL].pos+i] = tmp[i];
+  else
+    for (i=0; i<recC[C_DM].len; i++) buf[recC[C_DM].pos+i] = tmp[i];
 #endif
   if (values[C_MYKTO])
     sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
@@ -753,7 +763,10 @@ int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
   else
     for (i=0; i<recE[E_EUR].len; i++) buf[recE[E_EUR].pos+i] = tmp[i];
 #else
-  for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
+  if (use_euro)
+    for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
+  else
+    for (i=0; i<recE[E_DM].len; i++) buf[recE[E_DM].pos+i] = tmp[i];
 #endif
   bigint_sprintf (tmp, "%s", kto);
   padzeroclip (tmp,17);
@@ -862,11 +875,7 @@ void dtaus2control (char *cdtaus, char *ccontrol)
       fprintf(fcontrol, "BEGIN {\n");
       bufp = buf;
 
-#ifndef DEFAULT_EURO
-      for (index=A_TRANS; index <= A_EURO; index++) {
-#else
-      for (index=A_TRANS; index < A_EURO; index++) {
-#endif
+      for (index=A_TRANS; index < A_LOOP; index++) {
        bufp = buf + recA[index].pos;
        memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
        if (index == A_DATE || index == A_TODO)
@@ -875,10 +884,14 @@ void dtaus2control (char *cdtaus, char *ccontrol)
          printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
       }
 
-#ifndef DEFAULT_EURO
-      if (tmp[recA[index].pos] == '1')
+      bufp = buf + recA[A_CURR].pos;
+      if (*bufp == '1') {
        use_euro = 1;
-#endif
+       fprintf(fcontrol, "  Euro\n");
+      } else {
+       use_euro = 0;
+       fprintf(fcontrol, "  DM\n");
+      }
 
       fprintf(fcontrol, "}\n\n");
     } else {
@@ -902,19 +915,29 @@ void dtaus2control (char *cdtaus, char *ccontrol)
       } else {
        fprintf(fcontrol, "{\n");
 
-       for (index=C_NAME; index < C_EURO; index++) {
+       for (index=C_NAME; index < C_LOOP; index++) {
 #ifndef DEFAULT_EURO
          if (use_euro && index == C_VAL)
            index = C_EUR;
+#else
+         if (!use_euro && index == C_VAL)
+           index = C_DM;
 #endif
          bufp = buf + recC[index].pos;
          memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
+
+         /*
+          * C_EUR and C_DM are outside of the loop, can only be
+          * selected for the non-default currency, but the value
+          * should be stored in the normal record field.
+          */
 #ifndef DEFAULT_EURO
          if (index == C_EUR)
-           printctln(fcontrol, recC[C_VAL].name, strip_zeros(string2real(tmp)));
-         else
+#else
+         if (index == C_DM)
 #endif
-         if (index == C_VAL)
+           printctln(fcontrol, recC[C_VAL].name, strip_zeros(string2real(tmp)));
+         else if (index == C_VAL)
            printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
          else if (index == C_TRANS)
            printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
@@ -923,6 +946,9 @@ void dtaus2control (char *cdtaus, char *ccontrol)
 #ifndef DEFAULT_EURO
          if (use_euro && index == C_EUR)
            index = C_VAL;
+#else
+         if (!use_euro && index == C_DM)
+           index = C_VAL;
 #endif
        }
 
@@ -983,20 +1009,28 @@ void dtaus2control (char *cdtaus, char *ccontrol)
 #ifndef DEFAULT_EURO
        if (use_euro && index == E_VAL)
          index = E_EUR;
+#else
+       if (!use_euro && index == E_VAL)
+         index = E_DM;
 #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)
+       if (index == E_VAL || index == E_DM)
 #endif
-         printctln(fcontrol, recE[index].name, strip_zeros(string2real(tmp)));
+         printctln(fcontrol, recE[E_VAL].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;
+#else
+         if (!use_euro && index == E_DM)
+           index = E_VAL;
 #endif
       }
 
@@ -1078,18 +1112,16 @@ 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;
+         if (! strcasecmp (ident, "dm"))
+           use_euro = 0;
        }
-#endif
       control_nextline ((void *)line, 100, fcontrol);
     }
     if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
@@ -1107,14 +1139,10 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
       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");
@@ -1129,14 +1157,10 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
     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 {