Print this page
5396 gcc 4.8.2 longjmp errors for cscope-fast
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/cscope-fast/display.c
+++ new/usr/src/tools/cscope-fast/display.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /* Copyright (c) 1988 AT&T */
23 23 /* All Rights Reserved */
24 24
25 25
26 26 /*
27 27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 28 * Use is subject to license terms.
29 + * Copyright 2015 Gary Mills
29 30 */
30 31
31 -#pragma ident "%Z%%M% %I% %E% SMI"
32 -
33 32 /*
34 33 * cscope - interactive C symbol cross-reference
35 34 *
36 35 * display functions
37 36 */
38 37
39 38 #include "global.h"
40 39 #include "version.h" /* FILEVERSION and FIXVERSION */
41 40 #include <curses.h> /* COLS and LINES */
42 41 #include <setjmp.h> /* jmp_buf */
43 42 #include <string.h>
44 43 #include <errno.h>
45 44
46 45 /* see if the function column should be displayed */
47 46 #define displayfcn() (field <= ASSIGN)
48 47
49 48 #define MINCOLS 68 /* minimum columns for 3 digit Lines message numbers */
50 49
51 50 int *displine; /* screen line of displayed reference */
52 51 int disprefs; /* displayed references */
53 52 int field; /* input field */
54 53 unsigned fldcolumn; /* input field column */
55 54 int mdisprefs; /* maximum displayed references */
56 55 int selectlen; /* selection number field length */
57 56 int nextline; /* next line to be shown */
58 57 int topline = 1; /* top line of page */
59 58 int bottomline; /* bottom line of page */
60 59 int totallines; /* total reference lines */
61 60 FILE *refsfound; /* references found file */
62 61 FILE *nonglobalrefs; /* non-global references file */
63 62
64 63 static int fldline; /* input field line */
65 64 static int subsystemlen; /* OGS subsystem name display */
66 65 /* field length */
67 66 static int booklen; /* OGS book name display field length */
68 67 static int filelen; /* file name display field length */
69 68 static int fcnlen; /* function name display field length */
70 69 static jmp_buf env; /* setjmp/longjmp buffer */
71 70 static int lastdispline; /* last displayed reference line */
72 71 static char lastmsg[MSGLEN + 1]; /* last message displayed */
73 72 static int numlen; /* line number display field length */
74 73 static char depthstring[] = "Depth: ";
75 74 static char helpstring[] = "Press the ? key for help";
76 75
77 76
78 77 typedef char *(*FP)(); /* pointer to function returning a character pointer */
79 78
80 79 static struct {
81 80 char *text1;
82 81 char *text2;
83 82 FP findfcn;
84 83 enum {
85 84 EGREP,
86 85 REGCMP
87 86 } patterntype;
88 87 } fields[FIELDS + 1] = {
89 88 /* last search is not part of the cscope display */
90 89 { "Find this", "C symbol",
91 90 (FP) findsymbol, REGCMP},
92 91 { "Find this", "definition",
93 92 (FP) finddef, REGCMP},
94 93 { "Find", "functions called by this function",
95 94 (FP) findcalledby, REGCMP},
96 95 { "Find", "functions calling this function",
97 96 (FP) findcalling, REGCMP},
98 97 { "Find", "assignments to",
99 98 (FP) findassignments, REGCMP},
100 99 { "Change this", "grep pattern",
101 100 findgreppat, EGREP},
102 101 { "Find this", "egrep pattern",
103 102 findegreppat, EGREP},
104 103 { "Find this", "file",
105 104 (FP) findfile, REGCMP},
106 105 { "Find", "files #including this file",
107 106 (FP) findinclude, REGCMP},
108 107 { "Find all", "function/class definitions",
109 108 (FP) findallfcns, REGCMP},
110 109 };
111 110
112 111 /* initialize display parameters */
113 112
114 113 void
115 114 dispinit(void)
116 115 {
117 116 /* calculate the maximum displayed reference lines */
118 117 lastdispline = FLDLINE - 2;
119 118 mdisprefs = lastdispline - REFLINE + 1;
120 119 if (mdisprefs <= 0) {
121 120 (void) printw("cscope: window must be at least %d lines high",
122 121 FIELDS + 6);
123 122 myexit(1);
124 123 }
125 124 if (COLS < MINCOLS) {
126 125 (void) printw("cscope: window must be at least %d columns wide",
127 126 MINCOLS);
128 127 myexit(1);
129 128 }
130 129 if (!mouse) {
131 130 if (returnrequired == NO && mdisprefs > 9) {
132 131 mdisprefs = 9; /* single digit selection number */
133 132 }
134 133 /* calculate the maximum selection number width */
135 134 (void) sprintf(newpat, "%d", mdisprefs);
136 135 selectlen = strlen(newpat);
137 136 }
138 137 /* allocate the displayed line array */
139 138 displine = (int *)mymalloc(mdisprefs * sizeof (int));
140 139 }
141 140
142 141 /* display a page of the references */
143 142
144 143 void
145 144 display(void)
146 145 {
147 146 char *subsystem; /* OGS subsystem name */
148 147 char *book; /* OGS book name */
149 148 char file[PATHLEN + 1]; /* file name */
150 149 char function[PATLEN + 1]; /* function name */
151 150 char linenum[NUMLEN + 1]; /* line number */
152 151 int screenline; /* screen line number */
153 152 int width; /* source line display width */
154 153 int i;
155 154 char *s;
156 155
157 156 (void) erase();
158 157
159 158 /* if there are no references */
160 159 if (totallines == 0) {
161 160 if (*lastmsg != '\0') {
162 161 (void) addstr(lastmsg); /* redisplay any message */
163 162 } else {
164 163 (void) printw("Cscope version %d%s", FILEVERSION,
165 164 FIXVERSION);
166 165 (void) move(0, COLS - (int)sizeof (helpstring));
167 166 (void) addstr(helpstring);
168 167 }
169 168 } else { /* display the pattern */
170 169 if (changing == YES) {
171 170 (void) printw("Change \"%s\" to \"%s\"",
172 171 pattern, newpat);
173 172 } else {
174 173 (void) printw("%c%s: %s",
175 174 toupper(fields[field].text2[0]),
176 175 fields[field].text2 + 1, pattern);
177 176 }
178 177 /* display the cscope invocation nesting depth */
179 178 if (cscopedepth > 1) {
180 179 (void) move(0, COLS - (int)sizeof (depthstring) - 2);
181 180 (void) addstr(depthstring);
182 181 (void) printw("%d", cscopedepth);
183 182 }
184 183 /* display the column headings */
185 184 (void) move(2, selectlen + 1);
186 185 if (ogs == YES && field != FILENAME) {
187 186 (void) printw("%-*s ", subsystemlen, "Subsystem");
188 187 (void) printw("%-*s ", booklen, "Book");
189 188 }
190 189 if (dispcomponents > 0) {
191 190 (void) printw("%-*s ", filelen, "File");
192 191 }
193 192 if (displayfcn()) {
194 193 (void) printw("%-*s ", fcnlen, "Function");
195 194 }
196 195 if (field != FILENAME) {
197 196 (void) addstr("Line");
198 197 }
199 198 (void) addch('\n');
200 199
201 200 /* if at end of file go back to beginning */
202 201 if (nextline > totallines) {
203 202 seekline(1);
204 203 }
205 204 /* calculate the source text column */
206 205 width = COLS - selectlen - numlen - 2;
207 206 if (ogs == YES) {
208 207 width -= subsystemlen + booklen + 2;
209 208 }
210 209 if (dispcomponents > 0) {
211 210 width -= filelen + 1;
212 211 }
213 212 if (displayfcn()) {
214 213 width -= fcnlen + 1;
215 214 }
216 215 /*
217 216 * until the max references have been displayed or
218 217 * there is no more room
219 218 */
220 219 topline = nextline;
221 220 for (disprefs = 0, screenline = REFLINE;
222 221 disprefs < mdisprefs && screenline <= lastdispline;
223 222 ++disprefs, ++screenline) {
224 223 /* read the reference line */
225 224 if (fscanf(refsfound, "%s%s%s %[^\n]", file, function,
226 225 linenum, yytext) < 4) {
227 226 break;
228 227 }
229 228 ++nextline;
230 229 displine[disprefs] = screenline;
231 230
232 231 /* if no mouse, display the selection number */
233 232 if (!mouse) {
234 233 (void) printw("%*d", selectlen, disprefs + 1);
235 234 }
236 235 /* display any change mark */
237 236 if (changing == YES &&
238 237 change[topline + disprefs - 1] == YES) {
239 238 (void) addch('>');
240 239 } else {
241 240 (void) addch(' ');
242 241 }
243 242 /* display the file name */
244 243 if (field == FILENAME) {
245 244 (void) printw("%-.*s\n", COLS - 3, file);
246 245 continue;
247 246 }
248 247 /* if OGS, display the subsystem and book names */
249 248 if (ogs == YES) {
250 249 ogsnames(file, &subsystem, &book);
251 250 (void) printw("%-*.*s ", subsystemlen,
252 251 subsystemlen, subsystem);
253 252 (void) printw("%-*.*s ", booklen, booklen,
254 253 book);
255 254 }
256 255 /* display the requested path components */
257 256 if (dispcomponents > 0) {
258 257 (void) printw("%-*.*s ", filelen, filelen,
259 258 pathcomponents(file, dispcomponents));
260 259 }
261 260 /* display the function name */
262 261 if (displayfcn()) {
263 262 (void) printw("%-*.*s ", fcnlen, fcnlen,
264 263 function);
265 264 }
266 265 /* display the line number */
267 266 (void) printw("%*s ", numlen, linenum);
268 267
269 268 /* there may be tabs in egrep output */
270 269 while ((s = strchr(yytext, '\t')) != NULL) {
271 270 *s = ' ';
272 271 }
273 272 /* display the source line */
274 273 s = yytext;
275 274 for (;;) {
276 275 /* see if the source line will fit */
277 276 if ((i = strlen(s)) > width) {
278 277 /* find the nearest blank */
279 278 for (i = width; s[i] != ' ' && i > 0;
280 279 --i) {
281 280 }
282 281 if (i == 0) {
283 282 i = width; /* no blank */
284 283 }
285 284 }
286 285 /* print up to this point */
287 286 (void) printw("%.*s", i, s);
288 287 s += i;
289 288
290 289 /* if line didn't wrap around */
291 290 if (i < width) {
292 291 /* go to next line */
293 292 (void) addch('\n');
294 293 }
295 294 /* skip blanks */
296 295 while (*s == ' ') {
297 296 ++s;
298 297 }
299 298 /* see if there is more text */
300 299 if (*s == '\0') {
301 300 break;
302 301 }
303 302 /* if the source line is too long */
304 303 if (++screenline > lastdispline) {
305 304 /*
306 305 * if this is the first displayed line,
307 306 * display what will fit on the screen
308 307 */
309 308 if (topline == nextline - 1) {
310 309 goto endrefs;
311 310 }
312 311 /* erase the reference */
313 312 while (--screenline >=
314 313 displine[disprefs]) {
315 314 (void) move(screenline, 0);
316 315 (void) clrtoeol();
317 316 }
318 317 ++screenline;
319 318
320 319 /*
321 320 * go back to the beginning of this
322 321 * reference
323 322 */
324 323 --nextline;
325 324 seekline(nextline);
326 325 goto endrefs;
327 326 }
328 327 /* indent the continued source line */
329 328 (void) move(screenline, COLS - width);
330 329 }
331 330
332 331 }
333 332 endrefs:
334 333 /* check for more references */
335 334 bottomline = nextline;
336 335 if (bottomline - topline < totallines) {
337 336 (void) move(FLDLINE - 1, 0);
338 337 (void) standout();
339 338 (void) printw("%*s", selectlen + 1, "");
340 339 if (bottomline - 1 == topline) {
341 340 (void) printw("Line %d", topline);
342 341 } else {
343 342 (void) printw("Lines %d-%d", topline,
344 343 bottomline - 1);
345 344 }
346 345 (void) printw(" of %d, press the space bar to "
347 346 "display next lines", totallines);
348 347 (void) standend();
349 348 }
350 349 }
351 350 /* display the input fields */
352 351 (void) move(FLDLINE, 0);
353 352 for (i = 0; i < FIELDS; ++i) {
354 353 (void) printw("%s %s:\n", fields[i].text1, fields[i].text2);
355 354 }
356 355 drawscrollbar(topline, nextline, totallines);
357 356 }
358 357
359 358 /* set the cursor position for the field */
360 359 void
361 360 setfield(void)
362 361 {
363 362 fldline = FLDLINE + field;
364 363 fldcolumn = strlen(fields[field].text1) +
365 364 strlen(fields[field].text2) + 3;
366 365 }
367 366
368 367 /* move to the current input field */
369 368
370 369 void
371 370 atfield(void)
372 371 {
373 372 (void) move(fldline, (int)fldcolumn);
374 373 }
375 374
376 375 /* search for the symbol or text pattern */
377 376
378 377 /*ARGSUSED*/
379 378 SIGTYPE
↓ open down ↓ |
337 lines elided |
↑ open up ↑ |
380 379 jumpback(int sig)
381 380 {
382 381 longjmp(env, 1);
383 382 }
384 383
385 384 BOOL
386 385 search(void)
387 386 {
388 387 char *egreperror = NULL; /* egrep error message */
389 388 FINDINIT rc = NOERROR; /* findinit return code */
390 - SIGTYPE (*savesig)(); /* old value of signal */
389 + SIGTYPE (*volatile savesig)() = SIG_DFL; /* old value of signal */
391 390 FP f; /* searching function */
392 391 char *s;
393 392 int c;
394 393
395 394 /* note: the pattern may have been a cscope argument */
396 395 if (caseless == YES) {
397 396 for (s = pattern; *s != '\0'; ++s) {
398 397 *s = tolower(*s);
399 398 }
400 399 }
401 400 /* open the references found file for writing */
402 401 if (writerefsfound() == NO) {
403 402 return (NO);
404 403 }
405 404 /* find the pattern - stop on an interrupt */
406 405 if (linemode == NO) {
407 406 putmsg("Searching");
408 407 }
409 408 initprogress();
410 409 if (setjmp(env) == 0) {
411 410 savesig = signal(SIGINT, jumpback);
412 411 f = fields[field].findfcn;
413 412 if (fields[field].patterntype == EGREP) {
414 413 egreperror = (*f)(pattern);
415 414 } else {
416 415 if ((nonglobalrefs = fopen(temp2, "w")) == NULL) {
417 416 cannotopen(temp2);
418 417 return (NO);
419 418 }
420 419 if ((rc = findinit()) == NOERROR) {
421 420 (void) dbseek(0L); /* goto the first block */
422 421 (*f)();
423 422 findcleanup();
424 423
425 424 /* append the non-global references */
426 425 (void) freopen(temp2, "r", nonglobalrefs);
427 426 while ((c = getc(nonglobalrefs)) != EOF) {
428 427 (void) putc(c, refsfound);
429 428 }
430 429 }
431 430 (void) fclose(nonglobalrefs);
432 431 }
433 432 }
434 433 (void) signal(SIGINT, savesig);
435 434 /* reopen the references found file for reading */
436 435 (void) freopen(temp1, "r", refsfound);
437 436 nextline = 1;
438 437 totallines = 0;
439 438
440 439 /* see if it is empty */
441 440 if ((c = getc(refsfound)) == EOF) {
442 441 if (egreperror != NULL) {
443 442 (void) sprintf(lastmsg, "Egrep %s in this pattern: %s",
444 443 egreperror, pattern);
445 444 } else if (rc == NOTSYMBOL) {
446 445 (void) sprintf(lastmsg, "This is not a C symbol: %s",
447 446 pattern);
448 447 } else if (rc == REGCMPERROR) {
449 448 (void) sprintf(lastmsg,
450 449 "Error in this regcmp(3X) regular expression: %s",
451 450 pattern);
452 451 } else {
453 452 (void) sprintf(lastmsg, "Could not find the %s: %s",
454 453 fields[field].text2, pattern);
455 454 }
456 455 return (NO);
457 456 }
458 457 /* put back the character read */
459 458 (void) ungetc(c, refsfound);
460 459
461 460 countrefs();
462 461 return (YES);
463 462 }
464 463
465 464 /* open the references found file for writing */
466 465
467 466 BOOL
468 467 writerefsfound(void)
469 468 {
470 469 if (refsfound == NULL) {
471 470 if ((refsfound = fopen(temp1, "w")) == NULL) {
472 471 cannotopen(temp1);
473 472 return (NO);
474 473 }
475 474 } else if (freopen(temp1, "w", refsfound) == NULL) {
476 475 putmsg("Cannot reopen temporary file");
477 476 return (NO);
478 477 }
479 478 return (YES);
480 479 }
481 480
482 481 /* count the references found */
483 482
484 483 void
485 484 countrefs(void)
486 485 {
487 486 char *subsystem; /* OGS subsystem name */
488 487 char *book; /* OGS book name */
489 488 char file[PATHLEN + 1]; /* file name */
490 489 char function[PATLEN + 1]; /* function name */
491 490 char linenum[NUMLEN + 1]; /* line number */
492 491 int i;
493 492
494 493 /*
495 494 * count the references found and find the length of the file,
496 495 * function, and line number display fields
497 496 */
498 497 subsystemlen = 9; /* strlen("Subsystem") */
499 498 booklen = 4; /* strlen("Book") */
500 499 filelen = 4; /* strlen("File") */
501 500 fcnlen = 8; /* strlen("Function") */
502 501 numlen = 0;
503 502 while ((i = fscanf(refsfound, "%250s%250s%6s %5000[^\n]", file,
504 503 function, linenum, yytext)) != EOF) {
505 504 if (i != 4 || !isgraph(*file) ||
506 505 !isgraph(*function) || !isdigit(*linenum)) {
507 506 putmsg("File does not have expected format");
508 507 totallines = 0;
509 508 return;
510 509 }
511 510 if ((i = strlen(pathcomponents(file,
512 511 dispcomponents))) > filelen) {
513 512 filelen = i;
514 513 }
515 514 if (ogs == YES) {
516 515 ogsnames(file, &subsystem, &book);
517 516 if ((i = strlen(subsystem)) > subsystemlen) {
518 517 subsystemlen = i;
519 518 }
520 519 if ((i = strlen(book)) > booklen) {
521 520 booklen = i;
522 521 }
523 522 }
524 523 if ((i = strlen(function)) > fcnlen) {
525 524 fcnlen = i;
526 525 }
527 526 if ((i = strlen(linenum)) > numlen) {
528 527 numlen = i;
529 528 }
530 529 ++totallines;
531 530 }
532 531 rewind(refsfound);
533 532
534 533 /* restrict the width of displayed columns */
535 534 i = (COLS - 5) / 3;
536 535 if (ogs == YES) {
537 536 i = (COLS - 7) / 5;
538 537 }
539 538 if (filelen > i && i > 4) {
540 539 filelen = i;
541 540 }
542 541 if (subsystemlen > i && i > 9) {
543 542 subsystemlen = i;
544 543 }
545 544 if (booklen > i && i > 4) {
546 545 booklen = i;
547 546 }
548 547 if (fcnlen > i && i > 8) {
549 548 fcnlen = i;
550 549 }
551 550 }
552 551
553 552 /* print error message on system call failure */
554 553
555 554 void
556 555 myperror(char *text)
557 556 {
558 557 char msg[MSGLEN + 1]; /* message */
559 558
560 559 (void) sprintf(msg, "%s: %s", text, strerror(errno));
561 560 putmsg(msg);
562 561 }
563 562
564 563 /* putmsg clears the message line and prints the message */
565 564
566 565 void
567 566 putmsg(char *msg)
568 567 {
569 568 if (incurses == NO) {
570 569 *msg = tolower(*msg);
571 570 (void) fprintf(stderr, "cscope: %s\n", msg);
572 571 } else {
573 572 (void) move(MSGLINE, 0);
574 573 (void) clrtoeol();
575 574 (void) addstr(msg);
576 575 (void) refresh();
577 576 }
578 577 (void) strncpy(lastmsg, msg, sizeof (lastmsg) - 1);
579 578 }
580 579
581 580 /* clearmsg2 clears the second message line */
582 581
583 582 void
584 583 clearmsg2(void)
585 584 {
586 585 if (incurses == YES) {
587 586 (void) move(MSGLINE + 1, 0);
588 587 (void) clrtoeol();
589 588 }
590 589 }
591 590
592 591 /* putmsg2 clears the second message line and prints the message */
593 592
594 593 void
595 594 putmsg2(char *msg)
596 595 {
597 596 if (incurses == NO) {
598 597 putmsg(msg);
599 598 } else {
600 599 clearmsg2();
601 600 (void) addstr(msg);
602 601 (void) refresh();
603 602 }
604 603 }
605 604
606 605 /* position the references found file at the specified line */
607 606
608 607 void
609 608 seekline(int line)
610 609 {
611 610 int c;
612 611
613 612 /* verify that there is a references found file */
614 613 if (refsfound == NULL) {
615 614 return;
616 615 }
617 616 /* go to the beginning of the file */
618 617 rewind(refsfound);
619 618
620 619 /* find the requested line */
621 620 nextline = 1;
622 621 while (nextline < line && (c = getc(refsfound)) != EOF) {
623 622 if (c == '\n') {
624 623 nextline++;
625 624 }
626 625 }
627 626 }
628 627
629 628 /* get the OGS subsystem and book names */
630 629
631 630 void
632 631 ogsnames(char *file, char **subsystem, char **book)
633 632 {
634 633 static char buf[PATHLEN + 1];
635 634 char *s, *slash;
636 635
637 636 *subsystem = *book = "";
638 637 (void) strcpy(buf, file);
639 638 s = buf;
640 639 if (*s == '/') {
641 640 ++s;
642 641 }
643 642 while ((slash = strchr(s, '/')) != NULL) {
644 643 *slash = '\0';
645 644 if ((int)strlen(s) >= 3 && strncmp(slash - 3, ".ss", 3) == 0) {
646 645 *subsystem = s;
647 646 s = slash + 1;
648 647 if ((slash = strchr(s, '/')) != NULL) {
649 648 *book = s;
650 649 *slash = '\0';
651 650 }
652 651 break;
653 652 }
654 653 s = slash + 1;
655 654 }
656 655 }
657 656
658 657 /* get the requested path components */
659 658
660 659 char *
661 660 pathcomponents(char *path, int components)
662 661 {
663 662 int i;
664 663 char *s;
665 664
666 665 s = path + strlen(path) - 1;
667 666 for (i = 0; i < components; ++i) {
668 667 while (s > path && *--s != '/') {
669 668 ;
670 669 }
671 670 }
672 671 if (s > path && *s == '/') {
673 672 ++s;
674 673 }
675 674 return (s);
676 675 }
↓ open down ↓ |
276 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX