home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / modula2 / compiler / m2mmdemo / isinst / module / listdemo.mod < prev    next >
Encoding:
Text File  |  1989-02-27  |  8.4 KB  |  286 lines

  1.  
  2. MODULE ListDemo;
  3.   (*---------------------------------------------------------------------*)
  4.   (*                          L I S T - D E M O                          *)
  5.   (*                           M 2 P R O L I B                           *)
  6.   (*  Copyright (C) 1988    Bühlmann Computer Software   CH-8636 WALD    *)
  7.   (*                     -- All Rights Reserved --                       *)
  8.   (*---------------------------------------------------------------------*)
  9.   (*  Author: X. Bühlmann                                                *)
  10.   (*                                                                     *)
  11.   (*  Version 1.0      Date: 30/05/88                                    *)
  12.   (*  Version 1.1      Date: 03/10/88       Angepasst auf M2Prolib V3.03 *)
  13.   (*---------------------------------------------------------------------*)
  14.   FROM SYSTEM IMPORT ADR, SIZE, WORD;
  15.   IMPORT Ascii, SystemDef, Files, Screen, String, ByteString, NumConv;
  16.   FROM SystemDef IMPORT aFileName;
  17.   FROM Random IMPORT SetRandomSeed, RandomCard;
  18.   FROM Keyboard IMPORT KeyPressed, Key;
  19.   FROM PrintSupport IMPORT aKeyTable, KeyTable, TableFile, ReadTable;
  20.   FROM PrintGround IMPORT PrinterInstall, aPrinterCode;
  21.   FROM PrintOut IMPORT PrnError, ePrnError, PrinterReset, ConnectPRN, 
  22.       InterfaceTp, Interface, KeyConvert;
  23.   FROM ListDriver IMPORT eFieldType, bFuncGroup, bFields, OpenList, 
  24.       CloseList, DefineFields, PrintList, eListStatus, LStatus;
  25.   FROM DateCalc IMPORT aDateType, rCardDateTp, aBtrvDate, BuildToDate, 
  26.       DateToBtrvDate;
  27.   CONST
  28.     cPageLen = 50;
  29.     cPort = 'PRN';
  30.   TYPE
  31.     listRec = 
  32.       RECORD
  33.         s : ARRAY [0..100] OF CHAR;
  34.         c : CARDINAL;
  35.         i : INTEGER;
  36.         l : LONGINT;
  37.         r : REAL;
  38.         d : aDateType;
  39.         Bd : aBtrvDate;
  40.       END;
  41.   VAR
  42.     ProgramHalt : BOOLEAN;
  43.     Handle : WORD;
  44.     EOF : BOOLEAN;
  45.   (**)
  46.   PROCEDURE read(VAR c : CHAR);
  47.     VAR
  48.       n : CARDINAL;
  49.     BEGIN
  50.       c := 0c;
  51.       n := 1;
  52.       IF Files.FRead(Handle,ADR(c),n) THEN
  53.       END;
  54.       IF (n=0) OR (c=0c) THEN
  55.         c := 12c;
  56.         EOF := TRUE;
  57.       END;
  58.     END read;
  59.   PROCEDURE readStr(VAR s : ARRAY OF CHAR);
  60.     VAR
  61.       xInd : CARDINAL;
  62.       c : CHAR;
  63.     BEGIN
  64.       xInd := 0;
  65.       LOOP
  66.         read(c);
  67.         IF (c>=40c) & (xInd<=HIGH(s)) THEN
  68.           s[xInd] := c;
  69.           INC(xInd);
  70.         END;
  71.         IF c=12c THEN
  72.           EXIT;
  73.         END;
  74.       END;
  75.     END readStr;
  76.   PROCEDURE ReadAsciiFirst(fileName : aFileName; VAR Line : ARRAY OF 
  77.       CHAR): BOOLEAN;
  78.     BEGIN
  79.       ByteString.FillBytes(ADR(Line), SIZE(Line), 0c);
  80.       EOF := FALSE;
  81.       IF Files.FOpen(fileName,Files.readAccess,Files.compatibility,
  82.           Files.inherit,Handle) THEN
  83.         readStr(Line);
  84.         RETURN NOT EOF;
  85.       END;
  86.       RETURN FALSE;
  87.     END ReadAsciiFirst;
  88.   PROCEDURE ReadAsciiNext(VAR Line : ARRAY OF CHAR): BOOLEAN;
  89.     BEGIN
  90.       ByteString.FillBytes(ADR(Line), SIZE(Line), 0c);
  91.       readStr(Line);
  92.       RETURN NOT EOF;
  93.     END ReadAsciiNext;
  94.   PROCEDURE CloseAsciiFile();
  95.     BEGIN
  96.       IF Files.FClose(Handle) THEN
  97.         EOF := FALSE;
  98.       END;
  99.     END CloseAsciiFile;
  100.   (*
  101.     *)
  102.   PROCEDURE Handler(error : ePrnError): BOOLEAN;
  103.     VAR
  104.       l : 
  105.         RECORD
  106.           chr : CARDINAL;
  107.         END;
  108.     BEGIN
  109.       CASE error OF
  110.       | outOfPaper :
  111.         Screen.ScrPutString(' Printer out of Paper');
  112.         Screen.ScrWriteLn();
  113.       | notBusy :
  114.         Screen.ScrPutString(' Printer not ready ');
  115.         Screen.ScrWriteLn();
  116.       ELSE
  117.         Screen.ScrPutString(' Printer not online or other error ');
  118.         Screen.ScrWriteLn();
  119.       END;
  120.       Screen.ScrPutString(' Esc = abort  /  Return = continue ');
  121.       Screen.ScrWriteLn();
  122.       LOOP
  123.         l.chr := Key();
  124.         CASE l.chr OF
  125.         | ORD(Ascii.cCR) :
  126.           ProgramHalt := FALSE;
  127.           RETURN TRUE;
  128.         | ORD(Ascii.cESC) :
  129.           ProgramHalt := TRUE;
  130.           RETURN FALSE;
  131.         ELSE
  132.         END;
  133.       END;
  134.     END Handler;
  135.   PROCEDURE End(): BOOLEAN;
  136.     BEGIN
  137.       IF KeyPressed() OR ProgramHalt THEN
  138.         IF (Key()#0) OR ProgramHalt THEN
  139.           RETURN TRUE;
  140.         END;
  141.       END;
  142.       RETURN FALSE;
  143.     END End;
  144.   PROCEDURE list();
  145.     VAR
  146.       random, Page, xInd : CARDINAL;
  147.       dbRec : listRec;
  148.     PROCEDURE ListDef();
  149.       BEGIN
  150.         DefineFields(ADR(Page), SIZE(Page), 1, Card, 0);
  151.         WITH dbRec DO
  152.           DefineFields(ADR(s), SIZE(s), 11, Str, 0);
  153.           DefineFields(ADR(c), SIZE(c), 11, Card, 0);
  154.           DefineFields(ADR(i), SIZE(i), 11, int, 0);
  155.           DefineFields(ADR(l), SIZE(l), 11, long, 0);
  156.           DefineFields(ADR(r), SIZE(r), 11, Real, 3);
  157.           DefineFields(ADR(d), SIZE(d), 11, date, 0);
  158.           DefineFields(ADR(Bd), SIZE(Bd), 11, Bdate, 0);
  159.         END;
  160.       END ListDef;
  161.     PROCEDURE RandomNumbers();
  162.       VAR
  163.         xDate : rCardDateTp;
  164.       BEGIN
  165.         IF random<32769 THEN
  166.           random := RandomCard(random);
  167.         ELSE
  168.           random := RandomCard(32000);
  169.         END;
  170.         SetRandomSeed(random);
  171.         WITH dbRec DO
  172.           c := random;
  173.           i := INTEGER(random MOD RandomCard(32000));
  174.           l := LONGINT(random) * LONGINT(10);
  175.           r := FLOAT(random) * FLOAT(random MOD RandomCard(32000)) /
  176.                100.0;
  177.           (**)
  178.           WITH xDate DO
  179.             day := RandomCard(28);
  180.             month := RandomCard(12);
  181.             year := RandomCard(2200);
  182.           END;
  183.           BuildToDate(xDate, d);
  184.           IF DateToBtrvDate(d,Bd) THEN
  185.           END;
  186.           (**)
  187.           WITH xDate DO
  188.             day := RandomCard(28);
  189.             month := RandomCard(12);
  190.             year := RandomCard(2200);
  191.           END;
  192.           BuildToDate(xDate, d);
  193.         END;
  194.       END RandomNumbers;
  195.     BEGIN
  196.       random := 32000;
  197.       ProgramHalt := FALSE;
  198.       TableFile := 'KeyTable.PRN';
  199.       PrinterInstall(cPort);
  200.       ConnectPRN(Interface, TRUE);
  201.       KeyConvert(TRUE);
  202.       IF End() THEN
  203.         ConnectPRN(Interface, FALSE);
  204.         RETURN;
  205.       END;
  206.       (**)
  207.       ListDef();
  208.       IF OpenList('DEMO.LST') THEN
  209.         Page := 1;
  210.         xInd := 0;
  211.         PrintList(1);
  212.         PrintList(6);
  213.         INC(xInd, 6);
  214.         ByteString.FillBytes(ADR(dbRec), SIZE(dbRec), 0c);
  215.         IF ReadAsciiFirst('DEMO.DB',dbRec.s) THEN
  216.           RandomNumbers();
  217.           PrintList(11);
  218.           LOOP
  219.             ByteString.FillBytes(ADR(dbRec), SIZE(dbRec), 0c);
  220.             IF ReadAsciiNext(dbRec.s) THEN
  221.               RandomNumbers();
  222.               PrintList(11);
  223.               INC(xInd, 2);
  224.               IF xInd>cPageLen THEN
  225.                 xInd := 6;
  226.                 INC(Page);
  227.                 PrintList(21);
  228.                 PrintList(26);
  229.                 PrintList(1);
  230.                 PrintList(6);
  231.               END;
  232.             ELSE
  233.               EXIT;
  234.             END;
  235.             IF End() THEN
  236.               EXIT;
  237.             END;
  238.           END;
  239.         ELSE
  240.           Screen.ScrWriteLn();
  241.           Screen.ScrPutString('Data-Base-File DEMO.DB not found');
  242.           Screen.ScrWriteLn();
  243.         END;
  244.         CloseAsciiFile();
  245.         PrintList(21);
  246.         PrintList(26);
  247.         IF CloseList() THEN
  248.         END;
  249.       ELSE
  250.         Screen.ScrWriteLn();
  251.         Screen.ScrPutString('List-File DEMO.LST not found');
  252.         Screen.ScrWriteLn();
  253.       END;
  254.     END list;
  255.   PROCEDURE Copyright();
  256.     BEGIN
  257.       Screen.ClearScrBound();
  258.       Screen.ScrWriteLn();
  259.       Screen.ScrPutString(
  260.           '                L I S T - D E M O    Version 1.1   ');
  261.       Screen.ScrWriteLn();
  262.       Screen.ScrPutString(
  263.           '                           1 9 8 8                 ');
  264.       Screen.ScrWriteLn();
  265.       Screen.ScrWriteLn();
  266.       Screen.ScrPutString(
  267.           '                         Copyright by           ');
  268.       Screen.ScrWriteLn();
  269.       Screen.ScrPutString(
  270.           '                 (c) Bühlmann Computer Software    ');
  271.       Screen.ScrWriteLn();
  272.       Screen.ScrPutString(
  273.           '                         CH-8636 Wald              ');
  274.       Screen.ScrWriteLn();
  275.       Screen.ScrWriteLn();
  276.       Screen.ScrWriteLn();
  277.       Screen.ScrPutString('  Esc = abort ');
  278.       Screen.ScrWriteLn();
  279.     END Copyright;
  280.   BEGIN
  281.     SetRandomSeed(3327);
  282.     EOF := FALSE;
  283.     Copyright();
  284.     list();
  285.   END ListDemo.
  286.