integer fileout,filein
sequence tekens
atom convertForward
atom cl2dForward
global procedure convert2file(integer index; same)
filein=open(cmd[index],"rb")
if call_func(convertForward,{})
then removef(cmd[index+same])
renamef("klad",cmd[index+same])
end if
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")
call_proc(cl2dForward,{})
close(filein)
close(fileout)
return 1
end if
end if
end function
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
convertForward=routine_id("convert")
cl2dForward=routine_id("cl2d")