AlvinSeville7cf

findstr error

Jul 4th, 2021 (edited)
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 39.62 KB | None | 0 0
  1. @echo off
  2. setlocal
  3.  
  4. call :init
  5. set /a "init_error_level=%errorlevel%"
  6. if %init_error_level% gtr 0 exit /b %init_error_level%
  7.  
  8. call :clear_arguments args
  9.  
  10. set /a "i=0"
  11. :copy_options
  12.     set "option=%~1"
  13.     if defined option (
  14.         set "args[%i%]=%option%"
  15.         shift
  16.         set /a "i+=1"
  17.         goto copy_options
  18.     )
  19.  
  20. call :expand_sugar_options args
  21. set /a "temp_error_level=%errorlevel%"
  22. if %temp_error_level% gtr 0 exit /b %temp_error_level%
  23.  
  24. set /a "i=0"
  25. :main_loop
  26.     set /a "j=%i% + 1"
  27.     call set "option=%%args[%i%]%%"
  28.     call set "value=%%args[%j%]%%"
  29.  
  30.     set /a "is_help=%false%"
  31.     if "%option%" == "-h" set /a "is_help=%true%"
  32.     if "%option%" == "--help" set /a "is_help=%true%"
  33.  
  34.     if "%is_help%" == "%true%" (
  35.         call :help
  36.         exit /b %ec_success%
  37.     )
  38.  
  39.     set /a "is_version=%false%"
  40.     if "%option%" == "-v" set /a "is_version=%true%"
  41.     if "%option%" == "--version" set /a "is_version=%true%"
  42.  
  43.     if "%is_version%" == "%true%" (
  44.         call :version
  45.         exit /b %ec_success%
  46.     )
  47.  
  48.     set /a "is_interactive=%false%"
  49.     if "%option%" == "-i" set /a "is_interactive=%true%"
  50.     if "%option%" == "--interactive" set /a "is_interactive=%true%"
  51.  
  52.     if "%is_interactive%" == "%true%" (
  53.         call :interactive
  54.         exit /b %ec_success%
  55.     )
  56.  
  57.     set /a "is_width=%false%"
  58.     if "%option%" == "-w" set /a "is_width=%true%"
  59.     if "%option%" == "--width" set /a "is_width=%true%"
  60.  
  61.     if "%is_width%" == "%true%" (
  62.         set /a "width=%value%"
  63.         set /a "i+=2"
  64.         goto main_loop
  65.     )
  66.  
  67.     set /a "is_no_startup_check=%false%"
  68.     if "%option%" == "-nsc" set /a "is_no_startup_check=%true%"
  69.     if "%option%" == "--no-startup-check" set /a "is_no_startup_check=%true%"
  70.  
  71.     if "%is_no_startup_check%" == "%true%" (
  72.         set /a "startup_check=%false%"
  73.         set /a "i+=1"
  74.         goto main_loop
  75.     )
  76.  
  77.     set /a "is_debug_mode=%false%"
  78.     if "%option%" == "-dm" set /a "is_debug_mode=%true%"
  79.     if "%option%" == "--debug-mode" set /a "is_debug_mode=%true%"
  80.  
  81.     if "%is_debug_mode%" == "%true%" (
  82.         set /a "debug_mode=%true%"
  83.         set /a "i+=1"
  84.         goto main_loop
  85.     )
  86.  
  87.     if "%startup_check%" == "%true%" (
  88.         bc --version 2> nul > nul || (
  89.             echo %em_bc_not_found%
  90.             exit /b %ec_bc_not_found%
  91.         )
  92.     )
  93.  
  94.     if "%debug_mode%" == "%true%" call :print_array args "Expansion result: "
  95.  
  96.     call :parse_chart_data i args data_value data_color data_char data_placeholder_char
  97.     set /a "temp_errorlevel=%errorlevel%"
  98.     if %temp_errorlevel% gtr 0 exit /b %temp_errorlevel%
  99.  
  100.     if "%debug_mode%" == "%true%" (
  101.         call :print_array data_value "Data/Values: "
  102.         call :print_array data_char "Data/Chars: "
  103.         call :print_array data_placeholder_char "Data/Placeholder chars: "
  104.     )
  105.  
  106.     call :try_draw_chart data_value data_color data_char data_placeholder_char
  107.     set /a "temp_error_level=%errorlevel%"
  108.     if %temp_error_level% gtr 0 exit /b %temp_error_level%
  109.     exit /b %ec_success%
  110.  
  111. :init
  112.     set /a "ec_success=0"
  113.     set /a "ec_bc_not_found=10"
  114.  
  115.     set "em_bc_not_found=bc utility not found to perform calculations with float numbers."
  116.  
  117.     set /a "true=0"
  118.     set /a "false=1"
  119.  
  120.     set "prompt=>>> "
  121.     set "number_regex=^[0-9][0-9]*$"
  122.  
  123.     set /a "default_width=10"
  124.     set /a "width=%default_width%"
  125.  
  126.     set "default_char=-"
  127.     set "default_placeholder_char= "
  128.  
  129.     set /a "debug_mode=%false%"
  130.    
  131.     set /a "startup_check=%true%"
  132.  
  133.     call :set_esc
  134.  
  135.     set "default_color_code=%esc%[0m"
  136. exit /b %ec_success%
  137.  
  138. :help
  139.     echo Creates simple chart.
  140.     echo.
  141.     echo Syntax:
  142.     echo    chart [options] [value { [options] } [value { [options] }]...]
  143.     echo.
  144.     echo Options:
  145.     echo    -h^|--help - writes help and exits
  146.     echo    -v^|--version - writes version and exits
  147.     echo    -i^|--interactive - fall in interactive mode
  148.     echo    -w^|--width - chart item width
  149.     echo    -f^|--foreground - specifies --item-foreground for all chart items (user defined values take precedence)
  150.     echo        Available value set is: black, red, green, yellow, blue, purple, cyan, white, random, random-all.
  151.     echo    -b^|--background - specifies --item-background for all chart items (user defined values take precedence)
  152.     echo        Available value set is: black, red, green, yellow, blue, purple, cyan, white, random, random-all.
  153.     echo    -c^|--char - specifies --item-char for all chart items (user defined values take precedence)
  154.     echo    -pc^|--placeholder-char - specifies --item-placeholder-char for all chart items (user defined values take precedence)
  155.     echo    -dm^|--debug-mode - enables debug mode
  156.     echo.
  157.     echo Style options:
  158.     echo    -if^|--item-foreground - specifies chart item foreground color
  159.     echo    -ib^|--item-background - specifies chart item background color
  160.     echo    -ic^|--item-char - specifies chart item char used to display it
  161.     echo    -ipc^|--item-placeholder-char - specifies chart item placeholder char used to display it
  162.     echo.
  163.     echo Interactive mode commands:
  164.     echo    q^|quit - exits
  165.     echo    c^|clear - clears screen
  166.     echo    h^|help - writes help
  167.     echo.
  168.     echo Error codes:
  169.     echo    - 0 - Success
  170.     echo    - 10 - bc utility not found to perform calculations with float numbers.
  171.     echo    - 20 - Unexpected value instead of nonnegative number while expanding --foreground^|--background^|--char^|--placeholder-char."
  172.     echo    - 30 - Unexpected value instead of nonnegative number while expanding random colors.
  173.     echo    - 40 - No data provided to draw chart.
  174.     echo    - 50 - Unexpected value instead of nonnegative number.
  175.     echo    - 60 - Missing opening curly brace ^({^).
  176.     echo    - 61 - Missing closing curly brace ^(}^).
  177.     echo    - 70 - Unexpected foreground color name. Valid color name set is: black (default), red, green, yellow, blue, purple, cyan, white, random.
  178.     echo    - 80 - Unexpected background color name. Valid color name set is: black (default), red, green, yellow, blue, purple, cyan, white, random.
  179.     echo.
  180.     echo Examples:
  181.     echo    - chart --help
  182.     echo    - chart 1 5 3
  183.     echo    - chart 1 { --item-foreground red } 5 { --item-foreground green } 3 { --item-foreground blue }
  184.     echo    - chart --foreground red 1 2 3 =^> is converted to =^> chart 1 { --item-foreground red } 2 { --item-foreground red } 3 { --item-foreground red }
  185.     echo    - chart --foreground random 1 2 3 =^> is converted to =^> chart --foreground ^<random-color^> 1 2 3 =^> is converted to =^> chart 1 { --item-foreground ^<random-color^> } 2 { --item-foreground ^<random-color^> } 3 { --item-foreground ^<random-color^> }
  186.     echo    - chart --foreground random-all 1 2 3 =^> is converted to =^> chart 1 { --item-foreground ^<random-color-for-1^> } 2 { --item-foreground ^<random-color-for-2^> } 3 { --item-foreground ^<random-color-for-3^> }
  187. exit /b %ec_success%
  188.  
  189. :version
  190.     echo 1.1 ^(c^) 2021 year
  191. exit /b %ec_success%
  192.  
  193. :interactive
  194.     set "i_em_help_option_is_not_available=--help option is not available in ineractive mode. You have to use help command."
  195.     set "i_em_version_option_is_not_available=--version option is not available in ineractive mode."
  196.     set "i_em_interactive_option_is_not_available=--interactive option is not available in ineractive mode."
  197.  
  198.     set /a "i_last_errorlevel=0"
  199.  
  200.     :interactive_loop
  201.         set /a "i_color_code=32"
  202.         if not %i_last_errorlevel% == 0 set /a "i_color_code=31"
  203.         set /a "debug_mode=%false%"
  204.         set /a "width=%default_width%"
  205.         set "i_command="
  206.         call :clear_arguments i_args
  207.         call :clear_arguments i_data_value
  208.         call :clear_arguments i_data_color
  209.         call :clear_arguments i_data_char
  210.         call :clear_arguments i_data_placeholder_char
  211.         set /p "i_command=%esc%[%i_color_code%m%i_last_errorlevel% %prompt%%esc%[0m"
  212.         call :perform_substitutions i_command "%i_command%"
  213.        
  214.         if not defined i_command goto interactive_loop
  215.         if "%i_command: =%" == "" goto interactive_loop
  216.        
  217.         call :to_array i_args %i_command%
  218.         set "i_first=%i_args[0]%"
  219.        
  220.         set "i_comment_regex=^#.*$"
  221.         echo %i_first%| findstr /r "%i_comment_regex%" 2> nul > nul && goto interactive_loop
  222.  
  223.         call set "i_command=%%i_command:!!=%i_previous_command%%%"
  224.         call :to_array i_args %i_command%
  225.  
  226.         set "i_first=%i_args[0]%"
  227.  
  228.         set /a "i_is_quit=%false%"
  229.         if "%i_first%" == "q" set /a "i_is_quit=%true%"
  230.         if "%i_first%" == "quit" set /a "i_is_quit=%true%"
  231.  
  232.         if "%i_is_quit%" == "%true%" exit /b %ec_success%
  233.    
  234.         set /a "i_is_clear=%false%"
  235.         if "%i_first%" == "c" set /a "i_is_clear=%true%"
  236.         if "%i_first%" == "clear" set /a "i_is_clear=%true%"
  237.  
  238.         if "%i_is_clear%" == "%true%" (
  239.             cls
  240.             goto interactive_loop
  241.         )
  242.  
  243.         set /a "i_is_help=%false%"
  244.         if "%i_first%" == "h" set /a "i_is_help=%true%"
  245.         if "%i_first%" == "help" set /a "i_is_help=%true%"
  246.  
  247.         if "%i_is_help%" == "%true%" (
  248.             call :help
  249.             goto interactive_loop
  250.         )
  251.  
  252.         call :expand_sugar_options i_args
  253.         set /a "i_temp_error_level=%errorlevel%"
  254.         if %i_temp_error_level% gtr 0 (
  255.             set /a "i_last_errorlevel=0"
  256.             goto interactive_loop
  257.         )
  258.  
  259.         set "i_previous_command=%i_command%"
  260.  
  261.         set /a "i_i=0"
  262.         :i_main_loop
  263.             set /a "i_j=%i_i% + 1"
  264.             call set "i_option=%%i_args[%i_i%]%%"
  265.             call set "i_value=%%i_args[%i_j%]%%"
  266.  
  267.             set /a "i_is_help=%false%"
  268.             if "%i_option%" == "-h" set /a "i_is_help=%true%"
  269.             if "%i_option%" == "--help" set /a "i_is_help=%true%"
  270.  
  271.             if "%i_is_help%" == "%true%" (
  272.                 echo %i_em_help_option_is_not_available%
  273.                 goto interactive_loop
  274.             )
  275.  
  276.             set /a "i_is_version=%false%"
  277.             if "%i_option%" == "-v" set /a "i_is_version=%true%"
  278.             if "%i_option%" == "--version" set /a "i_is_version=%true%"
  279.  
  280.             if "%i_is_version%" == "%true%" (
  281.                 echo %i_em_version_option_is_not_available%
  282.                 goto interactive_loop
  283.             )
  284.  
  285.             set /a "i_is_interactive=%false%"
  286.             if "%i_option%" == "-i" set /a "i_is_interactive=%true%"
  287.             if "%i_option%" == "--interactive" set /a "i_is_interactive=%true%"
  288.  
  289.             if "%i_is_interactive%" == "%true%" (
  290.                 echo %i_em_interactive_option_is_not_available%
  291.                 goto interactive_loop
  292.             )
  293.  
  294.             set /a "i_is_width=%false%"
  295.             if "%i_option%" == "-w" set /a "i_is_width=%true%"
  296.             if "%i_option%" == "--width" set /a "i_is_width=%true%"
  297.  
  298.             if "%i_is_width%" == "%true%" (
  299.                 set /a "width=%i_value%"
  300.                 set /a "i_i+=2"
  301.                 goto i_main_loop
  302.             )
  303.  
  304.             set /a "i_is_debug_mode=%false%"
  305.             if "%i_option%" == "-dm" set /a "i_is_debug_mode=%true%"
  306.             if "%i_option%" == "--debug-mode" set /a "i_is_debug_mode=%true%"
  307.  
  308.             if "%i_is_debug_mode%" == "%true%" (
  309.                 set /a "debug_mode=%true%"
  310.                 set /a "i_i+=1"
  311.                 goto i_main_loop
  312.             )
  313.  
  314.             if "%debug_mode%" == "%true%" call :print_array i_args "Expansion result: "
  315.  
  316.             call :parse_chart_data i_i i_args i_data_value i_data_color i_data_char i_data_placeholder_char
  317.             set /a "i_temp_errorlevel=%errorlevel%"
  318.             if %i_temp_errorlevel% gtr 0 (
  319.                 set /a "i_last_errorlevel=%i_temp_error_level%"
  320.                 goto interactive_loop
  321.             )
  322.  
  323.             if "%debug_mode%" == "%true%" (
  324.                 call :print_array i_data_value "Data/Values: "
  325.                 call :print_array i_data_char "Data/Chars: "
  326.                 call :print_array i_data_placeholder_char "Data/Placeholder chars: "
  327.             )
  328.  
  329.             call :try_draw_chart i_data_value i_data_color i_data_char i_data_placeholder_char
  330.             set /a "i_last_errorlevel=0"
  331.             goto interactive_loop
  332. exit /b %ec_success%
  333.  
  334. :clear_arguments
  335.     set "ca_array_name=%~1"
  336.  
  337.     set /a "ca_i=0"
  338.     :ca_clear_arguments_loop
  339.         call set "ca_argument=%%%ca_array_name%[%ca_i%]%%"
  340.         if defined ca_argument (
  341.             set "%ca_array_name%[%ca_i%]="
  342.             set /a "ca_i+=1"
  343.             goto ca_clear_arguments_loop
  344.         )
  345. exit /b %ec_success%
  346.  
  347. :to_array
  348.     set "ta_array_name=%~1"
  349.  
  350.     shift
  351.     set /a "ta_i=0"
  352.     :ta_conversion_loop
  353.         set "ta_argument=%~1"
  354.         if defined ta_argument (
  355.             set "%ta_array_name%[%ta_i%]=%ta_argument%"
  356.             set /a "ta_i+=1"
  357.             shift
  358.             goto ta_conversion_loop
  359.         )
  360. exit /b %ec_success%
  361.  
  362. :expand_sugar_options
  363.     set /a "eso_ec_unexpected_value=20"
  364.  
  365.     set "eso_em_unexpected_value=Unexpected value instead of nonnegative number while expanding --foreground^|--background^|--char^|--placeholder-char."
  366.  
  367.     set "eso_args_array_name=%~1"
  368.  
  369.     set /a "eso_temp_errorlevel=%errorlevel%"
  370.     if %eso_temp_errorlevel% gtr 0 exit /b %eso_temp_errorlevel%
  371.  
  372.     set "eso_temp_foreground_value="
  373.     set "eso_temp_background_value="
  374.     set /a "eso_temp_foreground_value_is_random_for_all=%false%"
  375.     set /a "eso_temp_background_value_is_random_for_all=%false%"
  376.     set "eso_temp_char_value="
  377.     set "eso_temp_placeholder_char_value="
  378.  
  379.     set /a "eso_i=0"
  380.     :eso_expand_options_loop
  381.         set /a "eso_j=%eso_i% + 1"
  382.  
  383.         if not defined %eso_args_array_name%[%eso_i%] exit /b %ec_success%
  384.  
  385.         call set "eso_option=%%%eso_args_array_name%[%eso_i%]%%"
  386.         call set "eso_value=%%%eso_args_array_name%[%eso_j%]%%"
  387.  
  388.         set /a "eso_is_foreground=%false%"
  389.         if "%eso_option%" == "-f" set /a "eso_is_foreground=%true%"
  390.         if "%eso_option%" == "--foreground" set /a "eso_is_foreground=%true%"
  391.  
  392.         if "%eso_is_foreground%" == "%true%" goto eso_if_eso_is_foreground_equal_to_true
  393.  
  394.         set /a "eso_is_background=%false%"
  395.         if "%eso_option%" == "-b" set /a "eso_is_background=%true%"
  396.         if "%eso_option%" == "--background" set /a "eso_is_background=%true%"
  397.  
  398.         if "%eso_is_background%" == "%true%" goto eso_if_eso_is_background_equal_to_true
  399.  
  400.         set /a "eso_is_char=%false%"
  401.         if "%eso_option%" == "-c" set /a "eso_is_char=%true%"
  402.         if "%eso_option%" == "--char" set /a "eso_is_char=%true%"
  403.  
  404.         if "%eso_is_char%" == "%true%" (
  405.             set "eso_temp_char_value=%eso_value:~0,1%"
  406.  
  407.             call :remove_array_item "%eso_args_array_name%" "%eso_i%"
  408.             call :remove_array_item "%eso_args_array_name%" "%eso_i%"
  409.             goto eso_expand_options_loop
  410.         )
  411.  
  412.         set /a "eso_is_placeholder_char=%false%"
  413.         if "%eso_option%" == "-pc" set /a "eso_is_placeholder_char=%true%"
  414.         if "%eso_option%" == "--placeholder-char" set /a "eso_is_placeholder_char=%true%"
  415.  
  416.         if "%eso_is_placeholder_char%" == "%true%" (
  417.             set "eso_temp_placeholder_char_value=%eso_value:~0,1%"
  418.  
  419.             call :remove_array_item "%eso_args_array_name%" "%eso_i%"
  420.             call :remove_array_item "%eso_args_array_name%" "%eso_i%"
  421.             goto eso_expand_options_loop
  422.         )
  423.  
  424.         set /a "eso_is_skippable_option_with_value=%false%"
  425.         if "%eso_option%" == "-w" set /a "eso_is_skippable_option_with_value=%true%"
  426.         if "%eso_option%" == "--width" set /a "eso_is_skippable_option_with_value=%true%"
  427.  
  428.         if "%eso_is_skippable_option_with_value%" == "%true%" (
  429.             set /a "eso_i+=2"
  430.             goto eso_expand_options_loop
  431.         )
  432.  
  433.         set /a "eso_is_skippable_option_without_value=%false%"
  434.         if "%eso_option%" == "-h" set /a "eso_is_skippable_option_without_value=%true%"
  435.         if "%eso_option%" == "--help" set /a "eso_is_skippable_option_without_value=%true%"
  436.         if "%eso_option%" == "-v" set /a "eso_is_skippable_option_without_value=%true%"
  437.         if "%eso_option%" == "--version" set /a "eso_is_skippable_option_without_value=%true%"
  438.         if "%eso_option%" == "-i" set /a "eso_is_skippable_option_without_value=%true%"
  439.         if "%eso_option%" == "--interactive" set /a "eso_is_skippable_option_without_value=%true%"
  440.         if "%eso_option%" == "-nsc" set /a "eso_is_skippable_option_without_value=%true%"
  441.         if "%eso_option%" == "--no-startup-check" set /a "eso_is_skippable_option_without_value=%true%"
  442.         if "%eso_option%" == "-dm" set /a "eso_is_skippable_option_without_value=%true%"
  443.         if "%eso_option%" == "--debug-mode" set /a "eso_is_skippable_option_without_value=%true%"
  444.  
  445.         if "%eso_is_skippable_option_without_value%" == "%true%" (
  446.             set /a "eso_i+=1"
  447.             goto eso_expand_options_loop
  448.         )
  449.  
  450.         call set "eso_value=%%%eso_args_array_name%[%eso_i%]%%"
  451.         call set "eso_next_argument=%%%eso_args_array_name%[%eso_j%]%%"
  452.  
  453.         echo %eso_value%| findstr /r "%number_regex%" 2> nul > nul || (
  454.             echo %eso_em_unexpected_value%
  455.             exit /b %eso_ec_unexpected_value%
  456.         )
  457.  
  458.         if not "%eso_next_argument%" == "{" (
  459.             call :insert_array_item "%eso_args_array_name%" "}" "%eso_j%"
  460.             call :insert_array_item "%eso_args_array_name%" "{" "%eso_j%"
  461.         )
  462.  
  463.         set /a "eso_i+=2"
  464.  
  465.         set /a "eso_temp_random_foreground=0"
  466.         set /a "eso_temp_random_background=0"
  467.  
  468.         call :random_foreground_color_code eso_temp_random_foreground
  469.         call :random_background_color_code eso_temp_random_background
  470.  
  471.         if defined eso_temp_foreground_value (
  472.             if "%eso_temp_foreground_value_is_random_for_all%" == "%true%" (
  473.                 call :insert_array_item "%eso_args_array_name%" "%eso_temp_random_foreground%" "%eso_i%"
  474.             ) else (
  475.                 call :insert_array_item "%eso_args_array_name%" "%eso_temp_foreground_value%" "%eso_i%"
  476.             )
  477.             call :insert_array_item "%eso_args_array_name%" "--item-foreground" "%eso_i%"
  478.             set /a "eso_i+=2"
  479.         )
  480.         if defined eso_temp_background_value (
  481.             if "%eso_temp_background_value_is_random_for_all%" == "%true%" (
  482.                 call :insert_array_item "%eso_args_array_name%" "%eso_temp_random_background%" "%eso_i%"
  483.             ) else (
  484.                 call :insert_array_item "%eso_args_array_name%" "%eso_temp_background_value%" "%eso_i%"
  485.             )
  486.             call :insert_array_item "%eso_args_array_name%" "--item-background" "%eso_i%"
  487.             set /a "eso_i+=2"
  488.         )
  489.         if defined eso_temp_char_value (
  490.             call :insert_array_item "%eso_args_array_name%" "%eso_temp_char_value%" "%eso_i%"
  491.             call :insert_array_item "%eso_args_array_name%" "--item-char" "%eso_i%"
  492.             set /a "eso_i+=2"
  493.         )
  494.         if defined eso_temp_placeholder_char_value (
  495.             call :insert_array_item "%eso_args_array_name%" "%eso_temp_placeholder_char_value%" "%eso_i%"
  496.             call :insert_array_item "%eso_args_array_name%" "--item-placeholder-char" "%eso_i%"
  497.             set /a "eso_i+=2"
  498.         )
  499.  
  500.         :eso_move_to_closing_brace
  501.             call set "eso_argument=%%%eso_args_array_name%[%eso_i%]%%"
  502.             if not defined eso_argument exit /b %ec_success%
  503.             if not "%eso_argument%" == "}" (
  504.                 set /a "eso_i+=1"
  505.                 goto eso_move_to_closing_brace
  506.             )
  507.        
  508.         set /a "eso_i+=1"
  509.         goto eso_expand_options_loop
  510. exit /b %ec_success%
  511.  
  512. :eso_if_eso_is_foreground_equal_to_true
  513.     if "%eso_value%" == "random-all" (
  514.         set /a "eso_temp_foreground_value_is_random_for_all=%true%"
  515.         set /a "eso_temp_foreground_value=0"
  516.         goto eso_remove_array_items_for_foreground_color_option
  517.     )
  518.     call :to_foreground_color_code eso_temp_foreground_value "%eso_value%"
  519.     set /a "eso_temp_errorlevel=%errorlevel%"
  520.     if %eso_temp_errorlevel% gtr 0 exit /b %eso_temp_errorlevel%
  521.     set /a "eso_temp_foreground_value_is_random_for_all=%false%"
  522.  
  523.     :eso_remove_array_items_for_foreground_color_option
  524.     call :remove_array_item "%eso_args_array_name%" "%eso_i%"
  525.     call :remove_array_item "%eso_args_array_name%" "%eso_i%"
  526.     goto eso_expand_options_loop
  527.  
  528. :eso_if_eso_is_background_equal_to_true
  529.     if "%eso_value%" == "random-all" (
  530.         set /a "eso_temp_background_value_is_random_for_all=%true%"
  531.         set /a "eso_temp_background_value=0"
  532.         goto eso_remove_array_items_for_background_color_option
  533.     )
  534.     call :to_background_color_code eso_temp_background_value "%eso_value%"
  535.     set /a "eso_temp_errorlevel=%errorlevel%"
  536.     if %eso_temp_errorlevel% gtr 0 exit /b %eso_temp_errorlevel%
  537.     set /a "eso_temp_background_value_is_random_for_all=%false%"
  538.  
  539.     :eso_remove_array_items_for_background_color_option
  540.     call :remove_array_item "%eso_args_array_name%" "%eso_i%"
  541.     call :remove_array_item "%eso_args_array_name%" "%eso_i%"
  542.     goto eso_expand_options_loop
  543.  
  544. :expand_sugar_options_random_colors
  545.     set /a "esorc_ec_unexpected_value=30"
  546.  
  547.     set "esorc_em_unexpected_value=Unexpected value instead of nonnegative number while expanding random colors."
  548.  
  549.     set "esorc_args_array_name=%~1"
  550.  
  551.     set /a "esorc_i=0"
  552.     :esorc_expand_options_loop
  553.         set /a "esorc_j=%esorc_i% + 1"
  554.  
  555.         if not defined %esorc_args_array_name%[%esorc_i%] exit /b %ec_success%
  556.  
  557.         call set "esorc_option=%%%esorc_args_array_name%[%esorc_i%]%%"
  558.         call set "esorc_value=%%%esorc_args_array_name%[%esorc_j%]%%"
  559.  
  560.         set /a "esorc_is_foreground_or_item_foreground=%false%"
  561.         if "%esorc_option%" == "-f" set /a "esorc_is_foreground_or_item_foreground=%true%"
  562.         if "%esorc_option%" == "--foreground" set /a "esorc_is_foreground_or_item_foreground=%true%"
  563.         if "%esorc_option%" == "-if" set /a "esorc_is_foreground_or_item_foreground=%true%"
  564.         if "%esorc_option%" == "--item-foreground" set /a "esorc_is_foreground_or_item_foreground=%true%"
  565.  
  566.         if "%esorc_is_foreground_or_item_foreground%" == "%true%" (
  567.             if not "%esorc_value%" == "random-all" call :random_foreground_color_code "%esorc_args_array_name%[%esorc_j%]"
  568.  
  569.             set /a "esorc_i+=2"
  570.             goto esorc_expand_options_loop
  571.         )
  572.  
  573.         set /a "esorc_is_background_or_item_background=%false%"
  574.         if "%esorc_option%" == "-b" set /a "esorc_is_background_or_item_background=%true%"
  575.         if "%esorc_option%" == "--background" set /a "esorc_is_background_or_item_background=%true%"
  576.         if "%esorc_option%" == "-ib" set /a "esorc_is_background_or_item_background=%true%"
  577.         if "%esorc_option%" == "--item-background" set /a "esorc_is_background_or_item_background=%true%"
  578.  
  579.         if "%esorc_is_background_or_item_background%" == "%true%" (
  580.             if not "%esorc_value%" == "random-all" call :random_background_color_code "%esorc_args_array_name%[%esorc_j%]"
  581.  
  582.             set /a "esorc_i+=2"
  583.             goto esorc_expand_options_loop
  584.         )
  585.  
  586.         set /a "esorc_is_skippable_option_with_value=%false%"
  587.         if "%esorc_option%" == "-w" set /a "esorc_is_skippable_option_with_value=%true%"
  588.         if "%esorc_option%" == "--width" set /a "esorc_is_skippable_option_with_value=%true%"
  589.  
  590.         if "%esorc_is_skippable_option_with_value%" == "%true%" (
  591.             set /a "esorc_i+=2"
  592.             goto esorc_expand_options_loop
  593.         )
  594.  
  595.         set /a "esorc_is_skippable_option_without_value_or_brace=%false%"
  596.         if "%esorc_option%" == "-h" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  597.         if "%esorc_option%" == "--help" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  598.         if "%esorc_option%" == "-v" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  599.         if "%esorc_option%" == "--version" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  600.         if "%esorc_option%" == "-i" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  601.         if "%esorc_option%" == "--interactive" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  602.         if "%esorc_option%" == "-dm" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  603.         if "%esorc_option%" == "--debug-mode" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  604.         if "%esorc_option%" == "{" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  605.         if "%esorc_option%" == "}" set /a "esorc_is_skippable_option_without_value_or_brace=%true%"
  606.  
  607.         if "%esorc_is_skippable_option_without_value_or_brace%" == "%true%" (
  608.             set /a "esorc_i+=1"
  609.             goto esorc_expand_options_loop
  610.         )
  611.  
  612.         call set "esorc_value=%%%esorc_args_array_name%[%esorc_i%]%%"
  613.  
  614.         echo %esorc_value%| findstr /r "%number_regex%" 2> nul > nul || (
  615.             echo %esorc_em_unexpected_value%
  616.             exit /b %esorc_ec_unexpected_value%
  617.         )
  618.  
  619.         set /a "esorc_i+=1"
  620.         goto esorc_expand_options_loop
  621. exit /b %ec_success%
  622.  
  623. :try_draw_chart
  624.     set /a "tdc_ec_no_data_provided=40"
  625.  
  626.     set "tdc_em_no_data_provided=No data provided to draw chart."
  627.  
  628.     set "tdc_data_value_array_name=%~1"
  629.     set "tdc_data_color_array_name=%~2"
  630.     set "tdc_data_char_array_name=%~3"
  631.     set "tdc_data_placeholder_char_array_name=%~4"
  632.    
  633.     set "tdc_temp_file=tmp.txt"
  634.  
  635.     call find_max.bat tdc_max "%tdc_data_value_array_name%" 2> nul > nul || (
  636.         echo %tdc_em_no_data_provided%
  637.         exit /b %tdc_ec_no_data_provided%
  638.     )
  639.    
  640.     set /a "tdc_i=0"
  641.     :tdc_loop
  642.         call set "tdc_value=%%%tdc_data_value_array_name%[%tdc_i%]%%"
  643.         call set "tdc_color=%%%tdc_data_color_array_name%[%tdc_i%]%%"
  644.         call set "tdc_char=%%%tdc_data_char_array_name%[%tdc_i%]%%"
  645.         call set "tdc_placeholder_char=%%%tdc_data_placeholder_char_array_name%[%tdc_i%]%%"
  646.  
  647.         if not defined tdc_value exit /b %ec_success%
  648.  
  649.         echo scale=5; part=%tdc_value%/%tdc_max%*%width%; scale=0; part / 1 | bc > "%tdc_temp_file%"
  650.  
  651.         set /p tdc_item_length=<%tdc_temp_file%
  652.         set /a "tdc_space_count=%width% - %tdc_item_length%"
  653.        
  654.         call :repeat_string tdc_item "%tdc_char%" "%tdc_item_length%"
  655.         call :repeat_string tdc_space "%tdc_placeholder_char%" "%tdc_space_count%"
  656.  
  657.         echo %tdc_color%%tdc_item%%tdc_space% %tdc_value%%esc%[0m
  658.  
  659.         set /a "tdc_i+=1"
  660.         goto tdc_loop
  661. exit /b %ec_success%
  662.  
  663. :parse_chart_data
  664.     set /a "pcd_ec_unexpected_value=50"
  665.  
  666.     set "pcd_em_unexpected_value=Unexpected value instead of nonnegative number."
  667.  
  668.     set "pcd_index_variable_name=%~1"
  669.     set "pcd_args_array_name=%~2"
  670.     set "pcd_data_value_array_name=%~3"
  671.     set "pcd_data_color_array_name=%~4"
  672.     set "pcd_data_char_array_name=%~5"
  673.     set "pcd_data_placeholder_char_array_name=%~6"
  674.  
  675.     set /a "pcd_i=%pcd_index_variable_name%"
  676.     set /a "pcd_data_i=0"
  677.     :pcd_loop
  678.         set /a "pcd_j=%pcd_i% + 1"
  679.         call set "pcd_value=%%%pcd_args_array_name%[%pcd_i%]%%"
  680.         call set "pcd_style=%%%pcd_args_array_name%[%pcd_j%]%%"
  681.  
  682.         if not defined %pcd_args_array_name%[%pcd_i%] exit /b %ec_success%
  683.  
  684.         echo %pcd_value%| findstr /r "%number_regex%" 2> nul > nul || (
  685.             echo %pcd_em_unexpected_value%
  686.             exit /b %pcd_ec_unexpected_value%
  687.         )
  688.  
  689.         set "%pcd_data_value_array_name%[%pcd_data_i%]=%pcd_value%"
  690.  
  691.         set "pcd_color=%default_color_code%"
  692.         set "pcd_char=%default_char%"
  693.         set "pcd_placeholder_char=%default_placeholder_char%"
  694.        
  695.         if not "%pcd_style%" == "{" (
  696.             set "%pcd_data_color_array_name%[%pcd_data_i%]=%pcd_color%"
  697.             set "%pcd_data_char_array_name%[%pcd_data_i%]=%pcd_char%"
  698.             set "%pcd_data_placeholder_char_array_name%[%pcd_data_i%]=%pcd_placeholder_char%"
  699.  
  700.             set /a "pcd_data_i+=1"
  701.             set /a "pcd_i+=1"
  702.             goto pcd_loop
  703.         )
  704.  
  705.         set /a "pcd_i+=1"
  706.         call :skip_style_block pcd_i pcd_color pcd_char pcd_placeholder_char "%pcd_args_array_name%"
  707.         set /a "pcd_temp_errorlevel=%errorlevel%"
  708.         if %pcd_temp_errorlevel% gtr 0 exit /b %pcd_temp_errorlevel%
  709.        
  710.         set "%pcd_data_color_array_name%[%pcd_data_i%]=%pcd_color%"
  711.         set "%pcd_data_char_array_name%[%pcd_data_i%]=%pcd_char%"
  712.         set "%pcd_data_placeholder_char_array_name%[%pcd_data_i%]=%pcd_placeholder_char%"
  713.         set /a "pcd_data_i+=1"
  714.         goto pcd_loop
  715. exit /b %ec_success%
  716.  
  717. :skip_style_block
  718.     set /a "ssb_ec_missing_opening_curly_brace=60"
  719.     set /a "ssb_ec_missing_closing_curly_brace=61"
  720.  
  721.     set "ssb_em_missing_opening_curly_brace=Missing opening curly brace ^({^)."
  722.     set "ssb_em_missing_closing_curly_brace=Missing closing curly brace ^(}^)."
  723.  
  724.     set "ssb_index_variable_name=%~1"
  725.     set "ssb_result_color_variable_name=%~2"
  726.     set "ssb_result_char_variable_name=%~3"
  727.     set "ssb_result_placeholder_char_variable_name=%~4"
  728.     set "ssb_args_array_name=%~5"
  729.  
  730.     set /a "ssb_i=%ssb_index_variable_name%"
  731.  
  732.     set "ssb_item_foreground=0"
  733.     set "ssb_item_background=0"
  734.     set "ssb_item_char=%default_char%"
  735.     set "ssb_item_placeholder_char=%default_placeholder_char%"
  736.  
  737.     call set "ssb_option=%%%ssb_args_array_name%[%ssb_i%]%%"
  738.     if not "%ssb_option%" == "{" (
  739.         echo %ssb_em_missing_opening_curly_brace%
  740.         exit /b %ssb_ec_missing_opening_curly_brace%
  741.     )
  742.    
  743.     set /a "ssb_i+=1"
  744.     :ssb_loop
  745.         set /a "ssb_j=%ssb_i% + 1"
  746.         call set "ssb_option=%%%ssb_args_array_name%[%ssb_i%]%%"
  747.         call set "ssb_value=%%%ssb_args_array_name%[%ssb_j%]%%"
  748.  
  749.         set /a "ssb_is_item_foreground=%false%"
  750.         if "%ssb_option%" == "-if" set /a "ssb_is_item_foreground=%true%"
  751.         if "%ssb_option%" == "--item-foreground" set /a "ssb_is_item_foreground=%true%"
  752.  
  753.         if "%ssb_is_item_foreground%" == "%true%" (
  754.             set "ssb_item_foreground=%ssb_value%"
  755.             set /a "ssb_i+=2"
  756.             goto ssb_loop
  757.         )
  758.  
  759.         set /a "ssb_is_item_background=%false%"
  760.         if "%ssb_option%" == "-ib" set /a "ssb_is_item_background=%true%"
  761.         if "%ssb_option%" == "--item-background" set /a "ssb_is_item_background=%true%"
  762.  
  763.         if "%ssb_is_item_background%" == "%true%" (
  764.             set "ssb_item_background=%ssb_value%"
  765.             set /a "ssb_i+=2"
  766.             goto ssb_loop
  767.         )
  768.  
  769.         set /a "ssb_is_item_char=%false%"
  770.         if "%ssb_option%" == "-ic" set /a "ssb_is_item_char=%true%"
  771.         if "%ssb_option%" == "--item-char" set /a "ssb_is_item_char=%true%"
  772.  
  773.         if "%ssb_is_item_char%" == "%true%" (
  774.             set "ssb_item_char=%ssb_value:~0,1%"
  775.             set /a "ssb_i+=2"
  776.             goto ssb_loop
  777.         )
  778.  
  779.         set /a "ssb_is_item_placeholder_char=%false%"
  780.         if "%ssb_option%" == "-ipc" set /a "ssb_is_item_placeholder_char=%true%"
  781.         if "%ssb_option%" == "--item-placeholder-char" set /a "ssb_is_item_placeholder_char=%true%"
  782.  
  783.         if "%ssb_is_item_placeholder_char%" == "%true%" (
  784.             set "ssb_item_placeholder_char=%ssb_value:~0,1%"
  785.             set /a "ssb_i+=2"
  786.             goto ssb_loop
  787.         )
  788.  
  789.         if not "%ssb_option%" == "}" (
  790.             echo %ssb_em_missing_closing_curly_brace%
  791.             exit /b %ssb_ec_missing_closing_curly_brace%
  792.         )
  793.  
  794.         call :to_color_code "%ssb_result_color_variable_name%" "%ssb_item_foreground%" "%ssb_item_background%"
  795.         set /a "ssb_error_level=%errorlevel%"
  796.         if %ssb_error_level% gtr 0 exit /b %ssb_error_level%
  797.         set "%ssb_result_char_variable_name%=%ssb_item_char%"
  798.         set "%ssb_result_placeholder_char_variable_name%=%ssb_item_placeholder_char%"
  799.         set /a "%ssb_index_variable_name%=%ssb_i% + 1"
  800. exit /b %ec_success%
  801.  
  802. :to_color_code
  803.     set "tcc_variable_name=%~1"
  804.     set "tcc_foreground_color=%~2"
  805.     set "tcc_background_color=%~3"
  806.  
  807.     set "%tcc_variable_name%=%esc%[0m"
  808.  
  809.     call :to_foreground_color_code tcc_foreground_color "%tcc_foreground_color%"
  810.     set /a "tcc_error_level=%errorlevel%"
  811.     if %tcc_error_level% gtr 0 exit /b %tcc_error_level%
  812.  
  813.     call :to_background_color_code tcc_background_color "%tcc_background_color%"
  814.     set /a "tcc_error_level=%errorlevel%"
  815.     if %tcc_error_level% gtr 0 exit /b %tcc_error_level%
  816.  
  817.     if %tcc_foreground_color% neq 0 (
  818.         if %tcc_background_color% neq 0 (
  819.             set "%tcc_variable_name%=%esc%[%tcc_foreground_color%;%tcc_background_color%m"
  820.         ) else (
  821.             set "%tcc_variable_name%=%esc%[%tcc_foreground_color%m"
  822.         )
  823.     ) else (
  824.         if %tcc_background_color% neq 0 (
  825.             set "%tcc_variable_name%=%esc%[%tcc_background_color%m"
  826.         ) else (
  827.             set "%tcc_variable_name%=%default_color_code%"
  828.         )
  829.     )
  830.    
  831. exit /b %ec_success%
  832.  
  833. :to_foreground_color_code
  834.     set "tfcc_variable_name=%~1"
  835.     set "tfcc_color=%~2"
  836.  
  837.     echo %tfcc_color%| findstr /r "%number_regex%" 2> nul > nul && (
  838.         set "%tfcc_variable_name%=%tfcc_color%"
  839.         exit /b %ec_success%
  840.     )
  841.  
  842.     call :name_to_foreground_color_code "%tfcc_variable_name%" "%tfcc_color%"
  843.     set /a "tfcc_error_level=%errorlevel%"
  844.     if %tfcc_error_level% gtr 0 exit /b %tfcc_error_level%
  845. exit /b %ec_success%
  846.  
  847. :to_background_color_code
  848.     set "tbcc_variable_name=%~1"
  849.     set "tbcc_color=%~2"
  850.  
  851.     echo %tbcc_color%| findstr /r "%number_regex%" 2> nul > nul && (
  852.         set "%tbcc_variable_name%=%tbcc_color%"
  853.         exit /b %ec_success%
  854.     )
  855.  
  856.     call :name_to_background_color_code "%tbcc_variable_name%" "%tbcc_color%"
  857.     set /a "tbcc_error_level=%errorlevel%"
  858.     if %tbcc_error_level% gtr 0 exit /b %tbcc_error_level%
  859. exit /b %ec_success%
  860.  
  861. :name_to_foreground_color_code
  862.     set /a "ntfcc_ec_wrong_color_name=70"
  863.  
  864.     set "ntfcc_em_wrong_color_name=Unexpected foreground color name. Valid color name set is: black (default), red, green, yellow, blue, purple, cyan, white, random."
  865.  
  866.     set "ntfcc_variable_name=%~1"
  867.     set "ntfcc_color_name=%~2"
  868.  
  869.     set "ntfcc_default_color=30"
  870.  
  871.     if "%ntfcc_color_name%" == "black" set /a "%ntfcc_variable_name%=30" && exit /b %ec_success%
  872.     if "%ntfcc_color_name%" == "red" set /a "%ntfcc_variable_name%=31" && exit /b %ec_success%
  873.     if "%ntfcc_color_name%" == "green" set /a "%ntfcc_variable_name%=32" && exit /b %ec_success%
  874.     if "%ntfcc_color_name%" == "yellow" set /a "%ntfcc_variable_name%=33" && exit /b %ec_success%
  875.     if "%ntfcc_color_name%" == "blue" set /a "%ntfcc_variable_name%=34" && exit /b %ec_success%
  876.     if "%ntfcc_color_name%" == "purple" set /a "%ntfcc_variable_name%=35" && exit /b %ec_success%
  877.     if "%ntfcc_color_name%" == "cyan" set /a "%ntfcc_variable_name%=36" && exit /b %ec_success%
  878.     if "%ntfcc_color_name%" == "white" set /a "%ntfcc_variable_name%=37" && exit /b %ec_success%
  879.     if "%ntfcc_color_name%" == "default" set /a "%ntfcc_variable_name%=%ntfcc_default_color%" && exit /b %ec_success%
  880.     if "%ntfcc_color_name%" == "random" (
  881.         call :random_foreground_color_code "%ntfcc_variable_name%"
  882.         exit /b %ec_success%
  883.     )
  884.  
  885.     set /a "%ntfcc_variable_name%=0"
  886.     echo %ntfcc_em_wrong_color_name%
  887. exit /b %ntfcc_ec_wrong_color_name%
  888.  
  889. :name_to_background_color_code
  890.     set /a "ntbcc_ec_wrong_color_name=80"
  891.  
  892.     set "ntbcc_em_wrong_color_name=Unexpected background color name. Valid color name set is: black (default), red, green, yellow, blue, purple, cyan, white, random."
  893.  
  894.     set "ntbcc_variable_name=%~1"
  895.     set "ntbcc_color_name=%~2"
  896.  
  897.     set "ntbcc_default_color=40"
  898.  
  899.     if "%ntbcc_color_name%" == "black" set /a "%ntbcc_variable_name%=40" && exit /b %ec_success%
  900.     if "%ntbcc_color_name%" == "red" set /a "%ntbcc_variable_name%=41" && exit /b %ec_success%
  901.     if "%ntbcc_color_name%" == "green" set /a "%ntbcc_variable_name%=42" && exit /b %ec_success%
  902.     if "%ntbcc_color_name%" == "yellow" set /a "%ntbcc_variable_name%=43" && exit /b %ec_success%
  903.     if "%ntbcc_color_name%" == "blue" set /a "%ntbcc_variable_name%=44" && exit /b %ec_success%
  904.     if "%ntbcc_color_name%" == "purple" set /a "%ntbcc_variable_name%=45" && exit /b %ec_success%
  905.     if "%ntbcc_color_name%" == "cyan" set /a "%ntbcc_variable_name%=46" && exit /b %ec_success%
  906.     if "%ntbcc_color_name%" == "white" set /a "%ntbcc_variable_name%=47" && exit /b %ec_success%
  907.     if "%ntbcc_color_name%" == "default" set /a "%ntbcc_variable_name%=%ntbcc_default_color%" && exit /b %ec_success%
  908.     if "%ntbcc_color_name%" == "random" (
  909.         call :random_background_color_code "%ntbcc_variable_name%"
  910.         exit /b %ec_success%
  911.     )
  912.  
  913.     set /a "%ntbcc_variable_name%=0"
  914.     echo %ntbcc_em_wrong_color_name%
  915. exit /b %ntbcc_ec_wrong_color_name%
  916.  
  917. :random_foreground_color_code
  918.     set "rfcc_variable_name=%~1"
  919.  
  920.     set /a "%rfcc_variable_name%=30 + %random% %% 8"
  921. exit /b %ec_success%
  922.  
  923. :random_background_color_code
  924.     set "rbcc_variable_name=%~1"
  925.    
  926.     set /a "%rbcc_variable_name%=40 + %random% %% 8"
  927. exit /b %ec_success%
  928.  
  929. :insert_array_item
  930.     set "iai_array_name=%~1"
  931.     set "iai_item_value=%~2"
  932.     set /a "iai_item_index=%~3"
  933.  
  934.     set /a "iai_i=%iai_item_index%"
  935.     :iai_moving_to_last_item
  936.         set "iai_item_name=%iai_array_name%[%iai_i%]"
  937.         if defined %iai_item_name% (
  938.             set /a "iai_i+=1"
  939.             goto iai_moving_to_last_item
  940.         )
  941.    
  942.     :iai_shifting_items_to_right
  943.         set /a "iai_j=%iai_i% - 1"
  944.         set "iai_item_name=%iai_array_name%[%iai_i%]"
  945.         set "iai_previous_item_name=%iai_array_name%[%iai_j%]"
  946.  
  947.         if %iai_j% geq %iai_item_index% (
  948.             call set "%iai_item_name%=%%%iai_previous_item_name%%%"
  949.             set /a "iai_i-=1"
  950.             goto iai_shifting_items_to_right
  951.         )
  952.  
  953.     set "%iai_array_name%[%iai_i%]=%iai_item_value%"
  954. exit /b %ec_success%
  955.  
  956. :remove_array_item
  957.     set "rai_array_name=%~1"
  958.     set /a "rai_item_index=%~2"
  959.  
  960.     set /a "rai_i=%rai_item_index%"
  961.     :rai_remove_loop
  962.         set /a "rai_j=%rai_i% + 1"
  963.         set "rai_item_name=%rai_array_name%[%rai_i%]"
  964.         set "rai_next_item_name=%rai_array_name%[%rai_j%]"
  965.  
  966.         if defined %rai_item_name% (
  967.             call set "%rai_item_name%=%%%rai_next_item_name%%%"
  968.             set /a "rai_i+=1"
  969.             goto rai_remove_loop
  970.         )
  971. exit /b %ec_success%
  972.  
  973. :print_array
  974.     set "pa_array_name=%~1"
  975.     set "pa_note=%~2"
  976.  
  977.     echo| set /p "=%pa_note%"
  978.     set /a "pa_i=0"
  979.     :pa_print_loop
  980.         set "pa_item_name=%pa_array_name%[%pa_i%]"
  981.         if defined %pa_item_name% (
  982.             echo| call set /p "=item-%pa_i%=[%%%pa_item_name%%%] "
  983.             set /a "pa_i+=1"
  984.             goto pa_print_loop
  985.         )
  986.     echo.
  987. exit /b %ec_success%
  988.  
  989. :repeat_string
  990.     set "rs_variable_name=%~1"
  991.     set "rs_string=%~2"
  992.     set "rs_count=%~3"
  993.  
  994.     set /a "rs_i=0"
  995.     set "rs_string_result="
  996.  
  997.     :rs_repetition_loop
  998.         if %rs_i% lss %rs_count% (
  999.             set "rs_string_result=%rs_string_result%%rs_string%"
  1000.             set /a "rs_i+=1"
  1001.             goto rs_repetition_loop
  1002.         )
  1003.  
  1004.     set "%rs_variable_name%=%rs_string_result%"
  1005. exit /b %ec_success%
  1006.  
  1007. :perform_substitutions
  1008.     set "ps_variable_name=%~1"
  1009.     set "ps_value=%~2"
  1010.  
  1011.     :ps_substitute_loop
  1012.         set "ps_value_before_substitution=%ps_value%"
  1013.         call set "ps_value=%ps_value%"
  1014.         if not "%ps_value_before_substitution%" == "%ps_value%" goto ps_substitute_loop
  1015.    
  1016.     set "%ps_variable_name%=%ps_value%"
  1017. exit /b %ec_success%
  1018.  
  1019. :set_esc
  1020.     for /f "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  1021.         set "esc=%%b"
  1022.         exit /b 0
  1023.     )
  1024. exit /b %ec_success%
  1025.  
Add Comment
Please, Sign In to add comment