Date: Sun, 24 Sep 2000 17:10:48 -0700 From: "David O'Brien" <obrien@freebsd.org> To: Blaz Zupan <blaz@amis.net> Cc: freebsd-current@freebsd.org Subject: Re: .indent.pro for KNF? Message-ID: <20000924171048.A18141@dragon.nuxi.com> In-Reply-To: <Pine.BSF.4.21.0009242019310.48724-100000@titanic.medinet.si>; from blaz@amis.net on Sun, Sep 24, 2000 at 08:24:44PM %2B0200 References: <Pine.BSF.4.21.0009242019310.48724-100000@titanic.medinet.si>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Sep 24, 2000 at 08:24:44PM +0200, Blaz Zupan wrote: > Does anybody have a .indent.pro file for indent(1) that enforces KNF style as > specified in style(9)? From Bruce Evans, this is " a wrapper around indent(1) to print the percentage changes that indent with the best (least bad) approximation to KNF parameters that I know of would do." --- #!/bin/sh TMP=`mktemp /tmp/_knfom.XXXXXX` TMPBAK=`mktemp /tmp/_knfom.XXXXXX` trap 'rm -f $TMP $TMPBAK; exit 1' 1 2 3 13 15 trap 'rm -f $TMP $TMPBAK' 0 for i do cp "$i" $TMP # XXX the typedef list hasn't been updated since 1993, except for the last # two entries. indent -npro \ -TBitSetTmp \ -TDBM \ -TDIR \ -TFix16_peh \ -TFix24_peh \ -TFix32_peh \ -TFix48_peh \ -TFix_peh \ -TGPT \ -TIntTmp \ -TLLattrib \ -TLLtoken \ -TPix \ -TProtoHook \ -TRatTmp \ -TSGTTY \ -TSeqNum \ -TStrTmp \ -TXCHAR \ -T_Fix \ -T__sFILE \ -T__sighandler_4_3_t \ -T__sighandler_t \ -T_code \ -T_dirdesc \ -T_ftsent \ -T_physadr \ -T_quad \ -T_uquad \ -T_vsIoAddr \ -T_vsStats \ -T_vs_box \ -T_vs_cursor \ -T_vs_event \ -Tbitstr_t \ -Tboolean_t \ -Tcaddr_t \ -Tcbool \ -Tcc_t \ -Tclock_t \ -Tclockframe \ -Tcomp_t \ -Tcomplex \ -Tdaddr_t \ -Tdb \ -Tdb_addr_t \ -Tdb_expr_t \ -Tdb_regs_t \ -Tdes_block \ -Tdev_pager_t \ -Tdev_t \ -Tfd_mask \ -Tfd_set \ -Tfhandle_t \ -Tfixpt_t \ -Tfpos_t \ -Tfsid_t \ -Tgid_t \ -Tino_t \ -Tint16 \ -Tint32 \ -Tjmp_buf \ -Tkey_t \ -Tlabel_t \ -Tllinsert \ -Tlock_data_t \ -Tlock_t \ -Tmode_t \ -Tn_long \ -Tn_short \ -Tn_time \ -Tnetobj \ -Tnew_handler_t \ -Tnfstype \ -Tnfsv2fh_t \ -Tnlink_t \ -Toff_t \ -Tone_arg_error_handler_t \ -Tpd_entry_t \ -Tpid_t \ -Tpmap_statistics_t \ -Tpmap_t \ -Tpt_entry_t \ -Tptrdiff_t \ -Tpv_entry \ -Tqaddr_t \ -Tqhdr \ -Tqueue_chain_t \ -Tqueue_entry_t \ -Tqueue_head_t \ -Tqueue_t \ -Tregexp \ -Tsegsz_t \ -TRefNum \ -Tsig_t \ -Tsigjmp_buf \ -Tsigset_t \ -Tsimple_lock_data_t \ -Tsimple_lock_t \ -Tsize_t \ -Tspeed_t \ -Tssize_t \ -Tsw_blk_t \ -Tsw_bm_t \ -Tsw_pager_t \ -Tswblk_t \ -Ttcflag_t \ -Ttcp_seq \ -Ttime_t \ -Ttimeout_func_t \ -Ttpr_t \ -Ttwo_arg_error_handler_t \ -Tu_char \ -Tu_int \ -Tu_int32 \ -Tu_long \ -Tu_short \ -Tuid_t \ -Tuint16 \ -Tuint32 \ -Tushort \ -Tva_list \ -Tvm_inherit_t \ -Tvm_map_entry_t \ -Tvm_map_object_t \ -Tvm_map_t \ -Tvm_object_hash_entry_t \ -Tvm_object_t \ -Tvm_offset_t \ -Tvm_page_t \ -Tvm_pager_t \ -Tvm_prot_t \ -Tvm_size_t \ -Tvm_statistics_data_t \ -Tvm_statistics_t \ -Tvn_pager_t \ -TvsIoAddrAddr \ -Twchar_t \ -Txdrproc_t \ -Tsy_call_t \ -Tvop_t \ -bad -bap -nbbb -nbc -br -nbs -c33 -cd33 -cdb -ce -ci4 -cli0 -d0 -di0 -ndj \ -ei -nfc1 -nfcb -i8 -ip -l79 -lc77 -nlp -npcs -psl -sc -nsob -nv \ $TMP $TMPBAK (wc -l "$i" | tr '\012' ' '; diff $TMPBAK $TMP | grep -cv '^[1-9]') | awk '{printf("%7.3f%% %s\n", 100 - 100 * $3 / 2 / ($1 + .1), $2)}' done --- -di0 is wrong for global declarations but right for local declarations. indent -di8 would get the tabs for global declarations wrong anyway. -nfcb is an extension to prevent formatting of big comments - otherwise there is too much comment reformatting compared with code reformatting (there still is). These diffs implement -[n]fcb and attempt to implement no-space=after-sizeof (not optional) and no-space-after 'struct foo *' (not optional). Without these, indent unKNFizes even more perfectly KNF code. The most serious bugs in indent are that it doesn't understand ANSI function headers, and -lp doesn't actually work. I think these are both fixed in gnu indent. diff -c2 args.c~ args.c *** args.c~ Sun Aug 29 11:15:27 1999 --- args.c Sun Aug 29 11:15:32 1999 *************** *** 111,114 **** --- 111,115 ---- "fb", PRO_FONT, 0, 0, (int *) &bodyf, "fc1", PRO_BOOL, true, ON, &format_col1_comments, + "fcb", PRO_BOOL, true, ON, &format_block_comments, "fc", PRO_FONT, 0, 0, (int *) &scomf, "fk", PRO_FONT, 0, 0, (int *) &keywordf, *************** *** 132,135 **** --- 133,137 ---- "nei", PRO_BOOL, true, OFF, &ps.else_if, "nfc1", PRO_BOOL, true, OFF, &format_col1_comments, + "nfcb", PRO_BOOL, true, OFF, &format_block_comments, "nip", PRO_BOOL, true, OFF, &ps.indent_parameters, "nlp", PRO_BOOL, true, OFF, &lineup_to_parens, diff -c2 indent.1~ indent.1 *** indent.1~ Sun Aug 29 11:45:30 1999 --- indent.1 Sun Aug 29 11:46:03 1999 *************** *** 64,67 **** --- 64,68 ---- .Bk -words .Op Fl fc1 | Fl nfc1 + .Op Fl fcb | Fl nfcb .Ek .Op Fl i Ns Ar n *************** *** 249,252 **** --- 250,262 ---- used. The default is .Fl fc1 . + .It Fl fcb , nfcb + Enables (disables) the formatting of block comments (ones that begin + with `/*\\n'). Often, block comments have been not so carefully hand + formatted by the programmer, but reformatting that would just change + the line breaks is not wanted. In such cases, + .Fl nfcb + should be used. Block comments are then handled like box comments. + The default is + .Fl fcb . .It Fl i Ns Ar n The number of spaces for one indentation level. The default is 8. diff -c2 indent.c~ indent.c *** indent.c~ Sun Aug 29 11:15:27 1999 --- indent.c Sun Aug 29 11:15:32 1999 *************** *** 166,169 **** --- 166,170 ---- ps.unindent_displace = 0; /* -d0 */ ps.case_indent = 0; /* -cli0 */ + format_block_comments = 1; /* -fcb */ format_col1_comments = 1; /* -fc1 */ procnames_start_line = 1; /* -psl */ *************** *** 534,538 **** ps.last_u_d = true; ps.cast_mask &= (1 << ps.p_l_follow) - 1; ! } ps.sizeof_mask &= (1 << ps.p_l_follow) - 1; if (--ps.p_l_follow < 0) { --- 535,541 ---- ps.last_u_d = true; ps.cast_mask &= (1 << ps.p_l_follow) - 1; ! ps.want_blank = false; ! } else ! ps.want_blank = true; ps.sizeof_mask &= (1 << ps.p_l_follow) - 1; if (--ps.p_l_follow < 0) { *************** *** 544,548 **** *e_code++ = token[0]; - ps.want_blank = true; if (sp_sw && (ps.p_l_follow == 0)) { /* check for end of if --- 547,550 ---- diff -c2 indent_globs.h~ indent_globs.h *** indent_globs.h~ Wed Sep 8 17:15:09 1999 --- indent_globs.h Wed Sep 8 17:15:11 1999 *************** *** 156,159 **** --- 156,161 ---- int proc_calls_space; /* If true, procedure calls look like: * foo(bar) rather than foo (bar) */ + int format_block_comments; /* true if comments beginning with + * `/*\n' are to be reformatted */ int format_col1_comments; /* If comments which start in column 1 * are to be magically reformatted diff -c2 lexi.c~ lexi.c *** lexi.c~ Sun Aug 29 11:15:27 1999 --- lexi.c Sun Aug 29 11:15:32 1999 *************** *** 59,63 **** }; ! struct templ specials[100] = { "switch", 1, --- 59,63 ---- }; ! struct templ specials[1000] = { "switch", 1, *************** *** 89,92 **** --- 89,94 ---- "do", 6, "sizeof", 7, + "const", 9, + "volatile", 9, 0, 0 }; *************** *** 258,273 **** case 3: /* a "struct" */ ! if (ps.p_l_follow) ! break; /* inside parens: cast */ l_struct = true; /* ! * Next time around, we will want to know that we have had a ! * 'struct' */ case 4: /* one of the declaration keywords */ if (ps.p_l_follow) { ps.cast_mask |= 1 << ps.p_l_follow; ! break; /* inside parens: cast */ } last_code = decl; --- 260,284 ---- case 3: /* a "struct" */ ! /* ! * Next time around, we may want to know that we have had a ! * 'struct' ! */ l_struct = true; /* ! * Fall through to test for a cast, function prototype or ! * sizeof(). */ case 4: /* one of the declaration keywords */ if (ps.p_l_follow) { ps.cast_mask |= 1 << ps.p_l_follow; ! ! /* ! * Forget that we saw `struct' if we're in a sizeof(). ! */ ! if (ps.sizeof_mask) ! l_struct = false; ! ! break; /* inside parens: cast, prototype or sizeof() */ } last_code = decl; diff -c2 pr_comment.c~ pr_comment.c *** pr_comment.c~ Sun Aug 29 11:15:27 1999 --- pr_comment.c Sun Aug 29 11:15:32 1999 *************** *** 112,119 **** } else { ! if (*buf_ptr == '-' || *buf_ptr == '*') { ! ps.box_com = true; /* a comment with a '-' or '*' immediately * after the /* is assumed to be a boxed ! * comment */ break_delim = 0; } --- 112,124 ---- } else { ! if (*buf_ptr == '-' || *buf_ptr == '*' || ! (*buf_ptr == '\n' && !format_block_comments)) { ! ps.box_com = true; /* A comment with a '-' or '*' immediately * after the /* is assumed to be a boxed ! * comment. A comment with a newline ! * immediately after the /* is assumed to ! * be a block comment and is treated as a ! * box comment unless format_block_comments ! * is nonzero (the default). */ break_delim = 0; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000924171048.A18141>