UNLIBRARY / Wildcarded removal of functions from library without errors

Apr 13, 2010
236
3
58
The Hague
#1
Contrary to the mechanics of UNSET, UNALIAS and UNFUNCTION there is no UNLIBRARY yet.
Also, I would like to be able to suppress the error if I try to remove a function that is not in the library.
 
#2
Here is a .BTM that I created last year to tide me over until an UNLIBRARY command is available;
Code:
:: RmvLibrary.btm
::
:: This allows the removal of all in-memory functions from a specific library
::
@setlocal
@echo off
:: Assume that library files are located in _startpath\library
set LibPath=%_startpath\library
:: Scratch files location
set utils=c:\utils

:: If a library name was not entered on the command line...
iff %# eq 0 then
  Gosub LibsLoaded
  quit
endiff

set Lib2Remove=%1

:: Get a list of the libraries
ffind /v/m/t" {" "%LibPath\*.library" > %utils\LibRemove.list

:: No library has been found yet
set FoundLib=N

:: Loop through the list of libraries
do LibLine in @%utils\LibRemove.list
  iff %@left[4,%LibLine] eq ---- then
    iff %@word["\",-0,%LibLine] eq %Lib2Remove then
      :: Found the library
      set FoundLib=Y
    endiff
    iterate
  endiff

  iff %FoundLib eq Y then
    iff %@len[%LibLine] eq 0 then
      quit
    else
      :: Remove the library function
      on error gosub CantFind
      library /d %@word[0,%LibLine]
      on error
    endiff
  endiff  
enddo
endlocal
quit

:: Display libraries
:LibsLoaded
ffind /k/m/v/t"----" %utils\LibRemove.list > clip:
do theLibrary in @clip:
  echo %@word["\",-0,%theLibrary]
enddo
Return


:: Cannot find the library function in memory
:CantFind
iff %_? eq 2 then
  echo Library function %@word[0,%LibLine] not loaded.
endiff
Return
YMMV

Joe