classify/sigmenu.cpp File Reference

#include "sigmenu.h"
#include "oldlist.h"
#include "emalloc.h"
#include "secname.h"
#include <signal.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Classes

Defines

Functions

Variables


Define Documentation

#define MAX_COMMAND_LENGTH   128

Note:
File: sigmenu.cpp
General purpose, menu-oriented signal handling routines
Author:
Dan Johnson
Date:
Mon Oct 2 07:25:50 1989, DSJ, Created.
 **	(c) Copyright Hewlett-Packard Company, 1988.
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 ** http://www.apache.org/licenses/LICENSE-2.0
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.

Definition at line 31 of file sigmenu.cpp.

Referenced by MainSignalHandler().


Function Documentation

void AddSignalMenuItem ( int  Signal,
int  ItemNum,
const char  ItemLabel[],
int_void  ItemFunc 
)

Add a new menu item to the list of menu items for Signal; not functional in current state.

Parameters:
Signal Signal to be trapped for this menu
ItemNum Menu number for this item
ItemLabel Menu label for this item
ItemFunc Function to be called when item is selected
Note:
Globals: SignalMenus list of menu items for each possible signal
Returns:
none
Whenever Signal is encountered, the user will be given a list of options to choose from. This list is the list of all of the menu items that have been specified for that Signal.
Note:
Exceptions: none
Date:
Mon Oct 2 07:42:19 1989, DSJ, Created.

Definition at line 82 of file sigmenu.cpp.

References cprintf(), ItemCompare(), MainSignalHandler(), NewSignalMenuItem(), NIL, s_adjoin(), and SignalMenus.

Referenced by init_dj_debug(), and init_ms_debug().

00083                                                         {
00084   #if 0
00085   #ifndef SECURE_NAMES
00086   SIG_MENU_ITEM *NewItem;
00087 
00088   /* check for a valid Signal */
00089   if (Signal >= NSIG || Signal <= 0) {
00090     cprintf ("Illegal signal (%d) specified for menu item!\n", Signal);
00091     return;
00092   }
00093 
00094   /* if this is the first item for this signal, indicate that the
00095      appropriate signal handler has been enabled */
00096   if (SignalMenus[Signal] == NIL)
00097     cprintf ("Signal handler enabled for signal %d.\n", Signal);
00098 
00099   /* add the new menu item to the appropriate list of menu items */
00100   NewItem = NewSignalMenuItem (ItemNum, ItemLabel, ItemFunc);
00101   SignalMenus[Signal] = s_adjoin (SignalMenus[Signal], NewItem, ItemCompare);
00102 
00103   /* set up the trap for the appropriate signal */
00104   signal(Signal, MainSignalHandler); 
00105   #endif
00106   #endif
00107 }                                /* AddSignalMenuItem */

int ItemCompare ( void *  arg1,
void *  arg2 
)

Compare ItemNum of Item1 with that of Item 2.

Parameters:
arg1 First menu item to be compared
arg2 Second menu item to be compared
Returns:
-1, 0, or 1
Return -1 if the ItemNum of Item1 is less than the ItemNum of Item2. Return 0 if they are equal. Return +1 if the ItemNum of Item1 is greater than the ItemNum of Item2.

This routine is used by the list sorter to sort lists of menu items according to their item number.

Note:
Exceptions: none
Date:
Mon Oct 2 08:11:59 1989, DSJ, Created.

Definition at line 219 of file sigmenu.cpp.

References SIG_MENU_ITEM::ItemNum.

Referenced by AddSignalMenuItem().

00220                             {  //SIG_MENU_ITEM         *Item2)
00221   SIG_MENU_ITEM *Item1 = (SIG_MENU_ITEM *) arg1;
00222   SIG_MENU_ITEM *Item2 = (SIG_MENU_ITEM *) arg2;
00223 
00224   if (Item1->ItemNum < Item2->ItemNum)
00225     return (-1);
00226   else if (Item1->ItemNum == Item2->ItemNum)
00227     return (0);
00228   else if (Item1->ItemNum > Item2->ItemNum)
00229     return (1);
00230   else
00231     return 0;
00232 }                                /* ItemCompare */

void MainSignalHandler ( int  Signal  ) 

Provide the user with a menu of actions for the trapped signal & Execute the appropriate function.

