1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * cscope - interactive C symbol cross-reference 28*7c478bd9Sstevel@tonic-gate * 29*7c478bd9Sstevel@tonic-gate * global type, data, and function definitions 30*7c478bd9Sstevel@tonic-gate */ 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 34*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #include <ctype.h> /* isalpha, isdigit, etc. */ 40*7c478bd9Sstevel@tonic-gate #include <signal.h> /* SIGINT and SIGQUIT */ 41*7c478bd9Sstevel@tonic-gate #include <stdio.h> /* standard I/O package */ 42*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 43*7c478bd9Sstevel@tonic-gate #include "constants.h" /* misc. constants */ 44*7c478bd9Sstevel@tonic-gate #include "invlib.h" /* inverted index library */ 45*7c478bd9Sstevel@tonic-gate #include "library.h" /* library function return values */ 46*7c478bd9Sstevel@tonic-gate #include "mouse.h" /* mouse interface */ 47*7c478bd9Sstevel@tonic-gate #define SIGTYPE void 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate typedef enum { /* boolean data type */ 50*7c478bd9Sstevel@tonic-gate NO, 51*7c478bd9Sstevel@tonic-gate YES 52*7c478bd9Sstevel@tonic-gate } BOOL; 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate typedef enum { /* findinit return code */ 55*7c478bd9Sstevel@tonic-gate NOERROR, 56*7c478bd9Sstevel@tonic-gate NOTSYMBOL, 57*7c478bd9Sstevel@tonic-gate REGCMPERROR 58*7c478bd9Sstevel@tonic-gate } FINDINIT; 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate typedef struct history { /* command history */ 61*7c478bd9Sstevel@tonic-gate int field; 62*7c478bd9Sstevel@tonic-gate char *text; 63*7c478bd9Sstevel@tonic-gate struct history *previous; 64*7c478bd9Sstevel@tonic-gate struct history *next; 65*7c478bd9Sstevel@tonic-gate } HISTORY; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate typedef enum { /* keyword type */ 68*7c478bd9Sstevel@tonic-gate DECL, /* type declaration */ 69*7c478bd9Sstevel@tonic-gate FLOW, /* control flow (do, if, for, while, switch, etc.) */ 70*7c478bd9Sstevel@tonic-gate MISC /* misc.: sizeof or table placeholder for compression */ 71*7c478bd9Sstevel@tonic-gate } KEYWORD; 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate /* digraph data for text compression */ 74*7c478bd9Sstevel@tonic-gate extern char dichar1[]; /* 16 most frequent first chars */ 75*7c478bd9Sstevel@tonic-gate extern char dichar2[]; /* 8 most frequent second chars */ 76*7c478bd9Sstevel@tonic-gate /* using the above as first chars */ 77*7c478bd9Sstevel@tonic-gate extern char dicode1[]; /* digraph first character code */ 78*7c478bd9Sstevel@tonic-gate extern char dicode2[]; /* digraph second character code */ 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate /* main.c global data */ 81*7c478bd9Sstevel@tonic-gate extern char *editor, *home, *shell; /* environment variables */ 82*7c478bd9Sstevel@tonic-gate extern BOOL compress; /* compress the characters in the crossref */ 83*7c478bd9Sstevel@tonic-gate extern int cscopedepth; /* cscope invocation nesting depth */ 84*7c478bd9Sstevel@tonic-gate extern char currentdir[]; /* current directory */ 85*7c478bd9Sstevel@tonic-gate extern BOOL dbtruncated; /* database symbols are truncated to 8 chars */ 86*7c478bd9Sstevel@tonic-gate extern char **dbvpdirs; /* directories (including current) in */ 87*7c478bd9Sstevel@tonic-gate /* database view path */ 88*7c478bd9Sstevel@tonic-gate extern int dbvpndirs; /* number of directories in database */ 89*7c478bd9Sstevel@tonic-gate /* view path */ 90*7c478bd9Sstevel@tonic-gate extern int dispcomponents; /* file path components to display */ 91*7c478bd9Sstevel@tonic-gate extern BOOL editallprompt; /* prompt between editing files */ 92*7c478bd9Sstevel@tonic-gate extern int fileargc; /* file argument count */ 93*7c478bd9Sstevel@tonic-gate extern char **fileargv; /* file argument values */ 94*7c478bd9Sstevel@tonic-gate extern int fileversion; /* cross-reference file version */ 95*7c478bd9Sstevel@tonic-gate extern BOOL incurses; /* in curses */ 96*7c478bd9Sstevel@tonic-gate extern INVCONTROL invcontrol; /* inverted file control structure */ 97*7c478bd9Sstevel@tonic-gate extern BOOL invertedindex; /* the database has an inverted index */ 98*7c478bd9Sstevel@tonic-gate extern BOOL isuptodate; /* consider the crossref up-to-date */ 99*7c478bd9Sstevel@tonic-gate extern BOOL linemode; /* use line oriented user interface */ 100*7c478bd9Sstevel@tonic-gate extern char *namefile; /* file of file names */ 101*7c478bd9Sstevel@tonic-gate extern char *newreffile; /* new cross-reference file name */ 102*7c478bd9Sstevel@tonic-gate extern FILE *newrefs; /* new cross-reference */ 103*7c478bd9Sstevel@tonic-gate extern BOOL noacttimeout; /* no activity timeout occurred */ 104*7c478bd9Sstevel@tonic-gate extern BOOL ogs; /* display OGS book and subsystem names */ 105*7c478bd9Sstevel@tonic-gate extern FILE *postings; /* new inverted index postings */ 106*7c478bd9Sstevel@tonic-gate extern char *prependpath; /* prepend path to file names */ 107*7c478bd9Sstevel@tonic-gate extern BOOL returnrequired; /* RETURN required after selection number */ 108*7c478bd9Sstevel@tonic-gate extern int symrefs; /* cross-reference file */ 109*7c478bd9Sstevel@tonic-gate extern char temp1[]; /* temporary file name */ 110*7c478bd9Sstevel@tonic-gate extern char temp2[]; /* temporary file name */ 111*7c478bd9Sstevel@tonic-gate extern long totalterms; /* total inverted index terms */ 112*7c478bd9Sstevel@tonic-gate extern BOOL truncatesyms; /* truncate symbols to 8 characters */ 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /* command.c global data */ 115*7c478bd9Sstevel@tonic-gate extern BOOL caseless; /* ignore letter case when searching */ 116*7c478bd9Sstevel@tonic-gate extern BOOL *change; /* change this line */ 117*7c478bd9Sstevel@tonic-gate extern BOOL changing; /* changing text */ 118*7c478bd9Sstevel@tonic-gate extern char newpat[]; /* new pattern */ 119*7c478bd9Sstevel@tonic-gate extern char pattern[]; /* symbol or text pattern */ 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate /* crossref.c global data */ 122*7c478bd9Sstevel@tonic-gate extern long dboffset; /* new database offset */ 123*7c478bd9Sstevel@tonic-gate extern BOOL errorsfound; /* prompt before clearing error messages */ 124*7c478bd9Sstevel@tonic-gate extern long fileindex; /* source file name index */ 125*7c478bd9Sstevel@tonic-gate extern long lineoffset; /* source line database offset */ 126*7c478bd9Sstevel@tonic-gate extern long npostings; /* number of postings */ 127*7c478bd9Sstevel@tonic-gate extern int symbols; /* number of symbols */ 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate /* dir.c global data */ 130*7c478bd9Sstevel@tonic-gate extern char **incdirs; /* #include directories */ 131*7c478bd9Sstevel@tonic-gate extern char **srcdirs; /* source directories */ 132*7c478bd9Sstevel@tonic-gate extern char **srcfiles; /* source files */ 133*7c478bd9Sstevel@tonic-gate extern int nincdirs; /* number of #include directories */ 134*7c478bd9Sstevel@tonic-gate extern int nsrcdirs; /* number of source directories */ 135*7c478bd9Sstevel@tonic-gate extern int nsrcfiles; /* number of source files */ 136*7c478bd9Sstevel@tonic-gate extern int msrcfiles; /* maximum number of source files */ 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate /* display.c global data */ 139*7c478bd9Sstevel@tonic-gate extern int *displine; /* screen line of displayed reference */ 140*7c478bd9Sstevel@tonic-gate extern int disprefs; /* displayed references */ 141*7c478bd9Sstevel@tonic-gate extern int field; /* input field */ 142*7c478bd9Sstevel@tonic-gate extern unsigned fldcolumn; /* input field column */ 143*7c478bd9Sstevel@tonic-gate extern int mdisprefs; /* maximum displayed references */ 144*7c478bd9Sstevel@tonic-gate extern int selectlen; /* selection number field length */ 145*7c478bd9Sstevel@tonic-gate extern int nextline; /* next line to be shown */ 146*7c478bd9Sstevel@tonic-gate extern int topline; /* top line of page */ 147*7c478bd9Sstevel@tonic-gate extern int bottomline; /* bottom line of page */ 148*7c478bd9Sstevel@tonic-gate extern int totallines; /* total reference lines */ 149*7c478bd9Sstevel@tonic-gate extern FILE *refsfound; /* references found file */ 150*7c478bd9Sstevel@tonic-gate extern FILE *nonglobalrefs; /* non-global references file */ 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate /* exec.c global data */ 153*7c478bd9Sstevel@tonic-gate extern pid_t childpid; /* child's process ID */ 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate /* find.c global data */ 156*7c478bd9Sstevel@tonic-gate extern char block[]; /* cross-reference file block */ 157*7c478bd9Sstevel@tonic-gate extern int blocklen; /* length of disk block read */ 158*7c478bd9Sstevel@tonic-gate extern char blockmark; /* mark character to be searched for */ 159*7c478bd9Sstevel@tonic-gate extern long blocknumber; /* block number */ 160*7c478bd9Sstevel@tonic-gate extern char *blockp; /* pointer to current character in block */ 161*7c478bd9Sstevel@tonic-gate extern char lastfilepath[]; /* last file that full path was computed for */ 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate /* lookup.c global data */ 164*7c478bd9Sstevel@tonic-gate extern struct keystruct { 165*7c478bd9Sstevel@tonic-gate char *text; 166*7c478bd9Sstevel@tonic-gate char delim; 167*7c478bd9Sstevel@tonic-gate KEYWORD type; 168*7c478bd9Sstevel@tonic-gate struct keystruct *next; 169*7c478bd9Sstevel@tonic-gate } keyword[]; 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate /* scanner.l global data */ 172*7c478bd9Sstevel@tonic-gate extern int first; /* buffer index for first char of symbol */ 173*7c478bd9Sstevel@tonic-gate extern int last; /* buffer index for last char of symbol */ 174*7c478bd9Sstevel@tonic-gate extern int lineno; /* symbol line number */ 175*7c478bd9Sstevel@tonic-gate extern FILE *yyin; /* input file descriptor */ 176*7c478bd9Sstevel@tonic-gate extern int yyleng; /* input line length */ 177*7c478bd9Sstevel@tonic-gate extern int yylineno; /* input line number */ 178*7c478bd9Sstevel@tonic-gate #if hpux 179*7c478bd9Sstevel@tonic-gate extern unsigned char yytext[]; /* input line text */ 180*7c478bd9Sstevel@tonic-gate #else 181*7c478bd9Sstevel@tonic-gate extern char yytext[]; /* input line text */ 182*7c478bd9Sstevel@tonic-gate #endif 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate /* vpinit.c global data */ 185*7c478bd9Sstevel@tonic-gate extern char *argv0; /* command name */ 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate /* cscope functions called from more than one function or between files */ 188*7c478bd9Sstevel@tonic-gate /* cgrep.c */ 189*7c478bd9Sstevel@tonic-gate void egrepcaseless(int i); 190*7c478bd9Sstevel@tonic-gate char *egrepinit(char *expression); 191*7c478bd9Sstevel@tonic-gate int egrep(char *f, FILE *o, char *fo); 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate /* command.c */ 194*7c478bd9Sstevel@tonic-gate BOOL command(int commandc); 195*7c478bd9Sstevel@tonic-gate void clearprompt(void); 196*7c478bd9Sstevel@tonic-gate BOOL readrefs(char *filename); 197*7c478bd9Sstevel@tonic-gate BOOL changestring(void); 198*7c478bd9Sstevel@tonic-gate void mark(int i); 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate /* crossref.c */ 201*7c478bd9Sstevel@tonic-gate void crossref(char *srcfile); 202*7c478bd9Sstevel@tonic-gate void savesymbol(int token); 203*7c478bd9Sstevel@tonic-gate void putfilename(char *srcfile); 204*7c478bd9Sstevel@tonic-gate void putposting(char *term, int type); 205*7c478bd9Sstevel@tonic-gate void putstring(char *s); 206*7c478bd9Sstevel@tonic-gate void warning(char *text); 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate /* dir.c */ 209*7c478bd9Sstevel@tonic-gate void sourcedir(char *dirlist); 210*7c478bd9Sstevel@tonic-gate void includedir(char *dirlist); 211*7c478bd9Sstevel@tonic-gate void makefilelist(void); 212*7c478bd9Sstevel@tonic-gate void incfile(char *file, int type); 213*7c478bd9Sstevel@tonic-gate BOOL infilelist(char *file); 214*7c478bd9Sstevel@tonic-gate void addsrcfile(char *path); 215*7c478bd9Sstevel@tonic-gate void freefilelist(void); 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate /* display.c */ 218*7c478bd9Sstevel@tonic-gate void dispinit(void); 219*7c478bd9Sstevel@tonic-gate void display(void); 220*7c478bd9Sstevel@tonic-gate void setfield(void); 221*7c478bd9Sstevel@tonic-gate void atfield(void); 222*7c478bd9Sstevel@tonic-gate void jumpback(int sig); 223*7c478bd9Sstevel@tonic-gate BOOL search(void); 224*7c478bd9Sstevel@tonic-gate BOOL writerefsfound(void); 225*7c478bd9Sstevel@tonic-gate void countrefs(void); 226*7c478bd9Sstevel@tonic-gate void myperror(char *text); 227*7c478bd9Sstevel@tonic-gate void putmsg(char *msg); 228*7c478bd9Sstevel@tonic-gate void clearmsg2(void); 229*7c478bd9Sstevel@tonic-gate void putmsg2(char *msg); 230*7c478bd9Sstevel@tonic-gate void seekline(int line); 231*7c478bd9Sstevel@tonic-gate void ogsnames(char *file, char **subsystem, char **book); 232*7c478bd9Sstevel@tonic-gate char *pathcomponents(char *path, int components); 233*7c478bd9Sstevel@tonic-gate void strtoupper(char *s); 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate /* edit.c */ 236*7c478bd9Sstevel@tonic-gate void editref(int i); 237*7c478bd9Sstevel@tonic-gate void editall(void); 238*7c478bd9Sstevel@tonic-gate void edit(char *file, char *linenum); 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate /* find.c */ 241*7c478bd9Sstevel@tonic-gate void findsymbol(void); 242*7c478bd9Sstevel@tonic-gate void finddef(void); 243*7c478bd9Sstevel@tonic-gate void findallfcns(void); 244*7c478bd9Sstevel@tonic-gate void findcalledby(void); 245*7c478bd9Sstevel@tonic-gate void findcalling(void); 246*7c478bd9Sstevel@tonic-gate void findassignments(void); 247*7c478bd9Sstevel@tonic-gate char *findgreppat(void); 248*7c478bd9Sstevel@tonic-gate char *findegreppat(char *egreppat); 249*7c478bd9Sstevel@tonic-gate void findfile(void); 250*7c478bd9Sstevel@tonic-gate void findinclude(void); 251*7c478bd9Sstevel@tonic-gate FINDINIT findinit(void); 252*7c478bd9Sstevel@tonic-gate void findcleanup(void); 253*7c478bd9Sstevel@tonic-gate void initprogress(void); 254*7c478bd9Sstevel@tonic-gate void progress(char *format, long n1, long n2); 255*7c478bd9Sstevel@tonic-gate BOOL match(void); 256*7c478bd9Sstevel@tonic-gate BOOL matchrest(void); 257*7c478bd9Sstevel@tonic-gate void getstring(char *s); 258*7c478bd9Sstevel@tonic-gate char *scanpast(int c); 259*7c478bd9Sstevel@tonic-gate char *readblock(void); 260*7c478bd9Sstevel@tonic-gate long dbseek(long offset); 261*7c478bd9Sstevel@tonic-gate 262*7c478bd9Sstevel@tonic-gate /* help.c */ 263*7c478bd9Sstevel@tonic-gate void help(void); 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate /* history.c */ 266*7c478bd9Sstevel@tonic-gate void addcmd(int f, char *s); 267*7c478bd9Sstevel@tonic-gate void resetcmd(void); 268*7c478bd9Sstevel@tonic-gate HISTORY *currentcmd(void); 269*7c478bd9Sstevel@tonic-gate HISTORY *prevcmd(void); 270*7c478bd9Sstevel@tonic-gate HISTORY *nextcmd(void); 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate /* input.c */ 273*7c478bd9Sstevel@tonic-gate void catchint(int sig); 274*7c478bd9Sstevel@tonic-gate int ungetch(int c); 275*7c478bd9Sstevel@tonic-gate int mygetch(void); 276*7c478bd9Sstevel@tonic-gate int getline(char s[], size_t size, int firstchar, BOOL iscaseless); 277*7c478bd9Sstevel@tonic-gate void askforchar(void); 278*7c478bd9Sstevel@tonic-gate void askforreturn(void); 279*7c478bd9Sstevel@tonic-gate void shellpath(char *out, int limit, char *in); 280*7c478bd9Sstevel@tonic-gate 281*7c478bd9Sstevel@tonic-gate /* lookup.c */ 282*7c478bd9Sstevel@tonic-gate void initsymtab(void); 283*7c478bd9Sstevel@tonic-gate struct keystruct *lookup(char *ident); 284*7c478bd9Sstevel@tonic-gate int hash(char *s); 285*7c478bd9Sstevel@tonic-gate 286*7c478bd9Sstevel@tonic-gate /* main.c */ 287*7c478bd9Sstevel@tonic-gate void rebuild(void); 288*7c478bd9Sstevel@tonic-gate void entercurses(void); 289*7c478bd9Sstevel@tonic-gate void exitcurses(void); 290*7c478bd9Sstevel@tonic-gate void myexit(int sig); 291*7c478bd9Sstevel@tonic-gate void cannotopen(char *file); 292*7c478bd9Sstevel@tonic-gate void cannotwrite(char *file); 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate /* menu.c */ 295*7c478bd9Sstevel@tonic-gate void initmenu(void); 296*7c478bd9Sstevel@tonic-gate 297*7c478bd9Sstevel@tonic-gate extern void initscanner(char *srcfile); 298*7c478bd9Sstevel@tonic-gate extern int yylex(void); 299*7c478bd9Sstevel@tonic-gate extern int execute(char *, ...); 300