// £123 | \ # various characters to persuade gedit to accept the file // Takes listing form Intercode Translator and adds in hot links // and converts some characters // All refs to PROCRs, CONSTs and TABLEs can be clicked to go to the referenced PROCR or section // The ref in all PROCR, CONST and TABLE headings can be clicked to go to the generated code // In the generated code section, the ref number can be clicked to go to the referenced PROCR or section // Param 1 is the output file from the Intercode translator // Param 2 is the output file -- default stdout // A switch -a puts fancy work on the action numbers // e.g. modernise -a LP9.txt ITi.htm // A .csv file from copy-typing of the printer listing from the Intercode Translator can // be used to insert lines mapping back to the original photographs of the listing // e.g. modernise -a -mbest.csv LP9.txt ITi.htm // Currently all rights are reserved, but this will be made available under the GNU public license. #include #include #include #include "cstrs.c" #define PROCMODE 1 #define TABMODE 2 #define CONSTMODE 3 int verbosity = 0; int unicode = 0; // NZ if UNICODE output char buff[999]; char buff2[999]; char lastser[6]; char **map = NULL; int mapptr = 0; void makemap(char *mapfn) // make the map of image files to serial numbers { FILE *fin = fopen(mapfn, "r"); char picfn[9]; int i, j; char *p; if ( fin == NULL ) { perror(mapfn); return; } picfn[0] = 0; picfn[8] = 0; if ( fin == NULL ) perror(mapfn); else { map = (char **)malloc(2000*sizeof(char *)); j = 0; while ( fgets(buff, 998, fin) != NULL ) if ( buff[0] == '0' && buff[1] == 'f' ) // 0file,164,"http://sw.ccs.bcs.org/leo/JohnD/P1000054.JPG",,,,"","DavidH/Q1000054" memcpy(picfn, buff+43, 8); else if ( buff[1] == 'q' ) // skip queries ; else if ( isdigit(buff[0]) && picfn[0] != 0 ) { if ( buff[0] == '0' ) // initial line strcpy(buff, " "); // will match heading else if ( buff[4] == ',' ) // section definition { memcpy(buff+10, buff, 4); // needs a * in front memcpy(buff+1, buff+10, 4); buff[0] = '*'; // needs a * in front } strcpy(buff+5, picfn); map[j++] = strdup(buff); picfn[0] = 0; } fclose(fin); mapptr = j; // no of items in the map printf("Mapping %d items\n", j); map[j] = "zzzzzzzzzzzzz"; // will never match } mapptr = 0; // printf("%s\n%s\n%s\n", map[0], map[1], map[j-1]); } char *crtrim(char *s) // chop the crlf from the end of s { int i = strlen(s); while ( --i >= 0 && s[i] <= ' ' ) ; s[++i] = 0; return s; } int htmlconv(int i, char *s) // replace single charact at biff[i] by the string in s { int j = strlen(buff) + 16; int ls = strlen(s); strcpy(buff+j, buff+i); // keep the rest of the buffer strcpy(buff+i, s); // put in the new stuff strcpy(buff+i+ls, buff+j+1); // copy the tail end back on // printf("---%s\n", buff); return i+ls; } main(int argc, char **argv) { FILE *fin; FILE *fout = stdout; int i, j, wc, ref, act; int mode = 0; int actlinks = 0; // type of action info to produce int mrgen = 0; // indicates that we are processing a listing from the master routine generator char *actinfo; char *sornot = ""; char *ten, *eleven; i = 0; while ( *(argv[++i]) == '-' ) if ( (j = argv[i][1]) == 'a' ) // include action links if ( argv[i][2] == 0 ) actlinks ++; else actlinks = atoi(argv[i]+2); else if ( j == 'v' ) if ( argv[i][2] == 0 ) verbosity ++; // never referenced at the moment else verbosity = atoi(argv[i]+2); else if ( j == 's' ) // map images should be invoked by https sornot = "s"; else if ( j == 'm' ) makemap(argv[i]+2); else if ( j == 'u' ) unicode = 1; else if ( j == 'g' ) mrgen = 1; if ( i >= argc ) { fprintf(stderr, "Usage %s {switches} printer_listing [HTML_output_file]\n", *argv); fprintf(stderr, " Look at: http://sw.ccs.bcs/org/leo/modernise.c\n", *argv); exit(1); } fin = fopen(argv[i], "r"); if ( fin == NULL ) { perror(argv[i]); exit(1); } if ( ++i < argc ) fout = fopen(argv[i], "w"); if ( fout == NULL ) { perror(argv[i]); exit(1); } if ( unicode != 0 ) { fputs("\n\n\n
\n", fout);
      ten = "\xd0\xae";
      eleven = "\xe2\x80\xbc";
   }
   else
   {  fputs("
\n", fout);
      ten = "◊";
      eleven = "Π";
   }

   while  ( fgets(buff, 998, fin) != NULL  &&  memcmp(buff+16, "    END", 7) != 0 )
   {  if  ( memcmp(buff+27, "   ", 3) == 0 )        // ref all spaces
         ref = 0;
      else
         ref = atoi(buff+27);
      i = strlen(buff);
      while  ( --i >= 0  &&  buff[i] <= ' ' ) ;
      if  ( actlinks == 2 )       // need to pad buff to get correct printing position
      {  if  ( i < 114 )
            memset(buff+i+1, ' ', 121-i);
         i = 114;
      }
      buff[++i] = 0;
      i = 0;

      if  ( map != NULL  &&  memcmp(buff+10, map[mapptr], 5) == 0 )
      {  char *p = map[mapptr++] + 5;
         fprintf(fout, "  Source image: %s.JPG\n", sornot, p, p);
      }

      i = strlen(buff);
      while  ( --i >= 10 )              // stop just to left of serial number
         if  ( (wc = buff[i]) == '<' )
            htmlconv(i, "<");
         else if  ( wc == 'g' )
            htmlconv(i, ">");
         else if  ( wc == 'p'  ||  wc == '£' )
            htmlconv(i, "£");
         else if  ( wc == 'h' )
            htmlconv(i, "½");
         else if  ( wc == 'e' )
            htmlconv(i, eleven);           // some people prefer ∏
         else if  ( wc == 't' )
            htmlconv(i, ten);
      if  ( buff[9] == 'g' )               // jump destination
         buff[9] = '>';                    // messy HTML

      if  ( strlen(buff) < 10 )                             // probably blank
         fprintf(fout, "%s\n", buff);
      else if  ( memcmp(buff+13, "00     PROCR", 12) == 0 ) // start of PROCR
      {  mode = PROCMODE;
         buff[19] = 0;
         fprintf(fout, "%sPROCR   %d%s\n",
                       buff, ref, ref, ref, buff+30);
      }
      else if  ( memcmp(buff+13, "00     CONST", 12) == 0 ) // start of CONST
      {  mode = CONSTMODE;
         buff[19] = 0;
         fprintf(fout, "%sCONST   %d%s\n",
                       buff, ref, ref, ref, buff+30);
      }
      else if  ( memcmp(buff+13, "00     TABLE", 12) == 0 ) // start of TABLE
      {  mode = TABMODE;
         buff[19] = 0;
         fprintf(fout, "%sTABLE   %d%s\n",
                       buff, ref, ref, ref, buff+30);
      }
      else if  ( isdigit(buff[10])  &&  mode == PROCMODE )  // serial number
      {  if  ( buff[18] != ' ' )                            // just in case a realy weird line appears
            fprintf(fout, "%s\n", buff);
         else
         {  if  ( isdigit(i = buff[19]) )
               act = atoi(buff+19);
            else if  ( i == ' ' )
               act = 0;
            else if  ( i == 'G' )
               act = 76;
            else
               act = -1;
            if  ( act < 0 )
               actinfo = "";
            else
               actinfo = icstr[act];
            if  ( memcmp(actinfo, "Leo", 3) == 0 )    // computer code instruction
            {  actinfo = ccstr[(act-100)*8 + atoi(buff+40)*4 + atoi(buff+43)];
               if  ( actlinks == 8 )                  // special for master routine
                  if  ( strlen(buff+46) < 28 )        // short line no notes or comment or error report
                     strcpy(buff+46, actinfo);
                  else                                // otherwise overwrite literal and old ref
                  {  memset(buff+46, ' ', 27);        // blank out the zero literal etc
                     memcpy(buff+46, actinfo, strlen(actinfo));
                  }
            }
            i = 19;
            while  ( buff[++i] > ' ' ) ;     // skip over the action number

            if  ( ref >= 100  &&  ref < 999 )
            {  buff[27] = 0;
               if  ( (actlinks&7) == 0 )     // omit links to action info
                  fprintf(fout, "%s%d%s\n", buff, ref, ref, buff+30);
               else if  ( actlinks == 2 )    // no links but append the string
                  fprintf(fout, "%s%d%s%s\n", buff, ref, ref, buff+30, actinfo); // used to be "..%-90s%s\n"
               else if  ( actlinks == 1 )    // inset titles for hover action
               {  buff[i++] = 0;
                  buff[18] = 0;
                  fprintf(fout, "%s %s %s%d%s\n",
                                  buff, actinfo, buff+19, buff+i, ref, ref, buff+30);
               }
               else
               {  buff[i++] = 0;
                  buff[18] = 0;
                  fprintf(fout, "%s %s %s%d%s\n",
                                  buff, act, buff+19, buff+i, ref, ref, buff+30);
               }
            }
            else if  ( (actlinks&7) == 0 )   // omit links to action info
               fprintf(fout, "%s\n", buff);
            else if  ( actlinks == 2 )       // no links but append the string
               fprintf(fout, "%s%s\n", buff, actinfo);   // used to be "%-120s%s\n"
            else if  ( actlinks == 1 )       // insert titles for hover action
            {  buff[i++] = 0;
               buff[18] = 0;
               fprintf(fout, "%s %s %s\n", buff, actinfo, buff+19, buff+i);
            }
            else                             // action link but no ref link
            {  buff[i++] = 0;
               buff[18] = 0;
               fprintf(fout, "%s %s %s\n", buff, act, buff+19, buff+i);
            }
         }
      }
      else
         fprintf(fout, "%s\n", buff);
   }

   fputs(buff, fout);

   if  ( mrgen != 0 )    // if the is output from 08004 - master routine generator
   {  while  ( fgets(buff, 998, fin) != NULL )
         if  ( ! isdigit(buff[2]) )        // not a line of addresses
            fputs(buff, fout);
         else
         {  i = 2;
            strcat(buff, "            ");  // ensure termination at the end of the printed line
            while  ( isdigit(buff[i]) )    // Scan agross the line
            {  ref = atoi(buff+i);
               if  ( ref < 100 )           // not a PROCR
                  fprintf(fout, "  %3d=%4d", ref, atoi(buff+i+4));
               else
                  fprintf(fout, "  %3d=%4d", ref, ref, atoi(buff+i+4));
               i += 10;
            }
            fputs("\n", fout);
         }
   }

   else
   {  while  ( fgets(buff, 998, fin) != NULL )
      {  ref = atoi(buff+11);
         if  ( memcmp(buff, " PROCEDURE", 10) == 0  &&  ref < 1000  &&  ref != 0 )
            fprintf(fout, " PROCEDURE  %d%s", ref, ref, ref, buff+15);
         else if  ( memcmp(buff, "  SECTION ", 10) == 0  &&  ref < 1000 )
            fprintf(fout, "  SECTION   %d%s", ref, ref, ref, buff+15);
         else
         {  i = strlen(buff);
            while  ( --i >= 5 )              // stop just to left of memory address
               if  ( (wc = buff[i]) == 'p'  ||  wc == '£' )
                  htmlconv(i, "£");
               else if  ( wc == 'e' )
                  htmlconv(i, eleven);           // some people prefer ∏
               else if  ( wc == 't' )
                  htmlconv(i, ten);
            fputs(buff, fout);
         }

      }
   }

   fputs("
\n", fout); fclose(fin); fclose(fout); }