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->quote);
59 g_free(pending->quote);
62 g_free(pending->continuing_quote);
63 pending->continuing_quote=NULL;
66 if (!pswit[OVERVIEW_SWITCH])
68 if (pswit[ECHO_SWITCH])
69 g_print("\n%s\n",parastart);
70 g_print("%s\n",pending->rbrack);
74 g_free(pending->rbrack);
79 if (!pswit[OVERVIEW_SWITCH])
81 if (pswit[ECHO_SWITCH])
82 g_print("\n%s\n",parastart);
83 g_print("%s\n",pending->sbrack);
87 g_free(pending->sbrack);
92 if (!pswit[OVERVIEW_SWITCH])
94 if (pswit[ECHO_SWITCH])
95 g_print("\n%s\n",parastart);
96 g_print("%s\n",pending->cbrack);
100 g_free(pending->cbrack);
101 pending->cbrack=NULL;
105 if (!pswit[OVERVIEW_SWITCH])
107 if (pswit[ECHO_SWITCH])
108 g_print("\n%s\n",parastart);
109 g_print("%s\n",pending->unders);
113 g_free(pending->unders);
114 pending->unders=NULL;
118 void reset_pending(struct pending *pending)
120 memset(pending,0,sizeof(*pending));
124 * check_for_mismatched_quotes:
126 * At end of paragraph, check for mismatched quotes.
128 * We don't want to report an error immediately, since it is a
129 * common convention to omit the quotes at end of paragraph if
130 * the next paragraph is a continuation of the same speaker.
131 * Where this is the case, the next para should begin with a
132 * quote, so we store the warning message and only display it
133 * at the top of the next iteration if the new para doesn't
134 * start with a quote.
135 * The -p switch overrides this default, and warns of unclosed
136 * quotes on _every_ paragraph, whether the next begins with a
139 void check_for_mismatched_quotes(struct counters *counters,
140 struct pending *pending)
145 const char *quote_type;
147 if (counters->open_quotes)
149 str=g_string_new(NULL);
150 counters->open_quotes=g_slist_reverse(counters->open_quotes);
152 while(counters->open_quotes)
154 c=GPOINTER_TO_INT(counters->open_quotes->data);
155 if (!CHAR_IS_SQUOTE(c))
157 g_string_append_unichar(str,c);
158 counters->open_quotes=g_slist_delete_link(counters->open_quotes,
159 counters->open_quotes);
161 pending->continuing_quote=g_string_free(str,FALSE);
163 quote_type="singlequotes?";
166 pending->quote=g_strdup_printf(" Line %ld - Mismatched %s",linecnt,
169 difference=matching_difference(counters,COUNTER_ILLUSTRATION);
172 if (difference<0 && pending->illustration.warning_text)
175 g_free(pending->illustration.queried_line);
176 pending->illustration.queried_line=NULL;
177 g_free(pending->illustration.warning_text);
178 pending->illustration.warning_text=NULL;
182 increment_matching(counters,CHAR_OPEN_SBRACK,FALSE);
187 if (pending->illustration.warning_text)
189 if (!pswit[OVERVIEW_SWITCH])
191 if (pending->illustration.queried_line)
192 g_print("\n%s\n",pending->illustration.queried_line);
193 g_print("%s\n",pending->illustration.warning_text);
197 g_free(pending->illustration.warning_text);
199 pending->illustration.warning_text=g_strdup_printf(
200 " Line %ld - Mismatched illustration tag?",linecnt);
201 g_free(pending->illustration.queried_line);
202 pending->illustration.queried_line=NULL;
205 if (matching_difference(counters,CHAR_OPEN_RBRACK))
207 g_strdup_printf(" Line %ld - Mismatched round brackets?",linecnt);
208 if (matching_difference(counters,CHAR_OPEN_SBRACK))
210 g_strdup_printf(" Line %ld - Mismatched square brackets?",linecnt);
211 if (matching_difference(counters,CHAR_OPEN_CBRACK))
213 g_strdup_printf(" Line %ld - Mismatched curly brackets?",linecnt);
214 if (counters->c_unders%2)
216 g_strdup_printf(" Line %ld - Mismatched underscores?",linecnt);