# HG changeset patch # User ali # Date 1369585428 -3600 # Node ID 8ade5460e2205a5161ea3ca67f43fb9cec67220f # Parent 6b786cc05b3cb4a3a678e44112e0b966da590c70 Break check_for_misspaced_punctuation() out diff -r 6b786cc05b3c -r 8ade5460e220 bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Sun May 26 16:54:06 2013 +0100 +++ b/bookloupe/bookloupe.c Sun May 26 17:23:48 2013 +0100 @@ -1781,6 +1781,252 @@ } } +struct parities { + int dquote,squote; +}; + +/* + * check_for_misspaced_punctuation: + * + * Look for added or missing spaces around punctuation and quotes. + * If there is a punctuation character like ! with no space on + * either side, suspect a missing!space. If there are spaces on + * both sides , assume a typo. If we see a double quote with no + * space or punctuation on either side of it, assume unspaced + * quotes "like"this. + */ +void check_for_misspaced_punctuation(const char *aline, + struct parities *parities,int isemptyline) +{ + int i,llen,isacro,isellipsis; + const char *s; + llen=strlen(aline); + for (i=1;i2 && aline[i-2]=='.') + isacro=1; + if (i+22 && aline[i-2]=='.') + isellipsis=1; + if (i+2dquote=!parities->dquote; + if (!parities->dquote) + { + /* parity even */ + if (!strchr("_-.'`/,;:!?)]} ",s[1])) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - " + "Wrongspaced quotes?\n",linecnt,(int)(s-aline)+1); + else + cnt_punct++; + } + } + else + { + /* parity odd */ + if (!gcisalpha(s[1]) && !isdigit(s[1]) && + !strchr("_-/.'`([{$",s[1]) || !s[1]) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - " + "Wrongspaced quotes?\n",linecnt,(int)(s-aline)+1); + else + cnt_punct++; + } + } + } + } + if (*aline==CHAR_DQUOTE) + { + if (strchr(",;:!?)]} ",aline[1])) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column 1 - Wrongspaced quotes?\n", + linecnt); + else + cnt_punct++; + } + } + if (pswit[SQUOTE_SWITCH]) + { + for (s=aline;*s;s++) + { + if ((*s==CHAR_SQUOTE || *s==CHAR_OPEN_SQUOTE) && + (s==aline || s>aline && !gcisalpha(s[-1]) || + !gcisalpha(s[1]))) + { + parities->squote=!parities->squote; + if (!parities->squote) + { + /* parity even */ + if (!strchr("_-.'`/\",;:!?)]} ",s[1])) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - " + "Wrongspaced singlequotes?\n", + linecnt,(int)(s-aline)+1); + else + cnt_punct++; + } + } + else + { + /* parity odd */ + if (!gcisalpha(s[1]) && !isdigit(s[1]) && + !strchr("_-/\".'`",s[1]) || !s[1]) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - " + "Wrongspaced singlequotes?\n", + linecnt,(int)(s-aline)+1); + else + cnt_punct++; + } + } + } + } + } +} + /* * procfile: * @@ -1795,10 +2041,10 @@ struct warnings *warnings; struct counters counters={0}; struct line_properties last={0}; + struct parities parities={0}; int isemptyline; long squot,start_para_line; signed int i,llen,isacro,isellipsis; - signed int dquotepar,squotepar; signed int isnewpara; char dquote_err[80],squote_err[80],rbrack_err[80],sbrack_err[80], cbrack_err[80],unders_err[80]; @@ -1810,7 +2056,6 @@ squot=0; i=llen=isacro=isellipsis=0; isnewpara=enddash=0; - dquotepar=squotepar=0; infile=fopen(filename,"rb"); if (!infile) { @@ -1946,7 +2191,7 @@ /* Capture its first line in case we want to report it later. */ strncpy(parastart,aline,80); parastart[79]=0; - dquotepar=squotepar=0; /* restart the quote count */ + memset(&parities,0,sizeof(parities)); /* restart the quote count */ s=aline; while (!gcisalpha(*s) && !gcisdigit(*s) && *s) s++; @@ -2022,237 +2267,7 @@ check_for_extra_period(aline,warnings); check_for_following_punctuation(aline); check_for_typos(aline,warnings); - /* - * Look for added or missing spaces around punctuation and quotes. - * If there is a punctuation character like ! with no space on - * either side, suspect a missing!space. If there are spaces on - * both sides , assume a typo. If we see a double quote with no - * space or punctuation on either side of it, assume unspaced - * quotes "like"this. - */ - llen=strlen(aline); - for (i=1;i2 && aline[i-2]=='.') - isacro=1; - if (i+22 && aline[i-2]=='.') - isellipsis=1; - if (i+2aline && !gcisalpha(s[-1]) || - !gcisalpha(s[1]))) - { - if (!(squotepar=!squotepar)) - { - /* parity even */ - if (!strchr("_-.'`/\",;:!?)]} ",s[1])) - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - " - "Wrongspaced singlequotes?\n", - linecnt,(int)(s-aline)+1); - else - cnt_punct++; - } - } - else - { - /* parity odd */ - if (!gcisalpha(s[1]) && !isdigit(s[1]) && - !strchr("_-/\".'`",s[1]) || !s[1]) - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - " - "Wrongspaced singlequotes?\n", - linecnt,(int)(s-aline)+1); - else - cnt_punct++; - } - } - } - } - } + check_for_misspaced_punctuation(aline,&parities,isemptyline); /* * Look for double punctuation like ,. or ,, * Thanks to DW for the suggestion!