home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / indent / part02 < prev    next >
Text File  |  1991-08-07  |  54KB  |  1,932 lines

  1. Newsgroups: comp.sources.misc,comp.lang.c++
  2. From: Benson I. Margulies <benson@odi.com>
  3. Subject:  v21i099:  indent - BSD Indent with C++ support, Part02/03
  4. Message-ID: <1991Aug8.015909.3312@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 3fb413b78ebfa59cd207a30fae98bbbf
  6. Date: Thu, 8 Aug 1991 01:59:09 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Benson I. Margulies <benson@odi.com>
  10. Posting-number: Volume 21, Issue 99
  11. Archive-name: indent/part02
  12. Environment: UNIX, C++
  13.  
  14. #! /bin/sh
  15. # into a shell via "sh file" or similar.  To overwrite existing files,
  16. # type "sh file -c".
  17. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  18. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  19. # Contents:  indent/Makefile indent/README indent/indent.1
  20. #   indent/indent_codes.h indent/io.c indent/lexi.c
  21. # Wrapped by kent@sparky on Wed Aug  7 19:44:13 1991
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. echo If this archive is complete, you will see the following message:
  24. echo '          "shar: End of archive 2 (of 3)."'
  25. if test -f 'indent/Makefile' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'indent/Makefile'\"
  27. else
  28.   echo shar: Extracting \"'indent/Makefile'\" \(1438 characters\)
  29.   sed "s/^X//" >'indent/Makefile' <<'END_OF_FILE'
  30. X#
  31. X# Copyright (c) 1987 Regents of the University of California.
  32. X# All rights reserved.
  33. X#
  34. X# Redistribution and use in source and binary forms are permitted
  35. X# provided that the above copyright notice and this paragraph are
  36. X# duplicated in all such forms and that any documentation,
  37. X# advertising materials, and other materials related to such
  38. X# distribution and use acknowledge that the software was developed
  39. X# by the University of California, Berkeley.  The name of the
  40. X# University may not be used to endorse or promote products derived
  41. X# from this software without specific prior written permission.
  42. X# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  43. X# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  44. X# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  45. X#
  46. X#    @(#)Makefile    5.9 (Berkeley) 9/15/88
  47. X#
  48. XCFLAGS=    -O -DBSD #-DMAXPATHLEN=256
  49. XLIBC=    /lib/libc.a
  50. XSRCS=    indent.c io.c lexi.c parse.c pr_comment.c args.c
  51. XOBJS=    indent.o io.o lexi.o parse.o pr_comment.o args.o
  52. XMAN=    indent.0
  53. X
  54. Xall: indent
  55. X
  56. Xindent: ${OBJS} ${LIBC}
  57. X    ${CC} -o $@ ${CFLAGS} ${OBJS}
  58. X
  59. Xclean:
  60. X    rm -f ${OBJS} core indent
  61. X
  62. Xcleandir: clean
  63. X    rm -f ${MAN} tags .depend
  64. X
  65. Xdepend: ${SRCS}
  66. X    mkdep ${CFLAGS} ${SRCS}
  67. X
  68. Xinstall: ${MAN}
  69. X    install -s -o bin -g bin -m 755 indent ${DESTDIR}/usr/ucb/indent
  70. X    install -c -o bin -g bin -m 444 indent.0 ${DESTDIR}/usr/man/cat1/indent.0
  71. X
  72. Xlint: ${SRCS}
  73. X    lint ${CFLAGS} ${SRCS}
  74. X
  75. Xtags: ${SRCS}
  76. X    ctags ${SRCS}
  77. END_OF_FILE
  78.   if test 1438 -ne `wc -c <'indent/Makefile'`; then
  79.     echo shar: \"'indent/Makefile'\" unpacked with wrong size!
  80.   fi
  81.   # end of 'indent/Makefile'
  82. fi
  83. if test -f 'indent/README' -a "${1}" != "-c" ; then 
  84.   echo shar: Will not clobber existing file \"'indent/README'\"
  85. else
  86.   echo shar: Extracting \"'indent/README'\" \(291 characters\)
  87.   sed "s/^X//" >'indent/README' <<'END_OF_FILE'
  88. XIndent is a C/C++ program formatter.  It reformats the C/C++ program
  89. Xin the input-file according to a long list of command line switches.
  90. X
  91. XThe original indent (part of the Berkeley Software Distribution) was
  92. Xonly for C programs.  It has since been modified to understand C++
  93. Xsyntax as well.
  94. END_OF_FILE
  95.   if test 291 -ne `wc -c <'indent/README'`; then
  96.     echo shar: \"'indent/README'\" unpacked with wrong size!
  97.   fi
  98.   # end of 'indent/README'
  99. fi
  100. if test -f 'indent/indent.1' -a "${1}" != "-c" ; then 
  101.   echo shar: Will not clobber existing file \"'indent/indent.1'\"
  102. else
  103.   echo shar: Extracting \"'indent/indent.1'\" \(13352 characters\)
  104.   sed "s/^X//" >'indent/indent.1' <<'END_OF_FILE'
  105. X.\" Copyright 1989 Object Design, Inc.
  106. X.\" Copyright (c) 1985 Sun Microsystems, Inc.
  107. X.\" Copyright (c) 1980 The Regents of the University of California.
  108. X.\" Copyright (c) 1976 Board of Trustees of the University of Illinois.
  109. X.\" All rights reserved.
  110. X.\" Redistribution and use in source and binary forms are permitted
  111. X.\" provided that the above copyright notice and this paragraph are
  112. X.\" duplicated in all such forms and that any documentation,
  113. X.\" advertising materials, and other materials related to such
  114. X.\" distribution and use acknowledge that the software was developed
  115. X.\" by the University of California, Berkeley, the University of Illinois,
  116. X.\" Urbana, and Sun Microsystems, Inc.  The name of either University
  117. X.\" or Sun Microsystems may not be used to endorse or promote products
  118. X.\" derived from this software without specific prior written permission.
  119. X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  120. X.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  121. X.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  122. X.\" 
  123. X.\"    @(#)indent.1    6.5 (Berkeley) 9/15/88
  124. X.\"
  125. X.TH INDENT 1 "July 14, 1989
  126. X.SH NAME
  127. Xindent \- indent and format C program source
  128. X.SH SYNOPSIS
  129. X.in +\w'\fBindent \fR'u
  130. X.ti -\w'\fBindent \fR'u
  131. X\fBindent \fR [ \fIinput-file\fR [ \fIoutput-file\fR ] ]
  132. X[\ \fB\-bad\fR\ |\ \fB\-nbad\fR\ ]
  133. X[\ \fB\-bap\fR\ |\ \fB\-nbap\fR\ ]
  134. X[\ \fB\-bbb\fR\ |\ \fB\-nbbb\fR\ ]
  135. X[\ \fB\-bc\fR\ |\ \fB\-nbc\fR\ ]
  136. X[\ \fB\-bl\fR\ ]
  137. X[\ \fB\-br\fR\ ]
  138. X[\ \fB\-brr\fR\ ]
  139. X[\ \fB\-c\fIn\fR\ ]
  140. X[\ \fB\-cd\fIn\fR\ ]
  141. X[\ \fB\-cdb\fR\ |\ \fB\-ncdb\fR\ ]
  142. X[\ \fB\-ce\fR\ |\ \fB\-nce\fR\ ]
  143. X[\ \fB\-ci\fIn\fR\ ]
  144. X[\ \fB\-cli\fIn\fR\ ]
  145. X[\ \fB\-cci\fIn\fR\ ]
  146. X[\ \fB\-d\fIn\fR\ ]
  147. X[\ \fB\-di\fIn\fR\ ]
  148. X[\ \fB\-fc1\fR\ |\ \fB\-nfc1\fR\ ]
  149. X[\ \fB\-i\fIn\fR\ ]
  150. X[\ \fB\-ip\fR\ |\ \fB\-nip\fR\ ]
  151. X[\ \fB\-l\fIn\fR\ ]
  152. X[\ \fB\-lc\fIn\fR\ ]
  153. X[\ \fB\-lp\fR\ |\ \fB\-nlp\fR\ ]
  154. X[\ \fB\-pcs\fR\ |\ \fB\-npcs\fR\ ]
  155. X[\ \fB\-npro\fR\ ]
  156. X[\ \fB\-prs\fR\ |\ \fB\-nprs\fR\ ]
  157. X[\ \fB\-psl\fR\ |\ \fB\-npsl\fR\ ]
  158. X[\ \fB\-sc\fR\ |\ \fB\-nsc\fR\ ]
  159. X[\ \fB\-sob\fR\ |\ \fB\-nsob\fR\ ]
  160. X[\ \fB\-st\fR\ ]
  161. X[\ \fB\-troff\fR\ ]
  162. X[\ \fB\-v\fR\ |\ \fB\-nv\fR\ ]
  163. X[\ \fB-+\fR ]
  164. X
  165. X.SH DESCRIPTION
  166. X.I Indent
  167. Xis a \fBC\fR program formatter.  It reformats the \fBC\fR program in the
  168. X\fIinput-file\fR according to the switches.  The switches which can be
  169. Xspecified are described below. They may appear before or after the file
  170. Xnames.
  171. X.LP
  172. X\fBNOTE\fP: If you only specify an \fIinput-file\fR, the formatting is
  173. Xdone `in-place', that is, the formatted file is written back into
  174. X.I input-file
  175. Xand a backup copy of
  176. X.I input-file
  177. Xis written in the current directory.  If
  178. X.I input-file
  179. Xis named `/blah/blah/file', the backup file is named
  180. X.RI file .BAK.
  181. X.LP
  182. XIf
  183. X.I output-file
  184. Xis specified,
  185. X.I indent
  186. Xchecks to make sure it is different from
  187. X.IR input-file .
  188. X.SH OPTIONS
  189. X.LP
  190. XThe options listed below control the formatting style imposed by
  191. X.IR indent .
  192. X.TP 15
  193. X.BR \-bap , \-nbap
  194. XIf
  195. X.B \-bap
  196. Xis specified, a blank line is forced after every procedure body.  Default:
  197. X.B \-nbap.
  198. X.TP 15
  199. X.BR \-bad , \-nbad
  200. XIf
  201. X.B \-bad
  202. Xis specified, a blank line is forced after every block of
  203. Xdeclarations.  Default:  
  204. X.B \-nbad.
  205. X.TP 15
  206. X.BR \-bbb , \-nbbb
  207. XIf
  208. X.B \-bbb
  209. Xis specified, a blank line is forced before every block comment.  Default:
  210. X.B \-nbbb.
  211. X.TP 15
  212. X.BR \-bc , \-nbc
  213. XIf
  214. X.B \-bc
  215. Xis specified, then a newline is forced after each comma in a declaration. 
  216. X.B \-nbc
  217. Xturns off this option.  The default is
  218. X.BR \-bc .
  219. X.TP 15
  220. X.BR \-br , \-bl , \-brr
  221. XSpecifying
  222. X.B \-bl
  223. Xlines up compound statements like this:
  224. X.ne 4
  225. X.nf
  226. X.ft L
  227. X    if (...)
  228. X    {
  229. X        code
  230. X    }
  231. X.ft R
  232. X.fi
  233. XSpecifying
  234. X.B \-br
  235. X(the default) makes them look like this:
  236. X.ne 3
  237. X.nf
  238. X.ft L
  239. X    if (...) {
  240. X        code
  241. X    }
  242. X.ft R
  243. X.fi
  244. XAnd specifying
  245. X.B \-brr
  246. Xmakes them look like this:
  247. X.ne 3
  248. X.nf
  249. X.ft L
  250. X    if (...)
  251. X        {
  252. X        code
  253. X        }
  254. X.ft R
  255. X.fi
  256. X.LP
  257. X.TP 15
  258. X.BI \-c n
  259. XThe column in which comments on code start.  The default is 33.  
  260. X.TP 15
  261. X.BI \-cd n
  262. XThe column in which comments on declarations start.  The default
  263. Xis for these comments to start in the same column as those on code.
  264. X.TP 15
  265. X.BI \-cdb , \-ncdb
  266. XEnables (disables) the placement of comment delimiters on blank lines.  With
  267. Xthis option enabled, comments look like this:
  268. X.nf
  269. X.ft L
  270. X.ne 3
  271. X    /*
  272. X     * this is a comment
  273. X     */
  274. X.ft R
  275. X.fi
  276. XRather than like this:
  277. X.nf
  278. X.ft L
  279. X    /* this is a comment */
  280. X.ft R
  281. X.fi
  282. XThis only affects block comments, not comments to the right of code. The default is
  283. X.B \-cdb .
  284. X.TP 15
  285. X.BI \-ce , \-nce
  286. XEnables (disables) forcing `else's to cuddle up to the immediatly preceeding
  287. X`}'.  The default is
  288. X.B \-ce .
  289. X.TP 15
  290. X.BI \-ci n
  291. XSets the continuation indent to be \fIn\fR.  Continuation
  292. Xlines will be indented that far from the beginning of the first line of the
  293. Xstatement.  Parenthesized expressions have extra indentation added to
  294. Xindicate the nesting, unless \fB\-lp\fR is in effect.
  295. X\fB\-ci\fR defaults to the same value as \fB\-i\fR.
  296. X.TP 15
  297. X.BI \-cli n
  298. XCauses case labels to be indented
  299. X.I n
  300. Xtab stops to the right of the containing \fBswitch\fR statement.
  301. X\fB-cli0.5\fR causes case labels to be indented half a tab stop.  The
  302. Xdefault is
  303. X.B \-cli0 .
  304. X.TP 15
  305. X.BI \-cci n
  306. XCauses case code to be indented
  307. X.I n
  308. Xtab stops to the right of the corresponding case label.
  309. X\fB-cci0.5\fR causes case code to be indented half a tab stop.  The
  310. Xdefault is
  311. X.B \-cci1 .
  312. X.TP 15
  313. X.BI \-d n
  314. XControls the placement of comments which are not to the
  315. Xright of code.  The default
  316. X.B \-d1
  317. Xmeans that such comments are placed one indentation level to the
  318. Xleft of code.  Specifying
  319. X.B \-d0
  320. Xlines up these comments with the code.  See the section on comment
  321. Xindentation below.
  322. X.TP 15
  323. X.BI \-di n
  324. XSpecifies the indentation, in character positions, from a declaration keyword
  325. Xto the following identifier.  The default is
  326. X.B \-di16 .
  327. X.if 0 \{.TP 15
  328. X.BR \-dj , \-ndj
  329. X.B \-dj
  330. Xleft justifies declarations.
  331. X.B \-ndj
  332. Xindents declarations the same as code.  The default is
  333. X.BR \-ndj .
  334. X.TP 15
  335. X.BI \-ei , \-nei
  336. XEnables (disables) special
  337. X.B else-if
  338. Xprocessing.  If it's enabled,
  339. X.BR if "s"
  340. Xfollowing
  341. X.BR else "s"
  342. Xwill have the same indendation as the preceeding
  343. X.B if
  344. Xstatement.\}
  345. X.TP 15
  346. X.BI \-fc1 , \-nfc1
  347. XEnables (disables) the formatting of comments that start in column 1.
  348. XOften, comments whose leading `/' is in column 1 have been carefully
  349. Xhand formatted by the programmer.  In such cases, \fB\-nfc1\fR should be
  350. Xused.  The default is \fB\-fc1\fR.
  351. X.TP 15
  352. X.BI \-i n
  353. XThe number of spaces for one indentation level.  The default is 4.
  354. X.TP 15
  355. X.BI \-ip , \-nip
  356. XEnables (disables) the indentation of parameter declarations from the left
  357. Xmargin.  The default is
  358. X.B \-ip .
  359. X.TP 15
  360. X.BI \-l n
  361. XMaximum length of an output line.  The default is 75.
  362. X.TP 15
  363. X.B \-npro
  364. XCauses the profile files, `./.indent.pro' and `~/.indent.pro', to be ignored.
  365. X.TP 15
  366. X.BI \-lp , \-nlp
  367. XLines up code surrounded by parenthesis in continuation lines.  If a line
  368. Xhas a left paren which is not closed on that line, then continuation lines
  369. Xwill be lined up to start at the character position just after the left
  370. Xparen.  For example, here is how a piece of continued code looks with -nlp
  371. Xin effect:
  372. X.ne 2
  373. X.nf
  374. X.ft L
  375. X    p1 = first_procedure(second_procedure(p2, p3),
  376. X        third_procedure(p4, p5));
  377. X.ft R
  378. X.fi
  379. X.ne 5
  380. XWith \fB-lp\fR in effect (the default) the code looks somewhat clearer:
  381. X.nf
  382. X.ft L
  383. X    p1 = first_procedure(second_procedure(p2, p3),
  384. X                         third_procedure(p4, p5));
  385. X.ft R
  386. X.fi
  387. X.ne 5
  388. XInserting a couple more newlines we get:
  389. X.nf
  390. X.ft L
  391. X    p1 = first_procedure(second_procedure(p2,
  392. X                                          p3),
  393. X                         third_procedure(p4,
  394. X                                         p5));
  395. X.ft R
  396. X.fi
  397. X.TP 15
  398. X.B \-pcs , \-npcs
  399. XIf true (\fB-pcs\fR) all procedure calls will have a space inserted between
  400. Xthe name and the '('.  The default is 
  401. X.B \-npcs
  402. X.TP 15
  403. X.B \-prs , \-nprs
  404. XIf true (\fB-prs\fR) all parentheses will have a space inserted
  405. Xafter the '(' and before the ')'.  The default is 
  406. X.B \-nprs
  407. X.TP 15
  408. X.B \-psl , \-npsl
  409. XIf true (\fB-psl\fR) the names of procedures being defined are placed in
  410. Xcolumn 1 \- their types, if any, will be left on the previous lines.  The
  411. Xdefault is 
  412. X.B -psl
  413. X.TP 15
  414. X.BI \-sc , \-nsc
  415. XEnables (disables) the placement of asterisks (`*'s) at the left edge of all
  416. Xcomments.    
  417. X.TP 15
  418. X.BR \-sob , \-nsob
  419. XIf
  420. X.B \-sob
  421. Xis specified, indent will swallow optional blank lines.  You can use this to
  422. Xget rid of blank lines after declarations.  Default:
  423. X.B \-nsob
  424. X.TP 15
  425. X.B \-st
  426. XCauses
  427. X.B indent
  428. Xto take its input from stdin, and put its output to stdout.
  429. X.TP 15
  430. X.BI \-T typename
  431. XAdds
  432. X.I typename
  433. Xto the list of type keywords.  Names accumulate:
  434. X.B \-T
  435. Xcan be specified more than once.  You need to specify all the typenames that
  436. Xappear in your program that are defined by \fBtypedef\fRs \- nothing will be
  437. Xharmed if you miss a few, but the program won't be formatted as nicely as
  438. Xit should.  This sounds like a painful thing to have to do, but it's really
  439. Xa symptom of a problem in C: \fBtypedef\fR causes a syntactic change in the
  440. Xlanguage and \fIindent\fR can't find all \fBtypedef\fRs.
  441. X.TP 15
  442. X.B \-troff
  443. XCauses
  444. X.B indent
  445. Xto format the program for processing by troff.  It will produce a fancy
  446. Xlisting in much the same spirit as
  447. X.BR vgrind.
  448. XIf the output file is not specified, the default is standard output,
  449. Xrather than formatting in place.
  450. X.TP 15
  451. X.BR \-v , \-nv
  452. X.B \-v
  453. Xturns on `verbose' mode,
  454. X.B \-nv
  455. Xturns it off.  When in verbose mode,
  456. X.I indent
  457. Xreports when it splits one line of input into two or more lines of output,
  458. Xand gives some size statistics at completion. The default is
  459. X.BR \-nv .
  460. X.TP 15
  461. X.B \-+
  462. Xturns on support for C++. In c++ mode, :: is permited in identifiers, 
  463. XC++ keywords are supported, and class definition keywords 
  464. X(public, private, etc.) are set in column 2.
  465. X.SH "FURTHER DESCRIPTION"
  466. X.LP
  467. XYou may set up your own `profile' of defaults to
  468. X.I indent
  469. Xby creating a file called
  470. X.BI . indent . pro
  471. Xin either your login directory or the current directory and including
  472. Xwhatever switches you like.  A `.indent.pro' in the current directory takes
  473. Xprecedence over the one in your login directory.  If
  474. X.I indent
  475. Xis run and a profile file exists, then it is read to set up the program's
  476. Xdefaults.  Switches on the command line, though, always override profile
  477. Xswitches.  The switches should be separated by spaces, tabs or newlines.
  478. X.LP
  479. X.B Comments
  480. X.LP
  481. X.IR "`Box' comments" .
  482. X.I Indent
  483. Xassumes that any comment with a dash or star immediately after the start of
  484. Xcomment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
  485. XEach line of such a comment is left unchanged, except that its indentation
  486. Xmay be adjusted to account for the change in indentation of the first line
  487. Xof the comment.
  488. X.LP
  489. X.IR "Straight text" .
  490. XAll other comments are treated as straight text.
  491. X.I Indent
  492. Xfits as many words (separated by blanks, tabs, or newlines) on a
  493. Xline as possible.  Blank lines break paragraphs.
  494. X.LP
  495. X.B Comment indentation
  496. X.LP
  497. XIf a comment is on a line with code it is started in the `comment column',
  498. Xwhich is set by the
  499. X.BI \-c n
  500. Xcommand line parameter.  Otherwise, the comment is started at
  501. X.I n
  502. Xindentation levels less than where code is currently being placed, where
  503. X.I n
  504. Xis specified by the
  505. X.BI \-d n
  506. Xcommand line parameter.  If the code on a line extends past the comment
  507. Xcolumn, the comment starts further to the right, and the right margin may be
  508. Xautomatically extended in extreme cases.
  509. X.LP
  510. X.B Special Comments
  511. X.LP
  512. X.I Indent
  513. Xproduces and interprets some special comments.
  514. XWhen indent cannot parse the source, it prints a message on standard error
  515. Xand inserts a comment into the output of the form
  516. X.nf
  517. X.ft L
  518. X    /**INDENT** ErrorMessage */
  519. X.ft R
  520. X.fi
  521. X.LP
  522. X.I Indent
  523. Xinterprets several special comments as directives. 
  524. XFirst, it makes no attempt to format lines containing the error comment
  525. Xdescribed above.
  526. X.LP
  527. XSecond, lines of the form:
  528. X.nf
  529. X.ft L
  530. X    /* INDENT OFF */
  531. Xor
  532. X    /* INDENT ON */
  533. X.ft R
  534. X.fi
  535. Xdisable and re-enable indent formatting. 
  536. XAny amount of whitespace may replace the spaces shown in the examples.
  537. X.LP
  538. XThird, 
  539. X.I indent
  540. Xallows formatting controls to be included in the source via comments of the form:
  541. X.nf
  542. X.ft L
  543. X    /* INDENT: arg1 arg2 arg3 ... arg4 */
  544. X.ft R
  545. X.fi
  546. XThe arguments given are in the same syntax as the command line or profile file.
  547. XFor example:
  548. X.nf
  549. X.ft L
  550. X    /* INDENT: -cli.25 -nfc1 */
  551. X.ft R
  552. X.fi
  553. X.LP
  554. X.B Preprocessor lines
  555. X.LP
  556. XIn general, \fIindent\fR leaves preprocessor lines alone.  The only
  557. Xreformmatting that it will do is to straighten up trailing comments.  It
  558. Xleaves imbedded comments alone.  Conditional compilation
  559. X(\fB#ifdef...#endif\fR) is recognized and \fIindent\fR attempts to correctly
  560. Xcompensate for the syntactic peculiarites introduced.
  561. X.LP
  562. X.B C syntax
  563. X.LP
  564. X\fIIndent\fR understands a substantial amount about the syntax of C, but it
  565. Xhas a `forgiving' parser.  It attempts to cope with the usual sorts of
  566. Xincomplete and misformed syntax.  In particular, the use of macros like:
  567. X.nf
  568. X.ft L
  569. X        #define forever for(;;)
  570. X.ft R
  571. X.fi
  572. Xis handled properly.
  573. X.SH FILES
  574. X.DT
  575. X.br
  576. X\&./.indent.pro    profile file
  577. X.br
  578. X.SH BUGS
  579. X.I Indent
  580. Xhas even more switches than \fIls\fR.
  581. X
  582. X.ne 5
  583. XA common mistake that often causes grief is typing:
  584. X.nf
  585. X.ft L
  586. X    indent *.c
  587. X.ft R
  588. X.fi
  589. Xto the shell in an attempt to indent all the \fBC\fR programs in a directory.
  590. XThis is probably a bug, not a feature.
  591. END_OF_FILE
  592.   if test 13352 -ne `wc -c <'indent/indent.1'`; then
  593.     echo shar: \"'indent/indent.1'\" unpacked with wrong size!
  594.   fi
  595.   # end of 'indent/indent.1'
  596. fi
  597. if test -f 'indent/indent_codes.h' -a "${1}" != "-c" ; then 
  598.   echo shar: Will not clobber existing file \"'indent/indent_codes.h'\"
  599. else
  600.   echo shar: Extracting \"'indent/indent_codes.h'\" \(1786 characters\)
  601.   sed "s/^X//" >'indent/indent_codes.h' <<'END_OF_FILE'
  602. X/*
  603. X * Copyright 1989 Object Design, Inc.
  604. X * Copyright (c) 1985 Sun Microsystems, Inc.
  605. X * Copyright (c) 1980 The Regents of the University of California.
  606. X * Copyright (c) 1976 Board of Trustees of the University of Illinois.
  607. X * All rights reserved.
  608. X *
  609. X * Redistribution and use in source and binary forms are permitted
  610. X * provided that the above copyright notice and this paragraph are
  611. X * duplicated in all such forms and that any documentation,
  612. X * advertising materials, and other materials related to such
  613. X * distribution and use acknowledge that the software was developed
  614. X * by the University of California, Berkeley, the University of Illinois,
  615. X * Urbana, and Sun Microsystems, Inc.  The name of either University
  616. X * or Sun Microsystems may not be used to endorse or promote products
  617. X * derived from this software without specific prior written permission.
  618. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  619. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  620. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  621. X *
  622. X *    @(#)indent_codes.h    5.6 (Berkeley) 9/15/88
  623. X */
  624. X
  625. X#define newline        1
  626. X#define lparen        2
  627. X#define rparen        3
  628. X#define unary_op    4
  629. X#define binary_op    5
  630. X#define postop        6
  631. X#define question    7
  632. X#define casestmt    8
  633. X#define colon        9
  634. X#define semicolon    10
  635. X#define lbrace        11
  636. X#define rbrace        12
  637. X#define ident        13
  638. X#define comma        14
  639. X#define comment        15
  640. X#define swstmt        16
  641. X#define preesc        17
  642. X#define form_feed    18
  643. X#define decl        19
  644. X#define sp_paren    20
  645. X#define sp_nparen    21
  646. X#define ifstmt        22
  647. X#define whilestmt    23
  648. X#define forstmt        24
  649. X#define stmt        25
  650. X#define stmtl        26
  651. X#define elselit        27
  652. X#define dolit        28
  653. X#define dohead        29
  654. X#define ifhead        30
  655. X#define elsehead    31
  656. X#define period        32
  657. X
  658. X#define cc_commnt    33
  659. X#define class        34
  660. X#define privpub        35
  661. END_OF_FILE
  662.   if test 1786 -ne `wc -c <'indent/indent_codes.h'`; then
  663.     echo shar: \"'indent/indent_codes.h'\" unpacked with wrong size!
  664.   fi
  665.   # end of 'indent/indent_codes.h'
  666. fi
  667. if test -f 'indent/io.c' -a "${1}" != "-c" ; then 
  668.   echo shar: Will not clobber existing file \"'indent/io.c'\"
  669. else
  670.   echo shar: Extracting \"'indent/io.c'\" \(15511 characters\)
  671.   sed "s/^X//" >'indent/io.c' <<'END_OF_FILE'
  672. X/*
  673. X * Copyright 1989 Object Design, Inc.
  674. X * Copyright (c) 1985 Sun Microsystems, Inc.
  675. X * Copyright (c) 1980 The Regents of the University of California.
  676. X * Copyright (c) 1976 Board of Trustees of the University of Illinois.
  677. X * All rights reserved.
  678. X *
  679. X * Redistribution and use in source and binary forms are permitted
  680. X * provided that the above copyright notice and this paragraph are
  681. X * duplicated in all such forms and that any documentation,
  682. X * advertising materials, and other materials related to such
  683. X * distribution and use acknowledge that the software was developed
  684. X * by the University of California, Berkeley, the University of Illinois,
  685. X * Urbana, and Sun Microsystems, Inc.  The name of either University
  686. X * or Sun Microsystems may not be used to endorse or promote products
  687. X * derived from this software without specific prior written permission.
  688. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  689. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  690. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  691. X */
  692. X
  693. X#ifndef lint
  694. Xstatic char sccsid[] = "@(#)io.c    5.10 (Berkeley) 9/15/88";
  695. X#endif /* not lint */
  696. X
  697. X#include "indent_globs.h"
  698. X#include <ctype.h>
  699. X
  700. X
  701. Xint         comment_open;
  702. Xstatic      paren_target;
  703. X
  704. Xdump_line()
  705. X{                /* dump_line is the routine that actually
  706. X                 * effects the printing of the new source. It
  707. X                 * prints the label section, followed by the
  708. X                 * code section with the appropriate nesting
  709. X                 * level, followed by any comments */
  710. X    register int cur_col,
  711. X                target_col;
  712. X    static      not_first_line;
  713. X
  714. X    if (ps.procname[0]) {
  715. X    if (troff) {
  716. X        if (comment_open) {
  717. X        comment_open = 0;
  718. X        fprintf(output, ".*/\n");
  719. X        }
  720. X        fprintf(output, ".Pr \"%s\"\n", ps.procname);
  721. X    }
  722. X    ps.ind_level = 0;
  723. X    ps.procname[0] = 0;
  724. X    }
  725. X    if (s_code == e_code && s_lab == e_lab && s_com == e_com) {
  726. X    if (suppress_blanklines > 0)
  727. X        suppress_blanklines--;
  728. X    else {
  729. X        ps.bl_line = true;
  730. X        n_real_blanklines++;
  731. X    }
  732. X    }
  733. X    else if (!inhibit_formatting) {
  734. X    suppress_blanklines = 0;
  735. X    ps.bl_line = false;
  736. X    if (prefix_blankline_requested && not_first_line)
  737. X        if (swallow_optional_blanklines) {
  738. X        if (n_real_blanklines == 1)
  739. X            n_real_blanklines = 0;
  740. X        }
  741. X        else {
  742. X        if (n_real_blanklines == 0)
  743. X            n_real_blanklines = 1;
  744. X        }
  745. X    while (--n_real_blanklines >= 0)
  746. X        putc('\n', output);
  747. X    n_real_blanklines = 0;
  748. X    if (ps.ind_level == 0) {
  749. X        if (!btype_3)
  750. X        ps.ind_stmt = 0;    /* this is a class A kludge. dont do
  751. X                     * additional statement indentation
  752. X                     * if we are at bracket level 0 */
  753. X        else
  754. X        if (*s_code != '{')
  755. X            ps.ind_stmt = 0;    /* this one is a class AA kludge:
  756. X                     * defeat the class A kludge if
  757. X                     * the statement is '{' */
  758. X    }
  759. X
  760. X    if (e_lab != s_lab || e_code != s_code)
  761. X        ++code_lines;    /* keep count of lines with code */
  762. X
  763. X
  764. X    if (e_lab != s_lab) {    /* print lab, if any */
  765. X        if (comment_open) {
  766. X        comment_open = 0;
  767. X        fprintf(output, ".*/\n");
  768. X        }
  769. X        while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
  770. X        e_lab--;
  771. X        cur_col = pad_output(1, compute_label_target());
  772. X        fprintf(output, "%.*s", e_lab - s_lab, s_lab);
  773. X        cur_col = count_spaces(cur_col, s_lab);
  774. X    }
  775. X    else
  776. X        cur_col = 1;    /* there is no label section */
  777. X
  778. X    ps.pcase = false;
  779. X
  780. X    if (s_code != e_code) {    /* print code section, if any */
  781. X        register char *p;
  782. X
  783. X        if (comment_open) {
  784. X        comment_open = 0;
  785. X        fprintf(output, ".*/\n");
  786. X        }
  787. X        target_col = compute_code_target();
  788. X        {
  789. X        register    i;
  790. X
  791. X        for (i = 0; i < ps.p_l_follow; i++)
  792. X            if (ps.paren_indents[i] >= 0)
  793. X            ps.paren_indents[i] = -(ps.paren_indents[i] + target_col);
  794. X        }
  795. X        cur_col = pad_output(cur_col, target_col);
  796. X        for (p = s_code; p < e_code; p++)
  797. X        if (*p == (char) 0200)
  798. X            fprintf(output, "%d", target_col * 7);
  799. X        else
  800. X            putc(*p, output);
  801. X        cur_col = count_spaces(cur_col, s_code);
  802. X    }
  803. X    if (s_com != e_com)
  804. X        if (troff) {
  805. X        int         all_here = 0;
  806. X        register char *p;
  807. X
  808. X        if (ps.cc_comment)
  809. X            all_here++;
  810. X        else if (e_com[-1] == '/' && e_com[-2] == '*')
  811. X            e_com -= 2, all_here++;
  812. X        while (e_com > s_com && e_com[-1] == ' ')
  813. X            e_com--;
  814. X        *e_com = 0;
  815. X        p = s_com;
  816. X        while (*p == ' ')
  817. X            p++;
  818. X        if (p[0] == '/' && (p[1] == '*' || p[1] == '/'))
  819. X            p += 2, all_here++;
  820. X        else if (p[0] == '*')
  821. X            p += p[1] == '/' ? 2 : 1;
  822. X        while (*p == ' ')
  823. X            p++;
  824. X        if (*p == 0)
  825. X            goto inhibit_newline;
  826. X        if (comment_open < 2 && ps.box_com) {
  827. X            comment_open = 0;
  828. X            fprintf(output, ".*/\n");
  829. X        }
  830. X        if (comment_open == 0) {
  831. X            if ('a' <= *p && *p <= 'z')
  832. X            *p = *p + 'A' - 'a';
  833. X            if (e_com - p < 50 && all_here == 2) {
  834. X            register char *follow = p;
  835. X            fprintf(output, "\n.nr C! \\w\1");
  836. X            while (follow < e_com) {
  837. X                switch (*follow) {
  838. X                case '\n':
  839. X                putc(' ', output);
  840. X                case 1:
  841. X                break;
  842. X                case '\\':
  843. X                putc('\\', output);
  844. X                default:
  845. X                putc(*follow, output);
  846. X                }
  847. X                follow++;
  848. X            }
  849. X            putc(1, output);
  850. X            }
  851. X            fprintf(output, "\n./* %dp %d %dp\n",
  852. X                ps.com_col * 7,
  853. X                (s_code != e_code || s_lab != e_lab) - ps.box_com,
  854. X                target_col * 7);
  855. X        }
  856. X        comment_open = 1 + ps.box_com;
  857. X        while (*p) {
  858. X            if (*p == BACKSLASH)
  859. X            putc(BACKSLASH, output);
  860. X            putc(*p++, output);
  861. X        }
  862. X        }
  863. X        else {        /* print comment, if any */
  864. X        register    target = ps.com_col;
  865. X        register char *com_st = s_com;
  866. X
  867. X        target += ps.comment_delta;
  868. X        while (*com_st == '\t')
  869. X            com_st++, target += 8;    /* ? */
  870. X        while (target <= 0)
  871. X            if (*com_st == ' ')
  872. X            target++, com_st++;
  873. X            else if (*com_st == '\t')
  874. X            target = ((target - 1) & ~7) + 9, com_st++;
  875. X            else
  876. X            target = 1;
  877. X        if (cur_col > target) {    /* if comment cant fit on this line,
  878. X                     * put it on next line */
  879. X            putc('\n', output);
  880. X            cur_col = 1;
  881. X            ++ps.out_lines;
  882. X        }
  883. X        while (e_com > com_st && isspace(e_com[-1]))
  884. X            e_com--;
  885. X        cur_col = pad_output(cur_col, target);
  886. X        if (!ps.box_com && !ps.cc_comment) {
  887. X            if (star_comment_cont && (com_st[1] != '*' || e_com <= com_st + 1))
  888. X            if (com_st[1] == ' ' && com_st[0] == ' ' && e_com > com_st + 1)
  889. X                com_st[1] = '*';
  890. X            else
  891. X                fwrite(" * ", com_st[0] == '\t' ? 2 : com_st[0] == '*' ? 1 : 3, 1, output);
  892. X        }
  893. X        fwrite(com_st, e_com - com_st, 1, output);
  894. X        ps.comment_delta = ps.n_comment_delta;
  895. X        cur_col = count_spaces(cur_col, com_st);
  896. X        ++ps.com_lines;    /* count lines with comments */
  897. X        }
  898. X    if (ps.use_ff)
  899. X        putc('\014', output);
  900. X    else
  901. X        putc('\n', output);
  902. Xinhibit_newline:
  903. X    ++ps.out_lines;
  904. X    if (ps.just_saw_decl == 1 && blanklines_after_declarations) {
  905. X        prefix_blankline_requested = 1;
  906. X        ps.just_saw_decl = 0;
  907. X    }
  908. X    else
  909. X        prefix_blankline_requested = postfix_blankline_requested;
  910. X    postfix_blankline_requested = 0;
  911. X    }
  912. X    ps.decl_on_line = ps.in_decl;    /* if we are in the middle of a
  913. X                     * declaration, remember that fact for
  914. X                     * proper comment indentation */
  915. X    ps.ind_stmt = ps.in_stmt & ~ps.in_decl;    /* next line should be
  916. X                         * indented if we have not
  917. X                         * completed this stmt and if
  918. X                         * we are not in the middle of
  919. X                         * a declaration */
  920. X    ps.use_ff = false;
  921. X    ps.dumped_decl_indent = 0;
  922. X    *(e_lab = s_lab) = '\0';    /* reset buffers */
  923. X    *(e_code = s_code) = '\0';
  924. X    *(e_com = s_com) = '\0';
  925. X    ps.ind_level = ps.i_l_follow;
  926. X    ps.paren_level = ps.p_l_follow;
  927. X    paren_target = -ps.paren_indents[ps.paren_level - 1];
  928. X    not_first_line = 1;
  929. X    return;
  930. X};
  931. X
  932. Xcompute_code_target()
  933. X{
  934. X    register    target_col = ps.ind_size * ps.ind_level + 1;
  935. X
  936. X    if (ps.paren_level)
  937. X    if (!lineup_to_parens)
  938. X        target_col += continuation_indent * ps.paren_level;
  939. X    else {
  940. X        register    w;
  941. X        register    t = paren_target;
  942. X
  943. X        if ((w = count_spaces(t, s_code) - max_col) > 0
  944. X            && count_spaces(target_col, s_code) <= max_col) {
  945. X        t -= w + 1;
  946. X        if (t > target_col)
  947. X            target_col = t;
  948. X        }
  949. X        else
  950. X        target_col = t;
  951. X    }
  952. X    else if (ps.ind_stmt)
  953. X    target_col += continuation_indent;
  954. X    return target_col;
  955. X}
  956. X
  957. Xcompute_label_target()
  958. X{
  959. X    return
  960. X    ps.pcase ?
  961. X        (cplus && ps.in_decl) ? cplus_ppp_indent
  962. X    : (int) (case_ind * ps.ind_size) + 1
  963. X    : *s_lab == '#' ? 1
  964. X    : ps.ind_size * (ps.ind_level - label_offset) + 1;
  965. X}
  966. X
  967. X
  968. X/*
  969. X * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
  970. X * 
  971. X * All rights reserved
  972. X * 
  973. X * 
  974. X * NAME: fill_buffer
  975. X * 
  976. X * FUNCTION: Reads one block of input into input_buffer
  977. X * 
  978. X * HISTORY: initial coding     November 1976    D A Willcox of CAC 1/7/77 A
  979. X * Willcox of CAC    Added check for switch back to partly full input
  980. X * buffer from temporary buffer
  981. X * 
  982. X */
  983. Xint
  984. Xfill_buffer()
  985. X{                /* this routine reads stuff from the input */
  986. X    register char *p;
  987. X    register int i;
  988. X    register FILE *f = input;
  989. X
  990. X    if (bp_save != 0) {        /* there is a partly filled input buffer left */
  991. X    buf_ptr = bp_save;    /* dont read anything, just switch buffers */
  992. X    buf_end = be_save;
  993. X    bp_save = be_save = 0;
  994. X    if (buf_ptr < buf_end)
  995. X        return;        /* only return if there is really something in
  996. X                 * this buffer */
  997. X    }
  998. X    for (p = buf_ptr = in_buffer;;) {
  999. X    if ((i = getc(f)) == EOF) {
  1000. X        *p++ = ' ';
  1001. X        *p++ = '\n';
  1002. X        had_eof = true;
  1003. X        break;
  1004. X    }
  1005. X    *p++ = i;
  1006. X    if (i == '\n')
  1007. X        break;
  1008. X    }
  1009. X    buf_end = p;
  1010. X    if (p[-2] == '/' && p[-3] == '*') {
  1011. X    if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)
  1012. X        fill_buffer();    /* flush indent error message */
  1013. X    else {
  1014. X        int         com = 0;
  1015. X
  1016. X        p = in_buffer;
  1017. X        while (*p == ' ' || *p == '\t')
  1018. X        p++;
  1019. X        if (*p == '/' && p[1] == '*') {
  1020. X        p += 2;
  1021. X        while (*p == ' ' || *p == '\t')
  1022. X            p++;
  1023. X        if (p[0] == 'I' && p[1] == 'N' && p[2] == 'D' && p[3] == 'E'
  1024. X            && p[4] == 'N' && p[5] == 'T') {
  1025. X            p += 6;
  1026. X            if(*p == ':') {
  1027. X#define MAX_SOURCE_ARG 100
  1028. X            char argbuf[MAX_SOURCE_ARG]; /* how big can they get ...  */
  1029. X            char * a;
  1030. X            p++;    /* skip the : */
  1031. X            /* since set_option changes flags, process pending stuff now */
  1032. X            if (s_com != e_com || s_lab != e_lab || s_code != e_code)
  1033. X                dump_line();
  1034. X            while (1) {
  1035. X                a = argbuf;    /* accumulate an option */
  1036. X                while (*p <= ' ') /* skip whitespace */
  1037. X                p++;
  1038. X                if(*p == '*') break;
  1039. X                while (*p > ' ')
  1040. X                *a++ = *p++;
  1041. X                *a++ = '\0';
  1042. X                set_option(argbuf);
  1043. X            }
  1044. X            goto End_Magic_Comment;
  1045. X            }
  1046. X            while (*p == ' ' || *p == '\t')
  1047. X            p++;
  1048. X            if (*p == '*')
  1049. X            com = 1;
  1050. X            else if (*p == 'O')
  1051. X            if (*++p == 'N')
  1052. X                p++, com = 1;
  1053. X            else if (*p == 'F' && *++p == 'F')
  1054. X                p++, com = 2;
  1055. X            while (*p == ' ' || *p == '\t')
  1056. X            p++;
  1057. X            if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && com) {
  1058. X            if (s_com != e_com || s_lab != e_lab || s_code != e_code)
  1059. X                dump_line();
  1060. X            if (!(inhibit_formatting = com - 1)) {
  1061. X                n_real_blanklines = 0;
  1062. X                postfix_blankline_requested = 0;
  1063. X                prefix_blankline_requested = 0;
  1064. X                suppress_blanklines = 1;
  1065. X            }
  1066. X            }
  1067. X        }
  1068. X        }
  1069. X    }
  1070. X    }
  1071. XEnd_Magic_Comment:
  1072. X    if (inhibit_formatting) {
  1073. X    p = in_buffer;
  1074. X    do
  1075. X        putc(*p, output);
  1076. X    while (*p++ != '\n');
  1077. X    }
  1078. X    return;
  1079. X};
  1080. X
  1081. X/*
  1082. X * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
  1083. X * 
  1084. X * All rights reserved
  1085. X * 
  1086. X * 
  1087. X * NAME: pad_output
  1088. X * 
  1089. X * FUNCTION: Writes tabs and spaces to move the current column up to the desired
  1090. X * position.
  1091. X * 
  1092. X * ALGORITHM: Put tabs and/or blanks into pobuf, then write pobuf.
  1093. X * 
  1094. X * PARAMETERS: current        integer        The current column target
  1095. X * nteger        The desired column
  1096. X * 
  1097. X * RETURNS: Integer value of the new column.  (If current >= target, no action is
  1098. X * taken, and current is returned.
  1099. X * 
  1100. X * GLOBALS: None
  1101. X * 
  1102. X * CALLS: write (sys)
  1103. X * 
  1104. X * CALLED BY: dump_line
  1105. X * 
  1106. X * HISTORY: initial coding     November 1976    D A Willcox of CAC
  1107. X * 
  1108. X */
  1109. Xpad_output(current, target)    /* writes tabs and blanks (if necessary) to
  1110. X                 * get the current output position up to the
  1111. X                 * target column */
  1112. X    int         current;    /* the current column value */
  1113. X    int         target;        /* position we want it at */
  1114. X{
  1115. X    register int curr;        /* internal column pointer */
  1116. X    register int tcur;
  1117. X
  1118. X    if (troff)
  1119. X    fprintf(output, "\\h'|%dp'", (target - 1) * 7);
  1120. X    else {
  1121. X    if (current >= target)
  1122. X        return (current);    /* line is already long enough */
  1123. X    curr = current;
  1124. X    while ((tcur = ((curr - 1) & tabmask) + tabsize + 1) <= target) {
  1125. X        putc('\t', output);
  1126. X        curr = tcur;
  1127. X    }
  1128. X    while (curr++ < target)
  1129. X        putc(' ', output);    /* pad with final blanks */
  1130. X    }
  1131. X    return (target);
  1132. X};
  1133. X
  1134. X/*
  1135. X * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
  1136. X * 
  1137. X * All rights reserved
  1138. X * 
  1139. X * 
  1140. X * NAME: count_spaces
  1141. X * 
  1142. X * FUNCTION: Find out where printing of a given string will leave the current
  1143. X * character position on output.
  1144. X * 
  1145. X * ALGORITHM: Run thru input string and add appropriate values to current
  1146. X * position.
  1147. X * 
  1148. X * RETURNS: Integer value of position after printing "buffer" starting in column
  1149. X * "current".
  1150. X * 
  1151. X * HISTORY: initial coding     November 1976    D A Willcox of CAC
  1152. X * 
  1153. X */
  1154. Xint
  1155. Xcount_spaces(current, buffer)
  1156. X/*
  1157. X * this routine figures out where the character position will be after
  1158. X * printing the text in buffer starting at column "current"
  1159. X */
  1160. X    int         current;
  1161. X    char       *buffer;
  1162. X{
  1163. X    register char *buf;        /* used to look thru buffer */
  1164. X    register int cur;        /* current character counter */
  1165. X
  1166. X    cur = current;
  1167. X
  1168. X    for (buf = buffer; *buf != '\0'; ++buf) {
  1169. X    switch (*buf) {
  1170. X
  1171. X    case '\n':
  1172. X    case 014:        /* form feed */
  1173. X        cur = 1;
  1174. X        break;
  1175. X
  1176. X    case '\t':
  1177. X        cur = ((cur - 1) & tabmask) + tabsize + 1;
  1178. X        break;
  1179. X
  1180. X    case '\b':        /* this is a backspace */
  1181. X        --cur;
  1182. X        break;
  1183. X
  1184. X    default:
  1185. X        ++cur;
  1186. X        break;
  1187. X    }            /* end of switch */
  1188. X    }                /* end of for loop */
  1189. X    return (cur);
  1190. X};
  1191. X
  1192. Xint    found_err;
  1193. Xdiag(level, msg, a, b)
  1194. X{
  1195. X    if (level)
  1196. X    found_err = 1;
  1197. X    if (output == stdout) {
  1198. X    fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
  1199. X    fprintf(stdout, msg, a, b);
  1200. X    fprintf(stdout, " */\n");
  1201. X    }
  1202. X    else {
  1203. X    fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
  1204. X    fprintf(stderr, msg, a, b);
  1205. X    fprintf(stderr, "\n");
  1206. X    }
  1207. X}
  1208. X
  1209. Xwritefdef(f, nm)
  1210. X    register struct fstate *f;
  1211. X{
  1212. X    fprintf(output, ".ds f%c %s\n.nr s%c %d\n",
  1213. X        nm, f->font, nm, f->size);
  1214. X}
  1215. X
  1216. Xchar       *
  1217. Xchfont(of, nf, s)
  1218. X    register struct fstate *of,
  1219. X               *nf;
  1220. X    char       *s;
  1221. X{
  1222. X    if (of->font[0] != nf->font[0]
  1223. X        || of->font[1] != nf->font[1]) {
  1224. X    *s++ = '\\';
  1225. X    *s++ = 'f';
  1226. X    if (nf->font[1]) {
  1227. X        *s++ = '(';
  1228. X        *s++ = nf->font[0];
  1229. X        *s++ = nf->font[1];
  1230. X    }
  1231. X    else
  1232. X        *s++ = nf->font[0];
  1233. X    }
  1234. X    if (nf->size != of->size) {
  1235. X    *s++ = '\\';
  1236. X    *s++ = 's';
  1237. X    if (nf->size < of->size) {
  1238. X        *s++ = '-';
  1239. X        *s++ = '0' + of->size - nf->size;
  1240. X    }
  1241. X    else {
  1242. X        *s++ = '+';
  1243. X        *s++ = '0' + nf->size - of->size;
  1244. X    }
  1245. X    }
  1246. X    return s;
  1247. X}
  1248. X
  1249. X
  1250. Xparsefont(f, s0)
  1251. X    register struct fstate *f;
  1252. X    char       *s0;
  1253. X{
  1254. X    register char *s = s0;
  1255. X    int         sizedelta = 0;
  1256. X    bzero(f, sizeof *f);
  1257. X    while (*s) {
  1258. X    if (isdigit(*s))
  1259. X        f->size = f->size * 10 + *s - '0';
  1260. X    else if (isupper(*s))
  1261. X        if (f->font[0])
  1262. X        f->font[1] = *s;
  1263. X        else
  1264. X        f->font[0] = *s;
  1265. X    else if (*s == 'c')
  1266. X        f->allcaps = 1;
  1267. X    else if (*s == '+')
  1268. X        sizedelta++;
  1269. X    else if (*s == '-')
  1270. X        sizedelta--;
  1271. X    else {
  1272. X        fprintf(stderr, "indent: bad font specification: %s\n", s0);
  1273. X        exit(1);
  1274. X    }
  1275. X    s++;
  1276. X    }
  1277. X    if (f->font[0] == 0)
  1278. X    f->font[0] = 'R';
  1279. X    if (bodyf.size == 0)
  1280. X    bodyf.size = 11;
  1281. X    if (f->size == 0)
  1282. X    f->size = bodyf.size + sizedelta;
  1283. X    else if (sizedelta > 0)
  1284. X    f->size += bodyf.size;
  1285. X    else
  1286. X    f->size = bodyf.size - f->size;
  1287. X}
  1288. END_OF_FILE
  1289.   if test 15511 -ne `wc -c <'indent/io.c'`; then
  1290.     echo shar: \"'indent/io.c'\" unpacked with wrong size!
  1291.   fi
  1292.   # end of 'indent/io.c'
  1293. fi
  1294. if test -f 'indent/lexi.c' -a "${1}" != "-c" ; then 
  1295.   echo shar: Will not clobber existing file \"'indent/lexi.c'\"
  1296. else
  1297.   echo shar: Extracting \"'indent/lexi.c'\" \(15857 characters\)
  1298.   sed "s/^X//" >'indent/lexi.c' <<'END_OF_FILE'
  1299. X/*
  1300. X * Copyright (c) 1985 Sun Microsystems, Inc.
  1301. X * Copyright (c) 1980 The Regents of the University of California.
  1302. X * Copyright (c) 1976 Board of Trustees of the University of Illinois.
  1303. X * All rights reserved.
  1304. X *
  1305. X * Redistribution and use in source and binary forms are permitted
  1306. X * provided that the above copyright notice and this paragraph are
  1307. X * duplicated in all such forms and that any documentation,
  1308. X * advertising materials, and other materials related to such
  1309. X * distribution and use acknowledge that the software was developed
  1310. X * by the University of California, Berkeley, the University of Illinois,
  1311. X * Urbana, and Sun Microsystems, Inc.  The name of either University
  1312. X * or Sun Microsystems may not be used to endorse or promote products
  1313. X * derived from this software without specific prior written permission.
  1314. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1315. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1316. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1317. X */
  1318. X
  1319. X#ifndef lint
  1320. Xstatic char sccsid[] = "@(#)lexi.c    5.11 (Berkeley) 9/15/88";
  1321. X#endif /* not lint */
  1322. X
  1323. X/*
  1324. X * Here we have the token scanner for indent.  It scans off one token and puts
  1325. X * it in the global variable "token".  It returns a code, indicating the type
  1326. X * of token scanned.
  1327. X */
  1328. X
  1329. X#include "indent_globs.h"
  1330. X#include "indent_codes.h"
  1331. X#include "ctype.h"
  1332. X
  1333. Xtypedef enum char_type {
  1334. X    alphanum = 1,
  1335. X    opchar = 3,
  1336. X    colonchar = 4
  1337. X} char_type;
  1338. X
  1339. Xstruct templ {
  1340. X    char       *rwd;
  1341. X    int         rwcode;
  1342. X    cplus_flag        cplus; 
  1343. X};
  1344. X
  1345. Xstruct templ specials[100] =
  1346. X{
  1347. X    "switch", 1, c_and_cplus,
  1348. X    "case", 2, c_and_cplus,
  1349. X    "break", 0, c_and_cplus,
  1350. X    "struct", 3, c_and_cplus,
  1351. X    "union", 3, c_and_cplus,
  1352. X    "enum", 3, c_and_cplus,
  1353. X    "default", 2, c_and_cplus,
  1354. X    "int", 4, c_and_cplus,
  1355. X    "char", 4, c_and_cplus,
  1356. X    "float", 4, c_and_cplus,
  1357. X    "double", 4, c_and_cplus,
  1358. X    "long", 4, c_and_cplus,
  1359. X    "short", 4, c_and_cplus,
  1360. X    "typedef", 8, c_and_cplus,
  1361. X    "unsigned", 4, c_and_cplus,
  1362. X    "register", 4, c_and_cplus,
  1363. X    "static", 4, c_and_cplus,
  1364. X    "global", 4, c_and_cplus,
  1365. X    "extern", 4, c_and_cplus,
  1366. X    "void", 4, c_and_cplus,
  1367. X    "goto", 0, c_and_cplus,
  1368. X    "return", 0, c_and_cplus,
  1369. X    "if", 5, c_and_cplus,
  1370. X    "while", 5, c_and_cplus,
  1371. X    "for", 5, c_and_cplus,
  1372. X    "else", 6, c_and_cplus,
  1373. X    "do", 6, c_and_cplus,
  1374. X    "sizeof", 7, c_and_cplus,
  1375. X    "class", 3, cplus_only,
  1376. X    "public", 2, cplus_only,
  1377. X    "private", 2, cplus_only,
  1378. X    "protected", 2, cplus_only,
  1379. X    "volatile", 4, c_and_cplus,
  1380. X
  1381. X    0, 0
  1382. X};
  1383. X
  1384. Xchar   chartype[128] =
  1385. X{                /* this is used to facilitate the decision of
  1386. X                 * what type (alphanumeric, operator) each
  1387. X                 * character is */
  1388. X    0, 0, 0, 0, 0, 0, 0, 0,
  1389. X    0, 0, 0, 0, 0, 0, 0, 0,
  1390. X    0, 0, 0, 0, 0, 0, 0, 0,
  1391. X    0, 0, 0, 0, 0, 0, 0, 0,
  1392. X    0, 3, 0, 0, 1, 3, 3, 0,
  1393. X    0, 0, 3, 3, 0, 3, 0, 3,
  1394. X    1, 1, 1, 1, 1, 1, 1, 1,
  1395. X    1, 1, 4, 0, 3, 3, 3, 3,
  1396. X    0, 1, 1, 1, 1, 1, 1, 1,
  1397. X    1, 1, 1, 1, 1, 1, 1, 1,
  1398. X    1, 1, 1, 1, 1, 1, 1, 1,
  1399. X    1, 1, 1, 0, 0, 0, 3, 1,
  1400. X    0, 1, 1, 1, 1, 1, 1, 1,
  1401. X    1, 1, 1, 1, 1, 1, 1, 1,
  1402. X    1, 1, 1, 1, 1, 1, 1, 1,
  1403. X    1, 1, 1, 0, 3, 0, 3, 0
  1404. X};
  1405. X
  1406. X
  1407. X
  1408. X
  1409. Xint
  1410. Xlexi()
  1411. X{
  1412. X    register char *tok;        /* local pointer to next char in token */
  1413. X    int         unary_delim;    /* this is set to 1 if the current token
  1414. X                 * 
  1415. X                 * forces a following operator to be unary */
  1416. X    static int  last_code;    /* the last token type returned */
  1417. X    static int  l_struct;    /* set to 1 if the last token was 'struct' */
  1418. X    static int  l_struct_start; /* set at struct, cleared at { or ; */
  1419. X    static int  l_class;    /* in c++, class name coming next. */
  1420. X    int         code;        /* internal code to be returned */
  1421. X    char        qchar;        /* the delimiter character for a string */
  1422. X
  1423. X    tok = token;        /* point to start of place to save token */
  1424. X    unary_delim = false;
  1425. X    ps.col_1 = ps.last_nl;    /* tell world that this token started in
  1426. X                 * column 1 iff the last thing scanned was nl */
  1427. X    ps.last_nl = false;
  1428. X
  1429. X    while (*buf_ptr == ' ' || *buf_ptr == '\t') {    /* get rid of blanks */
  1430. X    ps.col_1 = false;    /* leading blanks imply token is not in column
  1431. X                 * 1 */
  1432. X    if (++buf_ptr >= buf_end)
  1433. X        fill_buffer();
  1434. X    }
  1435. X
  1436. X    /* Scan an alphanumeric token */
  1437. X    /* In c++, :: starting token is aok, as is ~ sometimes */
  1438. X    /* well, int x = ~y; will work oddly here */
  1439. X    if (((char_type)chartype[*buf_ptr] == alphanum || buf_ptr[0] == '.' && isdigit(buf_ptr[1])) ||
  1440. X    (cplus && buf_ptr[0] == ':' && buf_ptr[1] == ':') ||
  1441. X    (cplus && ps.in_decl && *buf_ptr == '~'
  1442. X     && (char_type)chartype[buf_ptr[1]] == alphanum) /* destructors in classdefs */
  1443. X    ) {
  1444. X    /*
  1445. X     * we have a character or number
  1446. X     */
  1447. X    register char *j;    /* used for searching thru list of
  1448. X                 * 
  1449. X                 * reserved words */
  1450. X    register struct templ *p;
  1451. X
  1452. X    if (isdigit(*buf_ptr) || buf_ptr[0] == '.' && isdigit(buf_ptr[1])) {
  1453. X        int         seendot = 0,
  1454. X                    seenexp = 0;
  1455. X        if (*buf_ptr == '0' &&
  1456. X            (buf_ptr[1] == 'x' || buf_ptr[1] == 'X')) {
  1457. X        *tok++ = *buf_ptr++;
  1458. X        *tok++ = *buf_ptr++;
  1459. X        while (isxdigit(*buf_ptr))
  1460. X            *tok++ = *buf_ptr++;
  1461. X        }
  1462. X        else
  1463. X        while (1) {
  1464. X            if (*buf_ptr == '.')
  1465. X            if (seendot)
  1466. X                break;
  1467. X            else
  1468. X                seendot++;
  1469. X            *tok++ = *buf_ptr++;
  1470. X            if (!isdigit(*buf_ptr) && *buf_ptr != '.')
  1471. X            if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp)
  1472. X                break;
  1473. X            else {
  1474. X                seenexp++;
  1475. X                seendot++;
  1476. X                *tok++ = *buf_ptr++;
  1477. X                if (*buf_ptr == '+' || *buf_ptr == '-')
  1478. X                *tok++ = *buf_ptr++;
  1479. X            }
  1480. X        }
  1481. X        if (*buf_ptr == 'L' || *buf_ptr == 'l')
  1482. X        *tok++ = *buf_ptr++;
  1483. X    }
  1484. X    else {
  1485. X        int first;
  1486. X        first = 1;
  1487. X        while ((char_type)chartype[*buf_ptr] == alphanum ||
  1488. X           (buf_ptr[0] == ':' && buf_ptr[1] == ':' && cplus) ||
  1489. X           (cplus && first && buf_ptr[0] == '~'))
  1490. X        {            /* copy it over */
  1491. X        int colonp;
  1492. X        first = 0;
  1493. X        colonp = *buf_ptr == ':';
  1494. X        *tok++ = *buf_ptr++;
  1495. X        if(colonp) {
  1496. X            *tok++ = *buf_ptr++;
  1497. X            /* foo::~foo */
  1498. X            if(*buf_ptr == '~') *tok++ = *buf_ptr++;
  1499. X            colonp = 0;
  1500. X        }
  1501. X        if (buf_ptr >= buf_end)
  1502. X            fill_buffer();
  1503. X        }
  1504. X    }
  1505. X    *tok++ = '\0';
  1506. X    while (*buf_ptr == ' ' || *buf_ptr == '\t') {    /* get rid of blanks */
  1507. X        if (++buf_ptr >= buf_end)
  1508. X        fill_buffer();
  1509. X    }
  1510. X    ps.its_a_keyword = false;
  1511. X    ps.sizeof_keyword = false;
  1512. X    if (l_struct) {        /* if last token was 'struct', then this token
  1513. X                 * should be treated as a declaration */
  1514. X        if(l_class) addkey(tok, 4);
  1515. X        l_class = false;
  1516. X        l_struct = false;
  1517. X        last_code = ident;
  1518. X        ps.last_u_d = true;
  1519. X        return (decl);
  1520. X    }
  1521. X    ps.last_u_d = false;    /* Operator after indentifier is binary */
  1522. X    last_code = ident;    /* Remember that this is the code we will
  1523. X                 * return */
  1524. X
  1525. X    /*
  1526. X     * This loop will check if the token is a keyword.
  1527. X     */
  1528. X    for (p = specials; (j = p->rwd) != 0; p++) {
  1529. X        tok = token;    /* point at scanned token */
  1530. X        if (*j++ != *tok++ || *j++ != *tok++)
  1531. X        continue;    /* This test depends on the fact that
  1532. X                 * identifiers are always at least 1 character
  1533. X                 * long (ie. the first two bytes of the
  1534. X                 * identifier are always meaningful) */
  1535. X        if (tok[-1] == 0)
  1536. X        break;        /* If its a one-character identifier */
  1537. X        while (*tok++ == *j)
  1538. X        if (*j++ == 0 &&
  1539. X            (p->cplus == c_and_cplus ||
  1540. X             (cplus && p->cplus == cplus_only) ||
  1541. X             (!cplus && p->cplus == c_only)))
  1542. X            goto found_keyword;    /* I wish that C had a multi-level
  1543. X                     * break... */
  1544. X    }
  1545. X    if (p->rwd) {        /* we have a keyword */
  1546. X    found_keyword:
  1547. X        ps.its_a_keyword = true;
  1548. X        ps.last_u_d = true;
  1549. X        switch (p->rwcode) {
  1550. X        case 1:        /* it is a switch */
  1551. X        return (swstmt);
  1552. X        case 2:        /* a case or default */
  1553. X        return (casestmt);
  1554. X
  1555. X        case 3:        /* a "struct" */
  1556. X        if (ps.p_l_follow)
  1557. X            break;    /* inside parens: cast */
  1558. X        l_struct = true;
  1559. X        if(cplus)l_struct_start = true;
  1560. X        /* automatically note keywords */
  1561. X        if(cplus && strcmp(tok, "class") == 0 ||
  1562. X           strcmp(tok, "struct") == 0 ||
  1563. X           strcmp(tok, "union") == 0 ||
  1564. X           strcmp(tok, "enum") == 0)
  1565. X            l_class = true;
  1566. X        /*
  1567. X         * Next time around, we will want to know that we have had a
  1568. X         * 'struct'
  1569. X         */
  1570. X        case 4:        /* one of the declaration keywords */
  1571. X        if (ps.p_l_follow) {
  1572. X            ps.cast_mask |= 1 << ps.p_l_follow;
  1573. X            break;    /* inside parens: cast */
  1574. X        }
  1575. X        last_code = decl;
  1576. X        return (decl);
  1577. X
  1578. X        case 5:        /* if, while, for */
  1579. X        return (sp_paren);
  1580. X
  1581. X        case 6:        /* do, else */
  1582. X        return (sp_nparen);
  1583. X
  1584. X        case 7:
  1585. X        ps.sizeof_keyword = true;
  1586. X        return (ident);
  1587. X
  1588. X        case 8:        /* typedef is a decl */
  1589. X        last_code = decl;
  1590. X        return (decl);
  1591. X
  1592. X        default:        /* all others are treated like any other
  1593. X                 * identifier */
  1594. X        return (ident);
  1595. X        }            /* end of switch */
  1596. X    }            /* end of if (found_it) */
  1597. X    if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0) {
  1598. X        register char *tp = buf_ptr;
  1599. X        while (tp < buf_end)
  1600. X        if (*tp++ == ')' && *tp == ';')
  1601. X            goto not_proc;
  1602. X        strncpy(ps.procname, token, sizeof ps.procname - 1);
  1603. X        ps.in_parameter_declaration = 1;
  1604. X    not_proc:;
  1605. X    }
  1606. X    /*
  1607. X     * The following hack attempts to guess whether or not the current
  1608. X     * token is in fact a declaration keyword -- one that has been
  1609. X     * typedefd
  1610. X     */
  1611. X    if (((*buf_ptr == '*' && buf_ptr[1] != '=') || isalpha(*buf_ptr) || *buf_ptr == '_')
  1612. X        && !ps.p_l_follow
  1613. X            && !ps.block_init
  1614. X        && (ps.last_token == rparen || ps.last_token == semicolon ||
  1615. X            ps.last_token == decl ||
  1616. X            ps.last_token == lbrace || ps.last_token == rbrace)) {
  1617. X        ps.its_a_keyword = true;
  1618. X        ps.last_u_d = true;
  1619. X        last_code = decl;
  1620. X        return decl;
  1621. X    }
  1622. X    if (last_code == decl)    /* if this is a declared variable, then
  1623. X                 * following sign is unary */
  1624. X        ps.last_u_d = true;    /* will make "int a -1" work */
  1625. X    last_code = ident;
  1626. X    return (ident);        /* the ident is not in the list */
  1627. X    }                /* end of procesing for alpanum character */
  1628. X    /* l l l Scan a non-alphanumeric token */
  1629. X
  1630. X    l_class = false;        /* struct { ain't defining a class. */
  1631. X    *tok++ = *buf_ptr;        /* if it is only a one-character token, it is
  1632. X                 * moved here */
  1633. X    *tok = '\0';
  1634. X    if (++buf_ptr >= buf_end)
  1635. X    fill_buffer();
  1636. X
  1637. X    switch (*token) {
  1638. X    case '\n':
  1639. X    unary_delim = ps.last_u_d;
  1640. X    ps.last_nl = true;    /* remember that we just had a newline */
  1641. X    code = (had_eof ? 0 : newline);
  1642. X
  1643. X    /*
  1644. X     * if data has been exausted, the newline is a dummy, and we should
  1645. X     * return code to stop
  1646. X     */
  1647. X    break;
  1648. X
  1649. X    case '\'':            /* start of quoted character */
  1650. X    case '"':            /* start of string */
  1651. X    qchar = *token;
  1652. X    if (troff) {
  1653. X        tok[-1] = '`';
  1654. X        if (qchar == '"')
  1655. X        *tok++ = '`';
  1656. X        tok = chfont(&bodyf, &stringf, tok);
  1657. X    }
  1658. X    do {            /* copy the string */
  1659. X        while (1) {        /* move one character or [/<char>]<char> */
  1660. X        if (*buf_ptr == '\n') {
  1661. X            printf("%d: Unterminated literal\n", line_no);
  1662. X            goto stop_lit;
  1663. X        }
  1664. X        *tok = *buf_ptr++;
  1665. X        if (buf_ptr >= buf_end)
  1666. X            fill_buffer();
  1667. X        if (had_eof || ((tok - token) > (bufsize - 2))) {
  1668. X            printf("Unterminated literal\n");
  1669. X            ++tok;
  1670. X            goto stop_lit;
  1671. X            /* get outof literal copying loop */
  1672. X        }
  1673. X        if (*tok == BACKSLASH) {    /* if escape, copy extra char */
  1674. X            if (*buf_ptr == '\n')    /* check for escaped newline */
  1675. X            ++line_no;
  1676. X            if (troff) {
  1677. X            *++tok = BACKSLASH;
  1678. X            if (*buf_ptr == BACKSLASH)
  1679. X                *++tok = BACKSLASH;
  1680. X            }
  1681. X            *++tok = *buf_ptr++;
  1682. X            ++tok;    /* we must increment this again because we
  1683. X                 * copied two chars */
  1684. X            if (buf_ptr >= buf_end)
  1685. X            fill_buffer();
  1686. X        }
  1687. X        else
  1688. X            break;    /* we copied one character */
  1689. X        }            /* end of while (1) */
  1690. X    } while (*tok++ != qchar);
  1691. X    if (troff) {
  1692. X        tok = chfont(&stringf, &bodyf, tok - 1);
  1693. X        if (qchar == '"')
  1694. X        *tok++ = '\'';
  1695. X    }
  1696. Xstop_lit:
  1697. X    code = ident;
  1698. X    break;
  1699. X
  1700. X    case ('('):
  1701. X    case ('['):
  1702. X    unary_delim = true;
  1703. X    code = lparen;
  1704. X    break;
  1705. X
  1706. X    case (')'):
  1707. X    case (']'):
  1708. X    code = rparen;
  1709. X    break;
  1710. X
  1711. X    case '#':
  1712. X    unary_delim = ps.last_u_d;
  1713. X    code = preesc;
  1714. X    break;
  1715. X
  1716. X    case '?':
  1717. X    unary_delim = true;
  1718. X    code = question;
  1719. X    break;
  1720. X
  1721. X    case (':'):
  1722. X    if(l_struct_start)
  1723. X        code = ident;
  1724. X    else code = colon;
  1725. X    unary_delim = true;
  1726. X    break;
  1727. X
  1728. X    case (';'):
  1729. X    l_struct_start = false;
  1730. X    unary_delim = true;
  1731. X    code = semicolon;
  1732. X    break;
  1733. X
  1734. X    case ('{'):
  1735. X    l_struct_start = false;
  1736. X    unary_delim = true;
  1737. X
  1738. X    /*
  1739. X     * if (ps.in_or_st) ps.block_init = 1;
  1740. X     */
  1741. X    /* ?    code = ps.block_init ? lparen : lbrace; */
  1742. X    code = lbrace;
  1743. X    break;
  1744. X
  1745. X    case ('}'):
  1746. X    unary_delim = true;
  1747. X    /* ?    code = ps.block_init ? rparen : rbrace; */
  1748. X    code = rbrace;
  1749. X    break;
  1750. X
  1751. X    case 014:            /* a form feed */
  1752. X    unary_delim = ps.last_u_d;
  1753. X    ps.last_nl = true;    /* remember this so we can set 'ps.col_1'
  1754. X                 * right */
  1755. X    code = form_feed;
  1756. X    break;
  1757. X
  1758. X    case (','):
  1759. X    unary_delim = true;
  1760. X    code = comma;
  1761. X    break;
  1762. X
  1763. X    case '.':
  1764. X    unary_delim = false;
  1765. X    code = period;
  1766. X    break;
  1767. X
  1768. X    case '-':
  1769. X    case '+':            /* check for -, +, --, ++ */
  1770. X    code = (ps.last_u_d ? unary_op : binary_op);
  1771. X    unary_delim = true;
  1772. X
  1773. X    if (*buf_ptr == token[0]) {
  1774. X        /* check for doubled character */
  1775. X        *tok++ = *buf_ptr++;
  1776. X        /* buffer overflow will be checked at end of loop */
  1777. X        if (last_code == ident || last_code == rparen) {
  1778. X        code = (ps.last_u_d ? unary_op : postop);
  1779. X        /* check for following ++ or -- */
  1780. X        unary_delim = false;
  1781. X        }
  1782. X    }
  1783. X    else if (*buf_ptr == '=')
  1784. X        /* check for operator += */
  1785. X        *tok++ = *buf_ptr++;
  1786. X    else if (*buf_ptr == '>') {
  1787. X        /* check for operator -> */
  1788. X        *tok++ = *buf_ptr++;
  1789. X        if (!pointer_as_binop) {
  1790. X        unary_delim = false;
  1791. X        code = unary_op;
  1792. X        ps.want_blank = false;
  1793. X        }
  1794. X    }
  1795. X    break;            /* buffer overflow will be checked at end of
  1796. X                 * switch */
  1797. X
  1798. X    case '=':
  1799. X    if (ps.in_or_st)
  1800. X        ps.block_init = 1;
  1801. X#ifdef undef
  1802. X    if (chartype[*buf_ptr] == opchar) {    /* we have two char assignment */
  1803. X        tok[-1] = *buf_ptr++;
  1804. X        if ((tok[-1] == '<' || tok[-1] == '>') && tok[-1] == *buf_ptr)
  1805. X        *tok++ = *buf_ptr++;
  1806. X        *tok++ = '=';    /* Flip =+ to += */
  1807. X        *tok = 0;
  1808. X    }
  1809. X#else
  1810. X    if (*buf_ptr == '=') {/* == */
  1811. X        *tok++ = '=';    /* Flip =+ to += */
  1812. X        buf_ptr++;
  1813. X        *tok = 0;
  1814. X    }
  1815. X#endif
  1816. X    code = binary_op;
  1817. X    unary_delim = true;
  1818. X    break;
  1819. X    /* can drop thru!!! */
  1820. X
  1821. X    case '>':
  1822. X    case '<':
  1823. X    case '!':            /* ops like <, <<, <=, !=, etc */
  1824. X    if (*buf_ptr == '>' || *buf_ptr == '<' || *buf_ptr == '=') {
  1825. X        *tok++ = *buf_ptr;
  1826. X        if (++buf_ptr >= buf_end)
  1827. X        fill_buffer();
  1828. X    }
  1829. X    if (*buf_ptr == '=')
  1830. X        *tok++ = *buf_ptr++;
  1831. X    code = (ps.last_u_d ? unary_op : binary_op);
  1832. X    unary_delim = true;
  1833. X    break;
  1834. X
  1835. X    default:
  1836. X    if (token[0] == '/' && *buf_ptr == '*') {
  1837. X        /* it is start of a C comment */
  1838. X        *tok++ = '*';
  1839. X
  1840. X        if (++buf_ptr >= buf_end)
  1841. X        fill_buffer();
  1842. X
  1843. X        code = comment;
  1844. X        unary_delim = ps.last_u_d;
  1845. X        break;
  1846. X    }
  1847. X    if (token[0] == '/' && *buf_ptr == '/') {
  1848. X        /* it is start of a C++ comment */
  1849. X        *tok++ = '/';
  1850. X
  1851. X        if (++buf_ptr >= buf_end)
  1852. X        fill_buffer();
  1853. X
  1854. X        code = cc_commnt;
  1855. X        ps.cc_comment++;
  1856. X        unary_delim = ps.last_u_d;
  1857. X        break;
  1858. X    }
  1859. X    while (*(tok - 1) == *buf_ptr || *buf_ptr == '=') {
  1860. X        /*
  1861. X         * handle ||, &&, etc, and also things as in int *****i
  1862. X         */
  1863. X        *tok++ = *buf_ptr;
  1864. X        if (++buf_ptr >= buf_end)
  1865. X        fill_buffer();
  1866. X    }
  1867. X    code = (ps.last_u_d ? unary_op : binary_op);
  1868. X    unary_delim = true;
  1869. X
  1870. X
  1871. X    }                /* end of switch */
  1872. X    if (code != newline) {
  1873. X    l_struct = false;
  1874. X    last_code = code;
  1875. X    }
  1876. X    if (buf_ptr >= buf_end)    /* check for input buffer empty */
  1877. X    fill_buffer();
  1878. X    ps.last_u_d = unary_delim;
  1879. X    *tok = '\0';        /* null terminate the token */
  1880. X    return (code);
  1881. X};
  1882. X
  1883. X/*
  1884. X * Add the given keyword to the keyword table, using val as the keyword type
  1885. X */
  1886. Xaddkey(key, val)
  1887. X    char       *key;
  1888. X{
  1889. X    register struct templ *p = specials;
  1890. X    while (p->rwd)
  1891. X    if (p->rwd[0] == key[0] && strcmp(p->rwd, key) == 0)
  1892. X        return;
  1893. X    else
  1894. X        p++;
  1895. X    if (p >= specials + sizeof specials / sizeof specials[0])
  1896. X    return;            /* For now, table overflows are silently
  1897. X                 * ignored */
  1898. X    p->rwd = key;
  1899. X    p->rwcode = val;
  1900. X    p[1].rwd = 0;
  1901. X    p[1].rwcode = 0;
  1902. X    return;
  1903. X}
  1904. END_OF_FILE
  1905.   if test 15857 -ne `wc -c <'indent/lexi.c'`; then
  1906.     echo shar: \"'indent/lexi.c'\" unpacked with wrong size!
  1907.   fi
  1908.   # end of 'indent/lexi.c'
  1909. fi
  1910. echo shar: End of archive 2 \(of 3\).
  1911. cp /dev/null ark2isdone
  1912. MISSING=""
  1913. for I in 1 2 3 ; do
  1914.     if test ! -f ark${I}isdone ; then
  1915.     MISSING="${MISSING} ${I}"
  1916.     fi
  1917. done
  1918. if test "${MISSING}" = "" ; then
  1919.     echo You have unpacked all 3 archives.
  1920.     rm -f ark[1-9]isdone
  1921. else
  1922.     echo You still must unpack the following archives:
  1923.     echo "        " ${MISSING}
  1924. fi
  1925. exit 0
  1926. exit 0 # Just in case...
  1927. -- 
  1928. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1929. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1930. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1931. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1932.