Or: How Could I Have Been Such a Fool?
Hi there, boys and girls. I thought a bit about the file encryption utility we did yesterday and decided I had better take care of the problem of KryptisolC not handling file names with spaces sooner than later. If you werenít with us yesterday, click here for the whole sordid KryptisolC story.
For the command line, I thought we would figure out some delimiter character to use after the Ėf switch to surround the file specification string. Then we would teach Kryptisol to take all of the characters between the delimiters as a literal string no matter what was inside, including spaces.
To deal with the eraserl problem, the cleverest approach I could come up with was to rename each file to something like eraserl.wipeit and then call eraserl on eraserl.wipeit which would never have any spaces because it doesnít have any spaces and it would always be the same. I figured the chances of someone having a precious file in their subdirectory called eraserl.wipeit would be pretty slim. We could even have KryptisolC warn us if that was the case.
Well, I started to experiment with delimiter characters and I decided the most natural character would be quotes. But what to do if the file name already contained quotes? I thought we could probably do what a lot of other programs have done in the past and say that double quotes in succession like ĒĒ mean a literal quotation mark and a single quote like Ē is a delimiter. Yeah, thatís tedious, but it should work. So I set about making some example files with quotes in the file name. Huh? What? Turns out you canít do it with Windows. Who knew? But thatís probably a good thing, I thought; it makes our delimiter character all that more unique. The next step was to place quotes around the file spec on the command line, put some diagnostic printf() statements in KryptisolC and see what the returned command line parameters looked like. To my consternation the quotes were not returned. It looked like DOS was ignoring them. I was about to choose a different delimiter character when I noticed that what was returned was the literal text between the quotes. Wait a minute. Isnít that what we wanted? I ran a few more examples through the mill and, sure enough, if you put quotes around something on the command line, whatever is between the quotes gets returned as a literal string. Well, Iíll be.
Iím not sure when this happened. Iím not even sure it wasnít always the case, but itís something I didnít know. The only down side is that I can only guarantee that this is the case for the DOS boxes that come with Windows XP. DOS 3.4 might not have this feature. I could do some research on that, I guess. For now Iím just going to take it as a freebie because I no longer know anyone who uses Windows who is using anything but XP.
Good. So we donít have to mess with that. KryptisolC never had a problem with spaces it encountered in file names in the DOS environment, just on the command line. Next I started fooling with how to rename files for eraserl. Oops. The system Ďrení function, being a command line utility its own self, wouldnít take file names with spaces. Hmmmm . . . Well, what if you put them in quotes?. It worked. Then it dawned on me. eraserl will probably take them within quotes, too! And, lo and behold, it does! OK. Iím embarrassed that I worked with DOS all these years and never noticed that and never heard of it, but the bottom line is that DOS is behaving exactly as we want it to almost for free. I say ďalmostĒ because we do need to change a few lines of code, but this project is over almost before it started. All we needed to know was that it was done.