Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Format the output from LIBRARY /F

Aug
2,847
150
Take Command Console (TCC) has the LIBRARY command,
which provides the ability to

  • create
  • modify
  • delete
  • or display

library functions for use with TCC.

Ref: LIBRARY - Create, modify, delete, or display library functions

The LIBRARY /F option displays the loaded (matching) functions (the function name can contain wildcards).

For example;

Code:
R:\>library /f Utils.Library$c#run
utils.library$c#run {
@setlocal
@echo off
if isdir r:\temp set temp=r:\temp
set _libraryfunction=%0
set csc="C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\csc.exe"
iff %# eq 0 then
echo USAGE: %_libraryfunction test.cs
quit
endiff
set theEXE=%temp\%@name[%1].exe
set theHASH=%theEXE.hash
iff defined rebuild then
iff exist %theEXE then
del /q %theEXE
endiff
iff exist %theHASH then
del /q %theHASH
endiff
endiff
iff not exist %theHASH then
Gosub CompileEXE
iff exist %theEXE then
Gosub CreateHash
Gosub RunEXE
endiff
else
Gosub ReadHash
Gosub CompareHash
iff "%CompareHash" eq "Y" then
Gosub RunEXE
else
Gosub CompileEXE
iff exist %theEXE then
Gosub CreateHash
Gosub RunEXE
endiff
endiff
endiff
if isalias csc unalias csc
endlocal
quit
:CreateHash
echo %@md5[%1] >! %theHASH
set HashValue=%@md5[%1]
Return
:ReadHash
set HashValue=%@line[%theHASH,0]
Return
:CompareHash
debugstring Hash File: %HashValue
debugstring Source Hash: %@md5[%1]
iff "%HashValue" eq "%@md5[%1]" then
set CompareHash=Y
else
set CompareHash=N
endiff
debugstring CompareHash: %CompareHash
Return
:RunEXE
iff exist %theEXE then
%theEXE %2$
endiff
Return
:CompileEXE
rem You can remove VBCSCompiler.exe from memory by doing:
rem taskkill.exe /im VBCSCompiler.exe /f
if %@pid[VBCSCompiler.exe] eq 0 echo /shared /keepalive:600 not active.
%csc -nologo /shared /keepalive:600 %1 -out:%theEXE
iff %? ne 0 then
echo Error compiling %theEXE
quit
endiff
if %@pid[VBCSCompiler.exe] eq 0 echo /shared /keepalive:600 not active.
Return
}

...but I would prefer that the library code output be formatted.

So, I have developed a C# .NET Framework program,
CodeFormat.exe,
which accepts the output from the LIBRARY /F command via a pipe,
and outputs the library code formatted.

Code:
R:\>library /f Utils.Library$c#run | CodeFormat.exe
utils.library$c#run {
@setlocal
@echo off
if isdir r:\temp set temp=r:\temp
set _libraryfunction=%0
set csc="C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\csc.exe"

iff %# eq 0 then
    echo USAGE: %_libraryfunction test.cs
    quit
endiff

set theEXE=%temp\%@name[%1].exe
set theHASH=%theEXE.hash

iff defined rebuild then

    iff exist %theEXE then
        del /q %theEXE
    endiff

    iff exist %theHASH then
        del /q %theHASH
    endiff

endiff

iff not exist %theHASH then
    Gosub CompileEXE

    iff exist %theEXE then
        Gosub CreateHash
        Gosub RunEXE
    endiff

else
    Gosub ReadHash
    Gosub CompareHash

    iff "%CompareHash" eq "Y" then
        Gosub RunEXE
    else
        Gosub CompileEXE

        iff exist %theEXE then
            Gosub CreateHash
            Gosub RunEXE
        endiff

    endiff

endiff

if isalias csc unalias csc
endlocal
quit

:CreateHash
echo %@md5[%1] >! %theHASH
set HashValue=%@md5[%1]
Return

:ReadHash
set HashValue=%@line[%theHASH,0]
Return

:CompareHash
debugstring Hash File: %HashValue
debugstring Source Hash: %@md5[%1]

iff "%HashValue" eq "%@md5[%1]" then
    set CompareHash=Y
else
    set CompareHash=N
endiff

debugstring CompareHash: %CompareHash
Return

:RunEXE

