bookloupe/bookloupe.c
author ali <ali@juiblex.co.uk>
Sun May 26 22:43:45 2013 +0100 (2013-05-26)
changeset 67 865063352146
parent 66 a5ef278feb34
child 68 adb087007d08
permissions -rw-r--r--
Break check_for_control_characters() out
ali@0
     1
/*************************************************************************/
ali@40
     2
/* bookloupe--check for assorted weirdnesses in a PG candidate text file */
ali@0
     3
/*                                                                       */
ali@0
     4
/* Copyright 2000-2005 Jim Tinsley <jtinsley@pobox.com>                  */
ali@40
     5
/* Copyright 2012- J. Ali Harlow <ali@juiblex.co.uk>                     */
ali@0
     6
/*                                                                       */
ali@0
     7
/* This program is free software; you can redistribute it and/or modify  */
ali@0
     8
/* it under the terms of the GNU General Public License as published by  */
ali@0
     9
/* the Free Software Foundation; either version 2 of the License, or     */
ali@0
    10
/* (at your option) any later version.                                   */
ali@0
    11
/*                                                                       */
ali@0
    12
/* This program is distributed in the hope that it will be useful,       */
ali@0
    13
/* but WITHOUT ANY WARRANTY; without even the implied warranty of        */
ali@40
    14
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          */
ali@0
    15
/* GNU General Public License for more details.                          */
ali@0
    16
/*                                                                       */
ali@0
    17
/* You should have received a copy of the GNU General Public License     */
ali@40
    18
/* along with this program. If not, see <http://www.gnu.org/licenses/>.  */
ali@0
    19
/*************************************************************************/
ali@0
    20
ali@0
    21
#include <stdio.h>
ali@0
    22
#include <stdlib.h>
ali@0
    23
#include <string.h>
ali@0
    24
#include <ctype.h>
ali@0
    25
ali@0
    26
#define MAXWORDLEN    80    /* max length of one word             */
ali@0
    27
#define LINEBUFSIZE 2048    /* buffer size for an input line      */
ali@0
    28
ali@0
    29
#define MAX_USER_TYPOS 1000
ali@0
    30
#define USERTYPO_FILE "gutcheck.typ"
ali@0
    31
ali@0
    32
#ifndef MAX_PATH
ali@0
    33
#define MAX_PATH 16384
ali@0
    34
#endif
ali@0
    35
ali@0
    36
char aline[LINEBUFSIZE];
ali@0
    37
char prevline[LINEBUFSIZE];
ali@0
    38
ali@40
    39
/* Common typos. */
ali@40
    40
char *typo[] = {
ali@40
    41
    "teh", "th", "og", "fi", "ro", "adn", "yuo", "ot", "fo", "thet", "ane",
ali@40
    42
    "nad", "te", "ig", "acn",  "ahve", "alot", "anbd", "andt", "awya", "aywa",
ali@40
    43
    "bakc", "om", "btu", "byt", "cna", "cxan", "coudl", "dont", "didnt",
ali@40
    44
    "couldnt", "wouldnt", "doesnt", "shouldnt", "doign", "ehr", "hmi", "hse",
ali@40
    45
    "esle", "eyt", "fitrs", "firts", "foudn", "frmo", "fromt", "fwe", "gaurd",
ali@40
    46
    "gerat", "goign", "gruop", "haev", "hda", "hearign", "seeign", "sayign",
ali@40
    47
    "herat", "hge", "hsa", "hsi", "hte", "htere", "htese", "htey", "htis",
ali@40
    48
    "hvae", "hwich", "idae", "ihs", "iits", "int", "iwll", "iwth", "jsut",
ali@40
    49
    "loev", "sefl", "myu", "nkow", "nver", "nwe", "nwo", "ocur", "ohter",
ali@40
    50
    "omre", "onyl", "otehr", "otu", "owrk", "owuld", "peice", "peices",
ali@40
    51
    "peolpe", "peopel", "perhasp", "perhpas", "pleasent", "poeple", "porblem",
ali@40
    52
    "porblems", "rwite", "saidt", "saidh", "saids", "seh", "smae", "smoe",
ali@40
    53
    "sohw", "stnad", "stopry", "stoyr", "stpo", "tahn", "taht", "tath",
ali@40
    54
    "tehy", "tghe", "tghis", "theri", "theyll", "thgat", "thge", "thier",
ali@40
    55
    "thna", "thne", "thnig", "thnigs", "thsi", "thsoe", "thta", "timne",
ali@40
    56
    "tirne", "tkae", "tthe", "tyhat", "tyhe", "veyr", "vou", "vour", "vrey",
ali@40
    57
    "waht", "wasnt", "awtn", "watn", "wehn", "whic", "whcih", "whihc", "whta",
ali@40
    58
    "wihch", "wief", "wiht", "witha", "wiull", "wnat", "wnated", "wnats",
ali@40
    59
    "woh", "wohle", "wokr", "woudl", "wriet", "wrod", "wroet", "wroking",
ali@40
    60
    "wtih", "wuould", "wya", "yera", "yeras", "yersa", "yoiu", "youve",
ali@40
    61
    "ytou", "yuor", "abead", "ahle", "ahout", "ahove", "altbough", "balf",
ali@40
    62
    "bardly", "bas", "bave", "baving", "bebind", "beld", "belp", "belped",
ali@40
    63
    "ber", "bere", "bim", "bis", "bome", "bouse", "bowever", "buge",
ali@40
    64
    "dehates", "deht", "han", "hecause", "hecome", "heen", "hefore", "hegan",
ali@40
    65
    "hegin", "heing", "helieve", "henefit", "hetter", "hetween", "heyond",
ali@40
    66
    "hig", "higber", "huild", "huy", "hy", "jobn", "joh", "meanwbile",
ali@40
    67
    "memher", "memhers", "numher", "numhers", "perbaps", "prohlem", "puhlic",
ali@40
    68
    "witbout", "arn", "hin", "hirn", "wrok", "wroked", "amd", "aud",
ali@40
    69
    "prornise", "prornised", "modem", "bo", "heside", "chapteb", "chaptee",
ali@40
    70
    "se", ""
ali@40
    71
};
ali@0
    72
ali@0
    73
char *usertypo[MAX_USER_TYPOS];
ali@0
    74
ali@40
    75
/* Common abbreviations and other OK words not to query as typos. */
ali@40
    76
char *okword[] = {
ali@40
    77
    "mr", "mrs", "mss", "mssrs", "ft", "pm", "st", "dr", "hmm", "h'm", "hmmm",
ali@40
    78
    "rd", "sh", "br", "pp", "hm", "cf", "jr", "sr", "vs", "lb", "lbs", "ltd",
ali@40
    79
    "pompeii","hawaii","hawaiian", "hotbed", "heartbeat", "heartbeats",
ali@40
    80
    "outbid", "outbids", "frostbite", "frostbitten", ""
ali@40
    81
};
ali@0
    82
ali@40
    83
/* Common abbreviations that cause otherwise unexplained periods. */
ali@40
    84
char *abbrev[] = {
ali@40
    85
    "cent", "cents", "viz", "vol", "vols", "vid", "ed", "al", "etc", "op",
ali@40
    86
    "cit", "deg", "min", "chap", "oz", "mme", "mlle", "mssrs", ""
ali@40
    87
};
ali@0
    88
ali@40
    89
/*
ali@40
    90
 * Two-Letter combinations that rarely if ever start words,
ali@40
    91
 * but are common scannos or otherwise common letter combinations.
ali@40
    92
 */
ali@40
    93
char *nostart[] = {
ali@40
    94
    "hr", "hl", "cb", "sb", "tb", "wb", "tl", "tn", "rn", "lt", "tj", ""
ali@40
    95
};
ali@0
    96
ali@40
    97
/*
ali@40
    98
 * Two-Letter combinations that rarely if ever end words,
ali@40
    99
 * but are common scannos or otherwise common letter combinations.
ali@40
   100
 */
ali@40
   101
char *noend[] = {
ali@40
   102
    "cb", "gb", "pb", "sb", "tb", "wh", "fr", "br", "qu", "tw", "gl", "fl",
ali@40
   103
    "sw", "gr", "sl", "cl", "iy", ""
ali@40
   104
};
ali@0
   105
ali@40
   106
char *markup[] = {
ali@40
   107
    "a", "b", "big", "blockquote", "body", "br", "center", "col", "div", "em",
ali@40
   108
    "font", "h1", "h2", "h3", "h4", "h5", "h6", "head", "hr", "html", "i",
ali@40
   109
    "img", "li", "meta", "ol", "p", "pre", "small", "span", "strong", "sub",
ali@40
   110
    "sup", "table", "td", "tfoot", "thead", "title", "tr", "tt", "u", "ul", ""
ali@40
   111
};
ali@0
   112
ali@40
   113
char *DPmarkup[] = {
ali@40
   114
    "<sc>", "</sc>", "/*", "*/", "/#", "#/", "/$", "$/", "<tb>", ""
ali@40
   115
};
ali@0
   116
ali@40
   117
char *nocomma[] = {
ali@40
   118
    "the", "it's", "their", "an", "mrs", "a", "our", "that's", "its", "whose",
ali@40
   119
    "every", "i'll", "your", "my", "mr", "mrs", "mss", "mssrs", "ft", "pm",
ali@40
   120
    "st", "dr", "rd", "pp", "cf", "jr", "sr", "vs", "lb", "lbs", "ltd", "i'm",
ali@40
   121
    "during", "let", "toward", "among", ""
ali@40
   122
};
ali@0
   123
ali@40
   124
char *noperiod[] = {
ali@40
   125
    "every", "i'm", "during", "that's", "their", "your", "our", "my", "or",
ali@40
   126
    "and", "but", "as", "if", "the", "its", "it's", "until", "than", "whether",
ali@40
   127
    "i'll", "whose", "who", "because", "when", "let", "till", "very", "an",
ali@40
   128
    "among", "those", "into", "whom", "having", "thence", ""
ali@40
   129
}; 
ali@0
   130
ali@40
   131
char vowels[] = "aeiouàáâãäæèéêëìíîïòóôõöùúûü";
ali@0
   132
ali@0
   133
struct {
ali@0
   134
    char *htmlent;
ali@0
   135
    char *htmlnum;
ali@0
   136
    char *textent;
ali@40
   137
} entities[] = {
ali@40
   138
    "&amp;",	"&#38;",     "&", 
ali@40
   139
    "&lt;",	"&#60;",     "<",
ali@40
   140
    "&gt;",	"&#62;",     ">",
ali@40
   141
    "&deg;",	"&#176;",    " degrees",
ali@40
   142
    "&pound;",	"&#163;",    "L",
ali@40
   143
    "&quot;",	"&#34;",     "\"", /* quotation mark = APL quote */
ali@40
   144
    "&OElig;",	"&#338;",    "OE", /* latin capital ligature OE */
ali@40
   145
    "&oelig;",	"&#339;",    "oe", /* latin small ligature oe */
ali@40
   146
    "&Scaron;",	"&#352;",    "S", /* latin capital letter S with caron */
ali@40
   147
    "&scaron;",	"&#353;",    "s", /* latin small letter s with caron */
ali@40
   148
    "&Yuml;",	"&#376;",    "Y", /* latin capital letter Y with diaeresis */
ali@40
   149
    "&circ;",	"&#710;",    "",  /* modifier letter circumflex accent */
ali@40
   150
    "&tilde;",	"&#732;",    "~", /* small tilde, U+02DC ISOdia */
ali@40
   151
    "&ensp;",	"&#8194;",   " ", /* en space, U+2002 ISOpub */
ali@40
   152
    "&emsp;",	"&#8195;",   " ", /* em space, U+2003 ISOpub */
ali@40
   153
    "&thinsp;",	"&#8201;",   " ", /* thin space, U+2009 ISOpub */
ali@40
   154
    "&ndash;",	"&#8211;",   "-", /* en dash, U+2013 ISOpub */
ali@40
   155
    "&mdash;",	"&#8212;",   "--", /* em dash, U+2014 ISOpub */
ali@40
   156
    "&rsquo;",	"&#8217;",   "'", /* right single quotation mark */
ali@40
   157
    "&sbquo;",	"&#8218;",   "'", /* single low-9 quotation mark */
ali@40
   158
    "&ldquo;",	"&#8220;",   "\"", /* left double quotation mark */
ali@40
   159
    "&rdquo;",	"&#8221;",   "\"", /* right double quotation mark */
ali@40
   160
    "&bdquo;",	"&#8222;",   "\"", /* double low-9 quotation mark */
ali@40
   161
    "&lsaquo;",	"&#8249;",   "\"", /* single left-pointing angle quotation mark */
ali@40
   162
    "&rsaquo;",	"&#8250;",   "\"", /* single right-pointing angle quotation mark */
ali@40
   163
    "&nbsp;",	"&#160;",    " ", /* no-break space = non-breaking space, */
ali@40
   164
    "&iexcl;",	"&#161;",    "!", /* inverted exclamation mark */
ali@40
   165
    "&cent;",	"&#162;",    "c", /* cent sign */
ali@40
   166
    "&pound;",	"&#163;",    "L", /* pound sign */
ali@40
   167
    "&curren;",	"&#164;",    "$", /* currency sign */
ali@40
   168
    "&yen;",	"&#165;",    "Y", /* yen sign = yuan sign */
ali@40
   169
    "&sect;",	"&#167;",    "--", /* section sign */
ali@40
   170
    "&uml;",	"&#168;",    " ", /* diaeresis = spacing diaeresis */
ali@40
   171
    "&copy;",	"&#169;",    "(C) ", /* copyright sign */
ali@40
   172
    "&ordf;",	"&#170;",    " ", /* feminine ordinal indicator */
ali@40
   173
    "&laquo;",	"&#171;",    "\"", /* left-pointing double angle quotation mark */
ali@40
   174
    "&shy;",	"&#173;",    "-", /* soft hyphen = discretionary hyphen */
ali@40
   175
    "&reg;",	"&#174;",    "(R) ", /* registered sign = registered trade mark sign */
ali@40
   176
    "&macr;",	"&#175;",    " ", /* macron = spacing macron = overline */
ali@40
   177
    "&deg;",	"&#176;",    " degrees", /* degree sign */
ali@40
   178
    "&plusmn;",	"&#177;",    "+-", /* plus-minus sign = plus-or-minus sign */
ali@40
   179
    "&sup2;",	"&#178;",    "2", /* superscript two = superscript digit two */
ali@40
   180
    "&sup3;",	"&#179;",    "3", /* superscript three = superscript digit three */
ali@40
   181
    "&acute;",	"&#180;",    " ", /* acute accent = spacing acute */
ali@40
   182
    "&micro;",	"&#181;",    "m", /* micro sign */
ali@40
   183
    "&para;",	"&#182;",    "--", /* pilcrow sign = paragraph sign */
ali@40
   184
    "&cedil;",	"&#184;",    " ", /* cedilla = spacing cedilla */
ali@40
   185
    "&sup1;",	"&#185;",    "1", /* superscript one = superscript digit one */
ali@40
   186
    "&ordm;",	"&#186;",    " ", /* masculine ordinal indicator */
ali@40
   187
    "&raquo;",	"&#187;",    "\"", /* right-pointing double angle quotation mark */
ali@40
   188
    "&frac14;",	"&#188;",    "1/4", /* vulgar fraction one quarter */
ali@40
   189
    "&frac12;",	"&#189;",    "1/2", /* vulgar fraction one half */
ali@40
   190
    "&frac34;",	"&#190;",    "3/4", /* vulgar fraction three quarters */
ali@40
   191
    "&iquest;",	"&#191;",    "?", /* inverted question mark */
ali@40
   192
    "&Agrave;",	"&#192;",    "A", /* latin capital letter A with grave */
ali@40
   193
    "&Aacute;",	"&#193;",    "A", /* latin capital letter A with acute */
ali@40
   194
    "&Acirc;",	"&#194;",    "A", /* latin capital letter A with circumflex */
ali@40
   195
    "&Atilde;",	"&#195;",    "A", /* latin capital letter A with tilde */
ali@40
   196
    "&Auml;",	"&#196;",    "A", /* latin capital letter A with diaeresis */
ali@40
   197
    "&Aring;",	"&#197;",    "A", /* latin capital letter A with ring above */
ali@40
   198
    "&AElig;",	"&#198;",    "AE", /* latin capital letter AE */
ali@40
   199
    "&Ccedil;",	"&#199;",    "C", /* latin capital letter C with cedilla */
ali@40
   200
    "&Egrave;",	"&#200;",    "E", /* latin capital letter E with grave */
ali@40
   201
    "&Eacute;",	"&#201;",    "E", /* latin capital letter E with acute */
ali@40
   202
    "&Ecirc;",	"&#202;",    "E", /* latin capital letter E with circumflex */
ali@40
   203
    "&Euml;",	"&#203;",    "E", /* latin capital letter E with diaeresis */
ali@40
   204
    "&Igrave;",	"&#204;",    "I", /* latin capital letter I with grave */
ali@40
   205
    "&Iacute;",	"&#205;",    "I", /* latin capital letter I with acute */
ali@40
   206
    "&Icirc;",	"&#206;",    "I", /* latin capital letter I with circumflex */
ali@40
   207
    "&Iuml;",	"&#207;",    "I", /* latin capital letter I with diaeresis */
ali@40
   208
    "&ETH;",	"&#208;",    "E", /* latin capital letter ETH */
ali@40
   209
    "&Ntilde;",	"&#209;",    "N", /* latin capital letter N with tilde */
ali@40
   210
    "&Ograve;",	"&#210;",    "O", /* latin capital letter O with grave */
ali@40
   211
    "&Oacute;",	"&#211;",    "O", /* latin capital letter O with acute */
ali@40
   212
    "&Ocirc;",	"&#212;",    "O", /* latin capital letter O with circumflex */
ali@40
   213
    "&Otilde;",	"&#213;",    "O", /* latin capital letter O with tilde */
ali@40
   214
    "&Ouml;",	"&#214;",    "O", /* latin capital letter O with diaeresis */
ali@40
   215
    "&times;",	"&#215;",    "*", /* multiplication sign */
ali@40
   216
    "&Oslash;",	"&#216;",    "O", /* latin capital letter O with stroke */
ali@40
   217
    "&Ugrave;",	"&#217;",    "U", /* latin capital letter U with grave */
ali@40
   218
    "&Uacute;",	"&#218;",    "U", /* latin capital letter U with acute */
ali@40
   219
    "&Ucirc;",	"&#219;",    "U", /* latin capital letter U with circumflex */
ali@40
   220
    "&Uuml;",	"&#220;",    "U", /* latin capital letter U with diaeresis */
ali@40
   221
    "&Yacute;",	"&#221;",    "Y", /* latin capital letter Y with acute */
ali@40
   222
    "&THORN;",	"&#222;",    "TH", /* latin capital letter THORN */
ali@40
   223
    "&szlig;",	"&#223;",    "sz", /* latin small letter sharp s = ess-zed */
ali@40
   224
    "&agrave;",	"&#224;",    "a", /* latin small letter a with grave */
ali@40
   225
    "&aacute;",	"&#225;",    "a", /* latin small letter a with acute */
ali@40
   226
    "&acirc;",	"&#226;",    "a", /* latin small letter a with circumflex */
ali@40
   227
    "&atilde;",	"&#227;",    "a", /* latin small letter a with tilde */
ali@40
   228
    "&auml;",	"&#228;",    "a", /* latin small letter a with diaeresis */
ali@40
   229
    "&aring;",	"&#229;",    "a", /* latin small letter a with ring above */
ali@40
   230
    "&aelig;",	"&#230;",    "ae", /* latin small letter ae */
ali@40
   231
    "&ccedil;",	"&#231;",    "c", /* latin small letter c with cedilla */
ali@40
   232
    "&egrave;",	"&#232;",    "e", /* latin small letter e with grave */
ali@40
   233
    "&eacute;",	"&#233;",    "e", /* latin small letter e with acute */
ali@40
   234
    "&ecirc;",	"&#234;",    "e", /* latin small letter e with circumflex */
ali@40
   235
    "&euml;",	"&#235;",    "e", /* latin small letter e with diaeresis */
ali@40
   236
    "&igrave;",	"&#236;",    "i", /* latin small letter i with grave */
ali@40
   237
    "&iacute;",	"&#237;",    "i", /* latin small letter i with acute */
ali@40
   238
    "&icirc;",	"&#238;",    "i", /* latin small letter i with circumflex */
ali@40
   239
    "&iuml;",	"&#239;",    "i", /* latin small letter i with diaeresis */
ali@40
   240
    "&eth;",	"&#240;",    "eth", /* latin small letter eth */
ali@40
   241
    "&ntilde;",	"&#241;",    "n", /* latin small letter n with tilde */
ali@40
   242
    "&ograve;",	"&#242;",    "o", /* latin small letter o with grave */
ali@40
   243
    "&oacute;",	"&#243;",    "o", /* latin small letter o with acute */
ali@40
   244
    "&ocirc;",	"&#244;",    "o", /* latin small letter o with circumflex */
ali@40
   245
    "&otilde;",	"&#245;",    "o", /* latin small letter o with tilde */
ali@40
   246
    "&ouml;",	"&#246;",    "o", /* latin small letter o with diaeresis */
ali@40
   247
    "&divide;",	"&#247;",    "/", /* division sign */
ali@40
   248
    "&oslash;",	"&#248;",    "o", /* latin small letter o with stroke */
ali@40
   249
    "&ugrave;",	"&#249;",    "u", /* latin small letter u with grave */
ali@40
   250
    "&uacute;",	"&#250;",    "u", /* latin small letter u with acute */
ali@40
   251
    "&ucirc;",	"&#251;",    "u", /* latin small letter u with circumflex */
ali@40
   252
    "&uuml;",	"&#252;",    "u", /* latin small letter u with diaeresis */
ali@40
   253
    "&yacute;",	"&#253;",    "y", /* latin small letter y with acute */
ali@40
   254
    "&thorn;",	"&#254;",    "th", /* latin small letter thorn */
ali@40
   255
    "&yuml;",	"&#255;",    "y", /* latin small letter y with diaeresis */
ali@40
   256
    "", ""
ali@40
   257
};
ali@40
   258
ali@40
   259
/* special characters */
ali@0
   260
#define CHAR_SPACE        32
ali@0
   261
#define CHAR_TAB           9
ali@0
   262
#define CHAR_LF           10
ali@0
   263
#define CHAR_CR           13
ali@0
   264
#define CHAR_DQUOTE       34
ali@0
   265
#define CHAR_SQUOTE       39
ali@0
   266
#define CHAR_OPEN_SQUOTE  96
ali@0
   267
#define CHAR_TILDE       126
ali@0
   268
