User:Eriksiers/to OS: Difference between revisions

Content added Content deleted
(→‎Shell Script: untested changes)
m (updated lang tag)
 
Line 5: Line 5:
This is done without using any libraries. (FB can use various regex libs, including [[wp:Perl Compatible Regular Expressions|PCRE]].)
This is done without using any libraries. (FB can use various regex libs, including [[wp:Perl Compatible Regular Expressions|PCRE]].)


<lang qbasic>'$LANG: "fblite"
<syntaxhighlight lang="qbasic">'$LANG: "fblite"


OPTION EXPLICIT
OPTION EXPLICIT
Line 99: Line 99:
f_IN = DIR$
f_IN = DIR$
WEND
WEND
NEXT</lang>
NEXT</syntaxhighlight>


==[[PowerBASIC]]==
==[[PowerBASIC]]==
Line 109: Line 109:
Also unlike FreeBASIC, when reading in a line from a text file via <code>LINE INPUT #</code>, only CRLF is recognized as EOL.
Also unlike FreeBASIC, when reading in a line from a text file via <code>LINE INPUT #</code>, only CRLF is recognized as EOL.


<lang powerbasic>$DIM ALL
<syntaxhighlight lang="powerbasic>$DIM ALL


SUB replacer(fileIN AS STRING, tgtName AS STRING, target AS STRING)
SUB replacer(fileIN AS STRING, tgtName AS STRING, target AS STRING)
Line 171: Line 171:
MSGBOX "Done."
MSGBOX "Done."
$ENDIF
$ENDIF
END FUNCTION</lang>
END FUNCTION</syntaxhighlight>


==[[:Category:UNIX Shell|Shell Script]]==
==[[:Category:UNIX Shell|Shell Script]]==
Line 179: Line 179:
This script decides what to do based on the script's name: <i>source</i>2<i>target</i>. (This is handled by <code>case</code>.) The translation is performed by <code>sed</code>.
This script decides what to do based on the script's name: <i>source</i>2<i>target</i>. (This is handled by <code>case</code>.) The translation is performed by <code>sed</code>.


<lang bash>case $0 in
<syntaxhighlight lang="bash">case $0 in
dos2unix)
dos2unix)
sed s/\r//g $1>$1.unix
sed s/\r//g $1>$1.unix
Line 198: Line 198:
sed s/\n/\r/g $1>$1.mac
sed s/\n/\r/g $1>$1.mac
;;
;;
esac</lang>
esac</syntaxhighlight>


An alternative would be to make this rather generic. It could be called <code>from</code>, and could be called similar to this:
An alternative would be to make this rather generic. It could be called <code>from</code>, and could be called similar to this:
Line 204: Line 204:
...which would write the output to "file.txt.unix".
...which would write the output to "file.txt.unix".


<lang bash>case $1 in
<syntaxhighlight lang="bash">case $1 in
dos)
dos)
first=\r\n
first=\r\n
Line 244: Line 244:
esac
esac
esac
esac
sed -b s/$first/$second/g $f>$f.$2</lang>
sed -b s/$first/$second/g $f>$f.$2</syntaxhighlight>