SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member frankie54's Avatar
    Join Date
    Feb 2001
    Location
    NYC
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    unix carriage returns -vs- mac -vs- pc ...??

    I was editing a PHP script I wrote in gnotepad on one of my Linux
    boxes, and noticed that it looks completely different in BBEdit
    on a Mac running OS X.

    I actually had to re-format the script for it to work at all, as the
    Mac started concatenating parts which were previously clearly
    separated by carriage returns on the Linux system.

    Is anyone out there able to direct me to a resource already
    written describing the differences in document formatting
    between unix - mac - pc, and what to do to keep it consistent ?

    trivial, but important for anyone doing multi-platform work...

    Answers appreciated.

    frankie
    stay groovy !

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's interesting because I have always found BBEdit to be the best text editor (on Mac) for being able to handle all the different line break formats. It's never given me trouble when I've opened up windoze or *nix files. I'm sure that there is something built in that would handle converting the file (I guess it wouldn't hurt to RTFM ) Anyway, as I understand it, line breaks on the three architectures is like so:

    Windoze
    \r\n
    Unix
    \n
    Mac
    \r

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for newlines:

    *nix uses \n (newline)
    Mac uses \r (carriage return)
    Win uses \r\n (newline/carriage return pair)

    so if you view a *nix script on a Mac the Mac doesn't know those characters should start a newline, so it doesn't. usually they're rendered as a black square if i view a *nix script on Win. what can you do about it? use an editor that will save in the format you prefer. or i guess you could FTP the file (in ASCII mode) over a network and the FTP client/server will convert the newlines to the machine's native format.

    hope that helps.

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh, you beat me freaky.

  5. #5
    SitePoint Member frankie54's Avatar
    Join Date
    Feb 2001
    Location
    NYC
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    definitely where to start

    ...Yes, I will RTMFM for sure!! (the extra 'M' is for many)

    I am sure there must be ways for advanced editors such as BBEdit to:

    -1 ) display all ASCII characters, invisible or not.

    -2 ) save files in a format that's the most desirable.

    Additionally, there probably is 'import filters' out there which would
    be able to parse a document and replace the proper \r's and \n's....

    Of course, if I only was a master of regular expressions,
    I could write shell scripts which would do this too!!

    In passing freakysid, does retiring the Mr Spock avatar mean that it's now
    fair game for someone else?? (love the Kandinsky)

    frankie
    stay groovy !

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Spock with a beard is on holiday but will be back very soon. He has not retired.

    As for your point 2) there is an icon in the tool bar of BBEdit where you can specify the file format of the file being edited (*nix, mac, dos). You can also set this when you go File>Save As>Options

    Also, you can type "invisible" characters into the find/replace window. So you can do something like:

    find: '\r\n'

    replace: '\n'

    And use find/replace rather than do fancy regex.
    Last edited by freakysid; Jul 7, 2001 at 20:03.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •