예제 #1
0
void
display(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	screenline;		/* screen line number */
	int	width;			/* source line display width */
	int	i;
	char	*s;

	(void) erase();

	/* if there are no references */
	if (totallines == 0) {
		if (*lastmsg != '\0') {
			(void) addstr(lastmsg);	/* redisplay any message */
		} else {
			(void) printw("Cscope version %d%s", FILEVERSION,
			    FIXVERSION);
			(void) move(0, COLS - (int)sizeof (helpstring));
			(void) addstr(helpstring);
		}
	} else {	/* display the pattern */
		if (changing == YES) {
			(void) printw("Change \"%s\" to \"%s\"",
			    pattern, newpat);
		} else {
			(void) printw("%c%s: %s",
			    toupper(fields[field].text2[0]),
			    fields[field].text2 + 1, pattern);
		}
		/* display the cscope invocation nesting depth */
		if (cscopedepth > 1) {
			(void) move(0, COLS - (int)sizeof (depthstring) - 2);
			(void) addstr(depthstring);
			(void) printw("%d", cscopedepth);
		}
		/* display the column headings */
		(void) move(2, selectlen + 1);
		if (ogs == YES && field != FILENAME) {
			(void) printw("%-*s ", subsystemlen, "Subsystem");
			(void) printw("%-*s ", booklen, "Book");
		}
		if (dispcomponents > 0) {
			(void) printw("%-*s ", filelen, "File");
		}
		if (displayfcn()) {
			(void) printw("%-*s ", fcnlen, "Function");
		}
		if (field != FILENAME) {
			(void) addstr("Line");
		}
		(void) addch('\n');

		/* if at end of file go back to beginning */
		if (nextline > totallines) {
			seekline(1);
		}
		/* calculate the source text column */
		width = COLS - selectlen - numlen - 2;
		if (ogs == YES) {
			width -= subsystemlen + booklen + 2;
		}
		if (dispcomponents > 0) {
			width -= filelen + 1;
		}
		if (displayfcn()) {
			width -= fcnlen + 1;
		}
		/*
		 * until the max references have been displayed or
		 * there is no more room
		 */
		topline = nextline;
		for (disprefs = 0, screenline = REFLINE;
		    disprefs < mdisprefs && screenline <= lastdispline;
		    ++disprefs, ++screenline) {
			/* read the reference line */
			if (fscanf(refsfound, "%s%s%s %[^\n]", file, function,
			    linenum, yytext) < 4) {
				break;
			}
			++nextline;
			displine[disprefs] = screenline;

			/* if no mouse, display the selection number */
			if (!mouse) {
				(void) printw("%*d", selectlen, disprefs + 1);
			}
			/* display any change mark */
			if (changing == YES &&
			    change[topline + disprefs - 1] == YES) {
				(void) addch('>');
			} else {
				(void) addch(' ');
			}
			/* display the file name */
			if (field == FILENAME) {
				(void) printw("%-.*s\n", COLS - 3, file);
				continue;
			}
			/* if OGS, display the subsystem and book names */
			if (ogs == YES) {
				ogsnames(file, &subsystem, &book);
				(void) printw("%-*.*s ", subsystemlen,
				    subsystemlen, subsystem);
				(void) printw("%-*.*s ", booklen, booklen,
				    book);
			}
			/* display the requested path components */
			if (dispcomponents > 0) {
				(void) printw("%-*.*s ", filelen, filelen,
				    pathcomponents(file, dispcomponents));
			}
			/* display the function name */
			if (displayfcn()) {
				(void) printw("%-*.*s ", fcnlen, fcnlen,
				    function);
			}
			/* display the line number */
			(void) printw("%*s ", numlen, linenum);

			/* there may be tabs in egrep output */
			while ((s = strchr(yytext, '\t')) != NULL) {
				*s = ' ';
			}
			/* display the source line */
			s = yytext;
			for (;;) {
				/* see if the source line will fit */
				if ((i = strlen(s)) > width) {
					/* find the nearest blank */
					for (i = width; s[i] != ' ' && i > 0;
					    --i) {
					}
					if (i == 0) {
						i = width;	/* no blank */
					}
				}
				/* print up to this point */
				(void) printw("%.*s", i, s);
				s += i;

				/* if line didn't wrap around */
				if (i < width) {
					/* go to next line */
					(void) addch('\n');
				}
				/* skip blanks */
				while (*s == ' ') {
					++s;
				}
				/* see if there is more text */
				if (*s == '\0') {
					break;
				}
				/* if the source line is too long */
				if (++screenline > lastdispline) {
					/*
					 * if this is the first displayed line,
					 * display what will fit on the screen
					 */
					if (topline == nextline - 1) {
						goto endrefs;
					}
					/* erase the reference */
					while (--screenline >=
					    displine[disprefs]) {
						(void) move(screenline, 0);
						(void) clrtoeol();
					}
					++screenline;

					/*
					 * go back to the beginning of this
					 * reference
					 */
					--nextline;
					seekline(nextline);
					goto endrefs;
				}
				/* indent the continued source line */
				(void) move(screenline, COLS - width);
			}

		}
	endrefs:
		/* check for more references */
		bottomline = nextline;
		if (bottomline - topline < totallines) {
			(void) move(FLDLINE - 1, 0);
			(void) standout();
			(void) printw("%*s", selectlen + 1, "");
			if (bottomline - 1 == topline) {
				(void) printw("Line %d", topline);
			} else {
				(void) printw("Lines %d-%d", topline,
				    bottomline - 1);
			}
			(void) printw(" of %d, press the space bar to "
			    "display next lines", totallines);
			(void) standend();
		}
	}
	/* display the input fields */
	(void) move(FLDLINE, 0);
	for (i = 0; i < FIELDS; ++i) {
		(void) printw("%s %s:\n", fields[i].text1, fields[i].text2);
	}
	drawscrollbar(topline, nextline, totallines);
}
예제 #2
0
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
	 */
	subsystemlen = 9;	/* strlen("Subsystem") */
	booklen = 4;		/* strlen("Book") */
	filelen = 4;		/* strlen("File") */
	fcnlen = 8;		/* strlen("Function") */
	numlen = 0;
	while ((i = fscanf(refsfound, "%250s%250s%6s %5000[^\n]", file,
	    function, linenum, yytext)) != EOF) {
		if (i != 4 || !isgraph(*file) ||
		    !isgraph(*function) || !isdigit(*linenum)) {
			putmsg("File does not have expected format");
			totallines = 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;
	}
	rewind(refsfound);

	/* restrict the width of displayed columns */
	i = (COLS - 5) / 3;
	if (ogs == YES) {
		i = (COLS - 7) / 5;
	}
	if (filelen > i && i > 4) {
		filelen = i;
	}
	if (subsystemlen > i && i > 9) {
		subsystemlen = i;
	}
	if (booklen > i && i > 4) {
		booklen = i;
	}
	if (fcnlen > i && i > 8) {
		fcnlen = i;
	}
}
예제 #3
0
void
display(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     screenline;             /* screen line number */
    int     width;                  /* source line display width */
    int     i;
    char    *s;

    /* see if this is the initial display */
    erase();
    if (refsfound == NULL) {
#if CCS
	if (displayversion == YES) {
	    printw("cscope %s", ESG_REL);
	}
	else {
	    printw("cscope");
	}
#else
	printw("Cscope version %d%s", FILEVERSION, FIXVERSION);
#endif
	move(0, COLS - (int) sizeof(helpstring));
	addstr(helpstring);
    } else if (totallines == 0) {
	/* if no references were found */
	/* redisplay the last message */
	addstr(lastmsg);
    } else {
	/* display the pattern */
	if (changing == YES) {
	    printw("Change \"%s\" to \"%s\"", Pattern, newpat);
	} else {
	    printw("%c%s: %s", toupper((unsigned char)fields[field].text2[0]),
		   fields[field].text2 + 1, Pattern);
	}
	/* display the column headings */
	move(2, 2);
	if (ogs == YES && field != FILENAME) {
	    printw("%-*s ", subsystemlen, "Subsystem");
	    printw("%-*s ", booklen, "Book");
	}
	if (dispcomponents > 0)
	    printw("%-*s ", filelen, "File");

	if (field == SYMBOL || field == CALLEDBY || field == CALLING) {
	    printw("%-*s ", fcnlen, "Function");
	}
	if (field != FILENAME) {
	    addstr("Line");
	}
	addch('\n');

	/* if at end of file go back to beginning */
	if (nextline > totallines) {
	    seekline(1);
	}
	/* calculate the source text column */

	width = COLS - numlen - 3;

	if (ogs == YES) {
	    width -= subsystemlen + booklen + 2;
	}
	if (dispcomponents > 0) {
	    width -= filelen + 1;
	}
	if (field == SYMBOL || field == CALLEDBY || field == CALLING) {
	    width -= fcnlen + 1;
	}

	/* until the max references have been displayed or 
	   there is no more room */
	topline = nextline;
	for (disprefs = 0, screenline = REFLINE;
	     disprefs < mdisprefs && screenline <= lastdispline;
	     ++disprefs, ++screenline) {
	    /* read the reference line */
	    if (fscanf(refsfound, "%" PATHLEN_STR "s%" PATHLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR "[^\n]", file, function, 
		       linenum, tempstring) < 4) {
		break;
	    }
	    ++nextline;
	    displine[disprefs] = screenline;
			
	    /* if no mouse, display the selection number */
	    if (mouse == YES) {
		addch(' ');
	    } else {
		printw("%c", dispchars[disprefs]);
	    }

	    /* display any change mark */
	    if (changing == YES && 
		change[topline + disprefs - 1] == YES) {
		addch('>');
	    } else {
		addch(' ');
	    }

	    /* display the file name */
	    if (field == FILENAME) {
		printw("%-*s ", filelen, file);
	    } else {
		/* if OGS, display the subsystem and book names */
		if (ogs == YES) {
		    ogsnames(file, &subsystem, &book);
		    printw("%-*.*s ", subsystemlen, subsystemlen, subsystem);
		    printw("%-*.*s ", booklen, booklen, book);
		}
		/* display the requested path components */
		if (dispcomponents > 0) {
		    printw("%-*.*s ", filelen, filelen,
			   pathcomponents(file, dispcomponents));
		}
	    } /* else(field == FILENAME) */

	    /* display the function name */
	    if (field == SYMBOL || field == CALLEDBY || field == CALLING) {
		printw("%-*.*s ", fcnlen, fcnlen, function);
	    }
	    if (field == FILENAME) {
		addch('\n');	/* go to next line */
		continue;
	    }

	    /* display the line number */
	    printw("%*s ", numlen, linenum);
	    /* there may be tabs in egrep output */
	    while ((s = strchr(tempstring, '\t')) != NULL) {
		*s = ' ';
	    }

	    /* display the source line */
	    s = tempstring;
	    for (;;) {
		/* see if the source line will fit */
		if ((i = strlen(s)) > width) {
					
		    /* find the nearest blank */
		    for (i = width; s[i] != ' ' && i > 0; --i) {
			;
		    }
		    if (i == 0) {
			i = width;	/* no blank */
		    }
		}
		/* print up to this point */
		printw("%.*s", i, s);
		s += i;
				
		/* if line didn't wrap around */
		if (i < width) {
		    addch('\n');	/* go to next line */
		}
		/* skip blanks */
		while (*s == ' ') {
		    ++s;
		}
		/* see if there is more text */
		if (*s == '\0') {
		    break;
		}
		/* if the source line is too long */
		if (++screenline > lastdispline) {

		    /* if this is the first displayed line,
		       display what will fit on the screen */
		    if (topline == nextline -1) {
			disprefs++;
			/* break out of two loops */
			goto endrefs;
		    }
					
		    /* erase the reference */
		    while (--screenline >= displine[disprefs]) {
			move(screenline, 0);
			clrtoeol();
		    }
		    ++screenline;
					 
		    /* go back to the beginning of this reference */
		    --nextline;
		    seekline(nextline);
		    goto endrefs;
		}
		/* indent the continued source line */
		move(screenline, COLS - width);
	    } /* for(ever) */
	} /* for(reference output lines) */
    endrefs:
	/* position the cursor for the message */
	i = FLDLINE - 1;
	if (screenline < i) {
	    addch('\n');
	}
	else {
	    move(i, 0);
	}
	/* check for more references */
	i = totallines - nextline + 1;
	bottomline = nextline;
	if (i > 0) {
	    printw("* Lines %d-%d of %d, %d more - press the space bar to display more *", topline, bottomline, totallines, i);
	}
	/* if this is the last page of references */
	else if (topline > 1 && nextline > totallines) {
	    addstr("* Press the space bar to display the first lines again *");
	}
    }
    /* display the input fields */
    move(FLDLINE, 0);
    for (i = 0; i < FIELDS; ++i) {
	printw("%s %s:\n", fields[i].text1, fields[i].text2);
    }
    /* display any prompt */
    if (changing == YES) {
	move(PRLINE, 0);
	addstr(selprompt);
    }
    drawscrollbar(topline, nextline);	/* display the scrollbar */
    refresh();
}