From: VZDMZA::IN%"HUBER%DM0MPI53.BITNET@vm.gmd.de" "Joseph Huber, MPI Muenchen" 19-FEB-1992 15:30:28.23 To: IN%"WIEHL@VKCMZD.Chemie.Uni-Mainz.de" CC: Subj: INDENT PART 1 of 5 Received: from vm.gmd.de by VzdmzA.ZDV.Uni-Mainz.DE (PMDF #12046) id <01GGPHTOLYO08WW2LI@VzdmzA.ZDV.Uni-Mainz.DE>; Wed, 19 Feb 1992 15:21 GMT +0100 Received: from DM0MPI11 by vm.gmd.de (IBM VM SMTP R1.2.2MX) with BSMTP id 3094; Wed, 19 Feb 92 15:22:52 CET Received: from DM0MPI53.BITNET (DM0MPI53@DM0MPI12) by DM0MPI11 (Mailer R2.08) with BSMTP id 9550; Wed, 19 Feb 92 15:23:36 GMT Date: Wed, 19 Feb 92 15:18 +0200 From: "Joseph Huber, MPI Muenchen" Subject: INDENT PART 1 of 5 To: WIEHL@VKCMZD.Chemie.Uni-Mainz.de Message-id: <01GGPHTOLYO08WW2LI@VzdmzA.ZDV.Uni-Mainz.DE> Organization: Max-Planck-Institut fuer Physik, Muenchen X-Envelope-to: WIEHL@VKCMZD.Chemie.Uni-Mainz.de X-Delivery-Notice: SMTP MAIL FROM does not correspond to sender. X-Original-To: RSCS%"WIEHL@VKCMZD.CHEMIE.UNI-MAINZ.DE" Comments: This is gatewayed mail. WARNING: Mail may not necessarily be returnable thru this path. $! ------------------ CUT HERE ----------------------- $ v='f$verify(f$trnlnm("SHARE_VERIFY"))' $! $! This archive created by VMS_SHARE Version 7.2-007 22-FEB-1990 $! On 22-OCT-1991 10:13:24.93 By user MRL $! $! This VMS_SHARE Written by: $! Andy Harper, Kings College London UK $! $! Acknowledgements to: $! James Gray - Original VMS_SHARE $! Michael Bednarek - Original Concept and implementation $! $!+ THIS PACKAGE DISTRIBUTED IN 5 PARTS, TO KEEP EACH PART $! BELOW 70 BLOCKS $! $! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER $! AND EXECUTE AS A COMMAND PROCEDURE ( @name ) $! $! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING: $! 1. AAAREADME.TXT;2 $! 2. ARGS.C;25 $! 3. INDENT.C;36 $! 4. IO.C;18 $! 5. LEXI.C;20 $! 6. PARSE.C;4 $! 7. PR_COMMENT.C;21 $! 8. INDENT_CODES.H;2 $! 9. INDENT_GLOBS.H;11 $! 10. PARAM.H;1 $! 11. INDENT.1;2 $! 12. INDENT.HLP;9 $! 13. INDENT.LNK;3 $! 14. MAKEFILE.;1 $! 15. README.;1 $! $set="set" $set symbol/scope=(nolocal,noglobal) $f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID")) $e="write sys$error ""%UNPACK"", " $w="write sys$output ""%UNPACK"", " $ if f$trnlnm("SHARE_LOG") then $ w = "!" $ ve=f$getsyi("version") $ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START $ e "-E-OLDVER, Must run at least VMS 4.4" $ v=f$verify(v) $ exit 44 $UNPACK: SUBROUTINE ! P1=filename, P2=checksum $ if f$search(P1) .eqs. "" then $ goto file_absent $ e "-W-EXISTS, File ''P1' exists. Skipped." $ delete 'f'* $ exit $file_absent: $ if f$parse(P1) .nes. "" then $ goto dirok $ dn=f$parse(P1,,,"DIRECTORY") $ w "-I-CREDIR, Creating directory ''dn'." $ create/dir 'dn' $ if $status then $ goto dirok $ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped." $ delete 'f'* $ exit $dirok: $ w "-I-PROCESS, Processing file ''P1'." $ if .not. f$verify() then $ define/user sys$output nl: $ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1' PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET( SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:= CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b)); LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION( BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1); IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE; MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1; ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")= 1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF"; POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r); ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1; COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE, "output_file"));ENDPROCEDURE;Unpacker;QUIT; $ delete/nolog 'f'* $ CHECKSUM 'P1' $ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT $ e "-E-CHKSMFAIL, Checksum of ''P1' failed." $ ENDSUBROUTINE $START: $ create 'f' XThe following copy of INDENT includes modifications made by Mark London, XMRL@NERUS.PFC.MIT.EDU. It was tested with many different C sources as input Xfiles. Many of the changes were made necessary due to the original program V not Xbeing able to very easily handle structure initializations, particularly tho Vse Xfound in DECWINDOWS/X programs. `20 X XINDENT has been modified by different people, so different versions exist. XThe HELP file contained here does not include all the possible qualifiers of Xthis version, as it was obtained on a machine with a different version. Mos Vt Xof the important qualifiers are mentioned, however, including some that I ha Vve Xadded. To see undocumented commands, look at ARGS.C. Note that I have Xeliminated the code which creates a backup copy of the source, as that is Xunnecessary under VMS. I also have modified it so if only the file prefix Xis specified on the command line, it assumes the suffix is .C . $ CALL UNPACK AAAREADME.TXT;2 2003204511 $ create 'f' X/* X * Copyright (c) 1985 Sun Microsystems, Inc. Copyright (c) 1980 The Regents V of the University of California. Copyright (c) 1976 X * Board of Trustees of the University of Illinois. All rights reserved. X *`20 X * Redistribution and use in source and binary forms are permitted provided V that: (1) source distributions retain this entire X * copyright notice and comment, and (2) distributions including binaries di Vsplay the following acknowledgement: `60`60This product X * includes software developed by the University of California, Berkeley and V its contributors'' in the documentation or other X * materials provided with the distribution and in all advertising materials V mentioning features or use of this software. Neither X * the name of the University nor the names of its contributors may be used V to endorse or promote products derived from this X * software without specific prior written permission. THIS SOFTWARE IS PROV VIDED `60`60AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERC VHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. X */ X X#ifndef lint Xstatic char sccsid`5B`5D = "@(#)args.c`095.9 (Berkeley) 6/1/90"; X#endif X X/* X * Argument scanning and profile reading code. Default parameters are set h Vere as well. X */ X X#include "indent_globs.h" X#include X Xchar *getenv(),*index(); X X/* profile types */ X#define`09PRO_SPECIAL`091 X#define`09PRO_BOOL`092 X#define`09PRO_INT`09`093 X#define PRO_FONT`094 X X/* profile specials for booleans */ X#define`09ON`09`091 X#define`09OFF`09`090 X X/* profile specials for specials */ X#define`09IGN`09`091 X#define`09CLI`09`092 X#define`09STDIN`09`093 X#define`09KEY`09`094 X#define`09CCI`09`095 X Xchar *option_source = "?"; X X/* X * N.B.: because of the way the table here is scanned, options whose names a Vre substrings of other options must occur later; that X * is, with -lp vs -l, -lp must be first. Also, while (most) booleans occur V more than once, the last default value is the one X * actually assigned. X */ Xstruct pro `7B X char *p_name;`09`09`09/* name, eg -bl, -cli */ X int p_type;`09`09`09/* type (int, bool, special) */ X int p_default;`09`09/* the default value (if int) */ X int p_special;`09`09/* depends on type */ X int *p_obj;`09`09`09/* the associated variable */ X`7D pro`5B`5D = `7B X X "T",PRO_SPECIAL,0,KEY,0, X "bacc",PRO_BOOL,false,ON,&blank_conditional_compilation, X "badp",PRO_BOOL,false,ON,&blank_declarations_at_proctop, X "bad",PRO_BOOL,false,ON,&blanklines_after_declarations, X "bap",PRO_BOOL,false,ON,&blanklines_after_procs, X "bbb",PRO_BOOL,false,ON,&blanklines_before_blockcomments, X "bc",PRO_BOOL,true,OFF,&ps.leave_comma, X "bl",PRO_BOOL,false,OFF,&btype_2, X "br",PRO_BOOL,false,ON,&btype_2, X "bs",PRO_BOOL,false,ON,&Bill_Shannon, X "bsl",PRO_BOOL,false,ON,&break_single_line, X "cdb",PRO_BOOL,false,OFF,&comment_delimiter_on_blankline, X "cd",PRO_INT,0,0,&ps.decl_com_ind, X "ce",PRO_BOOL,false,ON,&cuddle_else, X "ci",PRO_INT,0,0,&continuation_indent, X "cci",PRO_SPECIAL,0,CCI,0, X "cli",PRO_SPECIAL,0,CLI,0, X "c",PRO_INT,33,0,&ps.com_ind, X "di",PRO_INT,0,0,&ps.decl_indent, X "dj",PRO_BOOL,false,ON,&ps.ljust_decl, X "d",PRO_INT,0,0,&ps.unindent_displace, X "eei",PRO_BOOL,false,ON,&extra_expression_indent, X "ei",PRO_BOOL,true,ON,&ps.else_if, X "fbc",PRO_FONT,0,0,(int *) &blkcomf, X "fbx",PRO_FONT,0,0,(int *) &boxcomf, X "fb",PRO_FONT,0,0,(int *) &bodyf, X "fc1",PRO_BOOL,true,ON,&format_col1_comments, X "fc",PRO_FONT,0,0,(int *) &scomf, X "fk",PRO_FONT,0,0,(int *) &keywordf, X "fs",PRO_FONT,0,0,(int *) &stringf, X "ip",PRO_BOOL,true,ON,&ps.indent_parameters, X "i",PRO_INT,2,0,&ps.ind_size, X "lc",PRO_INT,0,0,&block_comment_max_col, X "lp",PRO_BOOL,true,ON,&lineup_to_parens, X "l",PRO_INT,132,0,&max_col, X "nbacc",PRO_BOOL,false,OFF,&blank_conditional_compilation, X "nbadp",PRO_BOOL,false,OFF,&blank_declarations_at_proctop, X "nbad",PRO_BOOL,false,OFF,&blanklines_after_declarations, X "nbap",PRO_BOOL,false,OFF,&blanklines_after_procs, X "nbbb",PRO_BOOL,false,OFF,&blanklines_before_blockcomments, X "nbc",PRO_BOOL,true,ON,&ps.leave_comma, X "nbs",PRO_BOOL,false,OFF,&Bill_Shannon, X "ncdb",PRO_BOOL,false,OFF,&comment_delimiter_on_blankline, X "nce",PRO_BOOL,false,OFF,&cuddle_else, X "ndj",PRO_BOOL,false,OFF,&ps.ljust_decl, X "neei",PRO_BOOL,false,OFF,&extra_expression_indent, X "nei",PRO_BOOL,true,OFF,&ps.else_if, X "nfc1",PRO_BOOL,true,OFF,&format_col1_comments, X "nip",PRO_BOOL,true,OFF,&ps.indent_parameters, X "nlp",PRO_BOOL,true,OFF,&lineup_to_parens, X "npcs",PRO_BOOL,false,OFF,&proc_calls_space, X "npro",PRO_SPECIAL,0,IGN,0, X "npsl",PRO_BOOL,false,OFF,&procnames_start_line, X "nps",PRO_BOOL,false,OFF,&pointer_as_binop, X "nsc",PRO_BOOL,false,OFF,&star_comment_cont, X "nsob",PRO_BOOL,false,OFF,&swallow_optional_blanklines, X "nv",PRO_BOOL,false,OFF,&verbose, X "pcs",PRO_BOOL,false,ON,&proc_calls_space, X "prs",PRO_BOOL,false,ON,&paren_space, X "psl",PRO_BOOL,false,ON,&procnames_start_line, X "ps",PRO_BOOL,false,ON,&pointer_as_binop, X "sc",PRO_BOOL,false,ON,&star_comment_cont, X "sob",PRO_BOOL,false,ON,&swallow_optional_blanklines, X "spc",PRO_BOOL,false,ON,&spaces_after_comma, X "st",PRO_SPECIAL,0,STDIN,0, X "troff",PRO_BOOL,false,ON,&troff, X "v",PRO_BOOL,false,ON,&verbose, X "+",PRO_BOOL,false,ON,&cplus, X /* whew! */ X 0,0,0,0,0 X`7D; X X/* X * set_profile reads $HOME/.indent.pro and ./.indent.pro and handles argumen Vts given in these files. X */ Xset_profile() X`7B X register FILE *f; X char fname`5BBUFSIZ`5D; X#ifdef VMS X static char prof`5B`5D = "indent.pro"; X#else X static char prof`5B`5D = ".indent.pro"; X#endif X X#ifdef VMS X sprintf(fname,"%s%s",getenv("SYS$LOGIN"),prof); X#else X sprintf(fname,"%s/%s",getenv("HOME"),prof); X#endif X if ((f = fopen(option_source = fname,"r")) != NULL) `7B X scan_profile(f); X (void) fclose(f); X `7D X if ((f = fopen(option_source = prof,"r")) != NULL) `7B X scan_profile(f); X (void) fclose(f); X `7D X option_source = "Command line"; X`7D X Xscan_profile(f) X register FILE *f; X`7B X register int i; X register char *p; X char buf`5BBUFSIZ`5D; X X while (1) `7B X for (p = buf; (i = getc(f)) != EOF && (*p = i) > ' '; ++p); X if (p != buf) `7B X *p++ = 0; X if (verbose) X`09printf("profile: %s\n",buf); X set_option(buf); X `7D else if (i == EOF) X return; X `7D X`7D X Xchar *param_start; X Xeqin(s1,s2,type) X register char *s1; X register char *s2; X int type; X`7B X while (*s1 && (*s2 `7C`7C type == PRO_BOOL)) `7B X if (*s1++ != *s2++) X return (false); X `7D X if ((!*s2 && *s1 && type == PRO_BOOL) `7C`7C (!*s1 && *s2)) return (false) V; X param_start = s1; X return (true); X`7D X X/* X * Set the defaults. X */ Xset_defaults() X`7B X register struct pro *p; X X /* X * Because ps.case_indent is a float, we can't initialize it from the tabl Ve: X */ X ps.case_indent = 1.0;`09`09/* -cli1.0 */ X ps.case_code_indent = 1.0;`09/* -cci1.0 */ X for (p = pro; p->p_name; p++) X if (p->p_type != PRO_SPECIAL && p->p_type != PRO_FONT) X *p->p_obj = p->p_default; X`7D X Xset_option(arg) X register char *arg; X`7B X register struct pro *p; X extern double atof(); X X arg++;`09`09`09/* ignore leading "-" */ X for (p = pro; p->p_name; p++) X if (*p->p_name == *arg && eqin(arg,p->p_name,p->p_type)) X goto found; X fprintf(stderr,"indent: %s: unknown parameter \"%s\"\n",option_source,arg V - 1); X exit(1); Xfound: X switch (p->p_type) `7B X X case PRO_SPECIAL: X switch (p->p_special) `7B X X case IGN: X break; X X case CCI: X if (*param_start == 0) X`09goto need_param; X ps.case_code_indent = atof(param_start); X break; X X case CLI: X if (*param_start == 0) X`09goto need_param; X ps.case_indent = atof(param_start); X break; X X case STDIN: X if (input == 0) X`09input = stdin; X if (output == 0) X`09output = stdout; X break; X X case KEY: X if (*param_start == 0) X`09goto need_param; X `7B X`09register char *str = (char *) malloc(strlen(param_start) + 1); X`09strcpy(str,param_start); X`09addkey(str,4); X `7D X break; X X default: X fprintf(stderr,"\ Xindent: set_option: internal error: p_special %d\n",p->p_special); X exit(1); X `7D X break; X X case PRO_BOOL: X if (p->p_special == OFF) X *p->p_obj = false; X else X *p->p_obj = true; X break; X X case PRO_INT: X if (!isdigit(*param_start)) `7B X need_param: X fprintf(stderr,"indent: %s: `60`60%s'' requires a parameter\n", X`09 option_source,arg - 1); X exit(1); X `7D X *p->p_obj = atoi(param_start); X break; X X case PRO_FONT: X parsefont((struct fstate *) p->p_obj,param_start); X break; X X default: X fprintf(stderr,"indent: set_option: internal error: p_type %d\n", X`09 p->p_type); X exit(1); X `7D X`7D $ CALL UNPACK ARGS.C;25 402684803 $ create 'f' X/* X * Copyright (c) 1985 Sun Microsystems, Inc. X * Copyright (c) 1980 The Regents of the University of California. X * Copyright (c) 1976 Board of Trustees of the University of Illinois. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that: (1) source distributions retain this entire copyright X * notice and comment, and (2) distributions including binaries display X * the following acknowledgement: `60`60This product includes software X * developed by the University of California, Berkeley and its contributors' V' X * in the documentation or other materials provided with the distribution X * and in all advertising materials mentioning features or use of this X * software. Neither the name of the University nor the names of its X * contributors may be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED `60`60AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. X */ X X#ifndef lint Xchar copyright`5B`5D = X"@(#) Copyright (c) 1985 Sun Microsystems, Inc.\n\ X @(#) Copyright (c) 1980 The Regents of the University of California.\n\ X @(#) Copyright (c) 1976 Board of Trustees of the University of Illinois.\n\ X All rights reserved.\n"; X#endif /* not lint */ X X#ifndef lint Xstatic char sccsid`5B`5D = "@(#)indent.c`095.15 (Berkeley) 6/1/90"; X#endif /* not lint */ X X#ifdef VMS X#define MAXPATHLEN 500 X#else X#include "sys/param.h" X#endif X#include "indent_globs.h" X#include "indent_codes.h" X#include X Xchar *in_name = 0;`09/* will always point to name of input file */ Xchar *out_name = 0;`09/* will always point to name of output file */ Xchar bakfile`5BMAXPATHLEN`5D = ""; X Xmain(argc, argv) X int argc; X char **argv; X`7B X X extern int found_err;`09/* flag set in diag() on error */ X int dec_ind;`09/* current indentation for declarations */ X int di_stack`5B20`5D;`09/* a stack of structure indentation leve Vls */ X int flushed_nl;`09/* used when buffering up comments to remember X`09`09`09`09 * that a newline was passed over */ X int force_nl;`09/* when true, code must be broken */ X int hd_type;`09/* used to store type of stmt for if (...), X`09`09`09`09 * for (...), etc */ X register int i;`09`09/* local loop counter */ X int scase;`09`09/* set to true when we see a case, so we will X`09`09`09`09 * know what to do with the following colon */ X int sp_sw;`09`09/* when true, we are in the expressin of X`09`09`09`09 * if(...), while(...), etc. */ X int squest;`09`09/* when this is positive, we have seen a ? X`09`09`09`09 * without the matching : in a ?: X`09`09`09`09 * construct */ X register char *t_ptr;`09/* used for copying tokens */ X int type_code;`09/* the type of token, returned by lexi */ X X int last_else = 0;`09/* true iff last keyword was an else */ X X X /*-----------------------------------------------*\ X `7C`09`09 INITIALIZATION`09`09 `7C X \*-----------------------------------------------*/ X X X ps.p_stack`5B0`5D = stmt;`09/* this is the parser's stack */ X ps.last_nl = true;`09`09/* this is true if the last thing scanned was X`09`09`09`09 * a newline */ X ps.last_token = semicolon; X combuf = (char *) malloc(bufsize); X labbuf = (char *) malloc(bufsize); X codebuf = (char *) malloc(bufsize); X tokenbuf = (char *) malloc(bufsize); X l_com = combuf + bufsize - 5; X l_lab = labbuf + bufsize - 5; X l_code = codebuf + bufsize - 5; X l_token = tokenbuf + bufsize - 5; X combuf`5B0`5D = codebuf`5B0`5D = labbuf`5B0`5D = ' ';`09/* set up code, V label, and X`09`09`09`09`09`09 * comment buffers */ X combuf`5B1`5D = codebuf`5B1`5D = labbuf`5B1`5D = '\0'; X ps.else_if = 1;`09`09/* Default else-if special processing to on */ X s_lab = e_lab = labbuf + 1; X s_code = e_code = codebuf + 1; X s_com = e_com = combuf + 1; X s_token = e_token = tokenbuf + 1; X X in_buffer = (char *) malloc(10); X in_buffer_limit = in_buffer + 8; X buf_ptr = buf_end = in_buffer; X line_no = 1; X had_eof = ps.in_decl = ps.decl_on_line = break_comma = false; X sp_sw = force_nl = false; X ps.in_or_st = false; X ps.bl_line = true; X dec_ind = 0; X di_stack`5Bps.dec_nest = 0`5D = 0; X ps.want_blank = ps.in_stmt = ps.ind_stmt = false; X X X scase = ps.pcase = false; X squest = 0; X sc_end = 0; X bp_save = 0; X be_save = 0; X X output = 0; X X X X /*--------------------------------------------------*\ X `7C `09`09COMMAND LINE SCAN`09`09 `7C X \*--------------------------------------------------*/ X X#ifdef undef X max_col = 132;`09`09/* -l132 */ X lineup_to_parens = 1;`09/* -lp */ X ps.ljust_decl = 0;`09`09/* -ndj */ X ps.com_ind = 33;`09`09/* -c33 */ X star_comment_cont = 1;`09/* -sc */ X ps.ind_size = 2;`09`09/* -i2 */ X verbose = 0; X ps.decl_indent = 16;`09/* -di16 */ X ps.indent_parameters = 1;`09/* -ip */ X ps.decl_com_ind = 0;`09/* if this is not set to some positive value X`09`09`09`09 * by an arg, we will set this equal to X`09`09`09`09 * ps.com_ind */ X btype_2 = 0;`09`09/* -br0 */ X cuddle_else = 1;`09`09/* -ce */ X ps.unindent_displace = 0;`09/* -d0 */ X ps.case_indent = 1;`09`09/* -cli1 */ X ps.case_code_indent = 1;`09/* -cci1 */ X format_col1_comments = 1;`09/* -fc1 */ X procnames_start_line = 1;`09/* -psl */ X proc_calls_space = 0;`09/* -npcs */ X comment_delimiter_on_blankline = 0;`09/* -cdb0 */ X ps.leave_comma = 1;`09`09/* -nbc */ X spaces_after_comma = 0;`09/* -nspc */ X#endif X X for (i = 1; i < argc; ++i) X`09if (strcmp(argv`5Bi`5D, "-npro") == 0) X`09 break; X set_defaults(); X if (i >= argc) X`09set_profile(); X X for (i = 1; i < argc; ++i) `7B X X`09/* X`09 * look thru args (if any) for changes to defaults X`09 */ X`09if (argv`5Bi`5D`5B0`5D != '-') `7B/* no flag on parameter */ X`09 if (input == 0) `7B`09/* we must have the input file */ X`09`09in_name = argv`5Bi`5D;`09/* remember name of input file */ X`09`09continue; X`09 `7D X`09 else if (output == 0) `7B`09/* we have the output file */ X`09`09out_name = argv`5Bi`5D;`09/* remember name of output file */ X`09`09output = fopen(out_name, "w"); X`09`09if (output == 0)`09/* check for create error */ X`09`09`09err(out_name); X`09`09continue; X`09 `7D X`09 fprintf(stderr, "indent: unknown parameter: %s\n", argv`5Bi`5D); X`09 exit(1); X`09`7D X`09else X`09 set_option(argv`5Bi`5D); X `7D`09`09`09`09/* end of for */ X if (input == 0) `7B X `09if (in_name) `7B X`09`09input = fopen(in_name, "r"); X`09`09if (input == 0 && strcmp(&in_name`5Bstrlen(in_name) - 2`5D, ".c")) `7B X`09`09 strcat(in_name, ".c"); X`09`09 input = fopen(in_name, "r"); X`09`09`7D X`09`09if (input == 0) X`09`09`09err(in_name); X`09`7D else `7B X`09`09fprintf(stderr, "indent: usage: indent file `5B outfile `5D `5B option Vs `5D\n"); X`09`09exit(1); X`09`7D X `7D X if (output == 0) X`09if (troff) X`09 output = stdout; X`09else `7B X`09 out_name = in_name; X for (i = 0; i < strlen(out_name); ++i) X `09 if (out_name`5Bi`5D == ';') X`09 `7B X`09 out_name`5Bi`5D = 0; X`09 break; X`09 `7D X`09 output = fopen(out_name, "w"); X`09 if (output == 0)`09/* check for create error */ X`09`09err(out_name); X`09`7D X if (ps.com_ind <= 1) X`09ps.com_ind = 2;`09`09/* dont put normal comments before column 2 */ X if (troff) `7B X`09if (bodyf.font`5B0`5D == 0) X`09 parsefont(&bodyf, "R"); X`09if (scomf.font`5B0`5D == 0) X`09 parsefont(&scomf, "I"); X`09if (blkcomf.font`5B0`5D == 0) X`09 blkcomf = scomf, blkcomf.size += 2; X`09if (boxcomf.font`5B0`5D == 0) X`09 boxcomf = blkcomf; X`09if (stringf.font`5B0`5D == 0) X`09 parsefont(&stringf, "L"); X`09if (keywordf.font`5B0`5D == 0) X`09 parsefont(&keywordf, "B"); X`09writefdef(&bodyf, 'B'); X`09writefdef(&scomf, 'C'); X`09writefdef(&blkcomf, 'L'); X`09writefdef(&boxcomf, 'X'); X`09writefdef(&stringf, 'S'); X`09writefdef(&keywordf, 'K'); X `7D X if (block_comment_max_col <= 0) X`09block_comment_max_col = max_col; X if (ps.decl_com_ind <= 0)`09/* if not specified by user, set this */ X`09ps.decl_com_ind = ps.ljust_decl ? (ps.com_ind <= 10 ? 2 : ps.com_ind - 8) V : ps.com_ind; X if (continuation_indent == 0) X`09continuation_indent = ps.ind_size; X fill_buffer();`09`09/* get first batch of stuff into input buffer */ X X parse(semicolon); X `7B X`09register char *p = buf_ptr; X`09register col = 1; X X`09while (1) `7B X`09 if (*p == ' ') X`09`09col++; X`09 else if (*p == '\t') X`09`09col = ((col - 1) & `7E7) + 9; X`09 else X`09`09break; X`09 p++; X`09`7D X`09if (col > ps.ind_size) X`09 ps.ind_level = ps.i_l_follow = col / ps.ind_size; X `7D X if (troff) `7B X`09register char *p = in_name, X`09 *beg = in_name; X X`09while (*p) X`09 if (*p++ == '/') X`09`09beg = p; X`09fprintf(output, ".Fn \"%s\"\n", beg); X `7D X /* X * START OF MAIN LOOP X */ X X while (1) `7B`09`09`09/* this is the main loop. it will go until we X`09`09`09`09 * reach eof */ X`09int is_procname; X X`09type_code = lexi();`09/* lexi reads one token. The actual X`09`09`09`09 * characters read are stored in "token". lexi X`09`09`09`09 * returns a code indicating the type of token */ X`09is_procname = ps.procname`5B0`5D; X X`09/* X`09 * The following code moves everything following an if (), while (), X`09 * else, etc. up to the start of the following stmt to a buffer. This X`09 * allows proper handling of both kinds of brace placement. X`09 */ X X`09flushed_nl = false; X`09while (ps.search_brace) `7B`09/* if we scanned an if(), while(), X`09`09`09`09`09 * etc., we might need to copy stuff X`09`09`09`09`09 * into a buffer we must loop, copying X`09`09`09`09`09 * stuff into save_com, until we find X`09`09`09`09`09 * the start of the stmt which follows X`09`09`09`09`09 * the if, or whatever */ X`09 switch (type_code) `7B X`09 case newline: X`09`09++line_no; X`09`09flushed_nl = true; X`09 case form_feed: X`09`09break;`09`09/* form feeds and newlines found here will be X`09`09`09`09 * ignored */ X X`09 case lbrace:`09/* this is a brace that starts the compound X`09`09`09`09 * stmt */ X`09`09if (sc_end == 0) `7B`09/* ignore buffering if a comment wasnt X`09`09`09`09`09 * stored up */ X`09`09 ps.search_brace = false; X`09`09 goto check_type; X`09`09`7D X`09`09if (btype_2) `7B X`09`09 save_com`5B0`5D = '`7B';`09/* we either want to put the brace X`09`09`09`09`09 * right after the if */ X`09`09 goto sw_buffer;`09/* go to common code to get out of X`09`09`09`09`09 * this loop */ X`09`09`7D X`09 case comment:`09/* we have a comment, so we must copy it into X`09`09`09`09 * the buffer */ X`09`09if (!flushed_nl `7C`7C sc_end != 0) `7B X`09`09 if (sc_end == 0) `7B`09/* if this is the first comment, we X`09`09`09`09`09 * must set up the buffer */ X`09`09`09save_com`5B0`5D = save_com`5B1`5D = ' '; X`09`09`09sc_end = &(save_com`5B2`5D); X`09`09 `7D X`09`09 else `7B X`09`09`09*sc_end++ = '\n';`09/* add newline between X`09`09`09`09`09`09 * comments */ X`09`09`09*sc_end++ = ' '; X`09`09`09--line_no; X`09`09 `7D X`09`09 *sc_end++ = '/';`09/* copy in start of comment */ X`09`09 *sc_end++ = '*'; X X`09`09 for (;;) `7B`09/* loop until we get to the end of the comment */ X`09`09`09*sc_end = *buf_ptr++; X`09`09`09if (buf_ptr >= buf_end) X`09`09`09 fill_buffer(); X X`09`09`09if (*sc_end++ == '*' && *buf_ptr == '/') X`09`09`09 break;`09/* we are at end of comment */ X X`09`09`09if (sc_end >= &(save_com`5Bsc_size`5D)) `7B`09/* check for temp buf Vfer X`09`09`09`09`09`09`09`09 * overflow */ X`09`09`09 diag(1, "Internal buffer overflow - Move big comment from right V after if, while, or whatever."); X`09`09`09 fflush(output); X`09`09`09 exit(1); X`09`09`09`7D X`09`09 `7D X`09`09 *sc_end++ = '/';`09/* add ending slash */ X`09`09 if (++buf_ptr >= buf_end)`09/* get past / in buffer */ X`09`09`09fill_buffer(); X`09`09 break; X`09`09`7D X`09 default:`09`09/* it is the start of a normal statment */ X`09`09if (flushed_nl)`09/* if we flushed a newline, make sure it is X`09`09`09`09 * put back */ X`09`09 force_nl = true; X`09`09if (type_code == sp_paren && *token == 'i' X`09`09`09&& last_else && ps.else_if X`09`09`09`7C`7C type_code == sp_nparen && *token == 'e' X`09`09`09&& e_code != s_code && e_code`5B-1`5D == '`7D') X`09`09 force_nl = false; X X`09`09if (sc_end == 0) `7B`09/* ignore buffering if comment wasnt X`09`09`09`09`09 * saved up */ X`09`09 ps.search_brace = false; X`09`09 goto check_type; X`09`09`7D X`09`09if (force_nl) `7B`09/* if we should insert a nl here, put it into X`09`09`09`09 * the buffer */ X`09`09 force_nl = false; X`09`09 --line_no;`09/* this will be re-increased when the nl is X`09`09`09`09 * read from the buffer */ X`09`09 *sc_end++ = '\n'; X`09`09 *sc_end++ = ' '; X`09`09 if (verbose && !flushed_nl)`09/* print error msg if the line X`09`09`09`09`09`09 * was not already broken */ X`09`09`09diag(0, "Line broken"); X`09`09 flushed_nl = false; X`09`09`7D X`09`09for (t_ptr = token; *t_ptr; ++t_ptr) X`09`09 *sc_end++ = *t_ptr;`09/* copy token into temp buffer */ X`09`09ps.procname`5B0`5D = 0; X X`09sw_buffer: X`09`09ps.search_brace = false;`09/* stop looking for start of X`09`09`09`09`09`09 * stmt */ X`09`09bp_save = buf_ptr;`09/* save current input buffer */ X`09`09be_save = buf_end; X`09`09buf_ptr = save_com;`09/* fix so that subsequent calls to X`09`09`09`09`09 * lexi will take tokens out of X`09`09`09`09`09 * save_com */ X`09`09*sc_end++ = ' ';/* add trailing blank, just in case */ X`09`09buf_end = sc_end; X`09`09sc_end = 0; X`09`09break; X`09 `7D`09`09`09/* end of switch */ X`09 if (type_code != 0)`09/* we must make this check, just in case there X`09`09`09`09 * was an unexpected EOF */ X`09`09type_code = lexi();`09/* read another token */ X`09 /* if (ps.search_brace) ps.procname`5B0`5D = 0; */ X`09 if ((is_procname = ps.procname`5B0`5D) && flushed_nl X`09`09 && !procnames_start_line && ps.in_decl X`09`09 && type_code == ident) X`09`09flushed_nl = 0; X`09`7D`09`09`09/* end of while (search_brace) */ X`09last_else = 0; Xcheck_type: X`09if (type_code == 0) `7B`09/* we got eof */ X`09 if (s_lab != e_lab `7C`7C s_code != e_code X`09`09 `7C`7C s_com != e_com)`09/* must dump end of line */ X`09`09dump_line(); X`09 if (ps.tos > 1)`09/* check for balanced braces */ X`09`09diag(1, "Stuff missing from end of file."); X X`09 if (verbose) `7B X`09`09printf("There were %d output lines and %d comments\n", X`09`09 ps.out_lines, ps.out_coms); X`09`09printf("(Lines with comments)/(Lines with code): %6.3f\n", X`09`09 (1.0 * ps.com_lines) / code_lines); X`09 `7D X`09 fflush(output); X`09 exit(found_err); X`09`7D X`09if ( X`09`09(type_code != comment) && X`09`09(type_code != newline) && X`09`09(type_code != preesc) && X`09`09(type_code != form_feed)) `7B X`09 if (force_nl && X`09`09 (type_code != semicolon) && X`09`09 (type_code != lbrace `7C`7C !btype_2)) `7B X`09`09/* we should force a broken line here */ X`09`09if (verbose && !flushed_nl) X`09`09 diag(0, "Line broken"); X`09`09flushed_nl = false; X`09`09dump_line(); X`09`09ps.want_blank = false;`09/* dont insert blank at line start */ X`09`09force_nl = false; X`09 `7D X`09 ps.in_stmt = true;`09/* turn on flag which causes an extra level of X`09`09`09`09 * indentation. this is turned off by a ; or X`09`09`09`09 * '`7D' */ X`09 if (s_com != e_com) `7B`09/* the turkey has embedded a comment X`09`09`09`09`09 * in a line. fix it */ X/*`09`09*e_code++ = ' '; */ X`09`09for (t_ptr = s_com; *t_ptr; ++t_ptr) `7B X`09`09 CHECK_SIZE_CODE; X`09`09 *e_code++ = *t_ptr; X`09`09`7D X/*`09`09*e_code++ = ' '; */ X`09`09*e_code = '\0';`09/* null terminate code sect */ X`09`09ps.want_blank = false; X`09`09e_com = s_com; X`09 `7D X`09`7D X`09else if (type_code != comment)`09/* preserve force_nl thru a comment */ X`09 force_nl = false;`09/* cancel forced newline after newline, form X`09`09`09`09 * feed, etc */ X X X X`09/*-----------------------------------------------------*\ X`09`7C`09 do switch on type of token scanned`09`09`7C X`09\*-----------------------------------------------------*/ X`09CHECK_SIZE_CODE; X`09switch (type_code) `7B`09/* now, decide what to do with the token */ X X`09case form_feed:`09/* found a form feed in line */ X`09 ps.use_ff = true;`09/* a form feed is treated much like a newline */ X`09 dump_line(); X`09 ps.want_blank = false; X`09 break; X X`09case newline: X`09 if (ps.last_token != comma `7C`7C ps.p_l_follow > 0 X`09`09 `7C`7C !ps.leave_comma `7C`7C ps.block_init `7C`7C !break_comma `7 VC`7C s_com != e_com) `7B X`09`09dump_line(); X`09`09ps.want_blank = false; X`09 `7D X`09 ++line_no;`09`09/* keep track of input line number */ X`09 break; X X`09case lparen:`09`09/* got a '(' or '`5B' */ X`09 ++ps.p_l_follow;`09/* count parens to make Healy happy */ X`09 if (ps.want_blank && *token != '`5B' && X`09`09 (ps.last_token != ident `7C`7C proc_calls_space X`09 `7C`7C (ps.its_a_keyword && (!ps.sizeof_keyword `7C`7C Bill_Shannon V)))) X`09`09*e_code++ = ' '; X`09 if (ps.in_decl && !ps.block_init) X`09`09if (troff && !ps.dumped_decl_indent && !is_procname && ps.last_token = V= decl) `7B X`09`09 ps.dumped_decl_indent = 1; X`09`09 sprintf(e_code, "\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token); X`09`09 e_code += strlen(e_code); X`09`09`7D X`09`09else `7B X`09`09 while ((e_code - s_code) < dec_ind) `7B X`09`09`09CHECK_SIZE_CODE; X`09`09`09*e_code++ = ' '; X`09`09 `7D X`09`09 *e_code++ = token`5B0`5D; X`09`09`7D X`09 else X`09`09*e_code++ = token`5B0`5D; X`09 ps.paren_indents`5Bps.p_l_follow - 1`5D = e_code - s_code; X`09 if (sp_sw && ps.p_l_follow == 1 && extra_expression_indent X`09`09 && ps.paren_indents`5B0`5D < 2 * ps.ind_size) X`09`09ps.paren_indents`5B0`5D = 2 * ps.ind_size; X`09 if (*token == '(') X`09 ps.want_blank = paren_space; X`09 else X`09 ps.want_blank = false; X`09 if (ps.in_or_st && *token == '(' && ps.tos <= 2) `7B X`09`09/* X`09`09 * this is a kluge to make sure that declarations will be X`09`09 * aligned right if proc decl has an explicit type on it, i.e. X`09`09 * "int a(x) `7B..." X`09`09 */ X`09`09parse(semicolon);`09/* I said this was a kluge... */ X`09`09ps.in_or_st = false;`09/* turn off flag for structure decl or X`09`09`09`09`09 * initialization */ X`09 `7D X`09 if (ps.sizeof_keyword) X`09`09ps.sizeof_mask `7C= 1 << ps.p_l_follow; X`09 break; X X`09case rparen:`09`09/* got a ')' or '`5D' */ X`09 rparen_count--; X`09 if (ps.cast_mask & (1 << ps.p_l_follow) & `7Eps.sizeof_mask) `7B X`09`09ps.last_u_d = true; X`09`09ps.cast_mask &= (1 << ps.p_l_follow) - 1; X`09 `7D X`09 ps.sizeof_mask &= (1 << ps.p_l_follow) - 1; X`09 if (--ps.p_l_follow < 0) `7B X`09`09ps.p_l_follow = 0; X`09`09diag(0, "Extra %c", *token); X`09 `7D X`09 if (e_code == s_code)`09/* if the paren starts the line */ X`09`09ps.paren_level = ps.p_l_follow;`09/* then indent it */ X X`09 if (*token == ')' && paren_space) *e_code++ = ' '; X`09 *e_code++ = token`5B0`5D; X`09 ps.want_blank = true; X X`09 if (sp_sw && (ps.p_l_follow == 0)) `7B`09/* check for end of if X`09`09`09`09`09`09`09 * (...), or some such */ X`09`09sp_sw = false; X`09`09force_nl = break_single_line;`09/* must force newline after if */ X`09`09ps.last_u_d = true;`09/* inform lexi that a following X`09`09`09`09`09 * operator is unary */ X`09`09ps.in_stmt = false;`09/* dont use stmt continuation X`09`09`09`09`09 * indentation */ X X`09`09parse(hd_type);`09/* let parser worry about if, or whatever */ X`09 `7D X`09 ps.search_brace = btype_2;`09/* this should insure that constructs X`09`09`09`09`09 * such as main()`7B...`7D and int`5B`5D`7B...`7D X`09`09`09`09`09 * have their braces put in the right X`09`09`09`09`09 * place */ X`09 break; X +-+-+-+-+-+-+-+- END OF PART 1 +-+-+-+-+-+-+-+-