# HG changeset patch # User ali # Date 1369506471 -3600 # Node ID d48f66b0ad0d825522aa8a19d46570be07e21454 # Parent 66483ebc9b56d940520437399f95e43cc30e483a Break check_for_long_line() and check_for_short_line() out diff -r 66483ebc9b56 -r d48f66b0ad0d bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Sat May 25 19:14:21 2013 +0100 +++ b/bookloupe/bookloupe.c Sat May 25 19:27:51 2013 +0100 @@ -1089,31 +1089,93 @@ } /* + * check_for_long_line: + * + * Check for line too long. + */ +void check_for_long_line(const char *aline) +{ + if (strlen(aline)>LONGEST_PG_LINE) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",aline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Long line %d\n", + linecnt,strlen(aline),strlen(aline)); + else + cnt_long++; + } +} + +struct line_properties { + unsigned int len,blen; + char start; +}; + +/* + * check_for_short_line: + * + * Check for line too short. + * + * This one is a bit trickier to implement: we don't want to + * flag the last line of a paragraph for being short, so we + * have to wait until we know that our current line is a + * "normal" line, then report the _previous_ line if it was too + * short. We also don't want to report indented lines like + * chapter heads or formatted quotations. We therefore keep + * last->len as the length of the last line examined, and + * last->blen as the length of the last but one, and try to + * suppress unnecessary warnings by checking that both were of + * "normal" length. We keep the first character of the last + * line in last->start, and if it was a space, we assume that + * the formatting is deliberate. I can't figure out a way to + * distinguish something like a quoted verse left-aligned or + * the header or footer of a letter from a paragraph of short + * lines - maybe if I examined the whole paragraph, and if the + * para has less than, say, 8 lines and if all lines are short, + * then just assume it's OK? Need to look at some texts to see + * how often a formula like this would get the right result. + */ +void check_for_short_line(const char *aline,const struct line_properties *last) +{ + if (strlen(aline)>1 && last->len>1 && last->lenblen>1 && last->blen>SHORTEST_PG_LINE && last->start!=CHAR_SPACE) + { + if (pswit[ECHO_SWITCH]) + printf("\n%s\n",prevline); + if (!pswit[OVERVIEW_SWITCH]) + printf(" Line %ld column %d - Short line %d?\n", + linecnt-1,strlen(prevline),strlen(prevline)); + else + cnt_short++; + } +} + +/* * procfile: * * Process one file. */ void procfile(char *filename) { - char *s,*t,*s1,laststart,*wordstart; + char *s,*t,*s1,*wordstart; char inword[MAXWORDLEN],testword[MAXWORDLEN]; char parastart[81]; /* first line of current para */ FILE *infile; struct first_pass_results *first_pass_results; struct warnings *warnings; struct counters counters={0}; + struct line_properties last={0}; int isemptyline; long squot,start_para_line; signed int i,j,llen,isacro,isellipsis,istypo,alower; - unsigned int lastlen,lastblen; signed int dquotepar,squotepar; signed int isnewpara,vowel,consonant; char dquote_err[80],squote_err[80],rbrack_err[80],sbrack_err[80], cbrack_err[80],unders_err[80]; signed int qword_index,qperiod_index,isdup; signed int enddash; - laststart=CHAR_SPACE; - lastlen=lastblen=0; + last.start=CHAR_SPACE; *dquote_err=*squote_err=*rbrack_err=*cbrack_err=*sbrack_err= *unders_err=*prevline=0; linecnt=checked_linecnt=start_para_line=0; @@ -1150,8 +1212,6 @@ * Re-init some variables we've dirtied. */ squot=linecnt=0; - laststart=CHAR_SPACE; - lastlen=lastblen=0; while (flgets(aline,LINEBUFSIZE-1,infile,linecnt+1)) { linecnt++; @@ -1324,56 +1384,13 @@ } if (warnings->bin) check_for_odd_characters(aline,warnings,isemptyline); - /* Check for line too long. */ if (warnings->longline) - { - if (strlen(aline)>LONGEST_PG_LINE) - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",aline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Long line %d\n", - linecnt,strlen(aline),strlen(aline)); - else - cnt_long++; - } - } - /* - * Check for line too short. - * This one is a bit trickier to implement: we don't want to - * flag the last line of a paragraph for being short, so we - * have to wait until we know that our current line is a - * "normal" line, then report the _previous_ line if it was too - * short. We also don't want to report indented lines like - * chapter heads or formatted quotations. We therefore keep - * lastlen as the length of the last line examined, and - * lastblen as the length of the last but one, and try to - * suppress unnecessary warnings by checking that both were of - * "normal" length. We keep the first character of the last - * line in laststart, and if it was a space, we assume that the - * formatting is deliberate. I can't figure out a way to - * distinguish something like a quoted verse left-aligned or - * the header or footer of a letter from a paragraph of short - * lines - maybe if I examined the whole paragraph, and if the - * para has less than, say, 8 lines and if all lines are short, - * then just assume it's OK? Need to look at some texts to see - * how often a formula like this would get the right result. - */ - if (warnings->shortline && strlen(aline)>1 && lastlen>1 && - lastlen1 && lastblen>SHORTEST_PG_LINE && - laststart!=CHAR_SPACE) - { - if (pswit[ECHO_SWITCH]) - printf("\n%s\n",prevline); - if (!pswit[OVERVIEW_SWITCH]) - printf(" Line %ld column %d - Short line %d?\n", - linecnt-1,strlen(prevline),strlen(prevline)); - else - cnt_short++; - } - lastblen=lastlen; - lastlen=strlen(aline); - laststart=aline[0]; + check_for_long_line(aline); + if (warnings->shortline) + check_for_short_line(aline,&last); + last.blen=last.len; + last.len=strlen(aline); + last.start=aline[0]; /* Look for punctuation other than full ellipses at start of line. */ if (*aline && strchr(".?!,;:",aline[0]) && strncmp(". . .",aline,5)) { @@ -2468,7 +2485,7 @@ * If we say "start_para_line < linecnt - 1" it doesn't, but then it * misses genuine one-line paragraphs. */ - if (i && lastblen>2 && start_para_line2 && start_para_lineCHAR_SPACE) { for (i=strlen(prevline)-1;