@ECHO OFF
:USAGE
:START
:INITIALIZE
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET BASE_DIR=%~DP0
    SET IN_VAR_NAME=%1
    SET IN_VALUE=%2
    SET OUT_VAR_NAME=%1

:CODE
    SET GLOBALS_FILE=%BASE_DIR%\globals.txt
    SET REFERENCE_COUNT=1
    SET VALUE=

    :WHILE_REF_EXISTS
        CALL GEN-REF REFERENCE
        CALL GET-GLOBAL %GLOBALS_FILE% REFERENCE VALUE
        
        IF NOT %VALUE% == "" GOTO :WHILE_REF_EXISTS

    CALL SET-GLOBAL %GLOBALS_FILE% REFERENCE %IN_VALUE%
    CALL SET-GLOBAL %GLOBALS_FILE% REFERENCE_COUNT[%REFERENCE%] %REFERENCE_COUNT%
    
:RETURN
    ENDLOCAL & (
        SET %OUT_VAR_NAME%=%REFERENCE%
    )

:EOF
@ECHO ON

Create new ref with ref count.
Create new ref with ref count.