#define CHAR_ASTERISK     42
ali@0
   269
#define CHAR_FORESLASH    47
ali@0
   270
#define CHAR_CARAT        94
ali@0
   271
ali@0
   272
#define CHAR_UNDERSCORE    '_'
ali@0
   273
#define CHAR_OPEN_CBRACK   '{'
ali@0
   274
#define CHAR_CLOSE_CBRACK  '}'
ali@0
   275
#define CHAR_OPEN_RBRACK   '('
ali@0
   276
#define CHAR_CLOSE_RBRACK  ')'
ali@0
   277
#define CHAR_OPEN_SBRACK   '['
ali@0
   278
#define CHAR_CLOSE_SBRACK  ']'
ali@0
   279
ali@40
   280
/* longest and shortest normal PG line lengths */
ali@0
   281
#define LONGEST_PG_LINE   75
ali@0
   282
#define WAY_TOO_LONG      80
ali@0
   283
#define SHORTEST_PG_LINE  55
ali@0
   284
ali@0
   285
#define SWITCHES "ESTPXLOYHWVMUD" /* switches:-                            */
ali@0
   286
                                  /*     D - ignore DP-specific markup     */
ali@0
   287
                                  /*     E - echo queried line             */
ali@0
   288
                                  /*     S - check single quotes           */
ali@0
   289
                                  /*     T - check common typos            */
ali@0
   290
                                  /*     P - require closure of quotes on  */
ali@0
   291
                                  /*         every paragraph               */
ali@0
   292
                                  /*     X - "Trust no one" :-) Paranoid!  */
ali@0
   293
                                  /*         Queries everything            */
ali@0
   294
                                  /*     L - line end checking defaults on */
ali@0
   295
                                  /*         -L turns it off               */
ali@0
   296
                                  /*     O - overview. Just shows counts.  */
ali@0
   297
                                  /*     Y - puts errors to stdout         */
ali@0
   298
                                  /*         instead of stderr             */
ali@0
   299
                                  /*     H - Echoes header fields          */
ali@0
   300
                                  /*     M - Ignore markup in < >          */
ali@0
   301
                                  /*     U - Use file of User-defined Typos*/
ali@0
   302
                                  /*     W - Defaults for use on Web upload*/
ali@0
   303
                                  /*     V - Verbose - list EVERYTHING!    */
ali@0
   304
#define SWITNO 14                 /* max number of switch parms            */
ali@0
   305
                                  /*        - used for defining array-size */
ali@0
   306
#define MINARGS   1               /* minimum no of args excl switches      */
ali@0
   307
#define MAXARGS   1               /* maximum no of args excl switches      */
ali@0
   308
ali@0
   309
int pswit[SWITNO];                /* program switches set by SWITCHES      */
ali@0
   310
ali@0
   311
#define ECHO_SWITCH      0
ali@0
   312
#define SQUOTE_SWITCH    1
ali@0
   313
#define TYPO_SWITCH      2
ali@0
   314
#define QPARA_SWITCH     3
ali@0
   315
#define PARANOID_SWITCH  4
ali@0
   316
#define LINE_END_SWITCH  5
ali@0
   317
#define OVERVIEW_SWITCH  6
ali@0
   318
#define STDOUT_SWITCH    7
ali@0
   319
#define HEADER_SWITCH    8
ali@0
   320
#define WEB_SWITCH       9
ali@0
   321
#define VERBOSE_SWITCH   10
ali@0
   322
#define MARKUP_SWITCH    11
ali@0
   323
#define USERTYPO_SWITCH  12
ali@0
   324
#define DP_SWITCH        13
ali@0
   325
ali@0
   326
long cnt_dquot;       /* for overview mode, count of doublequote queries */
ali@0
   327
long cnt_squot;       /* for overview mode, count of singlequote queries */
ali@0
   328
long cnt_brack;       /* for overview mode, count of brackets queries */
ali@0
   329
long cnt_bin;         /* for overview mode, count of non-ASCII queries */
ali@0
   330
long cnt_odd;         /* for overview mode, count of odd character queries */
ali@0
   331
long cnt_long;        /* for overview mode, count of long line errors */
ali@0
   332
long cnt_short;       /* for overview mode, count of short line queries */
ali@0
   333
long cnt_punct;       /* for overview mode, count of punctuation and spacing queries */
ali@0
   334
long cnt_dash;        /* for overview mode, count of dash-related queries */
ali@0
   335
long cnt_word;        /* for overview mode, count of word queries */
ali@0
   336
long cnt_html;        /* for overview mode, count of html queries */
ali@0
   337
long cnt_lineend;     /* for overview mode, count of line-end queries */
ali@40
   338
long cnt_spacend;     /* count of lines with space at end */
ali@0
   339
long linecnt;         /* count of total lines in the file */
ali@40
   340
long checked_linecnt; /* count of lines actually checked */
ali@0
   341
ali@0
   342
void proghelp(void);
ali@0
   343
void procfile(char *);
ali@0
   344
ali@0
   345
#define LOW_THRESHOLD    0
ali@0
   346
#define HIGH_THRESHOLD   1
ali@0
   347
ali@0
   348
#define START 0
ali@0
   349
#define END 1
ali@0
   350
#define PREV 0
ali@0
   351
#define NEXT 1
ali@0
   352
#define FIRST_OF_PAIR 0
ali@0
   353
#define SECOND_OF_PAIR 1
ali@0
   354
ali@0
   355
#define MAX_WORDPAIR 1000
ali@0
   356
ali@0
   357
char running_from[MAX_PATH];
ali@0
   358
ali@0
   359
int mixdigit(char *);
ali@54
   360
const char *getaword(const char *,char *);
ali@40
   361
int matchword(char *,char *);
ali@40
   362
char *flgets(char *,int,FILE *,long);
ali@0
   363
void lowerit(char *);
ali@0
   364
int gcisalpha(unsigned char);
ali@0
   365
int gcisdigit(unsigned char);
ali@0
   366
int gcisletter(unsigned char);
ali@40
   367
char *gcstrchr(char *s,char c);
ali@0
   368
void postprocess_for_HTML(char *);
ali@0
   369
char *linehasmarkup(char *);
ali@0
   370
char *losemarkup(char *);
ali@40
   371
int tagcomp(char *,char *);
ali@0
   372
char *loseentities(char *);
ali@0
   373
int isroman(char *);
ali@0
   374
int usertypo_count;
ali@0
   375
void postprocess_for_DP(char *);
ali@0
   376
ali@0
   377
char wrk[LINEBUFSIZE];
ali@0
   378
ali@40
   379
#define MAX_QWORD 50
ali@40
   380
#define MAX_QWORD_LENGTH 40
ali@0
   381
char qword[MAX_QWORD][MAX_QWORD_LENGTH];
ali@0
   382
signed int dupcnt[MAX_QWORD];
ali@0
   383
ali@40
   384
int main(int argc,char **argv)
ali@0
   385
{
ali@40
   386
    char *argsw,*s;
ali@40
   387
    int i,switno,invarg;
ali@0
   388
    char usertypo_file[MAX_PATH];
ali@0
   389
    FILE *usertypofile;
ali@40
   390
    if (strlen(argv[0])<sizeof(running_from))
ali@40
   391
	/* save the path to the executable */
ali@40
   392
        strcpy(running_from,argv[0]);
ali@0
   393
    /* find out what directory we're running from */
ali@40
   394
    s=running_from+strlen(running_from);
ali@40
   395
    for (;*s!='/' && *s!='\\' && s>=running_from;s--)
ali@40
   396
        *s=0;
ali@40
   397
    switno=strlen(SWITCHES);
ali@40
   398
    for (i=switno;--i>0;)
ali@40
   399
        pswit[i]=0;           /* initialise switches */
ali@40
   400
    /*
ali@40
   401
     * Standard loop to extract switches.
ali@40
   402
     * When we come out of this loop, the arguments will be
ali@40
   403
     * in argv[0] upwards and the switches used will be
ali@40
   404
     * represented by their equivalent elements in pswit[]
ali@40
   405
     */
ali@40
   406
    while (--argc>0 && **++argv=='-')
ali@40
   407
        for (argsw=argv[0]+1;*argsw!='\0';argsw++)
ali@40
   408
            for (i=switno,invarg=1;(--i>=0) && invarg==1;)
ali@40
   409
                if ((toupper(*argsw))==SWITCHES[i])
ali@40
   410
		{
ali@40
   411
                    invarg=0;
ali@40
   412
                    pswit[i]=1;
ali@40
   413
		}
ali@40
   414
    /* Paranoid checking is turned OFF, not on, by its switch */
ali@40
   415
    pswit[PARANOID_SWITCH]^=1;
ali@40
   416
    if (pswit[PARANOID_SWITCH])
ali@40
   417
	/* if running in paranoid mode force typo checks as well   */
ali@40
   418
        pswit[TYPO_SWITCH]=pswit[TYPO_SWITCH]^1;
ali@40
   419
    /* Line-end checking is turned OFF, not on, by its switch */
ali@40
   420
    pswit[LINE_END_SWITCH]^=1;
ali@40
   421
    /* Echoing is turned OFF, not on, by its switch */
ali@40
   422
    pswit[ECHO_SWITCH]^=1;
ali@40
   423
    if (pswit[OVERVIEW_SWITCH])
ali@40
   424
	/* just print summary; don't echo */
ali@40
   425
        pswit[ECHO_SWITCH]=0;
ali@40
   426
    /*
ali@40
   427
     * Web uploads - for the moment, this is really just a placeholder
ali@40
   428
     * until we decide what processing we really want to do on web uploads
ali@40
   429
     */
ali@40
   430
    if (pswit[WEB_SWITCH])
ali@40
   431
    {
ali@40
   432
	/* specific override for web uploads */
ali@40
   433
        pswit[ECHO_SWITCH]=1;
ali@40
   434
        pswit[SQUOTE_SWITCH]=0;
ali@40
   435
        pswit[TYPO_SWITCH]=1;
ali@40
   436
        pswit[QPARA_SWITCH]=0;
ali@40
   437
        pswit[PARANOID_SWITCH]=1;
ali@40
   438
        pswit[LINE_END_SWITCH]=0;
ali@40
   439
        pswit[OVERVIEW_SWITCH]=0;
ali@40
   440
        pswit[STDOUT_SWITCH]=0;
ali@40
   441
        pswit[HEADER_SWITCH]=1;
ali@40
   442
        pswit[VERBOSE_SWITCH]=0;
ali@40
   443
        pswit[MARKUP_SWITCH]=0;
ali@40
   444
        pswit[USERTYPO_SWITCH]=0;
ali@40
   445
        pswit[DP_SWITCH]=0;
ali@40
   446
    }
ali@40
   447
    if (argc<MINARGS || argc>MAXARGS)
ali@40
   448
    {
ali@40
   449
	/* check number of args */
ali@0
   450
        proghelp();
ali@40
   451
        return 1;
ali@40
   452
    }
ali@0
   453
    /* read in the user-defined stealth scanno list */
ali@40
   454
    if (pswit[USERTYPO_SWITCH])
ali@40
   455
    {
ali@40
   456
	/* ... we were told we had one! */
ali@40
   457
        usertypofile=fopen(USERTYPO_FILE,"rb");
ali@40
   458
        if (!usertypofile)
ali@40
   459
	{
ali@40
   460
	    /* not in cwd. try excuteable directory. */
ali@40
   461
            strcpy(usertypo_file,running_from);
ali@40
   462
            strcat(usertypo_file,USERTYPO_FILE);
ali@40
   463
            usertypofile=fopen(usertypo_file,"rb");
ali@40
   464
            if (!usertypofile) {
ali@40
   465
		/* we ain't got no user typo file! */
ali@40
   466
                printf("   --> I couldn't find gutcheck.typ "
ali@40
   467
		  "-- proceeding without user typos.\n");
ali@40
   468
	    }
ali@40
   469
	}
ali@40
   470
        usertypo_count=0;
ali@40
   471
        if (usertypofile)
ali@40
   472
	{
ali@40
   473
	    /* we managed to open a User Typo File! */
ali@40
   474
            if (pswit[USERTYPO_SWITCH])
ali@40
   475
	    {
ali@40
   476
                while (flgets(aline,LINEBUFSIZE-1,usertypofile,
ali@40
   477
		  (long)usertypo_count))
ali@40
   478
		{
ali@40
   479
                    if (strlen(aline)>1)
ali@40
   480
		    {
ali@40
   481
                        if ((int)*aline>33)
ali@40
   482
			{
ali@40
   483
                            s=malloc(strlen(aline)+1);
ali@40
   484
                            if (!s)
ali@40
   485
			    {
ali@40
   486
                                fprintf(stderr,"bookloupe: cannot get enough "
ali@40
   487
				  "memory for user typo file!\n");
ali@0
   488
                                exit(1);
ali@40
   489
			    }
ali@40
   490
                            strcpy(s,aline);
ali@40
   491
                            usertypo[usertypo_count]=s;
ali@0
   492
                            usertypo_count++;
ali@40
   493
                            if (usertypo_count>=MAX_USER_TYPOS)
ali@40
   494
			    {
ali@40
   495
                                printf("   --> Only %d user-defined typos "
ali@42
   496
				  "allowed: ignoring the rest\n",
ali@42
   497
				  MAX_USER_TYPOS);
ali@0
   498
                                break;
ali@40
   499
			    }
ali@40
   500
			}
ali@40
   501
		    }
ali@40
   502
		}
ali@40
   503
	    }
ali@0
   504
            fclose(usertypofile);
ali@40
   505
	}
ali@40
   506
    }
ali@40
   507
    fprintf(stderr,"bookloupe: Check and report on an e-text\n");
ali@40
   508
    cnt_dquot=cnt_squot=cnt_brack=cnt_bin=cnt_odd=cnt_long=
ali@40
   509
    cnt_short=cnt_punct=cnt_dash=cnt_word=cnt_html=cnt_lineend=
ali@40
   510
    cnt_spacend=0;
ali@0
   511
    procfile(argv[0]);
ali@40
   512
    if (pswit[OVERVIEW_SWITCH])
ali@40
   513
    {
ali@40
   514
	printf("    Checked %ld lines of %ld (head+foot = %ld)\n\n",
ali@40
   515
	  checked_linecnt,linecnt,linecnt-checked_linecnt);
ali@40
   516
        printf("    --------------- Queries found --------------\n");
ali@40
   517
        if (cnt_long)
ali@40
   518
	    printf("    Long lines:                    %14ld\n",cnt_long);
ali@40
   519
        if (cnt_short)
ali@40
   520
	    printf("    Short lines:                   %14ld\n",cnt_short);
ali@40
   521
        if (cnt_lineend)
ali@40
   522
	    printf("    Line-end problems:             %14ld\n",cnt_lineend);
ali@40
   523
        if (cnt_word)
ali@40
   524
	    printf("    Common typos:                  %14ld\n",cnt_word);
ali@40
   525
        if (cnt_dquot)
ali@40
   526
	    printf("    Unmatched quotes:              %14ld\n",cnt_dquot);
ali@40
   527
        if (cnt_squot)
ali@40
   528
	    printf("    Unmatched SingleQuotes:        %14ld\n",cnt_squot);
ali@40
   529
        if (cnt_brack)
ali@40
   530
	    printf("    Unmatched brackets:            %14ld\n",cnt_brack);
ali@40
   531
        if (cnt_bin)
ali@40
   532
	    printf("    Non-ASCII characters:          %14ld\n",cnt_bin);
ali@40
   533
        if (cnt_odd)
ali@40
   534
	    printf("    Proofing characters:           %14ld\n",cnt_odd);
ali@40
   535
        if (cnt_punct)
ali@40
   536
	    printf("    Punctuation & spacing queries: %14ld\n",cnt_punct);
ali@40
   537
        if (cnt_dash)
ali@40
   538
	    printf("    Non-standard dashes:           %14ld\n",cnt_dash);
ali@40
   539
        if (cnt_html)
ali@40
   540
	    printf("    Possible HTML tags:            %14ld\n",cnt_html);
ali@0
   541
        printf("\n");
ali@40
   542
        printf("    TOTAL QUERIES                  %14ld\n",
ali@40
   543
          cnt_dquot+cnt_squot+cnt_brack+cnt_bin+cnt_odd+cnt_long+
ali@40
   544
          cnt_short+cnt_punct+cnt_dash+cnt_word+cnt_html+cnt_lineend);
ali@40
   545
    }
ali@40
   546
    return 0;
ali@0
   547
}
ali@0
   548
ali@41
   549
struct first_pass_results {
ali@41
   550
    long firstline,astline;
ali@41
   551
    long footerline,totlen,binlen,alphalen,endquote_count,shortline,dotcomma;
ali@41
   552
    long fslashline,hyphens,longline,verylongline,htmcount,standalone_digit;
ali@41
   553
    long spacedash,emdash,space_emdash,non_PG_space_emdash,PG_space_emdash;
ali@41
   554
    signed int Dutchcount,Frenchcount;
ali@41
   555
};
ali@41
   556
ali@40
   557
/*
ali@41
   558
 * first_pass:
ali@40
   559
 *
ali@41
   560
 * Run a first pass - verify that it's a valid PG
ali@41
   561
 * file, decide whether to report some things that
ali@41
   562
 * occur many times in the text like long or short
ali@41
   563
 * lines, non-standard dashes, etc.
ali@40
   564
 */
ali@41
   565
struct first_pass_results *first_pass(FILE *infile)
ali@0
   566
{
ali@54
   567
    char laststart=CHAR_SPACE;
ali@54
   568
    const char *s;
ali@41
   569
    signed int i,llen;
ali@41
   570
    unsigned int lastlen=0,lastblen=0;
ali@41
   571
    long spline=0,nspline=0;
ali@41
   572
    static struct first_pass_results results={0};
ali@41
   573
    char inword[MAXWORDLEN]="";
ali@40
   574
    while (fgets(aline,LINEBUFSIZE-1,infile))
ali@40
   575
    {
ali@40
   576
        while (aline[strlen(aline)-1]==10 || aline[strlen(aline)-1]==13)
ali@40
   577
	    aline[strlen(aline)-1]=0;
ali@0
   578
        linecnt++;
ali@40
   579
        if (strstr(aline,"*END") && strstr(aline,"SMALL PRINT") &&
ali@40
   580
	  (strstr(aline,"PUBLIC DOMAIN") || strstr(aline,"COPYRIGHT")))
ali@40
   581
	{
ali@0
   582
            if (spline)
ali@0
   583
                printf("   --> Duplicate header?\n");
ali@40
   584
            spline=linecnt+1;   /* first line of non-header text, that is */
ali@40
   585
	}
ali@40
   586
        if (!strncmp(aline,"*** START",9) && strstr(aline,"PROJECT GUTENBERG"))
ali@40
   587
	{
ali@0
   588
            if (nspline)
ali@0
   589
                printf("   --> Duplicate header?\n");
ali@40
   590
            nspline=linecnt+1;   /* first line of non-header text, that is */
ali@40
   591
	}
ali@40
   592
        if (spline || nspline)
ali@40
   593
	{
ali@0
   594
            lowerit(aline);
ali@40
   595
            if (strstr(aline,"end") && strstr(aline,"project gutenberg"))
ali@40
   596
	    {
ali@40
   597
                if (strstr(aline,"end")<strstr(aline,"project gutenberg"))
ali@40
   598
		{
ali@41
   599
                    if (results.footerline)
ali@40
   600
		    {
ali@40
   601
			/* it's an old-form header - we can detect duplicates */
ali@40
   602
                        if (!nspline)
ali@0
   603
                            printf("   --> Duplicate footer?\n");
ali@40
   604
		    }
ali@40
   605
                    else
ali@41
   606
                        results.footerline=linecnt;
ali@40
   607
		}
ali@40
   608
	    }
ali@40
   609
	}
ali@40
   610
        if (spline)
ali@41
   611
	    results.firstline=spline;
ali@40
   612
        if (nspline)
ali@41
   613
	    results.firstline=nspline;  /* override with new */
ali@41
   614
        if (results.footerline)
ali@40
   615
	    continue;    /* don't count the boilerplate in the footer */
ali@40
   616
        llen=strlen(aline);
ali@41
   617
        results.totlen+=llen;
ali@40
   618
        for (i=0;i<llen;i++)
ali@40
   619
	{
ali@40
   620
            if ((unsigned char)aline[i]>127)
ali@41
   621
		results.binlen++;
ali@40
   622
            if (gcisalpha(aline[i]))
ali@41
   623
		results.alphalen++;
ali@40
   624
            if (i>0 && aline[i]==CHAR_DQUOTE && isalpha(aline[i-1]))
ali@41
   625
		results.endquote_count++;
ali@40
   626
	}
ali@40
   627
        if (strlen(aline)>2 && lastlen>2 && lastlen<SHORTEST_PG_LINE &&
ali@40
   628
	  lastblen>2 && lastblen>SHORTEST_PG_LINE && laststart!=CHAR_SPACE)
ali@41
   629
	    results.shortline++;
ali@40
   630
        if (*aline && (unsigned char)aline[strlen(aline)-1]<=CHAR_SPACE)
ali@40
   631
	    cnt_spacend++;
ali@40
   632
        if (strstr(aline,".,"))
ali@41
   633
	    results.dotcomma++;
ali@40
   634
        /* only count ast lines for ignoring purposes where there is */
ali@0
   635
        /* locase text on the line */
ali@40
   636
        if (strstr(aline,"*"))
ali@40
   637
	{
ali@40
   638
            for (s=aline;*s;s++)
ali@40
   639
                if (*s>='a' && *s<='z')
ali@0
   640
                    break;
ali@40
   641
             if (*s)
ali@41
   642
		results.astline++;
ali@40
   643
	}
ali@40
   644
        if (strstr(aline,"/"))
ali@41
   645
            results.fslashline++;
ali@40
   646
        for (i=llen-1;i>0 && (unsigned char)aline[i]<=CHAR_SPACE;i--)
ali@40
   647
	    ;
ali@40
   648
        if (aline[i]=='-' && aline[i-1]!='-')
ali@41
   649
	    results.hyphens++;
ali@40
   650
        if (llen>LONGEST_PG_LINE)
ali@41
   651
	    results.longline++;
ali@40
   652
        if (llen>WAY_TOO_LONG)
ali@41
   653
	    results.verylongline++;
ali@40
   654
        if (strstr(aline,"<") && strstr(aline,">"))
ali@40
   655
	{
ali@40
   656
            i=(signed int)(strstr(aline,">")-strstr(aline,"<")+1);
ali@40
   657
            if (i>0)
ali@41
   658
                results.htmcount++;
ali@40
   659
            if (strstr(aline,"<i>"))
ali@41
   660
		results.htmcount+=4; /* bonus marks! */
ali@40
   661
	}
ali@0
   662
        /* Check for spaced em-dashes */
ali@40
   663
        if (strstr(aline,"--"))
ali@40
   664
	{
ali@41
   665
            results.emdash++;
ali@40
   666
            if (*(strstr(aline,"--")-1)==CHAR_SPACE ||
ali@40
   667
               (*(strstr(aline,"--")+2)==CHAR_SPACE))
ali@41
   668
		results.space_emdash++;
ali@40
   669
            if (*(strstr(aline,"--")-1)==CHAR_SPACE &&
ali@40
   670
               (*(strstr(aline,"--")+2)==CHAR_SPACE))
ali@40
   671
		/* count of em-dashes with spaces both sides */
ali@41
   672
		results.non_PG_space_emdash++;
ali@40
   673
            if (*(strstr(aline,"--")-1)!=CHAR_SPACE &&
ali@40
   674
               (*(strstr(aline,"--")+2)!=CHAR_SPACE))
ali@40
   675
		/* count of PG-type em-dashes with no spaces */
ali@41
   676
		results.PG_space_emdash++;
ali@40
   677
	}
ali@40
   678
        for (s=aline;*s;)
ali@40
   679
	{
ali@40
   680
            s=getaword(s,inword);
ali@40
   681
            if (!strcmp(inword,"hij") || !strcmp(inword,"niet")) 
ali@41
   682
                results.Dutchcount++;
ali@40
   683
            if (!strcmp(inword,"dans") || !strcmp(inword,"avec")) 
ali@41
   684
                results.Frenchcount++;
ali@40
   685
            if (!strcmp(inword,"0") || !strcmp(inword,"1")) 
ali@41
   686
                results.standalone_digit++;
ali@40
   687
	}
ali@0
   688
        /* Check for spaced dashes */
ali@40
   689
        if (strstr(aline," -") && *(strstr(aline," -")+2)!='-')
ali@41
   690
	    results.spacedash++;
ali@40
   691
        lastblen=lastlen;
ali@40
   692
        lastlen=strlen(aline);
ali@40
   693
        laststart=aline[0];
ali@40
   694
    }
ali@41
   695
    return &results;
ali@41
   696
}
ali@41
   697
