integer filein , fileout
sequence tekens , cmd
procedure cl2d()
integer pos_LF
fileout=open("klad","wb")
while sequence(tekens) do
pos_LF=find('\n',tekens)
while pos_LF do
tekens=tekens[1..pos_LF-1]&'\r'&tekens[pos_LF..]
pos_LF=find_from('\n',tekens,pos_LF+1)
end while
for i=1 to length(tekens) do
putc(fileout,tekens[i])
end for
tekens=get_bytes(filein,100)
end while
end procedure
function convert()
if(filein<3)
then puts(1,"file niet gevonden\n")
return 0
else
tekens=get_bytes(filein,100)
if find('\r',tekens)
then puts(1,"Dos format\n")
close(filein)
return 0
else
puts(1,"Linux format\n")
cl2d()
close(filein)
close(fileout)
return 1
end if
end if
end function
procedure convert2file(integer index; same)
filein=open(cmd[index],"rb")
if convert()
then removef(cmd[index+same])
renamef("klad",cmd[index+same])
end if
end procedure
ifdef JTP
cmd="norm.vrd"
convert2fl(1,0)
cmd="poule.vrd"
convert2fl(1,0)
elsedef
cmd=command_line()
filein=length(cmd)
if match("peu",cmd[1])
then
if filein < 3
then
puts(1,"Use : peu l2d fileinout or peu l2d filein fileout\n")
elsif filein < 4
then
convert2file(3,0)
else
convert2file(3,1)
end if
else
if filein < 2
then
puts(1,"Use : l2d fileinout or l2d filein fileout\n")
elsif filein < 3
then
convert2file(2,0)
else
convert2file(2,1)
end if
end if
enddef
abort(0)