1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
23*0Sstevel@tonic-gate /* All Rights Reserved */
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28*0Sstevel@tonic-gate * Use is subject to license terms.
29*0Sstevel@tonic-gate */
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate /*
34*0Sstevel@tonic-gate * cscope - interactive C symbol cross-reference
35*0Sstevel@tonic-gate *
36*0Sstevel@tonic-gate * build cross-reference file
37*0Sstevel@tonic-gate */
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate #include "global.h"
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate /* convert long to a string */
42*0Sstevel@tonic-gate #define ltobase(value) n = value; \
43*0Sstevel@tonic-gate s = buf + (sizeof (buf) - 1); \
44*0Sstevel@tonic-gate *s = '\0'; \
45*0Sstevel@tonic-gate digits = 1; \
46*0Sstevel@tonic-gate while (n >= BASE) { \
47*0Sstevel@tonic-gate ++digits; \
48*0Sstevel@tonic-gate i = n; \
49*0Sstevel@tonic-gate n /= BASE; \
50*0Sstevel@tonic-gate *--s = i - n * BASE + '!'; \
51*0Sstevel@tonic-gate } \
52*0Sstevel@tonic-gate *--s = n + '!';
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate #define SYMBOLINC 20 /* symbol list size increment */
55*0Sstevel@tonic-gate #define FREAD "r" /* fopen for reading */
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate long dboffset; /* new database offset */
58*0Sstevel@tonic-gate BOOL errorsfound; /* prompt before clearing messages */
59*0Sstevel@tonic-gate long fileindex; /* source file name index */
60*0Sstevel@tonic-gate long lineoffset; /* source line database offset */
61*0Sstevel@tonic-gate long npostings; /* number of postings */
62*0Sstevel@tonic-gate int nsrcoffset; /* number of file name database offsets */
63*0Sstevel@tonic-gate long *srcoffset; /* source file name database offsets */
64*0Sstevel@tonic-gate int symbols; /* number of symbols */
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate static char *filename; /* file name for warning messages */
67*0Sstevel@tonic-gate static long fcnoffset; /* function name database offset */
68*0Sstevel@tonic-gate static long macrooffset; /* macro name database offset */
69*0Sstevel@tonic-gate static int msymbols = SYMBOLINC; /* maximum number of symbols */
70*0Sstevel@tonic-gate static struct symbol { /* symbol data */
71*0Sstevel@tonic-gate int type; /* type */
72*0Sstevel@tonic-gate int first; /* index of first character in text */
73*0Sstevel@tonic-gate int last; /* index of last+1 character in text */
74*0Sstevel@tonic-gate int length; /* symbol length */
75*0Sstevel@tonic-gate } *symbol;
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate static void putcrossref(void);
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate void
crossref(char * srcfile)80*0Sstevel@tonic-gate crossref(char *srcfile)
81*0Sstevel@tonic-gate {
82*0Sstevel@tonic-gate int i;
83*0Sstevel@tonic-gate int length; /* symbol length */
84*0Sstevel@tonic-gate int token; /* current token */
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate /* open the source file */
87*0Sstevel@tonic-gate if ((yyin = vpfopen(srcfile, FREAD)) == NULL) {
88*0Sstevel@tonic-gate cannotopen(srcfile);
89*0Sstevel@tonic-gate errorsfound = YES;
90*0Sstevel@tonic-gate return;
91*0Sstevel@tonic-gate }
92*0Sstevel@tonic-gate filename = srcfile; /* save the file name for warning messages */
93*0Sstevel@tonic-gate putfilename(srcfile); /* output the file name */
94*0Sstevel@tonic-gate dbputc('\n');
95*0Sstevel@tonic-gate dbputc('\n');
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate /* read the source file */
98*0Sstevel@tonic-gate initscanner(srcfile);
99*0Sstevel@tonic-gate fcnoffset = macrooffset = 0;
100*0Sstevel@tonic-gate symbols = 0;
101*0Sstevel@tonic-gate if (symbol == NULL) {
102*0Sstevel@tonic-gate symbol = mymalloc(msymbols * sizeof (struct symbol));
103*0Sstevel@tonic-gate }
104*0Sstevel@tonic-gate for (;;) {
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate /* get the next token */
107*0Sstevel@tonic-gate switch (token = yylex()) {
108*0Sstevel@tonic-gate default:
109*0Sstevel@tonic-gate /* if requested, truncate C symbols */
110*0Sstevel@tonic-gate length = last - first;
111*0Sstevel@tonic-gate if (truncatesyms && length > 8 &&
112*0Sstevel@tonic-gate token != INCLUDE && token != NEWFILE) {
113*0Sstevel@tonic-gate length = 8;
114*0Sstevel@tonic-gate last = first + 8;
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate /* see if the token has a symbol */
117*0Sstevel@tonic-gate if (length == 0) {
118*0Sstevel@tonic-gate savesymbol(token);
119*0Sstevel@tonic-gate break;
120*0Sstevel@tonic-gate }
121*0Sstevel@tonic-gate /* see if the symbol is already in the list */
122*0Sstevel@tonic-gate for (i = 0; i < symbols; ++i) {
123*0Sstevel@tonic-gate if (length == symbol[i].length &&
124*0Sstevel@tonic-gate strncmp(yytext + first, yytext +
125*0Sstevel@tonic-gate symbol[i].first, length) == 0 &&
126*0Sstevel@tonic-gate (token == IDENT ||
127*0Sstevel@tonic-gate token == symbol[i].type)) {
128*0Sstevel@tonic-gate first = yyleng;
129*0Sstevel@tonic-gate break;
130*0Sstevel@tonic-gate }
131*0Sstevel@tonic-gate }
132*0Sstevel@tonic-gate if (i == symbols) { /* if not already in list */
133*0Sstevel@tonic-gate savesymbol(token);
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate break;
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate case NEWLINE: /* end of line containing symbols */
138*0Sstevel@tonic-gate --yyleng; /* remove the newline */
139*0Sstevel@tonic-gate putcrossref(); /* output the symbols and source line */
140*0Sstevel@tonic-gate lineno = yylineno; /* save the symbol line number */
141*0Sstevel@tonic-gate break;
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate case LEXEOF: /* end of file; last line may not have \n */
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate /*
146*0Sstevel@tonic-gate * if there were symbols, output them and the
147*0Sstevel@tonic-gate * source line
148*0Sstevel@tonic-gate */
149*0Sstevel@tonic-gate if (symbols > 0) {
150*0Sstevel@tonic-gate putcrossref();
151*0Sstevel@tonic-gate }
152*0Sstevel@tonic-gate (void) fclose(yyin); /* close the source file */
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate /* output the leading tab expected by the next call */
155*0Sstevel@tonic-gate dbputc('\t');
156*0Sstevel@tonic-gate return;
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate }
159*0Sstevel@tonic-gate }
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate /* save the symbol in the list */
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate void
savesymbol(int token)164*0Sstevel@tonic-gate savesymbol(int token)
165*0Sstevel@tonic-gate {
166*0Sstevel@tonic-gate /* make sure there is room for the symbol */
167*0Sstevel@tonic-gate if (symbols == msymbols) {
168*0Sstevel@tonic-gate msymbols += SYMBOLINC;
169*0Sstevel@tonic-gate symbol = (struct symbol *)myrealloc(symbol,
170*0Sstevel@tonic-gate msymbols * sizeof (struct symbol));
171*0Sstevel@tonic-gate }
172*0Sstevel@tonic-gate /* save the symbol */
173*0Sstevel@tonic-gate symbol[symbols].type = token;
174*0Sstevel@tonic-gate symbol[symbols].first = first;
175*0Sstevel@tonic-gate symbol[symbols].last = last;
176*0Sstevel@tonic-gate symbol[symbols].length = last - first;
177*0Sstevel@tonic-gate ++symbols;
178*0Sstevel@tonic-gate first = yyleng;
179*0Sstevel@tonic-gate }
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate /* output the file name */
182*0Sstevel@tonic-gate
183*0Sstevel@tonic-gate void
putfilename(char * srcfile)184*0Sstevel@tonic-gate putfilename(char *srcfile)
185*0Sstevel@tonic-gate {
186*0Sstevel@tonic-gate /* check for file system out of space */
187*0Sstevel@tonic-gate /* note: dbputc is not used to avoid lint complaint */
188*0Sstevel@tonic-gate if (putc(NEWFILE, newrefs) == EOF) {
189*0Sstevel@tonic-gate cannotwrite(newreffile);
190*0Sstevel@tonic-gate /* NOTREACHED */
191*0Sstevel@tonic-gate }
192*0Sstevel@tonic-gate ++dboffset;
193*0Sstevel@tonic-gate if (invertedindex) {
194*0Sstevel@tonic-gate srcoffset[nsrcoffset++] = dboffset;
195*0Sstevel@tonic-gate }
196*0Sstevel@tonic-gate dbfputs(srcfile);
197*0Sstevel@tonic-gate fcnoffset = macrooffset = 0;
198*0Sstevel@tonic-gate }
199*0Sstevel@tonic-gate
200*0Sstevel@tonic-gate /* output the symbols and source line */
201*0Sstevel@tonic-gate
202*0Sstevel@tonic-gate static void
putcrossref(void)203*0Sstevel@tonic-gate putcrossref(void)
204*0Sstevel@tonic-gate {
205*0Sstevel@tonic-gate int i, j;
206*0Sstevel@tonic-gate unsigned c;
207*0Sstevel@tonic-gate BOOL blank = NO; /* output blank */
208*0Sstevel@tonic-gate BOOL newline = NO; /* output newline */
209*0Sstevel@tonic-gate int symput = 0; /* symbols output */
210*0Sstevel@tonic-gate int type;
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate /* output the source line */
213*0Sstevel@tonic-gate lineoffset = dboffset;
214*0Sstevel@tonic-gate dbfprintf(newrefs, "%d ", lineno);
215*0Sstevel@tonic-gate for (i = 0; i < yyleng; ++i) {
216*0Sstevel@tonic-gate
217*0Sstevel@tonic-gate /* change a tab to a blank and compress blanks */
218*0Sstevel@tonic-gate if ((c = yytext[i]) == ' ' || c == '\t') {
219*0Sstevel@tonic-gate blank = YES;
220*0Sstevel@tonic-gate }
221*0Sstevel@tonic-gate /* look for the start of a symbol */
222*0Sstevel@tonic-gate else if (symput < symbols && i == symbol[symput].first) {
223*0Sstevel@tonic-gate
224*0Sstevel@tonic-gate /* check for compressed blanks */
225*0Sstevel@tonic-gate if (blank) {
226*0Sstevel@tonic-gate blank = NO;
227*0Sstevel@tonic-gate if (newline) {
228*0Sstevel@tonic-gate dbputc('\n');
229*0Sstevel@tonic-gate }
230*0Sstevel@tonic-gate dbputc(' ');
231*0Sstevel@tonic-gate }
232*0Sstevel@tonic-gate dbputc('\n'); /* symbols start on a new line */
233*0Sstevel@tonic-gate
234*0Sstevel@tonic-gate /* output any symbol type */
235*0Sstevel@tonic-gate if ((type = symbol[symput].type) != IDENT) {
236*0Sstevel@tonic-gate dbputc('\t');
237*0Sstevel@tonic-gate dbputc(type);
238*0Sstevel@tonic-gate } else {
239*0Sstevel@tonic-gate type = ' ';
240*0Sstevel@tonic-gate }
241*0Sstevel@tonic-gate /* output the symbol */
242*0Sstevel@tonic-gate j = symbol[symput].last;
243*0Sstevel@tonic-gate c = yytext[j];
244*0Sstevel@tonic-gate yytext[j] = '\0';
245*0Sstevel@tonic-gate if (invertedindex) {
246*0Sstevel@tonic-gate putposting(yytext + i, type);
247*0Sstevel@tonic-gate }
248*0Sstevel@tonic-gate putstring(yytext + i);
249*0Sstevel@tonic-gate newline = YES;
250*0Sstevel@tonic-gate yytext[j] = (char)c;
251*0Sstevel@tonic-gate i = j - 1;
252*0Sstevel@tonic-gate ++symput;
253*0Sstevel@tonic-gate } else {
254*0Sstevel@tonic-gate if (newline) {
255*0Sstevel@tonic-gate newline = NO;
256*0Sstevel@tonic-gate dbputc('\n');
257*0Sstevel@tonic-gate }
258*0Sstevel@tonic-gate /* check for compressed blanks */
259*0Sstevel@tonic-gate if (blank) {
260*0Sstevel@tonic-gate if (dicode2[c]) {
261*0Sstevel@tonic-gate c = (0200 - 2) + dicode1[' '] +
262*0Sstevel@tonic-gate dicode2[c];
263*0Sstevel@tonic-gate } else {
264*0Sstevel@tonic-gate dbputc(' ');
265*0Sstevel@tonic-gate }
266*0Sstevel@tonic-gate } else if (dicode1[c] &&
267*0Sstevel@tonic-gate (j = dicode2[(unsigned)yytext[i + 1]]) != 0 &&
268*0Sstevel@tonic-gate symput < symbols && i + 1 != symbol[symput].first) {
269*0Sstevel@tonic-gate /* compress digraphs */
270*0Sstevel@tonic-gate c = (0200 - 2) + dicode1[c] + j;
271*0Sstevel@tonic-gate ++i;
272*0Sstevel@tonic-gate }
273*0Sstevel@tonic-gate /*
274*0Sstevel@tonic-gate * if the last line of the file is a '}' without a
275*0Sstevel@tonic-gate * newline, the lex EOF code overwrites it with a 0
276*0Sstevel@tonic-gate */
277*0Sstevel@tonic-gate if (c) {
278*0Sstevel@tonic-gate dbputc((int)c);
279*0Sstevel@tonic-gate } else {
280*0Sstevel@tonic-gate dbputc(' ');
281*0Sstevel@tonic-gate }
282*0Sstevel@tonic-gate blank = NO;
283*0Sstevel@tonic-gate
284*0Sstevel@tonic-gate /* skip compressed characters */
285*0Sstevel@tonic-gate if (c < ' ') {
286*0Sstevel@tonic-gate ++i;
287*0Sstevel@tonic-gate
288*0Sstevel@tonic-gate /* skip blanks before a preprocesor keyword */
289*0Sstevel@tonic-gate /*
290*0Sstevel@tonic-gate * note: don't use isspace() because \f and \v
291*0Sstevel@tonic-gate * are used for keywords
292*0Sstevel@tonic-gate */
293*0Sstevel@tonic-gate while ((j = yytext[i]) == ' ' || j == '\t') {
294*0Sstevel@tonic-gate ++i;
295*0Sstevel@tonic-gate }
296*0Sstevel@tonic-gate /* skip the rest of the keyword */
297*0Sstevel@tonic-gate while (isalpha(yytext[i])) {
298*0Sstevel@tonic-gate ++i;
299*0Sstevel@tonic-gate }
300*0Sstevel@tonic-gate /* skip space after certain keywords */
301*0Sstevel@tonic-gate if (keyword[c].delim != '\0') {
302*0Sstevel@tonic-gate while ((j = yytext[i]) == ' ' ||
303*0Sstevel@tonic-gate j == '\t') {
304*0Sstevel@tonic-gate ++i;
305*0Sstevel@tonic-gate }
306*0Sstevel@tonic-gate }
307*0Sstevel@tonic-gate /* skip a '(' after certain keywords */
308*0Sstevel@tonic-gate if (keyword[c].delim == '(' &&
309*0Sstevel@tonic-gate yytext[i] == '(') {
310*0Sstevel@tonic-gate ++i;
311*0Sstevel@tonic-gate }
312*0Sstevel@tonic-gate --i; /* compensate for ++i in for() */
313*0Sstevel@tonic-gate }
314*0Sstevel@tonic-gate }
315*0Sstevel@tonic-gate }
316*0Sstevel@tonic-gate /* ignore trailing blanks */
317*0Sstevel@tonic-gate dbputc('\n');
318*0Sstevel@tonic-gate dbputc('\n');
319*0Sstevel@tonic-gate
320*0Sstevel@tonic-gate /* output any #define end marker */
321*0Sstevel@tonic-gate /*
322*0Sstevel@tonic-gate * note: must not be part of #define so putsource() doesn't discard it
323*0Sstevel@tonic-gate * so findcalledbysub() can find it and return
324*0Sstevel@tonic-gate */
325*0Sstevel@tonic-gate if (symput < symbols && symbol[symput].type == DEFINEEND) {
326*0Sstevel@tonic-gate dbputc('\t');
327*0Sstevel@tonic-gate dbputc(DEFINEEND);
328*0Sstevel@tonic-gate dbputc('\n');
329*0Sstevel@tonic-gate dbputc('\n'); /* mark beginning of next source line */
330*0Sstevel@tonic-gate macrooffset = 0;
331*0Sstevel@tonic-gate }
332*0Sstevel@tonic-gate symbols = 0;
333*0Sstevel@tonic-gate }
334*0Sstevel@tonic-gate
335*0Sstevel@tonic-gate /* output the inverted index posting */
336*0Sstevel@tonic-gate
337*0Sstevel@tonic-gate void
putposting(char * term,int type)338*0Sstevel@tonic-gate putposting(char *term, int type)
339*0Sstevel@tonic-gate {
340*0Sstevel@tonic-gate long i, n;
341*0Sstevel@tonic-gate char *s;
342*0Sstevel@tonic-gate int digits; /* digits output */
343*0Sstevel@tonic-gate long offset; /* function/macro database offset */
344*0Sstevel@tonic-gate char buf[11]; /* number buffer */
345*0Sstevel@tonic-gate
346*0Sstevel@tonic-gate /* get the function or macro name offset */
347*0Sstevel@tonic-gate offset = fcnoffset;
348*0Sstevel@tonic-gate if (macrooffset != 0) {
349*0Sstevel@tonic-gate offset = macrooffset;
350*0Sstevel@tonic-gate }
351*0Sstevel@tonic-gate /* then update them to avoid negative relative name offset */
352*0Sstevel@tonic-gate switch (type) {
353*0Sstevel@tonic-gate case DEFINE:
354*0Sstevel@tonic-gate macrooffset = dboffset;
355*0Sstevel@tonic-gate break;
356*0Sstevel@tonic-gate case DEFINEEND:
357*0Sstevel@tonic-gate macrooffset = 0;
358*0Sstevel@tonic-gate return; /* null term */
359*0Sstevel@tonic-gate case FCNDEF:
360*0Sstevel@tonic-gate fcnoffset = dboffset;
361*0Sstevel@tonic-gate break;
362*0Sstevel@tonic-gate case FCNEND:
363*0Sstevel@tonic-gate fcnoffset = 0;
364*0Sstevel@tonic-gate return; /* null term */
365*0Sstevel@tonic-gate }
366*0Sstevel@tonic-gate /* ignore a null term caused by a enum/struct/union without a tag */
367*0Sstevel@tonic-gate if (*term == '\0') {
368*0Sstevel@tonic-gate return;
369*0Sstevel@tonic-gate }
370*0Sstevel@tonic-gate /* skip any #include secondary type char (< or ") */
371*0Sstevel@tonic-gate if (type == INCLUDE) {
372*0Sstevel@tonic-gate ++term;
373*0Sstevel@tonic-gate }
374*0Sstevel@tonic-gate /*
375*0Sstevel@tonic-gate * output the posting, which should be as small as possible to reduce
376*0Sstevel@tonic-gate * the temp file size and sort time
377*0Sstevel@tonic-gate */
378*0Sstevel@tonic-gate (void) fputs(term, postings);
379*0Sstevel@tonic-gate (void) putc(' ', postings);
380*0Sstevel@tonic-gate
381*0Sstevel@tonic-gate /*
382*0Sstevel@tonic-gate * the line offset is padded so postings for the same term will sort
383*0Sstevel@tonic-gate * in ascending line offset order to order the references as they
384*0Sstevel@tonic-gate * appear withing a source file
385*0Sstevel@tonic-gate */
386*0Sstevel@tonic-gate ltobase(lineoffset);
387*0Sstevel@tonic-gate for (i = PRECISION - digits; i > 0; --i) {
388*0Sstevel@tonic-gate (void) putc('!', postings);
389*0Sstevel@tonic-gate }
390*0Sstevel@tonic-gate do {
391*0Sstevel@tonic-gate (void) putc(*s, postings);
392*0Sstevel@tonic-gate } while (*++s != '\0');
393*0Sstevel@tonic-gate
394*0Sstevel@tonic-gate /* postings are also sorted by type */
395*0Sstevel@tonic-gate (void) putc(type, postings);
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate /* function or macro name offset */
398*0Sstevel@tonic-gate if (offset > 0) {
399*0Sstevel@tonic-gate (void) putc(' ', postings);
400*0Sstevel@tonic-gate ltobase(offset);
401*0Sstevel@tonic-gate do {
402*0Sstevel@tonic-gate (void) putc(*s, postings);
403*0Sstevel@tonic-gate } while (*++s != '\0');
404*0Sstevel@tonic-gate }
405*0Sstevel@tonic-gate if (putc('\n', postings) == EOF) {
406*0Sstevel@tonic-gate cannotwrite(temp1);
407*0Sstevel@tonic-gate /* NOTREACHED */
408*0Sstevel@tonic-gate }
409*0Sstevel@tonic-gate ++npostings;
410*0Sstevel@tonic-gate }
411*0Sstevel@tonic-gate
412*0Sstevel@tonic-gate /* put the string into the new database */
413*0Sstevel@tonic-gate
414*0Sstevel@tonic-gate void
putstring(char * s)415*0Sstevel@tonic-gate putstring(char *s)
416*0Sstevel@tonic-gate {
417*0Sstevel@tonic-gate unsigned c;
418*0Sstevel@tonic-gate int i;
419*0Sstevel@tonic-gate
420*0Sstevel@tonic-gate /* compress digraphs */
421*0Sstevel@tonic-gate for (i = 0; (c = s[i]) != '\0'; ++i) {
422*0Sstevel@tonic-gate if (dicode1[c] && dicode2[(unsigned)s[i + 1]]) {
423*0Sstevel@tonic-gate c = (0200 - 2) + dicode1[c] +
424*0Sstevel@tonic-gate dicode2[(unsigned)s[i + 1]];
425*0Sstevel@tonic-gate ++i;
426*0Sstevel@tonic-gate }
427*0Sstevel@tonic-gate dbputc((int)c);
428*0Sstevel@tonic-gate }
429*0Sstevel@tonic-gate }
430*0Sstevel@tonic-gate
431*0Sstevel@tonic-gate /* print a warning message with the file name and line number */
432*0Sstevel@tonic-gate
433*0Sstevel@tonic-gate void
warning(text)434*0Sstevel@tonic-gate warning(text)
435*0Sstevel@tonic-gate char *text;
436*0Sstevel@tonic-gate {
437*0Sstevel@tonic-gate extern int yylineno;
438*0Sstevel@tonic-gate
439*0Sstevel@tonic-gate (void) fprintf(stderr, "cscope: \"%s\", line %d: warning: %s\n",
440*0Sstevel@tonic-gate filename, yylineno, text);
441*0Sstevel@tonic-gate errorsfound = YES;
442*0Sstevel@tonic-gate }
443