11 * If we are in a state of unbalanced quotes, and this line
12 * doesn't begin with a quote, output the stored error message.
13 * If the -p switch was used, print the warning even if the
14 * new para starts with quotes.
16 void print_pending(const char *aline,const char *parastart,
17 struct pending *pending)
20 while (g_unichar_isspace(g_utf8_get_char(aline)))
21 aline=g_utf8_next_char(aline);
22 if (pending->illustration.warning_text)
26 if (pswit[ECHO_SWITCH] && !pending->illustration.queried_line)
27 pending->illustration.queried_line=g_strdup(parastart);
31 if (!pswit[OVERVIEW_SWITCH])
33 if (pending->illustration.queried_line)
34 g_print("\n%s\n",pending->illustration.queried_line);
35 g_print("%s\n",pending->illustration.warning_text);
39 g_free(pending->illustration.warning_text);
40 pending->illustration.warning_text=NULL;
41 g_free(pending->illustration.queried_line);
42 pending->illustration.queried_line=NULL;
47 if (!pending->continuing_quote || !aline ||
48 !g_str_has_prefix(aline,pending->continuing_quote))
50 if (!pswit[OVERVIEW_SWITCH])
52 if (pswit[ECHO_SWITCH])
53 g_print("\n%s\n",parastart);
54 g_print("%s\n",pending->dquote);
59 g_free(pending->dquote);
64 if (!pending->continuing_quote ||
65 !g_str_has_prefix(aline,pending->continuing_quote))
67 if (!pswit[OVERVIEW_SWITCH])
69 if (pswit[ECHO_SWITCH])
70 g_print("\n%s\n",parastart);
71 g_print("%s\n",pending->squote);
76 g_free(pending->squote);
79 g_free(pending->continuing_quote);
80 pending->continuing_quote=NULL;
83 if (!pswit[OVERVIEW_SWITCH])
85 if (pswit[ECHO_SWITCH])
86 g_print("\n%s\n",parastart);
87 g_print("%s\n",pending->rbrack);
91 g_free(pending->rbrack);
96 if (!pswit[OVERVIEW_SWITCH])
98 if (pswit[ECHO_SWITCH])
99 g_print("\n%s\n",parastart);
100 g_print("%s\n",pending->sbrack);
104 g_free(pending->sbrack);
105 pending->sbrack=NULL;
109 if (!pswit[OVERVIEW_SWITCH])
111 if (pswit[ECHO_SWITCH])
112 g_print("\n%s\n",parastart);
113 g_print("%s\n",pending->cbrack);
117 g_free(pending->cbrack);
118 pending->cbrack=NULL;
122 if (!pswit[OVERVIEW_SWITCH])
124 if (pswit[ECHO_SWITCH])
125 g_print("\n%s\n",parastart);
126 g_print("%s\n",pending->unders);
130 g_free(pending->unders);
131 pending->unders=NULL;
135 void reset_pending(struct pending *pending)
137 memset(pending,0,sizeof(*pending));
141 * check_for_mismatched_quotes:
143 * At end of paragraph, check for mismatched quotes.
145 * We don't want to report an error immediately, since it is a
146 * common convention to omit the quotes at end of paragraph if
147 * the next paragraph is a continuation of the same speaker.
148 * Where this is the case, the next para should begin with a
149 * quote, so we store the warning message and only display it
150 * at the top of the next iteration if the new para doesn't
151 * start with a quote.
152 * The -p switch overrides this default, and warns of unclosed
153 * quotes on _every_ paragraph, whether the next begins with a
156 void check_for_mismatched_quotes(struct counters *counters,
157 struct pending *pending)
159 int quote_straight,quote_curved,difference;
160 quote_straight=matching_difference(counters,CHAR_DQUOTE);
161 quote_curved=matching_difference(counters,CHAR_LD_QUOTE);
162 if (quote_straight || quote_curved)
165 g_strdup_printf(" Line %ld - Mismatched quotes",linecnt);
166 if (pswit[QPARA_SWITCH] || quote_curved && quote_curved!=1 ||
167 quote_straight && quote_curved)
169 * Flag it to be noted regardless of the
170 * first line of the next para.
172 pending->continuing_quote=NULL;
173 else if (quote_straight)
174 pending->continuing_quote=utf8_strnfill(quote_straight,CHAR_DQUOTE);
176 pending->continuing_quote=utf8_strnfill(quote_curved,CHAR_LD_QUOTE);
178 if (pswit[SQUOTE_SWITCH])
180 if (matching_count(counters,CHAR_SQUOTE,TRUE))
181 quote_straight=matching_difference(counters,CHAR_SQUOTE);
184 if (matching_count(counters,CHAR_LS_QUOTE,TRUE))
185 quote_curved=matching_difference(counters,CHAR_LS_QUOTE);
188 if (quote_straight || quote_curved)
190 g_strdup_printf(" Line %ld - Mismatched singlequotes?",
192 if (pending->continuing_quote)
195 * Flag it to be noted regardless of the
196 * first line of the next para.
198 g_free(pending->continuing_quote);
199 pending->continuing_quote=NULL;
201 if (pswit[QPARA_SWITCH] || quote_straight && quote_straight!=1 ||
202 quote_curved && quote_curved!=1 || quote_straight && quote_curved)
203 pending->continuing_quote=NULL;
204 else if (quote_straight)
205 pending->continuing_quote=utf8_strnfill(quote_straight,CHAR_SQUOTE);
207 pending->continuing_quote=utf8_strnfill(quote_curved,CHAR_LS_QUOTE);
209 difference=matching_difference(counters,COUNTER_ILLUSTRATION);
212 if (difference<0 && pending->illustration.warning_text)
215 g_free(pending->illustration.queried_line);
216 pending->illustration.queried_line=NULL;
217 g_free(pending->illustration.warning_text);
218 pending->illustration.warning_text=NULL;
222 increment_matching(counters,CHAR_OPEN_SBRACK,FALSE);
227 if (pending->illustration.warning_text)
229 if (!pswit[OVERVIEW_SWITCH])
231 if (pending->illustration.queried_line)
232 g_print("\n%s\n",pending->illustration.queried_line);
233 g_print("%s\n",pending->illustration.warning_text);
237 g_free(pending->illustration.warning_text);
239 pending->illustration.warning_text=g_strdup_printf(
240 " Line %ld - Mismatched illustration tag?",linecnt);
241 g_free(pending->illustration.queried_line);
242 pending->illustration.queried_line=NULL;
245 if (matching_difference(counters,CHAR_OPEN_RBRACK))
247 g_strdup_printf(" Line %ld - Mismatched round brackets?",linecnt);
248 if (matching_difference(counters,CHAR_OPEN_SBRACK))
250 g_strdup_printf(" Line %ld - Mismatched square brackets?",linecnt);
251 if (matching_difference(counters,CHAR_OPEN_CBRACK))
253 g_strdup_printf(" Line %ld - Mismatched curly brackets?",linecnt);
254 if (counters->c_unders%2)
256 g_strdup_printf(" Line %ld - Mismatched underscores?",linecnt);