Notes on the code for Twootie CLX:
A call for Linux programmers

Professor Austen Clark
Department of Philosophy U-54
University of Connecticut
Storrs, CT 06269-2054 USA


Why CLX? 

Programming platforms--operating systems, application program interfaces, compilers, and proprietary object hierarchies--are born, evolve, and die with astounding rapidity.  Having been burned by this myself, I would advise anyone interested in developing free logic software to avoid commitment to any one platform wherever possible. For a long time this seemed to doom the code in Twootie and Bertie3 to oblivion.  But recently (as of  October 2001), Borland has released products which make it possible to carry on further development of Twootie or Bertie3 in either Windows or Linux, without committing whole-hog to either platform.  They are Delphi 6 (in Windows), Kylix 2 (in Linux) and the "Component Library, cross-platform", also known as CLX.  Short of rewriting the whole thing in JAVA, this seems like the best way to go.  

Briefly, here are the reasons why.  (1) The language in Delphi 6 is a superset of Turbo Pascal. All the code for Twootie compiles successfully in Delphi. (2)  If one develops the menus and commands etc using just the objects found in CLX, the entire application can be ported to Linux relatively easily. Or, if it is developed in Windows CLX, it can be ported to Linux.  (3) Last summer Borland moved the Kylix version of CLX under the GNU GPL as well. So *all* of the source code needed for Linux versions of Twootie and Bertie3 would be "copyleft" or "open source". This is much better than relying on any procedure library or object hierarchy specific to one platform. (4) Finally, there is an "Open edition" of Kylix which Borland distributes for free on its website. So Linux programmers can get their hands on the needed tools.  The only caveat Borland puts on it is that any application you develop on the Open Edition and distribute has to be distributed under GNU GPL.  But this is perfect for free educational software anyway.

Notes on the code for Twootie

TWOOTIE 2.0 was developed in Turbo Pascal version 5.5, for DOS. That version of TWOOTIE was distributed by McGraw Hill starting in 1992 with the second edition of "The Logic Book" (by Merrie Bergmann, James Moor, and Jack Nelson). None of "object oriented" extensions of the language were used. It is approximately 27,331 lines of source code, organized in 30 distinct modules.

Borland Software now distributes Turbo Pascal 5.5 for free on its website. (They call it "antique software".) Borland proceeded to develop a version of Turbo Pascal for Windows 3.11, called "Turbo Pascal for Windows". The last version of Turbo Pascal for Windows (TPW) was version 1.5, released in 1991.

The menus and help system for TWOOTIE 2.0 were implemented using a library of functions and procedures developed by TurboPower Software (now in Colorado Springs, Colorado): "Turbo Professional" version 5.0, copyright 1987. Any unit starting with the letters "tp" (such as "tpcrt", "tphelp", and "tpmenu") is a TurboPower unit. The company still exists, and the product is still listed, for $279. This is the last version of the library developed for Turbo Pascal in DOS. It works fine in DOS but not in Windows. There is no successor product that would enable calls to Turbo Professional 5.0 functions to work under Windows.

Nevertheless the calls to Turbopower functions occur within just a few modules of the code: those involved in the menu and help systems. To confirm that the problems have been isolated in this way, I converted the modules that make such calls into "stub" modules, which have all the old type declarations and unit interfaces, but no code within them to actually implement a menu system or help system. This version--call it Twootie CLX version 0.1--compiles successfully in Delphi 6 but currently cannot receive any commands. (In effect it has the full inference engine running in Windows; but, like a good Cartesian meditator, it is entirely cut off from the external world, with no way to get input into it or output out of it.) I am releasing a separate distribution containing all the source code for Twootie CLX because I think it might be the most useful one for subsequent development.

Twootie CLX version 0.1 also compiles successfully in Turbo Pascal for Windows, version 1.5. That version included the full Windows 3.11 API (application programming interface), and its own object hierarchy for object oriented programming. The Windows 3.11 API is now out of date, if not quite antique, and as explained below there is a better alternative to implementing the menus, commands, help system, and event handling in a platform-specific library. So I would not recommend further development in TPW 1.5.

Cross-platform development in CLX

Borland used Turbo Pascal for Windows, with its object oriented extensions, as the programming language for its "Delphi" product--a system initially confined to developing dedicated Windows applications. The language now has some further extensions, and is called "Object Pascal", but Turbo Pascal code runs fine within it. Some of the standard procedures in Turbo Pascal ("gotoxy" or "clreol", for example) are no longer supported in Delphi, but when those are intercepted by "stub" procedures in the "turboext.pas" unit, all the remaining code does indeed compile in Delphi version 6.

Like Turbo Pascal for Windows, Delphi also had (and has) its own object hierarchy for object-oriented Windows programming, called "VCL". But things got really interesting when Borland (a) developed a Linux version of Delphi, called "Kylix", and (b) developed a cross-platform library of objects, called "CLX". In August 2001 Borland released the source code for the Linux version of the CLX library. It is distributed under terms of the GNU General Public License, just like Twootie.