iff exist %theEXE then
    %theEXE %2$
endiff

Return

:CompileEXE
rem You can remove VBCSCompiler.exe from memory by doing:
rem taskkill.exe /im VBCSCompiler.exe /f
if %@pid[VBCSCompiler.exe] eq 0 echo /shared /keepalive:600 not active.
%csc -nologo /shared /keepalive:600 %1 -out:%theEXE

iff %? ne 0 then
    echo Error compiling %theEXE
    quit
endiff

if %@pid[VBCSCompiler.exe] eq 0 echo /shared /keepalive:600 not active.
Return

}

This is how I compiled the CodeFormat.cs code to CodeFormat.exe on my Windows 10 system;

Code:
E:\...\CodeFormat>which csc
csc is an alias : "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\csc.exe"

E:\...\CodeFormat>csc CodeFormat.cs
Microsoft (R) Visual C# Compiler version 4.14.0-3.26424.7 (a528c90a)
Copyright (C) Microsoft Corporation. All rights reserved.


E:\...\CodeFormat>dir codeformat.exe

 Volume in drive E is New Volume   Serial number is 2c1e:6e61
 Directory of  E:\Documents\GitHub\CodeFormat\codeformat.exe

2026-10-22  10:33           7,680  CodeFormat.exe
               7,680 bytes in 1 file and 0 dirs    8,192 bytes allocated
   1,299,130,318,848 bytes free

@rconn please add the ability to output formatted code when using;

Code:
library /f Utils.Library$c#run

...so that I don't have to pipe the ouput into my CodeFormat.exe

Code:
library /f Utils.Library$c#run | CodeFormat.exe

Source code for CodeFormat.cs is available from my GitHub repository.

Ref: GitHub - joec4281/CodeFormat: Format the code from the TCC Library /F command.

Joe
 
The LIBRARY /F option displays the loaded (matching) functions (the function name can contain wildcards).
[ example deleted ]
...but I would prefer that the library code output be formatted.
I have never written a library function for TCC in my life, so I am hearing about this for the first time. Let me ask an uninformed question:

I assume that TCC ignores spaces, blank lines, and tab indentation, so that library functions can be written the same as batch files.

If you want the library code to be formatted, why not just list /the/path/to/library-file ?

Is it because you have a lot of functions?
 
I have 22 different library files.

Here's the contents of my Utils library;

Code:
utils.library$aiu
utils.library$BuildPrompt
utils.library$c#run
utils.library$c#run1
utils.library$cpw
utils.library$cyg
utils.library$ibm3270
utils.library$mrkdwn
utils.library$relib
utils.library$vbrun
utils.library$xEd

Here's the contents of my VFP library;
Code:
vfp.library$VFP
vfp.library$VFP.DoCmd
vfp.library$VFP.Eval
vfp.library$VFP.SetVar
vfp.library$VFP.StartServer
vfp.library$VFP.StopServer

All functions loaded into memory,
eliminating the need to repeatedly load a .btm from disk.

No association remains to the physical file,
once the functions are loaded into memory,

Joe
 
Another explanation...
I have all of my user-defined functions in my PowerShell Profile,
so that they all load when I start PowerShell.

When I want to see the code from a user-defined function,
I can view my $Profile,
and find my user-defined function,
or...

Code:
PS E:\utils> get-inseegobattery
94
PS E:\utils> get-content function:get-inseegobattery

    <#
    .SYNOPSIS
        Retrieves the battery percentage of an Inseego hotspot.
    .DESCRIPTION
        Queries the /srv/status endpoint of the Inseego device at 192.168.1.1
        and extracts the statusBarBatteryPercent value.
    .EXAMPLE
        Get-InseegoBattery
        # Outputs: 51
    #>
    $ip = "192.168.1.1"
    try {
        $result = curl.exe -s "http://$ip/srv/status" |
                  Select-String -Pattern '"statusBarBatteryPercent"\s*:\s*"(\d+)"' |
                  ForEach-Object { $_.Matches.Groups[1].Value }

        if ($result) {
            return $result
        } else {
            Write-Warning "Could not parse battery status from device."
        }
    } catch {
        Write-Error "Failed to connect to Inseego hotspot at $ip`n$_"
    }

PS E:\utils>

Joe
 
Back
Top