home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume30 / indent / part03 < prev    next >
Encoding:
Text File  |  1992-07-05  |  59.9 KB  |  1,514 lines

  1. Newsgroups: comp.sources.misc
  2. From: jrs@panix.com (Jon Saxton)
  3. Subject:  v30i097:  indent - C/C++ indent for UNIX, OS/2 and MSDOS, Part03/04
  4. Message-ID: <1992Jul5.190352.26861@sparky.imd.sterling.com>
  5. X-Md4-Signature: ff3d85d1036c66a97dff1fda81fe59f7
  6. Date: Sun, 5 Jul 1992 19:03:52 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jrs@panix.com (Jon Saxton)
  10. Posting-number: Volume 30, Issue 97
  11. Archive-name: indent/part03
  12. Environment: UNIX, OS/2, MSDOS
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  19. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  20. # Contents:  codes.h comment.c globals.h indent.man readme
  21. # Wrapped by kent@sparky on Tue Jun 30 00:01:42 1992
  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 3 (of 4)."'
  25. if test -f 'codes.h' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'codes.h'\"
  27. else
  28.   echo shar: Extracting \"'codes.h'\" \(1778 characters\)
  29.   sed "s/^X//" >'codes.h' <<'END_OF_FILE'
  30. X/*
  31. X * Copyright 1989 Object Design, Inc.
  32. X * Copyright (c) 1985 Sun Microsystems, Inc.
  33. X * Copyright (c) 1980 The Regents of the University of California.
  34. X * Copyright (c) 1976 Board of Trustees of the University of Illinois.
  35. X * All rights reserved.
  36. X *
  37. X * Redistribution and use in source and binary forms are permitted
  38. X * provided that the above copyright notice and this paragraph are
  39. X * duplicated in all such forms and that any documentation,
  40. X * advertising materials, and other materials related to such
  41. X * distribution and use acknowledge that the software was developed
  42. X * by the University of California, Berkeley, the University of Illinois,
  43. X * Urbana, and Sun Microsystems, Inc.  The name of either University
  44. X * or Sun Microsystems may not be used to endorse or promote products
  45. X * derived from this software without specific prior written permission.
  46. X * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  47. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  48. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  49. X *
  50. X *    @(#)codes.h    6.0 (Berkeley) 92/06/15
  51. X */
  52. X
  53. X#define newline        1
  54. X#define lparen        2
  55. X#define rparen        3
  56. X#define unary_op    4
  57. X#define binary_op    5
  58. X#define postop        6
  59. X#define question    7
  60. X#define casestmt    8
  61. X#define colon        9
  62. X#define semicolon    10
  63. X#define lbrace        11
  64. X#define rbrace        12
  65. X#define ident        13
  66. X#define comma        14
  67. X#define comment        15
  68. X#define swstmt        16
  69. X#define preesc        17
  70. X#define form_feed    18
  71. X#define decl        19
  72. X#define sp_paren    20
  73. X#define sp_nparen    21
  74. X#define ifstmt        22
  75. X#define whilestmt    23
  76. X#define forstmt        24
  77. X#define stmt        25
  78. X#define stmtl        26
  79. X#define elselit        27
  80. X#define dolit        28
  81. X#define dohead        29
  82. X#define ifhead        30
  83. X#define elsehead    31
  84. X#define period        32
  85. X
  86. X#define cc_commnt    33
  87. X#define class        34
  88. X#define privpub        35
  89. END_OF_FILE
  90.   if test 1778 -ne `wc -c <'codes.h'`; then
  91.     echo shar: \"'codes.h'\" unpacked with wrong size!
  92.   fi
  93.   # end of 'codes.h'
  94. fi
  95. if test -f 'comment.c' -a "${1}" != "-c" ; then 
  96.   echo shar: Will not clobber existing file \"'comment.c'\"
  97. else
  98.   echo shar: Extracting \"'comment.c'\" \(17188 characters\)
  99.   sed "s/^X//" >'comment.c' <<'END_OF_FILE'
  100. X/*
  101. X * Copyright (c) 1985 Sun Microsystems, Inc.
  102. X * Copyright (c) 1980 The Regents of the University of California.
  103. X * Copyright (c) 1976 Board of Trustees of the University of Illinois.
  104. X * All rights reserved.
  105. X *
  106. X * Redistribution and use in source and binary forms are permitted
  107. X * provided that the above copyright notice and this paragraph are
  108. X * duplicated in all such forms and that any documentation,
  109. X * advertising materials, and other materials related to such
  110. X * distribution and use acknowledge that the software was developed
  111. X * by the University of California, Berkeley, the University of Illinois,
  112. X * Urbana, and Sun Microsystems, Inc.  The name of either University
  113. X * or Sun Microsystems may not be used to endorse or promote products
  114. X * derived from this software without specific prior written permission.
  115. X * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  116. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  117. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  118. X */
  119. X
  120. X#ifndef lint
  121. X# ifndef OS2
  122. X    static char sccsid[] = "@(#)comment.c    6.0 (Berkeley) 92/06/15";
  123. X# endif
  124. X#endif                          /* not lint */
  125. X
  126. X/*
  127. X * NAME:
  128. X *    pr_comment
  129. X *
  130. X * FUNCTION:
  131. X *    This routine takes care of scanning and printing comments.
  132. X *
  133. X * ALGORITHM:
  134. X *    1) Decide where the comment should be aligned, and if lines should
  135. X *       be broken.
  136. X *    2) If lines should not be broken and filled, just copy up to end of
  137. X *       comment.
  138. X *    3) If lines should be filled, then scan thru input_buffer copying
  139. X *       characters to com_buf.  Remember where the last blank, tab, or
  140. X *       newline was.  When line is filled, print up to last blank and
  141. X *       continue copying.
  142. X *
  143. X * HISTORY:
  144. X *    November 1976    D A Willcox of CAC    Initial coding
  145. X *    12/6/76        D A Willcox of CAC    Modification to handle
  146. X *                        UNIX-style comments
  147. X *
  148. X */
  149. X
  150. X/*
  151. X * this routine processes comments.  It makes an attempt to keep comments from
  152. X * going over the max line length.  If a line is too long, it moves everything
  153. X * from the last blank to the next comment line.  Blanks and tabs from the
  154. X * beginning of the input line are removed
  155. X */
  156. X
  157. X
  158. X#include "globals.h"
  159. X
  160. X#ifdef OS2
  161. X#include <malloc.h>
  162. X#endif
  163. X
  164. X#ifdef ANSIC
  165. Xvoid pr_comment(void)
  166. X#else
  167. Xpr_comment()
  168. X#endif
  169. X{
  170. X    int now_col;                /* column we are in now */
  171. X    int adj_max_col;            /* Adjusted max_col for when we decide to spill
  172. X                                   comments over the right margin */
  173. X    char *last_bl;              /* points to the last blank in the output
  174. X                                   buffer */
  175. X    char *t_ptr;                /* used for moving string */
  176. X    int unix_comment;           /* tri-state variable used to decide if it is a
  177. X                                   unix-style comment. 0 means only blanks
  178. X                                   since /*, 1 means regular style comment, 2
  179. X                                   means unix style comment */
  180. X    int break_delim = comment_delimiter_on_blankline;
  181. X    int l_just_saw_decl = ps.just_saw_decl;
  182. X
  183. X    /*
  184. X       int         ps.last_nl = 0;    /* true iff the last significant thing weve
  185. X       seen is a newline
  186. X    */
  187. X    int one_liner = 1;          /* true iff this comment is a one-liner */
  188. X
  189. X    adj_max_col = max_col;
  190. X    ps.just_saw_decl = 0;
  191. X    last_bl = 0;                /* no blanks found so far */
  192. X    ps.box_com = false;         /* at first, assume that we are not in a boxed
  193. X                                   comment or some other comment that should
  194. X                                   not be touched */
  195. X    ++ps.out_coms;              /* keep track of number of comments */
  196. X    unix_comment = 1;           /* set flag to let us figure out if there is a
  197. X                                   unix-style comment ** DISABLED: use 0 to
  198. X                                   reenable this hack! */
  199. X
  200. X    /* Figure where to align and how to treat the comment */
  201. X
  202. X    if (ps.col_1 && !format_col1_comments)
  203. X    {                           /* if comment starts in column 1 it should not
  204. X                                   be touched */
  205. X        ps.box_com = true;
  206. X        ps.com_col = 1;
  207. X    }
  208. X    else
  209. X    {
  210. X        if (*buf_ptr == '-' || *buf_ptr == '*')
  211. X        {
  212. X            ps.box_com = true;  /* a comment with a '-' or '*' immediately
  213. X                                   after the /* is assumed to be a boxed
  214. X                                   comment */
  215. X            break_delim = 0;
  216. X        }
  217. X        if ( /* ps.bl_line && */ (s_lab == e_lab) && (s_code == e_code))
  218. X        {
  219. X            /* klg: check only if this line is blank */
  220. X            /*
  221. X               If this (*and previous lines are*) blank, dont put comment way
  222. X               out at left
  223. X            */
  224. X            ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1;
  225. X            adj_max_col = block_comment_max_col;
  226. X            if (ps.com_col <= 1)
  227. X                ps.com_col = 1 + !format_col1_comments;
  228. X        }
  229. X        else
  230. X        {
  231. X            register target_col;
  232. X
  233. X            break_delim = 0;
  234. X            if (s_code != e_code)
  235. X                target_col = count_spaces(compute_code_target(), s_code);
  236. X            else
  237. X            {
  238. X                target_col = 1;
  239. X                if (s_lab != e_lab)
  240. X                    target_col = count_spaces(compute_label_target(), s_lab);
  241. X            }
  242. X            ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? ps.decl_com_ind : ps.com_ind;
  243. X            if (ps.com_col < target_col)
  244. X                ps.com_col = target_col +
  245. X                    (tabsize - ((target_col - 1) % tabsize)); /* JHT 22oct89 */
  246. X            if (ps.com_col + 24 > adj_max_col)
  247. X                adj_max_col = ps.com_col + 24;
  248. X        }
  249. X    }
  250. X    if (ps.box_com)
  251. X    {
  252. X        buf_ptr[-2] = 0;
  253. X        ps.n_comment_delta = 1 - count_spaces(1, in_buffer);
  254. X        buf_ptr[-2] = '/';
  255. X    }
  256. X    else
  257. X    {
  258. X        ps.n_comment_delta = 0;
  259. X        while (*buf_ptr == ' ' || *buf_ptr == '\t')
  260. X            buf_ptr++;
  261. X    }
  262. X    ps.comment_delta = 0;
  263. X    *e_com++ = '/';             /* put '/*' into buffer */
  264. X    if (ps.cc_comment)          /* (or '//') */
  265. X        *e_com++ = '/';
  266. X    else
  267. X        *e_com++ = '*';
  268. X    if (*buf_ptr != ' ' && !ps.box_com)
  269. X        *e_com++ = ' ';
  270. X
  271. X    *e_com = '\0';
  272. X    if (troff)
  273. X    {
  274. X        now_col = 1;
  275. X        adj_max_col = 80;
  276. X    }
  277. X    else
  278. X        now_col = count_spaces(ps.com_col, s_com);  /* figure what column we
  279. X                                                       would be in if we
  280. X                                                       printed the comment now */
  281. X
  282. X    /* Start to copy the comment */
  283. X
  284. X    while (1)
  285. X    {                           /* this loop will go until the comment is
  286. X                                   copied */
  287. X        if (*buf_ptr >= 040 && *buf_ptr != '*')
  288. X            ps.last_nl = 0;
  289. X        check_size(com);
  290. X        switch (*buf_ptr)
  291. X        {                       /* this checks for various spcl cases */
  292. X        case 014:              /* check for a form feed */
  293. X            if (!ps.box_com)
  294. X            {                   /* in a text comment, break the line here */
  295. X                ps.use_ff = true;
  296. X                /* fix so dump_line uses a form feed */
  297. X                dump_line();
  298. X                last_bl = 0;
  299. X                *e_com++ = ' ';
  300. X                *e_com++ = '*';
  301. X                *e_com++ = ' ';
  302. X                while (*++buf_ptr == ' ' || *buf_ptr == '\t');
  303. X            }
  304. X            else
  305. X            {
  306. X                if (++buf_ptr >= buf_end)
  307. X                    fill_buffer();
  308. X                *e_com++ = 014;
  309. X            }
  310. X            break;
  311. X
  312. X        case '\n':
  313. X            if (ps.cc_comment)
  314. X            {
  315. X                *e_com = '\0';
  316. X                dump_line();
  317. X                ps.cc_comment = 0;
  318. X                ps.just_saw_decl = l_just_saw_decl; /* ?? */
  319. X                if (++buf_ptr >= buf_end) /* eat '\n' */
  320. X                    fill_buffer();
  321. X                ps.last_nl = 1; /* jrs 12 Mar 92 */
  322. X                return;
  323. X            }
  324. X            if (had_eof)
  325. X            {                   /* check for unexpected eof */
  326. X                printf("Unterminated comment\n");
  327. X                *e_com = '\0';
  328. X                dump_line();
  329. X                return;
  330. X            }
  331. X            one_liner = 0;
  332. X            if (ps.box_com || ps.last_nl)
  333. X            {                   /* if this is a boxed comment, we dont ignore
  334. X                                   the newline */
  335. X                if (s_com == e_com)
  336. X                {
  337. X                    *e_com++ = ' ';
  338. X                    *e_com++ = ' ';
  339. X                }
  340. X                *e_com = '\0';
  341. X                if (!ps.box_com && e_com - s_com > 3)
  342. X                {
  343. X                    if (break_delim == 1 && s_com[0] == '/'
  344. X                        && s_com[1] == '*' && s_com[2] == ' ')
  345. X                    {
  346. X                        char *t = e_com;
  347. X
  348. X                        break_delim = 2;
  349. X                        e_com = s_com + 2;
  350. X                        *e_com = 0;
  351. X                        if (blanklines_before_blockcomments)
  352. X                            prefix_blankline_requested = 1;
  353. X                        dump_line();
  354. X                        e_com = t;
  355. X                        s_com[0] = s_com[1] = s_com[2] = ' ';
  356. X                    }
  357. X                    dump_line();
  358. X                    check_size(com);
  359. X                    *e_com++ = ' ';
  360. X                    *e_com++ = ' ';
  361. X                }
  362. X                dump_line();
  363. X                now_col = ps.com_col;
  364. X            }
  365. X            else
  366. X            {
  367. X                ps.last_nl = 1;
  368. X                if (unix_comment != 1)
  369. X                {               /* we are not in unix_style comment */
  370. X                    if (unix_comment == 0 && s_code == e_code)
  371. X                    {
  372. X                        /*
  373. X                           if it is a UNIX-style comment, ignore the
  374. X                           requirement that previous line be blank for
  375. X                           unindention
  376. X                        */
  377. X                        ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1;
  378. X                        if (ps.com_col <= 1)
  379. X                            ps.com_col = 2;
  380. X                    }
  381. X                    unix_comment = 2; /* permanently remember that we are in
  382. X                                         this type of comment */
  383. X                    dump_line();
  384. X                    ++line_no;
  385. X                    now_col = ps.com_col;
  386. X                    *e_com++ = ' ';
  387. X                    /*
  388. X                       fix so that the star at the start of the line will line
  389. X                       up
  390. X                    */
  391. X                    do          /* flush leading white space */
  392. X                        if (++buf_ptr >= buf_end)
  393. X                            fill_buffer();
  394. X                    while (*buf_ptr == ' ' || *buf_ptr == '\t');
  395. X                    break;
  396. X                }
  397. X                if (*(e_com - 1) == ' ' || *(e_com - 1) == '\t')
  398. X                    last_bl = e_com - 1;
  399. X                /*
  400. X                   if there was a space at the end of the last line, remember
  401. X                   where it was
  402. X                */
  403. X                else
  404. X                {               /* otherwise, insert one */
  405. X                    last_bl = e_com;
  406. X                    check_size(com);
  407. X                    *e_com++ = ' ';
  408. X                    ++now_col;
  409. X                }
  410. X            }
  411. X            ++line_no;          /* keep track of input line number */
  412. X            if (!ps.box_com)
  413. X            {
  414. X                int nstar = 1;
  415. X
  416. X                do
  417. X                {               /* flush any blanks and/or tabs at start of
  418. X                                   next line */
  419. X                    if (++buf_ptr >= buf_end)
  420. X                        fill_buffer();
  421. X                    if (*buf_ptr == '*' && --nstar >= 0)
  422. X                    {
  423. X                        if (++buf_ptr >= buf_end)
  424. X                            fill_buffer();
  425. X                        if (*buf_ptr == '/')
  426. X                            goto end_of_comment;
  427. X                    }
  428. X                } while (*buf_ptr == ' ' || *buf_ptr == '\t');
  429. X            }
  430. X            else if (++buf_ptr >= buf_end)
  431. X                fill_buffer();
  432. X            break;              /* end of case for newline */
  433. X
  434. X        case '*':              /* must check for possibility of being at end
  435. X                                   of comment */
  436. X            if (++buf_ptr >= buf_end) /* get to next char after * */
  437. X                fill_buffer();
  438. X
  439. X            if (unix_comment == 0)  /* set flag to show we are not in
  440. X                                       unix-style comment */
  441. X                unix_comment = 1;
  442. X
  443. X            if (*buf_ptr == '/')
  444. X            {                   /* it is the end!!! */
  445. X        end_of_comment:
  446. X                if (++buf_ptr >= buf_end)
  447. X                    fill_buffer();
  448. X
  449. X                if (*(e_com - 1) != ' ' && !ps.box_com)
  450. X                {               /* ensure blank before end */
  451. X                    *e_com++ = ' ';
  452. X                    ++now_col;
  453. X                }
  454. X                if (break_delim == 1 && !one_liner && s_com[0] == '/'
  455. X                    && s_com[1] == '*' && s_com[2] == ' ')
  456. X                {
  457. X                    char *t = e_com;
  458. X
  459. X                    break_delim = 2;
  460. X                    e_com = s_com + 2;
  461. X                    *e_com = 0;
  462. X                    if (blanklines_before_blockcomments)
  463. X                        prefix_blankline_requested = 1;
  464. X                    dump_line();
  465. X                    e_com = t;
  466. X                    s_com[0] = s_com[1] = s_com[2] = ' ';
  467. X                }
  468. X                if (break_delim == 2 && e_com > s_com + 3
  469. X                     /* now_col > adj_max_col - 2 && !ps.box_com */ )
  470. X                {
  471. X                    *e_com = '\0';
  472. X                    dump_line();
  473. X                    now_col = ps.com_col;
  474. X                }
  475. X                check_size(com);
  476. X                *e_com++ = '*';
  477. X                *e_com++ = '/';
  478. X                *e_com = '\0';
  479. X                ps.just_saw_decl = l_just_saw_decl;
  480. X                return;
  481. X            }
  482. X            else
  483. X            {                   /* handle isolated '*' */
  484. X                *e_com++ = '*';
  485. X                ++now_col;
  486. X            }
  487. X            break;
  488. X        default:               /* we have a random char */
  489. X            if (unix_comment == 0 && *buf_ptr != ' ' && *buf_ptr != '\t')
  490. X                unix_comment = 1; /* we are not in unix-style comment */
  491. X
  492. X            *e_com = *buf_ptr++;
  493. X            if (buf_ptr >= buf_end)
  494. X                fill_buffer();
  495. X
  496. X            if (*e_com == '\t') /* keep track of column */
  497. X                now_col = now_col + (tabsize - ((now_col - 1) % tabsize));
  498. X            else if (*e_com == '\b')  /* this is a backspace */
  499. X                --now_col;
  500. X            else
  501. X                ++now_col;
  502. X
  503. X            if (*e_com == ' ' || *e_com == '\t')
  504. X                last_bl = e_com;
  505. X            /* remember we saw a blank */
  506. X
  507. X            ++e_com;
  508. X            if (now_col > adj_max_col && !ps.box_com && unix_comment == 1 && e_com[-1] > ' ')
  509. X            {
  510. X                /*
  511. X                   the comment is too long, it must be broken up
  512. X                */
  513. X                if (break_delim == 1 && s_com[0] == '/'
  514. X                    && s_com[1] == '*' && s_com[2] == ' ')
  515. X                {
  516. X                    char *t = e_com;
  517. X
  518. X                    break_delim = 2;
  519. X                    e_com = s_com + 2;
  520. X                    *e_com = 0;
  521. X                    if (blanklines_before_blockcomments)
  522. X                        prefix_blankline_requested = 1;
  523. X                    dump_line();
  524. X                    e_com = t;
  525. X                    s_com[0] = s_com[1] = s_com[2] = ' ';
  526. X                }
  527. X                if (last_bl == 0)
  528. X                {               /* we have seen no blanks */
  529. X                    last_bl = e_com;  /* fake it */
  530. X                    *e_com++ = ' ';
  531. X                }
  532. X                *e_com = '\0';  /* print what we have */
  533. X                *last_bl = '\0';
  534. X                while (last_bl > s_com && last_bl[-1] < 040)
  535. X                    *--last_bl = 0;
  536. X                e_com = last_bl;
  537. X                dump_line();
  538. X
  539. X                *e_com++ = ps.cc_comment ? '/' : ' '; /* blanks or slashes */
  540. X                *e_com++ = ps.cc_comment ? '/' : ' '; /* for continuation */
  541. X                *e_com++ = ' ';
  542. X
  543. X                t_ptr = last_bl + 1;
  544. X                last_bl = 0;
  545. X                if (t_ptr >= e_com)
  546. X                {
  547. X                    while (*t_ptr == ' ' || *t_ptr == '\t')
  548. X                        t_ptr++;
  549. X                    while (*t_ptr != '\0')
  550. X                    {           /* move unprinted part of comment down in
  551. X                                   buffer */
  552. X                        if (*t_ptr == ' ' || *t_ptr == '\t')
  553. X                            last_bl = e_com;
  554. X                        *e_com++ = *t_ptr++;
  555. X                    }
  556. X                }
  557. X                *e_com = '\0';
  558. X                now_col = count_spaces(ps.com_col, s_com);  /* recompute current
  559. X                                                               position */
  560. X            }
  561. X            break;
  562. X        }
  563. X    }
  564. X}
  565. END_OF_FILE
  566.   if test 17188 -ne `wc -c <'comment.c'`; then
  567.     echo shar: \"'comment.c'\" unpacked with wrong size!
  568.   fi
  569.   # end of 'comment.c'
  570. fi
  571. if test -f 'globals.h' -a "${1}" != "-c" ; then 
  572.   echo shar: Will not clobber existing file \"'globals.h'\"
  573. else
  574.   echo shar: Extracting \"'globals.h'\" \(14797 characters\)
  575.   sed "s/^X//" >'globals.h' <<'END_OF_FILE'
  576. X/*
  577. X * Copyright 1989 Object Design, Inc.
  578. X * Copyright (c) 1985 Sun Microsystems, Inc.
  579. X * Copyright (c) 1980 The Regents of the University of California.
  580. X * Copyright (c) 1976 Board of Trustees of the University of Illinois.
  581. X * All rights reserved.
  582. X *
  583. X * Redistribution and use in source and binary forms are permitted
  584. X * provided that the above copyright notice and this paragraph are
  585. X * duplicated in all such forms and that any documentation,
  586. X * advertising materials, and other materials related to such
  587. X * distribution and use acknowledge that the software was developed
  588. X * by the University of California, Berkeley, the University of Illinois,
  589. X * Urbana, and Sun Microsystems, Inc.  The name of either University
  590. X * or Sun Microsystems may not be used to endorse or promote products
  591. X * derived from this software without specific prior written permission.
  592. X * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  593. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  594. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  595. X *
  596. X *    @(#)globals.h    6.0 (Berkeley) 92/06/15
  597. X */
  598. X
  599. X#include <stdio.h>
  600. X#include <memory.h>             /* gst: 24 mar 89 */
  601. X
  602. X#ifdef __IBMC__              /* IBM C Set/2 and other IBM C compilers */
  603. X# ifdef __OS2__
  604. X#  ifndef OS2
  605. X#   define OS2
  606. X#  endif
  607. X# endif
  608. X#endif
  609. X
  610. X#ifdef MSDOS        
  611. X# ifndef OS2
  612. X#  define OS2
  613. X# endif
  614. X#endif
  615. X
  616. X#ifdef OS2
  617. X# ifndef ANSIC
  618. X#  define ANSIC
  619. X# endif
  620. X#endif
  621. X
  622. X#define BACKSLASH '\\'
  623. X#define bufsize 1000            /* size of internal buffers */
  624. X#define inp_bufs 1000           /* size of input buffer */
  625. X#define sc_size 5000            /* size of save_com buffer */
  626. X#define label_offset 2          /* number of levels a label is placed to left
  627. X                                   of code */
  628. X#define cplus_ppp_indent 2      /* spaces to indent public, private, protected
  629. X                                   in c++ */
  630. X
  631. X#define false 0
  632. X#define true  1
  633. X
  634. X
  635. XFILE *input;                    /* the fid for the input file */
  636. XFILE *output;                   /* the output file */
  637. X
  638. X#ifdef OS2
  639. X#define check_size(name) \
  640. X    if (e_##name >= l_##name) { \
  641. X        register nsize = l_##name-s_##name+400; \
  642. X        name##buf = (char *) realloc(name##buf, nsize); \
  643. X        e_##name = name##buf + (e_##name-s_##name) + 1; \
  644. X        l_##name = name##buf + nsize - 5; \
  645. X        s_##name = name##buf + 1; \
  646. X    }
  647. X#else
  648. X#define check_size(name) \
  649. X    if (e_/**/name >= l_/**/name) { \
  650. X        register nsize = l_/**/name-s_/**/name+400; \
  651. X        name/**/buf = (char *) realloc(name/**/buf, nsize); \
  652. X        e_/**/name = name/**/buf + (e_/**/name-s_/**/name) + 1; \
  653. X        l_/**/name = name/**/buf + nsize - 5; \
  654. X        s_/**/name = name/**/buf + 1; \
  655. X    }
  656. X#endif
  657. X
  658. Xchar *labbuf;                   /* buffer for label */
  659. Xchar *s_lab;                    /* start ... */
  660. Xchar *e_lab;                    /* .. and end of stored label */
  661. Xchar *l_lab;                    /* limit of label buffer */
  662. X
  663. Xchar *codebuf;                  /* buffer for code section */
  664. Xchar *s_code;                   /* start ... */
  665. Xchar *e_code;                   /* .. and end of stored code */
  666. Xchar *l_code;                   /* limit of code section */
  667. X
  668. Xchar *combuf;                   /* buffer for comments */
  669. Xchar *s_com;                    /* start ... */
  670. Xchar *e_com;                    /* ... and end of stored comments */
  671. Xchar *l_com;                    /* limit of comment buffer */
  672. X
  673. Xchar in_buffer[inp_bufs];       /* input buffer */
  674. Xchar *buf_ptr;                  /* ptr to next character to be taken from
  675. X                                   in_buffer */
  676. Xchar *buf_end;                  /* ptr to first after last char in in_buffer */
  677. X
  678. Xchar save_com[sc_size];         /* input text is saved here when looking for
  679. X                                   the brace after an if, while, etc */
  680. Xchar *sc_end;                   /* pointer into save_com buffer */
  681. X
  682. Xchar *bp_save;                  /* saved value of buf_ptr when taking input
  683. X                                   from save_com */
  684. Xchar *be_save;                  /* similarly saved value of buf_end */
  685. X
  686. Xchar token[bufsize];            /* the last token scanned */
  687. X
  688. Xint cplus;                      /* c++ */
  689. Xint pointer_as_binop;
  690. Xint blanklines_after_declarations;
  691. Xint blanklines_before_blockcomments;
  692. Xint blanklines_after_procs;
  693. Xint blanklines_around_conditional_compilation;
  694. Xint swallow_optional_blanklines;
  695. Xint n_real_blanklines;
  696. Xint prefix_blankline_requested;
  697. Xint postfix_blankline_requested;
  698. X
  699. Xint tabsize;
  700. X
  701. Xint break_comma;                /* when true and not in parens, break after a
  702. X                                   comma */
  703. Xint btype_2;                    /* when true, brace should be on same line as
  704. X                                   if, while, etc */
  705. Xint btype_3;                    /* when true, braces are not only on the next
  706. X                                   line but indented with the enclosed code */
  707. Xfloat case_ind;                 /* indentation level to be used for a "case n:" */
  708. Xint code_lines;                 /* count of lines with code */
  709. Xint had_eof;                    /* set to true when input is exhausted */
  710. Xint line_no;                    /* the current line number. */
  711. Xint max_col;                    /* the maximum allowable line length */
  712. Xint verbose;                    /* when true, non-essential error messages are
  713. X                                   printed */
  714. Xint cuddle_else;                /* true if else should cuddle up to '}' */
  715. Xint star_comment_cont;          /* true iff comment continuation lines should
  716. X                                   have stars at the beginning of each line. */
  717. Xint comment_delimiter_on_blankline;
  718. Xint troff;                      /* true iff were generating troff input */
  719. Xint procnames_start_line;       /* if true, the names of procedures being
  720. X                                   defined get placed in column 1 (ie. a
  721. X                                   newline is placed between the type of the
  722. X                                   procedure and its name) */
  723. Xint proc_calls_space;           /* If true, procedure calls look like: foo(bar)
  724. X                                   rather than foo (bar) */
  725. Xint parens_space;               /* If true, parens gets spaces inside them */
  726. Xint format_col1_comments;       /* If comments which start in column 1 are to
  727. X                                   be magically reformatted (just like comments
  728. X                                   that begin in later columns) */
  729. Xint inhibit_formatting;         /* true if INDENT OFF is in effect */
  730. Xint suppress_blanklines;        /* set iff following blanklines should be
  731. X                                   suppressed */
  732. Xint continuation_indent;        /* set to the indentation between the edge of
  733. X                                   code and continuation lines */
  734. Xint lineup_to_parens;           /* if true, continued code within parens will
  735. X                                   be lined up to the open paren */
  736. Xint Bill_Shannon;               /* true iff a blank should always be inserted
  737. X                                   after sizeof */
  738. Xint blanklines_after_declarations_at_proctop; /* This is vaguely similar to
  739. X                                                 blanklines_after_declarations
  740. X                                                 except that it only applies to
  741. X                                                 the first set of declarations
  742. X                                                 in a procedure (just after the
  743. X                                                 first '{') and it causes a
  744. X                                                 blank line to be generated
  745. X                                                 even if there are no
  746. X                                                 declarations */
  747. Xint block_comment_max_col;
  748. Xint extra_expression_indent;    /* True if continuation lines from the
  749. X                                   expression part of "if(e)", "while(e)",
  750. X                                   "for(e;e;e)" should be indented an extra tab
  751. X                                   stop so that they don't conflict with the
  752. X                                   code that follows */
  753. X
  754. X/* -troff font state information */
  755. X
  756. Xstruct fstate
  757. X{
  758. X    char font[4];
  759. X    char size;
  760. X    int allcaps:1;
  761. X};
  762. Xchar *chfont();
  763. X
  764. Xstruct fstate
  765. X    keywordf,                   /* keyword font */
  766. X    stringf,                    /* string font */
  767. X    boxcomf,                    /* Box comment font */
  768. X    blkcomf,                    /* Block comment font */
  769. X    scomf,                      /* Same line comment font */
  770. X    bodyf;                      /* major body font */
  771. X
  772. X
  773. X#define STACKSIZE 150
  774. X
  775. Xstruct parser_state
  776. X{
  777. X    int last_token;
  778. X    struct fstate cfont;        /* Current font */
  779. X    int p_stack[STACKSIZE];     /* this is the parsers stack */
  780. X    int il[STACKSIZE];          /* this stack stores indentation levels */
  781. X    float cstk[STACKSIZE];      /* used to store case stmt indentation levels */
  782. X    int box_com;                /* set to true when we are in a "boxed"
  783. X                                   comment. In that case, the first non-blank
  784. X                                   char should be lined up with the / in /* */
  785. X    int comment_delta, n_comment_delta;
  786. X    int cast_mask;              /* indicates which close parens close off casts */
  787. X    int sizeof_mask;            /* indicates which close parens close off
  788. X                                   sizeof''s */
  789. X    int block_init;             /* true iff inside a block initialization */
  790. X    int block_init_level;       /* The level of brace nesting in an
  791. X                                   initialization */
  792. X    int last_nl;                /* this is true if the last thing scanned was a
  793. X                                   newline */
  794. X    int in_or_st;               /* Will be true iff there has been a declarator
  795. X                                   (e.g. int or char) and no left paren since
  796. X                                   the last semicolon. When true, a '{' is
  797. X                                   starting a structure definition or an
  798. X                                   initialization list */
  799. X    int bl_line;                /* set to 1 by dump_line if the line is blank */
  800. X    int col_1;                  /* set to true if the last token started in
  801. X                                   column 1 */
  802. X    int com_col;                /* this is the column in which the current
  803. X                                   coment should start */
  804. X    int com_ind;                /* the column in which comments to the right of
  805. X                                   code should start */
  806. X    int com_lines;              /* the number of lines with comments, set by
  807. X                                   dump_line */
  808. X    int dec_nest;               /* current nesting level for structure or init */
  809. X    int decl_com_ind;           /* the column in which comments after
  810. X                                   declarations should be put */
  811. X    int decl_on_line;           /* set to true if this line of code has part of
  812. X                                   a declaration on it */
  813. X    int i_l_follow;             /* the level to which ind_level should be set
  814. X                                   after the current line is printed */
  815. X    int in_decl;                /* set to true when we are in a declaration
  816. X                                   stmt.  The processing of braces is then
  817. X                                   slightly different */
  818. X    int in_stmt;                /* set to 1 while in a stmt */
  819. X    int ind_level;              /* the current indentation level */
  820. X    int ind_size;               /* the size of one indentation level */
  821. X    int ind_stmt;               /* set to 1 if next line should have an extra
  822. X                                   indentation level because we are in the
  823. X                                   middle of a stmt */
  824. X    int last_u_d;               /* set to true after scanning a token which
  825. X                                   forces a following operator to be unary */
  826. X    int leave_comma;            /* if true, never break declarations after
  827. X                                   commas */
  828. X    int ljust_decl;             /* true if declarations should be left
  829. X                                   justified */
  830. X    int out_coms;               /* the number of comments processed, set by
  831. X                                   pr_comment */
  832. X    int out_lines;              /* the number of lines written, set by
  833. X                                   dump_line */
  834. X    int p_l_follow;             /* used to remember how to indent following
  835. X                                   statement */
  836. X    int paren_level;            /* parenthesization level. used to indent
  837. X                                   within stmts */
  838. X    short paren_indents[20];    /* column positions of each paren */
  839. X    int pcase;                  /* set to 1 if the current line label is a
  840. X                                   case.  It is printed differently from a
  841. X                                   regular label */
  842. X    int search_brace;           /* set to true by parse when it is necessary to
  843. X                                   buffer up all info up to the start of a stmt
  844. X                                   after an if, while, etc */
  845. X    int unindent_displace;      /* comments not to the right of code will be
  846. X                                   placed this many indentation levels to the
  847. X                                   left of code */
  848. X    int use_ff;                 /* set to one if the current line should be
  849. X                                   terminated with a form feed */
  850. X    int want_blank;             /* set to true when the following token should
  851. X                                   be prefixed by a blank. (Said prefixing is
  852. X                                   ignored in some cases.) */
  853. X    int else_if;                /* True iff else if pairs should be handled
  854. X                                   specially */
  855. X    int decl_indent;            /* column to indent declared identifiers to */
  856. X    int its_a_keyword;
  857. X    int sizeof_keyword;
  858. X    int dumped_decl_indent;
  859. X    float case_indent;          /* The distance to indent case labels from the
  860. X                                   switch statement */
  861. X    float case_code_indent;     /* The distance to indent case code from the
  862. X                                   case label */
  863. X    int in_parameter_declaration;
  864. X    int indent_parameters;
  865. X    int tos;                    /* pointer to top of stack */
  866. X    char procname[100];         /* The name of the current procedure */
  867. X    int just_saw_decl;
  868. X    int cc_comment;             /* saw a C++ comment ("//...") */
  869. X}   ps;
  870. X
  871. Xint ifdef_level;
  872. Xstruct parser_state state_stack[5];
  873. Xstruct parser_state match_state[5];
  874. X
  875. Xtypedef enum cplus_flag
  876. X{
  877. X    c_only,
  878. X    c_and_cplus,
  879. X    cplus_only
  880. X}   cplus_flag;
  881. X
  882. X#ifdef ANSIC
  883. X#include "proto.h"
  884. X#endif
  885. END_OF_FILE
  886.   if test 14797 -ne `wc -c <'globals.h'`; then
  887.     echo shar: \"'globals.h'\" unpacked with wrong size!
  888.   fi
  889.   # end of 'globals.h'
  890. fi
  891. if test -f 'indent.man' -a "${1}" != "-c" ; then 
  892.   echo shar: Will not clobber existing file \"'indent.man'\"
  893. else
  894.   echo shar: Extracting \"'indent.man'\" \(15868 characters\)
  895.   sed "s/^X//" >'indent.man' <<'END_OF_FILE'
  896. X
  897. X
  898. X
  899. X     INDENT(1)             A/UX (July 14, 1989)              INDENT(1)
  900. X
  901. X
  902. X
  903. X     NAME
  904. X          indent - indent and format C program source
  905. X
  906. X     SYNOPSIS
  907. X          indent  [ input-file [ output-file ] ] [ -bad | -nbad ]
  908. X                 [ -bap | -nbap ] [ -bbb | -nbbb ] [ -bc | -nbc ]
  909. X                 [ -bl ] [ -br ] [ -brr ] [ -cn ] [ -cdn ]
  910. X                 [ -cdb | -ncdb ] [ -ce | -nce ] [ -cin ] [ -clin ]
  911. X                 [ -ccin ] [ -dn ] [ -din ] [ -fc1 | -nfc1 ] [ -in ]
  912. X                 [ -ip | -nip ] [ -ln ] [ -lcn ] [ -lp | -nlp ]
  913. X                 [ -pcs | -npcs ] [ -npro ] [ -prs | -nprs ]
  914. X                 [ -psl | -npsl ] [ -sc | -nsc ] [ -sob | -nsob ]
  915. X                 [ -st ] [ -tabsn ] [ -troff ] [ -v | -nv ] [ -+ ]
  916. X
  917. X
  918. X     DESCRIPTION
  919. X          Indent is a C program formatter.  It reformats the C program
  920. X          in the input-file according to the switches.  The switches
  921. X          which can be specified are described below. They may appear
  922. X          before or after the file names.
  923. X
  924. X          NOTE: If you only specify an input-file, the formatting is
  925. X          done 'in-place', that is, the formatted file is written back
  926. X          into input-file and a backup copy of input-file is written
  927. X          in the current directory.  If input-file is named
  928. X          '/blah/blah/file', the backup file is named file.BAK.
  929. X
  930. X          If output-file is specified, indent checks to make sure it
  931. X          is different from input-file.
  932. X
  933. X     OPTIONS
  934. X          The options listed below control the formatting style
  935. X          imposed by indent.
  936. X
  937. X          -bap,-nbap     If -bap is specified, a blank line is forced
  938. X                         after every procedure body.  Default:  -nbap.
  939. X
  940. X          -bad,-nbad     If -bad is specified, a blank line is forced
  941. X                         after every block of declarations.  Default:
  942. X                         -nbad.
  943. X
  944. X          -bbb,-nbbb     If -bbb is specified, a blank line is forced
  945. X                         before every block comment.  Default:  -nbbb.
  946. X
  947. X          -bc,-nbc       If -bc is specified, then a newline is forced
  948. X                         after each comma in a declaration. -nbc turns
  949. X                         off this option.  The default is -bc.
  950. X
  951. X          -br,-bl,-brr   Specifying -bl lines up compound statements
  952. X
  953. X
  954. X
  955. X
  956. X
  957. X
  958. X     Page 1                                          (printed 3/16/92)
  959. X
  960. X
  961. X
  962. X
  963. X
  964. X
  965. X     INDENT(1)             A/UX (July 14, 1989)              INDENT(1)
  966. X
  967. X
  968. X
  969. X                         like this:
  970. X                             if (...)
  971. X                             {
  972. X                                 code
  973. X                             }
  974. X                         Specifying -br (the default) makes them look
  975. X                         like this:
  976. X                             if (...) {
  977. X                                 code
  978. X                             }
  979. X                         And specifying -brr makes them look like
  980. X                         this:
  981. X                             if (...)
  982. X                                 {
  983. X                                 code
  984. X                                 }
  985. X
  986. X          -cn            The column in which comments on code start.
  987. X                         The default is 33.
  988. X
  989. X          -cdn           The column in which comments on declarations
  990. X                         start.  The default is for these comments to
  991. X                         start in the same column as those on code.
  992. X
  993. X          -cdb,-ncdb     Enables (disables) the placement of comment
  994. X                         delimiters on blank lines.  With this option
  995. X                         enabled, comments look like this:
  996. X                              /*
  997. X                               * this is a comment
  998. X                               */
  999. X                         Rather than like this:
  1000. X                              /* this is a comment */
  1001. X                         This only affects block comments, not
  1002. X                         comments to the right of code. The default is
  1003. X                         -cdb .
  1004. X
  1005. X          -ce,-nce       Enables (disables) forcing 'else's to cuddle
  1006. X                         up to the immediatly preceding }.  The default
  1007. X                         is -ce.
  1008. X
  1009. X          -cin           Sets the continuation indent to be n.
  1010. X                         Continuation lines will be indented that far
  1011. X                         from the beginning of the first line of the
  1012. X                         statement.  Parenthesized expressions have
  1013. X                         extra indentation added to indicate the
  1014. X                         nesting, unless -lp is in effect.  -ci
  1015. X                         defaults to the same value as -i.
  1016. X
  1017. X          -clin          Causes case labels to be indented n tab stops
  1018. X                         to the right of the containing switch
  1019. X                         statement.  -cli0.5 causes case labels to be
  1020. X                         indented half a tab stop.  The default is
  1021. X                         -cli0 .
  1022. X
  1023. X
  1024. X
  1025. X     Page 2                                          (printed 3/16/92)
  1026. X
  1027. X
  1028. X
  1029. X
  1030. X
  1031. X
  1032. X     INDENT(1)             A/UX (July 14, 1989)              INDENT(1)
  1033. X
  1034. X
  1035. X
  1036. X          -ccin          Causes case code to be indented n tab stops
  1037. X                         to the right of the corresponding case label.
  1038. X                         -cci0.5 causes case code to be indented half
  1039. X                         a tab stop.  The default is -cci1 .
  1040. X
  1041. X          -dn            Controls the placement of comments which are
  1042. X                         not to the right of code.  The default -d1
  1043. X                         means that such comments are placed one
  1044. X                         indentation level to the left of code.
  1045. X                         Specifying -d0 lines up these comments with
  1046. X                         the code.  See the section on comment
  1047. X                         indentation below.
  1048. X
  1049. X          -din           Specifies the indentation, in character
  1050. X                         positions, from a declaration keyword to the
  1051. X                         following identifier.  The default is -di16 .
  1052. X
  1053. X          -fc1,-nfc1     Enables (disables) the formatting of comments
  1054. X                         that start in column 1.  Often, comments
  1055. X                         whose leading '/' is in column 1 have been
  1056. X                         carefully hand formatted by the programmer.
  1057. X                         In such cases, -nfc1 should be used.  The
  1058. X                         default is -fc1.
  1059. X
  1060. X          -in            The number of spaces for one indentation
  1061. X                         level.  The default is 4.
  1062. X
  1063. X          -ip,-nip       Enables (disables) the indentation of
  1064. X                         parameter declarations from the left margin.
  1065. X                         The default is -ip .
  1066. X
  1067. X          -ln            Maximum length of an output line.  The
  1068. X                         default is 75.
  1069. X
  1070. X          -npro          Causes the profile files, './.indent.pro' and
  1071. X                         '~/.indent.pro', to be ignored.
  1072. X
  1073. X          -lp,-nlp       Lines up code surrounded by parenthesis in
  1074. X                         continuation lines.  If a line has a left
  1075. X                         paren which is not closed on that line, then
  1076. X                         continuation lines will be lined up to start
  1077. X                         at the character position just after the left
  1078. X                         paren.  For example, here is how a piece of
  1079. X                         continued code looks with -nlp in effect:
  1080. X                             p1 = first_procedure(second_procedure(p2, p3),
  1081. X                                 third_procedure(p4, p5));
  1082. X                         With -lp in effect (the default) the code
  1083. X                         looks somewhat clearer:
  1084. X                             p1 = first_procedure(second_procedure(p2, p3),
  1085. X                                                  third_procedure(p4, p5));
  1086. X
  1087. X
  1088. X
  1089. X
  1090. X
  1091. X     Page 3                                          (printed 3/16/92)
  1092. X
  1093. X
  1094. X
  1095. X
  1096. X
  1097. X
  1098. X     INDENT(1)             A/UX (July 14, 1989)              INDENT(1)
  1099. X
  1100. X
  1101. X
  1102. X                         Inserting a couple more newlines we get:
  1103. X                             p1 = first_procedure(second_procedure(p2,
  1104. X                                                                   p3),
  1105. X                                                  third_procedure(p4,
  1106. X                                                                  p5));
  1107. X
  1108. X          -pcs , -npcs   If true (-pcs) all procedure calls will have
  1109. X                         a space inserted between the name and the
  1110. X                         '('.  The default is -npcs
  1111. X
  1112. X          -prs , -nprs   If true (-prs) all parentheses will have a
  1113. X                         space inserted after the '(' and before the
  1114. X                         ')'.  The default is -nprs
  1115. X
  1116. X          -psl , -npsl   If true (-psl) the names of procedures being
  1117. X                         defined are placed in column 1 - their types,
  1118. X                         if any, will be left on the previous lines.
  1119. X                         The default is -psl
  1120. X
  1121. X          -sc,-nsc       Enables (disables) the placement of asterisks
  1122. X                         ('*'s) at the left edge of all comments.
  1123. X
  1124. X          -sob,-nsob     If -sob is specified, indent will swallow
  1125. X                         optional blank lines.  You can use this to
  1126. X                         get rid of blank lines after declarations.
  1127. X                         Default:  -nsob
  1128. X
  1129. X          -st            Causes indent to take its input from stdin,
  1130. X                         and put its output to stdout.
  1131. X
  1132. X          -Ttypename     Adds typename to the list of type keywords.
  1133. X                         Names accumulate:  -T can be specified more
  1134. X                         than once.  You need to specify all the
  1135. X                         typenames that appear in your program that
  1136. X                         are defined by typedefs - nothing will be
  1137. X                         harmed if you miss a few, but the program
  1138. X                         won't be formatted as nicely as it should.
  1139. X                         This sounds like a painful thing to have to
  1140. X                         do, but it's really a symptom of a problem in
  1141. X                         C: typedef causes a syntactic change in the
  1142. X                         language and indent can't find all typedefs.
  1143. X
  1144. X          -tabsn         Tells indent that tabs are assumed to be at
  1145. X                         every n columns.  The default is -tabs8.  If
  1146. X                         n is less than 3 then tabs will not be used
  1147. X                         at all in the output.
  1148. X
  1149. X          -troff         Causes indent to format the program for
  1150. X                         processing by troff.  It will produce a fancy
  1151. X                         listing in much the same spirit as vgrind.
  1152. X                         If the output file is not specified, the
  1153. X                         default is standard output, rather than
  1154. X                         formatting in place.
  1155. X
  1156. X
  1157. X
  1158. X     Page 4                                          (printed 3/16/92)
  1159. X
  1160. X
  1161. X
  1162. X
  1163. X
  1164. X
  1165. X     INDENT(1)             A/UX (July 14, 1989)              INDENT(1)
  1166. X
  1167. X
  1168. X
  1169. X          -v,-nv         -v turns on 'verbose' mode, -nv turns it off.
  1170. X                         When in verbose mode, indent reports when it
  1171. X                         splits one line of input into two or more
  1172. X                         lines of output, and gives some size
  1173. X                         statistics at completion. The default is -nv.
  1174. X
  1175. X          -+             turns on support for C++. In c++ mode, :: is
  1176. X                         permited in identifiers, C++ keywords are
  1177. X                         supported, and class definition keywords
  1178. X                         (public, private, etc.) are set in column 2.
  1179. X
  1180. X     FURTHER DESCRIPTION
  1181. X          You may set up your own 'profile' of defaults to indent by
  1182. X          creating a file called .indent.pro in either your login
  1183. X          directory or the current directory and including whatever
  1184. X          switches you like.  A '.indent.pro' in the current directory
  1185. X          takes precedence over the one in your login directory.  If
  1186. X          indent is run and a profile file exists, then it is read to
  1187. X          set up the program's defaults.  Switches on the command
  1188. X          line, though, always override profile switches.  The
  1189. X          switches should be separated by spaces, tabs or newlines.
  1190. X
  1191. X          Comments
  1192. X
  1193. X          'Box' comments.  Indent assumes that any comment with a dash
  1194. X          or star immediately after the start of comment (that is,
  1195. X          '/*-' or '/**') is a comment surrounded by a box of stars.
  1196. X          Each line of such a comment is left unchanged, except that
  1197. X          its indentation may be adjusted to account for the change in
  1198. X          indentation of the first line of the comment.
  1199. X
  1200. X          Straight text.  All other comments are treated as straight
  1201. X          text.  Indent fits as many words (separated by blanks, tabs,
  1202. X          or newlines) on a line as possible.  Blank lines break
  1203. X          paragraphs.
  1204. X
  1205. X          Comment indentation
  1206. X
  1207. X          If a comment is on a line with code it is started in the
  1208. X          'comment column', which is set by the -cn command line
  1209. X          parameter.  Otherwise, the comment is started at n
  1210. X          indentation levels less than where code is currently being
  1211. X          placed, where n is specified by the -dn command line
  1212. X          parameter.  If the code on a line extends past the comment
  1213. X          column, the comment starts further to the right, and the
  1214. X          right margin may be automatically extended in extreme cases.
  1215. X
  1216. X          Special Comments
  1217. X
  1218. X          Indent produces and interprets some special comments.  When
  1219. X          indent cannot parse the source, it prints a message on
  1220. X          standard error and inserts a comment into the output of the
  1221. X
  1222. X
  1223. X
  1224. X     Page 5                                          (printed 3/16/92)
  1225. X
  1226. X
  1227. X
  1228. X
  1229. X
  1230. X
  1231. X     INDENT(1)             A/UX (July 14, 1989)              INDENT(1)
  1232. X
  1233. X
  1234. X
  1235. X          form
  1236. X               /**INDENT** ErrorMessage */
  1237. X
  1238. X          Indent interprets several special comments as directives.
  1239. X          First, it makes no attempt to format lines containing the
  1240. X          error comment described above.
  1241. X
  1242. X          Second, lines of the form:
  1243. X               /* INDENT OFF */
  1244. X          or
  1245. X               /* INDENT ON */
  1246. X          disable and re-enable indent formatting. Any amount of
  1247. X          whitespace may replace the spaces shown in the examples.
  1248. X
  1249. X          Third, indent allows formatting controls to be included in
  1250. X          the source via comments of the form:
  1251. X               /* INDENT: arg1 arg2 arg3 ... arg4 */
  1252. X          The arguments given are in the same syntax as the command
  1253. X          line or profile file.  For example:
  1254. X               /* INDENT: -cli.25 -nfc1 */
  1255. X
  1256. X          Preprocessor lines
  1257. X
  1258. X          In general, indent leaves preprocessor lines alone.  The
  1259. X          only reformmatting that it will do is to straighten up
  1260. X          trailing comments.  It leaves imbedded comments alone.
  1261. X          Conditional compilation (#ifdef...#endif) is recognized and
  1262. X          indent attempts to correctly compensate for the syntactic
  1263. X          peculiarites introduced.
  1264. X
  1265. X          C syntax
  1266. X
  1267. X          Indent understands a substantial amount about the syntax of
  1268. X          C, but it has a 'forgiving' parser.  It attempts to cope
  1269. X          with the usual sorts of incomplete and misformed syntax.  In
  1270. X          particular, the use of macros like:
  1271. X                  #define forever for(;;)
  1272. X          is handled properly.
  1273. X
  1274. X     FILES
  1275. X          ./.indent.pro  profile file
  1276. X
  1277. X     BUGS
  1278. X          Indent has even more switches than ls.
  1279. X
  1280. X          A common mistake that often causes grief is typing:
  1281. X              indent *.c
  1282. X          to the shell in an attempt to indent all the C programs in a
  1283. X          directory.  This is a really nasty thing to do.  (Think
  1284. X          about it.)
  1285. X
  1286. X
  1287. X
  1288. X
  1289. X
  1290. X     Page 6                                          (printed 3/16/92)
  1291. X
  1292. X
  1293. X
  1294. X/users/jrs>
  1295. END_OF_FILE
  1296.   if test 15868 -ne `wc -c <'indent.man'`; then
  1297.     echo shar: \"'indent.man'\" unpacked with wrong size!
  1298.   fi
  1299.   # end of 'indent.man'
  1300. fi
  1301. if test -f 'readme' -a "${1}" != "-c" ; then 
  1302.   echo shar: Will not clobber existing file \"'readme'\"
  1303. else
  1304.   echo shar: Extracting \"'readme'\" \(7034 characters\)
  1305.   sed "s/^X//" >'readme' <<'END_OF_FILE'
  1306. X---------------------------------------------------------------------
  1307. X
  1308. XIndent is a C/C++ program formatter.  It reformats the C/C++ program
  1309. Xin the input-file according to a long list of command line switches.
  1310. X
  1311. XThe original indent (from the University of Illinois and part of the
  1312. XBerkeley Software Distribution) was only for C programs.  It has since
  1313. Xbeen modified to understand C++ syntax as well.
  1314. X
  1315. X---------------------------------------------------------------------
  1316. X
  1317. X            A short guide to indent
  1318. X        (for impatient users of OS/2 or MSDOS)
  1319. X
  1320. XAssuming you have managed to unpack the distribution sources and have
  1321. Xcompiled indent.exe:-
  1322. X
  1323. X1. Set up an environment variable called HOME pointing at some directory
  1324. X   where you keep useful things.  Copy indent.pro into that directory.
  1325. X   Alternatively put indent.pro somewhere along your DPATH or PATH.
  1326. X
  1327. X2. If you use a brain-damaged editor which doesn't allow tabs to be set
  1328. X   at any interval other than 8 columns, either change the line in
  1329. X   indent.pro which says
  1330. X    -tabs 4
  1331. X   or simply remove it altogether.
  1332. X
  1333. X3. Copy indent.exe to some directory on your PATH.
  1334. X
  1335. X4. Change directory to where your messy C or C++ programs reside.
  1336. X
  1337. X5. To clean up all the programs issue the command:
  1338. X    for %f in (*.c *.cpp) do indent %f
  1339. X
  1340. XIf you have an indent.pro in the current directory that will be processed
  1341. Xafter the one found in HOME or along DPATH or PATH.  This allows you to
  1342. Xhave options unique to a project without having to specify everything.
  1343. X
  1344. X---------------------------------------------------------------------
  1345. X
  1346. X             An even shorter guide to indent
  1347. X        (for impatient users of BSD-flavoured UNIX)
  1348. X
  1349. XRead the guide for OS/2-MSDOS and make the following changes:
  1350. X
  1351. X1. Copy indent.pro into your home directory or somewhere along your PATH,
  1352. X   calling it .indent.pro
  1353. X
  1354. X5. Use a loop syntax appropriate for your shell.
  1355. X
  1356. XIf you have a .indent.pro in the current directory that will be processed
  1357. Xafter the one found in your HOME directory or along your PATH.  This allows
  1358. Xyou to have options unique to a project without having to specify everything.
  1359. X
  1360. X---------------------------------------------------------------------
  1361. X
  1362. X                      OS/2 implementor's note
  1363. X                      -----------------------
  1364. X
  1365. XThere seems to have been three streams of development for this program.
  1366. X
  1367. XThe original indent came from the University of Illinois where it was
  1368. Xapparently written in 1976.  Some work was done by James Gosling and the
  1369. Xpeople at Sun Microsystems.  The program became part of the BSD UNIX
  1370. Xdistribution at some time not later than 1985.  At around that time it was
  1371. Xported to MSDOS by Bruce Mallett and various fixes were done by Bruce
  1372. XMallett and James Thompson.  James Thompson also implemented the handling
  1373. Xof tabs at spacings other than 8 (surely a most worthwhile enhancement; who
  1374. Xprograms in C with tabs set at 8 anyway?)
  1375. X
  1376. XWhile all this good stuff was going on, other (unnamed) people upgraded the
  1377. Xoriginal program to handle C++ syntax as well as ordinary C and apparently
  1378. Xfixed a few minor annoyances which were extant in the version from which
  1379. Xthe MSDOS implementation was derived.
  1380. X
  1381. XThen of course, the GNU project people of the Free Software Foundation have
  1382. Xbeen doing things with sources apparently derived from the BSD version.
  1383. X
  1384. XI have not looked at the GNU version of indent. I started with the BSD C++
  1385. Xformatter sources from comp.misc.sources volume 21 and modified them for
  1386. Xcompilation with Microsoft C386 under OS/2 2.0.  That gave me a working
  1387. Xbaseline version to which I made the following modifications:
  1388. X
  1389. X1  Changed some of the file names to allow compilation with Microsoft C
  1390. X   version 6.00A which objects to files whose names do not conform to
  1391. X   MSDOS's 8.3 format.
  1392. X
  1393. X2  Built new makefiles for OS/2 2.0 and for OS/2 1.X.  (The MSDOS version
  1394. X   is created by post-processing the OS/2 1.X version.)
  1395. X
  1396. X   Note that when you use Makefile.1x you'll see some warning messages
  1397. X   concerning the truncation of variable names.  You may safely ignore
  1398. X   them.  The messages do not appear when compiling the 32-bit version.
  1399. X
  1400. X2  Added James Thompson's tab stuff.
  1401. X
  1402. X3  Fixed a bug which was causing //-style comments to be followed by an
  1403. X   extra newline or an extra space depending on context.
  1404. X
  1405. X4  Corrected the stack overflow problem in the OS/2 1.x and MSDOS versions.
  1406. X   (This seems to have been independently discovered and fixed twice
  1407. X   previously but the sources contained no trace of the fix.)
  1408. X
  1409. X5  Patched the manual source to reflect the new -tabs option and generated
  1410. X   a human-readable version.
  1411. X
  1412. XFinally, I put the sources through the indenter to clean up the mess.
  1413. X
  1414. XMore recently still, I built the program using the IBM C Set/2 tools after
  1415. Xmodifying the 2.0 Makefile.  I also:
  1416. X
  1417. X6  Fixed a bug notified by Steve Comen which was causing overlength //
  1418. X   comments to be split incorrectly.
  1419. X
  1420. X7  Modified the profile search to include DPATH under OS/2 and to include
  1421. X   PATH on all platforms.
  1422. X
  1423. X8  Modified the action of the -tabsN specifier.  If N is 2 or less then
  1424. X   indent will not use tab characters in the output.  This patch had the
  1425. X   side-effect of avoiding a potential divide-by-zero fault which would
  1426. X   have arisen if someone had said -tabs0.
  1427. X
  1428. XJust before preparing the shar files for submission I removed all the tabs
  1429. Xwith the command:
  1430. X    for %f in (*.c *.h) do indent -tabs0 %f
  1431. X  
  1432. XNow, if I have done the job properly, the current source should combine both
  1433. Xthe BSD development streams.  Furthermore, it should compile under OS/2 1.x
  1434. Xfor OS/2 and MSDOS, under OS/2 2.0 for the 32-bit 'flat' model using either
  1435. Xthe Microsoft C386 compiler or the IBM C Set/2 compiler and on the original
  1436. XBSD UNIX platform.
  1437. X
  1438. XI am indebted to Steve Comen and his colleagues for help with testing and
  1439. Xverifying the BSD compatibility and for several patches.
  1440. X
  1441. XNow all that remains to be done is to incorporate the nicer features of this
  1442. Xversion into the GNU one.  Any volunteers?
  1443. X
  1444. XJon Saxton
  1445. XApril 1992
  1446. X
  1447. X-------------------------------------------------------------------------
  1448. X
  1449. XManifest
  1450. X
  1451. X    args.c        \
  1452. X    comment.c     \
  1453. X    indent.c      \_    Program source files
  1454. X    io.c          /
  1455. X    lexi.c         /
  1456. X    parse.c        /
  1457. X
  1458. X    codes.h        \
  1459. X    globals.h     >-    Header files
  1460. X    proto.h        /
  1461. X
  1462. X    indent.1        Manual source
  1463. X
  1464. X    indent.man        Manual in human-readable form
  1465. X
  1466. X    indent.def        Used only when compiling
  1467. X                under OS/2 for OS/2 or MSDOS
  1468. X
  1469. X    indent.pro        A sample profile (the one used to format
  1470. X                these sources).  Rename to .indent.pro
  1471. X                for use with BSD UNIX.
  1472. X
  1473. X    Makefile.1x        Makefile for compiling under OS/2 1.x.
  1474. X                Generates a bound 16-bit executable which
  1475. X                will run under OS/2 or MSDOS.
  1476. X
  1477. X    Makefile.20        Makefile for compiling under OS/2 2.0 using
  1478. X                the IBM C Set/2 compiler.  Generates a 32-
  1479. X                bit executable.
  1480. X
  1481. X    Makefile.bsd        Untouched.  This is the original Makefile
  1482. X                as distributed with the BSD version.
  1483. X
  1484. X    readme            This file
  1485. X
  1486. X    typedefs.os2        A collection of type names which may be
  1487. X                useful for programming the OS/2 kernel.
  1488. X                Simply add these to indent.pro or rename
  1489. X                typedefs.os2 to indent.pro in the current
  1490. X                directory.
  1491. END_OF_FILE
  1492.   if test 7034 -ne `wc -c <'readme'`; then
  1493.     echo shar: \"'readme'\" unpacked with wrong size!
  1494.   fi
  1495.   # end of 'readme'
  1496. fi
  1497. echo shar: End of archive 3 \(of 4\).
  1498. cp /dev/null ark3isdone
  1499. MISSING=""
  1500. for I in 1 2 3 4 ; do
  1501.     if test ! -f ark${I}isdone ; then
  1502.     MISSING="${MISSING} ${I}"
  1503.     fi
  1504. done
  1505. if test "${MISSING}" = "" ; then
  1506.     echo You have unpacked all 4 archives.
  1507.     rm -f ark[1-9]isdone
  1508. else
  1509.     echo You still must unpack the following archives:
  1510.     echo "        " ${MISSING}
  1511. fi
  1512. exit 0
  1513. exit 0 # Just in case...
  1514.