Corrections to data types, as found by Christian Zink <christian.zink@4students-ag...
[infodrom/dtaus] / dtaus.c
diff --git a/dtaus.c b/dtaus.c
index ed82a84..7c7ea71 100644 (file)
--- a/dtaus.c
+++ b/dtaus.c
@@ -1,6 +1,6 @@
 /*
 /*
-    dtaus.c - Datenträgeraustausch mit einer Bank
-    Copyright (c) 1996,8,2001  Martin Schulze <joey@infodrom.org>
+    dtaus.c - Belegloser Datenträgeraustausch mit einer Bank
+    Copyright (c) 1996,8,2001,2  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
 
     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
 #include <time.h>
 #include <malloc.h>
 
 #include <time.h>
 #include <malloc.h>
 
-/* #define DEFAULT_EURO */
+#define DEFAULT_EURO
+#ifndef DEFAULT_EURO
+int use_euro = 0;
+#endif
 
 /*
  *  First: Some control structures
 
 /*
  *  First: Some control structures
@@ -57,6 +60,7 @@ dtaus_record recA[] = {
   {"BLZ", 7, 8, REQ},
   {"Referenz", 70, 10, OPT},
   {"Datum", 50, 6, IGN},
   {"BLZ", 7, 8, REQ},
   {"Referenz", 70, 10, OPT},
   {"Datum", 50, 6, IGN},
+  {"Ausfuehrung", 95, 8, OPT},
   {"Euro", 127, 1, OPT},
   {NULL, 0, 0}
 };
   {"Euro", 127, 1, OPT},
   {NULL, 0, 0}
 };
@@ -67,15 +71,20 @@ dtaus_record recA[] = {
 #define A_BLZ  3
 #define A_REF  4
 #define A_DATE 5
 #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_EURO 7
+#define A_LEN  8
 
 dtaus_record recC[] = {
   {"Name", 93, 27, REQ},
   {"Konto", 21, 10, REQ},
   {"BLZ", 13, 8, REQ},
   {"Transaktion", 44, 5, REQ},
 
 dtaus_record recC[] = {
   {"Name", 93, 27, REQ},
   {"Konto", 21, 10, REQ},
   {"BLZ", 13, 8, REQ},
   {"Transaktion", 44, 5, REQ},
+#ifndef DEFAULT_EURO
   {"Betrag", 50, 11, REQ},
   {"Betrag", 50, 11, REQ},
+#else
+  {"Betrag", 79, 11, REQ},
+#endif
   {"Zweck", 155, 27, REQ},
   {"myName", 128, 27, OPT},
   {"myKonto", 69, 10, OPT},
   {"Zweck", 155, 27, REQ},
   {"myName", 128, 27, OPT},
   {"myKonto", 69, 10, OPT},
@@ -83,6 +92,9 @@ dtaus_record recC[] = {
   {"Euro", 182, 1, IGN},
   {"Text", 187, 29, OPT},
   {"Extension", 216, 29, OPT},
   {"Euro", 182, 1, IGN},
   {"Text", 187, 29, OPT},
   {"Extension", 216, 29, OPT},
+#ifndef DEFAULT_EURO
+  {"Betrag-Euro", 79, 11, IGN},
+#endif
   {NULL, 0, 0}
 };
 
   {NULL, 0, 0}
 };
 
@@ -98,15 +110,27 @@ dtaus_record recC[] = {
 #define C_EURO  9
 #define C_TEXT 10
 #define C_EXT  11
 #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
 #define C_LEN  12
+#endif
 
 
-#define MAX_TEXT 61
+#define MAX_TEXT 14
 
 dtaus_record recE[] = {
   {"Anzahl", 10, 7, IGN},
 
 dtaus_record recE[] = {
   {"Anzahl", 10, 7, IGN},
+#ifndef DEFAULT_EURO
   {"Summe", 17, 13, IGN},
   {"Summe", 17, 13, IGN},
+#else
+  {"Summe", 64, 13, IGN},
+#endif
   {"Kontos", 30, 17, IGN},
   {"BLZs", 47, 17, IGN},
   {"Kontos", 30, 17, IGN},
   {"BLZs", 47, 17, IGN},
+#ifndef DEFAULT_EURO
+  {"Summe-Euro", 64, 13, IGN},
+#endif
   {NULL, 0, 0}
 };
 
   {NULL, 0, 0}
 };
 
@@ -114,7 +138,9 @@ dtaus_record recE[] = {
 #define E_VAL  1
 #define E_KTO  2
 #define E_BLZ  3
 #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
 
 /*
  *  Second: Some low level routines
@@ -122,7 +148,7 @@ dtaus_record recE[] = {
 
 size_t dtaus_nextrec (void **buf, FILE *f)
 {
 
 size_t dtaus_nextrec (void **buf, FILE *f)
 {
-  bzero (buf, 128);
+  memset (buf, 0, 128);
   return fread(buf, 128, 1, f);
 }
 
   return fread(buf, 128, 1, f);
 }
 
@@ -208,7 +234,7 @@ char *strip_nondigits (char *s)
 char dtaus_char (void *buf, unsigned int pos)
 {
   static char res;
 char dtaus_char (void *buf, unsigned int pos)
 {
   static char res;
-  char *bufp = buf;
+  char *bufp = (char *)buf;
 
   bufp+=pos;
   memcpy(&res, bufp, 1);
 
   bufp+=pos;
   memcpy(&res, bufp, 1);
@@ -320,7 +346,7 @@ char *ext2string (char *s)
 unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
 {
   char tmp[30];
 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;
   static unsigned long int res;
 
   bufp+=pos;
@@ -340,8 +366,8 @@ char *extract_ident (char *line)
   static char word[30];
 
   if (strlen(line) > 0) {
   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);
 
     if (!x && !y) {
         strncpy(word, line, 29);
@@ -414,8 +440,8 @@ size_t control_nextline (void **buf, int len, FILE *f)
   char *cp;
   int i;
 
   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))) {
   cp = line;
 
   while (!strlen(line) && (cp = fgets(line, 100, f))) {
@@ -426,7 +452,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';
          while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
        } else
          line[strlen(line)-1] = '\0';
-       if (line[strlen(line)-1] == '\r')
+       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';
          line[strlen(line)-1] = '\0';
        for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
          line[i-1] = '\0';
@@ -468,7 +494,7 @@ void dtaus_prepareA (char *buf)
   struct tm *loctime;
   char tmp[10];
 
   struct tm *loctime;
   char tmp[10];
 
-  bzero (buf, 129);
+  memset (buf, 0, 129);
   timer = time ( NULL );
   loctime = localtime(&timer);
 
   timer = time ( NULL );
   loctime = localtime(&timer);
 
@@ -484,9 +510,12 @@ void dtaus_prepareA (char *buf)
   for (i=70;i<70+10; i++) buf[i] = '0';                /* A10 */
   for (i=80;i<80+48; i++) buf[i] = ' ';                /* A11 */
 #ifdef DEFAULT_EURO
   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) */
