/*
 *
 * HeadLiner: Headline generator © 1994 PSR Software
 * 
 * Freeware.  May not be altered or modified without permission!
 *
 * $VER: Headliner v1.3 (04.04.94)
 *
 */

/* BOUNDARY · This marks the start of the program which I hereby
give permission to be altered as suits you. */

  FONTPATH = 'Fonts:Headliner'
  TEMP = 'T:Spot.Headliner.temp'

/* BOUNDARY · This marks the end of the program which may be
altered. */

LF = '0d'x
AP = '27'x

Address SPOT
Options Results

'IsIconified'
If RC=0 Then 'UnIconify'

'IsMessages'
If ~(RC=0) Then Do
   'RequestNotify PROMPT "Use only from Message window."'
   Exit
End

lineloop=1
Do Until RC>0
  'RequestString TITLE "Headline #'lineloop'" PROMPT "Specify the headline'LF'   Cancel to stop"'
  If ~(RC>0) Then Do
    LINE.lineloop=RESULT
    lineloop=lineloop+1
  End
End

LINENO=lineloop-1
If LINENO=0 Then Exit

'RequestFile TITLE "Headliner Font" PATH "'fontpath'" FILE "Headliner.SANSERIF.font" PATTERN "Headliner.#?.font"'
If RC>0 Then Exit
FONT=RESULT

If ~Open('Font',FONT,'r') Then Do
  'RequestResponse TITLE "Headliner" PROMPT "Cannot open requested font."'
  Exit
End

/* Read in font */

CHARSNO=0
HEIGHT=0
SPACE=3
GAP=1

Do Until Eof('Font') | (LINE='begin')
  LINE=ReadLn('Font')
  If Upper(Left(LINE,6))='CHARS=' Then Do
    CHARS=Trim(Right(LINE,Length(LINE)-6))
    CHARNO=Length(CHARS)
  End
  If Upper(Left(LINE,7))='HEIGHT=' Then Do
    HEIGHT=Strip(Right(LINE,Length(LINE)-7),'b')
  End  
  If Upper(Left(LINE,6))='SPACE=' Then Do
    SPACE=Strip(Right(LINE,Length(LINE)-6),'b')
  End
  If Upper(Left(LINE,4))='GAP=' Then Do
    GAP=Strip(Right(LINE,Length(LINE)-4),'b')
  End
End

If Eof('Font') Then Do
  'RequestNotify TITLE "Headliner" PROMPT "Font file insufficient.'LF'End of file reached."'
  Exit
End
If CHARNO=0 Then Do
  'RequestNotify TITLE "Headliner" PROMPT "Font file insufficient.'LF'No character references."'
  Exit
End
If HEIGHT=0 Then Do
  'RequestNotify TITLE "Headliner" PROMPT "Font file insufficient.'LF'Character height not specified."'
  Exit
End

'progressopen TITLE "Headliner" PROMPT "Reading font"'
REQ=RESULT

Do charloop=1 To CHARNO
  'progressupdate' REQ charloop CHARNO
  If RC>0 Then Do
    'progressclose' REQ
    Exit
  End
  Do heightloop=0 to HEIGHT-1
    CHAR.charloop.heightloop=ReadLn('Font')
  End
End

Call Close('Font')
'progressupdate' REQ 1 1 'PROMPT "Creating message"'
 
/* Create Message · you know, this algorithm killed half my brain.  If anyone
   ever has a silly idea like I did when I wrote this, think again :-)        */

Do clearloop=1 To ((LINENO*height)+height)
  MESSAGE.clearloop=''
End

Do lineloop=1 To LINENO
  Do charloop=1 To Length(LINE.lineloop)
    THECHAR=Pos(SubStr(LINE.lineloop,charloop,1),CHARS)
    If THECHAR=0 Then Do heightloop=0 To Height-1
      ref=(lineloop*height)+heightloop
      MESSAGE.ref=Insert(Copies(' ',SPACE),MESSAGE.ref,Length(MESSAGE.ref))
    End
    Else Do heightloop=0 To Height-1
      ref=(lineloop*height)+heightloop
      MESSAGE.ref=Insert(CHAR.thechar.heightloop,MESSAGE.ref,Length(MESSAGE.ref))
      MESSAGE.ref=Insert(Copies(' ',GAP),MESSAGE.ref,Length(MESSAGE.ref))
    End
  End
End

'progressclose' REQ

/* Write Message · the everso simple bit */

If ~Open('Message',TEMP,'w') Then Do
  'RequestNotify PROMPT "Can'AP't create output file"'
End

Do lineloop=1 To LINENO
  Do heightloop=0 To Height-1
    ref=(lineloop*height)+heightloop
    Call WriteLn('Message',MESSAGE.ref)
  End
End

Call Close('Message')

'Write FILE "'TEMP'"'

Address Command 'Delete >NIL:' TEMP
