Tuesday, December 20, 2005

TraverToy2 and Platform Determination

First, let me mention that I've replaced TraverToy1 with an improved version. I should have run TraverToy1 through my CodeHelper program before I uploaded the source code. The revised version eliminates Dimensioned but unused variables and alphabetizes the Dim statements and removed a bug that in effect removed the end-of-line markers in a processed file. So I thought I make make the topic of today's blog end-of-line markers, which (interestingly enough) is one of the ways we can determine the platform on which a program is running.

In a text file, the Mac, Linux, and Windows all use a different way of indicating the end of a line. The Mac uses a Chr(13) or "carriage return" character, Linux uses a Chr(10) or "line feed" character, and Windows - to be different - uses a Chr(13) followed by a chr(10) character (CR/LF or "carriage return"/"line feed"). (Well, actually Windows isn't consistent on using that end-of-line marker - it does something different in EditFields - but that's another topic for another time. Suffice it to say that in a text file it does what I have just said it does.)

What practical use does this information have? Not very much. It is likely that all of the text files you have fit" your platform, so it's not that helpful to be told that a file on a Mac computer is a Mac file, a file on a Linux system is a Linux file, or that a file on a Windows PC is a Windows file. Whan might it be otherwise? Well, if you download from the internet a file that came from a friend using a different platform, you could end up with, say, a Windows file on your Mac computer. Even so, you're unlikely to have problems in accessing the file, since your computer will know what to do with it, even if it did come originally from a different platform.

What TraverToy2 does is allow you to do something like this: If you own a Mac and you're sent a Linux or Windows text file, you can modify the file with an RB program and send back the file as a Linux or Windows file based on the type of file you were sent. And so on. I have no idea where you'd find a situation where it would be important to do that, but I never promised that all the TraverToys would be useful. I just indicated that you'd find things here you wouldn't find elsewhere (and sometimes for good reason!)

To analyze the type of file, some "RegEx" routines are used. I won't try to explain RegEx at this point other than to say that it's a way to do some rather complex searches. Here it simply checks to see what chr(13) or chr(10) or Chr(13)+Chr(10) is being used as an end-of-line marker, and then reports accordingly that it's a Mac, Linux, or Windows text file. If you already know how to use RegEx, you won't need an explanation from me; if you don't know what "RegEx" is all about, I won't try to explain it here in "one easy lesson."

Acknowledgment: I think it was "dda" (Didier) who taught me how RegEx makes it possible to do thing like this, so I do hope to be getting back to a somewhat detailed explanation of RegEx later when we do some "whole word" searches of XML files.

Incidentally, you may be wondering what sort of goals I have for this blog. Well, I'm hoping (if I get feedback that there is some interest in people's reading what I write) to add at least one new entry every two days, and to add at least two new programs (usually short TraverToys, but occasionally larger programs) each week (but, again, that is dpendent upon there being evidence that people are reading the blog, so please take the time to send me a private email or to post a short comment if you want me to continue).

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

0 Comments:

Post a Comment

<< Home