bookloupe/bookloupe.c
changeset 103 adc06e9e8470
parent 99 7a62c77a0dbe
child 111 f805130deb6f
child 115 df21841a2b64
child 123 ddb5ddba6ef3
child 127 badcc3b340ab
child 131 2ff298db529e
child 136 2f3762ff90d8
child 142 466f43a12118
     1.1 --- a/bookloupe/bookloupe.c	Sat Sep 21 23:40:18 2013 +0100
     1.2 +++ b/bookloupe/bookloupe.c	Mon Sep 23 21:18:27 2013 +0100
     1.3 @@ -29,6 +29,7 @@
     1.4  #include <bl/bl.h>
     1.5  #include "bookloupe.h"
     1.6  #include "counters.h"
     1.7 +#include "pending.h"
     1.8  #include "HTMLentities.h"
     1.9  
    1.10  gchar *prevline;
    1.11 @@ -867,10 +868,26 @@
    1.12  	    isemptyline=FALSE;  /* ignore lines like  *  *  *  as spacers */
    1.13  	if (c==CHAR_UNDERSCORE)
    1.14  	    counters->c_unders++;
    1.15 -	if (c==CHAR_OPEN_CBRACK || c==CHAR_OPEN_RBRACK || c==CHAR_OPEN_SBRACK)
    1.16 +	if (c==CHAR_OPEN_SBRACK)
    1.17 +	{
    1.18 +	    if (!matching_difference(counters,COUNTER_ILLUSTRATION) &&
    1.19 +	      !matching_difference(counters,c) && s==aline &&
    1.20 +	      g_str_has_prefix(s,"[Illustration:"))
    1.21 +		increment_matching(counters,COUNTER_ILLUSTRATION,TRUE);
    1.22 +	    else
    1.23 +		increment_matching(counters,c,TRUE);
    1.24 +	}
    1.25 +	else if (c==CHAR_OPEN_CBRACK || c==CHAR_OPEN_RBRACK)
    1.26  	    increment_matching(counters,c,TRUE);
    1.27 -	if (c==CHAR_CLOSE_CBRACK || c==CHAR_CLOSE_RBRACK ||
    1.28 -	  c==CHAR_CLOSE_SBRACK)
    1.29 +	if (c==CHAR_CLOSE_SBRACK)
    1.30 +	{
    1.31 +	    if (!matching_count(counters,COUNTER_ILLUSTRATION,FALSE) &&
    1.32 +	      !matching_difference(counters,c) && !*snext)
    1.33 +		increment_matching(counters,COUNTER_ILLUSTRATION,FALSE);
    1.34 +	    else
    1.35 +		increment_matching(counters,c,FALSE);
    1.36 +	}
    1.37 +	else if (c==CHAR_CLOSE_CBRACK || c==CHAR_CLOSE_RBRACK)
    1.38  	    increment_matching(counters,c,FALSE);
    1.39  	sprev=s;
    1.40  	s=snext;
    1.41 @@ -2363,168 +2380,6 @@
    1.42  }
    1.43  
    1.44  /*
    1.45 - * print_pending:
    1.46 - *
    1.47 - * If we are in a state of unbalanced quotes, and this line
    1.48 - * doesn't begin with a quote, output the stored error message.
    1.49 - * If the -P switch was used, print the warning even if the
    1.50 - * new para starts with quotes.
    1.51 - */
    1.52 -void print_pending(const char *aline,const char *parastart,
    1.53 -  struct pending *pending)
    1.54 -{
    1.55 -    const char *s;
    1.56 -    gunichar c;
    1.57 -    s=aline;
    1.58 -    while (*s==' ')
    1.59 -	s++;
    1.60 -    c=g_utf8_get_char(s);
    1.61 -    if (pending->dquote)
    1.62 -    {
    1.63 -	if (c!=CHAR_DQUOTE || pswit[QPARA_SWITCH])
    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->dquote);
    1.70 -	    }
    1.71 -	    else
    1.72 -		cnt_dquot++;
    1.73 -	}
    1.74 -	g_free(pending->dquote);
    1.75 -	pending->dquote=NULL;
    1.76 -    }
    1.77 -    if (pending->squote)
    1.78 -    {
    1.79 -	if (!CHAR_IS_SQUOTE(c) || pswit[QPARA_SWITCH] || pending->squot)
    1.80 -	{
    1.81 -	    if (!pswit[OVERVIEW_SWITCH])
    1.82 -	    {
    1.83 -		if (pswit[ECHO_SWITCH])
    1.84 -		    g_print("\n%s\n",parastart);
    1.85 -		g_print("%s\n",pending->squote);
    1.86 -	    }
    1.87 -	    else
    1.88 -		cnt_squot++;
    1.89 -	}
    1.90 -	g_free(pending->squote);
    1.91 -	pending->squote=NULL;
    1.92 -    }
    1.93 -    if (pending->rbrack)
    1.94 -    {
    1.95 -	if (!pswit[OVERVIEW_SWITCH])
    1.96 -	{
    1.97 -	    if (pswit[ECHO_SWITCH])
    1.98 -		g_print("\n%s\n",parastart);
    1.99 -	    g_print("%s\n",pending->rbrack);
   1.100 -	}
   1.101 -	else
   1.102 -	    cnt_brack++;
   1.103 -	g_free(pending->rbrack);
   1.104 -	pending->rbrack=NULL;
   1.105 -    }
   1.106 -    if (pending->sbrack)
   1.107 -    {
   1.108 -	if (!pswit[OVERVIEW_SWITCH])
   1.109 -	{
   1.110 -	    if (pswit[ECHO_SWITCH])
   1.111 -		g_print("\n%s\n",parastart);
   1.112 -	    g_print("%s\n",pending->sbrack);
   1.113 -	}
   1.114 -	else
   1.115 -	    cnt_brack++;
   1.116 -	g_free(pending->sbrack);
   1.117 -	pending->sbrack=NULL;
   1.118 -    }
   1.119 -    if (pending->cbrack)
   1.120 -    {
   1.121 -	if (!pswit[OVERVIEW_SWITCH])
   1.122 -	{
   1.123 -	    if (pswit[ECHO_SWITCH])
   1.124 -		g_print("\n%s\n",parastart);
   1.125 -	    g_print("%s\n",pending->cbrack);
   1.126 -	}
   1.127 -	else
   1.128 -	    cnt_brack++;
   1.129 -	g_free(pending->cbrack);
   1.130 -	pending->cbrack=NULL;
   1.131 -    }
   1.132 -    if (pending->unders)
   1.133 -    {
   1.134 -	if (!pswit[OVERVIEW_SWITCH])
   1.135 -	{
   1.136 -	    if (pswit[ECHO_SWITCH])
   1.137 -		g_print("\n%s\n",parastart);
   1.138 -	    g_print("%s\n",pending->unders);
   1.139 -	}
   1.140 -	else
   1.141 -	    cnt_brack++;
   1.142 -	g_free(pending->unders);
   1.143 -	pending->unders=NULL;
   1.144 -    }
   1.145 -}
   1.146 -
   1.147 -/*
   1.148 - * check_for_mismatched_quotes:
   1.149 - *
   1.150 - * At end of paragraph, check for mismatched quotes.
   1.151 - *
   1.152 - * We don't want to report an error immediately, since it is a
   1.153 - * common convention to omit the quotes at end of paragraph if
   1.154 - * the next paragraph is a continuation of the same speaker.
   1.155 - * Where this is the case, the next para should begin with a
   1.156 - * quote, so we store the warning message and only display it
   1.157 - * at the top of the next iteration if the new para doesn't
   1.158 - * start with a quote.
   1.159 - * The -p switch overrides this default, and warns of unclosed
   1.160 - * quotes on _every_ paragraph, whether the next begins with a
   1.161 - * quote or not.
   1.162 - */
   1.163 -void check_for_mismatched_quotes(const struct counters *counters,
   1.164 -  struct pending *pending)
   1.165 -{
   1.166 -    int squote_straight,squote_curved;
   1.167 -    if (counters->quot%2)
   1.168 -	pending->dquote=
   1.169 -	  g_strdup_printf("    Line %ld - Mismatched quotes",linecnt);
   1.170 -    if (pswit[SQUOTE_SWITCH])
   1.171 -    {
   1.172 -	if (matching_count(counters,CHAR_SQUOTE,TRUE))
   1.173 -	    squote_straight=matching_difference(counters,CHAR_SQUOTE);
   1.174 -	else
   1.175 -	    squote_straight=0;
   1.176 -	if (matching_count(counters,CHAR_LS_QUOTE,TRUE))
   1.177 -	    squote_curved=matching_difference(counters,CHAR_LS_QUOTE);
   1.178 -	else
   1.179 -	    squote_curved=0;
   1.180 -	if (squote_straight || squote_curved)
   1.181 -	    pending->squote=
   1.182 -	      g_strdup_printf("    Line %ld - Mismatched singlequotes?",
   1.183 -	      linecnt);
   1.184 -	if (squote_straight && squote_straight!=1 ||
   1.185 -	  squote_curved && squote_curved!=1)
   1.186 -	    /*
   1.187 -	     * Flag it to be noted regardless of the
   1.188 -	     * first char of the next para.
   1.189 -	     */
   1.190 -	    pending->squot=1;
   1.191 -    }
   1.192 -    if (matching_difference(counters,CHAR_OPEN_RBRACK))
   1.193 -	pending->rbrack=
   1.194 -	  g_strdup_printf("    Line %ld - Mismatched round brackets?",linecnt);
   1.195 -    if (matching_difference(counters,CHAR_OPEN_SBRACK))
   1.196 -	pending->sbrack=
   1.197 -	  g_strdup_printf("    Line %ld - Mismatched square brackets?",linecnt);
   1.198 -    if (matching_difference(counters,CHAR_OPEN_CBRACK))
   1.199 -	pending->cbrack=
   1.200 -	  g_strdup_printf("    Line %ld - Mismatched curly brackets?",linecnt);
   1.201 -    if (counters->c_unders%2)
   1.202 -	pending->unders=
   1.203 -	  g_strdup_printf("    Line %ld - Mismatched underscores?",linecnt);
   1.204 -}
   1.205 -
   1.206 -/*
   1.207   * check_for_omitted_punctuation:
   1.208   *
   1.209   * Check for omitted punctuation at end of paragraph by working back
   1.210 @@ -2693,7 +2548,6 @@
   1.211  	}
   1.212  	checked_linecnt++;
   1.213  	print_pending(aline,parastart,&pending);
   1.214 -	memset(&pending,0,sizeof(pending));
   1.215  	isemptyline=analyse_quotes(aline,&counters);
   1.216  	if (isnewpara && !isemptyline)
   1.217  	{
   1.218 @@ -2774,7 +2628,7 @@
   1.219  	if (isemptyline)
   1.220  	{
   1.221  	    check_for_mismatched_quotes(&counters,&pending);
   1.222 -	    memset(&counters,0,sizeof(counters));
   1.223 +	    counters_reset(&counters);
   1.224  	    /* let the next iteration know that it's starting a new para */
   1.225  	    isnewpara=TRUE;
   1.226  	    if (prevline)
   1.227 @@ -2783,6 +2637,10 @@
   1.228  	g_free(prevline);
   1.229  	prevline=g_strdup(aline);
   1.230      }
   1.231 +    linecnt++;
   1.232 +    check_for_mismatched_quotes(&counters,&pending);
   1.233 +    print_pending(NULL,parastart,&pending);
   1.234 +    reset_pending(&pending);
   1.235      if (prevline)
   1.236      {
   1.237  	g_free(prevline);