+  buf[recA[A_EURO].pos] = '1';                         /* A12 (Currency) */
 #else
 #else
-  buf[127] = ' ';                              /* A12 (Currency) */
+  if (use_euro)
+    buf[recA[A_EURO].pos] = '1';                               /* A12 (Currency) */
+  else
+    buf[recA[A_EURO].pos] = ' ';                               /* A12 (Currency) */
 #endif
 }
 
 #endif
 }
 
@@ -498,24 +527,19 @@ void dtaus_prepareC (char *buf, int normaltext, int maxtext)
 {
   int i;
   int appendix = 0;
 {
   int i;
   int appendix = 0;
-  div_t res;
 
 
-  bzero (buf, 257);
-  buf[0] = '0';
+  memset (buf, 0, 257);
 
   if (normaltext)
     appendix = 1;
 
   if (normaltext)
     appendix = 1;
-  if (maxtext) {
-    res = div (maxtext-1, 4);
-    appendix += res.quot;
-    if (res.rem) appendix++;
-  }
+  appendix += maxtext;
   i = 187 + (appendix * 29);
 
   /* Bail out if the number is too large, shouldn't be possible though */
   if (i >= 1000)
     exit (1);
 
   i = 187 + (appendix * 29);
 
   /* Bail out if the number is too large, shouldn't be possible though */
   if (i >= 1000)
     exit (1);
 
+  buf[0] = (i/1000)+48;i-=(i/1000)*100;
   buf[1] = (i/100)+48;i-=(i/100)*100;
   buf[2] = (i/10)+48;i-=(i/10)*10;
   buf[3] = i+48;
   buf[1] = (i/100)+48;i-=(i/100)*100;
   buf[2] = (i/10)+48;i-=(i/10)*10;
   buf[3] = i+48;
@@ -524,19 +548,24 @@ 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=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
   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) */
+  buf[recC[C_EURO].pos] = '1';                         /* C17a (Currency) */
 #else
 #else
-  buf[182] = ' ';                              /* C17a (Currency) */
+  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 */
 #endif
   for (i=183;i<183+2; i++) buf[i] = ' ';       /* C17b */
-  for (i=185;i<185+2; i++) buf[i] = '0';       /* C18 (#Extension) */
   for (i=187;i<187+(29*2); i++) buf[i] = ' ';  /* C19-C22 (misc text) */
   for (i=245;i<245+11; i++) buf[i] = ' ';      /* C23 */
   for (i=187;i<187+(29*2); i++) buf[i] = ' ';  /* C19-C22 (misc text) */
   for (i=245;i<245+11; i++) buf[i] = ' ';      /* C23 */
+
+  buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10;
+  buf[185+1] = appendix+48;
 }
 
 /*
 }
 
 /*
@@ -547,7 +576,7 @@ void dtaus_prepareE (char *buf)
 {
   int i;
 
 {
   int i;
 
-  bzero (buf, 129);
+  memset (buf, 0, 129);
   buf[0] = '0';
   buf[1] = '1';
   buf[2] = '2';
   buf[0] = '0';
   buf[1] = '1';
   buf[2] = '2';
@@ -582,12 +611,16 @@ int dtaus_writeA(FILE *f, char **values)
   dtaus_prepareA(buf);
   buf[5] = values[A_TRANS][0];
   buf[6] = values[A_TRANS][1];
   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<recA[A_BLZ].len; i++) buf[recA[A_BLZ].pos+i] = tmp[i];
   sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
   for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
   sprintf (tmp, "%-27.27s", upcase(values[A_NAME]));
   for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i];
-  sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),10));
-  for (i=0; i<10; i++) buf[recA[A_KTO].pos+i] = tmp[i];
+  if (values[A_TODO]) {
+    sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_TODO]),recA[A_TODO].len));
+    for (i=0; i<recA[A_TODO].len; i++) buf[recA[A_TODO].pos+i] = tmp[i];
+  }
+  sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[A_KTO]),recA[A_KTO].len));
+  for (i=0; i<recA[A_KTO].len; i++) buf[recA[A_KTO].pos+i] = tmp[i];
 
   fputs(buf, f);
   return 1;
 
   fputs(buf, f);
   return 1;
@@ -601,10 +634,9 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
   int i, k;
   int maxtext = 0;
   int fieldnr;
   int i, k;
   int maxtext = 0;
   int fieldnr;
-  div_t res;
 
 
-  if (text)
-    for (maxtext=0;text[maxtext];maxtext++);
+  /* Just count */
+  if (text) for (maxtext=0;text[maxtext];maxtext++);
 
 #if DEBUG
   for (i=0; (recC[i].name); i++)
 
 #if DEBUG
   for (i=0; (recC[i].name); i++)
