Abstracted Functions

Cogent Tools Demo and Tutorials: Version 4.0
Prev |  | Next

# Chapter 10. Abstracted Functions

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.1. For Linux (`lib/linux.g`)

       /*--------------------------------------------------------------------
        * Function:    anyos_system
        * Returns:     doesn't return
        * Description: A wrapper for the system() function to allow for alternate
        *              code in QNX.
        *------------------------------------------------------------------*/
       function anyos_system(call, sig)
       {
         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.1. For Linux (`lib/linux.g`)

For Linux we assume that help files are not installed on the system, but that a browser is installed. Thus, this function walks through a list of browsers and starts the first available one, pointing it to the on-line Cogent documentation for the Demo and Tutorials.

       /*--------------------------------------------------------------------
        * Function:    anyos_help
        * Returns:     function
        * Description: Starts up a browser and displays the Tutorial docs.
        *------------------------------------------------------------------*/
       function anyos_help()
       {
         local url = string("http://developers.cogentrts.com/cogent/cogentdocs/booktu.html");
         local browser, browsers = list("galeon", "mozilla", "lynx", "opera",
                                        "dillo", "netscape", "w3m", "netrik",
                                        "skipstone", "amaya", "phoenix", "elinks");
         local b_length = length(browsers);

         for (i = 0; i < b_length; i++)
           {
             browser = car(nth_cdr(browsers,i));
             if (find_on_path(browser))
               {
                 system(string(browser, " ", url, " &"));
                 i = b_length;
               }
             else if(i == (b_length - 1))
               anygui_makemsg(string("\nSorry, your browser isn't supported. ",
                                 "Try installing one of these: \n",
                                 browsers, "\n\n",
                                 "Or modify the anyos_help() function, ",
                                 "line 60, in lib/linux.d\n",
                                 "and add your browser to the list.\n"));
           }
       }

### 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"));
       }

Prev | Home | Next
Sending Messages - `send_message`, `started_died_hook` | Up | Linux, QNX 4, or QNX 6 (in `lib/linux.g`, `lib/qnx4.g`, `lib/qnx6.g`)

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