


{  18/7/87  21:38   memo}

%include "sm:formats.inc"
%include "sm:consts.inc"
%include "sm:persons.inc"
%include "sm:utils.inc"
!  If APM.
%include "inc:fs.imp"
%include "inc:fsutil.imp"
%include "inc:util.imp"
%include "inc:dict.imp"
%include "ie:ie.inc"
%externalroutinespec reset terminal %alias "IE_RESET_TERMINAL"
%externalroutinespec run program(%string(255) file)
%include "inc:run.imp"
%externalroutinespec set up terminal %alias "IE_SET_UP_TERMINAL"
%externalbytespec Terminal Model %alias "IE_TT_MODEL"
%CONSTINTEGER WY 75=6
!

%begin

{!  If Vax.}
{%recordformat df(%integer l, a)}
{%record(df) d}
{%externalroutinespec spawn %alias "LIB$SPAWN"(%record(df)%name d)}
{%externalstring(255)%fnspec translate(%string(*)%name s)}
{%string(63) x}
!
%integer control
%conststring(255) copymess= %c
"Only 'yes' and 'no' are legitimate values for LETTERS_FILE_COPY.
Please assign one of them in your login.com file."
%conststring(255) edmess= %c
"Only VECCE and IE are currently known to Letters.
Please assign one of these to LETTER_EDITOR in your login.com file."
%record(line80listf) editors,copy values
%conststring(15) editor="MEMO_EDITOR"
%string(15) edt
%conststring(19) file copy="MEMO_FILE_COPY"
%string(19) flcpy
%string(255) from=""
%string(255) fromtab=""        ;!  Used to align From, To and Date.
%string(255) memofile=""
%record(personlistf) names
%record(personlistf)%name noname
%string(255) outname=""
%string(255) output=""
%record(personf)%name p,q
%record(line80f)%name qq
%integer start line,start position,tolaser

%routine set up(%string(*)%name a,%string(63) var,default,%string(255) errmess,
%record(line80listf)%name values)
  a=var
{!  If Vax.}
{  upper(a)}
{  a=translate(a)}
!
!  If APM.
  lower(a)
  a=translate command symbol(a)
!
  lower(a); lower(var)
  a=default %and %return %if a=var
  message(Errmess,"stop") %if %not belongs(a,values)
%end

%routine print personlist(%record(personlistf)%name a,%string(255) s)
%record(personf)%name p
  message("No list with ".s,"") %and %return %if a==nil %or a_head==nil
  newline
  print string(s.snl)
  p==a_head
  %while p##nil %cycle
    print string(p_id)
    print string(" : ".p_extra_head_line) %unless p_extra_head==nil
    newline
    p==p_next
  %repeat
  newline
%end

!  This does not read the terminating nl.

%routine read rest of line(%string(*)%name a)
%integer j
  a=""
  read symbol(j) %and a=a.tostring(j) %while next symbol#nl
%end

!  This skips leading spaces.
!  It does not read the terminating space or newline.

%routine read word(%string(*)%name a)
%integer j
  skip symbol %while next symbol=sp %or next symbol=nl
  a=""
  read symbol(j) %and a=a.tostring(j) %while sp#next symbol#nl
%end

%routine read line(%string(*)%name a)
  skip symbol %while next symbol=sp %or next symbol=nl
  read rest of line(a)
%end

%routine get body of memo(%string(*)%name outname)
%integer oldin
%string(255) x,y,z
  %on %event 15 %start
    message("Stopped from input in 'Get body of memo'","stop")
  %finish

  outname=""; x=""; y=""; z=""
  oldin=instream
  select input(control)
!  Identify editor to be used.
  %cycle
    input(outname,27)
    lower(outname)
!  Resolve outname.
    y="" %unless (edt="vecce" %and outname->y.("/").outname) %c
    %or (edt="ie" %and outname->y.(" ").outname)
    outname->(" ").outname %while charno(outname,1)=' '
    %signal %event 15 %if outname=end
    %unless "*"#outname#"" %then message("No output name provided","") %c
    %elsestart
!  Extend outname.
      outname=outname.".lay" %unless outname->x.(".")
!  Resolve input about ','.
      z="" %unless y->y.(",").z
      %signal %event 15 %unless y#end#z