@@ -624,15 +656,13 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
   }
 
   i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
   }
 
   i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
-    values[i][recC[i].len] = '\0';
+    values[i][recC[i].len-2] = '\0';
   i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
     values[i][recC[i].len] = '\0';
   i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
     values[i][recC[i].len] = '\0';
   i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
     values[i][recC[i].len] = '\0';
   i=C_ZWECK;if (values[i] && strlen(values[i]) > recC[i].len)
     values[i][recC[i].len] = '\0';
   i=C_MYNAM;if (values[i] && strlen(values[i]) > recC[i].len)
     values[i][recC[i].len] = '\0';
   i=C_TEXT;if (values[i] && strlen(values[i]) > recC[i].len)
     values[i][recC[i].len] = '\0';
-  i=C_EXT;if (values[i] && strlen(values[i]) > recC[i].len)
-    values[i][recC[i].len] = '\0';
 
   dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
   for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
 
   dtaus_prepareC (buf, values[C_TEXT] != NULL, maxtext);
   for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i];
@@ -647,7 +677,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));
   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];
   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
   if (values[C_MYKTO])
     sprintf (tmp, "%s", padzeroclip (strip_nondigits (values[C_MYKTO]),10));
   else
@@ -675,13 +712,6 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
     buf[recC[C_EXT].pos+1] = '2';
     sprintf (tmp, "%-27.27s", upcase(text[0]));
     for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
     buf[recC[C_EXT].pos+1] = '2';
     sprintf (tmp, "%-27.27s", upcase(text[0]));
     for (i=0; i<recC[C_EXT].len-2; i++) buf[recC[C_EXT].pos+2+i] = tmp[i];
