Break check_for_spaced_emdash() and check_for_spaced_dash() out
authorali <ali@juiblex.co.uk>
Sat May 25 20:29:36 2013 +0100 (2013-05-25)
changeset 477522c36859d0
parent 46 aa45307a6328
child 48 274aa1e09099
Break check_for_spaced_emdash() and check_for_spaced_dash() out
bookloupe/bookloupe.c
     1.1 --- a/bookloupe/bookloupe.c	Sat May 25 19:35:44 2013 +0100
     1.2 +++ b/bookloupe/bookloupe.c	Sat May 25 20:29:36 2013 +0100
     1.3 @@ -1171,6 +1171,71 @@
     1.4  }
     1.5  
     1.6  /*
     1.7 + * check_for_spaced_emdash:
     1.8 + *
     1.9 + * Check for spaced em-dashes.
    1.10 + *
    1.11 + * We must check _all_ occurrences of "--" on the line
    1.12 + * hence the loop - even if the first double-dash is OK
    1.13 + * there may be another that's wrong later on.
    1.14 + */
    1.15 +void check_for_spaced_emdash(const char *aline)
    1.16 +{
    1.17 +    const char *s,*t;
    1.18 +    s=aline;
    1.19 +    while ((t=strstr(s,"--")))
    1.20 +    {
    1.21 +	if (t>aline && t[-1]==CHAR_SPACE || t[2]==CHAR_SPACE)
    1.22 +	{
    1.23 +	    if (pswit[ECHO_SWITCH])
    1.24 +		printf("\n%s\n",aline);
    1.25 +	    if (!pswit[OVERVIEW_SWITCH])
    1.26 +		printf("    Line %ld column %d - Spaced em-dash?\n",
    1.27 +		  linecnt,(int)(t-aline)+1);
    1.28 +	    else
    1.29 +		cnt_dash++;
    1.30 +	}
    1.31 +	s=t+2;
    1.32 +    }
    1.33 +}
    1.34 +
    1.35 +/*
    1.36 + * check_for_spaced_dash:
    1.37 + *
    1.38 + * Check for spaced dashes.
    1.39 + */
    1.40 +void check_for_spaced_dash(const char *aline)
    1.41 +{
    1.42 +    const char *s;
    1.43 +    if ((s=strstr(aline," -")))
    1.44 +    {
    1.45 +	if (s[2]!='-')
    1.46 +	{
    1.47 +	    if (pswit[ECHO_SWITCH])
    1.48 +		printf("\n%s\n",aline);
    1.49 +	    if (!pswit[OVERVIEW_SWITCH])
    1.50 +		printf("    Line %ld column %d - Spaced dash?\n",
    1.51 +		  linecnt,(int)(s-aline)+1);
    1.52 +	    else
    1.53 +		cnt_dash++;
    1.54 +	}
    1.55 +    }
    1.56 +    else if ((s=strstr(aline,"- ")))
    1.57 +    {
    1.58 +	if (s==aline || s[-1]!='-')
    1.59 +	{
    1.60 +	    if (pswit[ECHO_SWITCH])
    1.61 +		printf("\n%s\n",aline);
    1.62 +	    if (!pswit[OVERVIEW_SWITCH])
    1.63 +		printf("    Line %ld column %d - Spaced dash?\n",
    1.64 +		  linecnt,(int)(s-aline)+1);
    1.65 +	    else
    1.66 +		cnt_dash++;
    1.67 +	}
    1.68 +    }
    1.69 +}
    1.70 +
    1.71 +/*
    1.72   * procfile:
    1.73   *
    1.74   * Process one file.
    1.75 @@ -1411,60 +1476,10 @@
    1.76          last.len=strlen(aline);
    1.77          last.start=aline[0];
    1.78  	check_for_starting_punctuation(aline);
    1.79 -        /*
    1.80 -	 * Check for spaced em-dashes.
    1.81 -         * We must check _all_ occurrences of "--" on the line
    1.82 -         * hence the loop - even if the first double-dash is OK
    1.83 -         * there may be another that's wrong later on.
    1.84 -	 */
    1.85          if (warnings->dash)
    1.86  	{
    1.87 -            s=aline;
    1.88 -            while (strstr(s,"--"))
    1.89 -	    {
    1.90 -                if (*(strstr(s,"--")-1)==CHAR_SPACE ||
    1.91 -                   (*(strstr(s,"--")+2)==CHAR_SPACE))
    1.92 -		{
    1.93 -                    if (pswit[ECHO_SWITCH])
    1.94 -			printf("\n%s\n",aline);
    1.95 -                    if (!pswit[OVERVIEW_SWITCH])
    1.96 -                        printf("    Line %ld column %d - Spaced em-dash?\n",
    1.97 -			  linecnt,(int)(strstr(s,"--")-aline)+1);
    1.98 -                    else
    1.99 -                        cnt_dash++;
   1.100 -		}
   1.101 -                s=strstr(s,"--")+2;
   1.102 -	    }
   1.103 -	}
   1.104 -        /* Check for spaced dashes. */
   1.105 -        if (warnings->dash)
   1.106 -	{
   1.107 -            if (strstr(aline," -"))
   1.108 -	    {
   1.109 -                if (*(strstr(aline," -")+2)!='-')
   1.110 -		{
   1.111 -                    if (pswit[ECHO_SWITCH])
   1.112 -			printf("\n%s\n",aline);
   1.113 -                    if (!pswit[OVERVIEW_SWITCH])
   1.114 -                        printf("    Line %ld column %d - Spaced dash?\n",
   1.115 -			  linecnt,(int)(strstr(aline," -")-aline)+1);
   1.116 -                    else
   1.117 -                        cnt_dash++;
   1.118 -		}
   1.119 -	    }
   1.120 -            else if (strstr(aline,"- "))
   1.121 -	    {
   1.122 -		if (*(strstr(aline,"- ")-1)!='-')
   1.123 -		{
   1.124 -		    if (pswit[ECHO_SWITCH])
   1.125 -			printf("\n%s\n",aline);
   1.126 -		    if (!pswit[OVERVIEW_SWITCH])
   1.127 -			printf("    Line %ld column %d - Spaced dash?\n",
   1.128 -			  linecnt,(int)(strstr(aline,"- ")-aline)+1);
   1.129 -		    else
   1.130 -			cnt_dash++;
   1.131 -		}
   1.132 -	    }
   1.133 +	    check_for_spaced_emdash(aline);
   1.134 +	    check_for_spaced_dash(aline);
   1.135  	}
   1.136          /*
   1.137  	 * Check for unmarked paragraphs indicated by separate speakers.