Checking+if+a+library+is+INSTALLed

//by Jon Ripley, January 2006//

//BBC BASIC for Windows// provides no built in function to check whether a library has been loaded into memory using the **INSTALL** command.

The following routine **FN_IsInstalled(lib$)** implements a method to check if a library is currently **INSTALL**ed:

code format="bb4w" DEF FN_IsInstalled(lib$) IF ?HIMEM = 0 THEN = FALSE LOCAL P%, tmp$ SYS "CharUpperBuff", !^lib$, LEN lib$ IF RIGHT$(lib$,4) = ".BBC" THEN lib$ = LEFT$(lib$, LEN lib$ - 4) P% = HIMEM REPEAT tmp$ = $$(P%+4) IF lib$ = "-" THEN PRINT tmp$ SYS "CharUpperBuff", !^tmp$, LEN tmp$ IF lib$ = tmp$ OR tmp$ = lib$ + ".BBC" THEN = TRUE P% += ?P% WHILE ?P% AND ?P% < &FF P% += ?P% ENDWHILE UNTIL (!P% AND &FFFFFF) = &FFFF00 = FALSE code

To check if a library is installed use code similar to the following:

code format="bb4w" IF FN_IsInstalled(@lib$+"WINLIB") THEN PRINT "WINLIB is installed." ELSE PRINT "WINLIB is not installed." ENDIF code

To list all installed libraries call **FN_IsInstalled("-")**.

Installing a library only once
When you [|INSTALL] a library, //BBC BASIC for Windows// checks whether that library is already installed (version 5.91a or later only), however it performs a case-sensitive comparison of the supplied path/filename. It will reliably detect the **same** INSTALL statement being executed a second time, but not necessarily a **different** INSTALL statement which installs the same library but specifies it differently.

Installing a library more than once is safe but wastes memory. If this is a concern, the following routine can be used instead of **INSTALL**:

code format="bb4w" DEF PROC_InstallOnce(lib$) IF NOT FN_IsInstalled(lib$) THEN INSTALL lib$ ENDPROC code