Hello, this is a patch that Andres asked me for. It makes pg_bsd_indent leave preprocessor space alone, as in this example:
#if 0 # if 0 # if 0 # error # endif # endif #else # line 7 #endif
diff -ur pg_bsd_indent/args.c pg_bsd_indent_patched/args.c --- pg_bsd_indent/args.c 2014-01-31 04:09:31.000000000 +0100 +++ pg_bsd_indent_patched/args.c 2017-02-08 01:59:01.921080544 +0100 @@ -221,6 +221,9 @@ "lc", PRO_INT, 0, 0, &block_comment_max_col }, { + "lps", PRO_BOOL, false, ON, &leave_preprocessor_space + }, + { "lp", PRO_BOOL, true, ON, &lineup_to_parens }, { @@ -269,6 +272,9 @@ "nip", PRO_BOOL, true, OFF, &ps.indent_parameters }, { + "nlps", PRO_BOOL, false, OFF, &leave_preprocessor_space + }, + { "nlp", PRO_BOOL, true, OFF, &lineup_to_parens }, { diff -ur pg_bsd_indent/indent.c pg_bsd_indent_patched/indent.c --- pg_bsd_indent/indent.c 2014-01-31 04:06:43.000000000 +0100 +++ pg_bsd_indent_patched/indent.c 2017-02-08 01:56:59.039931984 +0100 @@ -1091,17 +1091,25 @@ (s_code != e_code)) dump_line(); *e_lab++ = '#'; /* move whole line to 'label' buffer */ + if (leave_preprocessor_space) { + while (isblank((int)*buf_ptr)) { + CHECK_SIZE_LAB; + *e_lab++ = *buf_ptr++; + } + } + else { + while (isblank((int)*buf_ptr)) { + buf_ptr++; + } + } + t_ptr = e_lab; + { int in_comment = 0; int com_start = 0; char quote = 0; int com_end = 0; - while (*buf_ptr == ' ' || *buf_ptr == '\t') { - buf_ptr++; - if (buf_ptr >= buf_end) - fill_buffer(); - } while (*buf_ptr != '\n' || in_comment) { CHECK_SIZE_LAB; *e_lab = *buf_ptr++; @@ -1179,7 +1187,7 @@ ps.pcase = false; } - if (strncmp(s_lab, "#if", 3) == 0) { + if (t_ptr[0] == 'i' && t_ptr[1] == 'f') { if (blanklines_around_conditional_compilation) { int c; prefix_blankline_requested++; @@ -1192,7 +1200,7 @@ } else diag(1, "#if stack overflow"); } else - if (strncmp(s_lab, "#else", 5) == 0) { + if (t_ptr[0] == 'e' && t_ptr[1] == 'l') { if (ifdef_level <= 0) diag(1, "Unmatched #else"); else { @@ -1200,7 +1208,7 @@ ps = state_stack[ifdef_level - 1]; } } else - if (strncmp(s_lab, "#endif", 6) == 0) { + if (strncmp(t_ptr, "endif", 5) == 0) { if (ifdef_level <= 0) diag(1, "Unmatched #endif"); else { diff -ur pg_bsd_indent/indent_globs.h pg_bsd_indent_patched/indent_globs.h --- pg_bsd_indent/indent_globs.h 2005-11-15 01:30:24.000000000 +0100 +++ pg_bsd_indent_patched/indent_globs.h 2017-02-08 01:57:51.003994806 +0100 @@ -222,6 +222,7 @@ * "for(e;e;e)" should be indented an extra * tab stop so that they don't conflict with * the code that follows */ +EXTERN int leave_preprocessor_space; /* -troff font state information */
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers