17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*23a1cceaSRoger A. Faulkner * Common Development and Distribution License (the "License").
6*23a1cceaSRoger A. Faulkner * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate
227c478bd9Sstevel@tonic-gate /*
23*23a1cceaSRoger A. Faulkner * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
26*23a1cceaSRoger A. Faulkner /* Copyright (c) 1988 AT&T */
27*23a1cceaSRoger A. Faulkner /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate * cscope - interactive C symbol or text cross-reference
317c478bd9Sstevel@tonic-gate *
327c478bd9Sstevel@tonic-gate * command functions
337c478bd9Sstevel@tonic-gate */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include <curses.h> /* KEY_.* */
367c478bd9Sstevel@tonic-gate #include <fcntl.h> /* O_RDONLY */
377c478bd9Sstevel@tonic-gate #include <unistd.h>
387c478bd9Sstevel@tonic-gate #include <stdio.h>
397c478bd9Sstevel@tonic-gate #include "global.h"
407c478bd9Sstevel@tonic-gate #include "library.h"
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate BOOL caseless; /* ignore letter case when searching */
437c478bd9Sstevel@tonic-gate BOOL *change; /* change this line */
447c478bd9Sstevel@tonic-gate BOOL changing; /* changing text */
457c478bd9Sstevel@tonic-gate char newpat[PATLEN + 1]; /* new pattern */
467c478bd9Sstevel@tonic-gate char pattern[PATLEN + 1]; /* symbol or text pattern */
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate static char appendprompt[] = "Append to file: ";
497c478bd9Sstevel@tonic-gate static char pipeprompt[] = "Pipe to shell command: ";
507c478bd9Sstevel@tonic-gate static char readprompt[] = "Read from file: ";
517c478bd9Sstevel@tonic-gate static char selectionprompt[] = "Selection: ";
527c478bd9Sstevel@tonic-gate static char toprompt[] = "To: ";
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate static void scrollbar(MOUSEEVENT *p);
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate /* execute the command */
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate BOOL
command(int commandc)597c478bd9Sstevel@tonic-gate command(int commandc)
607c478bd9Sstevel@tonic-gate {
617c478bd9Sstevel@tonic-gate char filename[PATHLEN + 1]; /* file path name */
627c478bd9Sstevel@tonic-gate MOUSEEVENT *p; /* mouse data */
637c478bd9Sstevel@tonic-gate int c, i;
647c478bd9Sstevel@tonic-gate FILE *file;
657c478bd9Sstevel@tonic-gate HISTORY *curritem, *item; /* command history */
667c478bd9Sstevel@tonic-gate char *s;
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate switch (commandc) {
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate case ctrl('C'): /* toggle caseless mode */
717c478bd9Sstevel@tonic-gate if (caseless == NO) {
727c478bd9Sstevel@tonic-gate caseless = YES;
737c478bd9Sstevel@tonic-gate putmsg2("Caseless mode is now ON");
747c478bd9Sstevel@tonic-gate } else {
757c478bd9Sstevel@tonic-gate caseless = NO;
767c478bd9Sstevel@tonic-gate putmsg2("Caseless mode is now OFF");
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate egrepcaseless(caseless); /* turn on/off -i flag */
797c478bd9Sstevel@tonic-gate return (NO);
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate case ctrl('R'): /* rebuild the cross reference */
827c478bd9Sstevel@tonic-gate if (isuptodate == YES) {
837c478bd9Sstevel@tonic-gate putmsg("The -d option prevents rebuilding the "
847c478bd9Sstevel@tonic-gate "symbol database");
857c478bd9Sstevel@tonic-gate return (NO);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate exitcurses();
887c478bd9Sstevel@tonic-gate freefilelist(); /* remake the source file list */
897c478bd9Sstevel@tonic-gate makefilelist();
907c478bd9Sstevel@tonic-gate rebuild();
917c478bd9Sstevel@tonic-gate if (errorsfound == YES) {
927c478bd9Sstevel@tonic-gate errorsfound = NO;
937c478bd9Sstevel@tonic-gate askforreturn();
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate entercurses();
967c478bd9Sstevel@tonic-gate putmsg(""); /* clear any previous message */
977c478bd9Sstevel@tonic-gate totallines = 0;
987c478bd9Sstevel@tonic-gate topline = nextline = 1;
997c478bd9Sstevel@tonic-gate break;
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate case ctrl('X'): /* mouse selection */
1027c478bd9Sstevel@tonic-gate if ((p = getmouseevent()) == NULL) {
1037c478bd9Sstevel@tonic-gate return (NO); /* unknown control sequence */
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate /* if the button number is a scrollbar tag */
1067c478bd9Sstevel@tonic-gate if (p->button == '0') {
1077c478bd9Sstevel@tonic-gate scrollbar(p);
1087c478bd9Sstevel@tonic-gate break;
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate /* ignore a sweep */
1117c478bd9Sstevel@tonic-gate if (p->x2 >= 0) {
1127c478bd9Sstevel@tonic-gate return (NO);
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate /* if this is a line selection */
1157c478bd9Sstevel@tonic-gate if (p->y1 < FLDLINE) {
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate /* find the selected line */
1187c478bd9Sstevel@tonic-gate /* note: the selection is forced into range */
1197c478bd9Sstevel@tonic-gate for (i = disprefs - 1; i > 0; --i) {
1207c478bd9Sstevel@tonic-gate if (p->y1 >= displine[i]) {
1217c478bd9Sstevel@tonic-gate break;
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate /* display it in the file with the editor */
1257c478bd9Sstevel@tonic-gate editref(i);
1267c478bd9Sstevel@tonic-gate } else { /* this is an input field selection */
1277c478bd9Sstevel@tonic-gate field = mouseselection(p, FLDLINE, FIELDS);
1287c478bd9Sstevel@tonic-gate setfield();
1297c478bd9Sstevel@tonic-gate resetcmd();
1307c478bd9Sstevel@tonic-gate return (NO);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate break;
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate case '\t': /* go to next input field */
1357c478bd9Sstevel@tonic-gate case '\n':
1367c478bd9Sstevel@tonic-gate case '\r':
1377c478bd9Sstevel@tonic-gate case ctrl('N'):
1387c478bd9Sstevel@tonic-gate case KEY_DOWN:
1397c478bd9Sstevel@tonic-gate case KEY_ENTER:
1407c478bd9Sstevel@tonic-gate case KEY_RIGHT:
1417c478bd9Sstevel@tonic-gate field = (field + 1) % FIELDS;
1427c478bd9Sstevel@tonic-gate setfield();
1437c478bd9Sstevel@tonic-gate resetcmd();
1447c478bd9Sstevel@tonic-gate return (NO);
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate case ctrl('P'): /* go to previous input field */
1477c478bd9Sstevel@tonic-gate case KEY_UP:
1487c478bd9Sstevel@tonic-gate case KEY_LEFT:
1497c478bd9Sstevel@tonic-gate field = (field + (FIELDS - 1)) % FIELDS;
1507c478bd9Sstevel@tonic-gate setfield();
1517c478bd9Sstevel@tonic-gate resetcmd();
1527c478bd9Sstevel@tonic-gate return (NO);
1537c478bd9Sstevel@tonic-gate case KEY_HOME: /* go to first input field */
1547c478bd9Sstevel@tonic-gate field = 0;
1557c478bd9Sstevel@tonic-gate setfield();
1567c478bd9Sstevel@tonic-gate resetcmd();
1577c478bd9Sstevel@tonic-gate return (NO);
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate case KEY_LL: /* go to last input field */
1607c478bd9Sstevel@tonic-gate field = FIELDS - 1;
1617c478bd9Sstevel@tonic-gate setfield();
1627c478bd9Sstevel@tonic-gate resetcmd();
1637c478bd9Sstevel@tonic-gate return (NO);
1647c478bd9Sstevel@tonic-gate case ' ': /* display next page */
1657c478bd9Sstevel@tonic-gate case '+':
1667c478bd9Sstevel@tonic-gate case ctrl('V'):
1677c478bd9Sstevel@tonic-gate case KEY_NPAGE:
1687c478bd9Sstevel@tonic-gate /* don't redisplay if there are no lines */
1697c478bd9Sstevel@tonic-gate if (totallines == 0) {
1707c478bd9Sstevel@tonic-gate return (NO);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate * note: seekline() is not used to move to the next
1747c478bd9Sstevel@tonic-gate * page because display() leaves the file pointer at
1757c478bd9Sstevel@tonic-gate * the next page to optimize paging forward
1767c478bd9Sstevel@tonic-gate */
1777c478bd9Sstevel@tonic-gate break;
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate case '-': /* display previous page */
1807c478bd9Sstevel@tonic-gate case KEY_PPAGE:
1817c478bd9Sstevel@tonic-gate /* don't redisplay if there are no lines */
1827c478bd9Sstevel@tonic-gate if (totallines == 0) {
1837c478bd9Sstevel@tonic-gate return (NO);
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate i = topline; /* save the current top line */
1867c478bd9Sstevel@tonic-gate nextline = topline; /* go back to this page */
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate /* if on first page but not at beginning, go to beginning */
1897c478bd9Sstevel@tonic-gate if (nextline > 1 && nextline <= mdisprefs) {
1907c478bd9Sstevel@tonic-gate nextline = 1;
1917c478bd9Sstevel@tonic-gate } else { /* go back the maximum displayable lines */
1927c478bd9Sstevel@tonic-gate nextline -= mdisprefs;
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate /* if this was the first page, go to the last page */
1957c478bd9Sstevel@tonic-gate if (nextline < 1) {
1967c478bd9Sstevel@tonic-gate nextline = totallines - mdisprefs + 1;
1977c478bd9Sstevel@tonic-gate if (nextline < 1) {
1987c478bd9Sstevel@tonic-gate nextline = 1;
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate /* old top is past last line */
2017c478bd9Sstevel@tonic-gate i = totallines + 1;
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate * move down til the bottom line is just before the
2067c478bd9Sstevel@tonic-gate * previous top line
2077c478bd9Sstevel@tonic-gate */
2087c478bd9Sstevel@tonic-gate c = nextline;
2097c478bd9Sstevel@tonic-gate for (;;) {
2107c478bd9Sstevel@tonic-gate seekline(nextline);
2117c478bd9Sstevel@tonic-gate display();
2127c478bd9Sstevel@tonic-gate if (i - bottomline <= 0) {
2137c478bd9Sstevel@tonic-gate break;
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate nextline = ++c;
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate return (NO); /* display already up to date */
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate case '>': /* write or append the lines to a file */
2207c478bd9Sstevel@tonic-gate if (totallines == 0) {
2217c478bd9Sstevel@tonic-gate putmsg("There are no lines to write to a file");
2227c478bd9Sstevel@tonic-gate } else { /* get the file name */
2237c478bd9Sstevel@tonic-gate (void) move(PRLINE, 0);
2247c478bd9Sstevel@tonic-gate (void) addstr("Write to file: ");
2257c478bd9Sstevel@tonic-gate s = "w";
2267c478bd9Sstevel@tonic-gate if ((c = mygetch()) == '>') {
2277c478bd9Sstevel@tonic-gate (void) move(PRLINE, 0);
2287c478bd9Sstevel@tonic-gate (void) addstr(appendprompt);
2297c478bd9Sstevel@tonic-gate c = '\0';
2307c478bd9Sstevel@tonic-gate s = "a";
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate if (c != '\r' && c != '\n' && c != KEY_ENTER &&
2337c478bd9Sstevel@tonic-gate c != KEY_BREAK &&
234*23a1cceaSRoger A. Faulkner getaline(newpat, COLS - sizeof (appendprompt), c,
2357c478bd9Sstevel@tonic-gate NO) > 0) {
2367c478bd9Sstevel@tonic-gate shellpath(filename, sizeof (filename), newpat);
2377c478bd9Sstevel@tonic-gate if ((file = fopen(filename, s)) == NULL) {
2387c478bd9Sstevel@tonic-gate cannotopen(filename);
2397c478bd9Sstevel@tonic-gate } else {
2407c478bd9Sstevel@tonic-gate seekline(1);
2417c478bd9Sstevel@tonic-gate while ((c = getc(refsfound)) != EOF) {
2427c478bd9Sstevel@tonic-gate (void) putc(c, file);
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate seekline(topline);
2457c478bd9Sstevel@tonic-gate (void) fclose(file);
2467c478bd9Sstevel@tonic-gate }
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate clearprompt();
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate return (NO); /* return to the previous field */
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate case '<': /* read lines from a file */
2537c478bd9Sstevel@tonic-gate (void) move(PRLINE, 0);
2547c478bd9Sstevel@tonic-gate (void) addstr(readprompt);
255*23a1cceaSRoger A. Faulkner if (getaline(newpat, COLS - sizeof (readprompt), '\0',
2567c478bd9Sstevel@tonic-gate NO) > 0) {
2577c478bd9Sstevel@tonic-gate clearprompt();
2587c478bd9Sstevel@tonic-gate shellpath(filename, sizeof (filename), newpat);
2597c478bd9Sstevel@tonic-gate if (readrefs(filename) == NO) {
2607c478bd9Sstevel@tonic-gate putmsg2("Ignoring an empty file");
2617c478bd9Sstevel@tonic-gate return (NO);
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate return (YES);
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate clearprompt();
2667c478bd9Sstevel@tonic-gate return (NO);
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate case '^': /* pipe the lines through a shell command */
2697c478bd9Sstevel@tonic-gate case '|': /* pipe the lines to a shell command */
2707c478bd9Sstevel@tonic-gate if (totallines == 0) {
2717c478bd9Sstevel@tonic-gate putmsg("There are no lines to pipe to a shell command");
2727c478bd9Sstevel@tonic-gate return (NO);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate /* get the shell command */
2757c478bd9Sstevel@tonic-gate (void) move(PRLINE, 0);
2767c478bd9Sstevel@tonic-gate (void) addstr(pipeprompt);
277*23a1cceaSRoger A. Faulkner if (getaline(newpat,
2787c478bd9Sstevel@tonic-gate COLS - sizeof (pipeprompt), '\0', NO) == 0) {
2797c478bd9Sstevel@tonic-gate clearprompt();
2807c478bd9Sstevel@tonic-gate return (NO);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate /* if the ^ command, redirect output to a temp file */
2837c478bd9Sstevel@tonic-gate if (commandc == '^') {
2847c478bd9Sstevel@tonic-gate (void) strcat(strcat(newpat, " >"), temp2);
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate exitcurses();
2877c478bd9Sstevel@tonic-gate if ((file = mypopen(newpat, "w")) == NULL) {
2887c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2897c478bd9Sstevel@tonic-gate "cscope: cannot open pipe to shell command: %s\n",
2907c478bd9Sstevel@tonic-gate newpat);
2917c478bd9Sstevel@tonic-gate } else {
2927c478bd9Sstevel@tonic-gate seekline(1);
2937c478bd9Sstevel@tonic-gate while ((c = getc(refsfound)) != EOF) {
2947c478bd9Sstevel@tonic-gate (void) putc(c, file);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate seekline(topline);
2977c478bd9Sstevel@tonic-gate (void) mypclose(file);
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate if (commandc == '^') {
3007c478bd9Sstevel@tonic-gate if (readrefs(temp2) == NO) {
3017c478bd9Sstevel@tonic-gate putmsg("Ignoring empty output of ^ command");
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate askforreturn();
3057c478bd9Sstevel@tonic-gate entercurses();
3067c478bd9Sstevel@tonic-gate break;
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate case ctrl('L'): /* redraw screen */
3097c478bd9Sstevel@tonic-gate case KEY_CLEAR:
3107c478bd9Sstevel@tonic-gate (void) clearok(curscr, TRUE);
3117c478bd9Sstevel@tonic-gate (void) wrefresh(curscr);
3127c478bd9Sstevel@tonic-gate drawscrollbar(topline, bottomline, totallines);
3137c478bd9Sstevel@tonic-gate return (NO);
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate case '!': /* shell escape */
3167c478bd9Sstevel@tonic-gate (void) execute(shell, shell, (char *)NULL);
3177c478bd9Sstevel@tonic-gate seekline(topline);
3187c478bd9Sstevel@tonic-gate break;
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate case '?': /* help */
3217c478bd9Sstevel@tonic-gate (void) clear();
3227c478bd9Sstevel@tonic-gate help();
3237c478bd9Sstevel@tonic-gate (void) clear();
3247c478bd9Sstevel@tonic-gate seekline(topline);
3257c478bd9Sstevel@tonic-gate break;
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate case ctrl('E'): /* edit all lines */
3287c478bd9Sstevel@tonic-gate editall();
3297c478bd9Sstevel@tonic-gate break;
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate case ctrl('A'): /* repeat last pattern */
3327c478bd9Sstevel@tonic-gate case ctrl('Y'): /* (old command) */
3337c478bd9Sstevel@tonic-gate if (*pattern != '\0') {
3347c478bd9Sstevel@tonic-gate (void) addstr(pattern);
3357c478bd9Sstevel@tonic-gate goto repeat;
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate break;
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate case ctrl('B'): /* cmd history back */
3407c478bd9Sstevel@tonic-gate case ctrl('F'): /* cmd history fwd */
3417c478bd9Sstevel@tonic-gate curritem = currentcmd();
3427c478bd9Sstevel@tonic-gate item = (commandc == ctrl('F')) ? nextcmd() : prevcmd();
3437c478bd9Sstevel@tonic-gate clearmsg2();
3447c478bd9Sstevel@tonic-gate if (curritem == item) {
3457c478bd9Sstevel@tonic-gate /* inform user that we're at history end */
3467c478bd9Sstevel@tonic-gate putmsg2(
3477c478bd9Sstevel@tonic-gate "End of input field and search pattern history");
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate if (item) {
3507c478bd9Sstevel@tonic-gate field = item->field;
3517c478bd9Sstevel@tonic-gate setfield();
3527c478bd9Sstevel@tonic-gate atfield();
3537c478bd9Sstevel@tonic-gate (void) addstr(item->text);
3547c478bd9Sstevel@tonic-gate (void) strcpy(pattern, item->text);
3557c478bd9Sstevel@tonic-gate switch (c = mygetch()) {
3567c478bd9Sstevel@tonic-gate case '\r':
3577c478bd9Sstevel@tonic-gate case '\n':
3587c478bd9Sstevel@tonic-gate case KEY_ENTER:
3597c478bd9Sstevel@tonic-gate goto repeat;
3607c478bd9Sstevel@tonic-gate default:
3617c478bd9Sstevel@tonic-gate ungetch(c);
3627c478bd9Sstevel@tonic-gate atfield();
3637c478bd9Sstevel@tonic-gate (void) clrtoeol(); /* clear current field */
3647c478bd9Sstevel@tonic-gate break;
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate return (NO);
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate case '\\': /* next character is not a command */
3707c478bd9Sstevel@tonic-gate (void) addch('\\'); /* display the quote character */
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate /* get a character from the terminal */
3737c478bd9Sstevel@tonic-gate if ((commandc = mygetch()) == EOF) {
3747c478bd9Sstevel@tonic-gate return (NO); /* quit */
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate (void) addstr("\b \b"); /* erase the quote character */
3777c478bd9Sstevel@tonic-gate goto ispat;
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate case '.':
3807c478bd9Sstevel@tonic-gate atfield(); /* move back to the input field */
3817c478bd9Sstevel@tonic-gate /* FALLTHROUGH */
3827c478bd9Sstevel@tonic-gate default:
3837c478bd9Sstevel@tonic-gate /* edit a selected line */
3847c478bd9Sstevel@tonic-gate if (isdigit(commandc) && commandc != '0' && !mouse) {
3857c478bd9Sstevel@tonic-gate if (returnrequired == NO) {
3867c478bd9Sstevel@tonic-gate editref(commandc - '1');
3877c478bd9Sstevel@tonic-gate } else {
3887c478bd9Sstevel@tonic-gate (void) move(PRLINE, 0);
3897c478bd9Sstevel@tonic-gate (void) addstr(selectionprompt);
390*23a1cceaSRoger A. Faulkner if (getaline(newpat,
3917c478bd9Sstevel@tonic-gate COLS - sizeof (selectionprompt), commandc,
3927c478bd9Sstevel@tonic-gate NO) > 0 &&
3937c478bd9Sstevel@tonic-gate (i = atoi(newpat)) > 0) {
3947c478bd9Sstevel@tonic-gate editref(i - 1);
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate clearprompt();
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate } else if (isprint(commandc)) {
3997c478bd9Sstevel@tonic-gate /* this is the start of a pattern */
4007c478bd9Sstevel@tonic-gate ispat:
401*23a1cceaSRoger A. Faulkner if (getaline(newpat, COLS - fldcolumn - 1, commandc,
4027c478bd9Sstevel@tonic-gate caseless) > 0) {
4037c478bd9Sstevel@tonic-gate (void) strcpy(pattern, newpat);
4047c478bd9Sstevel@tonic-gate resetcmd(); /* reset history */
4057c478bd9Sstevel@tonic-gate repeat:
4067c478bd9Sstevel@tonic-gate addcmd(field, pattern); /* add to history */
4077c478bd9Sstevel@tonic-gate if (field == CHANGE) {
4087c478bd9Sstevel@tonic-gate /* prompt for the new text */
4097c478bd9Sstevel@tonic-gate (void) move(PRLINE, 0);
4107c478bd9Sstevel@tonic-gate (void) addstr(toprompt);
411*23a1cceaSRoger A. Faulkner (void) getaline(newpat,
4127c478bd9Sstevel@tonic-gate COLS - sizeof (toprompt), '\0', NO);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate /* search for the pattern */
4157c478bd9Sstevel@tonic-gate if (search() == YES) {
4167c478bd9Sstevel@tonic-gate switch (field) {
4177c478bd9Sstevel@tonic-gate case DEFINITION:
4187c478bd9Sstevel@tonic-gate case FILENAME:
4197c478bd9Sstevel@tonic-gate if (totallines > 1) {
4207c478bd9Sstevel@tonic-gate break;
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate topline = 1;
4237c478bd9Sstevel@tonic-gate editref(0);
4247c478bd9Sstevel@tonic-gate break;
4257c478bd9Sstevel@tonic-gate case CHANGE:
4267c478bd9Sstevel@tonic-gate return (changestring());
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate } else if (field == FILENAME &&
4297c478bd9Sstevel@tonic-gate access(newpat, READ) == 0) {
4307c478bd9Sstevel@tonic-gate /* try to edit the file anyway */
4317c478bd9Sstevel@tonic-gate edit(newpat, "1");
4327c478bd9Sstevel@tonic-gate }
4337c478bd9Sstevel@tonic-gate } else { /* no pattern--the input was erased */
4347c478bd9Sstevel@tonic-gate return (NO);
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate } else { /* control character */
4377c478bd9Sstevel@tonic-gate return (NO);
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate return (YES);
4417c478bd9Sstevel@tonic-gate }
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate /* clear the prompt line */
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate void
clearprompt(void)4467c478bd9Sstevel@tonic-gate clearprompt(void)
4477c478bd9Sstevel@tonic-gate {
4487c478bd9Sstevel@tonic-gate (void) move(PRLINE, 0);
4497c478bd9Sstevel@tonic-gate (void) clrtoeol();
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate
4527c478bd9Sstevel@tonic-gate /* read references from a file */
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate BOOL
readrefs(char * filename)4557c478bd9Sstevel@tonic-gate readrefs(char *filename)
4567c478bd9Sstevel@tonic-gate {
4577c478bd9Sstevel@tonic-gate FILE *file;
4587c478bd9Sstevel@tonic-gate int c;
4597c478bd9Sstevel@tonic-gate
4607c478bd9Sstevel@tonic-gate if ((file = fopen(filename, "r")) == NULL) {
4617c478bd9Sstevel@tonic-gate cannotopen(filename);
4627c478bd9Sstevel@tonic-gate return (NO);
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate if ((c = getc(file)) == EOF) { /* if file is empty */
4657c478bd9Sstevel@tonic-gate return (NO);
4667c478bd9Sstevel@tonic-gate }
4677c478bd9Sstevel@tonic-gate totallines = 0;
4687c478bd9Sstevel@tonic-gate nextline = 1;
4697c478bd9Sstevel@tonic-gate if (writerefsfound() == YES) {
4707c478bd9Sstevel@tonic-gate (void) putc(c, refsfound);
4717c478bd9Sstevel@tonic-gate while ((c = getc(file)) != EOF) {
4727c478bd9Sstevel@tonic-gate (void) putc(c, refsfound);
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate (void) fclose(file);
4757c478bd9Sstevel@tonic-gate (void) freopen(temp1, "r", refsfound);
4767c478bd9Sstevel@tonic-gate countrefs();
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate return (YES);
4797c478bd9Sstevel@tonic-gate }
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate /* change one text string to another */
4827c478bd9Sstevel@tonic-gate
4837c478bd9Sstevel@tonic-gate BOOL
changestring(void)4847c478bd9Sstevel@tonic-gate changestring(void)
4857c478bd9Sstevel@tonic-gate {
4867c478bd9Sstevel@tonic-gate char buf[PATLEN + 1]; /* input buffer */
4877c478bd9Sstevel@tonic-gate char newfile[PATHLEN + 1]; /* new file name */
4887c478bd9Sstevel@tonic-gate char oldfile[PATHLEN + 1]; /* old file name */
4897c478bd9Sstevel@tonic-gate char linenum[NUMLEN + 1]; /* file line number */
4907c478bd9Sstevel@tonic-gate char msg[MSGLEN + 1]; /* message */
4917c478bd9Sstevel@tonic-gate FILE *script; /* shell script file */
4927c478bd9Sstevel@tonic-gate BOOL anymarked = NO; /* any line marked */
4937c478bd9Sstevel@tonic-gate MOUSEEVENT *p; /* mouse data */
4947c478bd9Sstevel@tonic-gate int c, i;
4957c478bd9Sstevel@tonic-gate char *s;
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate /* open the temporary file */
4987c478bd9Sstevel@tonic-gate if ((script = fopen(temp2, "w")) == NULL) {
4997c478bd9Sstevel@tonic-gate cannotopen(temp2);
5007c478bd9Sstevel@tonic-gate return (NO);
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate /* create the line change indicators */
5037c478bd9Sstevel@tonic-gate change = (BOOL *)mycalloc((unsigned)totallines, sizeof (BOOL));
5047c478bd9Sstevel@tonic-gate changing = YES;
5057c478bd9Sstevel@tonic-gate initmenu();
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate /* until the quit command is entered */
5087c478bd9Sstevel@tonic-gate for (;;) {
5097c478bd9Sstevel@tonic-gate /* display the current page of lines */
5107c478bd9Sstevel@tonic-gate display();
5117c478bd9Sstevel@tonic-gate same:
5127c478bd9Sstevel@tonic-gate /* get a character from the terminal */
5137c478bd9Sstevel@tonic-gate (void) move(PRLINE, 0);
5147c478bd9Sstevel@tonic-gate (void) addstr(
5157c478bd9Sstevel@tonic-gate "Select lines to change (press the ? key for help): ");
5167c478bd9Sstevel@tonic-gate if ((c = mygetch()) == EOF || c == ctrl('D') ||
5177c478bd9Sstevel@tonic-gate c == ctrl('Z')) {
5187c478bd9Sstevel@tonic-gate break; /* change lines */
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate /* see if the input character is a command */
5217c478bd9Sstevel@tonic-gate switch (c) {
5227c478bd9Sstevel@tonic-gate case ' ': /* display next page */
5237c478bd9Sstevel@tonic-gate case '+':
5247c478bd9Sstevel@tonic-gate case ctrl('V'):
5257c478bd9Sstevel@tonic-gate case KEY_NPAGE:
5267c478bd9Sstevel@tonic-gate case '-': /* display previous page */
5277c478bd9Sstevel@tonic-gate case KEY_PPAGE:
5287c478bd9Sstevel@tonic-gate case '!': /* shell escape */
5297c478bd9Sstevel@tonic-gate case '?': /* help */
5307c478bd9Sstevel@tonic-gate (void) command(c);
5317c478bd9Sstevel@tonic-gate break;
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate case ctrl('L'): /* redraw screen */
5347c478bd9Sstevel@tonic-gate case KEY_CLEAR:
5357c478bd9Sstevel@tonic-gate (void) command(c);
5367c478bd9Sstevel@tonic-gate goto same;
5377c478bd9Sstevel@tonic-gate
5387c478bd9Sstevel@tonic-gate case ESC: /* kept for backwards compatibility */
5397c478bd9Sstevel@tonic-gate /* FALLTHROUGH */
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate case '\r': /* don't change lines */
5427c478bd9Sstevel@tonic-gate case '\n':
5437c478bd9Sstevel@tonic-gate case KEY_ENTER:
5447c478bd9Sstevel@tonic-gate case KEY_BREAK:
5457c478bd9Sstevel@tonic-gate case ctrl('G'):
5467c478bd9Sstevel@tonic-gate clearprompt();
5477c478bd9Sstevel@tonic-gate goto nochange;
5487c478bd9Sstevel@tonic-gate
5497c478bd9Sstevel@tonic-gate case '*': /* mark/unmark all displayed lines */
5507c478bd9Sstevel@tonic-gate for (i = 0; topline + i < nextline; ++i) {
5517c478bd9Sstevel@tonic-gate mark(i);
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate goto same;
5547c478bd9Sstevel@tonic-gate
5557c478bd9Sstevel@tonic-gate case 'a': /* mark/unmark all lines */
5567c478bd9Sstevel@tonic-gate for (i = 0; i < totallines; ++i) {
5577c478bd9Sstevel@tonic-gate if (change[i] == NO) {
5587c478bd9Sstevel@tonic-gate change[i] = YES;
5597c478bd9Sstevel@tonic-gate } else {
5607c478bd9Sstevel@tonic-gate change[i] = NO;
5617c478bd9Sstevel@tonic-gate }
5627c478bd9Sstevel@tonic-gate }
5637c478bd9Sstevel@tonic-gate /* show that all have been marked */
5647c478bd9Sstevel@tonic-gate seekline(totallines);
5657c478bd9Sstevel@tonic-gate break;
5667c478bd9Sstevel@tonic-gate case ctrl('X'): /* mouse selection */
5677c478bd9Sstevel@tonic-gate if ((p = getmouseevent()) == NULL) {
5687c478bd9Sstevel@tonic-gate goto same; /* unknown control sequence */
5697c478bd9Sstevel@tonic-gate }
5707c478bd9Sstevel@tonic-gate /* if the button number is a scrollbar tag */
5717c478bd9Sstevel@tonic-gate if (p->button == '0') {
5727c478bd9Sstevel@tonic-gate scrollbar(p);
5737c478bd9Sstevel@tonic-gate break;
5747c478bd9Sstevel@tonic-gate }
5757c478bd9Sstevel@tonic-gate /* find the selected line */
5767c478bd9Sstevel@tonic-gate /* note: the selection is forced into range */
5777c478bd9Sstevel@tonic-gate for (i = disprefs - 1; i > 0; --i) {
5787c478bd9Sstevel@tonic-gate if (p->y1 >= displine[i]) {
5797c478bd9Sstevel@tonic-gate break;
5807c478bd9Sstevel@tonic-gate }
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate mark(i);
5837c478bd9Sstevel@tonic-gate goto same;
5847c478bd9Sstevel@tonic-gate default:
5857c478bd9Sstevel@tonic-gate /* if a line was selected */
5867c478bd9Sstevel@tonic-gate if (isdigit(c) && c != '0' && !mouse) {
5877c478bd9Sstevel@tonic-gate if (returnrequired == NO) {
5887c478bd9Sstevel@tonic-gate mark(c - '1');
5897c478bd9Sstevel@tonic-gate } else {
5907c478bd9Sstevel@tonic-gate clearprompt();
5917c478bd9Sstevel@tonic-gate (void) move(PRLINE, 0);
5927c478bd9Sstevel@tonic-gate (void) addstr(selectionprompt);
593*23a1cceaSRoger A. Faulkner if (getaline(buf,
5947c478bd9Sstevel@tonic-gate COLS - sizeof (selectionprompt), c,
5957c478bd9Sstevel@tonic-gate NO) > 0 &&
5967c478bd9Sstevel@tonic-gate (i = atoi(buf)) > 0) {
5977c478bd9Sstevel@tonic-gate mark(i - 1);
5987c478bd9Sstevel@tonic-gate }
5997c478bd9Sstevel@tonic-gate }
6007c478bd9Sstevel@tonic-gate }
6017c478bd9Sstevel@tonic-gate goto same;
6027c478bd9Sstevel@tonic-gate }
6037c478bd9Sstevel@tonic-gate }
6047c478bd9Sstevel@tonic-gate /* for each line containing the old text */
6057c478bd9Sstevel@tonic-gate (void) fprintf(script, "ed - <<\\!\nH\n");
6067c478bd9Sstevel@tonic-gate *oldfile = '\0';
6077c478bd9Sstevel@tonic-gate seekline(1);
6087c478bd9Sstevel@tonic-gate for (i = 0; fscanf(refsfound, "%s%*s%s%*[^\n]", newfile, linenum) == 2;
6097c478bd9Sstevel@tonic-gate ++i) {
6107c478bd9Sstevel@tonic-gate /* see if the line is to be changed */
6117c478bd9Sstevel@tonic-gate if (change[i] == YES) {
6127c478bd9Sstevel@tonic-gate anymarked = YES;
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate /* if this is a new file */
6157c478bd9Sstevel@tonic-gate if (strcmp(newfile, oldfile) != 0) {
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate /* make sure it can be changed */
6187c478bd9Sstevel@tonic-gate if (access(newfile, WRITE) != 0) {
6197c478bd9Sstevel@tonic-gate (void) sprintf(msg,
6207c478bd9Sstevel@tonic-gate "Cannot write to file %s",
6217c478bd9Sstevel@tonic-gate newfile);
6227c478bd9Sstevel@tonic-gate putmsg(msg);
6237c478bd9Sstevel@tonic-gate anymarked = NO;
6247c478bd9Sstevel@tonic-gate break;
6257c478bd9Sstevel@tonic-gate }
6267c478bd9Sstevel@tonic-gate /* if there was an old file */
6277c478bd9Sstevel@tonic-gate if (*oldfile != '\0') {
6287c478bd9Sstevel@tonic-gate (void) fprintf(script,
6297c478bd9Sstevel@tonic-gate "w\n"); /* save it */
6307c478bd9Sstevel@tonic-gate }
6317c478bd9Sstevel@tonic-gate /* edit the new file */
6327c478bd9Sstevel@tonic-gate (void) strcpy(oldfile, newfile);
6337c478bd9Sstevel@tonic-gate (void) fprintf(script, "e %s\n", oldfile);
6347c478bd9Sstevel@tonic-gate }
6357c478bd9Sstevel@tonic-gate /* output substitute command */
6367c478bd9Sstevel@tonic-gate (void) fprintf(script,
6377c478bd9Sstevel@tonic-gate "%ss/", linenum); /* change */
6387c478bd9Sstevel@tonic-gate for (s = pattern; *s != '\0'; ++s) { /* old text */
6397c478bd9Sstevel@tonic-gate if (*s == '/') {
6407c478bd9Sstevel@tonic-gate (void) putc('\\', script);
6417c478bd9Sstevel@tonic-gate }
6427c478bd9Sstevel@tonic-gate (void) putc(*s, script);
6437c478bd9Sstevel@tonic-gate }
6447c478bd9Sstevel@tonic-gate (void) putc('/', script); /* to */
6457c478bd9Sstevel@tonic-gate for (s = newpat; *s != '\0'; ++s) { /* new text */
6467c478bd9Sstevel@tonic-gate if (strchr("/\\&", *s) != NULL) {
6477c478bd9Sstevel@tonic-gate (void) putc('\\', script);
6487c478bd9Sstevel@tonic-gate }
6497c478bd9Sstevel@tonic-gate (void) putc(*s, script);
6507c478bd9Sstevel@tonic-gate }
6517c478bd9Sstevel@tonic-gate (void) fprintf(script, "/gp\n"); /* and print */
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate }
6547c478bd9Sstevel@tonic-gate (void) fprintf(script, "w\nq\n!\n"); /* write and quit */
6557c478bd9Sstevel@tonic-gate (void) fclose(script);
6567c478bd9Sstevel@tonic-gate clearprompt();
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate /* if any line was marked */
6597c478bd9Sstevel@tonic-gate if (anymarked == YES) {
6607c478bd9Sstevel@tonic-gate /* edit the files */
6617c478bd9Sstevel@tonic-gate (void) refresh();
6627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "Changed lines:\n\r");
6637c478bd9Sstevel@tonic-gate (void) execute(shell, shell, temp2, (char *)NULL);
6647c478bd9Sstevel@tonic-gate askforreturn();
6657c478bd9Sstevel@tonic-gate }
6667c478bd9Sstevel@tonic-gate nochange:
6677c478bd9Sstevel@tonic-gate changing = NO;
6687c478bd9Sstevel@tonic-gate initmenu();
6697c478bd9Sstevel@tonic-gate free(change);
6707c478bd9Sstevel@tonic-gate seekline(topline);
6717c478bd9Sstevel@tonic-gate return (YES); /* clear any marks on exit without change */
6727c478bd9Sstevel@tonic-gate }
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate /* mark/unmark this displayed line to be changed */
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate void
mark(int i)6777c478bd9Sstevel@tonic-gate mark(int i)
6787c478bd9Sstevel@tonic-gate {
6797c478bd9Sstevel@tonic-gate int j;
6807c478bd9Sstevel@tonic-gate
6817c478bd9Sstevel@tonic-gate j = i + topline - 1;
6827c478bd9Sstevel@tonic-gate if (j < totallines) {
6837c478bd9Sstevel@tonic-gate (void) move(displine[i], selectlen);
6847c478bd9Sstevel@tonic-gate if (change[j] == NO) {
6857c478bd9Sstevel@tonic-gate change[j] = YES;
6867c478bd9Sstevel@tonic-gate (void) addch('>');
6877c478bd9Sstevel@tonic-gate } else {
6887c478bd9Sstevel@tonic-gate change[j] = NO;
6897c478bd9Sstevel@tonic-gate (void) addch(' ');
6907c478bd9Sstevel@tonic-gate }
6917c478bd9Sstevel@tonic-gate }
6927c478bd9Sstevel@tonic-gate }
6937c478bd9Sstevel@tonic-gate
6947c478bd9Sstevel@tonic-gate /* scrollbar actions */
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate static void
scrollbar(MOUSEEVENT * p)6977c478bd9Sstevel@tonic-gate scrollbar(MOUSEEVENT *p)
6987c478bd9Sstevel@tonic-gate {
6997c478bd9Sstevel@tonic-gate /* reposition list if it makes sense */
7007c478bd9Sstevel@tonic-gate if (totallines == 0) {
7017c478bd9Sstevel@tonic-gate return;
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate switch (p->percent) {
7047c478bd9Sstevel@tonic-gate
7057c478bd9Sstevel@tonic-gate case 101: /* scroll down one page */
7067c478bd9Sstevel@tonic-gate if (nextline + mdisprefs > totallines) {
7077c478bd9Sstevel@tonic-gate nextline = totallines - mdisprefs + 1;
7087c478bd9Sstevel@tonic-gate }
7097c478bd9Sstevel@tonic-gate break;
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate case 102: /* scroll up one page */
7127c478bd9Sstevel@tonic-gate nextline = topline - mdisprefs;
7137c478bd9Sstevel@tonic-gate if (nextline < 1) {
7147c478bd9Sstevel@tonic-gate nextline = 1;
7157c478bd9Sstevel@tonic-gate }
7167c478bd9Sstevel@tonic-gate break;
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate case 103: /* scroll down one line */
7197c478bd9Sstevel@tonic-gate nextline = topline + 1;
7207c478bd9Sstevel@tonic-gate break;
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate case 104: /* scroll up one line */
7237c478bd9Sstevel@tonic-gate if (topline > 1) {
7247c478bd9Sstevel@tonic-gate nextline = topline - 1;
7257c478bd9Sstevel@tonic-gate }
7267c478bd9Sstevel@tonic-gate break;
7277c478bd9Sstevel@tonic-gate default:
7287c478bd9Sstevel@tonic-gate nextline = p->percent * totallines / 100;
7297c478bd9Sstevel@tonic-gate }
7307c478bd9Sstevel@tonic-gate seekline(nextline);
7317c478bd9Sstevel@tonic-gate }
732