Added support for reading our own files again... including all
[infodrom/dtaus] / dtaus.c
diff --git a/dtaus.c b/dtaus.c
index 4ad2310..ec2c487 100644 (file)
--- a/dtaus.c
+++ b/dtaus.c
@@ -723,7 +723,8 @@ void dtaus2control (char *cdtaus, char *ccontrol)
   void *bufp;
   char tmp[30];
   char x[30];
-  int index, countC;
+  int index;
+  int extC;
 
   if (!cdtaus) {
     if (!(fdtaus = fopen("DTAUS0.TXT", "r")))
@@ -785,7 +786,10 @@ void dtaus2control (char *cdtaus, char *ccontrol)
   if (dtaus_nextrec(buf, fdtaus) == 1) {
     while (dtaus_char(buf,4) == 'C') {
       bufp = buf + 128;
-      if (dtaus_nextrec(bufp, fdtaus) == 1) {
+      if (dtaus_nextrec(bufp, fdtaus) != 1) {
+       fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
+       return;
+      } else {
        fprintf(fcontrol, "{\n");
 
        for (index=C_NAME; index <= C_EURO; index++) {
@@ -808,18 +812,34 @@ void dtaus2control (char *cdtaus, char *ccontrol)
          }
        }
 
-       countC = dtaus_int(buf, 185, 2);
-       countC = countC<3?0:countC-2/4;
-       countC += countC%4>0?1:0;
-       /* FIXME: Erweiterungsfelder werden ignoriert */
+       /* Number of extension records for this C record */
+       extC = dtaus_int(buf, 185, 2);
 
-       fprintf(fcontrol, "}\n");
-      } else {
-       fprintf (stderr, "Der zweite Teil der Transaktion ist kaputt.\n");
-       return;
       }
       if (dtaus_nextrec(buf, fdtaus) != 1)
        bzero (buf, sizeof(buf));
+
+      /*
+       * Are there extension records that we have to check?
+       *
+       * 2nd half of the AND is wrong, but since dtaus < 0.5 wrote 01
+       *     instead of 00 we should let it in so it can read its own
+       *     old files...  *sigh*
+       */
+      while (extC > 0 && dtaus_char(buf,4) != 'C') {
+       for (index=0; index < 4; index++) {
+         if ((dtaus_char(buf,index*29) != ' ')) {
+           bufp = buf + index*29;
+           memcpy(x, bufp, 2); tmp[2] = '\0'; bufp+=2;
+           memcpy(tmp, bufp, recC[C_TEXT].len-2); tmp[recC[C_TEXT].len-2] = '\0';
+           printctln(fcontrol, string2ext(x), strip_spaces(tmp));
+         }
+       }
+       if (dtaus_nextrec(buf, fdtaus) != 1)
+         bzero (buf, sizeof(buf));
+       extC--;
+      }
+      fprintf(fcontrol, "}\n");
     }
   }
 
@@ -829,7 +849,7 @@ void dtaus2control (char *cdtaus, char *ccontrol)
    */
   if (dtaus_char(buf,4) == 'E') {
     if (dtaus_char(buf,4) == 'E') {
-      fprintf(fcontrol, "END {\n");
+      fprintf(fcontrol, "\nEND {\n");
 
       for (index=E_COUNT; index <= E_BLZ; index++) {
        bufp = buf + recE[index].pos;