Break check_for_extra_period() out
authorali <ali@juiblex.co.uk>
Sun May 26 01:46:33 2013 +0100 (2013-05-26)
changeset 534c8606eb60c1
parent 52 a1fd8d3f0940
child 54 23b2ea51b029
Break check_for_extra_period() out
bookloupe/bookloupe.c
     1.1 --- a/bookloupe/bookloupe.c	Sat May 25 23:57:38 2013 +0100
     1.2 +++ b/bookloupe/bookloupe.c	Sun May 26 01:46:33 2013 +0100
     1.3 @@ -379,7 +379,6 @@
     1.4  #define MAX_QWORD 50
     1.5  #define MAX_QWORD_LENGTH 40
     1.6  char qword[MAX_QWORD][MAX_QWORD_LENGTH];
     1.7 -char qperiod[MAX_QWORD][MAX_QWORD_LENGTH];
     1.8  signed int dupcnt[MAX_QWORD];
     1.9  
    1.10  int main(int argc,char **argv)
    1.11 @@ -1415,13 +1414,115 @@
    1.12  }
    1.13  
    1.14  /*
    1.15 + * check_for_extra_period:
    1.16 + *
    1.17 + * Check for period without a capital letter. Cut-down from gutspell.
    1.18 + * Only works when it happens on a single line.
    1.19 + */
    1.20 +void check_for_extra_period(const char *aline,const struct warnings *warnings)
    1.21 +{
    1.22 +    const char *s,*t,*s1;
    1.23 +    signed int i,istypo,isdup;
    1.24 +    static char qperiod[MAX_QWORD][MAX_QWORD_LENGTH];
    1.25 +    static int qperiod_index=0;
    1.26 +    char testword[MAXWORDLEN]="";
    1.27 +    if (pswit[PARANOID_SWITCH])
    1.28 +    {
    1.29 +	for (t=s=aline;strstr(t,". ");)
    1.30 +	{
    1.31 +	    t=strstr(t,". ");
    1.32 +	    if (t==s)
    1.33 +	    {
    1.34 +		t++;
    1.35 +		/* start of line punctuation is handled elsewhere */
    1.36 +		continue;
    1.37 +	    }
    1.38 +	    if (!gcisalpha(t[-1]))
    1.39 +	    {
    1.40 +		t++;
    1.41 +		continue;
    1.42 +	    }
    1.43 +	    if (warnings->isDutch)
    1.44 +	    {
    1.45 +		/* For Frank & Jeroen -- 's Middags case */
    1.46 +		if (t[2]==CHAR_SQUOTE && t[3]>='a' && t[3]<='z' &&
    1.47 +		  t[4]==CHAR_SPACE && t[5]>='A' && t[5]<='Z')
    1.48 +		{
    1.49 +		    t++;
    1.50 +		    continue;
    1.51 +		}
    1.52 +	    }
    1.53 +	    s1=t+2;
    1.54 +	    while (*s1 && !gcisalpha(*s1) && !isdigit(*s1))
    1.55 +		s1++;
    1.56 +	    if (*s1>='a' && *s1<='z')
    1.57 +	    {
    1.58 +		/* we have something to investigate */
    1.59 +		istypo=1;
    1.60 +		/* so let's go back and find out */
    1.61 +		for (s1=t-1;s1>=s &&
    1.62 +		  (gcisalpha(*s1) || gcisdigit(*s1) || *s1==CHAR_SQUOTE &&
    1.63 +		  gcisalpha(s1[1]) && gcisalpha(s1[-1]));s1--)
    1.64 +		    ;
    1.65 +		s1++;
    1.66 +		for (i=0;*s1 && *s1!='.';s1++,i++)
    1.67 +		    testword[i]=*s1;
    1.68 +		testword[i]=0;
    1.69 +		for (i=0;*abbrev[i];i++)
    1.70 +		    if (!strcmp(testword,abbrev[i]))
    1.71 +			istypo=0;
    1.72 +		if (gcisdigit(*testword))
    1.73 +		    istypo=0;
    1.74 +		if (!testword[1])
    1.75 +		    istypo=0;
    1.76 +		if (isroman(testword))
    1.77 +		    istypo=0;
    1.78 +		if (istypo)
    1.79 +		{
    1.80 +		    istypo=0;
    1.81 +		    for (i=0;testword[i];i++)
    1.82 +			if (strchr(vowels,testword[i]))
    1.83 +			    istypo=1;
    1.84 +		}
    1.85 +		if (istypo)
    1.86 +		{
    1.87 +		    isdup=0;
    1.88 +		    if (strlen(testword)<MAX_QWORD_LENGTH &&
    1.89 +		      !pswit[VERBOSE_SWITCH])
    1.90 +			for (i=0;i<qperiod_index;i++)
    1.91 +			    if (!strcmp(testword,qperiod[i]))
    1.92 +				isdup=1;
    1.93 +		    if (!isdup)
    1.94 +		    {
    1.95 +			if (qperiod_index<MAX_QWORD &&
    1.96 +			  strlen(testword)<MAX_QWORD_LENGTH)
    1.97 +			{
    1.98 +			    strcpy(qperiod[qperiod_index],testword);
    1.99 +			    qperiod_index++;
   1.100 +			}
   1.101 +			if (pswit[ECHO_SWITCH])
   1.102 +			    printf("\n%s\n",aline);
   1.103 +			if (!pswit[OVERVIEW_SWITCH])
   1.104 +			    printf("    Line %ld column %d - Extra period?\n",
   1.105 +			      linecnt,(int)(t-aline)+1);
   1.106 +			else
   1.107 +			    cnt_punct++;
   1.108 +		    }
   1.109 +		}
   1.110 +	    }
   1.111 +	    t++;
   1.112 +	}
   1.113 +    }
   1.114 +}
   1.115 +
   1.116 +/*
   1.117   * procfile:
   1.118   *
   1.119   * Process one file.
   1.120   */
   1.121  void procfile(char *filename)
   1.122  {
   1.123 -    char *s,*t,*s1,*wordstart;
   1.124 +    char *s,*t,*wordstart;
   1.125      char inword[MAXWORDLEN],testword[MAXWORDLEN];
   1.126      char parastart[81];     /* first line of current para */
   1.127      FILE *infile;
   1.128 @@ -1431,32 +1532,23 @@
   1.129      struct line_properties last={0};
   1.130      int isemptyline;
   1.131      long squot,start_para_line;
   1.132 -    signed int i,j,llen,isacro,isellipsis,istypo,alower;
   1.133 +    signed int i,llen,isacro,isellipsis,istypo,alower;
   1.134      signed int dquotepar,squotepar;
   1.135      signed int isnewpara,vowel,consonant;
   1.136      char dquote_err[80],squote_err[80],rbrack_err[80],sbrack_err[80],
   1.137        cbrack_err[80],unders_err[80];
   1.138 -    signed int qword_index,qperiod_index,isdup;
   1.139 +    signed int qword_index,isdup;
   1.140      signed int enddash;
   1.141      last.start=CHAR_SPACE;
   1.142      *dquote_err=*squote_err=*rbrack_err=*cbrack_err=*sbrack_err=
   1.143        *unders_err=*prevline=0;
   1.144      linecnt=checked_linecnt=start_para_line=0;
   1.145      squot=0;
   1.146 -    i=llen=isacro=isellipsis=istypo=0;
   1.147 +    i=llen=isacro=isellipsis=0;
   1.148      isnewpara=vowel=consonant=enddash=0;
   1.149 -    qword_index=qperiod_index=isdup=0;
   1.150 +    qword_index=0;
   1.151      *inword=*testword=0;
   1.152      dquotepar=squotepar=0;
   1.153 -    for (j=0;j<MAX_QWORD;j++)
   1.154 -    {
   1.155 -        dupcnt[j]=0;
   1.156 -        for (i=0;i<MAX_QWORD_LENGTH;i++)
   1.157 -	{
   1.158 -            qword[i][j]=0;
   1.159 -            qperiod[i][j]=0;
   1.160 -	}
   1.161 -    }
   1.162      infile=fopen(filename,"rb");
   1.163      if (!infile)
   1.164      {
   1.165 @@ -1665,97 +1757,7 @@
   1.166  	check_for_mta_from(aline);
   1.167  	check_for_orphan_character(aline);
   1.168  	check_for_pling_scanno(aline);
   1.169 -        /*
   1.170 -	 * Check for period without a capital letter. Cut-down from gutspell.
   1.171 -         * Only works when it happens on a single line.
   1.172 -	 */
   1.173 -        if (pswit[PARANOID_SWITCH])
   1.174 -	{
   1.175 -            for (t=s=aline;strstr(t,". ");)
   1.176 -	    {
   1.177 -                t=strstr(t,". ");
   1.178 -                if (t==s)
   1.179 -		{
   1.180 -                    t++;
   1.181 -		    /* start of line punctuation is handled elsewhere */
   1.182 -                    continue;
   1.183 -		}
   1.184 -                if (!gcisalpha(t[-1]))
   1.185 -		{
   1.186 -                    t++;
   1.187 -                    continue;
   1.188 -		}
   1.189 -                if (warnings->isDutch)
   1.190 -		{
   1.191 -		    /* For Frank & Jeroen -- 's Middags case */
   1.192 -                    if (t[2]==CHAR_SQUOTE && t[3]>='a' && t[3]<='z' &&
   1.193 -		      t[4]==CHAR_SPACE && t[5]>='A' && t[5]<='Z')
   1.194 -		    {
   1.195 -                        t++;
   1.196 -                        continue;
   1.197 -		    }
   1.198 -		}
   1.199 -                s1=t+2;
   1.200 -                while (*s1 && !gcisalpha(*s1) && !isdigit(*s1))
   1.201 -                    s1++;
   1.202 -                if (*s1>='a' && *s1<='z')
   1.203 -		{
   1.204 -		    /* we have something to investigate */
   1.205 -                    istypo=1;
   1.206 -		    /* so let's go back and find out */
   1.207 -                    for (s1=t-1;s1>=s &&
   1.208 -		      (gcisalpha(*s1) || gcisdigit(*s1) || *s1==CHAR_SQUOTE &&
   1.209 -		      gcisalpha(s1[1]) && gcisalpha(s1[-1]));s1--)
   1.210 -			;
   1.211 -                    s1++;
   1.212 -                    for (i=0;*s1 && *s1!='.';s1++,i++)
   1.213 -                        testword[i]=*s1;
   1.214 -                    testword[i]=0;
   1.215 -                    for (i=0;*abbrev[i];i++)
   1.216 -                        if (!strcmp(testword,abbrev[i]))
   1.217 -                            istypo=0;
   1.218 -                    if (gcisdigit(*testword))
   1.219 -			istypo=0;
   1.220 -                    if (!testword[1])
   1.221 -			istypo=0;
   1.222 -                    if (isroman(testword))
   1.223 -			istypo=0;
   1.224 -                    if (istypo)
   1.225 -		    {
   1.226 -                        istypo=0;
   1.227 -                        for (i=0;testword[i];i++)
   1.228 -                            if (strchr(vowels,testword[i]))
   1.229 -                                istypo=1;
   1.230 -		    }
   1.231 -                    if (istypo)
   1.232 -		    {
   1.233 -                        isdup=0;
   1.234 -                        if (strlen(testword)<MAX_QWORD_LENGTH &&
   1.235 -			  !pswit[VERBOSE_SWITCH])
   1.236 -                            for (i=0;i<qperiod_index;i++)
   1.237 -                                if (!strcmp(testword,qperiod[i]))
   1.238 -                                    isdup=1;
   1.239 -                        if (!isdup)
   1.240 -			{
   1.241 -                            if (qperiod_index<MAX_QWORD &&
   1.242 -			      strlen(testword)<MAX_QWORD_LENGTH)
   1.243 -			    {
   1.244 -                                strcpy(qperiod[qperiod_index],testword);
   1.245 -                                qperiod_index++;
   1.246 -			    }
   1.247 -                            if (pswit[ECHO_SWITCH])
   1.248 -				printf("\n%s\n",aline);
   1.249 -                            if (!pswit[OVERVIEW_SWITCH])
   1.250 -                                printf("    Line %ld column %d - "
   1.251 -				  "Extra period?\n",linecnt,(int)(t-aline)+1);
   1.252 -                            else
   1.253 -                                cnt_punct++;
   1.254 -			}
   1.255 -		    }
   1.256 -		}
   1.257 -	    t++;
   1.258 -	    }
   1.259 -	}
   1.260 +	check_for_extra_period(aline,warnings);
   1.261          if (pswit[TYPO_SWITCH])
   1.262  	{
   1.263              /* Check for words usually not followed by punctuation. */