-
-    res = div (maxtext-1, 4);
-    i=res.quot;
-    if (res.rem) i++;
-
-    buf[185+0] = (i/10)+48;i-=(i/10)*10;
-    buf[185+1] = i+48;
   }
 
   fputs(buf, f);
   }
 
   fputs(buf, f);
@@ -717,10 +747,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);
   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];
   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];
   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];
@@ -738,6 +772,50 @@ void printctln(FILE *f, char *field, char *value)
     fprintf(f, "  %s\t%s\n", field, value);
 }
 
     fprintf(f, "  %s\t%s\n", field, value);
 }
 
+/*
+ * one date line, format it properly
+ */
+void printctlndate(FILE *f, char *field, char *value)
+{
+  char mydate[11];
+  int i;
+
+  if (!strlen(field) || !strlen(value))
+    return;
+
+  for (i=0;isspace (value[i]) && i<= strlen (value); i++);
+  if (i == strlen (value))
+    return;
+
+  memset (mydate, 0, sizeof (mydate));
+  if (strlen (value) == 6) {
+    mydate[0] = value[0];
+    mydate[1] = value[1];
+    mydate[2] = '.';
+    mydate[3] = value[2];
+    mydate[4] = value[3];
+    mydate[5] = '.';
+    mydate[6] = value[4];
+    mydate[7] = value[5];
+    fprintf(f, "  %s\t%s\n", field, mydate);
+  } else if (strlen (value) == 8) {
+    mydate[0] = value[0];
+    mydate[1] = value[1];
+    mydate[2] = '.';
+    mydate[3] = value[2];
+    mydate[4] = value[3];
+    mydate[5] = '.';
+    mydate[6] = value[4];
+    mydate[7] = value[5];
+    mydate[8] = value[6];
+    mydate[9] = value[7];
+    fprintf(f, "  %s\t%s\n", field, mydate);
+  } else {
+    fprintf (stderr, "Broken date field: %s\n", value);
+    fprintf(f, "  %s\t%s\n", field, value);
+  }
+}
+
 
 /*
  *  Third: Some high level routines
 
 /*
  *  Third: Some high level routines
@@ -746,12 +824,13 @@ void printctln(FILE *f, char *field, char *value)
 void dtaus2control (char *cdtaus, char *ccontrol)
 {
   FILE *fdtaus, *fcontrol;
 void dtaus2control (char *cdtaus, char *ccontrol)
 {
   FILE *fdtaus, *fcontrol;
-  void *buf;
-  void *bufp;
+  char *buf;
+  char *bufp;
   char tmp[30];
   char x[30];
   int index;
   int extC;
   char tmp[30];
   char x[30];
   int index;
   int extC;
+  div_t res;
 
   if (!cdtaus) {
     if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
 
   if (!cdtaus) {
     if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
@@ -783,19 +862,23 @@ void dtaus2control (char *cdtaus, char *ccontrol)
       fprintf(fcontrol, "BEGIN {\n");
       bufp = buf;
 
       fprintf(fcontrol, "BEGIN {\n");
       bufp = buf;
 
-      for (index=A_TRANS; index < A_DATE; index++) {
+#ifndef DEFAULT_EURO
+      for (index=A_TRANS; index <= A_EURO; index++) {
+#else
+      for (index=A_TRANS; index < A_EURO; index++) {
+#endif
        bufp = buf + recA[index].pos;
        memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
        bufp = buf + recA[index].pos;
        memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
-       printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
+       if (index == A_DATE || index == A_TODO)
+         printctlndate(fcontrol, recA[index].name, tmp);
+       else
+         printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
       }
 
       }
 
-      index = A_DATE; bufp = buf + recA[index].pos;
-      memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
-      printctln(fcontrol, recA[index].name, strip_spaces(tmp));
-
-      index = A_EURO; bufp = buf + recA[index].pos;
-      memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
-      printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
+#ifndef DEFAULT_EURO
+      if (tmp[recA[index].pos] == '1')
+       use_euro = 1;
+#endif
 
       fprintf(fcontrol, "}\n\n");
     } else {
 
       fprintf(fcontrol, "}\n\n");
     } else {
@@ -819,15 +902,28 @@ void dtaus2control (char *cdtaus, char *ccontrol)
       } else {
        fprintf(fcontrol, "{\n");
 
       } else {
        fprintf(fcontrol, "{\n");
 
-       for (index=C_NAME; index <= C_EURO; index++) {
+       for (index=C_NAME; index < C_EURO; index++) {
+#ifndef DEFAULT_EURO
+         if (use_euro && index == C_VAL)
+           index = C_EUR;
+#endif
          bufp = buf + recC[index].pos;
          memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
          bufp = buf + recC[index].pos;
          memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
+#ifndef DEFAULT_EURO
+         if (index == C_EUR)
+           printctln(fcontrol, recC[C_VAL].name, strip_zeros(string2real(tmp)));
+         else
+#endif
          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)));
          else
            printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
          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)));
          else
            printctln(fcontrol, recC[index].name, strip_zeros(strip_spaces(tmp)));
+#ifndef DEFAULT_EURO
+         if (use_euro && index == C_EUR)
+           index = C_VAL;
+#endif
        }
 
        for (index=C_TEXT; index <= C_EXT; index++) {
        }
 
        for (index=C_TEXT; index <= C_EXT; index++) {
@@ -841,10 +937,15 @@ void dtaus2control (char *cdtaus, char *ccontrol)
 
        /* Number of extension records for this C record */
        extC = dtaus_int(buf, 185, 2);
 
        /* Number of extension records for this C record */
        extC = dtaus_int(buf, 185, 2);
