#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.
#define MAX_COMMAND_LENGTH 128 |
** (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().
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.
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 |
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.
arg1 | First menu item to be compared | |
arg2 | Second menu item to be compared |
This routine is used by the list sorter to sort lists of menu items according to their item number.
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.
Signal | Signal that caused this function to be called |
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.
ItemNum | Menu number for this item | |
ItemLabel | Menu label for this item | |
ItemFunc | Function to be called when item is selected |
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 */
LIST SignalMenus[NSIG] [static] |
Definition at line 47 of file sigmenu.cpp.
Referenced by AddSignalMenuItem(), and MainSignalHandler().