2023-07-27 14:04:50 -04:00
|
|
|
/*===========================================================================
|
|
|
|
Copyright (c) 1998-2000, The Santa Cruz Operation
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
*Redistributions of source code must retain the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
*Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
*Neither name of The Santa Cruz Operation nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software
|
|
|
|
without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
|
|
|
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION)
|
|
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
DAMAGE.
|
|
|
|
=========================================================================*/
|
|
|
|
|
2023-08-04 13:49:03 -04:00
|
|
|
/* cscope - interactive C symbol or text cross-reference
|
2023-07-27 14:04:50 -04:00
|
|
|
*
|
2023-08-04 13:49:03 -04:00
|
|
|
* command functions
|
2023-07-27 14:04:50 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "global.h"
|
2023-08-04 13:49:03 -04:00
|
|
|
#include "build.h" /* for rebuild() */
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
|
|
|
|
#include <ncurses.h>
|
|
|
|
#else
|
|
|
|
#include <curses.h>
|
|
|
|
#endif
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2023-07-29 09:40:48 -04:00
|
|
|
/* These are strictly used to test how keys are suppose to behave.
|
|
|
|
* Think of it as modes: in _input mode_ the up arrow interacts
|
|
|
|
* with the history, while in _mode mode_ it selects what operation
|
|
|
|
* to perform with the user input.
|
|
|
|
* In the original version this was handled by
|
|
|
|
* "int selecting // whether the (upper) symbol list is being browsed".
|
|
|
|
*/
|
|
|
|
extern const void const* winput;
|
|
|
|
extern const void const* wmode;
|
|
|
|
extern const void const* wresult;
|
|
|
|
extern const void const* const* current_window;
|
2023-07-27 14:04:50 -04:00
|
|
|
|
2023-08-04 13:49:03 -04:00
|
|
|
BOOL caseless; /* ignore letter case when searching */
|
|
|
|
BOOL *change; /* change this line */
|
|
|
|
BOOL changing; /* changing text */
|
|
|
|
char newpat[PATLEN + 1]; /* new pattern */
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
/* Internal prototypes: */
|
2023-08-04 13:49:03 -04:00
|
|
|
static void clearprompt(void);
|
|
|
|
static void mark(unsigned int i);
|
|
|
|
static void scrollbar(MOUSE *p);
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
/* clear the prompt line */
|
|
|
|
|
|
|
|
static void
|
|
|
|
clearprompt(void)
|
|
|
|
{
|
2023-08-04 13:49:03 -04:00
|
|
|
move(PRLINE, 0);
|
|
|
|
clrtoeol();
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read references from a file */
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
readrefs(char *filename)
|
|
|
|
{
|
2023-08-04 13:49:03 -04:00
|
|
|
FILE *file;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
if ((file = myfopen(filename, "rb")) == NULL) {
|
|
|
|
cannotopen(filename);
|
|
|
|
return(NO);
|
|
|
|
}
|
|
|
|
if ((c = getc(file)) == EOF) { /* if file is empty */
|
|
|
|
fclose(file);
|
|
|
|
return(NO);
|
|
|
|
}
|
|
|
|
totallines = 0;
|
|
|
|
disprefs = 0;
|
|
|
|
nextline = 1;
|
|
|
|
if (writerefsfound() == YES) {
|
|
|
|
putc(c, refsfound);
|
|
|
|
while ((c = getc(file)) != EOF) {
|
|
|
|
putc(c, refsfound);
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
fclose(refsfound);
|
|
|
|
if ( (refsfound = myfopen(temp1, "rb")) == NULL) {
|
|
|
|
cannotopen(temp1);
|
|
|
|
return(NO);
|
|
|
|
}
|
|
|
|
countrefs();
|
|
|
|
} else
|
|
|
|
fclose(file);
|
|
|
|
return(YES);
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mark/unmark this displayed line to be changed */
|
|
|
|
static void
|
|
|
|
mark(unsigned int i)
|
|
|
|
{
|
|
|
|
unsigned int j;
|
2023-08-04 13:49:03 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
j = i + topline - 1;
|
|
|
|
if (j < totallines) {
|
2023-08-04 13:49:03 -04:00
|
|
|
move(displine[i], 1);
|
|
|
|
|
|
|
|
if (change[j] == NO) {
|
|
|
|
change[j] = YES;
|
|
|
|
addch('>');
|
|
|
|
} else {
|
|
|
|
change[j] = NO;
|
|
|
|
addch(' ');
|
|
|
|
}
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* scrollbar actions */
|
|
|
|
static void
|
|
|
|
scrollbar(MOUSE *p)
|
|
|
|
{
|
|
|
|
/* reposition list if it makes sense */
|
|
|
|
if (totallines == 0) {
|
2023-08-04 13:49:03 -04:00
|
|
|
return;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
switch (p->percent) {
|
2023-08-04 13:49:03 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
case 101: /* scroll down one page */
|
2023-08-04 13:49:03 -04:00
|
|
|
if (nextline + mdisprefs > totallines) {
|
|
|
|
nextline = totallines - mdisprefs + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
case 102: /* scroll up one page */
|
2023-08-04 13:49:03 -04:00
|
|
|
nextline = topline - mdisprefs;
|
|
|
|
if (nextline < 1) {
|
|
|
|
nextline = 1;
|
|
|
|
}
|
|
|
|
break;
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
case 103: /* scroll down one line */
|
2023-08-04 13:49:03 -04:00
|
|
|
nextline = topline + 1;
|
|
|
|
break;
|
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
case 104: /* scroll up one line */
|
2023-08-04 13:49:03 -04:00
|
|
|
if (topline > 1) {
|
|
|
|
nextline = topline - 1;
|
|
|
|
}
|
|
|
|
break;
|
2023-07-27 14:04:50 -04:00
|
|
|
default:
|
2023-08-04 13:49:03 -04:00
|
|
|
nextline = p->percent * totallines / 100;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
seekline(nextline);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* count the references found */
|
|
|
|
void
|
|
|
|
countrefs(void)
|
|
|
|
{
|
|
|
|
char *subsystem; /* OGS subsystem name */
|
|
|
|
char *book; /* OGS book name */
|
|
|
|
char file[PATHLEN + 1]; /* file name */
|
|
|
|
char function[PATLEN + 1]; /* function name */
|
|
|
|
char linenum[NUMLEN + 1]; /* line number */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* count the references found and find the length of the file,
|
|
|
|
function, and line number display fields */
|
2023-07-29 09:40:48 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
/* HBB NOTE 2012-04-07: it may look like we shouldn't assing tempstring here,
|
|
|
|
* since it's not used. But it has to be assigned just so the return value
|
|
|
|
* of fscanf will actually reach 4. */
|
|
|
|
while (EOF != (i = fscanf(refsfound,
|
2023-08-04 13:49:03 -04:00
|
|
|
"%" PATHLEN_STR "s%" PATLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR "[^\n]",
|
|
|
|
file, function, linenum, tempstring
|
|
|
|
)
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
if ( (i != 4)
|
|
|
|
|| !isgraph((unsigned char) *file)
|
|
|
|
|| !isgraph((unsigned char) *function)
|
|
|
|
|| !isdigit((unsigned char) *linenum)
|
|
|
|
) {
|
|
|
|
postmsg("File does not have expected format");
|
|
|
|
totallines = 0;
|
|
|
|
disprefs = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((i = strlen(pathcomponents(file, dispcomponents))) > filelen) {
|
|
|
|
filelen = i;
|
|
|
|
}
|
|
|
|
if (ogs == YES) {
|
|
|
|
ogsnames(file, &subsystem, &book);
|
|
|
|
if ((i = strlen(subsystem)) > subsystemlen) {
|
|
|
|
subsystemlen = i;
|
|
|
|
}
|
|
|
|
if ((i = strlen(book)) > booklen) {
|
|
|
|
booklen = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((i = strlen(function)) > fcnlen) {
|
|
|
|
fcnlen = i;
|
|
|
|
}
|
|
|
|
if ((i = strlen(linenum)) > numlen) {
|
|
|
|
numlen = i;
|
|
|
|
}
|
|
|
|
++totallines;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
rewind(refsfound);
|
|
|
|
|
|
|
|
/* restrict the width of displayed columns */
|
|
|
|
/* HBB FIXME 20060419: magic number alert! */
|
|
|
|
i = (COLS - 5) / 3;
|
|
|
|
if (ogs == YES) {
|
2023-08-04 13:49:03 -04:00
|
|
|
i = (COLS - 7) / 5;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
if (filelen > i && i > 4) {
|
2023-08-04 13:49:03 -04:00
|
|
|
filelen = i;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
if (subsystemlen > i && i > 9) {
|
2023-08-04 13:49:03 -04:00
|
|
|
subsystemlen = i;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
if (booklen > i && i > 4) {
|
2023-08-04 13:49:03 -04:00
|
|
|
booklen = i;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
if (fcnlen > i && i > 8) {
|
2023-08-04 13:49:03 -04:00
|
|
|
fcnlen = i;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
}
|