# HG changeset patch # User ali # Date 1369505661 -3600 # Node ID 66483ebc9b56d940520437399f95e43cc30e483a # Parent e4042a067753665ff0ffdb805078affbaea97c69 Break check_for_odd_characters() out diff -r e4042a067753 -r 66483ebc9b56 bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Sat May 25 17:01:36 2013 +0100 +++ b/bookloupe/bookloupe.c Sat May 25 19:14:21 2013 +0100 @@ -992,6 +992,103 @@ } /* + * check_for_odd_characters: + * + * Check for binary and other odd characters. + */ +void check_for_odd_characters(const char *aline,const struct warnings *warnings, + int isemptyline) +{ + /* Don't repeat multiple warnings on one line. */ + signed int eNon_A=0,eTab=0,eTilde=0,eCarat=0,eFSlash=0,eAst=0; + const char *s; + unsigned char c; + for (s=aline;*s;s++) + { + c=*(unsigned char *)s; + if (!eNon_A && (*s127)) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + if (c>127 && c<160) + printf(" Line %ld column %d - " + "Non-ISO-8859 character %d\n",linecnt,(int)(s-aline)+1,c); + else + printf(" Line %ld column %d - Non-ASCII character %d\n", + linecnt,(int)(s-aline)+1,c); + else + cnt_bin++; + eNon_A=1; + } + if (!eTab && *s==CHAR_TAB) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Tab character?\n", + linecnt,(int)(s-aline)+1); + else + cnt_odd++; + eTab=1; + } + if (!eTilde && *s==CHAR_TILDE) + { + /* + * Often used by OCR software to indicate an + * unrecognizable character. + */ + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Tilde character?\n", + linecnt,(int)(s-aline)+1); + else + cnt_odd++; + eTilde=1; + } + if (!eCarat && *s==CHAR_CARAT) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Carat character?\n", + linecnt,(int)(s-aline)+1); + else + cnt_odd++; + eCarat=1; + } + if (!eFSlash && *s==CHAR_FORESLASH && warnings->fslash) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Forward slash?\n", + linecnt,(int)(s-aline)+1); + else + cnt_odd++; + eFSlash=1; + } + /* + * Report asterisks only in paranoid mode, + * since they're often deliberate. + */ + if (!eAst && pswit[PARANOID_SWITCH] && warnings->ast && !isemptyline && + *s==CHAR_ASTERISK) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Asterisk?\n", + linecnt,(int)(s-aline)+1); + else + cnt_odd++; + eAst=1; + } + } +} + +/* * procfile: * * Process one file. @@ -1007,8 +1104,7 @@ struct counters counters={0}; int isemptyline; long squot,start_para_line; - signed int i,j,llen,isacro,isellipsis,istypo,alower, - eNon_A,eTab,eTilde,eAst,eFSlash,eCarat; + signed int i,j,llen,isacro,isellipsis,istypo,alower; unsigned int lastlen,lastblen; signed int dquotepar,squotepar; signed int isnewpara,vowel,consonant; @@ -1227,98 +1323,7 @@ } } if (warnings->bin) - { - /* Don't repeat multiple warnings on one line. */ - eNon_A=eTab=eTilde=eCarat=eFSlash=eAst=0; - for (s=aline;*s;s++) - { - if (!eNon_A && - (*s127)) - { - i=*s; /* annoying kludge for signed chars */ - if (i<0) - i+=256; - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - if (i>127 && i<160) - printf(" Line %ld column %d - " - "Non-ISO-8859 character %d\n", - linecnt,(int)(s-aline)+1,i); - else - printf(" Line %ld column %d - " - "Non-ASCII character %d\n", - linecnt,(int)(s-aline)+1,i); - else - cnt_bin++; - eNon_A=1; - } - if (!eTab && *s==CHAR_TAB) - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Tab character?\n", - linecnt,(int)(s-aline)+1); - else - cnt_odd++; - eTab=1; - } - if (!eTilde && *s==CHAR_TILDE) - { - /* - * Often used by OCR software to indicate an - * unrecognizable character. - */ - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Tilde character?\n", - linecnt,(int)(s-aline)+1); - else - cnt_odd++; - eTilde=1; - } - if (!eCarat && *s==CHAR_CARAT) - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Carat character?\n", - linecnt,(int)(s-aline)+1); - else - cnt_odd++; - eCarat=1; - } - if (!eFSlash && *s==CHAR_FORESLASH && warnings->fslash) - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Forward slash?\n", - linecnt,(int)(s-aline)+1); - else - cnt_odd++; - eFSlash=1; - } - /* - * Report asterisks only in paranoid mode, - * since they're often deliberate. - */ - if (!eAst && pswit[PARANOID_SWITCH] && warnings->ast && - !isemptyline && *s==CHAR_ASTERISK) - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Asterisk?\n", - linecnt,(int)(s-aline)+1); - else - cnt_odd++; - eAst=1; - } - } - } + check_for_odd_characters(aline,warnings,isemptyline); /* Check for line too long. */ if (warnings->longline) {