Parameters:
Signal Signal that caused this function to be called
Note:
Globals: SignalMenus List of menu items for each possible signal
Returns:
none
If the function returns SIG_RESUME, then terminate the signal handler and resume normal processing. If the function does not return SIG_RESUME, remain in the main signal handler menu.
Note:
Exceptions: none
Date:
Mon Oct 2 08:18:52 1989, DSJ, Created.

Definition at line 128 of file sigmenu.cpp.

References cprintf(), first, SIG_MENU_ITEM::ItemFunc, SIG_MENU_ITEM::ItemLabel, SIG_MENU_ITEM::ItemNum, iterate, MAX_COMMAND_LENGTH, NIL, NULL, SIG_RESUME, SignalMenus, and TRUE.

Referenced by AddSignalMenuItem().

00128                                    { 
00129   #ifndef SECURE_NAMES
00130   int Command;
00131   char CommandLine[MAX_COMMAND_LENGTH];
00132   char *Params;
00133   LIST Items;
00134   SIG_MENU_ITEM *MenuItem;
00135 
00136   while (TRUE) {
00137     Command = -1;
00138     cprintf ("\nMAIN SIGNAL HANDLER FOR SIGNAL %d\n", Signal);
00139     cprintf ("0. Resume normal operation\n");
00140 
00141     Items = SignalMenus[Signal];
00142     iterate(Items) { 
00143       MenuItem = (SIG_MENU_ITEM *) first (Items);
00144       cprintf ("%d. %s\n", MenuItem->ItemNum, MenuItem->ItemLabel);
00145     }
00146     cprintf ("\nEnter Selection: ");
00147 
00148     while (fgets (CommandLine, MAX_COMMAND_LENGTH, stdin) == NULL
00149       || strlen (CommandLine) <= 0);
00150 
00151     Command = strtol (CommandLine, &Params, 10);
00152     if (CommandLine == Params) {
00153       cprintf ("\nIllegal command! - Try again.\n");
00154       continue;
00155     }
00156 
00157     if (Command == 0)
00158       signal(Signal, MainSignalHandler); 
00159 
00160     Items = SignalMenus[Signal];
00161     iterate(Items) { 
00162       MenuItem = (SIG_MENU_ITEM *) first (Items);
00163       if (Command == MenuItem->ItemNum) {
00164         if ((*MenuItem->ItemFunc) ( /*Params */ ) == SIG_RESUME)
00165           signal(Signal, MainSignalHandler); 
00166         break;
00167       }
00168     }
00169     if (Items == NIL)
00170       cprintf ("\nIllegal command! - Try again.\n");
00171   }
00172   #endif
00173 }                                /* MainSignalHandler */

SIG_MENU_ITEM * NewSignalMenuItem ( int  ItemNum,
const char  ItemLabel[],
int_void  ItemFunc 
)

Allocate, initialize, and return a new signal menu item.

Parameters:
ItemNum Menu number for this item
ItemLabel Menu label for this item
ItemFunc Function to be called when item is selected
Returns:
Ptr to new signal menu item data structure.
Note:
Exceptions: none
Date:
Mon Oct 2 08:04:20 1989, DSJ, Created.

Definition at line 188 of file sigmenu.cpp.

References Emalloc(), SIG_MENU_ITEM::ItemFunc, SIG_MENU_ITEM::ItemLabel, and SIG_MENU_ITEM::ItemNum.

Referenced by AddSignalMenuItem().

00188                                                                            {
00189   SIG_MENU_ITEM *NewItem;
00190 
00191   NewItem = (SIG_MENU_ITEM *) Emalloc (sizeof (SIG_MENU_ITEM));
00192   NewItem->ItemNum = ItemNum;
00193   NewItem->ItemFunc = ItemFunc;
00194   NewItem->ItemLabel = (char *) Emalloc (strlen (ItemLabel) + 1);
00195   strcpy (NewItem->ItemLabel, ItemLabel);
00196   return (NewItem);
00197 
00198 }                                /* NewSignalMenuItem */


Variable Documentation

LIST SignalMenus[NSIG] [static]

Definition at line 47 of file sigmenu.cpp.

Referenced by AddSignalMenuItem(), and MainSignalHandler().


Generated on Wed Feb 28 19:49:21 2007 for Tesseract by  doxygen 1.5.1