1 //                  ROFF for Multics
  2 //
  3 //  Last modified on 05/30/74 at 18:45:20 by R F Mabee.
  4 //
  5 //  This file contains the following routines for processing
  6 //  headers, footers, etc.:
  7 //
  8 //        Readhead            Read a header into a vector.
  9 //        Gethead             Allocate a new vector and call Readhead.
 10 //        Sethead             Set a header or a footer from control line.
 11 //        Freeheads           Free up one set of headers or footers.
 12 //        Title               Print a header or a footer.
 13 //  All are declared external.
 14 
 15 //  Copyright (c) 1974 by Massachusetts Institute of Technology and Honeywell Information Systems, Inc.
 16 
 17 //  General permission is granted to copy and use this program, but not to sell it, provided that the above
 18 //  copyright statement is given.  Contact Information Processing Services, MIT, for further information.
 19 //  Please contact R F Mabee at MIT for information on this program and versions for other machines.
 20 
 21 get "runoff_head"   // Declarations for ROFF.
 22 
 23 
 24 let Readhead (Head) = valof   // Read in head or foot.
 25      $(   let l = Nr - Nrx
 26           for i = 1 to l do Head!(i + 2) := Rawchar!(i + Nrx - 1)
 27           Head!0, Head!1, Head!2 := Ll, In, l               //  Save line length and indenting by definition.
 28           resultis Head
 29      $)
 30 
 31 and Gethead () = Nrx = Nr -* 0, Readhead (Newvec (Nr - Nrx + 2))
 32 
 33 and Sethead (EOhf) be
 34      $(   let OldNrx = Nrx
 35           test Nrx = Nr
 36           then Freeheads (EOhf)
 37           or   $(   let Fline = 0
 38                     test '0' le Rawchar!Nrx le '9'
 39                     then $(   Fline := ReadNumber (10)
 40                               unless 0 < Fline le Maxheads do
 41                                    $(   Report ("Bad header number")
 42                                         Fline := 1
 43                                    $)
 44                               unless EOhf!Fline = 0 do Freevec (EOhf!Fline)
 45                               EOhf!Fline := 0
 46                          $)
 47                     or   $(   Fline := 1
 48                               Freeheads (EOhf)
 49                          $)
 50                     if Nrx < Nr do EOhf!Fline := Gethead ()
 51                $)
 52           let h = 0
 53           for i = 1 to Maxheads unless EOhf!i = 0 do h := h + 1
 54           EOhf!0 := h
 55           Nrx := OldNrx
 56      $)
 57 and Freeheads (EhOf) be
 58      $(   for i = 1 to Maxheads unless EhOf!i = 0 do
 59                          $(   Freevec (EhOf!i)
 60                               EhOf!i := 0
 61                          $)
 62           EhOf!0 := 0
 63      $)
 64 
 65 and Title (Head) be
 66      $(   if Head = 0 return
 67           unless Print logor Ft goto Out
 68           let w = vec Maxline
 69           let Ll, In, l = Head!0, Head!1, Head!2
 70           for i = 1 to l do
 71                $(   w!i := Head!(i + 2)
 72                     if w!i = Spec_char do
 73                          $(   l := Use_ref (Head + 2, w, l)
 74                               break
 75                          $)
 76                $)
 77           let Delim, Count = w!1, 0
 78           for i = 1 to 4 do
 79                $(   l := l + 1
 80                     w!l := Delim
 81                $)
 82           let Start, Lengths = vec 3, vec 3
 83           for i = 1 to l do if w!i = Delim do
 84                $(   Lengths!Count := i - Start!Count - 1
 85                     Count := Count + 1
 86                     Start!Count := i
 87                     if Count ge 4 break
 88                $)
 89 
 90           if Lengths!3 = 0 & Lengths!2 = 0 & Lengths!1 = 0 goto Out
 91           let Widths, Gaps = vec 3, vec 3
 92           for i = 1 to 3 do
 93                $(   let p, k, c = w + Start!i, Lengths!i, 0
 94                     for j = 1 to k do c := c + Width (p!j)
 95                     Widths!i := c
 96                $)
 97 
 98           Gaps!1 := In
 99           test Lengths!2 = 0
100           then Gaps!2, Gaps!3 := 0, Ll - Widths!3 - Widths!1 - In
101           or   $(   Gaps!2 := MaxI (0, (Ll - In - Widths!2) / 2 - Widths!1)
102                     Gaps!3 := Ll - Widths!3 - Widths!2 - Gaps!2 - Widths!1 - In
103                $)
104 
105           if Lengths!3 = 0 do Gaps!3 := 0
106 
107           PrinterIndent ()
108           for i = 1 to 3 do
109                $(   Blank (Gaps!i)
110                     let p = w + Start!i
111                     for j = 1 to Lengths!i do WriteChar (p!j)
112                $)
113 
114   Out:    Newline (1)
115      $)