4
\$\begingroup\$

This question wants you to golf batch programms. In Batch you can use

set x=averylongbatchcommand
%x% arg1

which expands to

set x=averylongbatchcommand
averylongbatchcommand arg1

Your task is it to expand these statements.
As you can also use set for arithmetic purposes like this:

set x = 0
set /a x= %x%+1

you should ignore the statements where the pattern with set /a is applied.
There will never be something like

set s=SET
%s% s=%s% a

where the variable is assigned using itself as command. But you have to handle things like

b:
set a =echo
%a% Hello World!
set a=goto
%a% b

Scoring

This is so the answer with the fewest bytes wins.

Testcases

set s=set
%s% e=echo
%e% I will have to use this exact thing very often because
%e% it absolutely wouldn't be shorter if i just left out these set statements

Expands to:

set s=set
set e=echo
echo I will have to use this exact thing very often because
echo it absolutely wouldn't be shorter if i just left out these set statements

set s=set
%s% i=0
set g=goto
:a
if %i%==15 (
%g% e
echo %i%
)
%s% /a i=%i%+1
%g% a
:e
%s% i=0
%g% a

Expands to:

set s=set
set i=0
set g=goto
:a
if %i%==15(
goto e
echo %i%
)
set /a i=%i%+1
goto a
e:
set i=0
goto a

set s=set
%s% s=%s% a=

Mustn't be supported.


set a=echo
%a% Hi
set a=type
%a% log.txt

Expands to:

set a=echo
echo Hi
set a=type
type log.txt

set x = 0 
set /a x= %x%+1

Expands to:

set x = 0
set /a x= %x%+1
\$\endgroup\$
9
  • \$\begingroup\$ I meant you shouldn't expand statements with /a. \$\endgroup\$ Oct 19 '16 at 10:08
  • 2
    \$\begingroup\$ Whats is the valid character set for variable names ? Can variable names have more than 1 character ? What if there is more than one = on a set line ? What is the behaviour of whitespace before or after = ? In particular does space after = become part of the assigned value ? Can the whitespace be tabs ? What is the behaviour of lines with an odd number of % ? \$\endgroup\$
    – Ton Hospel
    Oct 19 '16 at 10:17
  • \$\begingroup\$ For this question you can assume that every variable name is 1 character from a-z case-insensitive. Also whitespaces before the first = are ignored. But everything after the first = including other = will be put in the variable. \$\endgroup\$ Oct 19 '16 at 10:30
  • 1
    \$\begingroup\$ Why doesn't i get set to 0 in the second testcase ? \$\endgroup\$
    – Ton Hospel
    Oct 19 '16 at 10:48
  • \$\begingroup\$ @TonHospel I was confused by this as well, but the line before and after that example are meant to be read as one sentence, saying that references inside lines that start with set /a should not be substituted. \$\endgroup\$ Oct 19 '16 at 11:58