Iso or not iso source ?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Iso or not iso source ?

Post by jmburnod » Mon May 12, 2014 8:57 am

Hi All,
I am cooking a way to know on which platform a text file was created.
This script seems work but I guess someone have a better solution.

Code: Select all

on mouseUp
   answer file "Open"
   if it = empty then exit mouseUp
   put url("file:" & it) into tText
   put mactoIso(numtochar(142)) into tSearchFrench
   put mactoIso(numtochar(138)) into tSearchGerman
   if matchText(tText,tSearchFrench) or matchText(tText,tSearchGerman) then
      put "Iso" into tSource
   else
      put "Mac" into tSource
   end if
   answer "This file was created on" && tSource
end mouseUp
Thank for comment
Jean-Marc
https://alternatic.ch

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Iso or not iso source ?

Post by Klaus » Mon May 12, 2014 6:27 pm

Hi Jean-Marc,

on the mac you could use a shell command!
file -I <path_to_file.txt>

Gives me this for a ISO encoded text file:
/Users/klaus/Desktop/videos_alexa.txt: text/plain; charset=iso-8859-1

Hope this helps!


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Iso or not iso source ?

Post by jacque » Mon May 12, 2014 10:11 pm

I wonder if it would be reliable to just check the line endings.

numToChar(13) = Mac
numToChar(10) & numToChar(13) = Windows (LFCR)
numToChar(10) = Linux

But I'm not sure that would be consistent. If you are always on a Mac I think Klaus' shell command is reliable.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Iso or not iso source ?

Post by jmburnod » Mon May 12, 2014 11:21 pm

Hi,
@Klaus
I never used shell commands and i'm confused about syntax
LC Dictionary only talks about function shell.

@ Jacque
If you are always on a Mac I think Klaus' shell command is reliable.
I need it for OSX,windows and Linux to allow files exchange between all platforms
( except from mac to androïd and IOS to windows) :D
numToChar(13) = Mac
numToChar(10) & numToChar(13) = Windows (LFCR)
There is two chars for the line ending on windows ?

Thanks for your lights
Jean-Marc
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Iso or not iso source ?

Post by jacque » Tue May 13, 2014 12:02 am

jmburnod wrote: There is two chars for the line ending on windows ?
Yes.

But oops, I got it backwards. Windows line endings are CRLF.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm

Re: Iso or not iso source ?

Post by paul_gr » Tue May 13, 2014 2:48 am

jacque wrote: Yes.
But oops, I got it backwards. Windows line endings are CRLF.
Not always.
I'm using Notepad++ as a text editor on Windows and have it setup to save line endings as LF.
This is fairly common if anyone is using a programmers editor.

Paul

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Iso or not iso source ?

Post by jacque » Tue May 13, 2014 7:15 am

Wondered about that. I wasn't sure how predictable the line endings would be. On my Mac I have BBEdit set to use Linux line endings, so I don't follow the norm either. So probably a shell command is a better deal if there is one available on each platform.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Iso or not iso source ?

Post by jmburnod » Sun Jun 08, 2014 10:45 am

Hi All
So probably a shell command is a better deal if there is one available on each platform.
Sorry I dont know using Shell :oops:
I maybe have found a way working as Jacques has suggested 8)
(All concerned files are created by my app)

Code: Select all

function getFileCreatePlatform pFile
   put url ("binfile:" & pFile) into x
   put "n/a" into LsepLine
   put 0 into LBOMlength
   if offset(numToChar(13)&numToChar(10),x) > 0 then
      put "win" into LsepLine
   else if offset(numToChar(10),x) > 0 then
      put "unix" into LsepLine
   else if offset(numToChar(13),x) > 0 then
      put "mac" into LsepLine
   end if
   return LsepLine
end getFileCreatePlatform
Kind regards
Jean-Marc
https://alternatic.ch

Post Reply