Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 1 1: /* 2: * x r f 3: * 4: * Cross reference 5: */ 6: 7: /*)BUILD $(PROGRAM) = xrf 8: $(INCLUDE) = xrf.h 9: $(FILES) = { xrf0 xrf1 xrf2 xrf3 xrfi xrfd } 10: $(TKBOPTIONS) = { 11: TASK = ...XRF 12: STACK = 1500 13: } 14: $(ODL) = { 15: ; 16: ; OVERLAY DESCRIPTION FOR XRF 17: ; BOB DENNY 29-MAY-81 18: ; 19: .ROOT XRF0-XRF2-XRFD-$(RXLIB)-*(X1,X2,X3) 20: ; 21: X1: .FCTR XRFI-X1L1-X1L2-X1L3 22: X1L1: .FCTR $(RXLIB):CONCAT:FWILD 23: ; Note: CTIME requires several other library modules: 24: X1L2: .FCTR $(RXLIB):TIME:CTIME:LOCALT:$$$$RTIME:$$$$UTIME 25: X1L3: .FCTR $(RXLIB):CALLOC:MUL$$L:$$$$DIV2:EIS$$I 26: ; 27: X2: .FCTR XRF1-X2L 28: X2L: .FCTR $(RXLIB):EIS$$I 29: ; 30: X3: .FCTR XRF3-X3L 31: X3L: .FCTR $(RXLIB):CPYSTR:SPRINT 32: .END 33: } 34: $(OVR) = { 35: XRF0,XRF2,XRFD,$(SUPORT),$(RTLIB) 36: XRFI,$(RTLIB)/O:1 37: XRF1,$(RTLIB)/O:1 38: XRF3,$(RTLIB)/O:1 39: } 40: */ 41: 42: /* 43: * *************** 44: * * X R F 0 . C * 45: * *************** 46: * 47: * This is the mainline program for the C cross referencer and lister. 48: * It handles the following tasks: 49: * 50: * - Scans the command line 51: * - Opens the appropriate files 52: * - Calls some initialization functions 53: * - Invokes line by line processing 54: * - Prints the cross-reference index 55: * - Finishes up processing as appropriate 56: * 57: * Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 2 58: * Usage: 59: * 60: * xrf [-s] [-n] [-o out_file] in_files 61: * 62: * Flags: 63: * -s Spool out_file to printer (RSX11M only (??)) 64: * 65: * -n Narrow (80 column) output, normal is 132 column. 66: * 67: * -o file Write output to the indicated file. If -o is not 68: * specified, output will be to the first in_file 69: * with the filetype set to ".x" 70: * 71: * Written By: 72: * Bob Denny 73: * Creative System Design Co. 74: * 3452 E. Foothill Blvd. << Suite 601 >> 75: * Pasadena, Ca. 91107 76: * (213) 355-6836 77: * 78: * Experimental Version X1.0 5-May-80 79: * Split off initialization X1.1 7-May-80 80: * Prototype. Y1.2 9-May-80 81: * Release. V1.3 9-May-80 82: * Chg. for DECUS OTS. & Cmplr. V1.4 1-Jul-80 83: * Add support for RT-11 V1.5 3-Jul-80 84: * Conditionalized spool call V1.6 MM 9-Jul-80 85: * Added narrow, outfile, etc. V1.7 MM 10-Jul-80 86: * Added multiple infiles V1.8 MM 22-Jul-80 87: * Fspool now in the library V1.9 MM 2-Aug-80 88: * 89: ***************************************************************************** 90: */ 91: 92: #ifdef DOCUMENTATION 93: 94: title xrf Cross-Reference Lister for C Programs 95: index Cross-Reference Lister for C Programs 96: 97: synopsis 98: 99: xrf [-options] [-o outfile] [file ...] 100: 101: description 102: 103: xrf prepares a cross-reference listing for C source programs. The 104: following options are defined: 105: .lm +8 106: .s.i -8;-n Narrow output (80 columns). The default is 132 107: columns. 108: .s.i -8;-s Spool output to the default line printer. 109: .s.i -8;-o file Write output to the named file. The default is the 110: first input file encountered with a filetype (extension) of ".x". 111: .s.lm -8 112: xrf accepts wild-card file input. 113: 114: diagnostics 115: Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 3 116: .lm +8 117: .s.i -8;Trying to get too much. 118: .s 119: Internal error, get help. 120: .s.i -8;Not enough memory space. 121: .s 122: xrf ran out of main memory space. 123: .s.i -8;Cannot open "file" 124: .s.i -8;Cannot open listing file "file" 125: .s.i -8;Usage ... 126: .lm -8 127: 128: author 129: 130: Robert B. Denny 131: 132: bugs 133: 134: #endif 135: 136: #include /* RSX-11M Std. I/O Def's */ 137: #include "xrf.h" /* Global definitions */ 138: 139: int pageno; /* Current listing page no. */ Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 4 140: 141: 142: main ( argc, argv ) 143: char *argv[]; 144: { /* Start the main prog. */ 145: register int i; /* Arg count */ 146: register int c; /* Switch character code */ 147: register char *p; /* Fast arg pointer */ 148: char *in_file; /* Source file name string */ 149: char *out_file; /* Cref file name string */ 150: int splflg; /* Spool file flag */ 151: int nofiles; /* Flag "got a file" */ 152: 153: out_file = NULL; /* No output file yet */ 154: splflg = 0; /* Default no spool */ 155: for( i=1; i i'th arg token */ 158: if( *p++ == '-' ) /* if it's a switch token */ 159: { 160: while( c = *p++ ) /* Each char is a switch */ 161: switch(tolower(c)) /* Process 'em */ 162: { 163: case 'o': /* Output file */ 164: argv[i] = 0; 165: if (++i >= argc) 166: useage(); 167: out_file = argv[i]; 168: argv[i] = 0; 169: goto nextarg; 170: 171: case 'n': /* Narrow output */ 172: rperline = (80 - 16)/RSIZE; /* Set references */ 173: break; 174: 175: case 's': /* Spool listing */ 176: splflg++; 177: break; 178: 179: default : /* Bad switch, give help */ 180: useage(); 181: } 182: argv[i] = 0; /* Drop this one */ 183: } 184: nextarg:; 185: } /* Done with cmd string */ 186: 187: nofiles = 1; 188: for( i = 1; i < argc; i++) 189: { 190: if ((in_file = argv[i]) == 0) 191: continue; 192: initinfile(in_file); 193: while (nextinfile()) 194: { 195: if (nofiles) 196: { Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 5 197: initoutfile(out_file); 198: nofiles = 0; 199: } 200: pageno = 0; /* Init. page number */ 201: lineno = 0; /* Init. line number */ 202: myfree(); /* Clear out storage */ 203: root = NULL; /* No tree yet */ 204: newpage(); /* Start first page */ 205: while(fgets(scanbf, LWIDTH, src) != NULL) /* Get a line of source */ 206: { 207: ++lineno; /* Increment line number */ 208: scanp = scanbf; /* Reset scan pointer */ 209: while(getid()) /* scanp --> id or NULL */ 210: root = search(idbuf, root); /* Process identifier */ 211: /* Till done with this line */ 212: lstline(); /* List this line */ 213: } /* Till end of source file */ 214: newpage(); /* Start index on new page */ 215: prtree(root); /* Print the index */ 216: } 217: } 218: if (nofiles) 219: useage(); 220: #ifdef rsx 221: if(splflg) /* If we're to spool, */ 222: fspool(lst); /* Cross your fingers. */ 223: #endif 224: exit(); /* Exit closing files */ 225: } /***** END MAIN *****/ Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 6 226: 227: 228: /* 229: * 230: * Listing control routines. Newpage also used by prtree. 231: * 232: */ 233: 234: newpage() /* Start new page */ 235: { 236: ++pageno; /* Increment page number */ 237: linpg = 0; /* Reset line-in-page count */ 238: fprintf(lst,"%s%d\n\n", pghead, pageno); /* Output page heading */ 239: } 240: 241: lstline() /* Write listing line out */ 242: { 243: if(++linpg > MAXLIN) 244: newpage(); 245: fprintf(lst, "%4d:\t%s", lineno, scanbf); 246: } 247: 248: 249: /* 250: * *************** 251: * * X R F 2 . C * 252: * *************** 253: * 254: * This file contains the identifier tree and reference list management 255: * things. It uses a simple binary tree to store the identifiers for 256: * lookup and later sorted printing. Each node in the id tree has a 257: * pointer to the id string, left and right links and pointers to the 258: * beginning and end of the linked list of reference nodes for that 259: * id. Only the root of the tree is global, it is used by the sorted 260: * index printing function 'prtree'. 261: * 262: * Version V1.3 9-May-80 263: * Version V1.4 10-Jul-80 MM Bummed code 264: * Version V1.5 23-Jul-80 MM Redid storage code 265: * Version V1.6 23-Dec-80 RBD Fixed bug in myalloc() 266: */ 267: 268: #include 269: #include "xrf.h" Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 7 270: 271: 272: /* 273: * Tree search and insertion. This function returns a pointer to 274: * the new node if created. This may require some head scratching 275: * (I had to!). Look particularly at the significance of the pointer 276: * that is returned and how it is used by the recursive caller. If 277: * you want more, read "Algorithms + Data Structures = Programs" 278: * by Niklaus Wirth (Prentice Hall ISBN 0-13-022418-9) Chapter 4. 279: * 280: * It searches through the tree for a match to the supplied id (*kp). 281: * If it is found, a new reference node is linked into the list for 282: * that id. If no match is found, a new is node is inserted into the 283: * tree and appropriately initialized, including a first reference 284: * node. 285: * 286: */ 287: 288: struct idt *search(kp, link) /* Function "search" */ 289: struct idt *link; /* Pointer to id node in tree */ 290: char *kp; /* Pointer to key string */ 291: { 292: register struct idt *l; /* Fast tree pointer */ 293: register struct ref *r; /* Fast list pointer */ 294: register int cond; /* Condition from strcmp */ 295: struct ref *newref(); /* Make reference function */ 296: 297: l = link; /* Copy link into register */ 298: if(l == NULL) /* Not found, insert new id node */ 299: { 300: l = myalloc(sizeof(struct idt)); /* Make a new ident node */ 301: l->keyp = myalloc(strlen(kp)+1); /* Get string space */ 302: /* Fill in pointer to ... */ 303: strcpy(l->keyp, kp); /* ... stashed key string */ 304: l->left = l->right = NULL; /* No children */ 305: l->first = l->last = newref(); /* Attach it to the id node */ 306: } 307: else if((cond = strcmp(kp, l->keyp)) == 0) /* Match if true */ 308: { 309: r = newref(); /* Get a new ref. node */ 310: l->last->next = r; /* Hook new node into the list */ 311: l->last = r; 312: } 313: else if(cond < 0) /* Look left */ 314: l->left = search(kp, l->left); 315: else /* Look right */ 316: l->right = search(kp, l->right); 317: return(l); 318: } 319: 320: 321: /* 322: * Initialize a line number referece 323: */ 324: 325: static struct ref * 326: newref() Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 8 327: { 328: register struct ref *r; 329: 330: r = myalloc(sizeof(struct ref)); /* Make a reference node */ 331: r->lno = lineno; /* Fill in line no. of ref. */ 332: r->next = NULL; /* This is the end for now */ 333: return(r); /* Return pointer to the node */ 334: } 335: 336: /* 337: * Storage allocation: 338: * 339: * my_free Free byte pointer in local buffer 340: * my_left Number of bytes left in local buffer 341: * my_link Link of free space buffers (from malloc()) 342: * 343: * If space can be gotten locally, get it. If not, request a "large" 344: * chunk of memory and update my_free, my_left. 345: * 346: * My_link links chunks from monitor, myfree() returns them (called 347: * at a new input file). 348: */ 349: 350: struct my_alloc { 351: struct my_alloc *my_next; 352: }; 353: 354: static struct my_alloc *my_link = NULL; 355: static char *my_free = NULL; 356: static int my_left = 0; 357: 358: myalloc(amount) 359: int amount; 360: /* 361: * Allocate amount bytes. 362: */ 363: { 364: register char *new; 365: register int needed; 366: char *malloc(); 367: 368: needed = (amount + 1) & 0177776; /* Round up to a word bound */ 369: if (needed > my_left) { 370: /* 371: * Gotta get storage 372: */ 373: if ((my_free = malloc(512)) == NULL) 374: quit(); 375: my_left = 512 - (sizeof (struct my_alloc)); 376: ((struct my_alloc *)my_free)->my_next = my_link; 377: my_link = (struct my_alloc *)my_free; 378: my_free += sizeof (struct my_alloc); 379: } 380: my_left -= needed; 381: if (my_left < 0) 382: error("Trying to get too much: %d\n", needed); 383: new = my_free; 384: my_free += needed; Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 9 385: return(new); 386: } 387: 388: myfree() 389: /* 390: * Return all storage to the pool 391: */ 392: { 393: register struct my_alloc *link; 394: register struct my_alloc *next; 395: 396: next = my_link; 397: while ((link = next) != NULL) { 398: next = link->my_next; 399: free(link); 400: } 401: my_link = NULL; 402: my_free = NULL; 403: my_left = 0; 404: } Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 10 405: 406: 407: /* 408: * 'quit' handles dynamic memory deficit. (Sounds like U.S. Government!). 409: * It issues a polite message to the user, marks the list file for delete 410: * and exits to RSX. 411: * 412: */ 413: 414: quit() 415: { 416: char workbuf[40]; 417: 418: puts("Not enough memory space, sorry.\n"); 419: fgetname(lst, workbuf); 420: fclose(lst); 421: delete(workbuf); 422: exit(1); 423: } 424: 425: /* 426: * *************** 427: * * X R F D . C * 428: * *************** 429: * 430: * This file contains global externals and tables used by the C xrf'er. 431: * 432: * Version 1.5 3-Jul-80 Added RT-11 compatibility. 433: * Version 1.6 10-Jul-80 MM Added new stuff 434: * Version 1.7 22-Jul-80 MM For fwild() stuff 435: */ 436: 437: #include 438: #include "xrf.h" 439: 440: FILE *src; /* Source file pointer */ 441: FILE *lst; /* List file pointer */ 442: 443: int lineno = 0; /* Current source line number */ 444: int linpg = 0; /* Line-in-page count */ 445: int rperline = (LWIDTH - 16) / RSIZE; 446: 447: char pghead[LWIDTH+1]; 448: 449: char scanbf[LWIDTH+1]; /* Source line scan buffer */ 450: char *scanp; /* Scan pointer */ 451: 452: char idbuf[NCPS+1]; /* Ident. string buffer */ 453: 454: struct idt *root; /* ID tree root */ 455: int time_of_day[2]; /* For unix flavored systems */ 456: /* 457: * *************** 458: * * X R F I . C * 459: * *************** 460: * 461: * Do initialization things. Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 11 462: * NOTE: This is once-only code. It should be run in an overlay, 463: * along with FOPEN. The root need only contain XRF0 and XRFD. 464: * 465: * Version V1.4 1-Jul-80 466: * Version V1.5 3-Jul-80 Conditionaled date/time stuff. 467: * Version V1.6 MM 9-Jul-80 Changed date/time stuff 468: * Version V1.7 MM 10-Jul-80 File name changes 469: * Version V1.8 MM 21-Jul-80 Ctime() changed 470: * Version V1.9 MM 22-Jul-80 Redid initialization 471: * Version V1.11 RBD 26-Dec-80 Cleanup rt11 usage message 472: * Version V1.12 MM 22-Dec-81 Rtime isn't in vax library 473: * Version V1.13 MM 16-Feb-82 ctime fixup 474: */ 475: 476: #include 477: #include "xrf.h" 478: 479: extern int time_of_day[]; 480: Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 12 481: 482: /* 483: * Set up RSX file names, open them, and initialize the page header strings 484: */ 485: 486: initinfile(in) 487: char *in; 488: 489: { 490: char wrkbuf[40]; /* Working string buffer */ 491: 492: name(wrkbuf, in, "c", 0); /* Make input file name */ 493: if((src = fwild(wrkbuf, "r")) == NULL) 494: error("Cannot open %s\n", wrkbuf); 495: if (time_of_day[0] == 0) { 496: time(&time_of_day); 497: } 498: } 499: 500: initoutfile(out) 501: char *out; 502: { 503: char wrkbuf[40]; 504: char firstin[40]; 505: 506: if (out != NULL) 507: { 508: name(wrkbuf, out, "x", 0); 509: } 510: else 511: { 512: fgetname(src, firstin); 513: name(wrkbuf, firstin, "x", 1); /* Make list file name */ 514: } 515: if((lst = fopen(wrkbuf, "w")) == NULL) /* Try to open it */ 516: error("Cannot open listing file %s\n", wrkbuf); 517: 518: } 519: 520: nextinfile() 521: { 522: register char *wp; 523: register int c; 524: char wrkbuf[40]; 525: char *timetemp; 526: 527: if (fnext(src) == NULL) 528: return(0); 529: fgetname(src, wrkbuf); 530: for (wp = wrkbuf; (c = *wp++) && c != ':';); 531: if (c == 0) 532: wp = wrkbuf; 533: timetemp = ctime(&time_of_day); 534: timetemp[24] = '\0'; /* Trash newline */ 535: concat(pghead, "\fCross Reference of: ", 536: wp, "\t", timetemp, "\tPage ", 0); 537: return(1); Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 13 538: } 539: Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 14 540: 541: /* 542: * Make a file name. 543: * The mode argument is either 0 which means use type as default extension, 544: * or 1, which means force the extension to be type. Argument file is the 545: * 'raw' file name, sysnam is the final filename string. All arg's except 546: * mode are pointers, as usual. 547: * 548: */ 549: 550: name(sysnam, file, type, mode) 551: char *sysnam, *file, *type; 552: 553: int mode; 554: 555: { 556: register char *p1, *p2; /* Fast pointers */ 557: register int c; /* Fast char. buffer */ 558: 559: p1 = sysnam; /* p1 --> output string */ 560: p2 = file; /* p2 --> input string */ 561: while((c = *p2++) && c != '.') /* Copy up to '.' */ 562: *p1++ = c; 563: if( mode == 0 ) /* Default extension */ 564: { 565: if( c == '.' ) /* Extension explicitly given */ 566: { 567: do /* Copy '.' + any ext. */ 568: { 569: *p1++ = c; 570: } while( c = *p2++ ); 571: } 572: else /* No ext. given, default */ 573: { 574: *p1++ = '.'; 575: p2 = type; 576: while( c = *p2++ ) 577: *p1++ = c; 578: } 579: } 580: else /* Force extension */ 581: { 582: *p1++ = '.'; 583: p2 = type; 584: while( c = *p2++ ) 585: *p1++ = c; 586: } 587: *p1 = '\0'; /* Terminate with eos */ 588: } 589: /* 590: ***************************************************************************** 591: * 592: * Give user help on program useage. 593: */ 594: 595: useage() 596: { Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 15 597: extern int $$rsts; 598: #ifdef rt11 599: if ($$rsts) { 600: fprintf(stderr, "Usage: MCR XRF [-n] [-s] [-o outfile] infiles\n\n"); 601: fprintf(stderr, " -s Spool output file\n"); 602: } 603: else { 604: fprintf(stderr, "Usage (short): .RUN XR infile\n\n"); 605: fprintf(stderr, "Usage (long): .RUN XR\n"); 606: fprintf(stderr, " Argv: [-n] [-o outfile] infiles\n"); 607: } 608: #else 609: fprintf(stderr, "Usage: xrf [-s] [-n] [-o outfile] infiles\n\n"); 610: fprintf(stderr, " -s Spool output file\n"); 611: #endif 612: fprintf(stderr, " -n Narrow (80 column) output\n"); 613: fprintf(stderr, " -o Output to \"outfile\"\n\n"); 614: fprintf(stderr, "Input files may have wild-card names\n"); 615: fprintf(stderr, "Default input filetype is \".c\"\n"); 616: fprintf(stderr, "Default output filename is \".x\"\n"); 617: error("?XRF-E-parameter error"); 618: } 619: /* 620: * *************** 621: * * X R F 1 . C * 622: * *************** 623: * 624: * Lexical processing for C xref'er. Sifts through C source code 625: * and pulls out the identifiers. Recognizes reserved words and 626: * disregards them. Returns non-zero integer (true) if an id was 627: * successfully moved into 'idbuf', zero (false) if end-of-line 628: * was reached. I took care to test the C compiler's reaction to 629: * Formfeeds with respect to line numbers, and made sure the line 630: * numbers assigned by xrf act the same. 631: * 632: * Version V1.3 9-May-80 633: * Version V1.4 10-Jul-80 MM Allow $ in identifiers, bummed code 634: * Version V1.5 21-Jul-80 MM Dropped newline from ctime() 635: * Version V1.6 22-Jul-80 MM '.' is not an alpha char. 636: */ 637: 638: #include 639: #include "xrf.h" 640: 641: #define A 1 /* Alpha character */ 642: #define C 2 /* Start of comment possibly */ 643: #define L 3 /* Literal delimiter */ 644: #define N 4 /* Numeric character */ 645: #define Z 5 /* End of string */ 646: 647: #define NRW 28 /* # reserved words */ 648: 649: static int cmtflg = 0; /* Comment flag */ 650: 651: static char ctype[] = { /* Character action lookup */ 652: Z,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 653: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 654: 0,0,L,0,A,0,0,L,0,0,0,0,0,0,0,C, Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 16 655: N,N,N,N,N,N,N,N,N,N,0,0,0,0,0,0, 656: 0,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A, 657: A,A,A,A,A,A,A,A,A,A,A,0,0,0,0,A, 658: 0,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A, 659: A,A,A,A,A,A,A,A,A,A,A,0,0,0,0,0 660: }; 661: 662: static char *reswrd[NRW] = { 663: "auto", "break", "case", "char", 664: "continue", "default", "do", "double", 665: "else", "entry", "extern", "float", 666: "for", "goto", "if", "int", 667: "long", "register", "return", "short", 668: "sizeof", "static", "struct", "switch", 669: "typedef", "union", "unsigned", "while" 670: }; Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 17 671: 672: 673: /* 674: * Scan off a non reserved identifier. Put it into 'idbuf'. 675: * Returns +1 if successful, 0 if end-of-line was reached. 676: * 677: */ 678: 679: getid() /* Get an identifier into idbuf */ 680: 681: { 682: register char *p ; /* Fast scan pointer */ 683: register char *i ; /* Fast id buf pointer */ 684: register int c; /* Dispatch code */ 685: 686: p = scanp; /* Init fast pointers */ 687: i = idbuf; 688: 689: while ((c = *p) != 0) /* Scan till end of string */ 690: { 691: 692: if(c == '\014') /* If formfeed, */ 693: { 694: c = *p = ' '; /* Convert to harmless blank */ 695: newpage(); /* Force new page */ 696: } 697: 698: if (cmtflg) /* If comment flag is on */ 699: { 700: while(*p && *p++ != '*'); /* Scan to '*' or end of string */ 701: if(*p == '/') /* If we found end of comment */ 702: cmtflg = 0; /* Turn off comment flag */ 703: continue; /* and recycle */ 704: } 705: 706: switch(ctype[c]) /* Dispatch on the type */ 707: { 708: case A: /* Start of an identifier */ 709: i = idbuf; /* Reset the id buffer pointer */ 710: do 711: if( i < &idbuf[NCPS] ) /* Copy into idbuf */ 712: *i++ = *p++; 713: else /* Unless it gets full */ 714: p++; 715: while( (c=ctype[*p]) == A || c == N ); /* While alphanumeric */ 716: 717: while( i < &idbuf[NCPS] ) /* Pad idbuf with nulls */ 718: *i++ = '\0'; 719: if(nonres(idbuf)) /* If it's not a reserved word */ 720: { 721: scanp = p; /* Update the scan pointer */ 722: return (1); /* Return with success */ 723: } 724: break; /* End of identifier processing */ 725: 726: case N: /* Scan by a number string */ 727: do p++; while( (c=ctype[*p]) == N || c == A ); Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 18 728: break; 729: 730: case L: /* Scan by a literal */ 731: while (*++p != c && *p) { /* Scan to the matching trailing */ 732: if (*p == '\\') p++; /* Quote, ignoring backslash quoted */ 733: } /* Characters. If not at the end */ 734: if (*p) p++; /* Of the line, skip to the char. */ 735: break; /* Following the trailing quote */ 736: 737: case C: 738: if(*++p == '*') /* Start a comment */ 739: cmtflg = 1; /* by setting comment flag */ 740: break; 741: 742: default: /* Otherwise just scan it off */ 743: p++; 744: break; 745: } /* End of switch statement */ 746: 747: } /* If we exit here, end-of line. */ 748: return(0); /* Return with failure indication */ 749: } 750: Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 19 751: 752: 753: /* 754: * Search for reserved word. Return true (1) if NOT reserved word. 755: * Uses binary search. 756: */ 757: 758: nonres( bufp ) /* Test if not reserved word */ 759: char *bufp; 760: 761: { 762: register int low ; /* Low pointer index */ 763: register int mid ; /* Mid ... */ 764: register int hi ; /* hi ... */ 765: 766: int cond; /* Condition from strcmp */ 767: 768: low = 0; 769: hi = NRW-1; 770: 771: while (low <= hi) 772: { 773: mid = (low + hi) / 2; 774: if((cond = strcmp(bufp, reswrd[mid])) < 0) 775: hi = mid - 1; 776: else if (cond > 0) 777: low = mid + 1; 778: else 779: return(0); /* False, it IS reserved */ 780: } 781: return(1); /* True, it's NOT reserved */ 782: } 783: 784: /* 785: * *************** 786: * * X R F 3 . C * 787: * *************** 788: * 789: * Sorted cross reference listing routines. 'prtree' performs an 790: * inorder traversal of the id tree, printing the references to' 791: * each id while visiting that node. 792: * 793: * Version V1.3 9-May-80 794: * Version V1.4 10-Jul-80 MM Bummed code, added 80 col. support 795: */ 796: 797: #include 798: #include "xrf.h" 799: 800: 801: /* 802: * Inorder tree traversal. 803: */ 804: 805: prtree(link) 806: struct idt *link; 807: Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 20 808: { 809: if (link != NULL) 810: { 811: prtree(link->left); /* Visit the left */ 812: prtrefs(link); /* Print refs for this one */ 813: prtree(link->right); /* Visit the right */ 814: } 815: } 816: 817: /* 818: * List out a line of references. 819: * Start new page if it gets full. 820: */ 821: 822: lstrefs() 823: { 824: if(++linpg > MAXLIN) /* New page if necessary */ 825: newpage(); 826: fputss(scanbf, lst); /* Write out the string */ 827: } 828: 829: /* 830: * Print id and references. 831: * Share scan buffer for printout. 832: * Use newpag. 833: * 834: * The ref line number field width is hard-wired into the format statement. 835: * Trouble is, #define's don't (and shouldn't!) substitute into strings, 836: * like formats. 837: * 838: * Current values are 5 char field (RSIZE) and rperline ref's per line. 839: */ 840: 841: prtrefs(link) 842: struct idt *link; 843: 844: { 845: register struct ref *r; /* Ref chain pointer */ 846: register char *p; /* Fast scan buffer pointer */ 847: register int j; /* Counts refs printed on a line */ 848: 849: char *cpystr(); /* cpystr returns char pointer */ 850: 851: r = link->first; /* r --> head of ref chain */ 852: p = scanbf; /* p --> start of scan buffer */ 853: j = 0; /*Init refs-per-line */ 854: 855: p = cpystr(p, link->keyp); /* Start with the id string */ 856: while(p < &scanbf[NCPS]) /* Pad with blanks */ 857: *p++ = ' '; 858: *p++ = '\t'; /* Followed by a tab */ 859: do 860: { /* List Reference line numbers */ 861: if(j >= rperline) /* If this line is full */ 862: { 863: *p = '\0'; /* Terminate with null */ 864: lstrefs(); /* Write it out */ 865: p = scanbf; /* Reset buffer pointer */ Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 21 866: j = 0; /* Reset refs-on-line count */ 867: *p++ = '\t'; /* Start cont. line w/ 2 tabs */ 868: *p++ = '\t'; 869: } 870: j++; 871: sprintf(p,"%5d", r->lno); /* Insert reference into buffer */ 872: p += RSIZE; /* Update buffer pointer */ 873: r = r->next; /* On down the chain */ 874: } 875: while(r != NULL); /* Until the end */ 876: *p = '\0'; /* Terminate with null */ 877: lstrefs(); /* Write the line out */ 878: } Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 22 $$rsts 597 599 A 641 654 656 656 656 656 656 656 656 656 656 656 656 656 656 656 656 657 657 657 657 657 657 657 657 657 657 657 657 658 658 658 658 658 658 658 658 658 658 658 658 658 658 658 659 659 659 659 659 659 659 659 659 659 659 708 715 727 B 130 C 94 95 103 642 654 737 Cannot 123 124 Cross 94 95 DOCUMENT 92 Denny 130 FILE 440 441 Internal 119 L 643 654 654 730 LWIDTH 205 445 447 449 Lister 94 95 MAXLIN 243 824 N 644 655 655 655 655 655 655 655 655 655 655 715 726 727 NCPS 452 711 717 856 NRW 647 662 769 NULL 153 203 205 298 304 332 354 355 373 397 401 402 493 506 515 527 809 875 Narrow 106 Not 120 Programs 94 95 RSIZE 172 445 872 Referenc 94 95 Robert 130 Spool 108 The 103 106 109 Trying 117 Usage 125 Write 109 Z 645 652 a 103 110 accepts 112 amount 358 359 368 are 104 argc 142 155 165 188 argv 142 143 157 164 167 168 182 190 author 128 bufp 758 759 774 bugs 132 c 146 160 161 523 530 530 531 557 561 561 562 565 569 570 576 577 584 585 684 689 692 694 706 715 715 727 727 731 card 112 cmtflg 649 698 702 739 columns 106 107 concat 535 cond 294 307 313 766 774 776 cpystr 849 855 cross 103 ctime 533 ctype 651 706 715 727 define 641 642 643 644 645 647 defined 104 delete 421 descript 101 diagnost 114 Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 23 encounte 110 endif 134 223 611 enough 120 error 119 382 494 516 617 exit 224 422 extensio 110 fclose 420 fgetname 419 512 529 fgets 205 file 99 109 109 110 112 124 550 551 560 filetype 110 first 110 305 851 firstin 504 512 513 fnext 527 followin 104 fopen 515 fprintf 238 245 600 601 604 605 606 609 610 612 613 614 615 616 fputss 826 free 399 fspool 222 fwild 493 get 117 119 getid 209 679 h 136 268 437 476 638 797 help 119 hi 764 769 771 773 775 i 106 108 109 117 120 123 124 125 145 155 155 155 157 164 165 167 168 182 188 188 188 190 683 687 709 711 712 717 718 idbuf 210 452 687 709 711 717 719 idt 288 289 292 300 454 806 842 ifdef 92 220 598 in 486 487 492 in_file 148 190 192 include 136 137 268 269 437 438 476 477 638 639 797 798 index 95 initinfi 192 486 initoutf 197 500 input 110 112 is 106 109 j 847 853 861 866 870 keyp 301 303 307 855 kp 288 290 301 303 307 314 316 l 292 297 298 300 301 303 304 304 305 305 307 310 311 314 314 316 316 317 last 305 310 311 left 304 314 314 811 line 108 lineno 201 207 245 331 443 link 288 289 297 393 397 398 399 805 806 809 811 812 813 841 842 851 855 linpg 237 243 444 824 listing 103 124 lm 105 111 116 126 lno 331 871 low 762 768 771 773 777 lst 222 238 245 419 420 441 515 826 lstline 212 241 lstrefs 822 864 877 main 122 142 malloc 366 373 Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 24 memory 120 122 mid 763 773 774 775 777 mode 550 553 563 much 117 my_alloc 350 351 354 375 376 377 378 393 394 my_free 355 373 376 377 378 383 384 402 my_left 356 369 375 380 381 403 my_link 354 376 377 396 401 my_next 351 376 398 myalloc 300 301 330 358 myfree 202 388 n 106 name 492 508 513 550 named 109 needed 365 368 369 380 382 384 new 364 383 385 newpage 204 214 234 244 695 825 newref 295 305 309 326 next 310 332 394 396 397 398 873 nextarg 169 184 nextinfi 193 520 nofiles 151 187 195 198 218 nonres 719 758 o 99 109 of 110 122 open 123 124 options 99 104 out 122 500 501 506 508 out_file 149 153 167 197 outfile 99 output 106 108 109 p 147 157 158 160 682 686 689 694 700 700 701 712 714 715 721 727 727 731 731 732 732 734 734 738 743 846 852 855 855 856 857 858 863 865 867 868 871 872 876 p1 556 559 562 569 574 577 582 585 587 p2 556 560 561 570 575 576 583 584 pageno 139 200 236 238 pghead 238 447 535 prepares 103 printer 108 programs 103 prtree 215 805 811 813 prtrefs 812 841 puts 418 quit 374 414 r 293 309 310 311 328 330 331 332 333 845 851 871 873 873 875 ran 122 ref 293 295 325 328 330 845 referenc 103 reswrd 662 774 right 304 316 316 813 root 203 210 210 215 454 rperline 172 445 861 rsx 220 rt11 598 s 106 108 108 109 111 117 118 120 121 123 124 125 scanbf 205 208 245 449 826 852 856 865 scanp 208 450 686 721 search 210 288 314 316 Cross Reference of: XRF.LST;1 Mon May 12 13:31:32 1986 Page 25 source 103 space 120 122 splflg 150 154 176 221 sprintf 871 src 205 440 493 512 527 529 stderr 600 601 604 605 606 609 610 612 613 614 615 616 stdio 136 268 437 476 638 797 strcmp 307 774 strcpy 303 strlen 301 synopsis 97 sysnam 550 551 559 the 108 109 109 time 496 time_of_ 455 479 495 496 533 timetemp 525 533 534 536 title 94 to 108 109 117 tolower 161 too 117 type 550 551 575 583 useage 166 180 219 595 wild 112 with 110 workbuf 416 419 421 wp 522 530 530 532 536 wrkbuf 490 492 493 494 503 508 513 515 516 524 529 530 532 xrf 94 99 103 112 122