ali@42
   698
struct warnings {
ali@42
   699
    signed int shortline,longline,bin,dash,dotcomma,ast,fslash,digit,hyphen;
ali@42
   700
    signed int endquote,isDutch,isFrench;
ali@42
   701
};
ali@42
   702
ali@42
   703
/*
ali@42
   704
 * report_first_pass:
ali@42
   705
 *
ali@42
   706
 * Make some snap decisions based on the first pass results.
ali@42
   707
 */
ali@42
   708
struct warnings *report_first_pass(struct first_pass_results *results)
ali@42
   709
{
ali@42
   710
    static struct warnings warnings={0};
ali@42
   711
    if (cnt_spacend>0)
ali@42
   712
        printf("   --> %ld lines in this file have white space at end\n",
ali@42
   713
	  cnt_spacend);
ali@42
   714
    warnings.dotcomma=1;
ali@42
   715
    if (results->dotcomma>5)
ali@42
   716
    {
ali@42
   717
        warnings.dotcomma=0;
ali@42
   718
        printf("   --> %ld lines in this file contain '.,'. "
ali@42
   719
	  "Not reporting them.\n",results->dotcomma);
ali@42
   720
    }
ali@42
   721
    /*
ali@42
   722
     * If more than 50 lines, or one-tenth, are short,
ali@42
   723
     * don't bother reporting them.
ali@42
   724
     */
ali@42
   725
    warnings.shortline=1;
ali@42
   726
    if (results->shortline>50 || results->shortline*10>linecnt)
ali@42
   727
    {
ali@42
   728
        warnings.shortline=0;
ali@42
   729
        printf("   --> %ld lines in this file are short. "
ali@42
   730
	  "Not reporting short lines.\n",results->shortline);
ali@42
   731
    }
ali@42
   732
    /*
ali@42
   733
     * If more than 50 lines, or one-tenth, are long,
ali@42
   734
     * don't bother reporting them.
ali@42
   735
     */
ali@42
   736
    warnings.longline=1;
ali@42
   737
    if (results->longline>50 || results->longline*10>linecnt)
ali@42
   738
    {
ali@42
   739
        warnings.longline=0;
ali@42
   740
        printf("   --> %ld lines in this file are long. "
ali@42
   741
	  "Not reporting long lines.\n",results->longline);
ali@42
   742
    }
ali@42
   743
    /* If more than 10 lines contain asterisks, don't bother reporting them. */
ali@42
   744
    warnings.ast=1;
ali@42
   745
    if (results->astline>10)
ali@42
   746
    {
ali@42
   747
        warnings.ast=0;
ali@42
   748
        printf("   --> %ld lines in this file contain asterisks. "
ali@42
   749
	  "Not reporting them.\n",results->astline);
ali@42
   750
    }
ali@42
   751
    /*
ali@42
   752
     * If more than 10 lines contain forward slashes,
ali@42
   753
     * don't bother reporting them.
ali@42
   754
     */
ali@42
   755
    warnings.fslash=1;
ali@42
   756
    if (results->fslashline>10)
ali@42
   757
    {
ali@42
   758
        warnings.fslash=0;
ali@42
   759
        printf("   --> %ld lines in this file contain forward slashes. "
ali@42
   760
	  "Not reporting them.\n",results->fslashline);
ali@42
   761
    }
ali@42
   762
    /*
ali@42
   763
     * If more than 20 lines contain unpunctuated endquotes,
ali@42
   764
     * don't bother reporting them.
ali@42
   765
     */
ali@42
   766
    warnings.endquote=1;
ali@42
   767
    if (results->endquote_count>20)
ali@42
   768
    {
ali@42
   769
        warnings.endquote=0;
ali@42
   770
        printf("   --> %ld lines in this file contain unpunctuated endquotes. "
ali@42
   771
	  "Not reporting them.\n",results->endquote_count);
ali@42
   772
    }
ali@42
   773
    /*
ali@42
   774
     * If more than 15 lines contain standalone digits,
ali@42
   775
     * don't bother reporting them.
ali@42
   776
     */
ali@42
   777
    warnings.digit=1;
ali@42
   778
    if (results->standalone_digit>10)
ali@42
   779
    {
ali@42
   780
        warnings.digit=0;
ali@42
   781
        printf("   --> %ld lines in this file contain standalone 0s and 1s. "
ali@42
   782
	  "Not reporting them.\n",results->standalone_digit);
ali@42
   783
    }
ali@42
   784
    /*
ali@42
   785
     * If more than 20 lines contain hyphens at end,
ali@42
   786
     * don't bother reporting them.
ali@42
   787
     */
ali@42
   788
    warnings.hyphen=1;
ali@42
   789
    if (results->hyphens>20)
ali@42
   790
    {
ali@42
   791
        warnings.hyphen=0;
ali@42
   792
        printf("   --> %ld lines in this file have hyphens at end. "
ali@42
   793
	  "Not reporting them.\n",results->hyphens);
ali@42
   794
    }
ali@42
   795
    if (results->htmcount>20 && !pswit[MARKUP_SWITCH])
ali@42
   796
    {
ali@42
   797
        printf("   --> Looks like this is HTML. Switching HTML mode ON.\n");
ali@42
   798
        pswit[MARKUP_SWITCH]=1;
ali@42
   799
    }
ali@42
   800
    if (results->verylongline>0)
ali@42
   801
        printf("   --> %ld lines in this file are VERY long!\n",
ali@42
   802
	  results->verylongline);
ali@42
   803
    /*
ali@42
   804
     * If there are more non-PG spaced dashes than PG em-dashes,
ali@42
   805
     * assume it's deliberate.
ali@42
   806
     * Current PG guidelines say don't use them, but older texts do,
ali@42
   807
     * and some people insist on them whatever the guidelines say.
ali@42
   808
     */
ali@42
   809
    warnings.dash=1;
ali@42
   810
    if (results->spacedash+results->non_PG_space_emdash>
ali@42
   811
      results->PG_space_emdash)
ali@42
   812
    {
ali@42
   813
        warnings.dash=0;
ali@42
   814
        printf("   --> There are %ld spaced dashes and em-dashes. "
ali@42
   815
	  "Not reporting them.\n",
ali@42
   816
	  results->spacedash+results->non_PG_space_emdash);
ali@42
   817
    }
ali@42
   818
    /* If more than a quarter of characters are hi-bit, bug out. */
ali@42
   819
    warnings.bin=1;
ali@42
   820
    if (results->binlen*4>results->totlen)
ali@42
   821
    {
ali@42
   822
        printf("   --> This file does not appear to be ASCII. "
ali@42
   823
	  "Terminating. Best of luck with it!\n");
ali@42
   824
        exit(1);
ali@42
   825
    }
ali@42
   826
    if (results->alphalen*4<results->totlen)
ali@42
   827
    {
ali@42
   828
        printf("   --> This file does not appear to be text. "
ali@42
   829
	  "Terminating. Best of luck with it!\n");
ali@42
   830
        exit(1);
ali@42
   831
    }
ali@42
   832
    if (results->binlen*100>results->totlen || results->binlen>100)
ali@42
   833
    {
ali@42
   834
        printf("   --> There are a lot of foreign letters here. "
ali@42
   835
	  "Not reporting them.\n");
ali@42
   836
        warnings.bin=0;
ali@42
   837
    }
ali@42
   838
    warnings.isDutch=0;
ali@42
   839
    if (results->Dutchcount>50)
ali@42
   840
    {
ali@42
   841
        warnings.isDutch=1;
ali@42
   842
        printf("   --> This looks like Dutch - "
ali@42
   843
	  "switching off dashes and warnings for 's Middags case.\n");
ali@42
   844
    }
ali@42
   845
    warnings.isFrench=0;
ali@42
   846
    if (results->Frenchcount>50)
ali@42
   847
    {
ali@42
   848
        warnings.isFrench=1;
ali@42
   849
        printf("   --> This looks like French - "
ali@42
   850
	  "switching off some doublepunct.\n");
ali@42
   851
    }
ali@42
   852
    if (results->firstline && results->footerline)
ali@42
   853
        printf("    The PG header and footer appear to be already on.\n");
ali@42
   854
    else
ali@42
   855
    {
ali@42
   856
        if (results->firstline)
ali@42
   857
            printf("    The PG header is on - no footer.\n");
ali@42
   858
        if (results->footerline)
ali@42
   859
            printf("    The PG footer is on - no header.\n");
ali@42
   860
    }
ali@42
   861
    printf("\n");
ali@42
   862
    if (pswit[VERBOSE_SWITCH])
ali@42
   863
    {
ali@42
   864
        warnings.bin=1;
ali@42
   865
        warnings.shortline=1;
ali@42
   866
        warnings.dotcomma=1;
ali@42
   867
        warnings.longline=1;
ali@42
   868
        warnings.dash=1;
ali@42
   869
        warnings.digit=1;
ali@42
   870
        warnings.ast=1;
ali@42
   871
        warnings.fslash=1;
ali@42
   872
        warnings.hyphen=1;
ali@42
   873
        warnings.endquote=1;
ali@42
   874
        printf("   *** Verbose output is ON -- you asked for it! ***\n");
ali@42
   875
    }
ali@42
   876
    if (warnings.isDutch)
ali@42
   877
        warnings.dash=0;
ali@42
   878
    if (results->footerline>0 && results->firstline>0 &&
ali@42
   879
      results->footerline>results->firstline &&
ali@42
   880
      results->footerline-results->firstline<100)
ali@42
   881
    {
ali@42
   882
        printf("   --> I don't really know where this text starts. \n");
ali@42
   883
        printf("       There are no reference points.\n");
ali@42
   884
        printf("       I'm going to have to report the header and footer "
ali@42
   885
	  "as well.\n");
ali@42
   886
        results->firstline=0;
ali@42
   887
    }
ali@42
   888
    return &warnings;
ali@42
   889
}
ali@42
   890
ali@43
   891
struct counters {
ali@43
   892
    long quot;
ali@43
   893
    signed int c_unders,c_brack,s_brack,r_brack;
ali@43
   894
    signed int open_single_quote,close_single_quote;
ali@43
   895
};
ali@43
   896
ali@43
   897
/*
ali@43
   898
 * analyse_quotes:
ali@43
   899
 *
ali@43
   900
 * Look along the line, accumulate the count of quotes, and see
ali@43
   901
 * if this is an empty line - i.e. a line with nothing on it
ali@43
   902
 * but spaces.
ali@43
   903
 * If line has just spaces, period, * and/or - on it, don't
ali@43
   904
 * count it, since empty lines with asterisks or dashes to
ali@43
   905
 * separate sections are common.
ali@43
   906
 *
ali@43
   907
 * Returns: Non-zero if the line is empty.
ali@43
   908
 */
ali@43
   909
int analyse_quotes(const char *s,struct counters *counters)
ali@43
   910
{
ali@43
   911
    signed int guessquote=0;
ali@43
   912
    int isemptyline=1;    /* assume the line is empty until proven otherwise */
ali@43
   913
    while (*s)
ali@43
   914
    {
ali@43
   915
	if (*s==CHAR_DQUOTE)
ali@43
   916
	    counters->quot++;
ali@43
   917
	if (*s==CHAR_SQUOTE || *s==CHAR_OPEN_SQUOTE)
ali@43
   918
	{
ali@43
   919
	    if (s==aline)
ali@43
   920
	    {
ali@43
   921
		/*
ali@43
   922
		 * At start of line, it can only be an openquote.
ali@43
   923
		 * Hardcode a very common exception!
ali@43
   924
		 */
ali@43
   925
		if (strncmp(s+2,"tis",3) && strncmp(s+2,"Tis",3))
ali@43
   926
		    counters->open_single_quote++;
ali@43
   927
	    }
ali@43
   928
	    else if (gcisalpha(s[-1]) && gcisalpha(s[1]))
ali@43
   929
		/* Do nothing! it's definitely an apostrophe, not a quote */
ali@43
   930
		;
ali@43
   931
	    /* it's outside a word - let's check it out */
ali@43
   932
	    else if (*s==CHAR_OPEN_SQUOTE || gcisalpha(s[1]))
ali@43
   933
	    {
ali@43
   934
		/* it damwell better BE an openquote */
ali@43
   935
		if (strncmp(s+1,"tis",3) && strncmp(s+1,"Tis",3))
ali@43
   936
		    /* hardcode a very common exception! */
ali@43
   937
		    counters->open_single_quote++;
ali@43
   938
	    }
ali@43
   939
	    else
ali@43
   940
	    {
ali@43
   941
		/* now - is it a closequote? */
ali@43
   942
		guessquote=0;   /* accumulate clues */
ali@43
   943
		if (gcisalpha(s[-1]))
ali@43
   944
		{
ali@43
   945
		    /* it follows a letter - could be either */
ali@43
   946
		    guessquote++;
ali@43
   947
		    if (s[-1]=='s')
ali@43
   948
		    {
ali@43
   949
			/* looks like a plural apostrophe */
ali@43
   950
			guessquote-=3;
ali@43
   951
			if (s[1]==CHAR_SPACE)  /* bonus marks! */
ali@43
   952
			    guessquote-=2;
ali@43
   953
		    }
ali@43
   954
		}
ali@43
   955
		/* it doesn't have a letter either side */
ali@43
   956
		else if (strchr(".?!,;:",s[-1]) && strchr(".?!,;: ",s[1]))
ali@43
   957
		    guessquote+=8; /* looks like a closequote */
ali@43
   958
		else
ali@43
   959
		    guessquote++;
ali@43
   960
		if (counters->open_single_quote>counters->close_single_quote)
ali@43
   961
		    /*
ali@43
   962
		     * Give it the benefit of some doubt,
ali@43
   963
		     * if a squote is already open.
ali@43
   964
		     */
ali@43
   965
		    guessquote++;
ali@43
   966
		else
ali@43
   967
		    guessquote--;
ali@43
   968
		if (guessquote>=0)
ali@43
   969
		    counters->close_single_quote++;
ali@43
   970
	    }
ali@43
   971
	}
ali@43
   972
	if (*s!=CHAR_SPACE && *s!='-' && *s!='.' && *s!=CHAR_ASTERISK &&
ali@43
   973
	  *s!=13 && *s!=10)
ali@43
   974
	    isemptyline=0;  /* ignore lines like  *  *  *  as spacers */
ali@43
   975
	if (*s==CHAR_UNDERSCORE)
ali@43
   976
	    counters->c_unders++;
ali@43
   977
	if (*s==CHAR_OPEN_CBRACK)
ali@43
   978
	    counters->c_brack++;
ali@43
   979
	if (*s==CHAR_CLOSE_CBRACK)
ali@43
   980
	    counters->c_brack--;
ali@43
   981
	if (*s==CHAR_OPEN_RBRACK)
ali@43
   982
	    counters->r_brack++;
ali@43
   983
	if (*s==CHAR_CLOSE_RBRACK)
ali@43
   984
	    counters->r_brack--;
ali@43
   985
	if (*s==CHAR_OPEN_SBRACK)
ali@43
   986
	    counters->s_brack++;
ali@43
   987
	if (*s==CHAR_CLOSE_SBRACK)
ali@43
   988
	    counters->s_brack--;
ali@43
   989
	s++;
ali@43
   990
    }
ali@43
   991
    return isemptyline;
ali@43
   992
}
ali@43
   993
ali@41
   994
/*
ali@67
   995
 * check_for_control_characters:
ali@67
   996
 *
ali@67
   997
 * Check for invalid or questionable characters in the line
ali@67
   998
 * Anything above 127 is invalid for plain ASCII, and
ali@67
   999
 * non-printable control characters should also be flagged.
ali@67
  1000
 * Tabs should generally not be there.
ali@67
  1001
 */
ali@67
  1002
void check_for_control_characters(const char *aline)
ali@67
  1003
{
ali@67
  1004
    unsigned char c;
ali@67
  1005
    const char *s;
ali@67
  1006
    for (s=aline;*s;s++)
ali@67
  1007
    {
ali@67
  1008
	c=*(unsigned char *)s;
ali@67
  1009
	if (c<CHAR_SPACE && c!=CHAR_LF && c!=CHAR_CR && c!=CHAR_TAB)
ali@67
  1010
	{
ali@67
  1011
	    if (pswit[ECHO_SWITCH])
ali@67
  1012
		printf("\n%s\n",aline);
ali@67
  1013
	    if (!pswit[OVERVIEW_SWITCH])
ali@67
  1014
		printf("    Line %ld column %d - Control character %d\n",
ali@67
  1015
		  linecnt,(int)(s-aline)+1,c);
ali@67
  1016
	    else
ali@67
  1017
		cnt_bin++;
ali@67
  1018
	}
ali@67
  1019
    }
ali@67
  1020
}
ali@67
  1021
ali@67
  1022
/*
ali@44
  1023
 * check_for_odd_characters:
ali@44
  1024
 *
ali@44
  1025
 * Check for binary and other odd characters.
ali@44
  1026
 */
ali@44
  1027
void check_for_odd_characters(const char *aline,const struct warnings *warnings,
ali@44
  1028
  int isemptyline)
ali@44
  1029
{
ali@44
  1030
    /* Don't repeat multiple warnings on one line. */
ali@44
  1031
    signed int eNon_A=0,eTab=0,eTilde=0,eCarat=0,eFSlash=0,eAst=0;
ali@44
  1032
    const char *s;
ali@44
  1033
    unsigned char c;
ali@44
  1034
    for (s=aline;*s;s++)
ali@44
  1035
    {
ali@44
  1036
	c=*(unsigned char *)s;
ali@44
  1037
	if (!eNon_A && (*s<CHAR_SPACE && *s!=9 && *s!='\n' || c>127))
ali@44
  1038
	{
ali@44
  1039
	    if (pswit[ECHO_SWITCH])
ali@44
  1040
		printf("\n%s\n",aline);
ali@44
  1041
	    if (!pswit[OVERVIEW_SWITCH])
ali@44
  1042
		if (c>127 && c<160)
ali@44
  1043
		    printf("    Line %ld column %d - "
ali@44
  1044
		      "Non-ISO-8859 character %d\n",linecnt,(int)(s-aline)+1,c);
ali@44
  1045
		else
ali@44
  1046
		    printf("    Line %ld column %d - Non-ASCII character %d\n",
ali@44
  1047
		      linecnt,(int)(s-aline)+1,c);
ali@44
  1048
	    else
ali@44
  1049
		cnt_bin++;
ali@44
  1050
	    eNon_A=1;
ali@44
  1051
	}
ali@44
  1052
	if (!eTab && *s==CHAR_TAB)
ali@44
  1053
	{
ali@44
  1054
	    if (pswit[ECHO_SWITCH])
ali@44
  1055
		printf("\n%s\n",aline);
ali@44
  1056
	    if (!pswit[OVERVIEW_SWITCH])
ali@44
  1057
		printf("    Line %ld column %d - Tab character?\n",
ali@44
  1058
		  linecnt,(int)(s-aline)+1);
ali@44
  1059
	    else
ali@44
  1060
		cnt_odd++;
ali@44
  1061
	    eTab=1;
ali@44
  1062
	}
ali@44
  1063
	if (!eTilde && *s==CHAR_TILDE)
ali@44
  1064
	{
ali@44
  1065
	    /*
ali@44
  1066
	     * Often used by OCR software to indicate an
ali@44
  1067
	     * unrecognizable character.
ali@44
  1068
	     */
ali@44
  1069
	    if (pswit[ECHO_SWITCH])
ali@44
  1070
		printf("\n%s\n",aline);
ali@44
  1071
	    if (!pswit[OVERVIEW_SWITCH])
ali@44
  1072
		printf("    Line %ld column %d - Tilde character?\n",
ali@44
  1073
		  linecnt,(int)(s-aline)+1);
ali@44
  1074
	    else
ali@44
  1075
		cnt_odd++;
ali@44
  1076
	    eTilde=1;
ali@44
  1077
	}
ali@44
  1078
	if (!eCarat && *s==CHAR_CARAT)
ali@44
  1079
	{  
ali@44
  1080
	    if (pswit[ECHO_SWITCH])
ali@44
  1081
		printf("\n%s\n",aline);
ali@44
  1082
	    if (!pswit[OVERVIEW_SWITCH])
ali@44
  1083
		printf("    Line %ld column %d - Carat character?\n",
ali@44
  1084
		  linecnt,(int)(s-aline)+1);
ali@44
  1085
	    else
ali@44
  1086
		cnt_odd++;
ali@44
  1087
	    eCarat=1;
ali@44
  1088
	}
ali@44
  1089
	if (!eFSlash && *s==CHAR_FORESLASH && warnings->fslash)
ali@44
  1090
	{  
ali@44
  1091
	    if (pswit[ECHO_SWITCH])
ali@44
  1092
		printf("\n%s\n",aline);
ali@44
  1093
	    if (!pswit[OVERVIEW_SWITCH])
ali@44
  1094
		printf("    Line %ld column %d - Forward slash?\n",
ali@44
  1095
		  linecnt,(int)(s-aline)+1);
ali@44
  1096
	    else
ali@44
  1097
		cnt_odd++;
ali@44
  1098
	    eFSlash=1;
ali@44
  1099
	}
ali@44
  1100
	/*
ali@44
  1101
	 * Report asterisks only in paranoid mode,
ali@44
  1102
	 * since they're often deliberate.
ali@44
  1103
	 */
ali@44
  1104
	if (!eAst && pswit[PARANOID_SWITCH] && warnings->ast && !isemptyline &&
ali@44
  1105
	  *s==CHAR_ASTERISK)
ali@44
  1106
	{
ali@44
  1107
	    if (pswit[ECHO_SWITCH])
ali@44
  1108
		printf("\n%s\n",aline);
ali@44
  1109
	    if (!pswit[OVERVIEW_SWITCH])
ali@44
  1110
		printf("    Line %ld column %d - Asterisk?\n",
ali@44
  1111
		  linecnt,(int)(s-aline)+1);
ali@44
  1112
	    else
ali@44
  1113
		cnt_odd++;
ali@44
  1114
	    eAst=1;
ali@44
  1115
	}
ali@44
  1116
    }
ali@44
  1117
}
ali@44
  1118
