diff -r adc06e9e8470 -r 927fb871d2e3 bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Mon Sep 23 21:18:27 2013 +0100 +++ b/bookloupe/bookloupe.c Fri Sep 27 07:19:36 2013 +0100 @@ -160,8 +160,7 @@ { NULL } }; -long cnt_dquot; /* for overview mode, count of doublequote queries */ -long cnt_squot; /* for overview mode, count of singlequote queries */ +long cnt_quote; /* for overview mode, count of quote queries */ long cnt_brack; /* for overview mode, count of brackets queries */ long cnt_bin; /* for overview mode, count of non-ASCII queries */ long cnt_odd; /* for overview mode, count of odd character queries */ @@ -407,10 +406,8 @@ g_print(" Line-end problems: %14ld\n",cnt_lineend); if (cnt_word) g_print(" Common typos: %14ld\n",cnt_word); - if (cnt_dquot) - g_print(" Unmatched quotes: %14ld\n",cnt_dquot); - if (cnt_squot) - g_print(" Unmatched SingleQuotes: %14ld\n",cnt_squot); + if (cnt_quote) + g_print(" Unmatched quotes: %14ld\n",cnt_quote); if (cnt_brack) g_print(" Unmatched brackets: %14ld\n",cnt_brack); if (cnt_bin) @@ -425,8 +422,8 @@ g_print(" Possible HTML tags: %14ld\n",cnt_html); g_print("\n"); g_print(" TOTAL QUERIES %14ld\n", - cnt_dquot+cnt_squot+cnt_brack+cnt_bin+cnt_odd+cnt_long+ - cnt_short+cnt_punct+cnt_dash+cnt_word+cnt_html+cnt_lineend); + cnt_quote+cnt_brack+cnt_bin+cnt_odd+cnt_long+cnt_short+cnt_punct+ + cnt_dash+cnt_word+cnt_html+cnt_lineend); } g_free(running_from); if (usertypo) @@ -788,7 +785,7 @@ * * Returns: TRUE if the line is empty. */ -gboolean analyse_quotes(const char *aline,struct counters *counters) +gboolean analyse_quotes(const char *aline,int linecnt,struct counters *counters) { int guessquote=0; /* assume the line is empty until proven otherwise */ @@ -796,23 +793,24 @@ const char *s=aline,*sprev,*snext; gunichar c; sprev=NULL; + GError *tmp_err=NULL; while (*s) { snext=g_utf8_next_char(s); c=g_utf8_get_char(s); - if (c==CHAR_DQUOTE) - counters->quot++; - if (CHAR_IS_SQUOTE(c)) + if (CHAR_IS_DQUOTE(c)) + (void)count_quote(counters,c,QUOTE_CLASS(c),&tmp_err); + else if (CHAR_IS_SQUOTE(c) && pswit[SQUOTE_SWITCH]) { if (s==aline) { /* - * At start of line, it can only be an openquote. + * At start of line, it can only be a quotation mark. * Hardcode a very common exception! */ if (!g_str_has_prefix(snext,"tis") && !g_str_has_prefix(snext,"Tis")) - increment_matching(counters,c,TRUE); + (void)count_quote(counters,c,NEUTRAL_QUOTE,&tmp_err); } else if (g_unichar_isalpha(g_utf8_get_char(sprev)) && g_unichar_isalpha(g_utf8_get_char(snext))) @@ -822,15 +820,20 @@ else if (c==CHAR_OPEN_SQUOTE || c==CHAR_LS_QUOTE || g_unichar_isalpha(g_utf8_get_char(snext))) { - /* it damwell better BE an openquote */ + /* certainly looks like a quotation mark */ if (!g_str_has_prefix(snext,"tis") && !g_str_has_prefix(snext,"Tis")) /* hardcode a very common exception! */ - increment_matching(counters,c,TRUE); + { + if (strchr(".?!,;:",g_utf8_get_char(sprev))) + (void)count_quote(counters,c,NEUTRAL_QUOTE,&tmp_err); + else + (void)count_quote(counters,c,OPENING_QUOTE,&tmp_err); + } } else { - /* now - is it a closequote? */ + /* now - is it a quotation mark? */ guessquote=0; /* accumulate clues */ if (g_unichar_isalpha(g_utf8_get_char(sprev))) { @@ -844,25 +847,31 @@ /* bonus marks! */ guessquote-=2; } + if (innermost_quote_matches(counters,c)) + /* + * Give it the benefit of some doubt, + * if a squote is already open. + */ + guessquote++; + else + guessquote--; + if (guessquote>=0) + (void)count_quote(counters,c,CLOSING_QUOTE,&tmp_err); } - /* it doesn't have a letter either side */ - else if (strchr(".?!,;:",g_utf8_get_char(sprev)) && - strchr(".?!,;: ",g_utf8_get_char(snext))) - guessquote+=8; /* looks like a closequote */ else - guessquote++; - if (matching_difference(counters,CHAR_SQUOTE)>0) - /* - * Give it the benefit of some doubt, - * if a squote is already open. - */ - guessquote++; - else - guessquote--; - if (guessquote>=0) - increment_matching(counters,c,FALSE); + /* no adjacent letter - it must be a quote of some kind */ + (void)count_quote(counters,c,NEUTRAL_QUOTE,&tmp_err); } } + if (tmp_err) + { + if (pswit[ECHO_SWITCH]) + g_print("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + g_print(" Line %ld column %ld - %s\n", + linecnt,g_utf8_pointer_to_offset(aline,s)+1,tmp_err->message); + g_clear_error(&tmp_err); + } if (c!=CHAR_SPACE && c!='-' && c!='.' && c!=CHAR_ASTERISK && c!='\r' && c!='\n') isemptyline=FALSE; /* ignore lines like * * * as spacers */ @@ -2396,6 +2405,7 @@ gboolean letter_on_line=FALSE; const char *s; gunichar c; + gboolean closing_quote; for (s=prevline;*s;s=g_utf8_next_char(s)) if (g_unichar_isalpha(g_utf8_get_char(s))) { @@ -2417,7 +2427,11 @@ { s=g_utf8_prev_char(s); c=g_utf8_get_char(s); - } while (CHAR_IS_CLOSING_QUOTE(c) && c>CHAR_SPACE && s>prevline); + if (QUOTE_CLASS(c)==CLOSING_QUOTE || QUOTE_CLASS(c)==NEUTRAL_QUOTE) + closing_quote=TRUE; + else + closing_quote=FALSE; + } while (closing_quote && s>prevline); for (;s>prevline;s=g_utf8_prev_char(s)) { if (g_unichar_isalpha(g_utf8_get_char(s))) @@ -2548,7 +2562,7 @@ } checked_linecnt++; print_pending(aline,parastart,&pending); - isemptyline=analyse_quotes(aline,&counters); + isemptyline=analyse_quotes(aline,linecnt,&counters); if (isnewpara && !isemptyline) { /* This line is the start of a new paragraph. */