home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / lint-proto.pch < prev    next >
Encoding:
Internet Message Format  |  1988-11-09  |  25.9 KB

  1. Subject:  v16i066:  Turn 4.2BSD lint into a prototype generator
  2. Newsgroups: comp.sources.unix,comp.lang.c,comp.lang.c++
  3. Followup-To: comp.sources.d
  4. Sender: sources
  5. Approved: rsalz@uunet.UU.NET
  6.  
  7. Submitted-by: leech@cs.unc.edu
  8. Posting-number: Volume 16, Issue 66
  9. Archive-name: lint-proto.pch
  10.  
  11. [  This is a set of patches to the 4.2BSD lint sources.  It can be
  12.    merged into the 4.3 or a SunOS sources by hand (they're not that
  13.    extensive) and probably an ATT Unix also, although I've not tried that.
  14.    --r$  ]
  15.  
  16.     The following shar file contains patches to 4.2 BSD 'lint'
  17. to create a prototype generator. The modified BSD source is
  18. included as context diffs to (hopefully) get around copyright problems.
  19.     Thanks!
  20.     Jon Leech (leech@cs.unc.edu)
  21.     __@/
  22. #!/bin/sh
  23. # shar:    Shell Archiver
  24. #    Run the following text with /bin/sh to create:
  25. #    README
  26. #    print.c
  27. #    proto
  28. #    proto.1
  29. #    Makefile.diff
  30. #    lint.c.diff
  31. #    lmanifest.h.diff
  32. echo shar: extracting README '(2658 characters)'
  33. cat << \SHAR_EOF > README
  34.  
  35.  
  36.     PROTO - C prototype generator for BSD
  37.  
  38.  
  39. DESCRIPTION
  40.  
  41.     These files contain changes to 4.2 BSD lint to create a prototype
  42. generator. This was done by modifying lint pass 1. Normally lint
  43. creates an intermediate file in pass 1 including information on the
  44. types and parameters of functions in its input files. This
  45. intermediate file is read by lint pass 2 and used to check intermodule
  46. calls (among other purposes).
  47.  
  48.     The prototype generator changes the portions of lint pass 1 where
  49. the intermediate file is generated, gathering information on functions
  50. and printing it in prototype format (actually there are 3 possible
  51. output formats - see the man page for 'proto'). Warning messages
  52. generated by pass 1 have not all been suppressed; this is a cosmetic
  53. issue as the warnings are directed to standard error. The changes to
  54. lint pass 1 have been #ifdef'ed so that either the old or new versions
  55. may be created from the same source with appropriate flags to the C
  56. preprocessor.
  57.  
  58.     The generator consists of a frontend shell script, 'proto', and
  59. the modified lint pass 1, called 'proto1' by analogy to the two lint
  60. passes. The shell script gathers C preprocessor arguments and runs cpp
  61. over any input files, passing the result to proto1.
  62.  
  63. INSTALLATION
  64.  
  65.     Since source to BSD may not be distributed, proto is supplied in
  66. the form of context diffs (diff -c) to the changed files, and several
  67. added files. The patches to Makefile, lint.c, and lmanifest.h must be
  68. made, then print.c, proto, and proto.1 placed in your lint source
  69. directory. The files in this archive are:
  70.  
  71.     README         - this file
  72.     Makefile.diff    - context diffs to Makefile
  73.     lint.c.diff      - context diffs to lint.c
  74.     lmanifest.h.diff - context diffs to lmanifest.h
  75.     print.c         - new functions to print out prototypes
  76.     proto         - shell script frontend
  77.     proto.1         - man page
  78.  
  79.     Proto was generated from 4.2 BSD VAX source to lint.  It may also
  80. be compiled on Sun-3 and -4 workstations, with the proviso that, if
  81. the file /usr/include/pcc.h and the source directories for the
  82. portable C compiler are not in the expected places, the Makefile must
  83. be modified to reflect this (change the make variables M, P, and
  84. PCCH).
  85.  
  86.     The 'install' target in Makefile has been modified to install
  87. proto and proto1 as well as the previous lint binaries. This has not
  88. been tested, however. The man page 'proto.1' should be installed in
  89. /usr/man by hand. Note that the man page should be run through 'tbl'
  90. before installation.
  91.  
  92.     Please direct a copy of enhancements, bug fixes, etc. to the
  93. author.
  94.  
  95.     Enjoy!
  96.  
  97.     Jon Leech (leech@cs.unc.edu)
  98.     10/23/88
  99.     __@/
  100. SHAR_EOF
  101. echo shar: extracting print.c '(7335 characters)'
  102. cat << \SHAR_EOF > print.c
  103. /* print.c - C-style output functions for lint pass 1
  104.  *
  105.  *               COPYRIGHT NOTICE
  106.  *
  107.  * Copyright 1988 Jonathan P. Leech
  108.  *
  109.  * Permission is granted to reproduce and distribute this
  110.  *  software by any means so long as this notice is always retained
  111.  *  in the copies and so long as no fee is charged for copying.
  112.  *
  113.  * All other rights are reserved except as explicitly granted
  114.  *  by written permission of the author.
  115.  *
  116.  */
  117. #include <stdio.h>
  118. #include <ctype.h>
  119. #include "pass1.h"
  120. #include "lmanifest.h"
  121.  
  122. extern char *malloc();
  123. char *atype_name(),
  124.      *type_name(),
  125.      *flag_name(),
  126.      *Arg[MAX_ARG] = { NULL };
  127. int   ArgLine = -1;
  128. extern int FuncMode, PrintVars;
  129.  
  130. rec_print(rec, size, d, s)
  131. union rec *rec;
  132. {
  133.     int i;
  134.  
  135.     switch (rec->l.decflag) {
  136.     case LST:    /* static */
  137.     case LDI:    /* initialized */
  138.     case LIB:    /* library */
  139.     case LDC:    /* global */
  140.     case LDX:    /* global: if ! pflag, same as LDI     */
  141.         {
  142.         char *tname = atype_name(&rec->l.type, d, s, rec->l.name);
  143.  
  144.         /* Store function name for later use by func_decl() */
  145.         if (ISFTN(rec->l.type.aty)) {
  146.             if (!(Arg[0] = malloc(strlen(tname) + 10))) {
  147.             fprintf(stderr, "out of memory in rec_print()\n");
  148.             exit(1);
  149.             }
  150.             if (rec->l.decflag == LST)
  151.             sprintf(Arg[0], "static %s", tname);
  152.             else
  153.             strcpy(Arg[0], tname);
  154.             /* Save line on which function was defined */
  155.             ArgLine = rec->l.fline;
  156.         } else if (PrintVars) {
  157.             /* Variable, just print its declaration */
  158.             if (rec->l.decflag == LST)
  159.             printf("static ");
  160.  
  161.             fputs(tname, stdout);
  162.             fputs(";\n", stdout);
  163.         }
  164.         }
  165.         break;
  166.     case LFN:   /* library name */
  167.     case LRV:   /* function returning a value */
  168.     case LUV:   /* function/value context */
  169.     case LUE:   /* function/effects context */
  170.     case LUM:   /* mentioned somewhere other than at the declaration */
  171.     default:    /* combinations of flags, don't seem to happen */
  172.         break;
  173.     }
  174. }
  175.  
  176. #define NTYPE 40
  177. /* Get a string from the static pool (will not be reused for NTYPE calls) */
  178. char *buf_next() {
  179.     /* Allow up to NTYPE different strings */
  180.     static char buf[NTYPE][100];
  181.     static int    bufptr = 0;
  182.  
  183.     char *tmp = buf[bufptr];
  184.     bufptr = (bufptr + 1) % NTYPE;
  185.     *tmp = '\0';
  186.     return tmp;
  187. }
  188.  
  189. /* Print a type t in canonical (C) format
  190.  *  d & s are the dimoff & sizoff members from the corresponding
  191.  *  symbol table entry for the type member.
  192.  */
  193. char *type_name(t, d, s, var_name, struct_name)
  194. TWORD t;        /* Type in PCC internal form */
  195. int   d,        /* symtab->dimoff */
  196.       s;        /* symtab->sizoff */
  197. char *var_name;     /* Name of variable of this type (usually '%s' for printf) */
  198. char *struct_name;  /* Name of structure/union/enum(?) of base type */
  199. {
  200.     static char *tnames[] = {
  201.     "undef",
  202.     "farg",
  203.     "char",
  204.     "short",
  205.     "int",
  206.     "long",
  207.     "float",
  208.     "double",
  209.     "struct",
  210.     "union",
  211.     "enum",
  212.     "moety",    /* member of enum. type? */
  213.     "unsigned char",
  214.     "unsigned short",
  215.     "unsigned",
  216.     "unsigned long",
  217.     "?", "?"
  218.     };
  219.     char *buf = buf_next(),
  220.      *altbuf = buf_next(),
  221.      *this = buf,
  222.      *next;
  223.     int   i, sptr = 0, stack[100];  /* Stack of type modifiers for type t */
  224. #define VOID 0200   /* See "pcclocal.h"; this should not clash */
  225.  
  226.     /* Stack type modifiers up for easy access */
  227.     do {
  228.     if (ISPTR(t))
  229.         stack[sptr++] = PTR;
  230.     else if (ISFTN(t))
  231.         stack[sptr++] = FTN;
  232.     else if (ISARY(t))
  233.         stack[sptr++] = ARY;
  234.     else {
  235.     /* Watch out for void modifiers, no base type (?) */
  236.         stack[sptr++] = t;
  237.         break;
  238.     }
  239.     } while ((t = DECREF(t)));
  240.  
  241.     /* If no base type is supplied, must be a void (heuristic) */
  242.     if (sptr && (stack[sptr-1] == PTR ||
  243.          stack[sptr-1] == FTN ||
  244.          stack[sptr-1] == ARY))
  245.     stack[sptr++] = VOID;
  246.  
  247.     /* Nonsense type on stack to indicate an identifier */
  248.     stack[sptr] = 0;
  249.  
  250.     /* Initialize buffer with variable name */
  251.     strcpy(this, var_name);
  252.  
  253.     if (struct_name == NULL)
  254.     struct_name = "<Unknown tag>";
  255.  
  256.     /* For each layer of type, wrap the C-style declaration
  257.      *    of the type around it.
  258.      */
  259.     for (i = 0; i < sptr; i++) {
  260.     /* Where to build next buffer */
  261.     next = (this == buf) ? altbuf : buf;
  262.     switch (stack[i]) {
  263.         case PTR:
  264.         /*    *(*x)    -> **x
  265.          *    (*x)[]    -> (*x)[]
  266.          *    (*x)()    -> (*x)()
  267.          */
  268.         if (stack[i+1] == FTN || stack[i+1] == ARY) {
  269.             strcpy(next, "(*");
  270.             strcat(next, this);
  271.             strcat(next, ")");
  272.         } else {
  273.             strcpy(next, "*");
  274.             strcat(next, this);
  275.         }
  276.         break;
  277.         case FTN:
  278.         /*    *(x())    -> *x()
  279.          *    (x())[] -> x()[]    // illegal
  280.          *    (x())() -> x()()    // illegal
  281.          */
  282.         strcpy(next, this);
  283.         strcat(next, "()");
  284.         break;
  285.         case ARY:
  286.         /*    *(x[])    -> *x[]
  287.          *    (x[])[] -> x[][]
  288.          *    (x[])() -> x[]())   // illegal
  289.          */
  290.         if (dimtab[d]) {
  291.             sprintf(next, "%s[%d]", this, dimtab[d]);
  292.         } else {
  293.             /* Unknown dimension */
  294.             strcpy(next, this);
  295.             strcat(next, "[]");
  296.         }
  297.         d++;
  298.         break;
  299.         case STRTY:
  300.         sprintf(next, "struct %s %s", struct_name, this);
  301.         break;
  302.         case UNIONTY:
  303.         sprintf(next, "union %s %s", struct_name, this);
  304.         break;
  305.         case ENUMTY:
  306.         sprintf(next, "enum %s %s", struct_name, this);
  307.         break;
  308.         case MOETY:
  309.         sprintf(next, "(enum member ?%s?) %s", struct_name, this);
  310.         break;
  311.         case VOID:
  312.         sprintf(next, "void %s", this);
  313.         break;
  314.         default:
  315.         /* Scalar type */
  316.         if (this[0] != '\0')
  317.             sprintf(next, "%s %s", tnames[t], this);
  318.         else
  319.             strcpy(next, tnames[t]);
  320.         break;
  321.     }
  322.     /* Swap buffers */
  323.     this = next;
  324.     }
  325.  
  326.     /* Return the formed type string */
  327.     return next;
  328. }
  329.  
  330. /* Routine to form symbolic name of a type.
  331.  *  t - type
  332.  *  d - dimoff from symbol table
  333.  *  s - sizoff from symbol table
  334.  *  varname - variable name to generate (can use "" for none)
  335.  */
  336. char *atype_name(t, d, s, varname)
  337. ATYPE *t;
  338. int    d, s;
  339. char  *varname;
  340. {
  341.     char *ptr = buf_next();
  342.  
  343.     /* Size of type is in t->extra, if it's nonzero */
  344.     strcpy(ptr, type_name(t->aty, d, s, varname, t->extra1));
  345.  
  346.     return ptr;
  347. }
  348.  
  349. /* Return a new copy of a string */
  350. char *str_copy(s)
  351. char *s;
  352. {
  353.     char *t = malloc(strlen(s) + 1);
  354.  
  355.     if (!t) {
  356.     fprintf(stderr, "Out of memory in print.c:str_copy()\n");
  357.     exit(1);
  358.     }
  359.  
  360.     strcpy(t, s);
  361.     return t;
  362. }
  363.  
  364. /* Print out a function declaration using information on function
  365.  *  arguments stored away earlier in parsing.
  366.  * Comment out arguments in the prototype if Comment is true.
  367.  */
  368. void func_decl(nargs)
  369. int nargs;
  370. {
  371.     int i;
  372.     char *fname = Arg[0];
  373.  
  374.     /* Write function name */
  375.     if (!fname)
  376.     fname = "<Unknown function>";
  377.     else
  378.     fname[strlen(fname)-2] = '\0';    /* Dispose of trailing () */
  379.  
  380.     switch (FuncMode) {
  381.     case OLD_C:
  382.         printf("%s(/* ", fname);
  383.         break;
  384.     case MIXED:
  385.         printf("DECL(%s,(", fname);
  386.         break;
  387.     case C_PLUSPLUS:
  388.         printf("%s(", fname);
  389.         break;
  390.     }
  391.  
  392.     if (Arg[0] != NULL) {
  393.     free(Arg[0]);        /* Free it */
  394.     Arg[0] = NULL;        /* Mark empty slot for future calls */
  395.     }
  396.  
  397.     /* Write out each argument type & free associated space */
  398.     /* Note argument indices are 1-based */
  399.  
  400.     for (i = 1; i <= nargs; i++) {
  401.     fputs(Arg[i], stdout);
  402.     free(Arg[i]);
  403.     if (i < nargs) {
  404.         fputs(", ", stdout);
  405.     }
  406.     }
  407.  
  408.     switch (FuncMode) {
  409.     case OLD_C:
  410.         fputs(" */);\n", stdout);
  411.         break;
  412.     case MIXED:
  413.         fputs("));\n", stdout);
  414.         break;
  415.     case C_PLUSPLUS:
  416.         fputs(");\n", stdout);
  417.         break;
  418.     }
  419. }
  420. SHAR_EOF
  421. echo shar: extracting proto '(420 characters)'
  422. cat << \SHAR_EOF > proto
  423. #! /bin/sh
  424. #
  425. #  proto.sh - frontend for prototype generator
  426. #  collects CPP arguments and preprocesses source files before
  427. #   running proto1 over them.
  428.  
  429. proto=proto1
  430. propts=
  431. cppopts=
  432. for opt in $* ; do
  433.     case $opt in
  434.     -[IDU]*)
  435.         cppopts="$cppopts $opt"
  436.         ;;
  437.     -*)     propts="$propts $opt"
  438.         ;;
  439.     *)        echo 1>&2 "$opt:"
  440.         /lib/cpp $cppopts $opt | $proto $propts 2>/dev/null
  441.         ;;
  442.     esac
  443. done
  444. SHAR_EOF
  445. echo shar: extracting proto.1 '(2585 characters)'
  446. cat << \SHAR_EOF > proto.1
  447. .\"% tbl proto.1 | nroff -man | less
  448. .de Fs
  449. .sp
  450. .in +0.5i
  451. .nf
  452. .ft CW
  453. ..
  454. .de Fe
  455. .ft P
  456. .fi
  457. .in -0.5i
  458. .sp
  459. ..
  460. .TH PROTO 1 "October 23 1988"
  461. .SH NAME
  462. proto - generate function prototypes from C source
  463. .SH SYNOPSIS
  464. \fBproto\fP [ -m[c+M] -V ]
  465. .br
  466. .SH DESCRIPTION
  467. \fIproto\fP is a modified version of Berkeley lint. It reads C source
  468. files and prints a declaration of all functions and (optionally)
  469. global variables defined therein. Function declarations are in the form of
  470. prototypes which may be used in C++ or an ANSI C compiler.
  471. .LP
  472. The \fB-m\fP option controls the style in which prototypes are printed.
  473. There are three possibilities: old-C style (\fB-mc\fP), C++ style
  474. (\fB-m+\fP), or mixed style (\fB-mM\fP). The default is C++ style.
  475. .LP
  476. Given as input a function defined as follows:
  477. .Fs
  478. int f(i, d) int i; double d; { return d + i; }
  479. .Fe
  480. the output of \fIproto\fP for each style will be:
  481. .sp
  482. .in +0.5i
  483. .TS
  484. tab(@);
  485. l l
  486. l l
  487. lb l.
  488. Style@Form of \fIproto\fP output
  489. _@_
  490. -mc@int f(/* int i, double d */);
  491. -m+@int f(int i, double d);
  492. -mM@DECL(int f,(int i, double d));
  493. .TE
  494. .in -0.5i
  495. .sp
  496. .LP
  497. Output produced in old-C style is legal input to a C compiler which
  498. does not understand prototypes. The prototype information is commented
  499. out. Output in C++ style is legal input to C++ or a C compiler
  500. which does understand prototypes.
  501. Output in mixed style generates a definition of the macro DECL,
  502. such that the function prototype for f will appear in old-C or C++ style
  503. when the output of \fIproto\fP is read by the corresponding compiler.
  504. This relies on the macro \fBc_plusplus\fP being defined by a C++
  505. compiler, as does the AT&T C++ compiler \fIcfront\fP.
  506. .LP
  507. Normally, declarations for variables are not generated by \fIproto\fP.
  508. This may be overridden with the -V flag.
  509. .LP
  510. When a \fBtypedef\fP appears, the 'typedef name' of the type is
  511. not propagated through \fIproto\fP. Instead, the equivalent
  512. complex type appears in the output. For example, the following
  513. input:
  514. .Fs
  515. typedef char *STRING;
  516. STRING str_copy(s) STRING s; { return s; }
  517. .Fe
  518. generates the output:
  519. .Fs
  520. char *str_copy(char *s);
  521. .Fe
  522. If a \fBstruct\fP, \fBunion\fP, or \fBenum\fP is \fBtypedef\fP'ed
  523. without a tag, \fIproto\fP will be unable to determine the
  524. correct output form for a variable of or function returning that type.
  525. .SH AUTHOR
  526. Modifications to Berkeley lint by Jon Leech (leech@cs.unc.edu).
  527. .SH BUGS
  528. Someone with sufficient knowledge of PCC and lint could probably fix
  529. \fIproto\fP to generate typedef names instead of the corresponding
  530. type. This is the most annoying problem at present.
  531. .SH SEE ALSO
  532. cc(1), lint(1)
  533. SHAR_EOF
  534. echo shar: extracting Makefile.diff '(4215 characters)'
  535. cat << \SHAR_EOF > Makefile.diff
  536. diff -bc ./Makefile 4.2_lint/Makefile
  537. *** ./Makefile    Sun Oct 23 17:39:59 1988
  538. --- 4.2_lint/Makefile    Sat Mar 29 16:23:07 1986
  539. ***************
  540. *** 3,22 ****
  541.   #
  542.   M=/usr/src/lib/mip
  543.   P=/usr/src/lib/pcc
  544. ! # PCCH = /usr/include/pcc.h on BSD systems with this file.
  545. ! # Otherwise it must be copied from such a system.
  546. ! PCCH=pcc.h
  547. ! CFLAGS=-O -I$M -I.
  548.   LINTLIBS=llib-port.ln llib-lc.ln llib-lcurses.ln llib-ldbm.ln llib-lm.ln \
  549.     llib-lmp.ln llib-lplot.ln llib-ltermcap.ln
  550.   SRCS= $M/cgram.y $M/common.c $M/optim.c $M/pftn.c $M/scan.c $M/trees.c \
  551.     $M/xdefs.c lint.c hash.c $M/pass1.h $M/manifest.h macdefs.h \
  552.     lpass2.c
  553. - # Object files for prototype generation
  554. - POBJS= cgram.o rodata.o comm1.o optim.o pftn.o scan.o trees.o xdefs.o \
  555. -     lint_proto.o hash.o print.o
  556.  
  557. ! all:    lpass1 lpass2 proto1 $(LINTLIBS)
  558.  
  559.   lpass1: cgram.o rodata.o comm1.o optim.o pftn.o scan.o trees.o xdefs.o \
  560.     lint.o hash.o
  561. --- 3,16 ----
  562.   #
  563.   M=/usr/src/lib/mip
  564.   P=/usr/src/lib/pcc
  565. ! CFLAGS=-O
  566.   LINTLIBS=llib-port.ln llib-lc.ln llib-lcurses.ln llib-ldbm.ln llib-lm.ln \
  567.     llib-lmp.ln llib-lplot.ln llib-ltermcap.ln
  568.   SRCS= $M/cgram.y $M/common.c $M/optim.c $M/pftn.c $M/scan.c $M/trees.c \
  569.     $M/xdefs.c lint.c hash.c $M/pass1.h $M/manifest.h macdefs.h \
  570.     lpass2.c
  571.  
  572. ! all:    lpass1 lpass2 ${LINTLIBS}
  573.  
  574.   lpass1: cgram.o rodata.o comm1.o optim.o pftn.o scan.o trees.o xdefs.o \
  575.     lint.o hash.o
  576. ***************
  577. *** 23,32 ****
  578.     ${CC} ${CFLAGS} cgram.o rodata.o comm1.o optim.o pftn.o scan.o \
  579.         trees.o xdefs.o lint.o hash.o -o lpass1
  580.  
  581. - # Proto is much like lpass1, but must recompile lint.c with -DPROTO
  582. - proto1: $(POBJS)
  583. -    ${CC} ${CFLAGS} $(POBJS) -o proto1
  584. -
  585.   cgram.o: $M/manifest.h $M/pass1.h pcclocal.h macdefs.h cgram.c
  586.     $(CC) -c $(CFLAGS) -I$M -I. cgram.c
  587.  
  588. --- 17,22 ----
  589. ***************
  590. *** 34,40 ****
  591.     $(CC) -c $(CFLAGS) -R rodata.c
  592.  
  593.   comm1.o: $M/manifest.h $M/pass1.h pcclocal.h $M/common.c macdefs.h
  594. !    ln -s $M/common.c comm1.c
  595.     $(CC) -c $(CFLAGS) -I$M -I. -DPASS1COMMON comm1.c
  596.     rm -f comm1.c
  597.  
  598. --- 24,30 ----
  599.     $(CC) -c $(CFLAGS) -R rodata.c
  600.  
  601.   comm1.o: $M/manifest.h $M/pass1.h pcclocal.h $M/common.c macdefs.h
  602. !    ln $M/common.c comm1.c
  603.     $(CC) -c $(CFLAGS) -I$M -I. -DPASS1COMMON comm1.c
  604.     rm -f comm1.c
  605.  
  606. ***************
  607. *** 62,89 ****
  608.  
  609.   GREP= egrep
  610.  
  611. ! pcclocal.h: $P/localdefs.h $(PCCH)
  612.     rm -f pcclocal.h
  613. !    cat $(PCCH) $P/localdefs.h | $(GREP) '^#[    ]*(define[    ][    ]*PCC(F|T|TM|OM)?_|ifdef|ifndef|endif)' | sed -e 's/PCC[A-Z]*_//' > pcclocal.h
  614.  
  615. ! pcctokens: $P/localdefs.h $(PCCH)
  616.     rm -f pcctokens
  617. !    cat $(PCCH) $P/localdefs.h | $(GREP) '^#[    ]*define[    ][    ]*PCC_' | sed -e 's/^#[        ]*define[    ][    ]*PCC_/%term    /' > pcctokens
  618.  
  619.   lint.o: $M/manifest.h macdefs.h $M/pass1.h lmanifest.h
  620.     ${CC} -c ${CFLAGS} -I$M -I. lint.c
  621.  
  622. - # lint_proto is a version of lint.c with alternate output methods enabled
  623. - #   by defining PROTO.
  624. - lint_proto.o: $M/manifest.h macdefs.h $M/pass1.h lmanifest.h lint.c
  625. -    ${CC} -c -DPROTO ${CFLAGS} lint_proto.c
  626. -
  627. - print.o: $M/pass1.h lmanifest.h
  628. -    ${CC} -c -DPROTO ${CFLAGS} print.c
  629. -
  630. - lint_proto.c:
  631. -    ln -s lint.c lint_proto.c
  632. -
  633.   llib-port.ln: llib-port lpass1
  634.     -(/lib/cpp -C -Dlint llib-port | ./lpass1 -puv > llib-port.ln )
  635.  
  636. --- 52,68 ----
  637.  
  638.   GREP= egrep
  639.  
  640. ! pcclocal.h: $P/localdefs.h /usr/include/pcc.h
  641.     rm -f pcclocal.h
  642. !    cat /usr/include/pcc.h $P/localdefs.h | $(GREP) '^#[    ]*(define[    ][    ]*PCC(F|T|TM|OM)?_|ifdef|ifndef|endif)' | sed -e 's/PCC[A-Z]*_//' > pcclocal.h
  643.  
  644. ! pcctokens: $P/localdefs.h /usr/include/pcc.h
  645.     rm -f pcctokens
  646. !    cat /usr/include/pcc.h $P/localdefs.h | $(GREP) '^#[    ]*define[    ][    ]*PCC_' | sed -e 's/^#[        ]*define[    ][    ]*PCC_/%term    /' > pcctokens
  647.  
  648.   lint.o: $M/manifest.h macdefs.h $M/pass1.h lmanifest.h
  649.     ${CC} -c ${CFLAGS} -I$M -I. lint.c
  650.  
  651.   llib-port.ln: llib-port lpass1
  652.     -(/lib/cpp -C -Dlint llib-port | ./lpass1 -puv > llib-port.ln )
  653.  
  654. ***************
  655. *** 121,128 ****
  656.   install: all SHELL
  657.     install -s lpass1 ${DESTDIR}/usr/lib/lint/lint1
  658.     install -s lpass2 ${DESTDIR}/usr/lib/lint/lint2
  659. -    install -s proto1 ${DESTDIR}/usr/lib/lint/proto1
  660. -    install -c proto ${DESTDIR}/usr/lib/lint/proto
  661.     for i in llib-*; do install -c -m 644 $$i ${DESTDIR}/usr/lib/lint; done
  662.     -rm -f ${DESTDIR}/usr/lib/lint/llib-ltermlib*
  663.     ln -s llib-ltermcap ${DESTDIR}/usr/lib/lint/llib-ltermlib
  664. --- 100,105 ----
  665. SHAR_EOF
  666. echo shar: extracting lint.c.diff '(6691 characters)'
  667. cat << \SHAR_EOF > lint.c.diff
  668. diff -bc ./lint.c 4.2_lint/lint.c
  669. *** ./lint.c    Tue Oct  4 20:37:13 1988
  670. --- 4.2_lint/lint.c    Tue Nov 24 14:30:03 1987
  671. ***************
  672. *** 39,48 ****
  673.   int aflag = 0;    /* used to check precision of assignments */
  674.   int zflag = 0;    /* no 'structure never defined' error */
  675.   int Cflag = 0;    /* filter out certain output, for generating libraries */
  676. - #ifdef PROTO
  677. - int FuncMode = C_PLUSPLUS;  /* Comment out function argument types in prototypes */
  678. - int PrintVars = 0;        /* Whether to print out variable declarations */
  679. - #endif    /* PROTO */
  680.   char *libname = 0;  /* name of the library we're generating */
  681.  
  682.     /* flags for the "outdef" function */
  683. --- 39,44 ----
  684. ***************
  685. *** 57,66 ****
  686.     short lid, flgs;
  687.     }  lnames[LNAMES], *lnp;
  688.  
  689. - #ifdef PROTO
  690. - char *X_NONAME = "<Unnamed struct/union>";
  691. - #endif    /* PROTO */
  692. -
  693.   contx( p, down, pl, pr ) register NODE *p; register *pl, *pr; {
  694.  
  695.     *pl = *pr = VAL;
  696. --- 53,58 ----
  697. ***************
  698. *** 179,190 ****
  699.  
  700.   astype( t, i ) ATYPE *t; {
  701.     TWORD tt;
  702. !    int j, k=0;
  703. ! #ifndef PROTO
  704. !    int l = 0;
  705. ! #else
  706. !    char *l = NULL;
  707. ! #endif    /* PROTO */
  708.  
  709.     if( (tt=BTYPE(t->aty))==STRTY || tt==UNIONTY ){
  710.         if( i<0 || i>= DIMTABSZ-3 ){
  711. --- 171,177 ----
  712.  
  713.   astype( t, i ) ATYPE *t; {
  714.     TWORD tt;
  715. !    int j, k=0, l=0;
  716.  
  717.     if( (tt=BTYPE(t->aty))==STRTY || tt==UNIONTY ){
  718.         if( i<0 || i>= DIMTABSZ-3 ){
  719. ***************
  720. *** 194,204 ****
  721.             j = dimtab[i+3];
  722.             if( j<0 || j>SYMTSZ ){
  723.                 k = dimtab[i];
  724. - #ifndef PROTO
  725.                 l = X_NONAME | stab[j].suse;
  726. - #else
  727. -                l = X_NONAME;
  728. - #endif    /* PROTO */
  729.                 }
  730.             else {
  731.                 if( stab[j].suse <= 0 ) {
  732. --- 181,187 ----
  733. ***************
  734. *** 211,239 ****
  735.                     }
  736.                 else {
  737.                     k = dimtab[i];
  738. - #ifndef PROTO
  739.   #ifdef FLEXNAMES
  740.                     l = hashstr(stab[j].sname);
  741.   #else
  742.                     l = hashstr(stab[j].sname, LCHNM);
  743.   #endif
  744. - #else
  745. -                    l = stab[j].sname;
  746. - #endif    /* PROTO */
  747.                     }
  748.                 }
  749.             }
  750.  
  751.         t->extra = k;
  752. - #ifndef PROTO
  753.         t->extra1 = l;
  754. - #else
  755. - #ifdef FLEXNAMES
  756. -        t->extra1 = l;
  757. - #else
  758. -        strncpy(t->extra1, l, LCHNM);
  759. - #endif    /* FLEXNAMES */
  760. - #endif    /* PROTO */
  761.         return( 1 );
  762.         }
  763.     else return( 0 );
  764. --- 194,210 ----
  765. ***************
  766. *** 292,314 ****
  767.  
  768.                     }
  769.                 }
  770. ! #ifndef PROTO
  771. !            fwrite((char *)&t, sizeof(ATYPE), 1, stdout);
  772. ! #else /* PROTO */
  773. !            /* Save argument i */
  774. !            if (i < MAX_ARG-1)
  775. !                Arg[i+1] = str_copy(atype_name(&t, cfp->dimoff, cfp->sizoff, ""));
  776. !            else
  777. !                fprintf(stderr, "Can't save argument %d\n", i);
  778. ! #endif
  779.             }
  780.         }
  781. - #ifdef PROTO
  782. -        /* Function name & all argument types are accumulated;
  783. -         *  generate prototype.
  784. -         */
  785. -        func_decl(n);
  786. - #endif    /* PROTO */
  787.     }
  788.  
  789.   ctargs( p ) NODE *p; {
  790. --- 263,271 ----
  791.  
  792.                     }
  793.                 }
  794. !            fwrite( (char *)&t, sizeof(ATYPE), 1, stdout );
  795.             }
  796.         }
  797.     }
  798.  
  799.   ctargs( p ) NODE *p; {
  800. ***************
  801. *** 362,377 ****
  802.                 break;
  803.             }
  804.         }
  805. ! #ifndef PROTO
  806. !    fwrite((char *)&t, sizeof(ATYPE), 1, stdout);
  807. ! #else
  808. !    /* This type of declaration is an internal function call,
  809. !     *  *not* a definition. Ignore it for prototype purposes.
  810. !     */
  811. !    /*
  812. !    printf("(lpta) %s\n", atype_name(&t, -1, -1, ""));
  813. !     */
  814. ! #endif
  815.     }
  816.  
  817.   # define VALSET 1
  818. --- 319,325 ----
  819.                 break;
  820.             }
  821.         }
  822. !    fwrite( (char *)&t, sizeof(ATYPE), 1, stdout );
  823.     }
  824.  
  825.   # define VALSET 1
  826. ***************
  827. *** 885,905 ****
  828.         fsname.f.fn = s;
  829.   #endif
  830.         fsname.f.decflag = LFN;
  831. - #ifndef PROTO
  832.         fwrite( (char *)&fsname, sizeof(fsname), 1, stdout );
  833. - #else
  834. -        rec_print(&fsname, sizeof(fsname), -1, -1);
  835. - #endif    /* PROTO */
  836.   #ifdef FLEXNAMES
  837.         /* if generating a library, prefix with the library name */
  838.         /* only do this for flexnames */
  839. - #ifndef PROTO
  840.         if( libname ){
  841. !            fwrite(libname, strlen(libname), 1, stdout);
  842. !            putchar(':');
  843.         }
  844. !        fwrite((char *)&fsname.f.fn, strlen(fsname.f.fn)+1, 1, stdout);
  845. ! #endif    /* PROTO */
  846.   #endif
  847.         }
  848.     }
  849. --- 833,847 ----
  850.         fsname.f.fn = s;
  851.   #endif
  852.         fsname.f.decflag = LFN;
  853.         fwrite( (char *)&fsname, sizeof(fsname), 1, stdout );
  854.   #ifdef FLEXNAMES
  855.         /* if generating a library, prefix with the library name */
  856.         /* only do this for flexnames */
  857.         if( libname ){
  858. !            fwrite( libname, strlen(libname), 1, stdout );
  859. !            putchar( ':' );
  860.             }
  861. !        fwrite( fsname.f.fn, strlen(fsname.f.fn)+1, 1, stdout );
  862.   #endif
  863.         }
  864.     }
  865. ***************
  866. *** 1436,1475 ****
  867.                 while( p[1] ) p++;
  868.                 continue;
  869.  
  870. - #ifdef PROTO
  871. -            /* Set function prototype output mode.
  872. -             * Options are:
  873. -             *  -mc     old-c compatible (comment arguments)
  874. -             *  -m+     C++ compatible (no comments)
  875. -             *  -mM     mixed mode, selectable with #define
  876. -             */
  877. -            case 'm':
  878. -                switch (p[1]) {
  879. -                case 'c':
  880. -                case 'C':
  881. -                    FuncMode = OLD_C;
  882. -                    break;
  883. -                case '+':
  884. -                    FuncMode = C_PLUSPLUS;
  885. -                    break;
  886. -                case 'm':
  887. -                case 'M':
  888. -                    FuncMode = MIXED;
  889. -                    break;
  890.                 default:
  891. -                    fprintf(stderr, "%s: Unknown option %s (-mc, -m+, -mm allowed)\n",
  892. -                    argv[0], p);
  893. -                    exit(1);
  894. -                }
  895. -                continue;
  896. -
  897. -            case 'V':
  898. -                PrintVars = 1;
  899. -                continue;
  900. -
  901. - #endif    /* PROTO */
  902. -
  903. -            default:
  904.                 uerror( "illegal option: %c", *p );
  905.                 continue;
  906.  
  907. --- 1378,1384 ----
  908. ***************
  909. *** 1476,1501 ****
  910.                 }
  911.             }
  912.  
  913. - #ifdef PROTO
  914. -    /* Print out a header for mixed-mode prototypes */
  915. -    if (FuncMode == MIXED) {
  916. -        int i;
  917. -        static char *def_decl[] = {
  918. -        "#ifndef DECL",
  919. -        "#ifdef c_plusplus",
  920. -        "#define DECL(func,args) func args",
  921. -        "#else",
  922. -        "#define DECL(func,args) func()",
  923. -        "#endif\t/* c_plusplus */",
  924. -        "#endif\t/* DECL */",
  925. -        };
  926. -
  927. -        for (i = 0; i < sizeof(def_decl) / sizeof(char *); i++)
  928. -        puts(def_decl[i]);
  929. -
  930. -    }
  931. - #endif    /* PROTO */
  932. -
  933.     if( !pflag ){  /* set sizes to sizes of target machine */
  934.   # ifdef gcos
  935.         SZCHAR = ALCHAR = 9;
  936. --- 1385,1390 ----
  937. ***************
  938. *** 1597,1605 ****
  939.         }
  940.     fsave( fname );
  941.   #ifndef FLEXNAMES
  942. !    strncpy( rc.l.name, p->sname, LCHNM );
  943. ! #else
  944. !    rc.l.name = p->sname;
  945.   #endif
  946.     rc.l.decflag = lty;
  947.     t = p->stype;
  948. --- 1486,1492 ----
  949.         }
  950.     fsave( fname );
  951.   #ifndef FLEXNAMES
  952. !    strncpy( rc.l.name, exname(p->sname), LCHNM );
  953.   #endif
  954.     rc.l.decflag = lty;
  955.     t = p->stype;
  956. ***************
  957. *** 1610,1623 ****
  958.     astype( &rc.l.type, p->sizoff );
  959.     rc.l.nargs = (mode>USUAL) ? mode : 0;
  960.     rc.l.fline = line;
  961. - #ifndef PROTO
  962.     fwrite( (char *)&rc, sizeof(rc), 1, stdout );
  963.   #ifdef FLEXNAMES
  964. !    fwrite((char *)&rc.l.name, strlen(rc.l.name)+1, 1, stdout);
  965.   #endif
  966. - #else
  967. -    rec_print(&rc, sizeof(rc), p->dimoff, p->sizoff);
  968. - #endif    /* PROTO */
  969.     }
  970.   int proflg;
  971.   int gdebug;
  972. --- 1497,1507 ----
  973.     astype( &rc.l.type, p->sizoff );
  974.     rc.l.nargs = (mode>USUAL) ? mode : 0;
  975.     rc.l.fline = line;
  976.     fwrite( (char *)&rc, sizeof(rc), 1, stdout );
  977.   #ifdef FLEXNAMES
  978. !    rc.l.name = exname(p->sname);
  979. !    fwrite( rc.l.name, strlen(rc.l.name)+1, 1, stdout );
  980.   #endif
  981.     }
  982.   int proflg;
  983.   int gdebug;
  984. SHAR_EOF
  985. echo shar: extracting lmanifest.h.diff '(1072 characters)'
  986. cat << \SHAR_EOF > lmanifest.h.diff
  987. diff -bc ./lmanifest.h 4.2_lint/lmanifest.h
  988. *** ./lmanifest.h    Mon Oct 10 00:45:59 1988
  989. --- 4.2_lint/lmanifest.h    Fri Apr  5 19:40:13 1985
  990. ***************
  991. *** 33,54 ****
  992.   typedef struct ty {
  993.     TWORD aty;
  994.     short extra;
  995. - #ifndef PROTO
  996.     short extra1;
  997. - #else
  998. - #ifndef FLEXNAMES
  999. -    char extra1[LCHNM];
  1000. - #else
  1001. -    char *extra1;
  1002. - #endif    /* FLEXNAMES */
  1003. - #endif    /* PROTO */
  1004.     } ATYPE;
  1005.  
  1006. - #ifndef PROTO
  1007.   #define X_NONAME 0x8000        /* for extra1, if structure has no name */
  1008. - #else
  1009. - extern char *X_NONAME;        /* for extra1, if structure has no name */
  1010. - #endif    /* PROTO */
  1011.  
  1012.   typedef struct line {
  1013.     short decflag;
  1014. --- 33,42 ----
  1015. ***************
  1016. *** 73,91 ****
  1017.   #endif
  1018.         } f;
  1019.     };
  1020. -
  1021. - #ifdef PROTO
  1022. - /* Maximum # of arguments to a function. Arg 0 is function name */
  1023. - #define MAX_ARG 21
  1024. - extern
  1025. - char *Arg[MAX_ARG],    /* Function argument types in symbolic form */
  1026. -      *X_NONAME,
  1027. -      *atype_name(),
  1028. -      *str_copy();
  1029. -
  1030. - /* Possible function prototype output modes. */
  1031. - #define OLD_C    0
  1032. - #define C_PLUSPLUS 1
  1033. - #define MIXED    2
  1034. -
  1035. - #endif    /* PROTO */
  1036. --- 61,63 ----
  1037. SHAR_EOF
  1038. #    End of shell archive
  1039. exit 0
  1040.  
  1041.  
  1042.