Chapter 12. Controller Functions

Table of Contents

12.1. Choosing a Controller - the demo.g program
12.2. GTK: the Controller window - create_control_win
12.3. GTK: Building Control Buttons - control_button
12.4. Photon: the Controller window - create_control_win
12.5. Common: The Text Message Display - read_msg and messages.txt
12.6. Common: The Process Status Display - show_names, toggle_raw, .reassign_prog_name, extra_space
12.7. Common: The Data Directory - make_datadir

This chapter presents annotated code for gtkcontrol.g (for GTK) and phcontrol.g, as well as contain common functions that are used in Linux or QNX, GTK or Photon.

12.1. Choosing a Controller - the demo.g program

This mini-program starts the Tools Demo by starting the Controller. It first checks to make sure that a Controller is not running, and then it chooses which Controller program to run: gtkcontrol.g or phcontrol.g, based on the current operating system, and (in the case of QNX 6) the desired GUI.

   /*--------------------------------------------------------------------
    * File:        demo.g
    *
    * Description: This program starts the demo. 
    *------------------------------------------------------------------*/
   
   /*--------------------------------------------------------------------
    * Function:    main
    * Returns:     doesn't return
    * Description: Calls gtkcontrol.g or phcontrol.g, depending on the OS
    *              and/or a command line argument.
    *------------------------------------------------------------------*/
   function main()
   {
     if (_os_ == "Linux")
       system("gamma gtkcontrol.g");
     else if (_os_ == "QNX4")
       system("phgamma phcontrol.g");

The prompt for QNX 4 Gamma programs that run Photon is phgamma, not gamma. This demo.g program lets us effectively wrap the phgamma command in a gamma command, giving us one, simple way to start the demo in any of the three operating systems.

     else if (_os_ == "QNX6")
       {
         if (cadr(argv) == nil)
           system("gamma phcontrol.g");
         else if (cadr(argv) == "photon")
           system("gamma phcontrol.g");
         if (cadr(argv) == "gtk")
           system("gamma gtkcontrol.g");
       }
   }
   

The Gamma function system function is used to send the system command gamma *control.g, which starts the Controller. The optional third argument in the gamma demo command (which is only available in QNX 6) is accessed using argv, a symbol containing a list of command-line arguments. We use the Gamma function cadr to extract the third argument (if any) from the list.