ali@44
  1119
/*
ali@45
  1120
 * check_for_long_line:
ali@45
  1121
 *
ali@45
  1122
 * Check for line too long.
ali@45
  1123
 */
ali@45
  1124
void check_for_long_line(const char *aline)
ali@45
  1125
{
ali@45
  1126
    if (strlen(aline)>LONGEST_PG_LINE)
ali@45
  1127
    {
ali@45
  1128
	if (pswit[ECHO_SWITCH])
ali@45
  1129
	    printf("\n%s\n",aline);
ali@45
  1130
	if (!pswit[OVERVIEW_SWITCH])
ali@45
  1131
	    printf("    Line %ld column %d - Long line %d\n",
ali@45
  1132
	      linecnt,strlen(aline),strlen(aline));
ali@45
  1133
	else
ali@45
  1134
	    cnt_long++;
ali@45
  1135
    }
ali@45
  1136
}
ali@45
  1137
ali@45
  1138
struct line_properties {
ali@45
  1139
    unsigned int len,blen;
ali@45
  1140
    char start;
ali@45
  1141
};
ali@45
  1142
ali@45
  1143
/*
ali@45
  1144
 * check_for_short_line:
ali@45
  1145
 *
ali@45
  1146
 * Check for line too short.
ali@45
  1147
 *
ali@45
  1148
 * This one is a bit trickier to implement: we don't want to
ali@45
  1149
 * flag the last line of a paragraph for being short, so we
ali@45
  1150
 * have to wait until we know that our current line is a
ali@45
  1151
 * "normal" line, then report the _previous_ line if it was too
ali@45
  1152
 * short. We also don't want to report indented lines like
ali@45
  1153
 * chapter heads or formatted quotations. We therefore keep
ali@45
  1154
 * last->len as the length of the last line examined, and
ali@45
  1155
 * last->blen as the length of the last but one, and try to
ali@45
  1156
 * suppress unnecessary warnings by checking that both were of
ali@45
  1157
 * "normal" length. We keep the first character of the last
ali@45
  1158
 * line in last->start, and if it was a space, we assume that
ali@45
  1159
 * the formatting is deliberate. I can't figure out a way to
ali@45
  1160
 * distinguish something like a quoted verse left-aligned or
ali@45
  1161
 * the header or footer of a letter from a paragraph of short
ali@45
  1162
 * lines - maybe if I examined the whole paragraph, and if the
ali@45
  1163
 * para has less than, say, 8 lines and if all lines are short,
ali@45
  1164
 * then just assume it's OK? Need to look at some texts to see
ali@45
  1165
 * how often a formula like this would get the right result.
ali@45
  1166
 */
ali@45
  1167
void check_for_short_line(const char *aline,const struct line_properties *last)
ali@45
  1168
{
ali@45
  1169
    if (strlen(aline)>1 && last->len>1 && last->len<SHORTEST_PG_LINE &&
ali@45
  1170
      last->blen>1 && last->blen>SHORTEST_PG_LINE && last->start!=CHAR_SPACE)
ali@45
  1171
    {
ali@45
  1172
	if (pswit[ECHO_SWITCH])
ali@45
  1173
	    printf("\n%s\n",prevline);
ali@45
  1174
	if (!pswit[OVERVIEW_SWITCH])
ali@45
  1175
	    printf("    Line %ld column %d - Short line %d?\n",
ali@45
  1176
	      linecnt-1,strlen(prevline),strlen(prevline));
ali@45
  1177
	else
ali@45
  1178
	    cnt_short++;
ali@45
  1179
    }
ali@45
  1180
}
ali@45
  1181
ali@45
  1182
/*
ali@46
  1183
 * check_for_starting_punctuation:
ali@46
  1184
 *
ali@46
  1185
 * Look for punctuation other than full ellipses at start of line.
ali@46
  1186
 */
ali@46
  1187
void check_for_starting_punctuation(const char *aline)
ali@46
  1188
{
ali@46
  1189
    if (*aline && strchr(".?!,;:",aline[0]) && strncmp(". . .",aline,5))
ali@46
  1190
    {
ali@46
  1191
	if (pswit[ECHO_SWITCH])
ali@46
  1192
	    printf("\n%s\n",aline);
ali@46
  1193
	if (!pswit[OVERVIEW_SWITCH])
ali@46
  1194
	    printf("    Line %ld column 1 - Begins with punctuation?\n",
ali@46
  1195
	      linecnt);
ali@46
  1196
	else
ali@46
  1197
	    cnt_punct++;
ali@46
  1198
    }
ali@46
  1199
}
ali@46
  1200
ali@46
  1201
/*
ali@47
  1202
 * check_for_spaced_emdash:
ali@47
  1203
 *
ali@47
  1204
 * Check for spaced em-dashes.
ali@47
  1205
 *
ali@47
  1206
 * We must check _all_ occurrences of "--" on the line
ali@47
  1207
 * hence the loop - even if the first double-dash is OK
ali@47
  1208
 * there may be another that's wrong later on.
ali@47
  1209
 */
ali@47
  1210
void check_for_spaced_emdash(const char *aline)
ali@47
  1211
{
ali@47
  1212
    const char *s,*t;
ali@47
  1213
    s=aline;
ali@47
  1214
    while ((t=strstr(s,"--")))
ali@47
  1215
    {
ali@47
  1216
	if (t>aline && t[-1]==CHAR_SPACE || t[2]==CHAR_SPACE)
ali@47
  1217
	{
ali@47
  1218
	    if (pswit[ECHO_SWITCH])
ali@47
  1219
		printf("\n%s\n",aline);
ali@47
  1220
	    if (!pswit[OVERVIEW_SWITCH])
ali@47
  1221
		printf("    Line %ld column %d - Spaced em-dash?\n",
ali@47
  1222
		  linecnt,(int)(t-aline)+1);
ali@47
  1223
	    else
ali@47
  1224
		cnt_dash++;
ali@47
  1225
	}
ali@47
  1226
	s=t+2;
ali@47
  1227
    }
ali@47
  1228
}
ali@47
  1229
ali@47
  1230
/*
ali@47
  1231
 * check_for_spaced_dash:
ali@47
  1232
 *
ali@47
  1233
 * Check for spaced dashes.
ali@47
  1234
 */
ali@47
  1235
void check_for_spaced_dash(const char *aline)
ali@47
  1236
{
ali@47
  1237
    const char *s;
ali@47
  1238
    if ((s=strstr(aline," -")))
ali@47
  1239
    {
ali@47
  1240
	if (s[2]!='-')
ali@47
  1241
	{
ali@47
  1242
	    if (pswit[ECHO_SWITCH])
ali@47
  1243
		printf("\n%s\n",aline);
ali@47
  1244
	    if (!pswit[OVERVIEW_SWITCH])
ali@47
  1245
		printf("    Line %ld column %d - Spaced dash?\n",
ali@47
  1246
		  linecnt,(int)(s-aline)+1);
ali@47
  1247
	    else
ali@47
  1248
		cnt_dash++;
ali@47
  1249
	}
ali@47
  1250
    }
ali@47
  1251
    else if ((s=strstr(aline,"- ")))
ali@47
  1252
    {
ali@47
  1253
	if (s==aline || s[-1]!='-')
ali@47
  1254
	{
ali@47
  1255
	    if (pswit[ECHO_SWITCH])
ali@47
  1256
		printf("\n%s\n",aline);
ali@47
  1257
	    if (!pswit[OVERVIEW_SWITCH])
ali@47
  1258
		printf("    Line %ld column %d - Spaced dash?\n",
ali@47
  1259
		  linecnt,(int)(s-aline)+1);
ali@47
  1260
	    else
ali@47
  1261
		cnt_dash++;
ali@47
  1262
	}
ali@47
  1263
    }
ali@47
  1264
}
ali@47
  1265
ali@47
  1266
/*
ali@48
  1267
 * check_for_unmarked_paragraphs:
ali@48
  1268
 *
ali@48
  1269
 * Check for unmarked paragraphs indicated by separate speakers.
ali@48
  1270
 *
ali@48
  1271
 * May well be false positive:
ali@48
  1272
 * "Bravo!" "Wonderful!" called the crowd.
ali@48
  1273
 * but useful all the same.
ali@48
  1274
 */
ali@48
  1275
void check_for_unmarked_paragraphs(const char *aline)
ali@48
  1276
{
ali@48
  1277
    const char *s;
ali@48
  1278
    s=strstr(aline,"\"  \"");
ali@48
  1279
    if (!s)
ali@48
  1280
	s=strstr(aline,"\" \"");
ali@48
  1281
    if (s)
ali@48
  1282
    {
ali@48
  1283
	if (pswit[ECHO_SWITCH])
ali@48
  1284
	    printf("\n%s\n",aline);
ali@48
  1285
	if (!pswit[OVERVIEW_SWITCH])
ali@48
  1286
	    printf("    Line %ld column %d - Query missing paragraph break?\n",
ali@48
  1287
	      linecnt,(int)(s-aline)+1);
ali@48
  1288
	else
ali@48
  1289
	    cnt_punct++;
ali@48
  1290
    }
ali@48
  1291
}
ali@48
  1292
ali@48
  1293
/*
ali@49
  1294
 * check_for_jeebies:
ali@49
  1295
 *
ali@49
  1296
 * Check for "to he" and other easy h/b errors.
ali@49
  1297
 *
ali@49
  1298
 * This is a very inadequate effort on the h/b problem,
ali@49
  1299
 * but the phrase "to he" is always an error, whereas "to
ali@49
  1300
 * be" is quite common.
ali@49
  1301
 * Similarly, '"Quiet!", be said.' is a non-be error
ali@49
  1302
 * "to he" is _not_ always an error!:
ali@49
  1303
 *       "Where they went to he couldn't say."
ali@49
  1304
 * Another false positive:
ali@49
  1305
 *       What would "Cinderella" be without the . . .
ali@49
  1306
 * and another: "If he wants to he can see for himself."
ali@49
  1307
 */
ali@49
  1308
void check_for_jeebies(const char *aline)
ali@49
  1309
{
ali@49
  1310
    const char *s;
ali@49
  1311
    s=strstr(aline," be could ");
ali@49
  1312
    if (!s)
ali@49
  1313
	s=strstr(aline," be would ");
ali@49
  1314
    if (!s)
ali@49
  1315
	s=strstr(aline," was be ");
ali@49
  1316
    if (!s)
ali@49
  1317
	s=strstr(aline," be is ");
ali@49
  1318
    if (!s)
ali@49
  1319
	s=strstr(aline," is be ");
ali@49
  1320
    if (!s)
ali@49
  1321
	s=strstr(aline,"\", be ");
ali@49
  1322
    if (!s)
ali@49
  1323
	s=strstr(aline,"\" be ");
ali@49
  1324
    if (!s)
ali@49
  1325
	s=strstr(aline,"\" be ");
ali@49
  1326
    if (!s)
ali@49
  1327
	s=strstr(aline," to he ");
ali@49
  1328
    if (s)
ali@49
  1329
    {
ali@49
  1330
	if (pswit[ECHO_SWITCH])
ali@49
  1331
	    printf("\n%s\n",aline);
ali@49
  1332
	if (!pswit[OVERVIEW_SWITCH])
ali@49
  1333
	    printf("    Line %ld column %d - Query he/be error?\n",
ali@49
  1334
	      linecnt,(int)(s-aline)+1);
ali@49
  1335
	else
ali@49
  1336
	    cnt_word++;
ali@49
  1337
    }
ali@49
  1338
    s=strstr(aline," the had ");
ali@49
  1339
    if (!s)
ali@49
  1340
	s=strstr(aline," a had ");
ali@49
  1341
    if (!s)
ali@49
  1342
	s=strstr(aline," they bad ");
ali@49
  1343
    if (!s)
ali@49
  1344
	s=strstr(aline," she bad ");
ali@49
  1345
    if (!s)
ali@49
  1346
	s=strstr(aline," he bad ");
ali@49
  1347
    if (!s)
ali@49
  1348
	s=strstr(aline," you bad ");
ali@49
  1349
    if (!s)
ali@49
  1350
	s=strstr(aline," i bad ");
ali@49
  1351
    if (s)
ali@49
  1352
    {
ali@49
  1353
	if (pswit[ECHO_SWITCH])
ali@49
  1354
	    printf("\n%s\n",aline);
ali@49
  1355
	if (!pswit[OVERVIEW_SWITCH])
ali@49
  1356
	    printf("    Line %ld column %d - Query had/bad error?\n",
ali@49
  1357
	      linecnt,(int)(s-aline)+1);
ali@49
  1358
	else
ali@49
  1359
	    cnt_word++;
ali@49
  1360
    }
ali@49
  1361
    s=strstr(aline,"; hut ");
ali@49
  1362
    if (!s)
ali@49
  1363
	s=strstr(aline,", hut ");
ali@49
  1364
    if (s)
ali@49
  1365
    {
ali@49
  1366
	if (pswit[ECHO_SWITCH])
ali@49
  1367
	    printf("\n%s\n",aline);
ali@49
  1368
	if (!pswit[OVERVIEW_SWITCH])
ali@49
  1369
	    printf("    Line %ld column %d - Query hut/but error?\n",
ali@49
  1370
	      linecnt,(int)(s-aline)+1);
ali@49
  1371
	else
ali@49
  1372
	    cnt_word++;
ali@49
  1373
    }
ali@49
  1374
}
ali@49
  1375
ali@49
  1376
/*
ali@50
  1377
 * check_for_mta_from:
ali@50
  1378
 *
ali@50
  1379
 * Special case - angled bracket in front of "From" placed there by an
ali@50
  1380
 * MTA when sending an e-mail.
ali@50
  1381
 */
ali@50
  1382
void check_for_mta_from(const char *aline)
ali@50
  1383
{
ali@50
  1384
    const char *s;
ali@50
  1385
    s=strstr(aline,">From");
ali@50
  1386
    if (s)
ali@50
  1387
    {
ali@50
  1388
	if (pswit[ECHO_SWITCH])
ali@50
  1389
	    printf("\n%s\n",aline);
ali@50
  1390
	if (!pswit[OVERVIEW_SWITCH])
ali@50
  1391
	    printf("    Line %ld column %d - Query angled bracket with From\n",
ali@50
  1392
	      linecnt,(int)(s-aline)+1);
ali@50
  1393
	else
ali@50
  1394
	    cnt_punct++;
ali@50
  1395
    }
ali@50
  1396
}
ali@50
  1397
ali@50
  1398
/*
ali@51
  1399
 * check_for_orphan_character:
ali@51
  1400
 *
ali@51
  1401
 * Check for a single character line -
ali@51
  1402
 * often an overflow from bad wrapping.
ali@51
  1403
 */
ali@51
  1404
void check_for_orphan_character(const char *aline)
ali@51
  1405
{
ali@51
  1406
    if (*aline && !aline[1])
ali@51
  1407
    {
ali@51
  1408
	if (*aline=='I' || *aline=='V' || *aline=='X' || *aline=='L' ||
ali@51
  1409
	  gcisdigit(*aline))
ali@51
  1410
	    ; /* Nothing - ignore numerals alone on a line. */
ali@51
  1411
	else
ali@51
  1412
	{
ali@51
  1413
	    if (pswit[ECHO_SWITCH])
ali@51
  1414
		printf("\n%s\n",aline);
ali@51
  1415
	    if (!pswit[OVERVIEW_SWITCH])
ali@51
  1416
		printf("    Line %ld column 1 - Query single character line\n",
ali@51
  1417
		  linecnt);
ali@51
  1418
	    else
ali@51
  1419
		cnt_punct++;
ali@51
  1420
	}
ali@51
  1421
    }
ali@51
  1422
}
ali@51
  1423
ali@51
  1424
/*
ali@52
  1425
 * check_for_pling_scanno:
ali@52
  1426
 *
ali@52
  1427
 * Check for I" - often should be !
ali@52
  1428
 */
ali@52
  1429
void check_for_pling_scanno(const char *aline)
ali@52
  1430
{
ali@52
  1431
    const char *s;
ali@52
  1432
    s=strstr(aline," I\"");
ali@52
  1433
    if (s)
ali@52
  1434
    {
ali@52
  1435
	if (pswit[ECHO_SWITCH])
ali@52
  1436
	    printf("\n%s\n",aline);
ali@52
  1437
	if (!pswit[OVERVIEW_SWITCH])
ali@52
  1438
	    printf("    Line %ld column %ld - Query I=exclamation mark?\n",
ali@52
  1439
	      linecnt,s-aline);
ali@52
  1440
	else
ali@52
  1441
	    cnt_punct++;
ali@52
  1442
    }
ali@52
  1443
}
ali@52
  1444
ali@52
  1445
/*
ali@53
  1446
 * check_for_extra_period:
ali@53
  1447
 *
ali@53
  1448
 * Check for period without a capital letter. Cut-down from gutspell.
ali@53
  1449
 * Only works when it happens on a single line.
ali@53
  1450
 */
ali@53
  1451
void check_for_extra_period(const char *aline,const struct warnings *warnings)
ali@53
  1452
{
ali@53
  1453
    const char *s,*t,*s1;
ali@53
  1454
    signed int i,istypo,isdup;
ali@53
  1455
    static char qperiod[MAX_QWORD][MAX_QWORD_LENGTH];
ali@53
  1456
    static int qperiod_index=0;
ali@53
  1457
    char testword[MAXWORDLEN]="";
ali@53
  1458
    if (pswit[PARANOID_SWITCH])
ali@53
  1459
    {
ali@53
  1460
	for (t=s=aline;strstr(t,". ");)
ali@53
  1461
	{
ali@53
  1462
	    t=strstr(t,". ");
ali@53
  1463
	    if (t==s)
ali@53
  1464
	    {
ali@53
  1465
		t++;
ali@53
  1466
		/* start of line punctuation is handled elsewhere */
ali@53
  1467
		continue;
ali@53
  1468
	    }
ali@53
  1469
	    if (!gcisalpha(t[-1]))
ali@53
  1470
	    {
ali@53
  1471
		t++;
ali@53
  1472
		continue;
ali@53
  1473
	    }
ali@53
  1474
	    if (warnings->isDutch)
ali@53
  1475
	    {
ali@53
  1476
		/* For Frank & Jeroen -- 's Middags case */
ali@53
  1477
		if (t[2]==CHAR_SQUOTE && t[3]>='a' && t[3]<='z' &&
ali@53
  1478
		  t[4]==CHAR_SPACE && t[5]>='A' && t[5]<='Z')
ali@53
  1479
		{
ali@53
  1480
		    t++;
ali@53
  1481
		    continue;
ali@53
  1482
		}
ali@53
  1483
	    }
ali@53
  1484
	    s1=t+2;
ali@53
  1485
	    while (*s1 && !gcisalpha(*s1) && !isdigit(*s1))
ali@53
  1486
		s1++;
ali@53
  1487
	    if (*s1>='a' && *s1<='z')
ali@53
  1488
	    {
ali@53
  1489
		/* we have something to investigate */
ali@53
  1490
		istypo=1;
ali@53
  1491
		/* so let's go back and find out */
ali@53
  1492
		for (s1=t-1;s1>=s &&
ali@53
  1493
		  (gcisalpha(*s1) || gcisdigit(*s1) || *s1==CHAR_SQUOTE &&
ali@53
  1494
		  gcisalpha(s1[1]) && gcisalpha(s1[-1]));s1--)
ali@53
  1495
		    ;
ali@53
  1496
		s1++;
ali@53
  1497
		for (i=0;*s1 && *s1!='.';s1++,i++)
ali@53
  1498
		    testword[i]=*s1;
ali@53
  1499
		testword[i]=0;
ali@53
  1500
		for (i=0;*abbrev[i];i++)
ali@53
  1501
		    if (!strcmp(testword,abbrev[i]))
ali@53
  1502
			istypo=0;
ali@53
  1503
		if (gcisdigit(*testword))
ali@53
  1504
		    istypo=0;
ali@53
  1505
		if (!testword[1])
ali@53
  1506
		    istypo=0;
ali@53
  1507
		if (isroman(testword))
ali@53
  1508
		    istypo=0;
ali@53
  1509
		if (istypo)
ali@53
  1510
		{
ali@53
  1511
		    istypo=0;
ali@53
  1512
		    for (i=0;testword[i];i++)
ali@53
  1513
			if (strchr(vowels,testword[i]))
ali@53
  1514
			    istypo=1;
ali@53
  1515
		}
ali@53
  1516
		if (istypo)
ali@53
  1517
		{
ali@53
  1518
		    isdup=0;
ali@53
  1519
		    if (strlen(testword)<MAX_QWORD_LENGTH &&
ali@53
  1520
		      !pswit[VERBOSE_SWITCH])
ali@53
  1521
			for (i=0;i<qperiod_index;i++)
ali@53
  1522
			    if (!strcmp(testword,qperiod[i]))
ali@53
  1523
				isdup=1;
ali@53
  1524
		    if (!isdup)
ali@53
  1525
		    {
ali@53
  1526
			if (qperiod_index<MAX_QWORD &&
ali@53
  1527
			  strlen(testword)<MAX_QWORD_LENGTH)
ali@53
  1528
			{
ali@53
  1529
			    strcpy(qperiod[qperiod_index],testword);
ali@53
  1530
			    qperiod_index++;
ali@53
  1531
			}
ali@53
  1532
			if (pswit[ECHO_SWITCH])
ali@53
  1533
			    printf("\n%s\n",aline);
ali@53
  1534
			if (!pswit[OVERVIEW_SWITCH])
ali@53
  1535
			    printf("    Line %ld column %d - Extra period?\n",
ali@53
  1536
			      linecnt,(int)(t-aline)+1);
ali@53
  1537
			else
ali@53
  1538
			    cnt_punct++;
ali@53
  1539
		    }
ali@53
  1540
		}
ali@53
  1541
	    }
ali@53
  1542
	    t++;
ali@53
  1543
	}
ali@53
  1544
    }
ali@53
  1545
}
ali@53
  1546
