Chapter 10. Abstracted Functions

Table of Contents
10.1. Linux or QNX (in lib/linux.g, lib/qnx.g)
10.2. Linux, QNX 4, or QNX 6 (in lib/linux.g, lib/qnx4.g, lib/qnx6.g)
10.3. QNX 4 or QNX 6 (in lib/qnx4.g, lib/qnx6.g)
10.4. GTK or Photon (in lib/gtk.g, lib/photon.g)
10.5. GTK only (in lib/gtk.g)
10.6. Photon 1.14 or Photon 2 (in lib/qnx4.g, lib/qnx6.g)
10.7. Photon only (in lib/photon.g)

These functions have been created to handle differences between different operating systems (Linux, QNX 4, and QNX 6) and/or different graphical user interfaces (GTK, Photon 1.14 and Photon 2). We refer to these functions as "abstracted" because they come in OS- or GUI-specific pairs or triplets, where each function has exactly the same name and arguments. Each function in the pair or triplet is included in a mutually exclusive OS-specific or GUI-specific library. When a program starts up, the common.g function lib_require ensures that the appropriate libraries are loaded. Thereafter, when the program or the common code calls one of these functions, the code that runs is specific to the OS and GUI in use.

For more information on abstracted and common functions, please refer to Section 3.1, File Overview.

10.1. Linux or QNX (in lib/linux.g, lib/qnx.g)

Section 10.1.1, System Calls - anyos_system
Section 10.1.2, Showing Help - anyos_help

10.1.1. System Calls - anyos_system

This function has been abstracted because the QNX operating system emits a signal when it makes a system call. In QNX we have to block signals while we make the system call.

10.1.1.2. For QNX (lib/qnx.g)

The Gamma functions block_signal and unblock_signal signal are used for deactivating signals while the system call is made. The signal has to be re-defined using the Gamma signal function once block_signal has been used.

   /*--------------------------------------------------------------------
    * Function:    anyos_system
    * Application: common 
    * Returns:     t or nil
    * Description: A wrapper for the Gamma system() function that blocks
    *              signals while making a call, then reassigns a signal
    *              and unblocks the signals.  This is necessary for QNX4,
    *              and perhaps QNX6, because in that OS a system() call
    *              emits a signal.  
    *------------------------------------------------------------------*/
   function anyos_system(call, sig)
   {
     block_signal(sig);
     system(call);
     signal(sig, `anygui_sigchild());
     unblock_signal(sig);
   }
   

10.1.2. Showing Help - anyos_help

Each of these functions calls the anygui_makemsg function to create the message/dialog window that displays the message.

10.1.2.2. For QNX (lib/qnx.g)

For QNX, we assume that the Helpviewer is available to view the documentation. We use the Gamma is_file function to make sure the documentation has been installed in the Helpviewer. Then we use the Gamma/Photon functions PxHelpTopicRoot and PxHelpTopic to set the Helpviewer to the proper page.

   /*--------------------------------------------------------------------
    * Function:    anyos_help
    * Returns:     t or nil
    * Description: Starts up the Helpviewer and displays the Tutorial docs.
    *------------------------------------------------------------------*/
   function anyos_help()
   {
     local help_url = "/usr/cogent/help/cogent-set/booktu/booktu.html";
     
     if (is_file(help_url))
       {
         PxHelpTopicRoot("/Cogent Documentation/Cogent Tools Demo and Tutorial");
         PxHelpTopic("booktu.html");
       }
     else
       anygui_makemsg(string("\nSorry, the Cogent Tools Demo and Tutorial",
                             "\nmanual is not available on your system.\n",
                             "\nPlease check your",
                             "\nCogent Documentation installation.\n\n"));
   }
   

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.