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