ali@53
  1547
/*
ali@54
  1548
 * check_for_following_punctuation:
ali@54
  1549
 *
ali@54
  1550
 * Check for words usually not followed by punctuation.
ali@54
  1551
 */
ali@54
  1552
void check_for_following_punctuation(const char *aline)
ali@54
  1553
{
ali@54
  1554
    int i;
ali@54
  1555
    const char *s,*wordstart;
ali@54
  1556
    char inword[MAXWORDLEN];
ali@54
  1557
    if (pswit[TYPO_SWITCH])
ali@54
  1558
    {
ali@54
  1559
	for (s=aline;*s;)
ali@54
  1560
	{
ali@54
  1561
	    wordstart=s;
ali@54
  1562
	    s=getaword(s,inword);
ali@54
  1563
	    if (!*inword)
ali@54
  1564
		continue;
ali@54
  1565
	    lowerit(inword);
ali@54
  1566
	    for (i=0;*nocomma[i];i++)
ali@54
  1567
		if (!strcmp(inword,nocomma[i]))
ali@54
  1568
		{
ali@54
  1569
		    if (*s==',' || *s==';' || *s==':')
ali@54
  1570
		    {
ali@54
  1571
			if (pswit[ECHO_SWITCH])
ali@54
  1572
			    printf("\n%s\n",aline);
ali@54
  1573
			if (!pswit[OVERVIEW_SWITCH])
ali@54
  1574
			    printf("    Line %ld column %d - "
ali@54
  1575
			      "Query punctuation after %s?\n",
ali@54
  1576
			      linecnt,(int)(s-aline)+1,inword);
ali@54
  1577
			else
ali@54
  1578
			    cnt_punct++;
ali@54
  1579
		    }
ali@54
  1580
		}
ali@54
  1581
	    for (i=0;*noperiod[i];i++)
ali@54
  1582
		if (!strcmp(inword,noperiod[i]))
ali@54
  1583
		{
ali@54
  1584
		    if (*s=='.' || *s=='!')
ali@54
  1585
		    {
ali@54
  1586
			if (pswit[ECHO_SWITCH])
ali@54
  1587
			    printf("\n%s\n",aline);
ali@54
  1588
			if (!pswit[OVERVIEW_SWITCH])
ali@54
  1589
			    printf("    Line %ld column %d - "
ali@54
  1590
			      "Query punctuation after %s?\n",
ali@54
  1591
			      linecnt,(int)(s-aline)+1,inword);
ali@54
  1592
			else
ali@54
  1593
			    cnt_punct++;
ali@54
  1594
		    }
ali@54
  1595
		}
ali@54
  1596
	}
ali@54
  1597
    }
ali@54
  1598
}
ali@54
  1599
ali@54
  1600
/*
ali@55
  1601
 * check_for_typos:
ali@55
  1602
 *
ali@55
  1603
 * Check for commonly mistyped words,
ali@55
  1604
 * and digits like 0 for O in a word.
ali@55
  1605
 */
ali@55
  1606
void check_for_typos(const char *aline,struct warnings *warnings)
ali@55
  1607
{
ali@55
  1608
    const char *s,*wordstart;
ali@55
  1609
    char inword[MAXWORDLEN],testword[MAXWORDLEN];
ali@55
  1610
    int i,istypo,isdup,alower,vowel,consonant;
ali@55
  1611
    static int qword_index=0;
ali@55
  1612
    for (s=aline;*s;)
ali@55
  1613
    {
ali@55
  1614
	wordstart=s;
ali@55
  1615
	s=getaword(s,inword);
ali@55
  1616
	if (!*inword)
ali@55
  1617
	    continue; /* don't bother with empty lines */
ali@55
  1618
	if (mixdigit(inword))
ali@55
  1619
	{
ali@55
  1620
	    if (pswit[ECHO_SWITCH])
ali@55
  1621
		printf("\n%s\n",aline);
ali@55
  1622
	    if (!pswit[OVERVIEW_SWITCH])
ali@55
  1623
		printf("    Line %ld column %d - Query digit in %s\n",
ali@55
  1624
		  linecnt,(int)(wordstart-aline)+1,inword);
ali@55
  1625
	    else
ali@55
  1626
		cnt_word++;
ali@55
  1627
	}
ali@55
  1628
	/*
ali@55
  1629
	 * Put the word through a series of tests for likely typos and OCR
ali@55
  1630
	 * errors.
ali@55
  1631
	 */
ali@55
  1632
	if (pswit[TYPO_SWITCH])
ali@55
  1633
	{
ali@55
  1634
	    istypo=0;
ali@55
  1635
	    strcpy(testword,inword);
ali@55
  1636
	    alower=0;
ali@55
  1637
	    for (i=0;i<(signed int)strlen(testword);i++)
ali@55
  1638
	    {
ali@55
  1639
		/* lowercase for testing */
ali@55
  1640
		if (testword[i]>='a' && testword[i]<='z')
ali@55
  1641
		    alower=1;
ali@55
  1642
		if (alower && testword[i]>='A' && testword[i]<='Z')
ali@55
  1643
		{
ali@55
  1644
		    /*
ali@55
  1645
		     * We have an uppercase mid-word. However, there are
ali@55
  1646
		     * common cases:
ali@55
  1647
		     *   Mac and Mc like McGill
ali@55
  1648
		     *   French contractions like l'Abbe
ali@55
  1649
		     */
ali@55
  1650
		    if (i==2 && testword[0]=='m' && testword[1]=='c' ||
ali@55
  1651
		      i==3 && testword[0]=='m' && testword[1]=='a' &&
ali@55
  1652
		      testword[2]=='c' || i>0 && testword[i-1]==CHAR_SQUOTE)
ali@55
  1653
			; /* do nothing! */
ali@55
  1654
		    else
ali@55
  1655
			istypo=1;
ali@55
  1656
		}
ali@55
  1657
		testword[i]=(char)tolower(testword[i]);
ali@55
  1658
	    }
ali@55
  1659
	    /*
ali@55
  1660
	     * Check for certain unlikely two-letter combinations at word
ali@55
  1661
	     * start and end.
ali@55
  1662
	     */
ali@55
  1663
	    if (strlen(testword)>1)
ali@55
  1664
	    {
ali@55
  1665
		for (i=0;*nostart[i];i++)
ali@55
  1666
		    if (!strncmp(testword,nostart[i],2))
ali@55
  1667
			istypo=1;
ali@55
  1668
		for (i=0;*noend[i];i++)
ali@55
  1669
		    if (!strncmp(testword+strlen(testword)-2,noend[i],2))
ali@55
  1670
			istypo=1;
ali@55
  1671
	    }
ali@55
  1672
	    /* ght is common, gbt never. Like that. */
ali@55
  1673
	    if (strstr(testword,"cb"))
ali@55
  1674
		istypo=1;
ali@55
  1675
	    if (strstr(testword,"gbt"))
ali@55
  1676
		istypo=1;
ali@55
  1677
	    if (strstr(testword,"pbt"))
ali@55
  1678
		istypo=1;
ali@55
  1679
	    if (strstr(testword,"tbs"))
ali@55
  1680
		istypo=1;
ali@55
  1681
	    if (strstr(testword,"mrn"))
ali@55
  1682
		istypo=1;
ali@55
  1683
	    if (strstr(testword,"ahle"))
ali@55
  1684
		istypo=1;
ali@55
  1685
	    if (strstr(testword,"ihle"))
ali@55
  1686
		istypo=1;
ali@55
  1687
	    /*
ali@55
  1688
	     * "TBE" does happen - like HEARTBEAT - but uncommon.
ali@55
  1689
	     * Also "TBI" - frostbite, outbid - but uncommon.
ali@55
  1690
	     * Similarly "ii" like Hawaii, or Pompeii, and in Roman
ali@55
  1691
	     * numerals, but "ii" is a common scanno.
ali@55
  1692
	     */
ali@55
  1693
	    if (strstr(testword,"tbi"))
ali@55
  1694
		istypo=1;
ali@55
  1695
	    if (strstr(testword,"tbe"))
ali@55
  1696
		istypo=1;
ali@55
  1697
	    if (strstr(testword,"ii"))
ali@55
  1698
		istypo=1;
ali@55
  1699
	    /*
ali@55
  1700
	     * Check for no vowels or no consonants.
ali@55
  1701
	     * If none, flag a typo.
ali@55
  1702
	     */
ali@55
  1703
	    if (!istypo && strlen(testword)>1)
ali@55
  1704
	    {
ali@55
  1705
		vowel=consonant=0;
ali@55
  1706
		for (i=0;testword[i];i++)
ali@55
  1707
		{
ali@55
  1708
		    if (testword[i]=='y' || gcisdigit(testword[i]))
ali@55
  1709
		    {
ali@55
  1710
			/* Yah, this is loose. */
ali@55
  1711
			vowel++;
ali@55
  1712
			consonant++;
ali@55
  1713
		    }
ali@55
  1714
		    else if (strchr(vowels,testword[i]))
ali@55
  1715
			vowel++;
ali@55
  1716
		    else
ali@55
  1717
			consonant++;
ali@55
  1718
		}
ali@55
  1719
		if (!vowel || !consonant)
ali@55
  1720
		    istypo=1;
ali@55
  1721
	    }
ali@55
  1722
	    /*
ali@55
  1723
	     * Now exclude the word from being reported if it's in
ali@55
  1724
	     * the okword list.
ali@55
  1725
	     */
ali@55
  1726
	    for (i=0;*okword[i];i++)
ali@55
  1727
		if (!strcmp(testword,okword[i]))
ali@55
  1728
		    istypo=0;
ali@55
  1729
	    /*
ali@55
  1730
	     * What looks like a typo may be a Roman numeral.
ali@55
  1731
	     * Exclude these.
ali@55
  1732
	     */
ali@55
  1733
	    if (istypo && isroman(testword))
ali@55
  1734
		istypo=0;
ali@55
  1735
	    /* Check the manual list of typos. */
ali@55
  1736
	    if (!istypo)
ali@55
  1737
		for (i=0;*typo[i];i++)
ali@55
  1738
		    if (!strcmp(testword,typo[i]))
ali@55
  1739
			istypo=1;
ali@55
  1740
	    /*
ali@55
  1741
	     * Check lowercase s, l, i and m - special cases.
ali@55
  1742
	     *   "j" - often a semi-colon gone wrong.
ali@55
  1743
	     *   "d" for a missing apostrophe - he d
ali@55
  1744
	     *   "n" for "in"
ali@55
  1745
	     */
ali@55
  1746
	    if (!istypo && strlen(testword)==1 && strchr("slmijdn",*inword))
ali@55
  1747
		istypo=1;
ali@55
  1748
	    if (istypo)
ali@55
  1749
	    {
ali@55
  1750
		isdup=0;
ali@55
  1751
		if (strlen(testword)<MAX_QWORD_LENGTH &&
ali@55
  1752
		  !pswit[VERBOSE_SWITCH])
ali@55
  1753
		    for (i=0;i<qword_index;i++)
ali@55
  1754
			if (!strcmp(testword,qword[i]))
ali@55
  1755
			{
ali@55
  1756
			    isdup=1;
ali@55
  1757
			    ++dupcnt[i];
ali@55
  1758
			}
ali@55
  1759
		if (!isdup)
ali@55
  1760
		{
ali@55
  1761
		    if (qword_index<MAX_QWORD &&
ali@55
  1762
		      strlen(testword)<MAX_QWORD_LENGTH)
ali@55
  1763
		    {
ali@55
  1764
			strcpy(qword[qword_index],testword);
ali@55
  1765
			qword_index++;
ali@55
  1766
		    }
ali@55
  1767
		    if (pswit[ECHO_SWITCH])
ali@55
  1768
			printf("\n%s\n",aline);
ali@55
  1769
		    if (!pswit[OVERVIEW_SWITCH])
ali@55
  1770
		    {
ali@55
  1771
			printf("    Line %ld column %d - Query word %s",
ali@55
  1772
			  linecnt,(int)(wordstart-aline)+1,inword);
ali@55
  1773
			if (strlen(testword)<MAX_QWORD_LENGTH &&
ali@55
  1774
			  !pswit[VERBOSE_SWITCH])
ali@55
  1775
			    printf(" - not reporting duplicates");
ali@55
  1776
			printf("\n");
ali@55
  1777
		    }
ali@55
  1778
		    else
ali@55
  1779
			cnt_word++;
ali@55
  1780
		}
ali@55
  1781
	    }
ali@55
  1782
	}
ali@55
  1783
	/* check the user's list of typos */
ali@55
  1784
	if (!istypo && usertypo_count)
ali@55
  1785
	    for (i=0;i<usertypo_count;i++)
ali@55
  1786
		if (!strcmp(testword,usertypo[i]))
ali@55
  1787
		{
ali@55
  1788
		    if (pswit[ECHO_SWITCH])
ali@55
  1789
			printf("\n%s\n",aline);
ali@55
  1790
		    if (!pswit[OVERVIEW_SWITCH])  
ali@55
  1791
			printf("    Line %ld column %d - "
ali@55
  1792
			  "Query possible scanno %s\n",
ali@55
  1793
			  linecnt,(int)(wordstart-aline)+2,inword);
ali@55
  1794
		}
ali@55
  1795
	if (pswit[PARANOID_SWITCH] && warnings->digit)
ali@55
  1796
	{
ali@55
  1797
	    /* In paranoid mode, query all 0 and 1 standing alone. */
ali@55
  1798
	    if (!strcmp(inword,"0") || !strcmp(inword,"1"))
ali@55
  1799
	    {
ali@55
  1800
		if (pswit[ECHO_SWITCH])
ali@55
  1801
		    printf("\n%s\n",aline);
ali@55
  1802
		if (!pswit[OVERVIEW_SWITCH])
ali@55
  1803
		    printf("    Line %ld column %d - Query standalone %s\n",
ali@55
  1804
		      linecnt,(int)(wordstart-aline)+2,inword);
ali@55
  1805
		else
ali@55
  1806
		    cnt_word++;
ali@55
  1807
	    }
ali@55
  1808
	}
ali@55
  1809
    }
ali@55
  1810
}
ali@55
  1811
ali@56
  1812
struct parities {
ali@56
  1813
    int dquote,squote;
ali@56
  1814
};
ali@56
  1815
ali@56
  1816
/*
ali@56
  1817
 * check_for_misspaced_punctuation:
ali@56
  1818
 *
ali@56
  1819
 * Look for added or missing spaces around punctuation and quotes.
ali@56
  1820
 * If there is a punctuation character like ! with no space on
ali@56
  1821
 * either side, suspect a missing!space. If there are spaces on
ali@56
  1822
 * both sides , assume a typo. If we see a double quote with no
ali@56
  1823
 * space or punctuation on either side of it, assume unspaced
ali@56
  1824
 * quotes "like"this.
ali@56
  1825
 */
ali@56
  1826
void check_for_misspaced_punctuation(const char *aline,
ali@56
  1827
  struct parities *parities,int isemptyline)
ali@56
  1828
{
ali@56
  1829
    int i,llen,isacro,isellipsis;
ali@56
  1830
    const char *s;
ali@56
  1831
    llen=strlen(aline);
ali@56
  1832
    for (i=1;i<llen;i++)
ali@56
  1833
    {
ali@56
  1834
	/* For each character in the line after the first. */
ali@56
  1835
	if (strchr(".?!,;:_",aline[i]))  /* if it's punctuation */
ali@56
  1836
	{
ali@56
  1837
	    /* we need to suppress warnings for acronyms like M.D. */
ali@56
  1838
	    isacro=0;
ali@56
  1839
	    /* we need to suppress warnings for ellipsis . . . */
ali@56
  1840
	    isellipsis=0;
ali@56
  1841
	    /* if there are letters on both sides of it or ... */
ali@56
  1842
	    if (gcisalpha(aline[i-1]) && gcisalpha(aline[i+1]) ||
ali@56
  1843
	       gcisalpha(aline[i+1]) && strchr("?!,;:",aline[i]))
ali@56
  1844
	    {
ali@56
  1845
		/* ...if it's strict punctuation followed by an alpha */
ali@56
  1846
		if (aline[i]=='.')
ali@56
  1847
		{
ali@56
  1848
		    if (i>2 && aline[i-2]=='.')
ali@56
  1849
			isacro=1;
ali@56
  1850
		    if (i+2<llen && aline[i+2]=='.')
ali@56
  1851
			isacro=1;
ali@56
  1852
		}
ali@56
  1853
		if (!isacro)
ali@56
  1854
		{
ali@56
  1855
		    if (pswit[ECHO_SWITCH])
ali@56
  1856
			printf("\n%s\n",aline);
ali@56
  1857
		    if (!pswit[OVERVIEW_SWITCH])
ali@56
  1858
			printf("    Line %ld column %d - Missing space?\n",
ali@56
  1859
			  linecnt,i+1);
ali@56
  1860
		    else
ali@56
  1861
			cnt_punct++;
ali@56
  1862
		}
ali@56
  1863
	    }
ali@56
  1864
	    if (aline[i-1]==CHAR_SPACE &&
ali@56
  1865
	      (aline[i+1]==CHAR_SPACE || aline[i+1]==0))
ali@56
  1866
	    {
ali@56
  1867
		/*
ali@56
  1868
		 * If there are spaces on both sides,
ali@56
  1869
		 * or space before and end of line.
ali@56
  1870
		 */
ali@56
  1871
		if (aline[i]=='.')
ali@56
  1872
		{
ali@56
  1873
		    if (i>2 && aline[i-2]=='.')
ali@56
  1874
			isellipsis=1;
ali@56
  1875
		    if (i+2<llen && aline[i+2]=='.')
ali@56
  1876
			isellipsis=1;
ali@56
  1877
		}
ali@56
  1878
		if (!isemptyline && !isellipsis)
ali@56
  1879
		{
ali@56
  1880
		    if (pswit[ECHO_SWITCH])
ali@56
  1881
			printf("\n%s\n",aline);
ali@56
  1882
		    if (!pswit[OVERVIEW_SWITCH])
ali@56
  1883
			printf("    Line %ld column %d - "
ali@56
  1884
			  "Spaced punctuation?\n",linecnt,i+1);
ali@56
  1885
		    else
ali@56
  1886
			cnt_punct++;
ali@56
  1887
		}
ali@56
  1888
	    }
ali@56
  1889
	}
ali@56
  1890
    }
ali@56
  1891
    /* Split out the characters that CANNOT be preceded by space. */
ali@56
  1892
    llen=strlen(aline);
ali@56
  1893
    for (i=1;i<llen;i++)
ali@56
  1894
    {
ali@56
  1895
	/* for each character in the line after the first */
ali@56
  1896
	if (strchr("?!,;:",aline[i]))
ali@56
  1897
	{
ali@56
  1898
	    /* if it's punctuation that _cannot_ have a space before it */
ali@56
  1899
	    if (aline[i-1]==CHAR_SPACE && !isemptyline &&
ali@56
  1900
	      aline[i+1]!=CHAR_SPACE)
ali@56
  1901
	    {
ali@56
  1902
		/*
ali@56
  1903
		 * If aline[i+1) DOES == space,
ali@56
  1904
		 * it was already reported just above.
ali@56
  1905
		 */
ali@56
  1906
		if (pswit[ECHO_SWITCH])
ali@56
  1907
		    printf("\n%s\n",aline);
ali@56
  1908
		if (!pswit[OVERVIEW_SWITCH])
ali@56
  1909
		    printf("    Line %ld column %d - Spaced punctuation?\n",
ali@56
  1910
		      linecnt,i+1);
ali@56
  1911
		else
ali@56
  1912
		    cnt_punct++;
ali@56
  1913
	    }
ali@56
  1914
	}
ali@56
  1915
    }
ali@56
  1916
    /*
ali@56
  1917
     * Special case " .X" where X is any alpha.
ali@56
  1918
     * This plugs a hole in the acronym code above.
ali@56
  1919
     * Inelegant, but maintainable.
ali@56
  1920
     */
ali@56
  1921
    llen=strlen(aline);
ali@56
  1922
    for (i=1;i<llen;i++)
ali@56
  1923
    {
ali@56
  1924
	/* for each character in the line after the first */
ali@56
  1925
	if (aline[i]=='.')
ali@56
  1926
	{
ali@56
  1927
	    /* if it's a period */
ali@56
  1928
	    if (aline[i-1]==CHAR_SPACE && gcisalpha(aline[i+1]))
ali@56
  1929
	    {
ali@56
  1930
		/*
ali@56
  1931
		 * If the period follows a space and
ali@56
  1932
		 * is followed by a letter.
ali@56
  1933
		 */
ali@56
  1934
		if (pswit[ECHO_SWITCH])
ali@56
  1935
		    printf("\n%s\n",aline);
ali@56
  1936
		if (!pswit[OVERVIEW_SWITCH])
ali@56
  1937
		    printf("    Line %ld column %d - Spaced punctuation?\n",
ali@56
  1938
		      linecnt,i+1);
ali@56
  1939
		else
ali@56
  1940
		    cnt_punct++;
ali@56
  1941
	    }
ali@56
  1942
	}
ali@56
  1943
    }
ali@56
  1944
    for (i=1;i<llen;i++)
ali@56
  1945
    {
ali@56
  1946
	/* for each character in the line after the first */
ali@56
  1947
	if (aline[i]==CHAR_DQUOTE)
ali@56
  1948
	{
ali@56
  1949
	    if (!strchr(" _-.'`,;:!/([{?}])",aline[i-1]) &&
ali@56
  1950
	      !strchr(" _-.'`,;:!/([{?}])",aline[i+1]) && aline[i+1] ||
ali@56
  1951
	      !strchr(" _-([{'`",aline[i-1]) && gcisalpha(aline[i+1]))
ali@56
  1952
	    {
ali@56
  1953
		if (pswit[ECHO_SWITCH])
ali@56
  1954
		    printf("\n%s\n",aline);
ali@56
  1955
		if (!pswit[OVERVIEW_SWITCH])
ali@56
  1956
		    printf("    Line %ld column %d - Unspaced quotes?\n",
ali@56
  1957
		      linecnt,i+1);
ali@56
  1958
		else
ali@56
  1959
		    cnt_punct++;
ali@56
  1960
	    }
ali@56
  1961
	}
ali@56
  1962
    }
ali@56
  1963
    /* Check parity of quotes. */
ali@56
  1964
    for (s=aline;*s;s++)
ali@56
  1965
    {
ali@56
  1966
	if (*s==CHAR_DQUOTE)
ali@56
  1967
	{
ali@56
  1968
	    parities->dquote=!parities->dquote;
ali@56
  1969
	    if (!parities->dquote)
ali@56
  1970
	    {
ali@56
  1971
		/* parity even */
ali@56
  1972
		if (!strchr("_-.'`/,;:!?)]} ",s[1]))
ali@56
  1973
		{
ali@56
  1974
		    if (pswit[ECHO_SWITCH])
ali@56
  1975
			printf("\n%s\n",aline);
ali@56
  1976
		    if (!pswit[OVERVIEW_SWITCH])
ali@56
  1977
			printf("    Line %ld column %d - "
ali@56
  1978
			  "Wrongspaced quotes?\n",linecnt,(int)(s-aline)+1);
ali@56
  1979
		    else
ali@56
  1980
			cnt_punct++;
ali@56
  1981
		}
ali@56
  1982
	    }
ali@56
  1983
	    else
ali@56
  1984
	    {
ali@56
  1985
		/* parity odd */
ali@56
  1986
		if (!gcisalpha(s[1]) && !isdigit(s[1]) &&
ali@56
  1987
		  !strchr("_-/.'`([{$",s[1]) || !s[1])
ali@56
  1988
		{
ali@56
  1989
		    if (pswit[ECHO_SWITCH])
ali@56
  1990
			printf("\n%s\n",aline);
ali@56
  1991
		    if (!pswit[OVERVIEW_SWITCH])
ali@56
  1992
			printf("    Line %ld column %d - "
ali@56
  1993
			  "Wrongspaced quotes?\n",linecnt,(int)(s-aline)+1);
ali@56
  1994
		    else
ali@56
  1995
			cnt_punct++;
ali@56
  1996
		}
ali@56
  1997
	    }
ali@56
  1998
	}
ali@56
  1999
    }
ali@56
  2000
    if (*aline==CHAR_DQUOTE)
ali@56
  2001
    {
ali@56
  2002
	if (strchr(",;:!?)]} ",aline[1]))
ali@56
  2003
	{
ali@56
  2004
	    if (pswit[ECHO_SWITCH])
ali@56
  2005
		printf("\n%s\n",aline);
ali@56
  2006
	    if (!pswit[OVERVIEW_SWITCH])
ali@56
  2007
		printf("    Line %ld column 1 - Wrongspaced quotes?\n",
ali@56
  2008
		  linecnt);
ali@56
  2009
	    else
ali@56
  2010
		cnt_punct++;
ali@56
  2011
	}
ali@56
  2012
    }
ali@56
  2013
    if (pswit[SQUOTE_SWITCH])
ali@56
  2014
    {
ali@56
  2015
	for (s=aline;*s;s++)
ali@56
  2016
	{
ali@56
  2017
	    if ((*s==CHAR_SQUOTE || *s==CHAR_OPEN_SQUOTE) &&
ali@56
  2018
	      (s==aline || s>aline && !gcisalpha(s[-1]) ||
ali@56
  2019
	      !gcisalpha(s[1])))
ali@56
  2020
	    {
ali@56
  2021
		parities->squote=!parities->squote;
ali@56
  2022
		if (!parities->squote)
ali@56
  2023
		{
ali@56
  2024
		    /* parity even */
ali@56
  2025
		    if (!strchr("_-.'`/\",;:!?)]} ",s[1]))
ali@56
  2026
		    {
ali@56
  2027
			if (pswit[ECHO_SWITCH])
ali@56
  2028
			    printf("\n%s\n",aline);
ali@56
  2029
			if (!pswit[OVERVIEW_SWITCH])
ali@56
  2030
			    printf("    Line %ld column %d - "
ali@56
  2031
			      "Wrongspaced singlequotes?\n",
ali@56
  2032
			      linecnt,(int)(s-aline)+1);
ali@56
  2033
			else
ali@56
  2034
			    cnt_punct++;
ali@56
  2035
		    }
ali@56
  2036
		}
ali@56
  2037
		else
ali@56
  2038
		{
ali@56
  2039
		    /* parity odd */
ali@56
  2040
		    if (!gcisalpha(s[1]) && !isdigit(s[1]) &&
ali@56
  2041
		      !strchr("_-/\".'`",s[1]) || !s[1])
ali@56
  2042
		    {
ali@56
  2043
			if (pswit[ECHO_SWITCH])
ali@56
  2044
			    printf("\n%s\n",aline);
ali@56
  2045
			if (!pswit[OVERVIEW_SWITCH])
ali@56
  2046
			    printf("    Line %ld column %d - "
ali@56
  2047
			      "Wrongspaced singlequotes?\n",
ali@56
  2048
			      linecnt,(int)(s-aline)+1);
ali@56
  2049
			else
ali@56
  2050
			    cnt_punct++;
ali@56
  2051
		    }
ali@56
  2052
		}
ali@56
  2053
	    }
ali@56
  2054
	}
ali@56
  2055
    }
ali@56
  2056
}
ali@56
  2057
