home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ober1096.zip / libsrc / o2errlst.mod < prev    next >
Text File  |  1995-04-20  |  4KB  |  121 lines

  1. (*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*)
  2. (* This is the utility program which takes the error    *)
  3. (* message file for Gardens Point Modula and processes  *)
  4. (* it into the form necessary for use by O2InOut        *)
  5.  
  6. (* Format of the text file is:                          *)
  7. (*      textFile = {comment | message} nul.             *)
  8. (*      comment  = 'line not starting with number'.     *)
  9. (*      message  = number errMess.                      *)
  10. (*      number   = 'an ascii decimal number'.           *)
  11.  
  12. (* Format of the output table is:                       *)
  13. (*      outTable = index textFile.                      *)
  14. (*      index    = ARRAY[0 .. 512] OF CARDINAL;         *)
  15. (* each index entry is an index into the output table   *)
  16. (* and indexes the corresponding number.errMess string  *)
  17. (*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*)
  18.  
  19. MODULE O2ErrLst;
  20.  
  21. (*
  22.   Revisions:
  23.  
  24.   24-Mar-92  jrh  Remove 'old' format
  25.           (input o2errs.txt -> output o2errlst.dat);
  26.           'new' format with verbose error message text is
  27.           input errmess.txt -> output o2errlst.dat2.
  28.   12-Nov-92  jrh  Further size increase.
  29.   28-Feb-94  pms  Further size and index increase 5300 & 600
  30.   02-Mar-94  pms  Error list file now o2errlst.dat same as pc and native code.
  31. *)
  32.  
  33.   IMPORT SYSTEM;
  34.   FROM Terminal IMPORT WriteString, WriteLn, Write, WriteCard;
  35.   FROM ProgArgs IMPORT UNIXexit, EnvironString;
  36.   FROM PathLookup IMPORT FindAndOpen;
  37.   FROM UxFiles IMPORT Open, OpenMode, Create, Close,
  38.              ReadNBytes, WriteByte, File;
  39.  
  40.   CONST bytesInWord = 4;
  41.   CONST eol      = 12C;
  42.         fileSize = 53000; (* >= bytes in o2errs.txt *)
  43.         indexSiz = 600;
  44.         chrStart = indexSiz * bytesInWord;
  45.         totalSiz = chrStart + fileSize; (*  9000 @ 10-Apr-89 *)
  46.                     (* 10000 @ 16-Aug-89 *)
  47.                     (* 50000      Mar-92 *)
  48.                     (* 52048      Nov-92 *)
  49.                                         (* 55400      Mar-94 *)
  50.  
  51.   VAR   ch    : CHAR;
  52.         ok    : BOOLEAN;
  53.         read  : CARDINAL;
  54.         ix,lx : CARDINAL;
  55.         total : CARDINAL;
  56.         table : RECORD
  57.                   CASE (* no tag *) : BOOLEAN OF
  58.                   | TRUE  : index : ARRAY [1 .. indexSiz] OF CARDINAL;
  59.                   | FALSE : chars : ARRAY [0 .. totalSiz] OF CHAR;
  60.                   END;
  61.                 END;
  62.         pathStr, absName : ARRAY [0 .. 131] OF CHAR;
  63.         errFile, outFile : File;
  64.  
  65. BEGIN
  66.   FindAndOpen(".","o2errs.txt",absName,errFile);
  67.   IF errFile = NIL THEN
  68.     EnvironString("PATH",pathStr);
  69.     FindAndOpen(pathStr,"o2errs.txt",absName,errFile);
  70.   END;
  71.   IF errFile <> NIL THEN
  72.     WriteString("Reading ");
  73.     WriteString(absName); WriteLn;
  74.   ELSE
  75.     WriteString("**** o2errs.txt not found ****");
  76.     WriteLn; UNIXexit(1);
  77.   END;
  78.   FOR ix := 1 TO indexSiz DO table.index[ix] := 0 END;
  79.   Create(outFile,"o2errlst.dat",ok);
  80.   IF NOT ok THEN
  81.     WriteString("**** Can't create o2errlst.dat ****");
  82.     WriteLn; UNIXexit(1);
  83.   END;
  84.   ReadNBytes(errFile,
  85.              SYSTEM.ADR(table.chars[chrStart]),
  86.              fileSize,
  87.              read);
  88.   Close(errFile,ok);
  89.   ix := chrStart;
  90.   ch := table.chars[ix];
  91.   WHILE ch <> 0C DO (* another line *)
  92.     lx := ix;
  93.     WHILE ch = " " DO (* skip leading blanks *)
  94.       INC(ix); ch := table.chars[ix];
  95.     END;
  96.     (*
  97.        now, is there a number starting the line?
  98.     *)
  99.     IF ("0" <= ch) AND (ch <= "9") THEN
  100.       total := 0;
  101.       WHILE ("0" <= ch) AND (ch <= "9") DO
  102.         total := total * 10 + ORD(ch) - ORD("0");
  103.         INC(ix); ch := table.chars[ix];
  104.       END;
  105.       table.index[total] := lx;        
  106.     END;
  107.     (*
  108.        now find end of line
  109.     *)
  110.     WHILE (ch <> eol) AND (ch <> 0C) DO
  111.       INC(ix); ch := table.chars[ix];
  112.     END;
  113.     IF ch = eol THEN INC(ix); ch := table.chars[ix] END;
  114.   END; (* while *)  
  115.   FOR ix := 0 TO chrStart + read DO 
  116.     WriteByte(outFile,table.chars[ix]);
  117.   END;
  118.   Close(outFile,ok);
  119. END O2ErrLst.
  120.  
  121.