-
+       extC -= 2;
+       if (extC > 0) {
+         res = div (extC, 4);
+         extC = res.quot;
+         if (res.rem) extC++;
+       }
       }
       if (dtaus_nextrec(buf, fdtaus) != 1)
       }
       if (dtaus_nextrec(buf, fdtaus) != 1)
-       bzero (buf, sizeof(buf));
+       memset (buf, 0, sizeof(buf));
 
       /*
        * Are there extension records that we have to check?
 
       /*
        * Are there extension records that we have to check?
@@ -863,7 +964,7 @@ void dtaus2control (char *cdtaus, char *ccontrol)
          }
        }
        if (dtaus_nextrec(buf, fdtaus) != 1)
          }
        }
        if (dtaus_nextrec(buf, fdtaus) != 1)
-         bzero (buf, sizeof(buf));
+         memset (buf, 0, sizeof(buf));
        extC--;
       }
       fprintf(fcontrol, "}\n");
        extC--;
       }
       fprintf(fcontrol, "}\n");
@@ -879,12 +980,24 @@ void dtaus2control (char *cdtaus, char *ccontrol)
       fprintf(fcontrol, "\nEND {\n");
 
       for (index=E_COUNT; index <= E_BLZ; index++) {
       fprintf(fcontrol, "\nEND {\n");
 
       for (index=E_COUNT; index <= E_BLZ; index++) {
+#ifndef DEFAULT_EURO
+       if (use_euro && index == E_VAL)
+         index = E_EUR;
+#endif
        bufp = buf + recE[index].pos;
        memcpy(tmp, bufp, recE[index].len); tmp[recE[index].len] = '\0';
        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)
+#endif
          printctln(fcontrol, recE[index].name, strip_zeros(string2real(tmp)));
        else
          printctln(fcontrol, recE[index].name, strip_zeros(tmp));
          printctln(fcontrol, recE[index].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;
+#endif
       }
 
       fprintf(fcontrol, "}\n");
       }
 
       fprintf(fcontrol, "}\n");
@@ -956,7 +1069,7 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
   /* 
    * Record A lesen
    */
   /* 
    * Record A lesen
    */
