# HG changeset patch # User ali # Date 1369510176 -3600 # Node ID 7522c36859d0bbff706d966be88fb62adeae69ad # Parent aa45307a63289800a556d9ab73c9ca0df395a1f9 Break check_for_spaced_emdash() and check_for_spaced_dash() out diff -r aa45307a6328 -r 7522c36859d0 bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Sat May 25 19:35:44 2013 +0100 +++ b/bookloupe/bookloupe.c Sat May 25 20:29:36 2013 +0100 @@ -1171,6 +1171,71 @@ } /* + * check_for_spaced_emdash: + * + * Check for spaced em-dashes. + * + * We must check _all_ occurrences of "--" on the line + * hence the loop - even if the first double-dash is OK + * there may be another that's wrong later on. + */ +void check_for_spaced_emdash(const char *aline) +{ + const char *s,*t; + s=aline; + while ((t=strstr(s,"--"))) + { + if (t>aline && t[-1]==CHAR_SPACE || t[2]==CHAR_SPACE) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Spaced em-dash?\n", + linecnt,(int)(t-aline)+1); + else + cnt_dash++; + } + s=t+2; + } +} + +/* + * check_for_spaced_dash: + * + * Check for spaced dashes. + */ +void check_for_spaced_dash(const char *aline) +{ + const char *s; + if ((s=strstr(aline," -"))) + { + if (s[2]!='-') + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Spaced dash?\n", + linecnt,(int)(s-aline)+1); + else + cnt_dash++; + } + } + else if ((s=strstr(aline,"- "))) + { + if (s==aline || s[-1]!='-') + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Spaced dash?\n", + linecnt,(int)(s-aline)+1); + else + cnt_dash++; + } + } +} + +/* * procfile: * * Process one file. @@ -1411,60 +1476,10 @@ last.len=strlen(aline); last.start=aline[0]; check_for_starting_punctuation(aline); - /* - * Check for spaced em-dashes. - * We must check _all_ occurrences of "--" on the line - * hence the loop - even if the first double-dash is OK - * there may be another that's wrong later on. - */ if (warnings->dash) { - s=aline; - while (strstr(s,"--")) - { - if (*(strstr(s,"--")-1)==CHAR_SPACE || - (*(strstr(s,"--")+2)==CHAR_SPACE)) - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Spaced em-dash?\n", - linecnt,(int)(strstr(s,"--")-aline)+1); - else - cnt_dash++; - } - s=strstr(s,"--")+2; - } - } - /* Check for spaced dashes. */ - if (warnings->dash) - { - if (strstr(aline," -")) - { - if (*(strstr(aline," -")+2)!='-') - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Spaced dash?\n", - linecnt,(int)(strstr(aline," -")-aline)+1); - else - cnt_dash++; - } - } - else if (strstr(aline,"- ")) - { - if (*(strstr(aline,"- ")-1)!='-') - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Spaced dash?\n", - linecnt,(int)(strstr(aline,"- ")-aline)+1); - else - cnt_dash++; - } - } + check_for_spaced_emdash(aline); + check_for_spaced_dash(aline); } /* * Check for unmarked paragraphs indicated by separate speakers.