📄 cxr.c
字号:
* in a function: handles local variables * and looks for the end of the function */ switch (*s++) { case 'R': star = ' '; goto ahead2; /* No Break Needed */ case 'D': star = '*';ahead2: lino = getnumb(ns); fprintf(tfp, "%s\t%s\t%s\t%5d\t%c\n", s, xflnm, funcname, lino, star); break; case 'B': break; case 'E': lino = getnumb(s); /* * lino is used to hold the ending block * number at this point * * if the ending block number is the * same as the beginning block number * of the function, indicate that the * next variable found will be external. */ if (sblk == lino) { inafunc = NO; } break; case 'F': star = '$'; fprintf(tfp, "%s\t%c\n", s, star); break; default: fprintf(stderr, "SWITCH ERROR IN TMPSCAN: inafunc = yes\n"); dexit(1); }; };}mktmpfl(){ /* make temporary files */ tmp1 = tempnam((char *)NULL, "xr1"); tmp2 = tempnam((char *)NULL, "xr2"); /* holds output of "xpass" */ tmp3 = tempnam((char *)NULL, "xr3"); /* holds output of tmpscan() routine */ tmp4 = tempnam((char *)NULL, "xr4"); /* holds output of tempfile 3 */ tmpmade = YES; /* indicates temporary files have been made */ setsig();}tunlink(){ /* unlink temporary files */ if (tmpmade == YES) { /* if tempfiles exist */ unlink(tmp1); unlink(tmp2); unlink(tmp3); unlink(tmp4); };}dexit(n) int n;{ /* remove temporary files and exit with error status */ tunlink(); exit(n);}setsig(){ /* set up check on signals */ int sigout(); if (isatty(1)) { if (signal(SIGHUP, SIG_IGN) == SIG_DFL) signal(SIGHUP, sigout); if (signal(SIGINT, SIG_IGN) == SIG_DFL) signal(SIGINT, sigout); } else { signal(SIGHUP, SIG_IGN); signal(SIGINT, SIG_IGN); }; signal(SIGQUIT, sigout); signal(SIGTERM, sigout);}sigout(){ /* signal caught; unlink tmp files */ tunlink(); signal(SIGHUP, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); dexit(1);}sortfile(){ /* sorts temp file 3 --- stores on 4 */ register int status; arv[0] = "sort"; arv[1] = "-o"; arv[2] = tmp4; arv[3] = tmp3; arv[4] = 0; /* execute sort */ if ((status = callsys(SRT, arv)) > 0) { fprintf(stderr, "Sort failed with status %d\n", status); dexit(1); };}prtsort(){ /* prints sorted files and formats output for cxref listing */ FILE *fp; char line[MAX]; /* open tempfile of sorted data */ if ((fp = fopen(tmp4, "r")) == NULL) { fprintf(stderr, "CAN'T OPEN %s\n", tmp4); dexit(1); } else { if (hflag) { fprintf(stdout, "SYMBOL\t\tFILE\t\t\tFUNCTION LINE\n"); }; while (fgets(line, MAX, fp) != NULL) { scanline(line); /* routine to format output */ }; fprnt = YES; /* reinitialize for next file */ if (fp && ferror(fp)) { perror("cxref.prtsort"); dexit(1); } fclose(fp); putc('\n', stdout); };}scanline(line) char *line;{ /* formats what is to be printed on the output */ register char *sptr1; register int och, nch; char s1[MAXRFL], s2[MAXRFL], s3[MAXRFL], s4[MAXRFL], s5[MAXRFL]; /* * break down line into variable name, filename, * function name, and line number */ sscanf(line, "%s%s%s%s%s", s1, s2, s3, s4, s5); if (strcmp(s2, "$") == 0) { /* function name */ if (strcmp(sv1, s1) != 0) { strcpy(sv1, s1); printf("\n%s()", s1); /* append '()' to name */ *sv2 = *sv3 = *sv4 = '\0'; fprnt = NO; }; return; }; if (strcmp(s5, "*") == 0) { /* variable defined at this line number */ *s5 = '\0'; sptr1 = s4; och = '*'; /* prepend a star '*' */ for ( nch = *sptr1; *sptr1 = och; nch = *++sptr1) och = nch; } if (fprnt == YES) { /* if first line--copy the line to a save area */ prntwrd( strcpy(sv1, s1) ); prntflnm( strcpy(sv2, s2) ); prntfnc( strcpy(sv3, s3) ); prntlino( strcpy(sv4, s4) ); fprnt = NO; return; } else { /* * this part checks to see what variables have changed */ if (strcmp(sv1, s1) != 0) { nword = nflnm = nfnc = nlino = YES; } else { nword = NO; if (strcmp(sv2, s2) != 0) { nflnm = nfnc = nlino = YES; } else { nflnm = NO; if (strcmp(sv3, s3) != 0) { nfnc = nlino = YES; } else { nfnc = NO; nlino = (strcmp(sv4, s4) != 0) ? YES : NO; if (nlino == YES) { /* * everything is the same * except line number * add new line number */ addlino = YES; prntlino( strcpy(sv4, s4) ); }; /* * Want to return if we get to * this point. Case 1: nlino * is NO, then entire line is * same as previous one. * Case 2: only line number is * different, add new line number */ return; }; }; }; }; /* * either the word, filename or function name * are different; this part of the routine handles * what has changed... */ addlino = NO; lsize = 0; if (nword == YES) { /* word different--print line */ prntwrd( strcpy(sv1, s1) ); prntflnm( strcpy(sv2, s2) ); prntfnc( strcpy(sv3, s3) ); prntlino( strcpy(sv4, s4) ); return; } else { fputs("\n\t\t", stdout); if (nflnm == YES) { /* * different filename---new name, * function name and line number are * printed and saved */ prntflnm( strcpy(sv2, s2) ); prntfnc( strcpy(sv3, s3) ); prntlino( strcpy(sv4, s4) ); return; } else { /* prints filename as formatted by prntflnm()*/ switch (fsp) { case 1: printf("%s\t\t\t", s2); break; case 2: printf("%s\t\t", s2); break; case 3: printf("%s\t", s2); break; case 4: printf("%s ", s2); }; if (nfnc == YES) { /* * different function name---new name * is printed with line number; * name and line are saved */ prntfnc( strcpy(sv3, s3) ); prntlino( strcpy(sv4, s4) ); }; }; };}prntwrd(w) char *w;{ /* formats word(variable)*/ register int wsize; /*16 char max. word length */ if ((wsize = strlen(w)) < 8) { printf("\n%s\t\t", w); } else if ((wsize >= 8) && (wsize < 16)) { printf("\n%s\t", w); } else { printf("\n%s ", w); };}prntflnm(fn) char *fn;{ /* formats filename */ register int fsize; /*24 char max. fliename length */ if ((fsize = strlen(fn)) < 8) { printf("%s\t\t\t", fn); fsp = 1; } else { if ((fsize >= 8) && (fsize < 16)) { printf("%s\t\t", fn); fsp = 2; } else if ((fsize >= 16) && (fsize < 24)) { printf("%s\t", fn); fsp = 3; } else { printf("%s ", fn); fsp = 4; }; };}prntfnc(fnc) char *fnc;{ /* formats function name */ register int fsize; if ((fsize = strlen(fnc)) < 8) { printf("%s\t ", fnc); } else { switch (fsize) { case 8: printf("%s ", fnc); break; case 9: printf("%s ", fnc); break; default: printf("%s ", fnc); break; } };}char *myalloc(num, size) unsigned num, size;{ register char *ptr; if ((ptr = calloc(num, size)) == NULL) { perror("cxref"); dexit(1); }; return(ptr);}prntlino(ns) register char *ns;{ /* formats line numbers */ register int lino, i; char star; i = lino = 0; if (*ns == '*') { star = '*'; ns++; /* get past star */ } else { star = ' '; }; lino = getnumb(ns); if (lino < 10) /* keeps track of line width */ lsize += (i = 3); else if ((lino >=10) && (lino < 100)) lsize += (i = 4); else if ((lino >= 100) && (lino < 1000)) lsize += (i = 5); else if ((lino >= 1000) && (lino < 10000)) lsize += (i = 6); else /* lino > 10000 */ lsize += (i = 7); if (addlino == YES) { if (lsize <= LSIZE) { /* line length not exceeded--print line number */ fprintf(stdout, " %c%d", star, lino); } else { /* line to long---format lines overflow */ fprintf(stdout, "\n\t\t\t\t\t\t %c%d", star, lino); lsize = i; }; addlino = NO; } else { fprintf(stdout, " %c%d", star, lino); };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -