' **********************************************
' *  This is a routine which you can load into *
' * your progs to save running the LIBRARIAN   *
' * every time you need to make a new LST file.*
' **********************************************
Dim Opt$(150)
Dim Opt!(150)
Dim St%(150)
@Makelistlib
'
Procedure Makelistlib
  Cls
  Z%=0
  Alert 0,"Select LIB file and |ensure there is a MKE|file to go with it.",1," OK ",Ok%
  Clr B$,Flib$
  Fileselect "a:\*.LIB",B$,Flib$
  Clr B$,Sfile$
  Alert 0," Please enter name of | LST file to make ",1," OK ",But%
  Fileselect "a:\*.LST",B$,Sfile$
  Clr Fmke$
  If Flib$<>""
    Fmke$=Left$(Flib$,(Len(Flib$)-3))+"MKE"
    Open "i",#99,Fmke$
    On Error Gosub Handle
    Repeat
      Line Input #99,Opt$(Z%)
      @Ffile(Opt$(Z%))
      Opt$(Z%)=Ret$
      Input #99,St%(Z%)
      Inc Z%
    Until Eof(#99)
    Close #99
    @Select
    Cls
    Print " Building LIB file now."
    Open "i",#99,Flib$
    On Error Gosub Handle
    Open "o",#1,Sfile$
    Ex!=False
    Fp%=0
    For X%=0 To Z%+2
      If Opt!(X%)=True
        Seek #99,St%(X%)
        Print "Adding => ";Opt$(X%)
        Repeat
          Print #1,B$
          Line Input #99,B$
        Until B$="<ENDLIB> "
      Endif
    Next X%
  Endif
  Clr B$,A$,Fp%
  Close #1
  Close #99
  Erase St%()
Return
Procedure Handle
  Close #99
  Resume Next
Return
Procedure Ffile(A$)
  If A$<>""
    A$=A$+" "
    Clr A%,B%,C%
    Do
      B%=A%
      A%=Instr(A%+1,A$,"\")
      Exit If A%=0
    Loop
    If B%>0
      If Mid$(A$,7,1)<>"\"
        C%=Instr(1,A$," ")
        Ret$=Mid$(A$,B%+1,C%)
      Else
        C%=Instr(B%+1,A$," ")
        Ret$=Mid$(A$,B%+1,C%-B%)
      Endif
    Else
      Ret$=A$
    Endif
  Endif
Return
Procedure Select
  Arrayfill Opt!(),False
  Y=1
  P=0
  Rerun=0
  Cls
  While Opt$(P)<>"" And P<120
    For X=1 To 72 Step 16
      Print At(X,Y);" ";Opt$(P)
      Inc P
    Next X
    Inc Y
  Wend
  Sp=Y-1
  P=0
  F=0
  Of=1
  Y=1
  X=1
  Oy=1
  Ox=18
  K$=""
  Ex!=False
  Repeat
    K$=Inkey$
    If Oy<>Y Or Ox<>X
      Print At(X,Y);">";Opt$(F);"<"
      Print At(Ox,Oy);" ";Opt$(Of);" "
      Oy=Y
      Ox=X
      Of=F
    Endif
    If Len(K$)>1 And X<54 And Asc(Right$(K$,1))=77
      Add X,16
      Inc F
    Endif
    If Len(K$)>1 And X>1 And Asc(Right$(K$,1))=75
      Sub X,16
      Dec F
    Endif
    If Len(K$)>1 And Y>1 And Asc(Right$(K$,1))=72
      Sub F,5
      Dec Y
    Endif
    If Len(K$)>1 And Y<Sp And Asc(Right$(K$,1))=80
      Add F,5
      Inc Y
    Endif
    If K$=Chr$(27)
      Ex!=True
    Endif
    If K$=" "
      Opt!(F)=True
      Opt$(F)=Chr$(27)+"p"+Opt$(F)+Chr$(27)+"q"
      Print At(X,Y);">";Opt$(F);"<"
      Print At(Ox,Oy);" ";Opt$(Of);" "
    Endif
  Until Ex!=True
Return