ali@55
  2058
/*
ali@57
  2059
 * check_for_double_punctuation:
ali@57
  2060
 *
ali@57
  2061
 * Look for double punctuation like ,. or ,,
ali@57
  2062
 * Thanks to DW for the suggestion!
ali@57
  2063
 * In books with references, ".," and ".;" are common
ali@57
  2064
 * e.g. "etc., etc.," and vol. 1.; vol 3.;
ali@57
  2065
 * OTOH, from my initial tests, there are also fairly
ali@57
  2066
 * common errors. What to do? Make these cases paranoid?
ali@57
  2067
 * ".," is the most common, so warnings->dotcomma is used
ali@57
  2068
 * to suppress detailed reporting if it occurs often.
ali@57
  2069
 */
ali@57
  2070
void check_for_double_punctuation(const char *aline,struct warnings *warnings)
ali@57
  2071
{
ali@57
  2072
    int i,llen;
ali@57
  2073
    llen=strlen(aline);
ali@57
  2074
    for (i=0;i<llen;i++)
ali@57
  2075
    {
ali@57
  2076
	/* for each punctuation character in the line */
ali@57
  2077
	if (strchr(".?!,;:",aline[i]) && strchr(".?!,;:",aline[i+1]) &&
ali@57
  2078
	  aline[i] && aline[i+1])
ali@57
  2079
	{
ali@57
  2080
	    /* followed by punctuation, it's a query, unless . . . */
ali@57
  2081
	    if (aline[i]==aline[i+1] && (aline[i]=='.' || aline[i]=='?' ||
ali@57
  2082
	      aline[i]=='!') ||
ali@57
  2083
	      !warnings->dotcomma && aline[i]=='.' && aline[i+1]==',' ||
ali@57
  2084
	      warnings->isFrench && !strncmp(aline+i,",...",4) ||
ali@57
  2085
	      warnings->isFrench && !strncmp(aline+i,"...,",4) ||
ali@57
  2086
	      warnings->isFrench && !strncmp(aline+i,";...",4) ||
ali@57
  2087
	      warnings->isFrench && !strncmp(aline+i,"...;",4) ||
ali@57
  2088
	      warnings->isFrench && !strncmp(aline+i,":...",4) ||
ali@57
  2089
	      warnings->isFrench && !strncmp(aline+i,"...:",4) ||
ali@57
  2090
	      warnings->isFrench && !strncmp(aline+i,"!...",4) ||
ali@57
  2091
	      warnings->isFrench && !strncmp(aline+i,"...!",4) ||
ali@57
  2092
	      warnings->isFrench && !strncmp(aline+i,"?...",4) ||
ali@57
  2093
	      warnings->isFrench && !strncmp(aline+i,"...?",4))
ali@57
  2094
	    {
ali@57
  2095
		if (warnings->isFrench && !strncmp(aline+i,",...",4) ||
ali@57
  2096
		  warnings->isFrench && !strncmp(aline+i,"...,",4) ||
ali@57
  2097
		  warnings->isFrench && !strncmp(aline+i,";...",4) ||
ali@57
  2098
		  warnings->isFrench && !strncmp(aline+i,"...;",4) ||
ali@57
  2099
		  warnings->isFrench && !strncmp(aline+i,":...",4) ||
ali@57
  2100
		  warnings->isFrench && !strncmp(aline+i,"...:",4) ||
ali@57
  2101
		  warnings->isFrench && !strncmp(aline+i,"!...",4) ||
ali@57
  2102
		  warnings->isFrench && !strncmp(aline+i,"...!",4) ||
ali@57
  2103
		  warnings->isFrench && !strncmp(aline+i,"?...",4) ||
ali@57
  2104
		  warnings->isFrench && !strncmp(aline+i,"...?",4))
ali@57
  2105
		    i+=4;
ali@57
  2106
		; /* do nothing for .. !! and ?? which can be legit */
ali@57
  2107
	    }
ali@57
  2108
	    else
ali@57
  2109
	    {
ali@57
  2110
		if (pswit[ECHO_SWITCH])
ali@57
  2111
		    printf("\n%s\n",aline);
ali@57
  2112
		if (!pswit[OVERVIEW_SWITCH])
ali@57
  2113
		    printf("    Line %ld column %d - Double punctuation?\n",
ali@57
  2114
		      linecnt,i+1);
ali@57
  2115
		else
ali@57
  2116
		    cnt_punct++;
ali@57
  2117
	    }
ali@57
  2118
	}
ali@57
  2119
    }
ali@57
  2120
}
ali@57
  2121
ali@57
  2122
/*
ali@58
  2123
 * check_for_spaced_quotes:
ali@58
  2124
 */
ali@58
  2125
void check_for_spaced_quotes(const char *aline)
ali@58
  2126
{
ali@58
  2127
    const char *s,*t;
ali@58
  2128
    s=aline;
ali@58
  2129
    while ((t=strstr(s," \" ")))
ali@58
  2130
    {
ali@58
  2131
	if (pswit[ECHO_SWITCH])
ali@58
  2132
	    printf("\n%s\n",aline);
ali@58
  2133
	if (!pswit[OVERVIEW_SWITCH])
ali@58
  2134
	    printf("    Line %ld column %d - Spaced doublequote?\n",
ali@58
  2135
	      linecnt,(int)(t-aline+1));
ali@58
  2136
	else
ali@58
  2137
	    cnt_punct++;
ali@58
  2138
	s=t+2;
ali@58
  2139
    }
ali@58
  2140
    s=aline;
ali@58
  2141
    while ((t=strstr(s," ' ")))
ali@58
  2142
    {
ali@58
  2143
	if (pswit[ECHO_SWITCH])
ali@58
  2144
	    printf("\n%s\n",aline);
ali@58
  2145
	if (!pswit[OVERVIEW_SWITCH])
ali@58
  2146
	    printf("    Line %ld column %d - Spaced singlequote?\n",
ali@58
  2147
	      linecnt,(int)(t-aline+1));
ali@58
  2148
	else
ali@58
  2149
	    cnt_punct++;
ali@58
  2150
	s=t+2;
ali@58
  2151
    }
ali@58
  2152
    s=aline;
ali@58
  2153
    while ((t=strstr(s," ` ")))
ali@58
  2154
    {
ali@58
  2155
	if (pswit[ECHO_SWITCH])
ali@58
  2156
	    printf("\n%s\n",aline);
ali@58
  2157
	if (!pswit[OVERVIEW_SWITCH])
ali@58
  2158
	    printf("    Line %ld column %d - Spaced singlequote?\n",
ali@58
  2159
	      linecnt,(int)(t-aline+1));
ali@58
  2160
	else
ali@58
  2161
	    cnt_punct++;
ali@58
  2162
	s=t+2;
ali@58
  2163
    }
ali@58
  2164
}
ali@58
  2165
ali@58
  2166
/*
ali@59
  2167
 * check_for_miscased_genative:
ali@59
  2168
 *
ali@59
  2169
 * Check special case of 'S instead of 's at end of word.
ali@59
  2170
 */
ali@59
  2171
void check_for_miscased_genative(const char *aline)
ali@59
  2172
{
ali@59
  2173
    const char *s;
ali@59
  2174
    s=aline+1;
ali@59
  2175
    while (*s)
ali@59
  2176
    {
ali@59
  2177
	if (*s==CHAR_SQUOTE && s[1]=='S' && s[-1]>='a' && s[-1]<='z')
ali@59
  2178
	{
ali@59
  2179
	    if (pswit[ECHO_SWITCH])
ali@59
  2180
		printf("\n%s\n",aline);
ali@59
  2181
	    if (!pswit[OVERVIEW_SWITCH])
ali@59
  2182
		printf("    Line %ld column %d - Capital \"S\"?\n",
ali@59
  2183
		  linecnt,(int)(s-aline+2));
ali@59
  2184
	    else
ali@59
  2185
		cnt_punct++;
ali@59
  2186
	}
ali@59
  2187
	s++;
ali@59
  2188
    }
ali@59
  2189
}
ali@59
  2190
ali@59
  2191
/*
ali@60
  2192
 * check_end_of_line:
ali@60
  2193
 *
ali@60
  2194
 * Now check special cases - start and end of line -
ali@60
  2195
 * for single and double quotes. Start is sometimes [sic]
ali@60
  2196
 * but better to query it anyway.
ali@60
  2197
 * While we're here, check for dash at end of line.
ali@60
  2198
 */
ali@60
  2199
void check_end_of_line(const char *aline,struct warnings *warnings)
ali@60
  2200
{
ali@60
  2201
    int i,llen;
ali@60
  2202
    llen=strlen(aline);
ali@60
  2203
    if (llen>1)
ali@60
  2204
    {
ali@60
  2205
	if (aline[llen-1]==CHAR_DQUOTE || aline[llen-1]==CHAR_SQUOTE ||
ali@60
  2206
	  aline[llen-1]==CHAR_OPEN_SQUOTE)
ali@60
  2207
	    if (aline[llen-2]==CHAR_SPACE)
ali@60
  2208
	    {
ali@60
  2209
		if (pswit[ECHO_SWITCH])
ali@60
  2210
		    printf("\n%s\n",aline);
ali@60
  2211
		if (!pswit[OVERVIEW_SWITCH])
ali@60
  2212
		    printf("    Line %ld column %d - Spaced quote?\n",
ali@60
  2213
		      linecnt,llen);
ali@60
  2214
		else
ali@60
  2215
		    cnt_punct++;
ali@60
  2216
	    }
ali@60
  2217
	if ((aline[0]==CHAR_SQUOTE || aline[0]==CHAR_OPEN_SQUOTE) &&
ali@60
  2218
	  aline[1]==CHAR_SPACE)
ali@60
  2219
	{
ali@60
  2220
	    if (pswit[ECHO_SWITCH])
ali@60
  2221
		printf("\n%s\n",aline);
ali@60
  2222
	    if (!pswit[OVERVIEW_SWITCH])
ali@60
  2223
		printf("    Line %ld column 1 - Spaced quote?\n",linecnt);
ali@60
  2224
	    else
ali@60
  2225
		cnt_punct++;
ali@60
  2226
	}
ali@60
  2227
	/*
ali@60
  2228
	 * Dash at end of line may well be legit - paranoid mode only
ali@60
  2229
	 * and don't report em-dash at line-end.
ali@60
  2230
	 */
ali@60
  2231
	if (pswit[PARANOID_SWITCH] && warnings->hyphen)
ali@60
  2232
	{
ali@60
  2233
	    for (i=llen-1;i>0 && (unsigned char)aline[i]<=CHAR_SPACE;i--)
ali@60
  2234
		;
ali@60
  2235
	    if (aline[i]=='-' && aline[i-1]!='-')
ali@60
  2236
	    {
ali@60
  2237
		if (pswit[ECHO_SWITCH])
ali@60
  2238
		    printf("\n%s\n",aline);
ali@60
  2239
		if (!pswit[OVERVIEW_SWITCH])
ali@60
  2240
		    printf("    Line %ld column %d - Hyphen at end of line?\n",
ali@60
  2241
		      linecnt,i);
ali@60
  2242
	    }
ali@60
  2243
	}
ali@60
  2244
    }
ali@60
  2245
}
ali@60
  2246
ali@60
  2247
/*
ali@61
  2248
 * check_for_unspaced_bracket:
ali@61
  2249
 *
ali@61
  2250
 * Brackets are often unspaced, but shouldn't be surrounded by alpha.
ali@61
  2251
 * If so, suspect a scanno like "a]most".
ali@61
  2252
 */
ali@61
  2253
void check_for_unspaced_bracket(const char *aline)
ali@61
  2254
{
ali@61
  2255
    int i,llen;
ali@61
  2256
    llen=strlen(aline);
ali@61
  2257
    for (i=1;i<llen-1;i++)
ali@61
  2258
    {
ali@61
  2259
	/* for each bracket character in the line except 1st & last */
ali@61
  2260
	if (strchr("{[()]}",aline[i]) && gcisalpha(aline[i-1]) &&
ali@61
  2261
	  gcisalpha(aline[i+1]))
ali@61
  2262
	{
ali@61
  2263
	    if (pswit[ECHO_SWITCH])
ali@61
  2264
		printf("\n%s\n",aline);
ali@61
  2265
	    if (!pswit[OVERVIEW_SWITCH])
ali@61
  2266
		printf("    Line %ld column %d - Unspaced bracket?\n",
ali@61
  2267
		  linecnt,i);
ali@61
  2268
	    else
ali@61
  2269
		cnt_punct++;
ali@61
  2270
	}
ali@61
  2271
    }
ali@61
  2272
}
ali@61
  2273
ali@61
  2274
/*
ali@62
  2275
 * check_for_unpunctuated_endquote:
ali@62
  2276
 */
ali@62
  2277
void check_for_unpunctuated_endquote(const char *aline)
ali@62
  2278
{
ali@62
  2279
    int i,llen;
ali@62
  2280
    llen=strlen(aline);
ali@62
  2281
    for (i=1;i<llen;i++)
ali@62
  2282
    {
ali@62
  2283
	/* for each character in the line except 1st */
ali@62
  2284
	if (aline[i]==CHAR_DQUOTE && isalpha(aline[i-1]))
ali@62
  2285
	{
ali@62
  2286
	    if (pswit[ECHO_SWITCH])
ali@62
  2287
		printf("\n%s\n",aline);
ali@62
  2288
	    if (!pswit[OVERVIEW_SWITCH])
ali@62
  2289
		printf("    Line %ld column %d - "
ali@62
  2290
		  "endquote missing punctuation?\n",linecnt,i);
ali@62
  2291
	    else
ali@62
  2292
		cnt_punct++;
ali@62
  2293
	}
ali@62
  2294
    }
ali@62
  2295
}
ali@62
  2296
ali@62
  2297
/*
ali@63
  2298
 * check_for_html_tag:
ali@63
  2299
 *
ali@63
  2300
 * Check for <HTML TAG>.
ali@63
  2301
 *
ali@63
  2302
 * If there is a < in the line, followed at some point
ali@63
  2303
 * by a > then we suspect HTML.
ali@63
  2304
 */
ali@63
  2305
void check_for_html_tag(const char *aline)
ali@63
  2306
{
ali@63
  2307
    int i;
ali@63
  2308
    const char *open,*close;
ali@63
  2309
    open=strstr(aline,"<");
ali@63
  2310
    if (open)
ali@63
  2311
    {
ali@63
  2312
	close=strstr(aline,">");
ali@63
  2313
	if (close)
ali@63
  2314
	{
ali@63
  2315
	    i=(signed int)(close-open+1);
ali@63
  2316
	    if (i>0)
ali@63
  2317
	    {
ali@63
  2318
		strncpy(wrk,open,i);
ali@63
  2319
		wrk[i]=0;
ali@63
  2320
		if (pswit[ECHO_SWITCH])
ali@63
  2321
		    printf("\n%s\n",aline);
ali@63
  2322
		if (!pswit[OVERVIEW_SWITCH])
ali@63
  2323
		    printf("    Line %ld column %d - HTML Tag? %s \n",
ali@63
  2324
		      linecnt,(int)(open-aline)+1,wrk);
ali@63
  2325
		else
ali@63
  2326
		    cnt_html++;
ali@63
  2327
	    }
ali@63
  2328
	}
ali@63
  2329
    }
ali@63
  2330
}
ali@63
  2331
ali@63
  2332
/*
ali@64
  2333
 * check_for_html_entity:
ali@64
  2334
 *
ali@64
  2335
 * Check for &symbol; HTML.
ali@64
  2336
 *
ali@64
  2337
 * If there is a & in the line, followed at
ali@64
  2338
 * some point by a ; then we suspect HTML.
ali@64
  2339
 */
ali@64
  2340
void check_for_html_entity(const char *aline)
ali@64
  2341
{
ali@64
  2342
    int i;
ali@64
  2343
    const char *s,*amp,*scolon;
ali@64
  2344
    amp=strstr(aline,"&");
ali@64
  2345
    if (amp)
ali@64
  2346
    {
ali@64
  2347
	scolon=strstr(aline,";");
ali@64
  2348
	if (scolon)
ali@64
  2349
	{
ali@64
  2350
	    i=(int)(scolon-amp+1);
ali@64
  2351
	    for (s=amp;s<scolon;s++)   
ali@64
  2352
		if (*s==CHAR_SPACE)
ali@64
  2353
		    i=0;                /* Don't report "Jones & Son;" */
ali@64
  2354
	    if (i>0)
ali@64
  2355
	    {
ali@64
  2356
		strncpy(wrk,amp,i);
ali@64
  2357
		wrk[i]=0;
ali@64
  2358
		if (pswit[ECHO_SWITCH])
ali@64
  2359
		    printf("\n%s\n",aline);
ali@64
  2360
		if (!pswit[OVERVIEW_SWITCH])
ali@64
  2361
		    printf("    Line %ld column %d - HTML symbol? %s \n",
ali@64
  2362
		      linecnt,(int)(amp-aline)+1,wrk);
ali@64
  2363
		else
ali@64
  2364
		    cnt_html++;
ali@64
  2365
	    }
ali@64
  2366
	}
ali@64
  2367
    }
ali@64
  2368
}
ali@64
  2369
ali@65
  2370
