Break check_for_odd_characters() out
authorali <ali@juiblex.co.uk>
Sat May 25 19:14:21 2013 +0100 (2013-05-25)
changeset 4466483ebc9b56
parent 43 e4042a067753
child 45 d48f66b0ad0d
Break check_for_odd_characters() out
bookloupe/bookloupe.c
     1.1 --- a/bookloupe/bookloupe.c	Sat May 25 17:01:36 2013 +0100
     1.2 +++ b/bookloupe/bookloupe.c	Sat May 25 19:14:21 2013 +0100
     1.3 @@ -992,6 +992,103 @@
     1.4  }
     1.5  
     1.6  /*
     1.7 + * check_for_odd_characters:
     1.8 + *
     1.9 + * Check for binary and other odd characters.
    1.10 + */
    1.11 +void check_for_odd_characters(const char *aline,const struct warnings *warnings,
    1.12 +  int isemptyline)
    1.13 +{
    1.14 +    /* Don't repeat multiple warnings on one line. */
    1.15 +    signed int eNon_A=0,eTab=0,eTilde=0,eCarat=0,eFSlash=0,eAst=0;
    1.16 +    const char *s;
    1.17 +    unsigned char c;
    1.18 +    for (s=aline;*s;s++)
    1.19 +    {
    1.20 +	c=*(unsigned char *)s;
    1.21 +	if (!eNon_A && (*s<CHAR_SPACE && *s!=9 && *s!='\n' || c>127))
    1.22 +	{
    1.23 +	    if (pswit[ECHO_SWITCH])
    1.24 +		printf("\n%s\n",aline);
    1.25 +	    if (!pswit[OVERVIEW_SWITCH])
    1.26 +		if (c>127 && c<160)
    1.27 +		    printf("    Line %ld column %d - "
    1.28 +		      "Non-ISO-8859 character %d\n",linecnt,(int)(s-aline)+1,c);
    1.29 +		else
    1.30 +		    printf("    Line %ld column %d - Non-ASCII character %d\n",
    1.31 +		      linecnt,(int)(s-aline)+1,c);
    1.32 +	    else
    1.33 +		cnt_bin++;
    1.34 +	    eNon_A=1;
    1.35 +	}
    1.36 +	if (!eTab && *s==CHAR_TAB)
    1.37 +	{
    1.38 +	    if (pswit[ECHO_SWITCH])
    1.39 +		printf("\n%s\n",aline);
    1.40 +	    if (!pswit[OVERVIEW_SWITCH])
    1.41 +		printf("    Line %ld column %d - Tab character?\n",
    1.42 +		  linecnt,(int)(s-aline)+1);
    1.43 +	    else
    1.44 +		cnt_odd++;
    1.45 +	    eTab=1;
    1.46 +	}
    1.47 +	if (!eTilde && *s==CHAR_TILDE)
    1.48 +	{
    1.49 +	    /*
    1.50 +	     * Often used by OCR software to indicate an
    1.51 +	     * unrecognizable character.
    1.52 +	     */
    1.53 +	    if (pswit[ECHO_SWITCH])
    1.54 +		printf("\n%s\n",aline);
    1.55 +	    if (!pswit[OVERVIEW_SWITCH])
    1.56 +		printf("    Line %ld column %d - Tilde character?\n",
    1.57 +		  linecnt,(int)(s-aline)+1);
    1.58 +	    else
    1.59 +		cnt_odd++;
    1.60 +	    eTilde=1;
    1.61 +	}
    1.62 +	if (!eCarat && *s==CHAR_CARAT)
    1.63 +	{  
    1.64 +	    if (pswit[ECHO_SWITCH])
    1.65 +		printf("\n%s\n",aline);
    1.66 +	    if (!pswit[OVERVIEW_SWITCH])
    1.67 +		printf("    Line %ld column %d - Carat character?\n",
    1.68 +		  linecnt,(int)(s-aline)+1);
    1.69 +	    else
    1.70 +		cnt_odd++;
    1.71 +	    eCarat=1;
    1.72 +	}
    1.73 +	if (!eFSlash && *s==CHAR_FORESLASH && warnings->fslash)
    1.74 +	{  
    1.75 +	    if (pswit[ECHO_SWITCH])
    1.76 +		printf("\n%s\n",aline);
    1.77 +	    if (!pswit[OVERVIEW_SWITCH])
    1.78 +		printf("    Line %ld column %d - Forward slash?\n",
    1.79 +		  linecnt,(int)(s-aline)+1);
    1.80 +	    else
    1.81 +		cnt_odd++;
    1.82 +	    eFSlash=1;
    1.83 +	}
    1.84 +	/*
    1.85 +	 * Report asterisks only in paranoid mode,
    1.86 +	 * since they're often deliberate.
    1.87 +	 */
    1.88 +	if (!eAst && pswit[PARANOID_SWITCH] && warnings->ast && !isemptyline &&
    1.89 +	  *s==CHAR_ASTERISK)
    1.90 +	{
    1.91 +	    if (pswit[ECHO_SWITCH])
    1.92 +		printf("\n%s\n",aline);
    1.93 +	    if (!pswit[OVERVIEW_SWITCH])
    1.94 +		printf("    Line %ld column %d - Asterisk?\n",
    1.95 +		  linecnt,(int)(s-aline)+1);
    1.96 +	    else
    1.97 +		cnt_odd++;
    1.98 +	    eAst=1;
    1.99 +	}
   1.100 +    }
   1.101 +}
   1.102 +
   1.103 +/*
   1.104   * procfile:
   1.105   *
   1.106   * Process one file.
   1.107 @@ -1007,8 +1104,7 @@
   1.108      struct counters counters={0};
   1.109      int isemptyline;
   1.110      long squot,start_para_line;
   1.111 -    signed int i,j,llen,isacro,isellipsis,istypo,alower,
   1.112 -      eNon_A,eTab,eTilde,eAst,eFSlash,eCarat;
   1.113 +    signed int i,j,llen,isacro,isellipsis,istypo,alower;
   1.114      unsigned int lastlen,lastblen;
   1.115      signed int dquotepar,squotepar;
   1.116      signed int isnewpara,vowel,consonant;
   1.117 @@ -1227,98 +1323,7 @@
   1.118  	    }
   1.119  	}
   1.120          if (warnings->bin)
   1.121 -	{
   1.122 -	    /* Don't repeat multiple warnings on one line. */
   1.123 -            eNon_A=eTab=eTilde=eCarat=eFSlash=eAst=0;
   1.124 -            for (s=aline;*s;s++)
   1.125 -	    {
   1.126 -                if (!eNon_A &&
   1.127 -		  (*s<CHAR_SPACE && *s!=9 && *s!='\n' || (unsigned char)*s>127))
   1.128 -		{
   1.129 -                    i=*s;  /* annoying kludge for signed chars */
   1.130 -                    if (i<0)
   1.131 -			i+=256;
   1.132 -                    if (pswit[ECHO_SWITCH])
   1.133 -			printf("\n%s\n",aline);
   1.134 -                    if (!pswit[OVERVIEW_SWITCH])
   1.135 -                        if (i>127 && i<160)
   1.136 -                            printf("    Line %ld column %d - "
   1.137 -			      "Non-ISO-8859 character %d\n",
   1.138 -			      linecnt,(int)(s-aline)+1,i);
   1.139 -                        else
   1.140 -                            printf("    Line %ld column %d - "
   1.141 -			      "Non-ASCII character %d\n",
   1.142 -			      linecnt,(int)(s-aline)+1,i);
   1.143 -                    else
   1.144 -                        cnt_bin++;
   1.145 -                    eNon_A=1;
   1.146 -		}
   1.147 -                if (!eTab && *s==CHAR_TAB)
   1.148 -		{
   1.149 -                    if (pswit[ECHO_SWITCH])
   1.150 -			printf("\n%s\n",aline);
   1.151 -                    if (!pswit[OVERVIEW_SWITCH])
   1.152 -                        printf("    Line %ld column %d - Tab character?\n",
   1.153 -			  linecnt,(int)(s-aline)+1);
   1.154 -                    else
   1.155 -                        cnt_odd++;
   1.156 -                    eTab=1;
   1.157 -		}
   1.158 -                if (!eTilde && *s==CHAR_TILDE)
   1.159 -		{
   1.160 -		    /*
   1.161 -		     * Often used by OCR software to indicate an
   1.162 -		     * unrecognizable character.
   1.163 -		     */
   1.164 -                    if (pswit[ECHO_SWITCH])
   1.165 -			printf("\n%s\n",aline);
   1.166 -                    if (!pswit[OVERVIEW_SWITCH])
   1.167 -                        printf("    Line %ld column %d - Tilde character?\n",
   1.168 -			  linecnt,(int)(s-aline)+1);
   1.169 -                    else
   1.170 -                        cnt_odd++;
   1.171 -                    eTilde=1;
   1.172 -		}
   1.173 -                if (!eCarat && *s==CHAR_CARAT)
   1.174 -		{  
   1.175 -                    if (pswit[ECHO_SWITCH])
   1.176 -			printf("\n%s\n",aline);
   1.177 -                    if (!pswit[OVERVIEW_SWITCH])
   1.178 -                        printf("    Line %ld column %d - Carat character?\n",
   1.179 -			  linecnt,(int)(s-aline)+1);
   1.180 -                    else
   1.181 -                        cnt_odd++;
   1.182 -                    eCarat=1;
   1.183 -		}
   1.184 -                if (!eFSlash && *s==CHAR_FORESLASH && warnings->fslash)
   1.185 -		{  
   1.186 -                    if (pswit[ECHO_SWITCH])
   1.187 -			printf("\n%s\n",aline);
   1.188 -                    if (!pswit[OVERVIEW_SWITCH])
   1.189 -                        printf("    Line %ld column %d - Forward slash?\n",
   1.190 -			  linecnt,(int)(s-aline)+1);
   1.191 -                    else
   1.192 -                        cnt_odd++;
   1.193 -                    eFSlash=1;
   1.194 -		}
   1.195 -                /*
   1.196 -		 * Report asterisks only in paranoid mode,
   1.197 -		 * since they're often deliberate.
   1.198 -		 */
   1.199 -                if (!eAst && pswit[PARANOID_SWITCH] && warnings->ast &&
   1.200 -		  !isemptyline && *s==CHAR_ASTERISK)
   1.201 -		{
   1.202 -                    if (pswit[ECHO_SWITCH])
   1.203 -			printf("\n%s\n",aline);
   1.204 -                    if (!pswit[OVERVIEW_SWITCH])
   1.205 -                        printf("    Line %ld column %d - Asterisk?\n",
   1.206 -			  linecnt,(int)(s-aline)+1);
   1.207 -                    else
   1.208 -                        cnt_odd++;
   1.209 -                    eAst=1;
   1.210 -		}
   1.211 -	    }
   1.212 -	}
   1.213 +	    check_for_odd_characters(aline,warnings,isemptyline);
   1.214          /* Check for line too long. */
   1.215          if (warnings->longline)
   1.216  	{