!  Extend input.
      y=y.".lay" %unless y="" %or y->x.(".")
      z=z.".lay" %unless z="" %or z->x.(".")
      %if y="" %thenstart
        y=outname %if exists(outname)
        %exit
      %finish
    %finish
{!  If Vax.}
{    outname=fixfile(outname,defaultdir,defaultext)}
{    y=fixfile(y,defaultdir,defaultext)}
{    z=fixfile(z,defaultdir,defaultext)}
!
    %exit %if exists(y)
    message(y." does not exist","")
  %repeat
  select input(0)  ;!  To control the editor.
{!  If Vax.}
{  z=",".z %unless z=""}
{  %if edt="vecce" %then z=y.z."/".outname %else %c}
{  %if edt="ie" %then z=y." ".outname %else %c}
{  message(edt." is an unknown editor. Please set MEMO_EDITOR.","stop")}
{  z=edt." ".z}
{  d_a=addr(z)+1; d_l=length(z)}
{  spawn(d)}
!
!  If APM.
  %if edt="vecce" %thenstart
    z=",".z %unless z=""
    memed(y.z."/".outname)
  %finishelse %c
  %if edt="ie" %thenstart
    start line=1; start position=1
    terminal model=WY 75
    set up terminal
    ie editor(y,outname,0,20,start line,start position,
    Default  Profile,Default Keyboard,Confirm!Silent!Reset Heap)
    reset terminal
  %finishelse message( %c
  edt." is an unknown editor. Please set Memo_editor to one".snl. %c
  "of VECCE or IE.","stop")
!
  select input(oldin)
%end


%routine reset ids(%record(personlistf)%name noname)
%record(personf)%name p
  %return %if noname==nil
  p==noname_head
  %while p##nil %cycle
    q==p; p==p_next
    q_id=q_extra_head_line %if q_surname=""
  %repeat
  noname==nil %if noname_head==nil
%end

%routine get cc(%record(personlistf)%name noname,%integer control)
!  This uses stream 3 if "@" appears in any list of recipients.
  %on %event 15 %start
    message("Stopped from input in 'Get cc'","stop")
  %finish
  get recipients(noname,24,control)
  select input(control); select output(0)
  reset ids(noname)
%end

%routine print style
  print string("$D #='$K163'".snl)
  print string("$Z.INCLUDE office:crest".snl)
  print string("$D.var bottom,file,fromtab".snl)
  print string("$D Head1(from)='-".snl)
  print string("$M(0.3"",0.5"",7.6"",10.5"")-".snl)
  print string("$T=0.5"",1"",1.5"",2"",2.5"",3"",3.5"",4"",". %c
               "4.5"",5"",5.5"",6"",6.5"",7"",7.5"",8""-".snl)
  print string("$L=0.2""?-".snl)
  print string("$Times17-".snl)
  print string("$J0$I=3$G=3$T*0-".snl)
  print string("$B0.3""$H{Department of Computer Science}-".snl)
  print string("$Q(file)$T8$H{FILE COPY}-".snl)
  print string("$B0.4""$G d0.075"" i0.02"" e7.8"" i0,0""-".snl)
  print string("$B0.2""$H{Memorandum}$T<0 $Times12  $I{From$ }$T>". %c
  "fromtab$from'".snl)
  print string("$D head2(date)='-".snl)
  print string("$B0$I{Date$ }$T>fromtab$date-".snl)
  print string("$B1$G d0.05"" i0,0.02"" e7.8"" i0,0$B0-".snl)
  print string("$J1'".snl)
  print string("$D.var pageno".snl)
  print string("$D.format memopages".snl)
  print string("=$Q(1-pageno)$O(0.2"",Y,7.2"",H-0.5""-Y)[]".snl)
  print string("=$Q(pageno)$O(0.2"",0,7.2"",H-0.5"")[]".snl)
  print string("=$pageno=pageno+1".snl)
  print string("=$Q(pageno-1)$B1$v(pageno)$B^0".snl)
  print string("=$C".snl)
  print string("=$memopages".snl)
  print string("$S*.memo".snl)
%end

%routine print heading(%string(255) date,from,to)
%integer m,n
  print string("$file=")
  n=19                                    ;!  Length of Date.
  n=length(from) %if n<length(from)
  n=length(to) %if n<length(to)
  %if to="FILE" %thenstart
    print string("1".snl)
    q==dests1_head
    %while q##nil %cycle
      %if q_extra_head==nil %then m=length(q_id) %c
      %else m=length(q_extra_head_line)
      n=m %if n<m
      q==q_next
    %repeat
  %finishelse print string("0".snl)
  n=n+1
  m=n//5
  m=m+1 %if m*5<n
  fromtab=itod(16-m)
  print string("$fromtab=".fromtab.snl)
  print string("$Head1'".from."'".snl)
  print string("$B0$I{To$ }$T>".fromtab)
  %if to="FILE" %thenstart
    q==dests1_head
    %while q##nil %cycle
      print string("$B0$T".fromtab) %unless q==dests1_head
      %if q_extra_head==nil %then print string(q_id) %c
      %else print string(q_extra_head_line)
      %if q_next##nil %then print string(",") %elsestart
        print string(".") %unless q==dests1_head
      %finish
      newline
      q==q_next
    %repeat
  %finishelse print string(to.snl)
  print string("$Head2'".date."'".snl)
  print string("$bottom=Y".snl)
  print string("$X0$Y0".snl)
  print string("$crest(W-1"",0,1)".snl)
  print string("$X0$Y(bottom)".snl)
  print string("$Times12".snl)
  print string("$pageno=0".snl)
  print string("$memopages".snl)
