FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour memowrit() file type DOS or UNIX
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
memowrit() file type DOS or UNIX
Posted: Mon Feb 14, 2022 08:41 AM

Dear Crsitobal,
sometimes when I save text with memowrite() the files are stored as UNIX Type files.
I do not find out where I can change that the files are always DOS Type files.
I think I saw inside your fivedit this possibility. Can you please show me where you can change type format with FW source code?
Best regards,
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: memowrit() file type DOS or UNIX
Posted: Mon Feb 14, 2022 09:05 AM

Dear Otto,

From google:

The main difference is in the line endings for each. Windows uses CR-LF as the line ending in a text file, while linux uses LF and MacOS uses (used?) CR. The upshot of this is that if you save a script file on Windows it will default to CR-LF which will make the script unable to be executed in Linux.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: memowrit() file type DOS or UNIX
Posted: Mon Feb 14, 2022 09:12 AM

Dear Otto
PREFERENCES - GENERAL - Convert and Settings - Set EOL CRLF ( or LF or CR )

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: memowrit() file type DOS or UNIX
Posted: Mon Feb 14, 2022 10:21 AM

Dear Antonio, dear Cristobal,
Thank you for your help.
As I need this inside my code, do you think strTans() could work?
>Windows uses CR-LF as the line ending in a text file, while linux uses LF
Best regards,
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: memowrit() file type DOS or UNIX
Posted: Mon Feb 14, 2022 04:38 PM

Dear Otto,

You can use StrTran( cText, Chr( 13 ) + Chr( 10 ), Chr( 10 ) ) to go from Windows to Linux

but to go from Linux to Windows I think you can not use StrTran() or you will go into an endless loop as it will never stop:
StrTran( cText, Chr( 10 ), Chr( 13 ) + Chr( 10 ) )

So from Linux to Windows you may do:
local aLines := hb_ATokens( cText, LF )

and then create the text:
cText := ""
AEval( aLines, { | cLine | cText += cLine + CRLF } )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: memowrit() file type DOS or UNIX
Posted: Mon Feb 14, 2022 04:56 PM

Dear Antonio,

Thank you.
As these files are only a few lines, maybe I can
STRTRAN() CRLF to something
then STRTRAN() LF to CRLF
and then something to CRLF.
I will try when I face the next time, a wrong file type.
Best regards,
Otto

Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: memowrit() file type DOS or UNIX
Posted: Wed Feb 16, 2022 10:00 PM
hi,

i have a "Old" which need CRLF else all is "one line"

i have this working Source which work under Xbase++
Code (fw): Select all Collapse
#include "Directry.ch"
PROCEDURE MAIN()
LOCAL aDir
LOCAL cFile
LOCAL cMemo
LOCAL cOut
LOCAL i,iMax

   aDir := Directory("*.PRG")
   iMax := LEN(aDir)

   FOR i := 1 TO iMax
      cFile := aDir[i][F_NAME]
      cMemo := MEMOREAD(cFile)
      cMemo := StrTran(cMemo,CHR(10),CHR(13)+CHR(10))

      cOut := UPPER(cFile)
      cOut := StrTran(cOut,".PRG",".PPG") // just to have other Extension
      MemoWrit(cOut, cMemo)
   NEXT

RETURN

it should also run under harbour
greeting,

Jimmy

Continue the discussion