struct pending {
ali@65
  2371
    char dquote[80],squote[80],rbrack[80],sbrack[80],cbrack[80],unders[80];
ali@65
  2372
    long squot;
ali@65
  2373
};
ali@65
  2374
ali@65
  2375
/*
ali@65
  2376
 * print_pending:
ali@65
  2377
 *
ali@65
  2378
 * If we are in a state of unbalanced quotes, and this line
ali@65
  2379
 * doesn't begin with a quote, output the stored error message.
ali@65
  2380
 * If the -P switch was used, print the warning even if the
ali@65
  2381
 * new para starts with quotes.
ali@65
  2382
 */
ali@65
  2383
void print_pending(const char *aline,const char *parastart,
ali@65
  2384
  struct pending *pending)
ali@65
  2385
{
ali@65
  2386
    const char *s;
ali@65
  2387
    s=aline;
ali@65
  2388
    while (*s==' ')
ali@65
  2389
	s++;
ali@65
  2390
    if (*pending->dquote)
ali@65
  2391
	if (*s!=CHAR_DQUOTE || pswit[QPARA_SWITCH])
ali@65
  2392
	{
ali@65
  2393
	    if (!pswit[OVERVIEW_SWITCH])
ali@65
  2394
	    {
ali@65
  2395
		if (pswit[ECHO_SWITCH])
ali@65
  2396
		    printf("\n%s\n",parastart);
ali@65
  2397
		puts(pending->dquote);
ali@65
  2398
	    }
ali@65
  2399
	    else
ali@65
  2400
		cnt_dquot++;
ali@65
  2401
	}
ali@65
  2402
    if (*pending->squote)
ali@65
  2403
    {
ali@65
  2404
	if (*s!=CHAR_SQUOTE && *s!=CHAR_OPEN_SQUOTE || pswit[QPARA_SWITCH] ||
ali@65
  2405
	  pending->squot)
ali@65
  2406
	{
ali@65
  2407
	    if (!pswit[OVERVIEW_SWITCH])
ali@65
  2408
	    {
ali@65
  2409
		if (pswit[ECHO_SWITCH])
ali@65
  2410
		    printf("\n%s\n",parastart);
ali@65
  2411
		puts(pending->squote);
ali@65
  2412
	    }
ali@65
  2413
	    else
ali@65
  2414
		cnt_squot++;
ali@65
  2415
	}
ali@65
  2416
    }
ali@65
  2417
    if (*pending->rbrack)
ali@65
  2418
    {
ali@65
  2419
	if (!pswit[OVERVIEW_SWITCH])
ali@65
  2420
	{
ali@65
  2421
	    if (pswit[ECHO_SWITCH])
ali@65
  2422
		printf("\n%s\n",parastart);
ali@65
  2423
	    puts(pending->rbrack);
ali@65
  2424
	}
ali@65
  2425
	else
ali@65
  2426
	    cnt_brack++;
ali@65
  2427
    }
ali@65
  2428
    if (*pending->sbrack)
ali@65
  2429
    {
ali@65
  2430
	if (!pswit[OVERVIEW_SWITCH])
ali@65
  2431
	{
ali@65
  2432
	    if (pswit[ECHO_SWITCH])
ali@65
  2433
		printf("\n%s\n",parastart);
ali@65
  2434
	    puts(pending->sbrack);
ali@65
  2435
	}
ali@65
  2436
	else
ali@65
  2437
	    cnt_brack++;
ali@65
  2438
    }
ali@65
  2439
    if (*pending->cbrack)
ali@65
  2440
    {
ali@65
  2441
	if (!pswit[OVERVIEW_SWITCH])
ali@65
  2442
	{
ali@65
  2443
	    if (pswit[ECHO_SWITCH])
ali@65
  2444
		printf("\n%s\n",parastart);
ali@65
  2445
	    puts(pending->cbrack);
ali@65
  2446
	}
ali@65
  2447
	else
ali@65
  2448
	    cnt_brack++;
ali@65
  2449
    }
ali@65
  2450
    if (*pending->unders)
ali@65
  2451
    {
ali@65
  2452
	if (!pswit[OVERVIEW_SWITCH])
ali@65
  2453
	{
ali@65
  2454
	    if (pswit[ECHO_SWITCH])
ali@65
  2455
		printf("\n%s\n",parastart);
ali@65
  2456
	    puts(pending->unders);
ali@65
  2457
	}
ali@65
  2458
	else
ali@65
  2459
	    cnt_brack++;
ali@65
  2460
    }
ali@65
  2461
}
ali@65
  2462
ali@65
  2463
/*
ali@65
  2464
 * check_for_mismatched_quotes:
ali@65
  2465
 *
ali@65
  2466
 * At end of paragraph, check for mismatched quotes.
ali@65
  2467
 *
ali@65
  2468
 * We don't want to report an error immediately, since it is a
ali@65
  2469
 * common convention to omit the quotes at end of paragraph if
ali@65
  2470
 * the next paragraph is a continuation of the same speaker.
ali@65
  2471
 * Where this is the case, the next para should begin with a
ali@65
  2472
 * quote, so we store the warning message and only display it
ali@65
  2473
 * at the top of the next iteration if the new para doesn't
ali@65
  2474
 * start with a quote.
ali@65
  2475
 * The -p switch overrides this default, and warns of unclosed
ali@65
  2476
 * quotes on _every_ paragraph, whether the next begins with a
ali@65
  2477
 * quote or not.
ali@65
  2478
 */
ali@65
  2479
void check_for_mismatched_quotes(const struct counters *counters,
ali@65
  2480
  struct pending *pending)
ali@65
  2481
{
ali@65
  2482
    if (counters->quot%2)
ali@65
  2483
	sprintf(pending->dquote,"    Line %ld - Mismatched quotes",
ali@65
  2484
	  linecnt);
ali@65
  2485
    if (pswit[SQUOTE_SWITCH] && counters->open_single_quote &&
ali@65
  2486
      counters->open_single_quote!=counters->close_single_quote)
ali@65
  2487
	sprintf(pending->squote,"    Line %ld - Mismatched singlequotes?",
ali@65
  2488
	  linecnt);
ali@65
  2489
    if (pswit[SQUOTE_SWITCH] && counters->open_single_quote &&
ali@65
  2490
      counters->open_single_quote!=counters->close_single_quote &&
ali@65
  2491
      counters->open_single_quote!=counters->close_single_quote+1)
ali@65
  2492
	/*
ali@65
  2493
	 * Flag it to be noted regardless of the
ali@65
  2494
	 * first char of the next para.
ali@65
  2495
	 */
ali@65
  2496
	pending->squot=1;
ali@65
  2497
    if (counters->r_brack)
ali@65
  2498
	sprintf(pending->rbrack,"    Line %ld - Mismatched round brackets?",
ali@65
  2499
	  linecnt);
ali@65
  2500
    if (counters->s_brack)
ali@65
  2501
	sprintf(pending->sbrack,"    Line %ld - Mismatched square brackets?",
ali@65
  2502
	  linecnt);
ali@65
  2503
    if (counters->c_brack)
ali@65
  2504
	sprintf(pending->cbrack,"    Line %ld - Mismatched curly brackets?",
ali@65
  2505
	  linecnt);
ali@65
  2506
    if (counters->c_unders%2)
ali@65
  2507
	sprintf(pending->unders,"    Line %ld - Mismatched underscores?",
ali@65
  2508
	  linecnt);
ali@65
  2509
}
ali@65
  2510
ali@64
  2511
/*
ali@66
  2512
 * check_for_omitted_punctuation:
ali@66
  2513
 *
ali@66
  2514
 * Check for omitted punctuation at end of paragraph by working back
ali@66
  2515
 * through prevline. DW.
ali@66
  2516
 * Need to check this only for "normal" paras.
ali@66
  2517
 * So what is a "normal" para?
ali@66
  2518
 *    Not normal if one-liner (chapter headings, etc.)
ali@66
  2519
 *    Not normal if doesn't contain at least one locase letter
ali@66
  2520
 *    Not normal if starts with space
ali@66
  2521
 */
ali@66
  2522
void check_for_omitted_punctuation(const char *prevline,
ali@66
  2523
  struct line_properties *last,int start_para_line)
ali@66
  2524
{
ali@66
  2525
    int i;
ali@66
  2526
    const char *s;
ali@66
  2527
    for (s=prevline,i=0;*s && !i;s++)
ali@66
  2528
	if (gcisletter(*s))
ali@66
  2529
	    /* use i to indicate the presence of a letter on the line */
ali@66
  2530
	    i=1;
ali@66
  2531
    /*
ali@66
  2532
     * This next "if" is a problem.
ali@66
  2533
     * If we say "start_para_line <= linecnt - 1", that includes
ali@66
  2534
     * one-line "paragraphs" like chapter heads. Lotsa false positives.
ali@66
  2535
     * If we say "start_para_line < linecnt - 1" it doesn't, but then it
ali@66
  2536
     * misses genuine one-line paragraphs.
ali@66
  2537
     */
ali@66
  2538
    if (i && last->blen>2 && start_para_line<linecnt-1 && *prevline>CHAR_SPACE)
ali@66
  2539
    {
ali@66
  2540
	for (i=strlen(prevline)-1;
ali@66
  2541
	  (prevline[i]==CHAR_DQUOTE || prevline[i]==CHAR_SQUOTE) &&
ali@66
  2542
	  prevline[i]>CHAR_SPACE && i>0;
ali@66
  2543
	  i--)
ali@66
  2544
	    ;
ali@66
  2545
	for (;i>0;i--)
ali@66
  2546
	{
ali@66
  2547
	    if (gcisalpha(prevline[i]))
ali@66
  2548
	    {
ali@66
  2549
		if (pswit[ECHO_SWITCH])
ali@66
  2550
		    printf("\n%s\n",prevline);
ali@66
  2551
		if (!pswit[OVERVIEW_SWITCH])
ali@66
  2552
		    printf("    Line %ld column %d - "
ali@66
  2553
		      "No punctuation at para end?\n",
ali@66
  2554
		      linecnt-1,strlen(prevline));
ali@66
  2555
		else
ali@66
  2556
		    cnt_punct++;
ali@66
  2557
		break;
ali@66
  2558
	    }
ali@66
  2559
	    if (strchr("-.:!([{?}])",prevline[i]))
ali@66
  2560
		break;
ali@66
  2561
	}
ali@66
  2562
    }
ali@66
  2563
}
ali@66
  2564
ali@66
  2565
/*
ali@41
  2566
 * procfile:
ali@41
  2567
 *
ali@41
  2568
 * Process one file.
ali@41
  2569
 */
ali@41
  2570
void procfile(char *filename)
ali@41
  2571
{
ali@65
  2572
    const char *s;
ali@41
  2573
    char parastart[81];     /* first line of current para */
ali@41
  2574
    FILE *infile;
ali@41
  2575
    struct first_pass_results *first_pass_results;
ali@42
  2576
    struct warnings *warnings;
ali@43
  2577
    struct counters counters={0};
ali@45
  2578
    struct line_properties last={0};
ali@56
  2579
    struct parities parities={0};
ali@65
  2580
    struct pending pending={{0},};
ali@43
  2581
    int isemptyline;
ali@65
  2582
    long start_para_line;
ali@55
  2583
    signed int i,llen,isacro,isellipsis;
ali@55
  2584
    signed int isnewpara;
ali@41
  2585
    signed int enddash;
ali@45
  2586
    last.start=CHAR_SPACE;
ali@65
  2587
    *prevline=0;
ali@41
  2588
    linecnt=checked_linecnt=start_para_line=0;
ali@53
  2589
    i=llen=isacro=isellipsis=0;
ali@55
  2590
    isnewpara=enddash=0;
ali@41
  2591
    infile=fopen(filename,"rb");
ali@41
  2592
    if (!infile)
ali@41
  2593
    {
ali@41
  2594
        if (pswit[STDOUT_SWITCH])
ali@41
  2595
            fprintf(stdout,"bookloupe: cannot open %s\n",filename);
ali@41
  2596
        else
ali@41
  2597
            fprintf(stderr,"bookloupe: cannot open %s\n",filename);
ali@41
  2598
	exit(1);
ali@41
  2599
    }
ali@41
  2600
    fprintf(stdout,"\n\nFile: %s\n\n",filename);
ali@41
  2601
    first_pass_results=first_pass(infile);
ali@42
  2602
    warnings=report_first_pass(first_pass_results);
ali@40
  2603
    /*
ali@40
  2604
     * Here we go with the main pass. Hold onto yer hat!
ali@40
  2605
     */
ali@65
  2606
    rewind(infile);
ali@65
  2607
    linecnt=0;
ali@40
  2608
    while (flgets(aline,LINEBUFSIZE-1,infile,linecnt+1))
ali@40
  2609
    {
ali@0
  2610
        linecnt++;
ali@40
  2611
        if (linecnt==1)
ali@40
  2612
	    isnewpara=1;
ali@40
  2613
        if (pswit[DP_SWITCH] && !strncmp(aline,"-----File: ",11))
ali@40
  2614
	    continue;    // skip DP page separators completely
ali@41
  2615
        if (linecnt<first_pass_results->firstline ||
ali@41
  2616
	  (first_pass_results->footerline>0 &&
ali@41
  2617
	  linecnt>first_pass_results->footerline))
ali@40
  2618
	{
ali@40
  2619
            if (pswit[HEADER_SWITCH])
ali@40
  2620
	    {
ali@40
  2621
                if (!strncmp(aline,"Title:",6))
ali@40
  2622
                    printf("    %s\n",aline);
ali@40
  2623
                if (!strncmp(aline,"Author:",7))
ali@40
  2624
                    printf("    %s\n",aline);
ali@40
  2625
                if (!strncmp(aline,"Release Date:",13))
ali@40
  2626
                    printf("    %s\n",aline);
ali@40
  2627
                if (!strncmp(aline,"Edition:",8))
ali@40
  2628
                    printf("    %s\n\n",aline);
ali@40
  2629
	    }
ali@0
  2630
            continue;                /* skip through the header */
ali@40
  2631
	}
ali@0
  2632
        checked_linecnt++;
ali@65
  2633
	print_pending(aline,parastart,&pending);
ali@65
  2634
	memset(&pending,0,sizeof(pending));
ali@43
  2635
	isemptyline=analyse_quotes(aline,&counters);
ali@40
  2636
        if (isnewpara && !isemptyline)
ali@40
  2637
	{
ali@40
  2638
	    /* This line is the start of a new paragraph. */
ali@40
  2639
            start_para_line=linecnt;
ali@40
  2640
	    /* Capture its first line in case we want to report it later. */
ali@40
  2641
            strncpy(parastart,aline,80);
ali@40
  2642
            parastart[79]=0;
ali@56
  2643
	    memset(&parities,0,sizeof(parities));  /* restart the quote count */
ali@40
  2644
            s=aline;
ali@40
  2645
            while (!gcisalpha(*s) && !gcisdigit(*s) && *s)
ali@40
  2646
		s++;
ali@40
  2647
            if (*s>='a' && *s<='z')
ali@40
  2648
	    {
ali@40
  2649
		/* and its first letter is lowercase */
ali@40
  2650
                if (pswit[ECHO_SWITCH])
ali@40
  2651
		    printf("\n%s\n",aline);
ali@0
  2652
                if (!pswit[OVERVIEW_SWITCH])
ali@40
  2653
                    printf("    Line %ld column %d - "
ali@40
  2654
		      "Paragraph starts with lower-case\n",
ali@40
  2655
		      linecnt,(int)(s-aline)+1);
ali@0
  2656
                else
ali@0
  2657
                    cnt_punct++;
ali@40
  2658
	    }
ali@40
  2659
            isnewpara=0; /* Signal the end of new para processing. */
ali@40
  2660
	}
ali@40
  2661
        /* Check for an em-dash broken at line end. */
ali@40
  2662
        if (enddash && *aline=='-')
ali@40
  2663
	{
ali@40
  2664
            if (pswit[ECHO_SWITCH])
ali@40
  2665
		printf("\n%s\n",aline);
ali@0
  2666
            if (!pswit[OVERVIEW_SWITCH])
ali@40
  2667
                printf("    Line %ld column 1 - Broken em-dash?\n",linecnt);
ali@0
  2668
            else
ali@0
  2669
                cnt_punct++;
ali@40
  2670
	}
ali@40
  2671
        enddash=0;
ali@40
  2672
        for (s=aline+strlen(aline)-1;*s==' ' && s>aline;s--)
ali@40
  2673
	    ;
ali@40
  2674
        if (s>=aline && *s=='-')
ali@40
  2675
            enddash=1;
ali@67
  2676
	check_for_control_characters(aline);
ali@42
  2677
        if (warnings->bin)
ali@44
  2678
	    check_for_odd_characters(aline,warnings,isemptyline);
ali@42
  2679
        if (warnings->longline)
ali@45
  2680
	    check_for_long_line(aline);
ali@45
  2681
        if (warnings->shortline)
ali@45
  2682
	    check_for_short_line(aline,&last);
ali@45
  2683
        last.blen=last.len;
ali@45
  2684
        last.len=strlen(aline);
ali@45
  2685
        last.start=aline[0];
ali@46
  2686
	check_for_starting_punctuation(aline);
ali@42
  2687
        if (warnings->dash)
ali@40
  2688
	{
ali@47
  2689
	    check_for_spaced_emdash(aline);
ali@47
  2690
	    check_for_spaced_dash(aline);
ali@40
  2691
	}
ali@48
  2692
	check_for_unmarked_paragraphs(aline);
ali@49
  2693
	check_for_jeebies(aline);
ali@50
  2694
	check_for_mta_from(aline);
ali@51
  2695
	check_for_orphan_character(aline);
ali@52
  2696
	check_for_pling_scanno(aline);
ali@53
  2697
	check_for_extra_period(aline,warnings);
ali@54
  2698
	check_for_following_punctuation(aline);
ali@55
  2699
	check_for_typos(aline,warnings);
ali@56
  2700
	check_for_misspaced_punctuation(aline,&parities,isemptyline);
ali@57
  2701
	check_for_double_punctuation(aline,warnings);
ali@58
  2702
	check_for_spaced_quotes(aline);
ali@59
  2703
	check_for_miscased_genative(aline);
ali@60
  2704
	check_end_of_line(aline,warnings);
ali@61
  2705
	check_for_unspaced_bracket(aline);
ali@42
  2706
        if (warnings->endquote)
ali@62
  2707
	    check_for_unpunctuated_endquote(aline);
ali@63
  2708
	check_for_html_tag(aline);
ali@64
  2709
	check_for_html_entity(aline);
ali@40
  2710
        if (isemptyline)
ali@40
  2711
	{
ali@65
  2712
	    check_for_mismatched_quotes(&counters,&pending);
ali@43
  2713
	    memset(&counters,0,sizeof(counters));
ali@40
  2714
	    /* let the next iteration know that it's starting a new para */
ali@40
  2715
            isnewpara=1;
ali@66
  2716
	    check_for_omitted_punctuation(prevline,&last,start_para_line);
ali@40
  2717
	}
ali@40
  2718
        strcpy(prevline,aline);
ali@0
  2719
    }
ali@40
  2720
    fclose(infile);
ali@0
  2721
    if (!pswit[OVERVIEW_SWITCH])
ali@40
  2722
        for (i=0;i<MAX_QWORD;i++)
ali@0
  2723
            if (dupcnt[i])
ali@40
  2724
                printf("\nNote: Queried word %s was duplicated %d time%s\n",
ali@40
  2725
		  qword[i],dupcnt[i],"s");
ali@0
  2726
}
ali@0
  2727
ali@40
  2728
/*
ali@40
  2729
 * flgets:
ali@40
  2730
 *
ali@40
  2731
 * Get one line from the input stream, checking for
ali@40
  2732
 * the existence of exactly one CR/LF line-end per line.
ali@40
  2733
 *
ali@40
  2734
 * Returns: a pointer to the line.
ali@40
  2735
 */
ali@40
  2736
char *flgets(char *theline,int maxlen,FILE *thefile,long lcnt)
ali@0
  2737
{
ali@0
  2738
    char c;
ali@40
  2739
    int len,isCR,cint;
ali@40
  2740
    *theline=0;
ali@40
  2741
    len=isCR=0;
ali@40
  2742
    c=cint=fgetc(thefile);
ali@40
  2743
    do
ali@40
  2744
    {
ali@40
  2745
        if (cint==EOF)
ali@40
  2746
            return NULL;
ali@40
  2747
	/* either way, it's end of line */
ali@40
  2748
        if (c==10)
ali@40
  2749
	{
ali@0
  2750
            if (isCR)
ali@0
  2751
                break;
ali@40
  2752
            else
ali@40
  2753
	    {
ali@40
  2754
		/* Error - a LF without a preceding CR */
ali@40
  2755
                if (pswit[LINE_END_SWITCH])
ali@40
  2756
		{
ali@40
  2757
                    if (pswit[ECHO_SWITCH])
ali@40
  2758
			printf("\n%s\n",theline);
ali@0
  2759
                    if (!pswit[OVERVIEW_SWITCH])
ali@40
  2760
                        printf("    Line %ld - No CR?\n",lcnt);
ali@0
  2761
                    else
ali@0
  2762
                        cnt_lineend++;
ali@40
  2763
		}
ali@0
  2764
                break;
ali@40
  2765
	    }
ali@40
  2766
	}
ali@40
  2767
        if (c==13)
ali@40
  2768
	{
ali@40
  2769
            if (isCR)
ali@40
  2770
	    {
ali@40
  2771
		/* Error - two successive CRs */
ali@40
  2772
                if (pswit[LINE_END_SWITCH])
ali@40
  2773
		{
ali@40
  2774
                    if (pswit[ECHO_SWITCH])
ali@40
  2775
			printf("\n%s\n",theline);
ali@0
  2776
                    if (!pswit[OVERVIEW_SWITCH])
ali@40
  2777
                        printf("    Line %ld - Two successive CRs?\n",lcnt);
ali@0
  2778
                    else
ali@0
  2779
                        cnt_lineend++;
ali@40
  2780
		}
ali@40
  2781
	    }
ali@40
  2782
            isCR=1;
ali@40
  2783
	}
ali@40
  2784
        else
ali@40
  2785
	{
ali@40
  2786
            if (pswit[LINE_END_SWITCH] && isCR)
ali@40
  2787
	    {
ali@40
  2788
                if (pswit[ECHO_SWITCH])
ali@40
  2789
		    printf("\n%s\n",theline);
ali@0
  2790
                if (!pswit[OVERVIEW_SWITCH])
ali@40
  2791
                    printf("    Line %ld column %d - CR without LF?\n",
ali@40
  2792
		      lcnt,len+1);
ali@0
  2793
                else
ali@0
  2794
                    cnt_lineend++;
ali@40
  2795
	    }
ali@40
  2796
            theline[len]=c;
ali@40
  2797
            len++;
ali@40
  2798
            theline[len]=0;
ali@40
  2799
            isCR=0;
ali@40
  2800
	}
ali@40
  2801
        c=cint=fgetc(thefile);
ali@40
  2802
    } while(len<maxlen);
ali@0
  2803
    if (pswit[MARKUP_SWITCH])  
ali@0
  2804
        postprocess_for_HTML(theline);
ali@0
  2805
    if (pswit[DP_SWITCH])  
ali@0
  2806
        postprocess_for_DP(theline);
ali@40
  2807
    return theline;
ali@0
  2808
}
ali@0
  2809