%end

%routine print tail
  print string(snl."$E*".snl)
%end

%routine append text(%string(255) s)
%integer i,oldin
  %on %event 9 %start
    close input
    select input(oldin)
    %return
  %finish
  oldin=instream
  open input(1,s)
  select input(1)
  %cycle
    read symbol(i)
    print symbol(i)
  %repeat
%end

%routine put out(%record(personlistf)%name copy)
%record(personf)%name p,q
%string(255) x
  %if copy==nil %or copy_head==nil %thenstart
    p==newperson
    p_id=""
    append cell(p,copy)
  %finish
  names_head==nil; names_tail==nil
  select output(2)
  print style
  p==copy_head
  %while p##nil %cycle
    q==newperson
    q=p; q_next==nil; q_prev==nil
    append cell(q,names)
    x=p_id
    print heading(ddate,from,x)
    append text(outname)
    print tail
    p==p_next
  %repeat
  print string("$E*.memo".snl."$E*".snl)
  close output
  select output(0)
%end

%routine reedit
%record(personf)%name p
%integer n
  %on %event 15 %start
    message("Stopped from input while Changing ".prt(n),"stop")
  %finish
  message( %c
  "For each item that may be changed you will be shown the prompt and".snl.%c
  "the current value. Respond with yes if you wish to change its value,".snl. %c
  "and give the new value in response to the prompt that follows.","")
  print string("Change ".prt(31)." ".from.snl)
  n=31
  print string("New ".prt(31).snl) %and %c
  input(from,31) %if panswer(31)=yes
  n=24
  print string("Change ".prt(24)."? ".snl)
  p==noname_head
  %while p##nil %cycle
    %unless p_extra_head==nil %thenstart
      print string(p_extra_head_line) %and newline %if "*"#p_extra_head_line#""
    %finish
    p==p_next
  %repeat
  print string("*".snl)
  %if panswer(24)=yes %thenstart
    print string("New ".prt(24).snl)
    delete list(noname)
    get recipients(noname,24,control)
  %finish
!  Set up to produce a file copy if desired.
  %if flcpy="yes" %thenstart
    p==newperson
    p_id="FILE"
    append cell(p,noname)
  %finish
  n=27
  print string("Change ".prt(27).outname.snl)
  skip symbol %and get body of memo(outname) %if panswer(27)=yes
%end

{  Main Program}

  %on %event 15 %start
    message("Memo stopped during input","stop")
  %finish
  select input(0); select output(0)
  control=0
!
  message("Type ""?"" for HELP, "".end"" to abandon.","")
  input(from,31)
!  Identify editor to be used.
  editors_head==nil; editors_tail==nil
  qq==newline80; qq_line="vecce"; append cell(qq,editors)
  qq==newline80; qq_line="ie"; append cell(qq,editors)
  set up(edt,editor,"vecce",edmess,editors)
  copy values_head==nil; copy values_tail==nil
  qq==newline80; qq_line="yes"; append cell(qq,copy values)
  qq==newline80; qq_line="no"; append cell(qq,copy values)
  set up(flcpy,file copy,"yes",copymess,copyvalues)
  noname==newpersonlist
  get cc(noname,control)
  %if flcpy="yes" %thenstart
    p==newperson
    p_id="FILE"
    append cell(p,noname)
  %finish
  get body of memo(outname)
  select input(control); select output(0)
  %if control=0 %thenstart
    message( %c
    "You may change any item other than the permanent heading by".snl. %c
    "answering ""yes"" to the next prompt.","")
    %cycle
      print string(prt(29).snl)
      %exit %if panswer(29)=no
      reedit
    %repeat
  %finish
  message(prt(49),"")
  tolaser=panswer(49)
  memofile=""
!  If APM.
  memofile="lp2:" %if tolaser=yes
!
  output="x".seqno.".lay"
  memofile=memofile.output
  open output(2,memofile)
  put out(noname)
  %if tolaser=yes %thenstart
{!  If Vax.}
{    x="@U0:[SM.OFFICE]LAS ".memofile}
{    d_l=length(x); d_a=addr(x)+1}
{    spawn(d)}
{    delete(memofile.";1")}
{    message(memofile." deleted.","")}
!
!  If APM.
    message("Memoranda sent to laser in ".memofile,"")
!
  %finishelse  message("Memoranda are in ".memofile,"")

%endofprogram
