Monday, 2 July 2012

BACK TO DOS!

Dick Pountain/13 February 2002/14:49/Idealog 91

There comes a time in the life of many men when they are driven by irresistible, genetically-programmed forces to start rebuilding things - old steam engines, tractors, Bugattis, even lawnmowers. Fortunately a lifetime of motorcycling has very effectively inoculated me against such urges, and I derive absolutely no erotic frisson from having grease underneath my fingernails (indeed I started paying other people to fix things many years ago). A spanner is nothing more than a spanner to me.

Nevertheless I've recently realized that this recreative urge is so powerful that it's become sublimated into a less concrete form, namely an interest in preserving old software. This bug infected me quite some time ago, and I've mentioned it here before in connection with my love of solving horrendous file conversion problems - you see my favourite tools for this purpose mostly run under DOS. What jogged my mind about this was Dave Moss's Back Office column this month, which is devoted to the joys of the DOS NET command, and Paul and Mark's recent column about using DOS scripts for controlling power switches. Both of these made me feel less guilt about my retro tendencies, and reassured me that I'm not alone. 

Not being entirely daft, I combine all the convenience of Windows with my DOS doodling by employing the excellent TextPad editor as my user interface. With three text windows open, one for the source of the script I'm writing, one for a test input file and one for the output file, I open a fourth, command prompt window to issue the Nife command line that edits the file: I only ever need type this once and the reuse it thanks to DOSKey. TextPad even supports user-defined syntax colouring and can run DOS programs from its Tools menu, so my whole edit/run/debug cycle is as fast and convenient as any IDE.

As an example, I recently felt inclined to bring the Idealog columns on my Web site (www.dickpountain.co.uk) up to date. The site was originally built using Netobjects Fusion, but I so hated the fiddly way Fusion updates multi-file pages that I resolved to automate the process myself. A Perl script would probably have done it, but to tell the truth I've never really warmed to Perl: it looks too much like C. Instead the solution I knocked up in a short afternoon uses the line-by-line Nife editor in three separate passes, each storing its result in a temporary file: one extracts the date and issue number, two extracts the column title, and three extracts the body copy while stuffing <BR> tags between its paragraphs. From one of the Fusion-generated Idealog pages I then chopped out the chunks of horrible HTML that fit between these elements and stored them as four more template files. A 7-line batch file called convert.bat runs the three Nife passes and concatenates all seven temporary files using a simple DOS Copy command, while a second 3-line batch file, convertall.bat, runs this first batch file in a FOR loop to convert everything called idealog*.txt. Clicking on convertall mangles a whole directory full of original Idealog files into appropriately-named .htm files.

While writing these scripts I discovered, rather to my surprise, that despite the fact that Windows 2000 no longer runs on top of DOS, its Command Prompt actually supports some very substantial enhancements to the batch language. There are powerful new parsing options (particularly for the FOR command) so that for example I was able to extract the digits 57 from a filename like idealog57.txt using the simple construct '%fname:~7,2%' which chops a chunk out of fname just like Basic's midstr function. In truth I've yet to get the full measure of how far these extensions will take you. 

For those occasions when even this extended DOS batch language doesn't have the command I need, I often write a little custom filter to do the job in Turbo Pascal 4, which I've resurrected from dusty floppies (and even found its paperback manual - remember those?) An example might be to perform some transformation on a filename that requires more than just extracting digits, such as turning 'dmf981110.txt' into '10th November 1998'.

Very, very occasionally I need some seriously intelligent logic, and for that I may use a small DOS-based language interpreter called Glow (a miniature relative of POP-11) that can read in an external text file as a list and then perform Lisp-style operations on it - for example some complex set conjunction like 'if the next word is in list A and in list B or in list C' where A, B and C are all dynamically constructed. Glow was written by a guy called Andrew Arblaster back in 1990 and is now completely unsupported: because of DOS's severe memory limitations it's rather slow and fragile, but writing in it still gives me much pleasure, tinged with some regret that the twin tyranny of C++ and Visual Basic has killed off such languages so completely. Future generations will never know just how powerful list processing was and how much simpler it made many tasks. With this kit of antique tools at my elbow there's very little in the way of twisting text files that I'm afraid to tackle nowadays, and the weirdest thing is that, TextPad apart, I can find very few Windows-based tools that will do half as well.

[Footnote: Please don't email me to ask for copies of Nife or Glow as I do not own the copyright on either and am no longer in touch with their authors.]

No comments:

Post a Comment

CHINA SYNDROME

Dick Pountain /Idealog 357/ 08 Apr 2024 01:09 Unless you live permanently as an avatar in Second Life [does that even still exist?] then it ...