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 */ 21*23a1cceaSRoger A. Faulkner 22*23a1cceaSRoger A. Faulkner /* 23*23a1cceaSRoger A. Faulkner * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 24*23a1cceaSRoger A. Faulkner */ 25*23a1cceaSRoger A. Faulkner 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * cscope - interactive C symbol cross-reference 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * global type, data, and function definitions 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <ctype.h> /* isalpha, isdigit, etc. */ 367c478bd9Sstevel@tonic-gate #include <signal.h> /* SIGINT and SIGQUIT */ 377c478bd9Sstevel@tonic-gate #include <stdio.h> /* standard I/O package */ 387c478bd9Sstevel@tonic-gate #include <sys/types.h> 397c478bd9Sstevel@tonic-gate #include "constants.h" /* misc. constants */ 407c478bd9Sstevel@tonic-gate #include "invlib.h" /* inverted index library */ 417c478bd9Sstevel@tonic-gate #include "library.h" /* library function return values */ 427c478bd9Sstevel@tonic-gate #include "mouse.h" /* mouse interface */ 437c478bd9Sstevel@tonic-gate #define SIGTYPE void 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate typedef enum { /* boolean data type */ 467c478bd9Sstevel@tonic-gate NO, 477c478bd9Sstevel@tonic-gate YES 487c478bd9Sstevel@tonic-gate } BOOL; 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate typedef enum { /* findinit return code */ 517c478bd9Sstevel@tonic-gate NOERROR, 527c478bd9Sstevel@tonic-gate NOTSYMBOL, 537c478bd9Sstevel@tonic-gate REGCMPERROR 547c478bd9Sstevel@tonic-gate } FINDINIT; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate typedef struct history { /* command history */ 577c478bd9Sstevel@tonic-gate int field; 587c478bd9Sstevel@tonic-gate char *text; 597c478bd9Sstevel@tonic-gate struct history *previous; 607c478bd9Sstevel@tonic-gate struct history *next; 617c478bd9Sstevel@tonic-gate } HISTORY; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate typedef enum { /* keyword type */ 647c478bd9Sstevel@tonic-gate DECL, /* type declaration */ 657c478bd9Sstevel@tonic-gate FLOW, /* control flow (do, if, for, while, switch, etc.) */ 667c478bd9Sstevel@tonic-gate MISC /* misc.: sizeof or table placeholder for compression */ 677c478bd9Sstevel@tonic-gate } KEYWORD; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* digraph data for text compression */ 707c478bd9Sstevel@tonic-gate extern char dichar1[]; /* 16 most frequent first chars */ 717c478bd9Sstevel@tonic-gate extern char dichar2[]; /* 8 most frequent second chars */ 727c478bd9Sstevel@tonic-gate /* using the above as first chars */ 737c478bd9Sstevel@tonic-gate extern char dicode1[]; /* digraph first character code */ 747c478bd9Sstevel@tonic-gate extern char dicode2[]; /* digraph second character code */ 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* main.c global data */ 777c478bd9Sstevel@tonic-gate extern char *editor, *home, *shell; /* environment variables */ 787c478bd9Sstevel@tonic-gate extern BOOL compress; /* compress the characters in the crossref */ 797c478bd9Sstevel@tonic-gate extern int cscopedepth; /* cscope invocation nesting depth */ 807c478bd9Sstevel@tonic-gate extern char currentdir[]; /* current directory */ 817c478bd9Sstevel@tonic-gate extern BOOL dbtruncated; /* database symbols are truncated to 8 chars */ 827c478bd9Sstevel@tonic-gate extern char **dbvpdirs; /* directories (including current) in */ 837c478bd9Sstevel@tonic-gate /* database view path */ 847c478bd9Sstevel@tonic-gate extern int dbvpndirs; /* number of directories in database */ 857c478bd9Sstevel@tonic-gate /* view path */ 867c478bd9Sstevel@tonic-gate extern int dispcomponents; /* file path components to display */ 877c478bd9Sstevel@tonic-gate extern BOOL editallprompt; /* prompt between editing files */ 887c478bd9Sstevel@tonic-gate extern int fileargc; /* file argument count */ 897c478bd9Sstevel@tonic-gate extern char **fileargv; /* file argument values */ 907c478bd9Sstevel@tonic-gate extern int fileversion; /* cross-reference file version */ 917c478bd9Sstevel@tonic-gate extern BOOL incurses; /* in curses */ 927c478bd9Sstevel@tonic-gate extern INVCONTROL invcontrol; /* inverted file control structure */ 937c478bd9Sstevel@tonic-gate extern BOOL invertedindex; /* the database has an inverted index */ 947c478bd9Sstevel@tonic-gate extern BOOL isuptodate; /* consider the crossref up-to-date */ 957c478bd9Sstevel@tonic-gate extern BOOL linemode; /* use line oriented user interface */ 967c478bd9Sstevel@tonic-gate extern char *namefile; /* file of file names */ 977c478bd9Sstevel@tonic-gate extern char *newreffile; /* new cross-reference file name */ 987c478bd9Sstevel@tonic-gate extern FILE *newrefs; /* new cross-reference */ 997c478bd9Sstevel@tonic-gate extern BOOL noacttimeout; /* no activity timeout occurred */ 1007c478bd9Sstevel@tonic-gate extern BOOL ogs; /* display OGS book and subsystem names */ 1017c478bd9Sstevel@tonic-gate extern FILE *postings; /* new inverted index postings */ 1027c478bd9Sstevel@tonic-gate extern char *prependpath; /* prepend path to file names */ 1037c478bd9Sstevel@tonic-gate extern BOOL returnrequired; /* RETURN required after selection number */ 1047c478bd9Sstevel@tonic-gate extern int symrefs; /* cross-reference file */ 1057c478bd9Sstevel@tonic-gate extern char temp1[]; /* temporary file name */ 1067c478bd9Sstevel@tonic-gate extern char temp2[]; /* temporary file name */ 1077c478bd9Sstevel@tonic-gate extern long totalterms; /* total inverted index terms */ 1087c478bd9Sstevel@tonic-gate extern BOOL truncatesyms; /* truncate symbols to 8 characters */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* command.c global data */ 1117c478bd9Sstevel@tonic-gate extern BOOL caseless; /* ignore letter case when searching */ 1127c478bd9Sstevel@tonic-gate extern BOOL *change; /* change this line */ 1137c478bd9Sstevel@tonic-gate extern BOOL changing; /* changing text */ 1147c478bd9Sstevel@tonic-gate extern char newpat[]; /* new pattern */ 1157c478bd9Sstevel@tonic-gate extern char pattern[]; /* symbol or text pattern */ 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* crossref.c global data */ 1187c478bd9Sstevel@tonic-gate extern long dboffset; /* new database offset */ 1197c478bd9Sstevel@tonic-gate extern BOOL errorsfound; /* prompt before clearing error messages */ 1207c478bd9Sstevel@tonic-gate extern long fileindex; /* source file name index */ 1217c478bd9Sstevel@tonic-gate extern long lineoffset; /* source line database offset */ 1227c478bd9Sstevel@tonic-gate extern long npostings; /* number of postings */ 1237c478bd9Sstevel@tonic-gate extern int symbols; /* number of symbols */ 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate /* dir.c global data */ 1267c478bd9Sstevel@tonic-gate extern char **incdirs; /* #include directories */ 1277c478bd9Sstevel@tonic-gate extern char **srcdirs; /* source directories */ 1287c478bd9Sstevel@tonic-gate extern char **srcfiles; /* source files */ 1297c478bd9Sstevel@tonic-gate extern int nincdirs; /* number of #include directories */ 1307c478bd9Sstevel@tonic-gate extern int nsrcdirs; /* number of source directories */ 1317c478bd9Sstevel@tonic-gate extern int nsrcfiles; /* number of source files */ 1327c478bd9Sstevel@tonic-gate extern int msrcfiles; /* maximum number of source files */ 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate /* display.c global data */ 1357c478bd9Sstevel@tonic-gate extern int *displine; /* screen line of displayed reference */ 1367c478bd9Sstevel@tonic-gate extern int disprefs; /* displayed references */ 1377c478bd9Sstevel@tonic-gate extern int field; /* input field */ 1387c478bd9Sstevel@tonic-gate extern unsigned fldcolumn; /* input field column */ 1397c478bd9Sstevel@tonic-gate extern int mdisprefs; /* maximum displayed references */ 1407c478bd9Sstevel@tonic-gate extern int selectlen; /* selection number field length */ 1417c478bd9Sstevel@tonic-gate extern int nextline; /* next line to be shown */ 1427c478bd9Sstevel@tonic-gate extern int topline; /* top line of page */ 1437c478bd9Sstevel@tonic-gate extern int bottomline; /* bottom line of page */ 1447c478bd9Sstevel@tonic-gate extern int totallines; /* total reference lines */ 1457c478bd9Sstevel@tonic-gate extern FILE *refsfound; /* references found file */ 1467c478bd9Sstevel@tonic-gate extern FILE *nonglobalrefs; /* non-global references file */ 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate /* exec.c global data */ 1497c478bd9Sstevel@tonic-gate extern pid_t childpid; /* child's process ID */ 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* find.c global data */ 1527c478bd9Sstevel@tonic-gate extern char block[]; /* cross-reference file block */ 1537c478bd9Sstevel@tonic-gate extern int blocklen; /* length of disk block read */ 1547c478bd9Sstevel@tonic-gate extern char blockmark; /* mark character to be searched for */ 1557c478bd9Sstevel@tonic-gate extern long blocknumber; /* block number */ 1567c478bd9Sstevel@tonic-gate extern char *blockp; /* pointer to current character in block */ 1577c478bd9Sstevel@tonic-gate extern char lastfilepath[]; /* last file that full path was computed for */ 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* lookup.c global data */ 1607c478bd9Sstevel@tonic-gate extern struct keystruct { 1617c478bd9Sstevel@tonic-gate char *text; 1627c478bd9Sstevel@tonic-gate char delim; 1637c478bd9Sstevel@tonic-gate KEYWORD type; 1647c478bd9Sstevel@tonic-gate struct keystruct *next; 1657c478bd9Sstevel@tonic-gate } keyword[]; 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* scanner.l global data */ 1687c478bd9Sstevel@tonic-gate extern int first; /* buffer index for first char of symbol */ 1697c478bd9Sstevel@tonic-gate extern int last; /* buffer index for last char of symbol */ 1707c478bd9Sstevel@tonic-gate extern int lineno; /* symbol line number */ 1717c478bd9Sstevel@tonic-gate extern FILE *yyin; /* input file descriptor */ 1727c478bd9Sstevel@tonic-gate extern int yyleng; /* input line length */ 1737c478bd9Sstevel@tonic-gate extern int yylineno; /* input line number */ 1747c478bd9Sstevel@tonic-gate #if hpux 1757c478bd9Sstevel@tonic-gate extern unsigned char yytext[]; /* input line text */ 1767c478bd9Sstevel@tonic-gate #else 1777c478bd9Sstevel@tonic-gate extern char yytext[]; /* input line text */ 1787c478bd9Sstevel@tonic-gate #endif 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* vpinit.c global data */ 1817c478bd9Sstevel@tonic-gate extern char *argv0; /* command name */ 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* cscope functions called from more than one function or between files */ 1847c478bd9Sstevel@tonic-gate /* cgrep.c */ 1857c478bd9Sstevel@tonic-gate void egrepcaseless(int i); 1867c478bd9Sstevel@tonic-gate char *egrepinit(char *expression); 1877c478bd9Sstevel@tonic-gate int egrep(char *f, FILE *o, char *fo); 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate /* command.c */ 1907c478bd9Sstevel@tonic-gate BOOL command(int commandc); 1917c478bd9Sstevel@tonic-gate void clearprompt(void); 1927c478bd9Sstevel@tonic-gate BOOL readrefs(char *filename); 1937c478bd9Sstevel@tonic-gate BOOL changestring(void); 1947c478bd9Sstevel@tonic-gate void mark(int i); 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate /* crossref.c */ 1977c478bd9Sstevel@tonic-gate void crossref(char *srcfile); 1987c478bd9Sstevel@tonic-gate void savesymbol(int token); 1997c478bd9Sstevel@tonic-gate void putfilename(char *srcfile); 2007c478bd9Sstevel@tonic-gate void putposting(char *term, int type); 2017c478bd9Sstevel@tonic-gate void putstring(char *s); 2027c478bd9Sstevel@tonic-gate void warning(char *text); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* dir.c */ 2057c478bd9Sstevel@tonic-gate void sourcedir(char *dirlist); 2067c478bd9Sstevel@tonic-gate void includedir(char *dirlist); 2077c478bd9Sstevel@tonic-gate void makefilelist(void); 2087c478bd9Sstevel@tonic-gate void incfile(char *file, int type); 2097c478bd9Sstevel@tonic-gate BOOL infilelist(char *file); 2107c478bd9Sstevel@tonic-gate void addsrcfile(char *path); 2117c478bd9Sstevel@tonic-gate void freefilelist(void); 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate /* display.c */ 2147c478bd9Sstevel@tonic-gate void dispinit(void); 2157c478bd9Sstevel@tonic-gate void display(void); 2167c478bd9Sstevel@tonic-gate void setfield(void); 2177c478bd9Sstevel@tonic-gate void atfield(void); 2187c478bd9Sstevel@tonic-gate void jumpback(int sig); 2197c478bd9Sstevel@tonic-gate BOOL search(void); 2207c478bd9Sstevel@tonic-gate BOOL writerefsfound(void); 2217c478bd9Sstevel@tonic-gate void countrefs(void); 2227c478bd9Sstevel@tonic-gate void myperror(char *text); 2237c478bd9Sstevel@tonic-gate void putmsg(char *msg); 2247c478bd9Sstevel@tonic-gate void clearmsg2(void); 2257c478bd9Sstevel@tonic-gate void putmsg2(char *msg); 2267c478bd9Sstevel@tonic-gate void seekline(int line); 2277c478bd9Sstevel@tonic-gate void ogsnames(char *file, char **subsystem, char **book); 2287c478bd9Sstevel@tonic-gate char *pathcomponents(char *path, int components); 2297c478bd9Sstevel@tonic-gate void strtoupper(char *s); 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate /* edit.c */ 2327c478bd9Sstevel@tonic-gate void editref(int i); 2337c478bd9Sstevel@tonic-gate void editall(void); 2347c478bd9Sstevel@tonic-gate void edit(char *file, char *linenum); 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate /* find.c */ 2377c478bd9Sstevel@tonic-gate void findsymbol(void); 2387c478bd9Sstevel@tonic-gate void finddef(void); 2397c478bd9Sstevel@tonic-gate void findallfcns(void); 2407c478bd9Sstevel@tonic-gate void findcalledby(void); 2417c478bd9Sstevel@tonic-gate void findcalling(void); 2427c478bd9Sstevel@tonic-gate void findassignments(void); 2437c478bd9Sstevel@tonic-gate char *findgreppat(void); 2447c478bd9Sstevel@tonic-gate char *findegreppat(char *egreppat); 2457c478bd9Sstevel@tonic-gate void findfile(void); 2467c478bd9Sstevel@tonic-gate void findinclude(void); 2477c478bd9Sstevel@tonic-gate FINDINIT findinit(void); 2487c478bd9Sstevel@tonic-gate void findcleanup(void); 2497c478bd9Sstevel@tonic-gate void initprogress(void); 2507c478bd9Sstevel@tonic-gate void progress(char *format, long n1, long n2); 2517c478bd9Sstevel@tonic-gate BOOL match(void); 2527c478bd9Sstevel@tonic-gate BOOL matchrest(void); 2537c478bd9Sstevel@tonic-gate void getstring(char *s); 2547c478bd9Sstevel@tonic-gate char *scanpast(int c); 2557c478bd9Sstevel@tonic-gate char *readblock(void); 2567c478bd9Sstevel@tonic-gate long dbseek(long offset); 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate /* help.c */ 2597c478bd9Sstevel@tonic-gate void help(void); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* history.c */ 2627c478bd9Sstevel@tonic-gate void addcmd(int f, char *s); 2637c478bd9Sstevel@tonic-gate void resetcmd(void); 2647c478bd9Sstevel@tonic-gate HISTORY *currentcmd(void); 2657c478bd9Sstevel@tonic-gate HISTORY *prevcmd(void); 2667c478bd9Sstevel@tonic-gate HISTORY *nextcmd(void); 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate /* input.c */ 2697c478bd9Sstevel@tonic-gate void catchint(int sig); 2707c478bd9Sstevel@tonic-gate int ungetch(int c); 2717c478bd9Sstevel@tonic-gate int mygetch(void); 272*23a1cceaSRoger A. Faulkner int getaline(char s[], size_t size, int firstchar, BOOL iscaseless); 2737c478bd9Sstevel@tonic-gate void askforchar(void); 2747c478bd9Sstevel@tonic-gate void askforreturn(void); 2757c478bd9Sstevel@tonic-gate void shellpath(char *out, int limit, char *in); 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate /* lookup.c */ 2787c478bd9Sstevel@tonic-gate void initsymtab(void); 2797c478bd9Sstevel@tonic-gate struct keystruct *lookup(char *ident); 2807c478bd9Sstevel@tonic-gate int hash(char *s); 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate /* main.c */ 2837c478bd9Sstevel@tonic-gate void rebuild(void); 2847c478bd9Sstevel@tonic-gate void entercurses(void); 2857c478bd9Sstevel@tonic-gate void exitcurses(void); 2867c478bd9Sstevel@tonic-gate void myexit(int sig); 2877c478bd9Sstevel@tonic-gate void cannotopen(char *file); 2887c478bd9Sstevel@tonic-gate void cannotwrite(char *file); 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate /* menu.c */ 2917c478bd9Sstevel@tonic-gate void initmenu(void); 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate extern void initscanner(char *srcfile); 2947c478bd9Sstevel@tonic-gate extern int yylex(void); 2957c478bd9Sstevel@tonic-gate extern int execute(char *, ...); 296