-  bzero(valA, sizeof(valA));
+  memset (valA, 0, sizeof(valA));
   control_nextline ((void *)line, 100, fcontrol);
   ident = extract_ident(line);
   if (!strcmp(ident, "begin") && (line[0] == '{')) {
   control_nextline ((void *)line, 100, fcontrol);
   ident = extract_ident(line);
   if (!strcmp(ident, "begin") && (line[0] == '{')) {
@@ -964,9 +1077,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)
     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);
        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])) {
       control_nextline ((void *)line, 100, fcontrol);
     }
     if (((recindex = rec_index("art", REC_A)) != -1) && valA[recindex] && strlen(valA[recindex])) {
@@ -981,7 +1103,17 @@ 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    Sammelauftrag\n\n");
       fprintf(fbeleg, "\n    VOL ........................:\n");
       fprintf(fbeleg, "\n    Erstellungsdatum ...........: %s\n", get_date());
-      fprintf(fbeleg, "\n    Waehrung ...................: DM\n");
+      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");
     }
     if (!dtaus_writeA(fdtaus, valA)) {
       fprintf (stderr, "Konnte den Anfangsdatensatz nicht schreiben.\n");
@@ -996,7 +1128,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());
     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 {
     fprintf (fcheck, "     %-10s  %-8s  %-30s   %12s\n", "Kontonr.", "BLZ", "Name", "Betrag");
     fprintf (fcheck, "    --------------------------------------------------------------------\n");
   } else {
@@ -1011,7 +1150,7 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
   sum_val = bigint_int(0);
   sum_blz = bigint_int(0);
   sum_kto = bigint_int(0);
   sum_val = bigint_int(0);
   sum_blz = bigint_int(0);
   sum_kto = bigint_int(0);
-  bzero(valC, sizeof(valC));
+  memset (valC, 0, sizeof(valC));
   control_nextline ((void *)line, 100, fcontrol);
   if (line[0] == '{') {
     while (strlen(line) && line[0] == '{') {
   control_nextline ((void *)line, 100, fcontrol);
   if (line[0] == '{') {
     while (strlen(line) && line[0] == '{') {
@@ -1067,7 +1206,7 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
       for (recindex=0; recindex<C_LEN; recindex++)
        if (valC[recindex])
          free(valC[recindex]);
       for (recindex=0; recindex<C_LEN; recindex++)
        if (valC[recindex])
          free(valC[recindex]);
-      bzero(valC, sizeof(valC));
+      memset (valC, 0, sizeof(valC));
       control_nextline ((void *)line, 100, fcontrol);
     }
   } else {
       control_nextline ((void *)line, 100, fcontrol);
     }
   } else {