Chapter 3. View the Code

Table of Contents

3.1. File Overview
3.2. demo.g - The Demo Start-Up mini-program
3.3. gtkcontrol.g - The Controller program in GTK
3.4. phcontrol.g - The Controller program in Photon
3.5. emul.g - The PID Emulator program
3.6. gtkmonitor.g - The Monitor program in GTK
3.7. phmonitor.g - The Monitor program in Photon
3.8. gtklog.g - The Log program in GTK
3.9. phlog.g - The Log program in Photon
3.10. gtkhistory.g - The History program in GTK
3.11. phhistory.g - The History program in Photon
3.12. lib/common.g - Common library
3.13. lib/linux.g - Linux library
3.14. lib/qnx.g - General QNX library
3.15. lib/qnx4.g - QNX 4 library
3.16. lib/qnx6.g - QNX 6 library
3.17. lib/gtk.g - GTK library
3.18. lib/photon.g - Photon library

3.1. File Overview

The code for the Cogent Tools Demo has been written to facilitate cross-platform implementation in Linux and QNX, and their respective GUIs—GTK and Photon. Despite cosmetic differences due to the different GUI software, much of the functionality within the programs is similar if not identical. To avoid having to maintain and document several versions of identical or similar functions, we have set up libraries that contain common code and abstracted code. Overall, there are three general categories of functions, grouped into files as follows.

Application-specific functions are specific to a single application, such as the PID Emulator (emul.g) or the Monitor running in Photon (phmonitor.g). Each Photon-specific program (ph*.g) has two sets of widget files: a Photon 1.14 version for QNX 4, and a Photon 2 version for QNX 6.

Common functions  run on any OS (Linux, QNX 4, and QNX 6), regardless of GUI support (GTK or Photon), and are all found in lib/common.g. Every application loads these.

Abstracted functions are a group of functions that come in pairs or triples. Each member of the pair or triple varies from OS to OS or from GUI to GUI, but has the same name, takes the same argument lists and performs the same tasks as the other function(s) in that group. But the code within the function is different. For example, the anyos_help function in lib/linux.g calls a web browser on a Linux system to display this book's title page, while anyos_helpa function in lib/qnx.g calls the Helpviewer on a QNX system to display the same page.

The libraries that contain these identically-named functions are loaded in a mutually exclusive way, using the Gamma require function. The lib/common.g file's first function is lib_require, which determines the operating system and loads one of the following groups:

Once a library is loaded its functions are accessible by the original program and any other function in the loaded group.