Definition at line 66 of file indent.c.
67{
68 int dec_ind;
69 int di_stack[20];
70 int force_nl;
71 int hd_type = 0;
72
74 int scase;
75
76 int sp_sw;
77
78 int squest;
79
80
81 const char *t_ptr;
82 int tabs_to_var;
83 int type_code;
84
85 int last_else = 0;
86 const char *profile_name = NULL;
88
89
90
91
92
93
95
98
118
125
133 sp_sw = force_nl = false;
136 dec_ind = 0;
139
141 squest = 0;
145
147 tabs_to_var = 0;
148
149
150
151
152
153#ifdef undef
164
165
168
169
180#endif
181
182 for (
i = 1;
i < argc; ++
i)
183 if (strcmp(argv[
i],
"-npro") == 0)
184 break;
185 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'P' && argv[
i][2] !=
'\0')
186 profile_name = argv[
i];
190
191 for (
i = 1;
i < argc; ++
i) {
192
193
194
195
196 if (argv[
i][0] !=
'-') {
202 continue;
203 }
204 else if (
output == NULL) {
207
208 errx(1,
"input and output files must be different");
209 }
213 continue;
214 }
215 errx(1,
"unknown parameter: %s", argv[
i]);
216 }
217 else
219 }
225 else {
228 }
229 }
230
242
244 {
246 int col = 1;
247
248 while (1) {
249 if (*p == ' ')
250 col++;
251 else if (*p == '\t')
253 else
254 break;
255 p++;
256 }
259 }
260
261
262
263
264
265 while (1) {
266
267 int comment_buffered = false;
268
270
271
272
273
274
275
276
277
278
279
281 switch (type_code) {
287 }
289
290
291
292
293
294
295
296
297
298 force_nl = false;
300 break;
303
304
305
306
307
312 }
313 comment_buffered = true;
316 for (;;) {
321 break;
323
324 diag2(1,
"Internal buffer overflow - Move big comment from right after if, while, or whatever");
327 }
328 }
332 break;
334
335
336
337
338
341
342
343
344
345
346
347 while (isspace((
unsigned char)*
buf_ptr)) {
351 break;
352 }
353 goto sw_buffer;
354 }
355
356 default:
357 {
358 int remove_newlines;
359
360 remove_newlines =
361
364
367 if (remove_newlines)
368 force_nl = false;
370
372 goto check_type;
373 }
376 }
378 (!comment_buffered && remove_newlines)) {
379 force_nl = !remove_newlines;
382 }
383 }
384 if (force_nl) {
385
386 force_nl = false;
388
392
393 diag2(0,
"Line broken");
394 }
395 for (t_ptr =
token; *t_ptr; ++t_ptr)
397
398 sw_buffer:
400
404
405
409 break;
410 }
411 }
412
413
414
415
416 if (type_code != 0) {
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
440 errx(1,
"input too long");
441 }
442 }
445 }
446 }
447 transient_state =
ps;
448 type_code =
lexi(&transient_state);
450 type_code !=
comment && !transient_state.search_brace) {
451 ps = transient_state;
452 }
453 }
454 }
455 last_else = 0;
456check_type:
457 if (type_code == 0) {
462 diag2(1,
"Stuff missing from end of file");
463
465 printf(
"There were %d output lines and %d comments\n",
467 printf(
"(Lines with comments)/(Lines with code): %6.3f\n",
469 }
472 }
473 if (
478 if (force_nl &&
481
483 diag2(0,
"Line broken");
486 force_nl = false;
487 }
489
490
492
494
503 }
504 }
506 force_nl = false;
507
508
509
510
511
512
513
515
516
517
518 switch (type_code) {
519
524 break;
525
531 }
533 break;
534
536
538 diag3(0,
"Reached internal limit of %d unclosed parens",
541 }
543 ;
546
549 }
552
553
554
564
565
566
567
568
571
572 }
573
574
575
576
577
581 break;
582
588 } else
594 }
597
599
601
602 sp_sw = false;
603 force_nl = true;
605
607
608
610 }
612
613
614
615 break;
616
620
621
622
623
624
625
627 ;
630 }
633
634 {
636
640 }
642 break;
643
645 {
647
653 }
655 break;
656
661 break;
662
664 squest++;
665
666
671 break;
672
674 scase = true;
675 goto copy_id;
676
678 if (squest > 0) {
679 --squest;
684 break;
685 }
689 break;
690 }
692
693
694
695
696 {
698
705 }
707
708
709
710
711 scase = false;
713 break;
714
718
719 scase = false;
720 squest = 0;
728
731
734 }
735
737
738
739
741
742
743
744
745
746
747 diag2(1,
"Unbalanced parens");
749 if (sp_sw) {
750
751 sp_sw = false;
753 }
754 }
758
759
760 if (!sp_sw) {
762 force_nl = true;
763 }
764 break;
765
769 force_nl = true;
770
773 else
775
780 }
784
787 } else
789 }
790 }
793
795
796 diag2(1,
"Unbalanced parens");
798 if (sp_sw) {
799 sp_sw = false;
802 }
803 }
806
808
811 diag3(0,
"Reached internal limit of %d struct levels",
814 }
815
816 }
817 else {
819
820
821
827 }
828 dec_ind = 0;
831
836 break;
837
840
841
844 diag2(1,
"Unbalanced parens");
846 sp_sw = false;
847 }
851
853 diag2(0,
"Line broken");
855 }
860
865 }
872 break;
873
875 sp_sw = true;
877
878 goto copy_id;
879
881 sp_sw = true;
882
885
886
887
888
889 goto copy_id;
890
896 diag2(0,
"Line broken");
899 }
900 force_nl = true;
901 last_else = 1;
903 }
904 else {
907 diag2(0,
"Line broken");
910 }
911 force_nl = true;
912 last_else = 0;
914 }
915 goto copy_id;
916
920 goto copy_id;
921
924 goto copy_id;
925
932 }
933 }
937 }
939
945
947
950 } else {
951
954 }
955 goto copy_id;
956
965 }
968 }
970 }
973
977 }
978 }
980 sp_sw = false;
981 force_nl = true;
985 }
986 copy_id:
987 {
989
995 }
998 break;
999
1001 {
1003
1009 }
1011 break;
1012
1014
1017 break;
1018
1021
1022
1025
1028 }
1036 force_nl = true;
1037 }
1038 break;
1039
1047 {
1048 int in_comment = 0;
1049 int com_start = 0;
1050 char quote = 0;
1051 int com_end = 0;
1052
1057 }
1065 if (!in_comment) {
1069 }
1070 break;
1071 case '/':
1072 if (*
buf_ptr ==
'*' && !in_comment && !quote) {
1073 in_comment = 1;
1076 }
1077 break;
1078 case '"':
1079 if (quote == '"')
1080 quote = 0;
1081 break;
1082 case '\'':
1083 if (quote == '\'')
1084 quote = 0;
1085 break;
1086 case '*':
1087 if (*
buf_ptr ==
'/' && in_comment) {
1088 in_comment = 0;
1091 }
1092 break;
1093 }
1094 }
1095
1099
1101
1104 }
1105 else {
1107
1110 }
1112 errx(1,
"input too long");
1113 memmove(
sc_end,
s_lab + com_start, com_end - com_start);
1114 sc_end += com_end - com_start;
1121
1122
1126 }
1130 }
1131
1132 if (strncmp(
s_lab,
"#if", 3) == 0) {
1136 }
1137 else
1138 diag2(1,
"#if stack overflow");
1139 }
1140 else if (strncmp(
s_lab,
"#el", 3) == 0) {
1142 diag2(1,
s_lab[3] ==
'i' ?
"Unmatched #elif" :
"Unmatched #else");
1143 else {
1146 }
1147 }
1148 else if (strncmp(
s_lab,
"#endif", 6) == 0) {
1150 diag2(1,
"Unmatched #endif");
1151 else
1153 } else {
1154 struct directives {
1157 }
1158 recognized[] = {
1159 {7, "include"},
1160 {6, "define"},
1161 {5, "undef"},
1162 {4, "line"},
1163 {5, "error"},
1164 {6, "pragma"}
1165 };
1166 int d =
nitems(recognized);
1167 while (--d >= 0)
1168 if (strncmp(
s_lab + 1, recognized[d].
string, recognized[d].
size) == 0)
1169 break;
1170 if (d < 0) {
1171 diag2(1,
"Unrecognized cpp directive");
1172 break;
1173 }
1174 }
1178 }
1179 else {
1182 }
1183 break;
1184
1185
1188 break;
1189 }
1190
1194 }
1195}
void set_profile(const char *profile_name)
void errx(int eval, const char *fmt,...)
static void bakcopy(void)
static void indent_declaration(int cur_dec_ind, int tabs_to_var)
int compute_code_target(void)
int lexi(struct parser_state *)
void diag2(int, const char *)
void diag3(int, const char *, int)
int count_spaces_until(int, char *, char *)
void alloc_typenames(void)
int block_comment_max_col
int blanklines_after_procs
int postfix_blankline_requested
struct parser_state state_stack[5]
int prefix_blankline_requested
int extra_expression_indent
int format_block_comments
int comment_delimiter_on_blankline
#define CHECK_SIZE_LAB(desired_size)
struct parser_state match_state[5]
int blanklines_around_conditional_compilation
int swallow_optional_blanklines
int lineup_to_parens_always
int blanklines_after_declarations_at_proctop
if(TABLE==NULL||TABLE_index==NULL)
static void const char fflush(stdout)
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
static pg_noinline void Size size
int in_parameter_declaration
References alloc_typenames(), BACKSLASH, bakcopy(), be_save, Bill_Shannon, binary_op, parser_state::bl_line, blanklines_after_declarations_at_proctop, blanklines_after_procs, blanklines_around_conditional_compilation, block_comment_max_col, parser_state::block_init, parser_state::block_init_level, bp_save, break_comma, btype_2, buf_end, buf_ptr, bufsize, parser_state::case_indent, casestmt, parser_state::cast_mask, CHECK_SIZE_CODE, CHECK_SIZE_LAB, code_lines, codebuf, colon, parser_state::com_ind, parser_state::com_lines, combuf, comma, comment, comment_delimiter_on_blankline, compute_code_target(), continuation_indent, count_spaces_until(), cuddle_else, parser_state::dec_nest, decl, parser_state::decl_com_ind, parser_state::decl_indent, parser_state::decl_on_line, diag2(), diag3(), dolit, dump_line(), parser_state::dumped_decl_indent, e_code, e_com, e_lab, e_token, parser_state::else_if, elselit, err(), errx(), exit(), extra_expression_indent, fflush(), fill_buffer(), form_feed, format_block_comments, format_col1_comments, forstmt, found_err, funcname, function_brace_split, had_eof, i, parser_state::i_l_follow, ident, if(), ifdef_level, ifhead, ifstmt, parser_state::il, in_buffer, in_buffer_limit, parser_state::in_decl, in_name, parser_state::in_or_st, parser_state::in_parameter_declaration, parser_state::in_stmt, parser_state::ind_level, parser_state::ind_size, parser_state::ind_stmt, indent_declaration(), parser_state::indent_parameters, input, parser_state::just_saw_decl, parser_state::keyword, l_code, l_com, l_lab, l_token, labbuf, parser_state::last_nl, parser_state::last_token, parser_state::last_u_d, lbrace, parser_state::leave_comma, len, lexi(), line_no, lineup_to_parens, lineup_to_parens_always, parser_state::ljust_decl, parser_state::local_decl_indent, lparen, malloc, match_state, max_col, n_real_blanklines, newline, nitems, parser_state::not_cast_mask, parser_state::out_coms, parser_state::out_lines, out_name, output, parser_state::p_l_follow, parser_state::p_stack, parser_state::paren_indents, parser_state::paren_level, parse(), parser_state::pcase, period, postfix_blankline_requested, postop, pr_comment(), preesc, prefix_blankline_requested, printf, proc_calls_space, parser_state::procname, procnames_start_line, ps, question, rbrace, rparen, s_code, s_com, s_lab, s_token, save_com, sc_buf, sc_end, sc_size, parser_state::search_brace, semicolon, set_defaults(), set_option, set_profile(), size, sp_nparen, sp_paren, space_after_cast, star_comment_cont, state_stack, generate_unaccent_rules::stdout, stmt, storage, strpfx, structure, swallow_optional_blanklines, swstmt, tabsize, token, tokenbuf, parser_state::tos, type_def, unary_op, parser_state::unindent_displace, parser_state::use_ff, use_tabs, verbose, parser_state::want_blank, and whilestmt.