April 18, 2024, 06:36:17 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


How can I convert a Unix file to Dos ?

Started by psevet, June 16, 2010, 11:01:36 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

psevet

Hello,

I'm facing problems while trying to convert a Unix File to Dos, in order to have it displayed under Notepad (Wordpad can edit Unix files without any previous conversion).

Basically, I found a command line utility that works fine sometimes and fails others ("todos.exe") under Window XP Professional Edition, in Dos mode.

How can I code a command line utility with Emergence Basic (or a Windows utility, provided the conversion doesn't show up while executing), not to mention a dll ?

Thanks in advance for your help.

Regards,

Pierre

LarryMc

From the help file:

QuoteSYSTEM(command as STRING, OPT param as STRING)

Description

Runs another executable.

Parameters

command - Executable to run.

param - Parameter for executable.

Return value

None

Remarks

Command must be full pathname to executable or the executable needs to be in the system path.

Example usage

SYSTEM "notepad.exe" , "c:\\mydocs\\prog.txt"

I'd try this first; if I understand your question correctly.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Doc

June 16, 2010, 12:38:54 PM #2 Last Edit: June 16, 2010, 12:41:45 PM by Doc
Line endings on Unix/Linux are denoted by chr$(10) only, where Windows/DOS uses a combination of chr$(13) + chr$(10)

Much easier said than done...
Your choices are to set up a loop to insert the chr$(13) characters in front of the chr$(10) for each line of your file (or edit control) --or likely easier-- loop through and replace all of the existing chr$(10) characters with the chr$(13) + chr$(10) combination.

-Doc-

Edit:

Forgot to add for the sake of total confusion:
Line endings on Mac are chr$(13) only

psevet

Thanks Doc !

Now that  I know what to do, I think I can try to cook something.

Regards.

Pierre

Doc

You're welcome!

Untested, but maybe you can use some of it:
'------------- change line endings ----------------
SUB UnixToDosLines
def pos:INT
def buffer2[32766]:ISTRING
pos = INSTR(buffer,CHR$(10))
while(pos)
if(mid$(buffer,pos,1) = CHR$(10))
buffer2 = left$(buffer,pos-1)
buffer2 = buffer2 + mid$(buffer,pos+1)
buffer = buffer2
endif
pos = INSTR(pos+1,buffer,chr$(13) + chr$(10))
endwhile
return


Most of the code above came from a sub in the old "editor" sample file, so I cannot take credit for it... just made a couple of modifications in this case.