'===========================================================================
' Subject: LIBRARY BUILDER                    Date: 01-29-98 (22:03)       
'  Author: David A. Wicker                    Code: QB                     
'  Origin: pyramax@fastlane.net             Packet: LIBRARY.ABC
'===========================================================================
DEFINT A-Z
'$DYNAMIC
' Create new .QLBs and .LIBs by combining others >>>>>>>>>>>>>>>>>>>>>>>>>>>>
' Written by David A. Wicker                                     Jan 29, 1998
' pyramax@fastlane.net
' http://www.fastlane.net/~pyramax
' ---------------------------------------------------------------------------
' As always, if you borrow anything from any source code for your
' shareware or freeware projects, please give credit to the original author!
' ---------------------------------------------------------------------------

' DEFINT A-Z and '$DYNAMIC as the first two lines of every QBasic program
' ensure maximum speed and maximum memory capability.
' They are chiseled in every single program I write.

' The FOLLOWING files must be available:
' * Denotes it must be in the current directory
' + Denotes it must be in the current directory or available on path
' - - -
' * bqlb45.lib
' + lib.exe
' + link.exe

DEF FNN$ (A) = MID$(STR$(A), 2)
' Convert a number to a string minus the preceding space.

PRINT
PRINT "LIBRARY BUILDER ÄÄ Written by David A. Wicker ÄÄ FREEWARE /\"
PRINT
' Hold down the [ALT] key and without letting it go, lightly tap out
' "1" "9" and "6" on the NUMBER KEYPAD.  You can store special characters
' such as this connecting line and more in your source code.
' Bring up [ALT] [H]elp, [C]ontents and <ASCII Character Codes> to see
' what all characters you can insert and display.  Most characters less
' than the SPACE #32 will not display well as part of the QBasic source code.

' Also this program was written solely for functionality only.
' Aside from some rudimentary checks for NULL input, there is no color
' or special effects.  I leave that up to your discretion.  :)

INPUT "Name of NEW .QLB and .LIB to build:", P$
' NOTE!  The new .QLB and .LIB written will overwrite any prior existing.

P$ = UCASE$(P$)
' UCASE$ converts any string to all UPPERCASE.

IF P$ = "" THEN END
A$ = ""
B$ = ""

FILES "*.QLB"
' Give a small directory of available .QLB files.

N = 1
DO
  PRINT "Name of .QLB #" + FNN$(N) + " to add: [ENTER] by itself shows completion"
 
  INPUT ":", T$
' Using a "," instead of the ";" for an input will hide the "?" output.

  T$ = UCASE$(T$)
  IF T$ = "" AND A$ = "" THEN END
  IF T$ > "" THEN
    A$ = A$ + " +" + T$ + ".lib"
    B$ = B$ + " " + T$ + ".lib"
    N = N + 1
  END IF
LOOP UNTIL T$ = ""
' Keep looping and adding size to A$ and B$ until complete.

PRINT
PRINT "OKAY to BUILD " + P$ + ".QLB ?  [Y / N]";
INPUT ":", Q$
IF UCASE$(LEFT$(Q$, 1)) <> "Y" THEN END

BSAVE P$ + ".lib", 0, 16
BSAVE P$ + ".qlb", 0, 16
KILL P$ + ".lib"
KILL P$ + ".qlb"
' This simple routine creates and then kills the .QLB/.LIB to be created.
' By using BSAVE we ensure no errors when the KILL statement comes around.

OPEN "o", 1, "$lib$.kbd"
PRINT #1, P$ + ".lib"
PRINT #1, "y"
PRINT #1, A$
PRINT #1, ""
CLOSE

SHELL "lib<$lib$.kbd"
' The SHELL command allows you to send a STRING directly to DOS.  Both DOS
' Commands and executing .EXE files are possible.

' using the "<" in DOS redirects the program being executed to use keystrokes
' from the selected file instead of the keyboard.  If the file is short of
' data causing the executable to not exit gracefully, the computer will
' hang and the keyboard will be disabled.  CTRL-ALT-DEL is your
' only salvation. :)

OPEN "o", 1, "$lib$.kbd"
PRINT #1, "/qu" + B$
PRINT #1, P$ + ".qlb"
PRINT #1, ""
PRINT #1, "bqlb45.lib"
CLOSE

SHELL "link<$lib$.kbd"
KILL "$lib$.kbd"

PRINT "* COMPLETE! *"
PRINT "Files: " + P$ + ".qlb and " + P$ + ".lib have been created."

' It's messy but it works!  Thanks to MAKEQLB.FAQ for some raw data, but
' apparently it is requiring a different linker and library builder as I
' could not get the example illustrated to work at all.

' I was only able to manage writing this by carefully watching how QBasic
' 4.5 created a library via the [ALT] [R]un, Make [L]ibrary .

' Done !  Make this an executable so you can always have an easy way to
' build QBasic libraries in the future.  Why use QBasic libraries ?
' As far as I have seen, they take =ZERO= memory from actual QBasic
' code so by converting your favorite subprograms and functions into
' a Library ensures maximum memory in the future, and, the convenience
' of porting them to any other QBasic program.
' IE:  QB /L MYLIB.LIB PROGRAM.BAS
