QB64 Phoenix Edition
module/library version string? - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10)
+---- Thread: module/library version string? (/showthread.php?tid=1692)



module/library version string? - thesolarcode - 05-17-2023

Trying to implement version string per library.
I don't want to have for each library a separate CONST or SUB/FUNCTION with different name just to get it's version string. 
I also don't want to hardcode the library names and versions in a single place.
DATA / READ / RESTORE doesn't work, because RESTORE doesn't accept a variable.
Any ideas how I could implement this?


RE: module/library version string? - Petr - 05-17-2023

Hi,

Restore need label name, not variable:

Code: (Select All)
For t = 1 To 4
    Restore num_A
    count = 0
    Do Until count = t
        Read NrA
        count = count + 1
    Loop
    Restore num_B

    count = 0
    Do Until count = t
        Read NrB
        count = count + 1
    Loop
    Print "First number is: "; NrA
    Print "Second number is: "; NrB
    Print "First plus second number: "; NrA + NrB
Next

num_A:
Data 5,10,15,20

num_B:
Data 1,2,3,4



RE: module/library version string? - RhoSigma - 05-17-2023

(05-17-2023, 08:11 PM)thesolarcode Wrote: Trying to implement version string per library.
I don't want to have for each library a separate CONST or SUB/FUNCTION with different name just to get it's version string. 
I also don't want to hardcode the library names and versions in a single place.
DATA / READ / RESTORE doesn't work, because RESTORE doesn't accept a variable.
Any ideas how I could implement this?

Here's a prototype how I'd do it, it's certainly not bulletproof, but should work as an example to build your own.

Save as "Versions.bas"
Code: (Select All)
'Example for multiple embedded version strings.
_TITLE "Versions"

'The idea is to embed clearly identifyable strings into the compiled EXE.

'Each library defines its version string either globally in the .bi file or
'locally in any of the library's functions in the .bm file.
'Don't use CONSTs here, as CONSTed strings will not be embedded into the
'EXE per define, but only if the CONST would be actually assigned to a variable.
MY$ = "$VER: my.library 1.0 (17.05.23) Copyright (c) 2023 by Me :END$"
YOUR$ = "$VER: your.library 1.0 (17.05.23) Copyright (c) 2023 by You :END$"
OTHER$ = "$VER: other.library 1.0 (17.05.23) Copyright (c) 2023 by Whoever :END$"

COLOR 12: PRINT "This program makes use of the following modules/libraries:"
COLOR 15: PrintEmbeddedVersions "" 'empty or "ALL" to print all
PRINT
COLOR 12: PRINT "your.lib version is:"
COLOR 15: PrintEmbeddedVersions "your.lib" 'any unique part string will do
COLOR 7
END

'This SUB loads the programs own EXE into a string and searches for
'the embedded strings.
SUB PrintEmbeddedVersions (which$) 'empty = "ALL"
    OPEN "Versions.exe" FOR BINARY AS #1
    exe$ = SPACE$(LOF(1))
    GET #1, , exe$
    CLOSE #1
    IF which$ = "" THEN wch$ = "ALL": ELSE wch$ = which$ 'check and avoid side effect on argument

    vPos& = 0: vEnd& = 0
    DO
        vPos& = INSTR(vEnd& + 1, exe$, UCASE$("$ver: ")) 'see notes below
        IF vPos& > 0 THEN
            vEnd& = INSTR(vPos& + 1, exe$, UCASE$(" :end$")) 'see notes below
            IF vEnd& > 0 THEN
                vStr$ = MID$(exe$, vPos& + 6, vEnd& - vPos& - 6)
                IF UCASE$(wch$) = "ALL" OR INSTR(vStr$, wch$) > 0 THEN PRINT vStr$
            END IF
        END IF
    LOOP UNTIL vPos& = 0
END SUB
'You may wonder about the UCASE$ usage, when we could simply write the search
'string in uppercase as we use it in the actual version strings. Well, these
'search strings are also embedded in the EXE and would be misinterpreted as
'another version string with random (binary) content in between. With the use
'of UCASE$ and the lowercase writing we avoid this, as the lowercase text is
'actually embedded in the EXE, but the SUB searches only for the uppercase
'appearances of the strings.



RE: module/library version string? - DSMan195276 - 05-18-2023

(05-17-2023, 08:11 PM)thesolarcode Wrote: I don't want to have for each library a separate CONST or SUB/FUNCTION with different name just to get it's version string.

Can you clarify why you don't want to do this? What exactly is the goal?