Difference between revisions of "Batch Conversion Limitations"

From eXo Wiki
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
For batch files to successfully convert into bash files for Linux and MacOS, there are some limitations for how they can be written. This page is to ensure that team members writing batch files are aware of some of those limitations.
For batch files to successfully convert into bash files for Linux and MacOS, there are some limitations for how they can be written. This page is to ensure that team members writing batch files are aware of some of those limitations.


=== Indenting nested if statements and for loops is necessary. ===
=== Indenting multi-line nested if statements and for loops is necessary. ===
With the limitations of tooling, nested statements that written without indentation, such as the below example, will fail to convert:
With the limitations of tooling, nested statements that written without indentation will fail to convert. <u>Each indentation should be specifically 2 or 3 spaces.</u> Avoid tabs.
<pre>
 
Example that fails to convert:
<pre style="color: red;">
if [...] (
if [...] (
some command
some command
Line 12: Line 14:
</pre>
</pre>


Instead, anything that is nested should have spacing to indicate the level of nesting. The closing parentheses are especially important.
Instead, anything that is nested should have spacing to indicate the level of nesting. Correct indentation on closing parentheses is especially important as that is how the converter determines the boundary.


Example that correctly converts:
Example that successfully converts:
<pre>
<pre style="color: blue;">
if [...] (
if [...] (
   some command
   some command
Line 23: Line 25:
)
)
</pre>
</pre>
Something like this is also okay:
<pre style="color: blue;">
if %nsl%==On (
  if %PPmode%==Off (
      if %filter%==On (
        set conf=".\emulators\dosbox\Staging_noline_sl.conf"
        goto preinstall)))
</pre>When all of the closing parenthesis are together, the converter splits them apart and converts each one as appropriate.


=== Labels must never be placed inside of loops or conditions. ===
=== Labels must never be placed inside of loops or conditions. ===
The converted goto function has been designed to work through stack frames for Linux and MacOS. For this reason, a label must never be placed inside of a loop or condition. Such code will fail to convert.
The converted goto function has been designed to work through stack frames for Linux and MacOS. For this reason, a label must never be placed inside of a loop or condition. Such code will fail to convert.
Example:
 
<pre>
Example that fails to convert:
<pre style="color: red;">
if exist file2.txt goto mylabel
if exist file2.txt goto mylabel
if exist .\mydir\file1.txt (
if exist .\mydir\file1.txt (
Line 37: Line 49:


Example that successfully converts:
Example that successfully converts:
<pre>
<pre style="color: blue;">
if exist file2.txt goto mylabel
if exist file2.txt goto mylabel
if exist .\mydir\file1.txt (
if exist .\mydir\file1.txt (
Line 47: Line 59:
echo This does not converts
echo This does not converts
:skip
:skip
</pre>
=== Labels must be unique ===
There must only be one instance of each label in a batch file.
Example that causes conversion problem (there are two labels named addNSLpp):
<pre style="color: red;">
:addNSLpp
set NSLsl=false
echo %cclear%
cls
echo. %cback%%cwipe%
echo %cnote%Would you like to retain subtle CRT scanlines?
echo.
echo CRT scanlines are a personal perference but can make
echo an image look sharper
echo %cchoice%
.\util\choice /C:YN /N [Y]es or [N]o
If errorlevel = 2 goto NSLslno
If errorlevel = 1 goto NSLslyes
:NSLslno
set NSLsl=false
goto addNSLpp
:NSLslyes
set NSLsl=true
goto addNSLpp
:addNSLpp
set NSLpp=false
echo %cclear%
cls
echo. %cback%%cwipe%
echo %cnote%Would you like to use Pixel Perfect mode at the same time?
echo %cchoice%
.\util\choice /C:YN /N [Y]es or [N]o
If errorlevel = 2 goto NSLppno
If errorlevel = 1 goto NSLppyes
</pre>
</pre>

Latest revision as of 21:29, 10 October 2026

For batch files to successfully convert into bash files for Linux and MacOS, there are some limitations for how they can be written. This page is to ensure that team members writing batch files are aware of some of those limitations.

Indenting multi-line nested if statements and for loops is necessary.

With the limitations of tooling, nested statements that written without indentation will fail to convert. Each indentation should be specifically 2 or 3 spaces. Avoid tabs.

Example that fails to convert:

if [...] (
some command
if [...] (
some command
)
)

Instead, anything that is nested should have spacing to indicate the level of nesting. Correct indentation on closing parentheses is especially important as that is how the converter determines the boundary.

Example that successfully converts:

if [...] (
  some command
  if [...] (
    some command
  )
)

Something like this is also okay:

if %nsl%==On (
   if %PPmode%==Off (
      if %filter%==On (
         set conf=".\emulators\dosbox\Staging_noline_sl.conf"
         goto preinstall)))

When all of the closing parenthesis are together, the converter splits them apart and converts each one as appropriate.

Labels must never be placed inside of loops or conditions.

The converted goto function has been designed to work through stack frames for Linux and MacOS. For this reason, a label must never be placed inside of a loop or condition. Such code will fail to convert.

Example that fails to convert:

if exist file2.txt goto mylabel
if exist .\mydir\file1.txt (
  echo file1 exists
  :mylabel
  echo This does not convert
)

Example that successfully converts:

if exist file2.txt goto mylabel
if exist .\mydir\file1.txt (
  echo file1 exists
  goto mylabel
)
goto skip
:mylabel
echo This does not converts
:skip

Labels must be unique

There must only be one instance of each label in a batch file.

Example that causes conversion problem (there are two labels named addNSLpp):

:addNSLpp
set NSLsl=false
echo %cclear%
cls
echo. %cback%%cwipe%
echo %cnote%Would you like to retain subtle CRT scanlines?
echo.
echo CRT scanlines are a personal perference but can make
echo an image look sharper
echo %cchoice%
.\util\choice /C:YN /N [Y]es or [N]o

If errorlevel = 2 goto NSLslno
If errorlevel = 1 goto NSLslyes

:NSLslno
set NSLsl=false
goto addNSLpp

:NSLslyes
set NSLsl=true
goto addNSLpp

:addNSLpp
set NSLpp=false
echo %cclear%
cls
echo. %cback%%cwipe%
echo %cnote%Would you like to use Pixel Perfect mode at the same time?
echo %cchoice%
.\util\choice /C:YN /N [Y]es or [N]o

If errorlevel = 2 goto NSLppno
If errorlevel = 1 goto NSLppyes