User:Eriksiers/to OS: Difference between revisions

m
updated lang tag
(→‎Shell Script: untested changes)
m (updated lang tag)
 
Line 5:
This is done without using any libraries. (FB can use various regex libs, including [[wp:Perl Compatible Regular Expressions|PCRE]].)
 
<langsyntaxhighlight lang="qbasic">'$LANG: "fblite"
 
OPTION EXPLICIT
Line 99:
f_IN = DIR$
WEND
NEXT</langsyntaxhighlight>
 
==[[PowerBASIC]]==
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.
 
<langsyntaxhighlight lang="powerbasic>$DIM ALL
 
SUB replacer(fileIN AS STRING, tgtName AS STRING, target AS STRING)
Line 171:
MSGBOX "Done."
$ENDIF
END FUNCTION</langsyntaxhighlight>
 
==[[:Category:UNIX Shell|Shell Script]]==
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>.
 
<langsyntaxhighlight lang="bash">case $0 in
dos2unix)
sed s/\r//g $1>$1.unix
Line 198:
sed s/\n/\r/g $1>$1.mac
;;
esac</langsyntaxhighlight>
 
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:
...which would write the output to "file.txt.unix".
 
<langsyntaxhighlight lang="bash">case $1 in
dos)
first=\r\n
Line 244:
esac
esac
sed -b s/$first/$second/g $f>$f.$2</langsyntaxhighlight>
1,150

edits