|
ali@103
|
1 |
#include <stdlib.h>
|
|
ali@103
|
2 |
#include <string.h>
|
|
ali@103
|
3 |
#include <glib.h>
|
|
ali@111
|
4 |
#include <bl/bl.h>
|
|
ali@103
|
5 |
#include "bookloupe.h"
|
|
ali@103
|
6 |
#include "pending.h"
|
|
ali@103
|
7 |
|
|
ali@103
|
8 |
/*
|
|
ali@103
|
9 |
* print_pending:
|
|
ali@103
|
10 |
*
|
|
ali@103
|
11 |
* If we are in a state of unbalanced quotes, and this line
|
|
ali@103
|
12 |
* doesn't begin with a quote, output the stored error message.
|
|
ali@103
|
13 |
* If the -p switch was used, print the warning even if the
|
|
ali@103
|
14 |
* new para starts with quotes.
|
|
ali@103
|
15 |
*/
|
|
ali@103
|
16 |
void print_pending(const char *aline,const char *parastart,
|
|
ali@103
|
17 |
struct pending *pending)
|
|
ali@103
|
18 |
{
|
|
ali@103
|
19 |
if (aline)
|
|
ali@111
|
20 |
while (g_unichar_isspace(g_utf8_get_char(aline)))
|
|
ali@111
|
21 |
aline=g_utf8_next_char(aline);
|
|
ali@103
|
22 |
if (pending->illustration.warning_text)
|
|
ali@103
|
23 |
{
|
|
ali@103
|
24 |
if (aline)
|
|
ali@103
|
25 |
{
|
|
ali@103
|
26 |
if (pswit[ECHO_SWITCH] && !pending->illustration.queried_line)
|
|
ali@103
|
27 |
pending->illustration.queried_line=g_strdup(parastart);
|
|
ali@103
|
28 |
}
|
|
ali@103
|
29 |
else
|
|
ali@103
|
30 |
{
|
|
ali@103
|
31 |
if (!pswit[OVERVIEW_SWITCH])
|
|
ali@103
|
32 |
{
|
|
ali@103
|
33 |
if (pending->illustration.queried_line)
|
|
ali@103
|
34 |
g_print("\n%s\n",pending->illustration.queried_line);
|
|
ali@103
|
35 |
g_print("%s\n",pending->illustration.warning_text);
|
|
ali@103
|
36 |
}
|
|
ali@103
|
37 |
else
|
|
ali@103
|
38 |
cnt_brack++;
|
|
ali@103
|
39 |
g_free(pending->illustration.warning_text);
|
|
ali@103
|
40 |
pending->illustration.warning_text=NULL;
|
|
ali@103
|
41 |
g_free(pending->illustration.queried_line);
|
|
ali@103
|
42 |
pending->illustration.queried_line=NULL;
|
|
ali@103
|
43 |
}
|
|
ali@103
|
44 |
}
|
|
ali@103
|
45 |
if (pending->dquote)
|
|
ali@103
|
46 |
{
|
|
ali@111
|
47 |
if (!pending->continuing_quote || !aline ||
|
|
ali@111
|
48 |
!g_str_has_prefix(aline,pending->continuing_quote))
|
|
ali@103
|
49 |
{
|
|
ali@103
|
50 |
if (!pswit[OVERVIEW_SWITCH])
|
|
ali@103
|
51 |
{
|
|
ali@103
|
52 |
if (pswit[ECHO_SWITCH])
|
|
ali@103
|
53 |
g_print("\n%s\n",parastart);
|
|
ali@103
|
54 |
g_print("%s\n",pending->dquote);
|
|
ali@103
|
55 |
}
|
|
ali@103
|
56 |
else
|
|
ali@103
|
57 |
cnt_dquot++;
|
|
ali@103
|
58 |
}
|
|
ali@103
|
59 |
g_free(pending->dquote);
|
|
ali@103
|
60 |
pending->dquote=NULL;
|
|
ali@103
|
61 |
}
|
|
ali@103
|
62 |
if (pending->squote)
|
|
ali@103
|
63 |
{
|
|
ali@111
|
64 |
if (!pending->continuing_quote ||
|
|
ali@111
|
65 |
!g_str_has_prefix(aline,pending->continuing_quote))
|
|
ali@103
|
66 |
{
|
|
ali@103
|
67 |
if (!pswit[OVERVIEW_SWITCH])
|
|
ali@103
|
68 |
{
|
|
ali@103
|
69 |
if (pswit[ECHO_SWITCH])
|
|
ali@103
|
70 |
g_print("\n%s\n",parastart);
|
|
ali@103
|
71 |
g_print("%s\n",pending->squote);
|
|
ali@103
|
72 |
}
|
|
ali@103
|
73 |
else
|
|
ali@103
|
74 |
cnt_squot++;
|
|
ali@103
|
75 |
}
|
|
ali@103
|
76 |
g_free(pending->squote);
|
|
ali@103
|
77 |
pending->squote=NULL;
|
|
ali@103
|
78 |
}
|
|
ali@111
|
79 |
g_free(pending->continuing_quote);
|
|
ali@111
|
80 |
pending->continuing_quote=NULL;
|
|
ali@103
|
81 |
if (pending->rbrack)
|
|
ali@103
|
82 |
{
|
|
ali@103
|
83 |
if (!pswit[OVERVIEW_SWITCH])
|
|
ali@103
|
84 |
{
|
|
ali@103
|
85 |
if (pswit[ECHO_SWITCH])
|
|
ali@103
|
86 |
g_print("\n%s\n",parastart);
|
|
ali@103
|
87 |
g_print("%s\n",pending->rbrack);
|
|
ali@103
|
88 |
}
|
|
ali@103
|
89 |
else
|
|
ali@103
|
90 |
cnt_brack++;
|
|
ali@103
|
91 |
g_free(pending->rbrack);
|
|
ali@103
|
92 |
pending->rbrack=NULL;
|
|
ali@103
|
93 |
}
|
|
ali@103
|
94 |
if (pending->sbrack)
|
|
ali@103
|
95 |
{
|
|
ali@103
|
96 |
if (!pswit[OVERVIEW_SWITCH])
|
|
ali@103
|
97 |
{
|
|
ali@103
|
98 |
if (pswit[ECHO_SWITCH])
|
|
ali@103
|
99 |
g_print("\n%s\n",parastart);
|
|
ali@103
|
100 |
g_print("%s\n",pending->sbrack);
|
|
ali@103
|
101 |
}
|
|
ali@103
|
102 |
else
|
|
ali@103
|
103 |
cnt_brack++;
|
|
ali@103
|
104 |
g_free(pending->sbrack);
|
|
ali@103
|
105 |
pending->sbrack=NULL;
|
|
ali@103
|
106 |
}
|
|
ali@103
|
107 |
if (pending->cbrack)
|
|
ali@103
|
108 |
{
|
|
ali@103
|
109 |
if (!pswit[OVERVIEW_SWITCH])
|
|
ali@103
|
110 |
{
|
|
ali@103
|
111 |
if (pswit[ECHO_SWITCH])
|
|
ali@103
|
112 |
g_print("\n%s\n",parastart);
|
|
ali@103
|
113 |
g_print("%s\n",pending->cbrack);
|
|
ali@103
|
114 |
}
|
|
ali@103
|
115 |
else
|
|
ali@103
|
116 |
cnt_brack++;
|
|
ali@103
|
117 |
g_free(pending->cbrack);
|
|
ali@103
|
118 |
pending->cbrack=NULL;
|
|
ali@103
|
119 |
}
|
|
ali@103
|
120 |
if (pending->unders)
|
|
ali@103
|
121 |
{
|
|
ali@103
|
122 |
if (!pswit[OVERVIEW_SWITCH])
|
|
ali@103
|
123 |
{
|
|
ali@103
|
124 |
if (pswit[ECHO_SWITCH])
|
|
ali@103
|
125 |
g_print("\n%s\n",parastart);
|
|
ali@103
|
126 |
g_print("%s\n",pending->unders);
|
|
ali@103
|
127 |
}
|
|
ali@103
|
128 |
else
|
|
ali@103
|
129 |
cnt_brack++;
|
|
ali@103
|
130 |
g_free(pending->unders);
|
|
ali@103
|
131 |
pending->unders=NULL;
|
|
ali@103
|
132 |
}
|
|
ali@103
|
133 |
}
|
|
ali@103
|
134 |
|
|
ali@103
|
135 |
void reset_pending(struct pending *pending)
|
|
ali@103
|
136 |
{
|
|
ali@103
|
137 |
memset(pending,0,sizeof(*pending));
|
|
ali@103
|
138 |
}
|
|
ali@103
|
139 |
|
|
ali@103
|
140 |
/*
|
|
ali@103
|
141 |
* check_for_mismatched_quotes:
|
|
ali@103
|
142 |
*
|
|
ali@103
|
143 |
* At end of paragraph, check for mismatched quotes.
|
|
ali@103
|
144 |
*
|
|
ali@103
|
145 |
* We don't want to report an error immediately, since it is a
|
|
ali@103
|
146 |
* common convention to omit the quotes at end of paragraph if
|
|
ali@103
|
147 |
* the next paragraph is a continuation of the same speaker.
|
|
ali@103
|
148 |
* Where this is the case, the next para should begin with a
|
|
ali@103
|
149 |
* quote, so we store the warning message and only display it
|
|
ali@103
|
150 |
* at the top of the next iteration if the new para doesn't
|
|
ali@103
|
151 |
* start with a quote.
|
|
ali@103
|
152 |
* The -p switch overrides this default, and warns of unclosed
|
|
ali@103
|
153 |
* quotes on _every_ paragraph, whether the next begins with a
|
|
ali@103
|
154 |
* quote or not.
|
|
ali@103
|
155 |
*/
|
|
ali@111
|
156 |
void check_for_mismatched_quotes(struct counters *counters,
|
|
ali@103
|
157 |
struct pending *pending)
|
|
ali@103
|
158 |
{
|
|
ali@111
|
159 |
int quote_straight,quote_curved,difference;
|
|
ali@111
|
160 |
quote_straight=matching_difference(counters,CHAR_DQUOTE);
|
|
ali@111
|
161 |
quote_curved=matching_difference(counters,CHAR_LD_QUOTE);
|
|
ali@111
|
162 |
if (quote_straight || quote_curved)
|
|
ali@111
|
163 |
{
|
|
ali@103
|
164 |
pending->dquote=
|
|
ali@103
|
165 |
g_strdup_printf(" Line %ld - Mismatched quotes",linecnt);
|
|
ali@111
|
166 |
if (pswit[QPARA_SWITCH] || quote_curved && quote_curved!=1 ||
|
|
ali@111
|
167 |
quote_straight && quote_curved)
|
|
ali@111
|
168 |
/*
|
|
ali@111
|
169 |
* Flag it to be noted regardless of the
|
|
ali@111
|
170 |
* first line of the next para.
|
|
ali@111
|
171 |
*/
|
|
ali@111
|
172 |
pending->continuing_quote=NULL;
|
|
ali@111
|
173 |
else if (quote_straight)
|
|
ali@111
|
174 |
pending->continuing_quote=utf8_strnfill(quote_straight,CHAR_DQUOTE);
|
|
ali@111
|
175 |
else
|
|
ali@111
|
176 |
pending->continuing_quote=utf8_strnfill(quote_curved,CHAR_LD_QUOTE);
|
|
ali@111
|
177 |
}
|
|
ali@103
|
178 |
if (pswit[SQUOTE_SWITCH])
|
|
ali@103
|
179 |
{
|
|
ali@103
|
180 |
if (matching_count(counters,CHAR_SQUOTE,TRUE))
|
|
ali@111
|
181 |
quote_straight=matching_difference(counters,CHAR_SQUOTE);
|
|
ali@103
|
182 |
else
|
|
ali@111
|
183 |
quote_straight=0;
|
|
ali@103
|
184 |
if (matching_count(counters,CHAR_LS_QUOTE,TRUE))
|
|
ali@111
|
185 |
quote_curved=matching_difference(counters,CHAR_LS_QUOTE);
|
|
ali@103
|
186 |
else
|
|
ali@111
|
187 |
quote_curved=0;
|
|
ali@111
|
188 |
if (quote_straight || quote_curved)
|
|
ali@103
|
189 |
pending->squote=
|
|
ali@103
|
190 |
g_strdup_printf(" Line %ld - Mismatched singlequotes?",
|
|
ali@103
|
191 |
linecnt);
|
|
ali@111
|
192 |
if (pending->continuing_quote)
|
|
ali@111
|
193 |
{
|
|
ali@103
|
194 |
/*
|
|
ali@103
|
195 |
* Flag it to be noted regardless of the
|
|
ali@111
|
196 |
* first line of the next para.
|
|
ali@103
|
197 |
*/
|
|
ali@111
|
198 |
g_free(pending->continuing_quote);
|
|
ali@111
|
199 |
pending->continuing_quote=NULL;
|
|
ali@111
|
200 |
}
|
|
ali@111
|
201 |
if (pswit[QPARA_SWITCH] || quote_straight && quote_straight!=1 ||
|
|
ali@111
|
202 |
quote_curved && quote_curved!=1 || quote_straight && quote_curved)
|
|
ali@111
|
203 |
pending->continuing_quote=NULL;
|
|
ali@111
|
204 |
else if (quote_straight)
|
|
ali@111
|
205 |
pending->continuing_quote=utf8_strnfill(quote_straight,CHAR_SQUOTE);
|
|
ali@111
|
206 |
else
|
|
ali@111
|
207 |
pending->continuing_quote=utf8_strnfill(quote_curved,CHAR_LS_QUOTE);
|
|
ali@103
|
208 |
}
|
|
ali@103
|
209 |
difference=matching_difference(counters,COUNTER_ILLUSTRATION);
|
|
ali@103
|
210 |
if (difference)
|
|
ali@103
|
211 |
{
|
|
ali@103
|
212 |
if (difference<0 && pending->illustration.warning_text)
|
|
ali@103
|
213 |
{
|
|
ali@103
|
214 |
difference++;
|
|
ali@103
|
215 |
g_free(pending->illustration.queried_line);
|
|
ali@103
|
216 |
pending->illustration.queried_line=NULL;
|
|
ali@103
|
217 |
g_free(pending->illustration.warning_text);
|
|
ali@103
|
218 |
pending->illustration.warning_text=NULL;
|
|
ali@103
|
219 |
}
|
|
ali@103
|
220 |
if (difference<0)
|
|
ali@103
|
221 |
{
|
|
ali@103
|
222 |
increment_matching(counters,CHAR_OPEN_SBRACK,FALSE);
|
|
ali@103
|
223 |
difference++;
|
|
ali@103
|
224 |
}
|
|
ali@103
|
225 |
if (difference)
|
|
ali@103
|
226 |
{
|
|
ali@103
|
227 |
if (pending->illustration.warning_text)
|
|
ali@103
|
228 |
{
|
|
ali@103
|
229 |
if (!pswit[OVERVIEW_SWITCH])
|
|
ali@103
|
230 |
{
|
|
ali@103
|
231 |
if (pending->illustration.queried_line)
|
|
ali@103
|
232 |
g_print("\n%s\n",pending->illustration.queried_line);
|
|
ali@103
|
233 |
g_print("%s\n",pending->illustration.warning_text);
|
|
ali@103
|
234 |
}
|
|
ali@103
|
235 |
else
|
|
ali@103
|
236 |
cnt_brack++;
|
|
ali@103
|
237 |
g_free(pending->illustration.warning_text);
|
|
ali@103
|
238 |
}
|
|
ali@103
|
239 |
pending->illustration.warning_text=g_strdup_printf(
|
|
ali@103
|
240 |
" Line %ld - Mismatched illustration tag?",linecnt);
|
|
ali@103
|
241 |
g_free(pending->illustration.queried_line);
|
|
ali@103
|
242 |
pending->illustration.queried_line=NULL;
|
|
ali@103
|
243 |
}
|
|
ali@103
|
244 |
}
|
|
ali@103
|
245 |
if (matching_difference(counters,CHAR_OPEN_RBRACK))
|
|
ali@103
|
246 |
pending->rbrack=
|
|
ali@103
|
247 |
g_strdup_printf(" Line %ld - Mismatched round brackets?",linecnt);
|
|
ali@103
|
248 |
if (matching_difference(counters,CHAR_OPEN_SBRACK))
|
|
ali@103
|
249 |
pending->sbrack=
|
|
ali@103
|
250 |
g_strdup_printf(" Line %ld - Mismatched square brackets?",linecnt);
|
|
ali@103
|
251 |
if (matching_difference(counters,CHAR_OPEN_CBRACK))
|
|
ali@103
|
252 |
pending->cbrack=
|
|
ali@103
|
253 |
g_strdup_printf(" Line %ld - Mismatched curly brackets?",linecnt);
|
|
ali@103
|
254 |
if (counters->c_unders%2)
|
|
ali@103
|
255 |
pending->unders=
|
|
ali@103
|
256 |
g_strdup_printf(" Line %ld - Mismatched underscores?",linecnt);
|
|
ali@103
|
257 |
}
|