1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright (c) 1997, by Sun Mircrosystems, Inc. 28*7c478bd9Sstevel@tonic-gate * All rights reserved. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.10 */ 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 36*7c478bd9Sstevel@tonic-gate #include "private.h" 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate int 39*7c478bd9Sstevel@tonic-gate menu_driver(MENU *m, int c) 40*7c478bd9Sstevel@tonic-gate { 41*7c478bd9Sstevel@tonic-gate int i, n; 42*7c478bd9Sstevel@tonic-gate int top; 43*7c478bd9Sstevel@tonic-gate ITEM *current; 44*7c478bd9Sstevel@tonic-gate int ret; 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate if (!m) { 47*7c478bd9Sstevel@tonic-gate return (E_BAD_ARGUMENT); 48*7c478bd9Sstevel@tonic-gate } 49*7c478bd9Sstevel@tonic-gate ret = E_OK; 50*7c478bd9Sstevel@tonic-gate if (Indriver(m)) { 51*7c478bd9Sstevel@tonic-gate return (E_BAD_STATE); 52*7c478bd9Sstevel@tonic-gate } 53*7c478bd9Sstevel@tonic-gate if (!Posted(m)) { 54*7c478bd9Sstevel@tonic-gate return (E_NOT_POSTED); 55*7c478bd9Sstevel@tonic-gate } 56*7c478bd9Sstevel@tonic-gate top = Top(m); 57*7c478bd9Sstevel@tonic-gate current = Current(m); 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate if (c > KEY_MAX && c < MAX_COMMAND) { 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* Clear the pattern buffer if not one of these requests */ 62*7c478bd9Sstevel@tonic-gate if (c != REQ_BACK_PATTERN && 63*7c478bd9Sstevel@tonic-gate c != REQ_NEXT_MATCH && 64*7c478bd9Sstevel@tonic-gate c != REQ_PREV_MATCH) { 65*7c478bd9Sstevel@tonic-gate Pindex(m) = 0; 66*7c478bd9Sstevel@tonic-gate IthPattern(m, 0) = '\0'; 67*7c478bd9Sstevel@tonic-gate } 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate switch (c) { 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate case REQ_RIGHT_ITEM: { 72*7c478bd9Sstevel@tonic-gate if (Right(current) == (ITEM *)0) { 73*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 74*7c478bd9Sstevel@tonic-gate break; 75*7c478bd9Sstevel@tonic-gate } 76*7c478bd9Sstevel@tonic-gate current = Right(current); 77*7c478bd9Sstevel@tonic-gate break; 78*7c478bd9Sstevel@tonic-gate } 79*7c478bd9Sstevel@tonic-gate case REQ_LEFT_ITEM: { 80*7c478bd9Sstevel@tonic-gate if (Left(current) == (ITEM *)0) { 81*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 82*7c478bd9Sstevel@tonic-gate break; 83*7c478bd9Sstevel@tonic-gate } 84*7c478bd9Sstevel@tonic-gate current = Left(current); 85*7c478bd9Sstevel@tonic-gate break; 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate case REQ_UP_ITEM: { 88*7c478bd9Sstevel@tonic-gate if (Up(current) == (ITEM *)0) { 89*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 90*7c478bd9Sstevel@tonic-gate break; 91*7c478bd9Sstevel@tonic-gate } 92*7c478bd9Sstevel@tonic-gate current = Up(current); 93*7c478bd9Sstevel@tonic-gate break; 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate case REQ_DOWN_ITEM: { 96*7c478bd9Sstevel@tonic-gate if (Down(current) == (ITEM *)0) { 97*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 98*7c478bd9Sstevel@tonic-gate break; 99*7c478bd9Sstevel@tonic-gate } 100*7c478bd9Sstevel@tonic-gate current = Down(current); 101*7c478bd9Sstevel@tonic-gate break; 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate case REQ_SCR_ULINE: { 104*7c478bd9Sstevel@tonic-gate if (--top < 0) { 105*7c478bd9Sstevel@tonic-gate ++top; 106*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 107*7c478bd9Sstevel@tonic-gate break; 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate current = Up(current); 110*7c478bd9Sstevel@tonic-gate break; 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate case REQ_SCR_DLINE: { 113*7c478bd9Sstevel@tonic-gate if (++top > Rows(m) - Height(m)) { 114*7c478bd9Sstevel@tonic-gate --top; 115*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 116*7c478bd9Sstevel@tonic-gate break; 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate current = Down(current); 119*7c478bd9Sstevel@tonic-gate break; 120*7c478bd9Sstevel@tonic-gate } 121*7c478bd9Sstevel@tonic-gate case REQ_SCR_UPAGE: { 122*7c478bd9Sstevel@tonic-gate n = min(Height(m), top); 123*7c478bd9Sstevel@tonic-gate if (n) { 124*7c478bd9Sstevel@tonic-gate top -= n; 125*7c478bd9Sstevel@tonic-gate for (i = n; i--; ) { 126*7c478bd9Sstevel@tonic-gate current = Up(current); 127*7c478bd9Sstevel@tonic-gate } 128*7c478bd9Sstevel@tonic-gate } else { 129*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 130*7c478bd9Sstevel@tonic-gate break; 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate break; 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate case REQ_SCR_DPAGE: { 135*7c478bd9Sstevel@tonic-gate n = min(Height(m), Rows(m) - Height(m) - top); 136*7c478bd9Sstevel@tonic-gate if (n) { 137*7c478bd9Sstevel@tonic-gate top += n; 138*7c478bd9Sstevel@tonic-gate for (i = n; i--; ) { 139*7c478bd9Sstevel@tonic-gate current = Down(current); 140*7c478bd9Sstevel@tonic-gate } 141*7c478bd9Sstevel@tonic-gate } else { 142*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 143*7c478bd9Sstevel@tonic-gate break; 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate break; 146*7c478bd9Sstevel@tonic-gate } 147*7c478bd9Sstevel@tonic-gate case REQ_FIRST_ITEM: { 148*7c478bd9Sstevel@tonic-gate current = IthItem(m, 0); 149*7c478bd9Sstevel@tonic-gate break; 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate case REQ_LAST_ITEM: { 152*7c478bd9Sstevel@tonic-gate current = IthItem(m, Nitems(m)-1); 153*7c478bd9Sstevel@tonic-gate break; 154*7c478bd9Sstevel@tonic-gate } 155*7c478bd9Sstevel@tonic-gate case REQ_NEXT_MATCH: { 156*7c478bd9Sstevel@tonic-gate if (IthPattern(m, 0) != NULL) { 157*7c478bd9Sstevel@tonic-gate ret = _match(m, NULL, ¤t); 158*7c478bd9Sstevel@tonic-gate } else { 159*7c478bd9Sstevel@tonic-gate if (Index(current)+1 >= Nitems(m)) { 160*7c478bd9Sstevel@tonic-gate current = IthItem(m, 0); 161*7c478bd9Sstevel@tonic-gate } else { 162*7c478bd9Sstevel@tonic-gate current = IthItem(m, Index(current)+1); 163*7c478bd9Sstevel@tonic-gate } 164*7c478bd9Sstevel@tonic-gate } 165*7c478bd9Sstevel@tonic-gate break; 166*7c478bd9Sstevel@tonic-gate } 167*7c478bd9Sstevel@tonic-gate case REQ_NEXT_ITEM: { 168*7c478bd9Sstevel@tonic-gate if (Index(current)+1 >= Nitems(m)) { 169*7c478bd9Sstevel@tonic-gate if (Cyclic(m)) { 170*7c478bd9Sstevel@tonic-gate current = IthItem(m, 0); 171*7c478bd9Sstevel@tonic-gate } else { 172*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate } else { 175*7c478bd9Sstevel@tonic-gate current = IthItem(m, Index(current)+1); 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate break; 178*7c478bd9Sstevel@tonic-gate } 179*7c478bd9Sstevel@tonic-gate case REQ_PREV_MATCH: { 180*7c478bd9Sstevel@tonic-gate if (IthPattern(m, 0) != NULL) { 181*7c478bd9Sstevel@tonic-gate ret = _match(m, '\b', ¤t); 182*7c478bd9Sstevel@tonic-gate } else { 183*7c478bd9Sstevel@tonic-gate /* This differs from PREV_ITEM in that */ 184*7c478bd9Sstevel@tonic-gate /* it is cyclic */ 185*7c478bd9Sstevel@tonic-gate if (Index(current)-1 < 0) { 186*7c478bd9Sstevel@tonic-gate current = IthItem(m, Nitems(m)-1); 187*7c478bd9Sstevel@tonic-gate } else { 188*7c478bd9Sstevel@tonic-gate current = IthItem(m, Index(current)-1); 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate } 191*7c478bd9Sstevel@tonic-gate break; 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate case REQ_PREV_ITEM: { 194*7c478bd9Sstevel@tonic-gate if (Index(current)-1 < 0) { 195*7c478bd9Sstevel@tonic-gate if (Cyclic(m)) { 196*7c478bd9Sstevel@tonic-gate current = IthItem(m, Nitems(m)-1); 197*7c478bd9Sstevel@tonic-gate } else { 198*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate } else { 201*7c478bd9Sstevel@tonic-gate current = IthItem(m, Index(current)-1); 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate break; 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate case REQ_TOGGLE_ITEM: { 206*7c478bd9Sstevel@tonic-gate if (!OneValue(m)) { 207*7c478bd9Sstevel@tonic-gate if (Selectable(Current(m))) { 208*7c478bd9Sstevel@tonic-gate Value(Current(m)) ^= TRUE; 209*7c478bd9Sstevel@tonic-gate _move_post_item(m, Current(m)); 210*7c478bd9Sstevel@tonic-gate _show(m); 211*7c478bd9Sstevel@tonic-gate } else { 212*7c478bd9Sstevel@tonic-gate ret = E_NOT_SELECTABLE; 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate } else { 215*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 216*7c478bd9Sstevel@tonic-gate } 217*7c478bd9Sstevel@tonic-gate break; 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate case REQ_BACK_PATTERN: { 220*7c478bd9Sstevel@tonic-gate if (Pindex(m) > 0) { 221*7c478bd9Sstevel@tonic-gate Pindex(m) -= 1; 222*7c478bd9Sstevel@tonic-gate IthPattern(m, Pindex(m)) = '\0'; 223*7c478bd9Sstevel@tonic-gate _position_cursor(m); 224*7c478bd9Sstevel@tonic-gate } else { 225*7c478bd9Sstevel@tonic-gate ret = E_REQUEST_DENIED; 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate break; 228*7c478bd9Sstevel@tonic-gate } 229*7c478bd9Sstevel@tonic-gate case REQ_CLEAR_PATTERN: { 230*7c478bd9Sstevel@tonic-gate /* This was already done at the top */ 231*7c478bd9Sstevel@tonic-gate break; 232*7c478bd9Sstevel@tonic-gate } 233*7c478bd9Sstevel@tonic-gate default: { 234*7c478bd9Sstevel@tonic-gate ret = E_UNKNOWN_COMMAND; 235*7c478bd9Sstevel@tonic-gate } 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate } else { 238*7c478bd9Sstevel@tonic-gate if (c > 037 && c < 0177) { 239*7c478bd9Sstevel@tonic-gate /*LINTED [E_PASS_INT_TO_SMALL_INT]*/ 240*7c478bd9Sstevel@tonic-gate ret = _match(m, c, ¤t); 241*7c478bd9Sstevel@tonic-gate } else { 242*7c478bd9Sstevel@tonic-gate ret = E_UNKNOWN_COMMAND; 243*7c478bd9Sstevel@tonic-gate } 244*7c478bd9Sstevel@tonic-gate } 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate /* Verify the location of the top row */ 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate _chk_top(m, &top, current); 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate /* Go change the actual values of Top and Current and do init/term */ 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate _affect_change(m, top, current); 253*7c478bd9Sstevel@tonic-gate 254*7c478bd9Sstevel@tonic-gate return (ret); 255*7c478bd9Sstevel@tonic-gate } 256