Break check_for_double_punctuation() out
authorali <ali@juiblex.co.uk>
Sun May 26 19:28:31 2013 +0100 (2013-05-26)
changeset 571e89f47e56df
parent 56 8ade5460e220
child 58 b3385bfb28ac
Break check_for_double_punctuation() out
bookloupe/bookloupe.c
     1.1 --- a/bookloupe/bookloupe.c	Sun May 26 17:23:48 2013 +0100
     1.2 +++ b/bookloupe/bookloupe.c	Sun May 26 19:28:31 2013 +0100
     1.3 @@ -2028,6 +2028,70 @@
     1.4  }
     1.5  
     1.6  /*
     1.7 + * check_for_double_punctuation:
     1.8 + *
     1.9 + * Look for double punctuation like ,. or ,,
    1.10 + * Thanks to DW for the suggestion!
    1.11 + * In books with references, ".," and ".;" are common
    1.12 + * e.g. "etc., etc.," and vol. 1.; vol 3.;
    1.13 + * OTOH, from my initial tests, there are also fairly
    1.14 + * common errors. What to do? Make these cases paranoid?
    1.15 + * ".," is the most common, so warnings->dotcomma is used
    1.16 + * to suppress detailed reporting if it occurs often.
    1.17 + */
    1.18 +void check_for_double_punctuation(const char *aline,struct warnings *warnings)
    1.19 +{
    1.20 +    int i,llen;
    1.21 +    llen=strlen(aline);
    1.22 +    for (i=0;i<llen;i++)
    1.23 +    {
    1.24 +	/* for each punctuation character in the line */
    1.25 +	if (strchr(".?!,;:",aline[i]) && strchr(".?!,;:",aline[i+1]) &&
    1.26 +	  aline[i] && aline[i+1])
    1.27 +	{
    1.28 +	    /* followed by punctuation, it's a query, unless . . . */
    1.29 +	    if (aline[i]==aline[i+1] && (aline[i]=='.' || aline[i]=='?' ||
    1.30 +	      aline[i]=='!') ||
    1.31 +	      !warnings->dotcomma && aline[i]=='.' && aline[i+1]==',' ||
    1.32 +	      warnings->isFrench && !strncmp(aline+i,",...",4) ||
    1.33 +	      warnings->isFrench && !strncmp(aline+i,"...,",4) ||
    1.34 +	      warnings->isFrench && !strncmp(aline+i,";...",4) ||
    1.35 +	      warnings->isFrench && !strncmp(aline+i,"...;",4) ||
    1.36 +	      warnings->isFrench && !strncmp(aline+i,":...",4) ||
    1.37 +	      warnings->isFrench && !strncmp(aline+i,"...:",4) ||
    1.38 +	      warnings->isFrench && !strncmp(aline+i,"!...",4) ||
    1.39 +	      warnings->isFrench && !strncmp(aline+i,"...!",4) ||
    1.40 +	      warnings->isFrench && !strncmp(aline+i,"?...",4) ||
    1.41 +	      warnings->isFrench && !strncmp(aline+i,"...?",4))
    1.42 +	    {
    1.43 +		if (warnings->isFrench && !strncmp(aline+i,",...",4) ||
    1.44 +		  warnings->isFrench && !strncmp(aline+i,"...,",4) ||
    1.45 +		  warnings->isFrench && !strncmp(aline+i,";...",4) ||
    1.46 +		  warnings->isFrench && !strncmp(aline+i,"...;",4) ||
    1.47 +		  warnings->isFrench && !strncmp(aline+i,":...",4) ||
    1.48 +		  warnings->isFrench && !strncmp(aline+i,"...:",4) ||
    1.49 +		  warnings->isFrench && !strncmp(aline+i,"!...",4) ||
    1.50 +		  warnings->isFrench && !strncmp(aline+i,"...!",4) ||
    1.51 +		  warnings->isFrench && !strncmp(aline+i,"?...",4) ||
    1.52 +		  warnings->isFrench && !strncmp(aline+i,"...?",4))
    1.53 +		    i+=4;
    1.54 +		; /* do nothing for .. !! and ?? which can be legit */
    1.55 +	    }
    1.56 +	    else
    1.57 +	    {
    1.58 +		if (pswit[ECHO_SWITCH])
    1.59 +		    printf("\n%s\n",aline);
    1.60 +		if (!pswit[OVERVIEW_SWITCH])
    1.61 +		    printf("    Line %ld column %d - Double punctuation?\n",
    1.62 +		      linecnt,i+1);
    1.63 +		else
    1.64 +		    cnt_punct++;
    1.65 +	    }
    1.66 +	}
    1.67 +    }
    1.68 +}
    1.69 +
    1.70 +/*
    1.71   * procfile:
    1.72   *
    1.73   * Process one file.
    1.74 @@ -2268,63 +2332,7 @@
    1.75  	check_for_following_punctuation(aline);
    1.76  	check_for_typos(aline,warnings);
    1.77  	check_for_misspaced_punctuation(aline,&parities,isemptyline);
    1.78 -        /*
    1.79 -	 * Look for double punctuation like ,. or ,,
    1.80 -         * Thanks to DW for the suggestion!
    1.81 -         * In books with references, ".," and ".;" are common
    1.82 -         * e.g. "etc., etc.," and vol. 1.; vol 3.;
    1.83 -         * OTOH, from my initial tests, there are also fairly
    1.84 -         * common errors. What to do? Make these cases paranoid?
    1.85 -         * ".," is the most common, so warnings->dotcomma is used
    1.86 -         * to suppress detailed reporting if it occurs often.
    1.87 -	 */
    1.88 -        llen=strlen(aline);
    1.89 -        for (i=0;i<llen;i++)
    1.90 -	{
    1.91 -	    /* for each punctuation character in the line */
    1.92 -            if (strchr(".?!,;:",aline[i]) && (strchr(".?!,;:",aline[i+1])) &&
    1.93 -	      aline[i] && aline[i+1])
    1.94 -	    {
    1.95 -		/* followed by punctuation, it's a query, unless . . . */
    1.96 -                if (aline[i]==aline[i+1] && (aline[i]=='.' || aline[i]=='?' ||
    1.97 -		  aline[i]=='!') ||
    1.98 -		  !warnings->dotcomma && aline[i]=='.' && aline[i+1]==',' ||
    1.99 -		  warnings->isFrench && !strncmp(aline+i,",...",4) ||
   1.100 -		  warnings->isFrench && !strncmp(aline+i,"...,",4) ||
   1.101 -		  warnings->isFrench && !strncmp(aline+i,";...",4) ||
   1.102 -		  warnings->isFrench && !strncmp(aline+i,"...;",4) ||
   1.103 -		  warnings->isFrench && !strncmp(aline+i,":...",4) ||
   1.104 -		  warnings->isFrench && !strncmp(aline+i,"...:",4) ||
   1.105 -		  warnings->isFrench && !strncmp(aline+i,"!...",4) ||
   1.106 -		  warnings->isFrench && !strncmp(aline+i,"...!",4) ||
   1.107 -		  warnings->isFrench && !strncmp(aline+i,"?...",4) ||
   1.108 -		  warnings->isFrench && !strncmp(aline+i,"...?",4))
   1.109 -		{
   1.110 -		    if (warnings->isFrench && !strncmp(aline+i,",...",4) ||
   1.111 -		      warnings->isFrench && !strncmp(aline+i,"...,",4) ||
   1.112 -		      warnings->isFrench && !strncmp(aline+i,";...",4) ||
   1.113 -		      warnings->isFrench && !strncmp(aline+i,"...;",4) ||
   1.114 -		      warnings->isFrench && !strncmp(aline+i,":...",4) ||
   1.115 -		      warnings->isFrench && !strncmp(aline+i,"...:",4) ||
   1.116 -		      warnings->isFrench && !strncmp(aline+i,"!...",4) ||
   1.117 -		      warnings->isFrench && !strncmp(aline+i,"...!",4) ||
   1.118 -		      warnings->isFrench && !strncmp(aline+i,"?...",4) ||
   1.119 -		      warnings->isFrench && !strncmp(aline+i,"...?",4))
   1.120 -			i+=4;
   1.121 -		    ; /* do nothing for .. !! and ?? which can be legit */
   1.122 -		}
   1.123 -                else
   1.124 -		{
   1.125 -                    if (pswit[ECHO_SWITCH])
   1.126 -			printf("\n%s\n",aline);
   1.127 -                    if (!pswit[OVERVIEW_SWITCH])
   1.128 -                        printf("    Line %ld column %d - Double punctuation?\n",
   1.129 -			  linecnt,i+1);
   1.130 -                    else
   1.131 -                        cnt_punct++;
   1.132 -		}
   1.133 -	    }
   1.134 -	}
   1.135 +	check_for_double_punctuation(aline,warnings);
   1.136          s=aline;
   1.137          while (strstr(s," \" "))
   1.138  	{