diff -r 7a62c77a0dbe -r 9fb13a5dde3b bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Sat Sep 21 23:40:18 2013 +0100 +++ b/bookloupe/bookloupe.c Mon Sep 23 21:18:27 2013 +0100 @@ -29,6 +29,7 @@ #include #include "bookloupe.h" #include "counters.h" +#include "pending.h" #include "HTMLentities.h" gchar *prevline; @@ -867,10 +868,26 @@ isemptyline=FALSE; /* ignore lines like * * * as spacers */ if (c==CHAR_UNDERSCORE) counters->c_unders++; - if (c==CHAR_OPEN_CBRACK || c==CHAR_OPEN_RBRACK || c==CHAR_OPEN_SBRACK) + if (c==CHAR_OPEN_SBRACK) + { + if (!matching_difference(counters,COUNTER_ILLUSTRATION) && + !matching_difference(counters,c) && s==aline && + g_str_has_prefix(s,"[Illustration:")) + increment_matching(counters,COUNTER_ILLUSTRATION,TRUE); + else + increment_matching(counters,c,TRUE); + } + else if (c==CHAR_OPEN_CBRACK || c==CHAR_OPEN_RBRACK) increment_matching(counters,c,TRUE); - if (c==CHAR_CLOSE_CBRACK || c==CHAR_CLOSE_RBRACK || - c==CHAR_CLOSE_SBRACK) + if (c==CHAR_CLOSE_SBRACK) + { + if (!matching_count(counters,COUNTER_ILLUSTRATION,FALSE) && + !matching_difference(counters,c) && !*snext) + increment_matching(counters,COUNTER_ILLUSTRATION,FALSE); + else + increment_matching(counters,c,FALSE); + } + else if (c==CHAR_CLOSE_CBRACK || c==CHAR_CLOSE_RBRACK) increment_matching(counters,c,FALSE); sprev=s; s=snext; @@ -2363,168 +2380,6 @@ } /* - * print_pending: - * - * If we are in a state of unbalanced quotes, and this line - * doesn't begin with a quote, output the stored error message. - * If the -P switch was used, print the warning even if the - * new para starts with quotes. - */ -void print_pending(const char *aline,const char *parastart, - struct pending *pending) -{ - const char *s; - gunichar c; - s=aline; - while (*s==' ') - s++; - c=g_utf8_get_char(s); - if (pending->dquote) - { - if (c!=CHAR_DQUOTE || pswit[QPARA_SWITCH]) - { - if (!pswit[OVERVIEW_SWITCH]) - { - if (pswit[ECHO_SWITCH]) - g_print("\n%s\n",parastart); - g_print("%s\n",pending->dquote); - } - else - cnt_dquot++; - } - g_free(pending->dquote); - pending->dquote=NULL; - } - if (pending->squote) - { - if (!CHAR_IS_SQUOTE(c) || pswit[QPARA_SWITCH] || pending->squot) - { - if (!pswit[OVERVIEW_SWITCH]) - { - if (pswit[ECHO_SWITCH]) - g_print("\n%s\n",parastart); - g_print("%s\n",pending->squote); - } - else - cnt_squot++; - } - g_free(pending->squote); - pending->squote=NULL; - } - if (pending->rbrack) - { - if (!pswit[OVERVIEW_SWITCH]) - { - if (pswit[ECHO_SWITCH]) - g_print("\n%s\n",parastart); - g_print("%s\n",pending->rbrack); - } - else - cnt_brack++; - g_free(pending->rbrack); - pending->rbrack=NULL; - } - if (pending->sbrack) - { - if (!pswit[OVERVIEW_SWITCH]) - { - if (pswit[ECHO_SWITCH]) - g_print("\n%s\n",parastart); - g_print("%s\n",pending->sbrack); - } - else - cnt_brack++; - g_free(pending->sbrack); - pending->sbrack=NULL; - } - if (pending->cbrack) - { - if (!pswit[OVERVIEW_SWITCH]) - { - if (pswit[ECHO_SWITCH]) - g_print("\n%s\n",parastart); - g_print("%s\n",pending->cbrack); - } - else - cnt_brack++; - g_free(pending->cbrack); - pending->cbrack=NULL; - } - if (pending->unders) - { - if (!pswit[OVERVIEW_SWITCH]) - { - if (pswit[ECHO_SWITCH]) - g_print("\n%s\n",parastart); - g_print("%s\n",pending->unders); - } - else - cnt_brack++; - g_free(pending->unders); - pending->unders=NULL; - } -} - -/* - * check_for_mismatched_quotes: - * - * At end of paragraph, check for mismatched quotes. - * - * We don't want to report an error immediately, since it is a - * common convention to omit the quotes at end of paragraph if - * the next paragraph is a continuation of the same speaker. - * Where this is the case, the next para should begin with a - * quote, so we store the warning message and only display it - * at the top of the next iteration if the new para doesn't - * start with a quote. - * The -p switch overrides this default, and warns of unclosed - * quotes on _every_ paragraph, whether the next begins with a - * quote or not. - */ -void check_for_mismatched_quotes(const struct counters *counters, - struct pending *pending) -{ - int squote_straight,squote_curved; - if (counters->quot%2) - pending->dquote= - g_strdup_printf(" Line %ld - Mismatched quotes",linecnt); - if (pswit[SQUOTE_SWITCH]) - { - if (matching_count(counters,CHAR_SQUOTE,TRUE)) - squote_straight=matching_difference(counters,CHAR_SQUOTE); - else - squote_straight=0; - if (matching_count(counters,CHAR_LS_QUOTE,TRUE)) - squote_curved=matching_difference(counters,CHAR_LS_QUOTE); - else - squote_curved=0; - if (squote_straight || squote_curved) - pending->squote= - g_strdup_printf(" Line %ld - Mismatched singlequotes?", - linecnt); - if (squote_straight && squote_straight!=1 || - squote_curved && squote_curved!=1) - /* - * Flag it to be noted regardless of the - * first char of the next para. - */ - pending->squot=1; - } - if (matching_difference(counters,CHAR_OPEN_RBRACK)) - pending->rbrack= - g_strdup_printf(" Line %ld - Mismatched round brackets?",linecnt); - if (matching_difference(counters,CHAR_OPEN_SBRACK)) - pending->sbrack= - g_strdup_printf(" Line %ld - Mismatched square brackets?",linecnt); - if (matching_difference(counters,CHAR_OPEN_CBRACK)) - pending->cbrack= - g_strdup_printf(" Line %ld - Mismatched curly brackets?",linecnt); - if (counters->c_unders%2) - pending->unders= - g_strdup_printf(" Line %ld - Mismatched underscores?",linecnt); -} - -/* * check_for_omitted_punctuation: * * Check for omitted punctuation at end of paragraph by working back @@ -2693,7 +2548,6 @@ } checked_linecnt++; print_pending(aline,parastart,&pending); - memset(&pending,0,sizeof(pending)); isemptyline=analyse_quotes(aline,&counters); if (isnewpara && !isemptyline) { @@ -2774,7 +2628,7 @@ if (isemptyline) { check_for_mismatched_quotes(&counters,&pending); - memset(&counters,0,sizeof(counters)); + counters_reset(&counters); /* let the next iteration know that it's starting a new para */ isnewpara=TRUE; if (prevline) @@ -2783,6 +2637,10 @@ g_free(prevline); prevline=g_strdup(aline); } + linecnt++; + check_for_mismatched_quotes(&counters,&pending); + print_pending(NULL,parastart,&pending); + reset_pending(&pending); if (prevline) { g_free(prevline);