summaryrefslogtreecommitdiffstats
path: root/usr.bin/indent
diff options
context:
space:
mode:
authorschweikh <schweikh@FreeBSD.org>2004-06-27 10:58:37 +0000
committerschweikh <schweikh@FreeBSD.org>2004-06-27 10:58:37 +0000
commit3a2780ff6eeaaf86c011ff26a9fb82f995961037 (patch)
tree15721606f07f694a3600ef728b48d784f4474038 /usr.bin/indent
parent7c81a9a35ed13623ee05aad76ac46e938ed8e357 (diff)
downloadFreeBSD-src-3a2780ff6eeaaf86c011ff26a9fb82f995961037.zip
FreeBSD-src-3a2780ff6eeaaf86c011ff26a9fb82f995961037.tar.gz
Fix problems with non-8 space tabs. New options for function
declarations with the opening brace on the same line as the declaration of arguments all spaces and no tabs (a feature which exists in GNU's indent). Man page update to follow RSN. PR: bin/67983 Submitted by: Chip Norkus <wd@teleri.net> Style guidance and bug for bug compatibility by: bde MFC after: 2 weeks
Diffstat (limited to 'usr.bin/indent')
-rw-r--r--usr.bin/indent/args.c4
-rw-r--r--usr.bin/indent/indent.c38
-rw-r--r--usr.bin/indent/indent_globs.h6
-rw-r--r--usr.bin/indent/io.c12
4 files changed, 45 insertions, 15 deletions
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c
index 6f50948..eb93960 100644
--- a/usr.bin/indent/args.c
+++ b/usr.bin/indent/args.c
@@ -111,6 +111,7 @@ struct pro {
{"eei", PRO_BOOL, false, ON, &extra_expression_indent},
{"ei", PRO_BOOL, true, ON, &ps.else_if},
{"fbc", PRO_FONT, 0, 0, (int *) &blkcomf},
+ {"fbs", PRO_BOOL, true, ON, &function_brace_split},
{"fbx", PRO_FONT, 0, 0, (int *) &boxcomf},
{"fb", PRO_FONT, 0, 0, (int *) &bodyf},
{"fc1", PRO_BOOL, true, ON, &format_col1_comments},
@@ -136,6 +137,7 @@ struct pro {
{"ndj", PRO_BOOL, false, OFF, &ps.ljust_decl},
{"neei", PRO_BOOL, false, OFF, &extra_expression_indent},
{"nei", PRO_BOOL, true, OFF, &ps.else_if},
+ {"nfbs", PRO_BOOL, true, OFF, &function_brace_split},
{"nfc1", PRO_BOOL, true, OFF, &format_col1_comments},
{"nfcb", PRO_BOOL, true, OFF, &format_block_comments},
{"nip", PRO_BOOL, true, OFF, &ps.indent_parameters},
@@ -146,6 +148,7 @@ struct pro {
{"nps", PRO_BOOL, false, OFF, &pointer_as_binop},
{"nsc", PRO_BOOL, true, OFF, &star_comment_cont},
{"nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines},
+ {"nut", PRO_BOOL, true, OFF, &use_tabs},
{"nv", PRO_BOOL, false, OFF, &verbose},
{"pcs", PRO_BOOL, false, ON, &proc_calls_space},
{"psl", PRO_BOOL, true, ON, &procnames_start_line},
@@ -154,6 +157,7 @@ struct pro {
{"sob", PRO_BOOL, false, ON, &swallow_optional_blanklines},
{"st", PRO_SPECIAL, 0, STDIN, 0},
{"troff", PRO_BOOL, false, ON, &troff},
+ {"ut", PRO_BOOL, true, ON, &use_tabs},
{"v", PRO_BOOL, false, ON, &verbose},
/* whew! */
{0, 0, 0, 0, 0}
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index d75a521..f91043f 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -83,7 +83,7 @@ main(int argc, char **argv)
int force_nl; /* when true, code must be broken */
int hd_type = 0; /* used to store type of stmt for if (...),
* for (...), etc */
- int i; /* local loop counter */
+ int i; /* local loop counter */
int scase; /* set to true when we see a case, so we will
* know what to do with the following colon */
int sp_sw; /* when true, we are in the expression of
@@ -91,8 +91,8 @@ main(int argc, char **argv)
int squest; /* when this is positive, we have seen a ?
* without the matching : in a <c>?<s>:<s>
* construct */
- int use_tabs; /* true if using tabs to indent to var name */
const char *t_ptr; /* used for copying tokens */
+ int tabs_to_var; /* true if using tabs to indent to var name */
int type_code; /* the type of token, returned by lexi */
int last_else = 0; /* true iff last keyword was an else */
@@ -765,8 +765,12 @@ check_type:
}
else if (ps.in_parameter_declaration && !ps.in_or_st) {
ps.i_l_follow = 0;
- dump_line();
- ps.want_blank = false;
+ if (function_brace_split) { /* dump the line prior to the
+ * brace ... */
+ dump_line();
+ ps.want_blank = false;
+ } else /* add a space between the decl and brace */
+ ps.want_blank = true;
}
}
if (ps.in_parameter_declaration)
@@ -914,11 +918,11 @@ check_type:
if (ps.ind_level == 0 || ps.dec_nest > 0) {
/* global variable or struct member in local variable */
dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
- use_tabs = ps.decl_indent > 0;
+ tabs_to_var = (use_tabs ? ps.decl_indent > 0 : 0);
} else {
/* local variable */
dec_ind = ps.local_decl_indent > 0 ? ps.local_decl_indent : i;
- use_tabs = ps.local_decl_indent > 0;
+ tabs_to_var = (use_tabs ? ps.local_decl_indent > 0 : 0);
}
goto copy_id;
@@ -935,18 +939,34 @@ check_type:
ps.dumped_decl_indent = 1;
e_code += strlen(e_code);
} else {
+ int cur_dec_ind;
int pos, startpos;
+ /*
+ * in order to get the tab math right for
+ * indentations that are not multiples of 8 we
+ * need to modify both startpos and dec_ind
+ * (cur_dec_ind) here by eight minus the
+ * remainder of the current starting column
+ * divided by eight. This seems to be a
+ * properly working fix
+ */
startpos = e_code - s_code;
+ cur_dec_ind = dec_ind;
pos = startpos;
- if (use_tabs) {
- while ((pos & ~7) + 8 <= dec_ind) {
+ if ((ps.ind_level * ps.ind_size) % 8 != 0) {
+ pos += (ps.ind_level * ps.ind_size) % 8;
+ cur_dec_ind += (ps.ind_level * ps.ind_size) % 8;
+ }
+
+ if (tabs_to_var) {
+ while ((pos & ~7) + 8 <= cur_dec_ind) {
CHECK_SIZE_CODE;
*e_code++ = '\t';
pos = (pos & ~7) + 8;
}
}
- while (pos < dec_ind) {
+ while (pos < cur_dec_ind) {
CHECK_SIZE_CODE;
*e_code++ = ' ';
pos++;
diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h
index d35900e..010b3a3 100644
--- a/usr.bin/indent/indent_globs.h
+++ b/usr.bin/indent/indent_globs.h
@@ -193,12 +193,16 @@ int blanklines_after_declarations_at_proctop; /* This is vaguely
* if there are no
* declarations */
int block_comment_max_col;
-int extra_expression_indent; /* True if continuation lines from the
+int extra_expression_indent; /* true if continuation lines from the
* expression part of "if(e)",
* "while(e)", "for(e;e;e)" should be
* indented an extra tab stop so that
* they don't conflict with the code
* that follows */
+int function_brace_split; /* split function declaration and
+ * brace onto separate lines */
+int use_tabs; /* set true to use tabs for spacing,
+ * false uses all spaces */
/* -troff font state information */
diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c
index 3a2eaf4..45eb6c2 100644
--- a/usr.bin/indent/io.c
+++ b/usr.bin/indent/io.c
@@ -472,11 +472,13 @@ pad_output(int current, int target)
if (current >= target)
return (current); /* line is already long enough */
curr = current;
- while ((tcur = ((curr - 1) & tabmask) + tabsize + 1) <= target) {
- putc('\t', output);
- curr = tcur;
- }
- while (curr++ < target)
+ if (use_tabs) {
+ while ((tcur = ((curr - 1) & tabmask) + tabsize + 1) <= target) {
+ putc('\t', output);
+ curr = tcur;
+ }
+ }
+ while (curr++ < target)
putc(' ', output); /* pad with final blanks */
}
return (target);
OpenPOWER on IntegriCloud