CLX is a cross-platform library, and it allows the programmer to develop an application that (with some adjustments) runs in both Windows (98, 2000, NT, and XP) and in Linux. If the windows, menus, commands etc are implemented using the objects in CLX, then code can be ported from Windows to Linux (or vice-versa) relatively easily. It would be terrific to have Linux versions of the programs, with *all* the source code distributed under GNU GPL. 

Borland Software is sponsoring an "open source" initiative for CLX and Linux, and they provide an "Open edition" of Kylix version 2, first released in October 2001. It can be downloaded for free from their website (see http://www.borland.com/kylix). Any programs developed using the "Open edition" and distributed must be distributed under the "copyleft" terms of the GNU GPL, just like Twootie.

How to start in Delphi or Kylix

The distribution includes "project files" which tie all the elements of the project together. They have the root name "twootclx". I am not sure if the same project files will work in Kylix. In Delphi, you can simply click on the file "twootclx.dpr" and then select the command Project | Build twootclx, and all the files will be linked back together again. (The project files assume all the source files are placed in the same directory as twootclx.dpr.) The project type is "CLX application", which limits the component palette to objects found in CLX.

Kylix is case-sensitive, and so in this distribution all the source file names and unit names are entirely lower-case. There are other environmental differences to which one must pay attention in cross-platform programming. See ch 10 of the Delphi manual, or the manual for Kylix 2.

Some advantages to having a windows version of Twootie.

There are a few technical features of contemporary windowing environments that could improve the program immensely. One is access to protected memory. Under DOS the inference engine had a workspace that was limited (after the program loads) to about 250,000 bytes. Under Windows, with the memory common on machines these days, it could be much, much larger. It would be fascinating to see what the inference engine could do with the increased workspace and computational power available today. (There are no static limits imposed by the code on the size of problems the inference engine could address--it's all done by allocating structures on the heap--but the fascinating challenge is to improve the algorithms in the inference engine code so that it could tackle some really big problems. And then put it in the hands of students!)

The graphical interface would improve the program in various ways, major and minor. Scrollable windows would make it easier to keep track of big trees. Logic symbols could be displayed on the screen, instead of the current mish-mash of brackets and letters. It would be nice to have device-independence for printing and viewing. It would be handy to be able to cut trees into the Windows clipboard and paste them into documents.

Some problems that await.

All the stuff done in Turbopower Professional calls needs to be redone to have a Windows (or is it Apple?) look-n-feel. This basically includes the menus and the help system. The main dispatcher for commands was found in "commanda.pas" and its (Turbopower) menus in "twmenu.pas". In Delphi you just drag menu objects onto the screen, set properties, and then click on them to associate them with code; the code with which they need to be associated is found in those files. The help system in Turbopower is compiled separately (yielding the files "thelp.hlp" and "thelp.obj", but then it is called from "helper.pas".

Turbo Pascal had a standard library of functions some of which are not found in Delphi. Along the various screen procedures mentioned, the keyboard ("readkey") and memory handling ("memavail", "mark", and "release") are now entirely changed. Turboext.pas contains stubs for the eleven formerly standard procedures that no longer exist.

The screen in Twootie 2.0 is a "TTY" or "console style" screen: 25 (or 43 or 50) rows each containing a line of 80 characters. In other words, it is not "graphical" but is just "text". There is a "gotoxy" function in Turbo Pascal, used a lot in this code. Worse is the fact that all the algorithms for figuring out how to draw a tree in a pretty way (and redraw it, if need be) assume a text box with some fixed, maximum number of equal width columns. The actual value is set when the program starts up and reads the configuration file "tconfig.two", though the code in "initial.pas" right now will refuse to accept values over 136. See "placer.pas" and "redrawer.pas". Usually sentences in symbolic logic look best when displayed in a fixed-width font such as Courier, so the routines in redrawer might work fine. They will probably fail though if the user insists on displaying sentences in a proportionally spaced font.

The "print" routines also assume text output. See "printer.pas".

The editor reads keypresses from the "keyboard buffer", which in Windows is now hidden behind a pile of messages. See "editor.pas". The program does not use the mouse at all. It is hard to tell how much of the editor functions can be taken over by standard objects in the CLX library; it has "Edit" and "Mask Edit" objects, which might do most of the work.

The main loop of the main module is a message-driven loop (now found in proecedure "commandloop" in the file twootie.pas), but otherwise the underlying architecture is not "event-driven", as any real Windows program is.

Future developments

Delphi 6.0 is an amazing product, and as I play around with it I will probably release subsequent versions of TwootCLX.zip. So check the Bertie/Twootie home page for developments. I would be happy to correspond with anyone who might be interested in developing a CLX version of Twootie.


Revised June 2002.  Other links:  

Bertie/Twootie source code.
The Bertie/Twootie homepage.
The self-paced logic project.
Austen Clark's homepage.