Forum OpenACS Q&A: CRLF Mac *nix DOS conversions

Collapse
Posted by MaineBob OConnor on

I have a MAC user that is using BBEdit to create and edit .adp files and the variables sucked out of the database do not show up... The error message is:

Error: can't read "db": no such variable
From this code:
<%
set db [ns_db gethandle]
set user_id [ad_verify_and_get_user_id]
set selection [ns_db 0or1row $db "select first_names, last_name,
email, screen_name, tgn_status, registration_date from users 
where user_id=$user_id"]
# and more not shown...

So, Linux RH7/ AOLserver AOLserver/3.3.1+ad13 / Postgres 7.1 Doesn't like MAC .adp files...

I first disovered that just saving the file in my Windows (DOS) editor makes the file work just fine because saving converts the CR to a CRLF pair.

Also I can translate the MAC CR to the *NiX LF character using this *Nix command:

tr '
' '
' < mac1.adp > lixux1.adp

I post this for others who might run into this problem...
AND
I wonder if there are options with BBEDIT to save the file either with the *nix LF or dos CRLF pair so that we don't have to do the "tr..." conversion every time an .adp file is uploaded.

IF there is a BBEDIT user out there, please tell me how to set it up for *nix or dos new lines.

Thank you.

-Bob

Collapse
Posted by mark dalrymple on
(just a note - 'Mac' isn't an acronym, so it shouldn't be capitalized)

BBEdit can save with unix line termination. In the text window, there's a little popup (the one which looks like a little file) that lets you change them on a file-by-file basis. BBEdit will honor the line termination of opened files (so once it's saved with unix line endings, BBEdit will keep them this way)

Collapse
Posted by MaineBob OConnor on

OK, on the web something was lost in the translation of the tr command above. perhaps 'cause of the single backslash... I doubled them up and show it here.

tr '
' '
' < mac1.adp > lixux1.adp

-Bob

Collapse
Posted by Torben Brosten on
Hi Bob,

Know that tcl automatically recognizes EOLs for Mac, *nix and MSDos systems. So you can create a short tcl script that automatically reads the file line by line, writing to a new file with the standard tcl (*nix) EOL. This gives you a way to automate/batch the process should files be inconsistently saved from various OS's in the future.

Collapse
Posted by MaineBob OConnor on

Hi Torben

    "...Know that tcl automatically recognizes EOLs for Mac, *nix and MSDos systems. So you can create a short tcl script that automatically reads the file line by line..."

A better solution would be for tcl to automatically recognize the Mac CR the same way it recognizes the *nix LF character. It appears that *nix just totally ignores the CR which is why Win/DOS files with CRLF work just fine.

How deep do we have to go to make this work? Is it just an issue with .adp files?

Here is the ideal:

  • CR (by itself) -> One New Line
  • LF (by itself) -> One New Line
  • CRLF (pair) -> One New Line

-Bob

Collapse
Posted by Torben Brosten on
Hi Bob,

You ask: How deep do we have to go to make this work?  Is it just an issue with .adp files?

In short, it's not deep, but pervasive.

I regularly use/mix MacOS and *nix files (sprinkling in some MSWin/DOS). This is a regular barrier of any text-based file on *nix coming from a Mac (that is not prepared for *nix). Still, it is not a difficult barrier to overcome.

There is an elegant example tcl script for converting files to *nix EOLs included in the 2nd ed. of "Practical Programming in Tcl an Tk" by Welch --I don't know if it is in the 3rd ed. It recursively reads a whole file before writing. The example works for most small files (I think).

Recently, I had to convert a 500MB+ file, so I could use linux tools on a mail collection file (less, grep, etc.). Previous to conversion, these linux utilities assumed the file was one long line and did not work as I had "wished".  The linux machine froze while processing the file using the example script. (The Mac software crashed when reading the entire file also).  I patched together a script that bypasses memory requirements; it writes a line as it reads a line --crude and slow, but it works.

Collapse
Posted by Henry Minsky on
Now that I am using a teletype I find that I need to put CR's back into text, or else the carriage just sits on the right margin printing all the characters on top of each other.