home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / oberon / system / textpreview.mod (.txt) < prev    next >
Oberon Text  |  2012-04-20  |  8KB  |  179 lines

  1. Syntax10.Scn.Fnt
  2. Syntax12.Scn.Fnt
  3. Syntax10i.Scn.Fnt
  4. Syntax10b.Scn.Fnt
  5. MODULE TextPreview;    (** CAS 19-May-92 (Rel. 2.42) **)
  6.     IMPORT
  7.         Texts, Viewers, Oberon, Printer, MenuViewers, TextFrames, TextPrinter, TextPFrames;
  8.     CONST
  9.         Version = "TextPreview  1.0  (cas 19 May 92)";
  10.         Menu = "System.Close  System.Copy  System.Grow  TextPreview.Synch  Edit.Store ";
  11.         mm = TextFrames.mm; Scale = mm DIV 10; Unit = TextPrinter.Unit;
  12.         bodyX = 15 * mm DIV Unit; bodyY = 15 * mm DIV Unit;
  13.         bodyW = 165 * mm DIV Unit; bodyH = 260 * mm DIV Unit;
  14.         W: Texts.Writer;
  15.     PROCEDURE Ch (ch: CHAR);
  16.     BEGIN Texts.Write(W, ch); Texts.Append(Oberon.Log, W.buf)
  17.     END Ch;
  18.     PROCEDURE Str (s: ARRAY OF CHAR);
  19.     BEGIN Texts.WriteString(W, s); Texts.Append(Oberon.Log, W.buf)
  20.     END Str;
  21.     PROCEDURE Int (n: LONGINT);
  22.     BEGIN Texts.Write(W, " "); Texts.WriteInt(W, n, 0); Texts.Append(Oberon.Log, W.buf)
  23.     END Int;
  24.     PROCEDURE Ln;
  25.     BEGIN Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
  26.     END Ln;
  27.     (* arguments *)
  28.     PROCEDURE GetMainArg (VAR S: Texts.Scanner; text: Texts.Text; org: LONGINT; VAR beg, end: LONGINT);
  29.         VAR time: LONGINT;
  30.     BEGIN Texts.OpenScanner(S, text, org); Texts.Scan(S); beg := org; end := text.len;
  31.         IF (S.class = Texts.Char) & (S.c = "^") THEN Oberon.GetSelection(text, beg, end, time);
  32.             IF time >= 0 THEN Texts.OpenScanner(S, text, beg); Texts.Scan(S) ELSE end := 0 END
  33.         END;
  34.         IF S.line # 0 THEN S.class := Texts.Inval END
  35.     END GetMainArg;
  36.     PROCEDURE ScanArgs (VAR S: Texts.Scanner; VAR pno, first, last, bx, by, bw, bh: INTEGER);
  37.         VAR i, k: INTEGER; ch: CHAR;
  38.     BEGIN
  39.         bx := bodyX; by := bodyY; bw := bodyW; bh := bodyH;
  40.         pno := 0; first := 0; last := 10000;
  41.         WHILE (S.class = Texts.Char) & (S.c = "\") DO Texts.Scan(S);
  42.             IF S.class = Texts.Name THEN ch := CAP(S.s[0]); Texts.Scan(S);
  43.                 IF ch = "A" THEN
  44.                 ELSIF (ch = "C") & (S.class = Texts.Int) & (1 <= S.i) & (S.i < 10) THEN Texts.Scan(S)
  45.                 ELSIF (ch = "F") & (S.class = Texts.Name) THEN Texts.Scan(S)
  46.                 ELSIF ch = "H" THEN
  47.                     IF (S.class = Texts.Name) OR (S.class = Texts.String) THEN Texts.Scan(S) END
  48.                 ELSIF ch = "M" THEN    (*margin options*)
  49.                     IF S.class = Texts.Name THEN ch := CAP(S.s[0]); Texts.Scan(S); i := 0;
  50.                         WHILE (S.class = Texts.Int) & (0 <= S.i) DO
  51.                             k := SHORT(S.i * Scale DIV TextPrinter.Unit); INC(i); Texts.Scan(S);
  52.                             IF ch = "H" THEN
  53.                             ELSIF ch = "B" THEN
  54.                                 IF i = 1 THEN bx := k ELSIF i = 2 THEN by := k
  55.                                 ELSIF i = 3 THEN bw := k ELSIF i = 4 THEN bh := k
  56.                                 END
  57.                             END
  58.                         END
  59.                     END
  60.                 ELSIF ch = "P" THEN    (*page options*)
  61.                     IF (S.class = Texts.Int) & (0 <= S.i) THEN pno := SHORT(S.i); first := pno; Texts.Scan(S)
  62.                     ELSIF S.class = Texts.Name THEN ch := CAP(S.s[0]); Texts.Scan(S)
  63.                     END
  64.                 ELSIF (ch = "S") & (S.class = Texts.Int) & (0 <= S.i) THEN first := SHORT(S.i); Texts.Scan(S);
  65.                     IF (S.class = Texts.Int) & (0 <= S.i) THEN last := SHORT(S.i); Texts.Scan(S) ELSE last := first END
  66.                 END
  67.             END
  68.         END
  69.     END ScanArgs;
  70.     (* pagination *)
  71.     PROCEDURE OpenDmyPrinter;
  72.         VAR name: ARRAY 32 OF CHAR;
  73.     BEGIN name := "Out.Prt"; Printer.Open(name, Oberon.User, Oberon.Password);
  74.         IF Printer.res # 0 THEN HALT(99) END
  75.     END OpenDmyPrinter;
  76.     PROCEDURE LocatePageBreaks (text: Texts.Text; pno, first, last, bx, by, bw, bh: INTEGER;
  77.             VAR pages: INTEGER; VAR porg: ARRAY OF LONGINT);
  78.         VAR org: LONGINT;
  79.     BEGIN org := 0; pages := 0;
  80.         WHILE (org < text.len) & (Printer.res = 0) DO
  81.             IF pages < LEN(porg) THEN porg[pages] := org END;
  82.             IF (first <= pno) & (pno <= last) THEN INC(pages) END;
  83.             TextPrinter.PlaceBody(bx, by, bw, bh, text, org, pno, FALSE);
  84.             Ch("."); INC(pno)
  85.         END
  86.     END LocatePageBreaks;
  87.     PROCEDURE CountPages (text: Texts.Text; pno, first, last, bx, by, bw, bh: INTEGER; VAR pages: INTEGER);
  88.         VAR porg: ARRAY 1000 OF LONGINT;
  89.     BEGIN LocatePageBreaks(text, pno, first, last, bx, by, bw, bh, pages, porg)
  90.     END CountPages;
  91.     (* commands *)
  92.     PROCEDURE Synch*;
  93.         VAR V: Viewers.Viewer; F: TextPFrames.Frame;
  94.     BEGIN F := Oberon.Par.vwr.dsc.next(TextPFrames.Frame);
  95.         V := Oberon.MarkedViewer();
  96.         IF (V IS MenuViewers.Viewer) & (V.dsc.next IS TextFrames.Frame) THEN
  97.             IF V.dsc.next IS TextPFrames.Frame THEN
  98.                 TextPFrames.Show(V.dsc.next(TextPFrames.Frame), F.org)
  99.             ELSIF V.dsc.next IS TextFrames.Frame THEN
  100.                 TextFrames.Show(V.dsc.next(TextFrames.Frame), F.org)
  101.             ELSE TextFrames.Show(V.dsc.next(TextFrames.Frame), F.org)
  102.             END
  103.         END
  104.     END Synch;
  105.     PROCEDURE This*;
  106.         VAR S: Texts.Scanner; V: Viewers.Viewer; F: TextFrames.Frame; beg, end: LONGINT; x, y: INTEGER;
  107.     BEGIN GetMainArg(S, Oberon.Par.text, Oberon.Par.pos, beg, end);
  108.         IF (S.class = Texts.Char) & (S.c = "*") THEN V := Oberon.MarkedViewer();
  109.             IF (V IS MenuViewers.Viewer) & (V.dsc.next IS TextFrames.Frame) THEN
  110.                 IF V.dsc IS TextFrames.Frame THEN
  111.                     Texts.OpenScanner(S, V.dsc(TextFrames.Frame).text, 0); Texts.Scan(S)
  112.                 ELSE S.s := "TextPreview.Text"
  113.                 END;
  114.                 F := V.dsc.next(TextFrames.Frame);
  115.                 Oberon.AllocateUserViewer(Oberon.Mouse.X, x, y);
  116.                 V := MenuViewers.New(TextFrames.NewMenu(S.s, Menu),
  117.                     TextPFrames.NewText(F.text, F.org), TextFrames.menuH, x, y)
  118.             END
  119.         END
  120.     END This;
  121.     PROCEDURE Paginate*;
  122.         VAR S: Texts.Scanner; V: Viewers.Viewer; F: TextPFrames.Frame; beg, end: LONGINT;
  123.             pages, h, pno, first, last, bx, by, bw, bh: INTEGER; porg: ARRAY 1000 OF LONGINT;
  124.     BEGIN GetMainArg(S, Oberon.Par.text, Oberon.Par.pos, beg, end);
  125.         IF (S.class = Texts.Char) & (S.c = "*") THEN Str("TextPreview.Paginate * "); Texts.Scan(S);
  126.             V := Oberon.MarkedViewer();
  127.             IF (V IS MenuViewers.Viewer) & (V.dsc.next IS TextPFrames.Frame) THEN
  128.                 ScanArgs(S, pno, first, last, bx, by, bw, bh);
  129.                 F := V.dsc.next(TextPFrames.Frame); OpenDmyPrinter;
  130.                 LocatePageBreaks(F.text, pno, first, last, bx, by, bw, bh, pages, porg);
  131.                 TextPFrames.SetPagination(F, pages, pno, bw, porg); Int(pages);
  132.                 h := F.H; TextPFrames.Resize(F, F.X, F.Y, F.W, 0); TextPFrames.Resize(F, F.X, F.Y, F.W, h)
  133.             ELSE Str("failed (* not a preview)")
  134.             END;
  135.             Ln
  136.         END
  137.     END Paginate;
  138.     PROCEDURE PageCount*;
  139.         VAR S: Texts.Scanner; V: Viewers.Viewer; text: Texts.Text; beg, end: LONGINT;
  140.             pages, total, pno, first, last, bx, by, bw, bh: INTEGER;
  141.     BEGIN Str("TextPreview.PageCount"); Ln;
  142.         GetMainArg(S, Oberon.Par.text, Oberon.Par.pos, beg, end);
  143.         OpenDmyPrinter;
  144.         IF (S.class = Texts.Char) & (S.c = "*") THEN Texts.Scan(S);
  145.             V := Oberon.MarkedViewer();
  146.             IF (V # NIL) & (V IS MenuViewers.Viewer) & (V.dsc.next IS TextFrames.Frame) THEN
  147.                 ScanArgs(S, pno, first, last, bx, by, bw, bh);
  148.                 text := V.dsc.next(TextFrames.Frame).text(Texts.Text);
  149.                 IF V.dsc IS TextFrames.Frame THEN
  150.                     Texts.OpenScanner(S, V.dsc(TextFrames.Frame).text, 0); Texts.Scan(S);
  151.                     IF S.class # Texts.Name THEN S.s[0] := "*"; S.s[1] := 0X END
  152.                 ELSE S.s[0] := "*"; S.s[1] := 0X
  153.                 END;
  154.                 Str("  "); Str(S.s); Str(" counting ");
  155.                 CountPages(text, pno, first, last, bx, by, bw, bh, pages);
  156.                 Int(pages); Ln
  157.             ELSE Str(" failed (bad * marker)"); Ln
  158.             END
  159.         ELSIF S.class = Texts.Name THEN
  160.             text := TextFrames.Text(S.s);
  161.             Str("  "); Str(S.s); Str(" counting ");
  162.             Texts.Scan(S); ScanArgs(S, pno, first, last, bx, by, bw, bh);
  163.             CountPages(text, pno, first, last, bx, by, bw, bh, pages);
  164.             Int(pages); Ln
  165.         ELSE total := 0;
  166.             ScanArgs(S, pno, first, last, bx, by, bw, bh);
  167.             WHILE (S.class = Texts.Name) & (beg < end) DO
  168.                 Str("  "); Str(S.s); Str(" counting ");
  169.                 text := TextFrames.Text(S.s);
  170.                 beg := Texts.Pos(S); Texts.Scan(S);
  171.                 CountPages(text, pno, first, last, bx, by, bw, bh, pages); INC(total, pages);
  172.                 Int(pages); Ln
  173.             END;
  174.             Str("  total"); Int(total); Ln
  175.         END
  176.     END PageCount;
  177. BEGIN Texts.OpenWriter(W); Str(Version); Ln
  178. END TextPreview.
  179.