/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* cscope - interactive C symbol or text cross-reference
*
* command functions
*/
#include <curses.h> /* KEY_.* */
#include <fcntl.h> /* O_RDONLY */
#include <unistd.h>
#include <stdio.h>
#include "global.h"
#include "library.h"
static void scrollbar(MOUSEEVENT *p);
/* execute the command */
{
MOUSEEVENT *p; /* mouse data */
int c, i;
char *s;
switch (commandc) {
putmsg2("Caseless mode is now ON");
} else {
putmsg2("Caseless mode is now OFF");
}
return (NO);
if (isuptodate == YES) {
putmsg("The -d option prevents rebuilding the "
"symbol database");
return (NO);
}
exitcurses();
freefilelist(); /* remake the source file list */
makefilelist();
rebuild();
if (errorsfound == YES) {
errorsfound = NO;
askforreturn();
}
entercurses();
totallines = 0;
break;
if ((p = getmouseevent()) == NULL) {
return (NO); /* unknown control sequence */
}
/* if the button number is a scrollbar tag */
if (p->button == '0') {
scrollbar(p);
break;
}
/* ignore a sweep */
if (p->x2 >= 0) {
return (NO);
}
/* if this is a line selection */
/* find the selected line */
/* note: the selection is forced into range */
for (i = disprefs - 1; i > 0; --i) {
break;
}
}
/* display it in the file with the editor */
editref(i);
} else { /* this is an input field selection */
setfield();
resetcmd();
return (NO);
}
break;
case '\t': /* go to next input field */
case '\n':
case '\r':
case ctrl('N'):
case KEY_DOWN:
case KEY_ENTER:
case KEY_RIGHT:
setfield();
resetcmd();
return (NO);
case KEY_UP:
case KEY_LEFT:
setfield();
resetcmd();
return (NO);
case KEY_HOME: /* go to first input field */
field = 0;
setfield();
resetcmd();
return (NO);
case KEY_LL: /* go to last input field */
setfield();
resetcmd();
return (NO);
case ' ': /* display next page */
case '+':
case ctrl('V'):
case KEY_NPAGE:
/* don't redisplay if there are no lines */
if (totallines == 0) {
return (NO);
}
/*
* note: seekline() is not used to move to the next
* page because display() leaves the file pointer at
* the next page to optimize paging forward
*/
break;
case '-': /* display previous page */
case KEY_PPAGE:
/* don't redisplay if there are no lines */
if (totallines == 0) {
return (NO);
}
i = topline; /* save the current top line */
/* if on first page but not at beginning, go to beginning */
nextline = 1;
} else { /* go back the maximum displayable lines */
/* if this was the first page, go to the last page */
if (nextline < 1) {
if (nextline < 1) {
nextline = 1;
}
/* old top is past last line */
i = totallines + 1;
}
}
/*
* move down til the bottom line is just before the
* previous top line
*/
c = nextline;
for (;;) {
display();
if (i - bottomline <= 0) {
break;
}
nextline = ++c;
}
return (NO); /* display already up to date */
case '>': /* write or append the lines to a file */
if (totallines == 0) {
putmsg("There are no lines to write to a file");
} else { /* get the file name */
(void) addstr("Write to file: ");
s = "w";
if ((c = mygetch()) == '>') {
(void) addstr(appendprompt);
c = '\0';
s = "a";
}
c != KEY_BREAK &&
NO) > 0) {
} else {
seekline(1);
}
}
}
clearprompt();
}
return (NO); /* return to the previous field */
case '<': /* read lines from a file */
(void) addstr(readprompt);
NO) > 0) {
clearprompt();
putmsg2("Ignoring an empty file");
return (NO);
}
return (YES);
}
clearprompt();
return (NO);
case '^': /* pipe the lines through a shell command */
case '|': /* pipe the lines to a shell command */
if (totallines == 0) {
putmsg("There are no lines to pipe to a shell command");
return (NO);
}
/* get the shell command */
(void) addstr(pipeprompt);
clearprompt();
return (NO);
}
/* if the ^ command, redirect output to a temp file */
if (commandc == '^') {
}
exitcurses();
"cscope: cannot open pipe to shell command: %s\n",
newpat);
} else {
seekline(1);
}
}
if (commandc == '^') {
putmsg("Ignoring empty output of ^ command");
}
}
askforreturn();
entercurses();
break;
case KEY_CLEAR:
return (NO);
case '!': /* shell escape */
break;
case '?': /* help */
(void) clear();
help();
(void) clear();
break;
editall();
break;
if (*pattern != '\0') {
goto repeat;
}
break;
curritem = currentcmd();
clearmsg2();
/* inform user that we're at history end */
"End of input field and search pattern history");
}
if (item) {
setfield();
atfield();
switch (c = mygetch()) {
case '\r':
case '\n':
case KEY_ENTER:
goto repeat;
default:
ungetch(c);
atfield();
(void) clrtoeol(); /* clear current field */
break;
}
}
return (NO);
case '\\': /* next character is not a command */
/* get a character from the terminal */
return (NO); /* quit */
}
goto ispat;
case '.':
atfield(); /* move back to the input field */
/* FALLTHROUGH */
default:
/* edit a selected line */
if (returnrequired == NO) {
} else {
(void) addstr(selectionprompt);
NO) > 0 &&
editref(i - 1);
}
clearprompt();
}
/* this is the start of a pattern */
caseless) > 0) {
resetcmd(); /* reset history */
/* prompt for the new text */
}
/* search for the pattern */
switch (field) {
case DEFINITION:
case FILENAME:
if (totallines > 1) {
break;
}
topline = 1;
editref(0);
break;
case CHANGE:
return (changestring());
}
/* try to edit the file anyway */
}
} else { /* no pattern--the input was erased */
return (NO);
}
} else { /* control character */
return (NO);
}
}
return (YES);
}
/* clear the prompt line */
void
clearprompt(void)
{
(void) clrtoeol();
}
/* read references from a file */
{
int c;
return (NO);
}
return (NO);
}
totallines = 0;
nextline = 1;
if (writerefsfound() == YES) {
}
countrefs();
}
return (YES);
}
/* change one text string to another */
changestring(void)
{
MOUSEEVENT *p; /* mouse data */
int c, i;
char *s;
/* open the temporary file */
return (NO);
}
/* create the line change indicators */
initmenu();
/* until the quit command is entered */
for (;;) {
/* display the current page of lines */
display();
same:
/* get a character from the terminal */
(void) addstr(
"Select lines to change (press the ? key for help): ");
c == ctrl('Z')) {
break; /* change lines */
}
/* see if the input character is a command */
switch (c) {
case ' ': /* display next page */
case '+':
case ctrl('V'):
case KEY_NPAGE:
case '-': /* display previous page */
case KEY_PPAGE:
case '!': /* shell escape */
case '?': /* help */
(void) command(c);
break;
case KEY_CLEAR:
(void) command(c);
goto same;
case ESC: /* kept for backwards compatibility */
/* FALLTHROUGH */
case '\r': /* don't change lines */
case '\n':
case KEY_ENTER:
case KEY_BREAK:
case ctrl('G'):
clearprompt();
goto nochange;
mark(i);
}
goto same;
for (i = 0; i < totallines; ++i) {
} else {
}
}
/* show that all have been marked */
break;
if ((p = getmouseevent()) == NULL) {
goto same; /* unknown control sequence */
}
/* if the button number is a scrollbar tag */
if (p->button == '0') {
scrollbar(p);
break;
}
/* find the selected line */
/* note: the selection is forced into range */
for (i = disprefs - 1; i > 0; --i) {
break;
}
}
mark(i);
goto same;
default:
/* if a line was selected */
if (returnrequired == NO) {
mark(c - '1');
} else {
clearprompt();
(void) addstr(selectionprompt);
COLS - sizeof (selectionprompt), c,
NO) > 0 &&
mark(i - 1);
}
}
}
goto same;
}
}
/* for each line containing the old text */
*oldfile = '\0';
seekline(1);
++i) {
/* see if the line is to be changed */
/* if this is a new file */
/* make sure it can be changed */
"Cannot write to file %s",
newfile);
break;
}
/* if there was an old file */
if (*oldfile != '\0') {
"w\n"); /* save it */
}
/* edit the new file */
}
/* output substitute command */
if (*s == '/') {
}
}
}
}
}
}
clearprompt();
/* if any line was marked */
/* edit the files */
(void) refresh();
askforreturn();
}
initmenu();
return (YES); /* clear any marks on exit without change */
}
void
mark(int i)
{
int j;
j = i + topline - 1;
if (j < totallines) {
(void) addch('>');
} else {
(void) addch(' ');
}
}
}
/* scrollbar actions */
static void
{
/* reposition list if it makes sense */
if (totallines == 0) {
return;
}
switch (p->percent) {
case 101: /* scroll down one page */
}
break;
case 102: /* scroll up one page */
if (nextline < 1) {
nextline = 1;
}
break;
case 103: /* scroll down one line */
break;
case 104: /* scroll up one line */
if (topline > 1) {
}
break;
default:
}
}