Finally added proper support for the upcoming European currency
[infodrom/dtaus] / dtaus.c
diff --git a/dtaus.c b/dtaus.c
index 152a2dc..70785f6 100644 (file)
--- 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 <joey@infodrom.org>
 
     This program is free software; you can redistribute it and/or modify
@@ -29,6 +29,9 @@
 #include <malloc.h>
 
 /* #define DEFAULT_EURO */
+#ifndef DEFAULT_EURO
+int use_euro = 0;
+#endif
 
 /*
  *  First: Some control structures
@@ -75,7 +78,11 @@ dtaus_record recC[] = {
   {"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},
@@ -83,6 +90,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}
 };
 
@@ -98,15 +108,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}
 };
 
@@ -114,7 +136,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
@@ -486,7 +510,10 @@ void dtaus_prepareA (char *buf)
 #ifdef DEFAULT_EURO
   buf[127] = '1';                              /* A12 (Currency) */
 #else
-  buf[127] = ' ';                              /* A12 (Currency) */
+  if (use_euro)
+    buf[127] = '1';                            /* A12 (Currency) */
+  else
+    buf[127] = ' ';                            /* A12 (Currency) */
 #endif
 }
 
@@ -526,7 +553,10 @@ void dtaus_prepareC (char *buf, int normaltext, int maxtext)
 #ifdef DEFAULT_EURO
   buf[182] = '1';                              /* C17a (Currency) */
 #else
-  buf[182] = ' ';                              /* C17a (Currency) */
+  if (use_euro)
+    buf[182] = '1';                            /* C17a (Currency) */
+  else
+    buf[182] = ' ';                            /* 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) */
@@ -641,7 +671,14 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
   sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_KTO]),10));
   for (i=0; i<recC[C_KTO].len; i++) buf[recC[C_KTO].pos+i] = tmp[i];
   sprintf (tmp, "%s", padzeroclip (real2string(values[C_VAL]),11));
+#ifndef DEFAULT_EURO
+  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_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];
+#endif
   if (values[C_MYKTO])
     sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
   else
@@ -704,10 +741,14 @@ int dtaus_writeE(FILE *f, int count, bigint sum, bigint blz, bigint kto)
   for (i=0; i<recE[E_COUNT].len; i++) buf[recE[E_COUNT].pos+i] = tmp[i];
   bigint_sprintf (tmp, "%s", sum);
   padzeroclip (tmp,13);
+#ifndef DEFAULT_EURO
+  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_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];
-  bigint_sprintf (tmp, "%s", sum);
-  padzeroclip (tmp,13);
-  for (i=0; i<recE[E_VAL].len; i++) buf[recE[E_VAL].pos+i] = tmp[i];
+#endif
   bigint_sprintf (tmp, "%s", kto);
   padzeroclip (tmp,17);
   for (i=0; i<recE[E_KTO].len; i++) buf[recE[E_KTO].pos+i] = tmp[i];
@@ -957,9 +998,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])) {
@@ -974,7 +1024,14 @@ 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());
-      fprintf(fbeleg, "\n    Waehrung ...................: DM\n");
+#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");
@@ -989,7 +1046,14 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
     else
       fprintf (fcheck, "    Sammelauftrag\n\n");
     fprintf (fcheck, "    Erstellungsdatum : %s\n\n", get_date());
-    fprintf (fcheck, "    Waehrung         : DM\n\n\n");
+#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 {