1.1 --- a/bookloupe/pending.c Mon Sep 23 21:18:27 2013 +0100
1.2 +++ b/bookloupe/pending.c Thu Dec 05 10:56:11 2013 +0000
1.3 @@ -1,6 +1,7 @@
1.4 #include <stdlib.h>
1.5 #include <string.h>
1.6 #include <glib.h>
1.7 +#include <bl/bl.h>
1.8 #include "bookloupe.h"
1.9 #include "pending.h"
1.10
1.11 @@ -15,20 +16,9 @@
1.12 void print_pending(const char *aline,const char *parastart,
1.13 struct pending *pending)
1.14 {
1.15 - const char *s;
1.16 - gunichar c;
1.17 if (aline)
1.18 - {
1.19 - s=aline;
1.20 - while (*s==' ')
1.21 - s++;
1.22 - c=g_utf8_get_char(s);
1.23 - }
1.24 - else
1.25 - {
1.26 - s=NULL;
1.27 - c='\0';
1.28 - }
1.29 + while (g_unichar_isspace(g_utf8_get_char(aline)))
1.30 + aline=g_utf8_next_char(aline);
1.31 if (pending->illustration.warning_text)
1.32 {
1.33 if (aline)
1.34 @@ -52,38 +42,25 @@
1.35 pending->illustration.queried_line=NULL;
1.36 }
1.37 }
1.38 - if (pending->dquote)
1.39 + if (pending->quote)
1.40 {
1.41 - if (c!=CHAR_DQUOTE || pswit[QPARA_SWITCH])
1.42 + if (!pending->continuing_quote || !aline ||
1.43 + !g_str_has_prefix(aline,pending->continuing_quote))
1.44 {
1.45 if (!pswit[OVERVIEW_SWITCH])
1.46 {
1.47 if (pswit[ECHO_SWITCH])
1.48 g_print("\n%s\n",parastart);
1.49 - g_print("%s\n",pending->dquote);
1.50 + g_print("%s\n",pending->quote);
1.51 }
1.52 else
1.53 - cnt_dquot++;
1.54 + cnt_quote++;
1.55 }
1.56 - g_free(pending->dquote);
1.57 - pending->dquote=NULL;
1.58 + g_free(pending->quote);
1.59 + pending->quote=NULL;
1.60 }
1.61 - if (pending->squote)
1.62 - {
1.63 - if (!CHAR_IS_SQUOTE(c) || pswit[QPARA_SWITCH] || pending->squot)
1.64 - {
1.65 - if (!pswit[OVERVIEW_SWITCH])
1.66 - {
1.67 - if (pswit[ECHO_SWITCH])
1.68 - g_print("\n%s\n",parastart);
1.69 - g_print("%s\n",pending->squote);
1.70 - }
1.71 - else
1.72 - cnt_squot++;
1.73 - }
1.74 - g_free(pending->squote);
1.75 - pending->squote=NULL;
1.76 - }
1.77 + g_free(pending->continuing_quote);
1.78 + pending->continuing_quote=NULL;
1.79 if (pending->rbrack)
1.80 {
1.81 if (!pswit[OVERVIEW_SWITCH])
1.82 @@ -159,34 +136,35 @@
1.83 * quotes on _every_ paragraph, whether the next begins with a
1.84 * quote or not.
1.85 */
1.86 -void check_for_mismatched_quotes(const struct counters *counters,
1.87 +void check_for_mismatched_quotes(struct counters *counters,
1.88 struct pending *pending)
1.89 {
1.90 - int squote_straight,squote_curved,difference;
1.91 - if (counters->quot%2)
1.92 - pending->dquote=
1.93 - g_strdup_printf(" Line %ld - Mismatched quotes",linecnt);
1.94 - if (pswit[SQUOTE_SWITCH])
1.95 + gboolean all_single;
1.96 + gunichar c;
1.97 + int difference;
1.98 + const char *quote_type;
1.99 + GString *str;
1.100 + if (counters->open_quotes)
1.101 {
1.102 - if (matching_count(counters,CHAR_SQUOTE,TRUE))
1.103 - squote_straight=matching_difference(counters,CHAR_SQUOTE);
1.104 + str=g_string_new(NULL);
1.105 + counters->open_quotes=g_slist_reverse(counters->open_quotes);
1.106 + all_single=TRUE;
1.107 + while(counters->open_quotes)
1.108 + {
1.109 + c=GPOINTER_TO_INT(counters->open_quotes->data);
1.110 + if (!CHAR_IS_SQUOTE(c))
1.111 + all_single=FALSE;
1.112 + g_string_append_unichar(str,c);
1.113 + counters->open_quotes=g_slist_delete_link(counters->open_quotes,
1.114 + counters->open_quotes);
1.115 + }
1.116 + pending->continuing_quote=g_string_free(str,FALSE);
1.117 + if (all_single)
1.118 + quote_type="singlequotes?";
1.119 else
1.120 - squote_straight=0;
1.121 - if (matching_count(counters,CHAR_LS_QUOTE,TRUE))
1.122 - squote_curved=matching_difference(counters,CHAR_LS_QUOTE);
1.123 - else
1.124 - squote_curved=0;
1.125 - if (squote_straight || squote_curved)
1.126 - pending->squote=
1.127 - g_strdup_printf(" Line %ld - Mismatched singlequotes?",
1.128 - linecnt);
1.129 - if (squote_straight && squote_straight!=1 ||
1.130 - squote_curved && squote_curved!=1)
1.131 - /*
1.132 - * Flag it to be noted regardless of the
1.133 - * first char of the next para.
1.134 - */
1.135 - pending->squot=1;
1.136 + quote_type="quotes";
1.137 + pending->quote=g_strdup_printf(" Line %ld - Mismatched %s",linecnt,
1.138 + quote_type);
1.139 }
1.140 difference=matching_difference(counters,COUNTER_ILLUSTRATION);
1.141 if (difference)