ali@40
  2810
/*
ali@40
  2811
 * mixdigit:
ali@40
  2812
 *
ali@40
  2813
 * Takes a "word" as a parameter, and checks whether it
ali@40
  2814
 * contains a mixture of alpha and digits. Generally, this is an
ali@40
  2815
 * error, but may not be for cases like 4th or L5 12s. 3d.
ali@40
  2816
 *
ali@40
  2817
 * Returns: 0 if no error found, 1 if error.
ali@40
  2818
 */
ali@40
  2819
int mixdigit(char *checkword)
ali@0
  2820
{
ali@40
  2821
    int wehaveadigit,wehavealetter,firstdigits,query,wl;
ali@0
  2822
    char *s;
ali@40
  2823
    wehaveadigit=wehavealetter=query=0;
ali@40
  2824
    for (s=checkword;*s;s++)
ali@0
  2825
        if (gcisalpha(*s))
ali@40
  2826
            wehavealetter=1;
ali@0
  2827
        else
ali@0
  2828
            if (gcisdigit(*s))
ali@40
  2829
                wehaveadigit=1;
ali@40
  2830
    if (wehaveadigit && wehavealetter)
ali@40
  2831
    {
ali@40
  2832
	/* Now exclude common legit cases, like "21st" and "12l. 3s. 11d." */
ali@40
  2833
        query=1;
ali@40
  2834
        wl=strlen(checkword);
ali@40
  2835
        for (firstdigits=0;gcisdigit(checkword[firstdigits]);firstdigits++)
ali@0
  2836
            ;
ali@0
  2837
        /* digits, ending in st, rd, nd, th of either case */
ali@40
  2838
        if (firstdigits+2==wl && (matchword(checkword+wl-2,"st") ||
ali@40
  2839
	  matchword(checkword+wl-2,"rd") || matchword(checkword+wl-2,"nd") ||
ali@40
  2840
	  matchword(checkword+wl-2,"th")))
ali@40
  2841
	    query=0;
ali@40
  2842
        if (firstdigits+3==wl && (matchword(checkword+wl-3,"sts") ||
ali@40
  2843
	  matchword(checkword+wl-3,"rds") || matchword(checkword+wl-3,"nds") ||
ali@40
  2844
	  matchword(checkword+wl-3,"ths")))
ali@40
  2845
	    query=0;
ali@40
  2846
        if (firstdigits+3==wl && (matchword(checkword+wl-4,"stly") ||
ali@40
  2847
	  matchword(checkword+wl-4,"rdly") ||
ali@40
  2848
	  matchword(checkword+wl-4,"ndly") || matchword(checkword+wl-4,"thly")))
ali@40
  2849
	    query=0;
ali@0
  2850
        /* digits, ending in l, L, s or d */
ali@40
  2851
        if (firstdigits+1==wl && (checkword[wl-1]=='l' ||
ali@40
  2852
	  checkword[wl-1]=='L' || checkword[wl-1]=='s' || checkword[wl-1]=='d'))
ali@40
  2853
	    query=0;
ali@40
  2854
        /*
ali@40
  2855
	 * L at the start of a number, representing Britsh pounds, like L500.
ali@40
  2856
         * This is cute. We know the current word is mixeddigit. If the first
ali@40
  2857
         * letter is L, there must be at least one digit following. If both
ali@40
  2858
         * digits and letters follow, we have a genuine error, else we have a
ali@40
  2859
         * capital L followed by digits, and we accept that as a non-error.
ali@40
  2860
	 */
ali@40
  2861
        if (checkword[0]=='L' && !mixdigit(checkword+1))
ali@40
  2862
	    query=0;
ali@40
  2863
    }
ali@40
  2864
    return query;
ali@0
  2865
}
ali@0
  2866
ali@40
  2867
/*
ali@40
  2868
 * getaword:
ali@40
  2869
 *
ali@40
  2870
 * Extracts the first/next "word" from the line, and puts
ali@40
  2871
 * it into "thisword". A word is defined as one English word unit--or
ali@40
  2872
 * at least that's the aim.
ali@40
  2873
 *
ali@40
  2874
 * Returns: a pointer to the position in the line where we will start
ali@40
  2875
 *          looking for the next word.
ali@40
  2876
 */
ali@54
  2877
const char *getaword(const char *fromline,char *thisword)
ali@0
  2878
{
ali@40
  2879
    int i,wordlen;
ali@54
  2880
    const char *s;
ali@40
  2881
    wordlen=0;
ali@40
  2882
    for (;!gcisdigit(*fromline) && !gcisalpha(*fromline) && *fromline;
ali@40
  2883
      fromline++)
ali@40
  2884
	;
ali@40
  2885
    /*
ali@40
  2886
     * Use a look-ahead to handle exceptions for numbers like 1,000 and 1.35.
ali@40
  2887
     * Especially yucky is the case of L1,000
ali@40
  2888
     * This section looks for a pattern of characters including a digit
ali@40
  2889
     * followed by a comma or period followed by one or more digits.
ali@40
  2890
     * If found, it returns this whole pattern as a word; otherwise we discard
ali@40
  2891
     * the results and resume our normal programming.
ali@40
  2892
     */
ali@40
  2893
    s=fromline;
ali@40
  2894
    for (;(gcisdigit(*s) || gcisalpha(*s) || *s==',' || *s=='.') &&
ali@40
  2895
      wordlen<MAXWORDLEN;s++)
ali@40
  2896
    {
ali@40
  2897
	thisword[wordlen]=*s;
ali@0
  2898
        wordlen++;
ali@40
  2899
    }
ali@40
  2900
    thisword[wordlen]=0;
ali@40
  2901
    for (i=1;i<wordlen-1;i++)
ali@40
  2902
    {
ali@40
  2903
        if (thisword[i]=='.' || thisword[i]==',')
ali@40
  2904
	{
ali@40
  2905
            if (gcisdigit(thisword[i-1]) && gcisdigit(thisword[i-1]))
ali@40
  2906
	    {
ali@40
  2907
                fromline=s;
ali@40
  2908
                return fromline;
ali@40
  2909
	    }
ali@40
  2910
	}
ali@40
  2911
    }
ali@0
  2912
    /* we didn't find a punctuated number - do the regular getword thing */
ali@40
  2913
    wordlen=0;
ali@40
  2914
    for (;(gcisdigit(*fromline) || gcisalpha(*fromline) || *fromline=='\'') &&
ali@40
  2915
      wordlen<MAXWORDLEN;fromline++)
ali@40
  2916
    {
ali@40
  2917
        thisword[wordlen]=*fromline;
ali@0
  2918
        wordlen++;
ali@40
  2919
    }
ali@40
  2920
    thisword[wordlen]=0;
ali@40
  2921
    return fromline;
ali@0
  2922
}
ali@0
  2923
ali@40
  2924
/*
ali@40
  2925
 * matchword:
ali@40
  2926
 *
ali@40
  2927
 * A case-insensitive string matcher.
ali@40
  2928
 */
ali@40
  2929
int matchword(char *checkfor,char *thisword)
ali@0
  2930
{
ali@40
  2931
    unsigned int ismatch,i;
ali@40
  2932
    if (strlen(checkfor)!=strlen(thisword))
ali@40
  2933
	return 0;
ali@40
  2934
    ismatch=1;     /* assume a match until we find a difference */
ali@40
  2935
    for (i=0;i<strlen(checkfor);i++)
ali@40
  2936
        if (toupper(checkfor[i])!=toupper(thisword[i]))
ali@40
  2937
            ismatch=0;
ali@40
  2938
    return ismatch;
ali@0
  2939
}
ali@0
  2940
ali@40
  2941
/*
ali@40
  2942
 * lowerit:
ali@40
  2943
 *
ali@40
  2944
 * Lowercase the line.
ali@40
  2945
 */
ali@0
  2946
ali@0
  2947
void lowerit(char *theline)
ali@0
  2948
{
ali@40
  2949
    for (;*theline;theline++)
ali@40
  2950
        if (*theline>='A' && *theline<='Z')
ali@40
  2951
            *theline+=32;
ali@0
  2952
}
ali@0
  2953
ali@40
  2954
/*
ali@40
  2955
 * isroman:
ali@40
  2956
 *
ali@40
  2957
 * Is this word a Roman Numeral?
ali@40
  2958
 *
ali@40
  2959
 * It doesn't actually validate that the number is a valid Roman Numeral--for
ali@40
  2960
 * example it will pass MXXXXXXXXXX as a valid Roman Numeral, but that's not
ali@40
  2961
 * what we're here to do. If it passes this, it LOOKS like a Roman numeral.
ali@40
  2962
 * Anyway, the actual Romans were pretty tolerant of bad arithmetic, or
ali@40
  2963
 * expressions thereof, except when it came to taxes. Allow any number of M,
ali@40
  2964
 * an optional D, an optional CM or CD, any number of optional Cs, an optional
ali@40
  2965
 * XL or an optional XC, an optional IX or IV, an optional V and any number
ali@40
  2966
 * of optional Is.
ali@40
  2967
 */
ali@0
  2968
int isroman(char *t)
ali@0
  2969
{
ali@0
  2970
    char *s;
ali@40
  2971
    if (!t || !*t)
ali@40
  2972
	return 0;
ali@40
  2973
    s=t;
ali@40
  2974
    while (*t=='m' && *t)
ali@40
  2975
	t++;
ali@40
  2976
    if (*t=='d')
ali@40
  2977
	t++;
ali@40
  2978
    if (*t=='c' && t[1]=='m')
ali@40
  2979
	t+=2;
ali@40
  2980
    if (*t=='c' && t[1]=='d')
ali@40
  2981
	t+=2;
ali@40
  2982
    while (*t=='c' && *t)
ali@40
  2983
	t++;
ali@40
  2984
    if (*t=='x' && t[1]=='l')
ali@40
  2985
	t+=2;
ali@40
  2986
    if (*t=='x' && t[1]=='c')
ali@40
  2987
	t+=2;
ali@40
  2988
    if (*t=='l')
ali@40
  2989
	t++;
ali@40
  2990
    while (*t=='x' && *t)
ali@40
  2991
	t++;
ali@40
  2992
    if (*t=='i' && t[1]=='x')
ali@40
  2993
	t+=2;
ali@40
  2994
    if (*t=='i' && t[1]=='v')
ali@40
  2995
	t+=2;
ali@40
  2996
    if (*t=='v')
ali@40
  2997
	t++;
ali@40
  2998
    while (*t=='i' && *t)
ali@40
  2999
	t++;
ali@40
  3000
    return !*t;
ali@0
  3001
}
ali@0
  3002
ali@40
  3003
/*
ali@40
  3004
 * gcisalpha:
ali@40
  3005
 *
ali@40
  3006
 * A version of isalpha() that is somewhat lenient on 8-bit texts.
ali@40
  3007
 * If we use the standard function, 8-bit accented characters break
ali@40
  3008
 * words, so that tete with accented characters appears to be two words, "t"
ali@40
  3009
 * and "t", with 8-bit characters between them. This causes over-reporting of
ali@40
  3010
 * errors. gcisalpha() recognizes accented letters from the CP1252 (Windows)
ali@40
  3011
 * and ISO-8859-1 character sets, which are the most common PG 8-bit types.
ali@40
  3012
 */
ali@0
  3013
int gcisalpha(unsigned char c)
ali@0
  3014
{
ali@40
  3015
    if (c>='a' && c<='z')
ali@40
  3016
	return 1;
ali@40
  3017
    if (c>='A' && c<='Z')
ali@40
  3018
	return 1;
ali@40
  3019
    if (c<140)
ali@40
  3020
	return 0;
ali@40
  3021
    if (c>=192 && c!=208 && c!=215 && c!=222 && c!=240 && c!=247 && c!=254)
ali@40
  3022
	return 1;
ali@40
  3023
    if (c==140 || c==142 || c==156 || c==158 || c==159)
ali@40
  3024
	return 1;
ali@40
  3025
    return 0;
ali@0
  3026
}
ali@0
  3027
ali@40
  3028
/*
ali@40
  3029
 * gcisdigit:
ali@40
  3030
 *
ali@40
  3031
 * A version of isdigit() that doesn't get confused in 8-bit texts.
ali@40
  3032
 */
ali@0
  3033
int gcisdigit(unsigned char c)
ali@0
  3034
{   
ali@40
  3035
    return c>='0' && c<='9';
ali@0
  3036
}
ali@0
  3037
ali@40
  3038
/*
ali@40
  3039
 * gcisletter:
ali@40
  3040
 *
ali@40
  3041
 * A version of isletter() that doesn't get confused in 8-bit texts.
ali@40
  3042
 * NB: this is ISO-8891-1-specific.
ali@40
  3043
 */
ali@0
  3044
int gcisletter(unsigned char c)
ali@0
  3045
{   
ali@40
  3046
    return c>='A' && c<='Z' || c>='a' && c<='z' || c>=192;
ali@0
  3047
}
ali@0
  3048
ali@40
  3049
/*
ali@40
  3050
 * gcstrchr:
ali@40
  3051
 *
ali@40
  3052
 * Wraps strchr to return NULL if the character being searched for is zero.
ali@40
  3053
 */
ali@40
  3054
char *gcstrchr(char *s,char c)
ali@0
  3055
{
ali@40
  3056
    if (!c)
ali@40
  3057
	return NULL;
ali@40
  3058
    return strchr(s,c);
ali@0
  3059
}
ali@0
  3060
ali@40
  3061
/*
ali@40
  3062
 * postprocess_for_DP:
ali@40
  3063
 *
ali@40
  3064
 * Invoked with the -d switch from flgets().
ali@40
  3065
 * It simply "removes" from the line a hard-coded set of common
ali@40
  3066
 * DP-specific tags, so that the line passed to the main routine has
ali@40
  3067
 * been pre-cleaned of DP markup.
ali@40
  3068
 */
ali@0
  3069
void postprocess_for_DP(char *theline)
ali@0
  3070
{
ali@40
  3071
    char *s,*t;
ali@0
  3072
    int i;
ali@0
  3073
    if (!*theline) 
ali@0
  3074
        return;
ali@40
  3075
    for (i=0;*DPmarkup[i];i++)
ali@40
  3076
    {
ali@40
  3077
        s=strstr(theline,DPmarkup[i]);
ali@40
  3078
        while (s)
ali@40
  3079
	{
ali@40
  3080
            t=s+strlen(DPmarkup[i]);
ali@40
  3081
            while (*t)
ali@40
  3082
	    {
ali@40
  3083
                *s=*t;
ali@40
  3084
                t++;
ali@40
  3085
		s++;
ali@40
  3086
	    }
ali@40
  3087
            *s=0;
ali@40
  3088
            s=strstr(theline,DPmarkup[i]);
ali@40
  3089
	}
ali@40
  3090
    }
ali@0
  3091
}
ali@0
  3092
ali@40
  3093
/*
ali@40
  3094
 * postprocess_for_HTML:
ali@40
  3095
 *
ali@40
  3096
 * Invoked with the -m switch from flgets().
ali@40
  3097
 * It simply "removes" from the line a hard-coded set of common
ali@40
  3098
 * HTML tags and "replaces" a hard-coded set of common HTML
ali@40
  3099
 * entities, so that the line passed to the main routine has
ali@40
  3100
 * been pre-cleaned of HTML.
ali@40
  3101
 */
ali@0
  3102
void postprocess_for_HTML(char *theline)
ali@0
  3103
{
ali@40
  3104
    if (strstr(theline,"<") && strstr(theline,">"))
ali@0
  3105
        while (losemarkup(theline))
ali@0
  3106
            ;
ali@0
  3107
    while (loseentities(theline))
ali@0
  3108
        ;
ali@0
  3109
}
ali@0
  3110
ali@0
  3111
char *losemarkup(char *theline)
ali@0
  3112
{
ali@40
  3113
    char *s,*t;
ali@0
  3114
    int i;
ali@0
  3115
    if (!*theline) 
ali@40
  3116
        return NULL;
ali@40
  3117
    s=strstr(theline,"<");
ali@40
  3118
    t=strstr(theline,">");
ali@40
  3119
    if (!s || !t)
ali@40
  3120
	return NULL;
ali@40
  3121
    for (i=0;*markup[i];i++)
ali@40
  3122
        if (!tagcomp(s+1,markup[i]))
ali@40
  3123
	{
ali@40
  3124
            if (!t[1])
ali@40
  3125
	    {
ali@40
  3126
                *s=0;
ali@40
  3127
                return s;
ali@40
  3128
	    }
ali@40
  3129
            else if (t>s)
ali@40
  3130
	    {
ali@40
  3131
		strcpy(s,t+1);
ali@40
  3132
		return s;
ali@40
  3133
	    }
ali@0
  3134
        }
ali@40
  3135
    /* It's an unrecognized <xxx>. */
ali@40
  3136
    return NULL;
ali@0
  3137
}
ali@0
  3138
ali@0
  3139
char *loseentities(char *theline)
ali@0
  3140
{
ali@0
  3141
    int i;
ali@40
  3142
    char *s,*t;
ali@0
  3143
    if (!*theline) 
ali@40
  3144
        return NULL;
ali@40
  3145
    for (i=0;*entities[i].htmlent;i++)
ali@40
  3146
    {
ali@40
  3147
        s=strstr(theline,entities[i].htmlent);
ali@40
  3148
        if (s)
ali@40
  3149
	{
ali@40
  3150
            t=malloc((size_t)strlen(s));
ali@40
  3151
            if (!t)
ali@40
  3152
		return NULL;
ali@40
  3153
            strcpy(t,s+strlen(entities[i].htmlent));
ali@40
  3154
            strcpy(s,entities[i].textent);
ali@40
  3155
            strcat(s,t);
ali@0
  3156
            free(t);
ali@40
  3157
            return theline;
ali@40
  3158
	}
ali@40
  3159
    }
ali@40
  3160
    for (i=0;*entities[i].htmlnum;i++)
ali@40
  3161
    {
ali@40
  3162
        s=strstr(theline,entities[i].htmlnum);
ali@40
  3163
        if (s)
ali@40
  3164
	{
ali@40
  3165
            t=malloc((size_t)strlen(s));
ali@40
  3166
            if (!t)
ali@40
  3167
		return NULL;
ali@40
  3168
            strcpy(t,s+strlen(entities[i].htmlnum));
ali@40
  3169
            strcpy(s,entities[i].textent);
ali@40
  3170
            strcat(s,t);
ali@0
  3171
            free(t);
ali@40
  3172
            return theline;
ali@40
  3173
	}
ali@40
  3174
    }
ali@40
  3175
    return NULL;
ali@0
  3176
}
ali@0
  3177
ali@40
  3178
int tagcomp(char *strin,char *basetag)
ali@0
  3179
{
ali@40
  3180
    char *s,*t;
ali@40
  3181
    s=basetag;
ali@40
  3182
    t=strin;
ali@40
  3183
    if (*t=='/')
ali@40
  3184
	t++; /* ignore a slash */
ali@40
  3185
    while (*s && *t)
ali@40
  3186
    {
ali@40
  3187
        if (tolower(*s)!=tolower(*t))
ali@40
  3188
	    return 1;
ali@40
  3189
        s++;
ali@40
  3190
	t++;
ali@40
  3191
    }
ali@40
  3192
    return 0;
ali@0
  3193
}
ali@0
  3194
ali@40
  3195
void proghelp()
ali@0
  3196
{
ali@40
  3197
    fputs("Bookloupe version " PACKAGE_VERSION ".\n",stderr);
ali@40
  3198
    fputs("Copyright 2000-2005 Jim Tinsley <jtinsley@pobox.com>.\n",stderr);
ali@40
  3199
    fputs("Copyright 2012- J. Ali Harlow <ali@juiblex.co.uk>.\n",stderr);
ali@40
  3200
    fputs("Bookloupe comes wih ABSOLUTELY NO WARRANTY. "
ali@40
  3201
      "For details, read the file COPYING.\n",stderr);
ali@40
  3202
    fputs("This is Free Software; "
ali@40
  3203
      "you may redistribute it under certain conditions (GPL);\n",stderr);
ali@40
  3204
    fputs("read the file COPYING for details.\n\n",stderr);
ali@40
  3205
    fputs("Usage is: bookloupe [-setpxloyhud] filename\n",stderr);
ali@40
  3206
    fputs("  where -s checks single quotes, -e suppresses echoing lines, "
ali@40
  3207
      "-t checks typos\n",stderr);
ali@40
  3208
    fputs("  -x (paranoid) switches OFF -t and extra checks, "
ali@40
  3209
      "-l turns OFF line-end checks\n",stderr);
ali@40
  3210
    fputs("  -o just displays overview without detail, "
ali@40
  3211
      "-h echoes header fields\n",stderr);
ali@40
  3212
    fputs("  -v (verbose) unsuppresses duplicate reporting, "
ali@40
  3213
      "-m suppresses markup\n",stderr);
ali@0
  3214
    fputs("  -d ignores DP-specific markup,\n",stderr);
ali@40
  3215
    fputs("  -u uses a file gutcheck.typ to query user-defined "
ali@40
  3216
      "possible typos\n",stderr);
ali@40
  3217
    fputs("Sample usage: bookloupe warpeace.txt \n",stderr);
ali@0
  3218
    fputs("\n",stderr);
ali@40
  3219
    fputs("Bookloupe looks for errors in Project Gutenberg(TM) etexts.\n",
ali@40
  3220
      stderr);
ali@40
  3221
    fputs("Bookloupe queries anything it thinks shouldn't be in a PG text; "
ali@40
  3222
      "non-ASCII\n",stderr);
ali@40
  3223
    fputs("characters like accented letters, "
ali@40
  3224
      "lines longer than 75 or shorter than 55,\n",stderr);
ali@40
  3225
    fputs("unbalanced quotes or brackets, "
ali@40
  3226
      "a variety of badly formatted punctuation, \n",stderr);
ali@40
  3227
    fputs("HTML tags, some likely typos. "
ali@40
  3228
      "It is NOT a substitute for human judgement.\n",stderr);
ali@0
  3229
    fputs("\n",stderr);
ali@0
  3230
}