Corrected the code after reading less ambigous specification I ordered.
authorJoey Schulze <joey@infodrom.org>
Sat, 17 Nov 2001 08:58:17 +0000 (08:58 +0000)
committerJoey Schulze <joey@infodrom.org>
Sat, 17 Nov 2001 08:58:17 +0000 (08:58 +0000)
 . C1 = Logical length of record C, i.e. 187 + number of extension records.

   ``Die Satzlängenangabe gezieht sich mit Ausnahme des konstanten
   Teils nicht auf die Satzabschnittlänge der Disketten, sondern auf
   die logische Satzlänge (konstanter Teil 187 Bytes +
   Erweiterungsteil(e) zu je 29 Bytes), max. "0622".''

   What does this mean?  There can only be 15 extension records and an
   extension record has the size of 29 bytes.  Hence the old code was
   wrong and the very old code was correct.  *sigh*

 . C18 = Number of extension records.

   ``00 = Es folgt kein Erweiterungsteil.
   01-15 = Anzahl der Erweiterungsteile á 29 Bytes''

Other things:

 . Generalized size in C1 (it's four digits, not only three, the first
   is not use though...)

 . Moved calculation of C18 into dtaus_prepareC()

 . Corrected stripping of the original Text field, should be
   superflous, but anyway...

 . Corrected decoding of C18 when decoding a dtaus file

dtaus.c

diff --git a/dtaus.c b/dtaus.c
index ed82a84..152a2dc 100644 (file)
--- a/dtaus.c
+++ b/dtaus.c
@@ -100,7 +100,7 @@ dtaus_record recC[] = {
 #define C_EXT  11
 #define C_LEN  12
 
-#define MAX_TEXT 61
+#define MAX_TEXT 14
 
 dtaus_record recE[] = {
   {"Anzahl", 10, 7, IGN},
@@ -498,24 +498,19 @@ void dtaus_prepareC (char *buf, int normaltext, int maxtext)
 {
   int i;
   int appendix = 0;
-  div_t res;
 
   bzero (buf, 257);
-  buf[0] = '0';
 
   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);
 
+  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;
@@ -534,9 +529,11 @@ void dtaus_prepareC (char *buf, int normaltext, int maxtext)
   buf[182] = ' ';                              /* C17a (Currency) */
 #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 */
+
+  buf[185+0] = (appendix/10)+48;appendix-=(appendix/10)*10;
+  buf[185+1] = appendix+48;
 }
 
 /*
@@ -601,10 +598,9 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
   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++)
@@ -624,15 +620,13 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values, char **text)
   }
 
   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_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];
@@ -675,13 +669,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];
-
-    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);
@@ -752,6 +739,7 @@ void dtaus2control (char *cdtaus, char *ccontrol)
   char x[30];
   int index;
   int extC;
+  div_t res;
 
   if (!cdtaus) {
     if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
@@ -841,7 +829,12 @@ void dtaus2control (char *cdtaus, char *ccontrol)
 
        /* 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)
        bzero (buf, sizeof(buf));