| 1063 | `--------------------------------------------------------------------*/ |
| 1064 | |
| 1065 | static void |
| 1066 | fix_output_parameters (void) |
| 1067 | { |
| 1068 | /* In auto reference mode, the maximum width of this field is |
| 1069 | precomputed and subtracted from the overall line width. Add one for |
| 1070 | the column which separate the file name from the line number. */ |
| 1071 | |
| 1072 | if (auto_reference) |
| 1073 | { |
| 1074 | reference_max_width = 0; |
| 1075 | for (int file_index = 0; file_index < number_input_files; file_index++) |
| 1076 | { |
| 1077 | intmax_t line_ordinal = file_line_count[file_index] + 1; |
| 1078 | if (file_index > 0) |
| 1079 | line_ordinal -= file_line_count[file_index - 1]; |
| 1080 | char ordinal_string[INT_BUFSIZE_BOUND (intmax_t)]; |
| 1081 | idx_t reference_width = sprintf (ordinal_string, "%jd", line_ordinal); |
| 1082 | if (input_file_name[file_index]) |
| 1083 | reference_width += strlen (input_file_name[file_index]); |
| 1084 | if (reference_width > reference_max_width) |
| 1085 | reference_max_width = reference_width; |
| 1086 | } |
| 1087 | reference_max_width++; |
| 1088 | reference.start = xmalloc (reference_max_width + 1); |
| 1089 | } |
| 1090 | |
| 1091 | /* If the reference appears to the left of the output line, reserve some |
| 1092 | space for it right away, including one gap size. */ |
| 1093 | |
| 1094 | if ((auto_reference || input_reference) && !right_reference) |
| 1095 | line_width = MAX (0, line_width - (reference_max_width + gap_size)); |
| 1096 | |
| 1097 | /* The output lines, minimally, will contain from left to right a left |
| 1098 | context, a gap, and a keyword followed by the right context with no |
| 1099 | special intervening gap. Half of the line width is dedicated to the |
| 1100 | left context and the gap, the other half is dedicated to the keyword |
| 1101 | and the right context; these values are computed once and for all here. |
| 1102 | There also are tail and head wrap around fields, used when the keyword |
| 1103 | is near the beginning or the end of the line, or when some long word |
| 1104 | cannot fit in, but leave place from wrapped around shorter words. The |
| 1105 | maximum width of these fields are recomputed separately for each line, |
| 1106 | on a case by case basis. It is worth noting that it cannot happen that |
| 1107 | both the tail and head fields are used at once. */ |
| 1108 | |
| 1109 | half_line_width = line_width >> 1; |
| 1110 | before_max_width = half_line_width - gap_size; |
| 1111 | keyafter_max_width = half_line_width; |
| 1112 | |
| 1113 | /* If truncation_string is the empty string, make it null to speed up |
| 1114 | tests. In this case, truncation_string_length will never get used, so |
| 1115 | there is no need to set it. */ |
| 1116 | |
| 1117 | if (truncation_string && *truncation_string) |
| 1118 | truncation_string_length = strlen (truncation_string); |
| 1119 | else |
| 1120 | truncation_string = NULL; |
| 1121 | |
| 1122 | if (gnu_extensions) |