ali@0: /*************************************************************************/ ali@40: /* bookloupe--check for assorted weirdnesses in a PG candidate text file */ ali@68: /* */ ali@68: /* Copyright 2000-2005 Jim Tinsley */ ali@68: /* Copyright 2012- J. Ali Harlow */ ali@68: /* */ ali@0: /* This program is free software; you can redistribute it and/or modify */ ali@0: /* it under the terms of the GNU General Public License as published by */ ali@0: /* the Free Software Foundation; either version 2 of the License, or */ ali@68: /* (at your option) any later version. */ ali@68: /* */ ali@0: /* This program is distributed in the hope that it will be useful, */ ali@68: /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ ali@68: /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ ali@68: /* GNU General Public License for more details. */ ali@68: /* */ ali@68: /* You should have received a copy of the GNU General Public License */ ali@68: /* along with this program. If not, see . */ ali@0: /*************************************************************************/ ali@0: ali@0: #include ali@0: #include ali@0: #include ali@0: #include ali@69: #include ali@69: #include ali@0: ali@69: gchar *prevline; ali@0: ali@40: /* Common typos. */ ali@40: char *typo[] = { ali@40: "teh", "th", "og", "fi", "ro", "adn", "yuo", "ot", "fo", "thet", "ane", ali@40: "nad", "te", "ig", "acn", "ahve", "alot", "anbd", "andt", "awya", "aywa", ali@40: "bakc", "om", "btu", "byt", "cna", "cxan", "coudl", "dont", "didnt", ali@40: "couldnt", "wouldnt", "doesnt", "shouldnt", "doign", "ehr", "hmi", "hse", ali@40: "esle", "eyt", "fitrs", "firts", "foudn", "frmo", "fromt", "fwe", "gaurd", ali@40: "gerat", "goign", "gruop", "haev", "hda", "hearign", "seeign", "sayign", ali@40: "herat", "hge", "hsa", "hsi", "hte", "htere", "htese", "htey", "htis", ali@40: "hvae", "hwich", "idae", "ihs", "iits", "int", "iwll", "iwth", "jsut", ali@40: "loev", "sefl", "myu", "nkow", "nver", "nwe", "nwo", "ocur", "ohter", ali@40: "omre", "onyl", "otehr", "otu", "owrk", "owuld", "peice", "peices", ali@40: "peolpe", "peopel", "perhasp", "perhpas", "pleasent", "poeple", "porblem", ali@40: "porblems", "rwite", "saidt", "saidh", "saids", "seh", "smae", "smoe", ali@40: "sohw", "stnad", "stopry", "stoyr", "stpo", "tahn", "taht", "tath", ali@40: "tehy", "tghe", "tghis", "theri", "theyll", "thgat", "thge", "thier", ali@40: "thna", "thne", "thnig", "thnigs", "thsi", "thsoe", "thta", "timne", ali@40: "tirne", "tkae", "tthe", "tyhat", "tyhe", "veyr", "vou", "vour", "vrey", ali@40: "waht", "wasnt", "awtn", "watn", "wehn", "whic", "whcih", "whihc", "whta", ali@40: "wihch", "wief", "wiht", "witha", "wiull", "wnat", "wnated", "wnats", ali@40: "woh", "wohle", "wokr", "woudl", "wriet", "wrod", "wroet", "wroking", ali@40: "wtih", "wuould", "wya", "yera", "yeras", "yersa", "yoiu", "youve", ali@40: "ytou", "yuor", "abead", "ahle", "ahout", "ahove", "altbough", "balf", ali@40: "bardly", "bas", "bave", "baving", "bebind", "beld", "belp", "belped", ali@40: "ber", "bere", "bim", "bis", "bome", "bouse", "bowever", "buge", ali@40: "dehates", "deht", "han", "hecause", "hecome", "heen", "hefore", "hegan", ali@40: "hegin", "heing", "helieve", "henefit", "hetter", "hetween", "heyond", ali@40: "hig", "higber", "huild", "huy", "hy", "jobn", "joh", "meanwbile", ali@40: "memher", "memhers", "numher", "numhers", "perbaps", "prohlem", "puhlic", ali@40: "witbout", "arn", "hin", "hirn", "wrok", "wroked", "amd", "aud", ali@40: "prornise", "prornised", "modem", "bo", "heside", "chapteb", "chaptee", ali@40: "se", "" ali@40: }; ali@0: ali@69: GTree *usertypo; ali@0: ali@40: /* Common abbreviations and other OK words not to query as typos. */ ali@40: char *okword[] = { ali@40: "mr", "mrs", "mss", "mssrs", "ft", "pm", "st", "dr", "hmm", "h'm", "hmmm", ali@40: "rd", "sh", "br", "pp", "hm", "cf", "jr", "sr", "vs", "lb", "lbs", "ltd", ali@40: "pompeii","hawaii","hawaiian", "hotbed", "heartbeat", "heartbeats", ali@40: "outbid", "outbids", "frostbite", "frostbitten", "" ali@40: }; ali@0: ali@40: /* Common abbreviations that cause otherwise unexplained periods. */ ali@40: char *abbrev[] = { ali@40: "cent", "cents", "viz", "vol", "vols", "vid", "ed", "al", "etc", "op", ali@40: "cit", "deg", "min", "chap", "oz", "mme", "mlle", "mssrs", "" ali@40: }; ali@0: ali@40: /* ali@40: * Two-Letter combinations that rarely if ever start words, ali@40: * but are common scannos or otherwise common letter combinations. ali@40: */ ali@40: char *nostart[] = { ali@40: "hr", "hl", "cb", "sb", "tb", "wb", "tl", "tn", "rn", "lt", "tj", "" ali@40: }; ali@0: ali@40: /* ali@40: * Two-Letter combinations that rarely if ever end words, ali@40: * but are common scannos or otherwise common letter combinations. ali@40: */ ali@40: char *noend[] = { ali@40: "cb", "gb", "pb", "sb", "tb", "wh", "fr", "br", "qu", "tw", "gl", "fl", ali@40: "sw", "gr", "sl", "cl", "iy", "" ali@40: }; ali@0: ali@40: char *markup[] = { ali@40: "a", "b", "big", "blockquote", "body", "br", "center", "col", "div", "em", ali@40: "font", "h1", "h2", "h3", "h4", "h5", "h6", "head", "hr", "html", "i", ali@40: "img", "li", "meta", "ol", "p", "pre", "small", "span", "strong", "sub", ali@40: "sup", "table", "td", "tfoot", "thead", "title", "tr", "tt", "u", "ul", "" ali@40: }; ali@0: ali@40: char *DPmarkup[] = { ali@40: "", "", "/*", "*/", "/#", "#/", "/$", "$/", "", "" ali@40: }; ali@0: ali@40: char *nocomma[] = { ali@40: "the", "it's", "their", "an", "mrs", "a", "our", "that's", "its", "whose", ali@40: "every", "i'll", "your", "my", "mr", "mrs", "mss", "mssrs", "ft", "pm", ali@40: "st", "dr", "rd", "pp", "cf", "jr", "sr", "vs", "lb", "lbs", "ltd", "i'm", ali@40: "during", "let", "toward", "among", "" ali@40: }; ali@0: ali@40: char *noperiod[] = { ali@40: "every", "i'm", "during", "that's", "their", "your", "our", "my", "or", ali@40: "and", "but", "as", "if", "the", "its", "it's", "until", "than", "whether", ali@40: "i'll", "whose", "who", "because", "when", "let", "till", "very", "an", ali@40: "among", "those", "into", "whom", "having", "thence", "" ali@40: }; ali@0: ali@40: char vowels[] = "aeiouàáâãäæèéêëìíîïòóôõöùúûü"; ali@0: ali@0: struct { ali@0: char *htmlent; ali@0: char *htmlnum; ali@0: char *textent; ali@40: } entities[] = { ali@40: "&", "&", "&", ali@40: "<", "<", "<", ali@40: ">", ">", ">", ali@40: "°", "°", " degrees", ali@40: "£", "£", "L", ali@40: """, """, "\"", /* quotation mark = APL quote */ ali@40: "Œ", "Œ", "OE", /* latin capital ligature OE */ ali@40: "œ", "œ", "oe", /* latin small ligature oe */ ali@40: "Š", "Š", "S", /* latin capital letter S with caron */ ali@40: "š", "š", "s", /* latin small letter s with caron */ ali@40: "Ÿ", "Ÿ", "Y", /* latin capital letter Y with diaeresis */ ali@40: "ˆ", "ˆ", "", /* modifier letter circumflex accent */ ali@40: "˜", "˜", "~", /* small tilde, U+02DC ISOdia */ ali@40: " ", " ", " ", /* en space, U+2002 ISOpub */ ali@40: " ", " ", " ", /* em space, U+2003 ISOpub */ ali@40: " ", " ", " ", /* thin space, U+2009 ISOpub */ ali@40: "–", "–", "-", /* en dash, U+2013 ISOpub */ ali@40: "—", "—", "--", /* em dash, U+2014 ISOpub */ ali@40: "’", "’", "'", /* right single quotation mark */ ali@40: "‚", "‚", "'", /* single low-9 quotation mark */ ali@40: "“", "“", "\"", /* left double quotation mark */ ali@40: "”", "”", "\"", /* right double quotation mark */ ali@40: "„", "„", "\"", /* double low-9 quotation mark */ ali@40: "‹", "‹", "\"", /* single left-pointing angle quotation mark */ ali@40: "›", "›", "\"", /* single right-pointing angle quotation mark */ ali@40: " ", " ", " ", /* no-break space = non-breaking space, */ ali@40: "¡", "¡", "!", /* inverted exclamation mark */ ali@40: "¢", "¢", "c", /* cent sign */ ali@40: "£", "£", "L", /* pound sign */ ali@40: "¤", "¤", "$", /* currency sign */ ali@40: "¥", "¥", "Y", /* yen sign = yuan sign */ ali@40: "§", "§", "--", /* section sign */ ali@40: "¨", "¨", " ", /* diaeresis = spacing diaeresis */ ali@40: "©", "©", "(C) ", /* copyright sign */ ali@40: "ª", "ª", " ", /* feminine ordinal indicator */ ali@40: "«", "«", "\"", /* left-pointing double angle quotation mark */ ali@40: "­", "­", "-", /* soft hyphen = discretionary hyphen */ ali@40: "®", "®", "(R) ", /* registered sign = registered trade mark sign */ ali@40: "¯", "¯", " ", /* macron = spacing macron = overline */ ali@40: "°", "°", " degrees", /* degree sign */ ali@40: "±", "±", "+-", /* plus-minus sign = plus-or-minus sign */ ali@40: "²", "²", "2", /* superscript two = superscript digit two */ ali@40: "³", "³", "3", /* superscript three = superscript digit three */ ali@40: "´", "´", " ", /* acute accent = spacing acute */ ali@40: "µ", "µ", "m", /* micro sign */ ali@40: "¶", "¶", "--", /* pilcrow sign = paragraph sign */ ali@40: "¸", "¸", " ", /* cedilla = spacing cedilla */ ali@40: "¹", "¹", "1", /* superscript one = superscript digit one */ ali@40: "º", "º", " ", /* masculine ordinal indicator */ ali@40: "»", "»", "\"", /* right-pointing double angle quotation mark */ ali@40: "¼", "¼", "1/4", /* vulgar fraction one quarter */ ali@40: "½", "½", "1/2", /* vulgar fraction one half */ ali@40: "¾", "¾", "3/4", /* vulgar fraction three quarters */ ali@40: "¿", "¿", "?", /* inverted question mark */ ali@40: "À", "À", "A", /* latin capital letter A with grave */ ali@40: "Á", "Á", "A", /* latin capital letter A with acute */ ali@40: "Â", "Â", "A", /* latin capital letter A with circumflex */ ali@40: "Ã", "Ã", "A", /* latin capital letter A with tilde */ ali@40: "Ä", "Ä", "A", /* latin capital letter A with diaeresis */ ali@40: "Å", "Å", "A", /* latin capital letter A with ring above */ ali@40: "Æ", "Æ", "AE", /* latin capital letter AE */ ali@40: "Ç", "Ç", "C", /* latin capital letter C with cedilla */ ali@40: "È", "È", "E", /* latin capital letter E with grave */ ali@40: "É", "É", "E", /* latin capital letter E with acute */ ali@40: "Ê", "Ê", "E", /* latin capital letter E with circumflex */ ali@40: "Ë", "Ë", "E", /* latin capital letter E with diaeresis */ ali@40: "Ì", "Ì", "I", /* latin capital letter I with grave */ ali@40: "Í", "Í", "I", /* latin capital letter I with acute */ ali@40: "Î", "Î", "I", /* latin capital letter I with circumflex */ ali@40: "Ï", "Ï", "I", /* latin capital letter I with diaeresis */ ali@40: "Ð", "Ð", "E", /* latin capital letter ETH */ ali@40: "Ñ", "Ñ", "N", /* latin capital letter N with tilde */ ali@40: "Ò", "Ò", "O", /* latin capital letter O with grave */ ali@40: "Ó", "Ó", "O", /* latin capital letter O with acute */ ali@40: "Ô", "Ô", "O", /* latin capital letter O with circumflex */ ali@40: "Õ", "Õ", "O", /* latin capital letter O with tilde */ ali@40: "Ö", "Ö", "O", /* latin capital letter O with diaeresis */ ali@40: "×", "×", "*", /* multiplication sign */ ali@40: "Ø", "Ø", "O", /* latin capital letter O with stroke */ ali@40: "Ù", "Ù", "U", /* latin capital letter U with grave */ ali@40: "Ú", "Ú", "U", /* latin capital letter U with acute */ ali@40: "Û", "Û", "U", /* latin capital letter U with circumflex */ ali@40: "Ü", "Ü", "U", /* latin capital letter U with diaeresis */ ali@40: "Ý", "Ý", "Y", /* latin capital letter Y with acute */ ali@40: "Þ", "Þ", "TH", /* latin capital letter THORN */ ali@40: "ß", "ß", "sz", /* latin small letter sharp s = ess-zed */ ali@40: "à", "à", "a", /* latin small letter a with grave */ ali@40: "á", "á", "a", /* latin small letter a with acute */ ali@40: "â", "â", "a", /* latin small letter a with circumflex */ ali@40: "ã", "ã", "a", /* latin small letter a with tilde */ ali@40: "ä", "ä", "a", /* latin small letter a with diaeresis */ ali@40: "å", "å", "a", /* latin small letter a with ring above */ ali@40: "æ", "æ", "ae", /* latin small letter ae */ ali@40: "ç", "ç", "c", /* latin small letter c with cedilla */ ali@40: "è", "è", "e", /* latin small letter e with grave */ ali@40: "é", "é", "e", /* latin small letter e with acute */ ali@40: "ê", "ê", "e", /* latin small letter e with circumflex */ ali@40: "ë", "ë", "e", /* latin small letter e with diaeresis */ ali@40: "ì", "ì", "i", /* latin small letter i with grave */ ali@40: "í", "í", "i", /* latin small letter i with acute */ ali@40: "î", "î", "i", /* latin small letter i with circumflex */ ali@40: "ï", "ï", "i", /* latin small letter i with diaeresis */ ali@40: "ð", "ð", "eth", /* latin small letter eth */ ali@40: "ñ", "ñ", "n", /* latin small letter n with tilde */ ali@40: "ò", "ò", "o", /* latin small letter o with grave */ ali@40: "ó", "ó", "o", /* latin small letter o with acute */ ali@40: "ô", "ô", "o", /* latin small letter o with circumflex */ ali@40: "õ", "õ", "o", /* latin small letter o with tilde */ ali@40: "ö", "ö", "o", /* latin small letter o with diaeresis */ ali@40: "÷", "÷", "/", /* division sign */ ali@40: "ø", "ø", "o", /* latin small letter o with stroke */ ali@40: "ù", "ù", "u", /* latin small letter u with grave */ ali@40: "ú", "ú", "u", /* latin small letter u with acute */ ali@40: "û", "û", "u", /* latin small letter u with circumflex */ ali@40: "ü", "ü", "u", /* latin small letter u with diaeresis */ ali@40: "ý", "ý", "y", /* latin small letter y with acute */ ali@40: "þ", "þ", "th", /* latin small letter thorn */ ali@40: "ÿ", "ÿ", "y", /* latin small letter y with diaeresis */ ali@40: "", "" ali@40: }; ali@40: ali@40: /* special characters */ ali@68: #define CHAR_SPACE 32 ali@68: #define CHAR_TAB 9 ali@68: #define CHAR_LF 10 ali@68: #define CHAR_CR 13 ali@68: #define CHAR_DQUOTE 34 ali@68: #define CHAR_SQUOTE 39 ali@0: #define CHAR_OPEN_SQUOTE 96 ali@68: #define CHAR_TILDE 126 ali@68: #define CHAR_ASTERISK 42 ali@68: #define CHAR_FORESLASH 47 ali@68: #define CHAR_CARAT 94 ali@0: ali@0: #define CHAR_UNDERSCORE '_' ali@0: #define CHAR_OPEN_CBRACK '{' ali@0: #define CHAR_CLOSE_CBRACK '}' ali@0: #define CHAR_OPEN_RBRACK '(' ali@0: #define CHAR_CLOSE_RBRACK ')' ali@0: #define CHAR_OPEN_SBRACK '[' ali@0: #define CHAR_CLOSE_SBRACK ']' ali@0: ali@40: /* longest and shortest normal PG line lengths */ ali@0: #define LONGEST_PG_LINE 75 ali@0: #define WAY_TOO_LONG 80 ali@0: #define SHORTEST_PG_LINE 55 ali@0: ali@69: enum { ali@69: ECHO_SWITCH, ali@69: SQUOTE_SWITCH, ali@69: TYPO_SWITCH, ali@69: QPARA_SWITCH, ali@69: PARANOID_SWITCH, ali@69: LINE_END_SWITCH, ali@69: OVERVIEW_SWITCH, ali@69: STDOUT_SWITCH, ali@69: HEADER_SWITCH, ali@69: WEB_SWITCH, ali@69: VERBOSE_SWITCH, ali@69: MARKUP_SWITCH, ali@69: USERTYPO_SWITCH, ali@69: DP_SWITCH, ali@69: SWITNO ali@69: }; ali@0: ali@69: gboolean pswit[SWITNO]; /* program switches */ ali@0: ali@69: static GOptionEntry options[]={ ali@69: { "dp", 'd', 0, G_OPTION_ARG_NONE, pswit+DP_SWITCH, ali@69: "Ignore DP-specific markup", NULL }, ali@69: { "noecho", 'e', 0, G_OPTION_ARG_NONE, pswit+ECHO_SWITCH, ali@69: "Don't echo queried line", NULL }, ali@69: { "squote", 's', 0, G_OPTION_ARG_NONE, pswit+SQUOTE_SWITCH, ali@69: "Check single quotes", NULL }, ali@69: { "typo", 't', 0, G_OPTION_ARG_NONE, pswit+TYPO_SWITCH, ali@69: "Check common typos", NULL }, ali@69: { "qpara", 'p', 0, G_OPTION_ARG_NONE, pswit+QPARA_SWITCH, ali@69: "Require closure of quotes on every paragraph", NULL }, ali@69: { "relaxed", 'x', 0, G_OPTION_ARG_NONE, pswit+PARANOID_SWITCH, ali@69: "Disable paranoid querying of everything", NULL }, ali@69: { "line-end", 'l', 0, G_OPTION_ARG_NONE, pswit+LINE_END_SWITCH, ali@69: "Disable line end checking", NULL }, ali@69: { "overview", 'o', 0, G_OPTION_ARG_NONE, pswit+OVERVIEW_SWITCH, ali@69: "Overview: just show counts", NULL }, ali@69: { "stdout", 'y', 0, G_OPTION_ARG_NONE, pswit+STDOUT_SWITCH, ali@69: "Output errors to stdout instead of stderr", NULL }, ali@69: { "header", 'h', 0, G_OPTION_ARG_NONE, pswit+HEADER_SWITCH, ali@69: "Echo header fields", NULL }, ali@69: { "markup", 'm', 0, G_OPTION_ARG_NONE, pswit+MARKUP_SWITCH, ali@69: "Ignore markup in < >", NULL }, ali@69: { "usertypo", 'u', 0, G_OPTION_ARG_NONE, pswit+USERTYPO_SWITCH, ali@69: "Use file of user-defined typos", NULL }, ali@69: { "web", 'w', 0, G_OPTION_ARG_NONE, pswit+WEB_SWITCH, ali@69: "Defaults for use on www upload", NULL }, ali@69: { "verbose", 'v', 0, G_OPTION_ARG_NONE, pswit+VERBOSE_SWITCH, ali@69: "Verbose - list everything", NULL }, ali@69: { NULL } ali@69: }; ali@0: ali@68: long cnt_dquot; /* for overview mode, count of doublequote queries */ ali@68: long cnt_squot; /* for overview mode, count of singlequote queries */ ali@68: long cnt_brack; /* for overview mode, count of brackets queries */ ali@68: long cnt_bin; /* for overview mode, count of non-ASCII queries */ ali@68: long cnt_odd; /* for overview mode, count of odd character queries */ ali@68: long cnt_long; /* for overview mode, count of long line errors */ ali@68: long cnt_short; /* for overview mode, count of short line queries */ ali@68: long cnt_punct; /* for overview mode, ali@68: count of punctuation and spacing queries */ ali@68: long cnt_dash; /* for overview mode, count of dash-related queries */ ali@68: long cnt_word; /* for overview mode, count of word queries */ ali@68: long cnt_html; /* for overview mode, count of html queries */ ali@68: long cnt_lineend; /* for overview mode, count of line-end queries */ ali@68: long cnt_spacend; /* count of lines with space at end */ ali@68: long linecnt; /* count of total lines in the file */ ali@68: long checked_linecnt; /* count of lines actually checked */ ali@0: ali@69: void proghelp(GOptionContext *context); ali@69: void procfile(const char *); ali@0: ali@69: gchar *running_from; ali@0: ali@69: int mixdigit(const char *); ali@69: gchar *getaword(const char **); ali@69: char *flgets(char **,long); ali@69: gboolean gcisalpha(unsigned char); ali@69: gboolean gcisdigit(unsigned char); ali@69: gboolean gcisletter(unsigned char); ali@0: void postprocess_for_HTML(char *); ali@0: char *linehasmarkup(char *); ali@0: char *losemarkup(char *); ali@69: int tagcomp(const char *,const char *); ali@0: char *loseentities(char *); ali@69: gboolean isroman(const char *); ali@0: void postprocess_for_DP(char *); ali@0: ali@69: GTree *qword,*qperiod; ali@68: ali@68: struct first_pass_results { ali@68: long firstline,astline; ali@68: long footerline,totlen,binlen,alphalen,endquote_count,shortline,dotcomma; ali@68: long fslashline,hyphens,longline,verylongline,htmcount,standalone_digit; ali@68: long spacedash,emdash,space_emdash,non_PG_space_emdash,PG_space_emdash; ali@68: int Dutchcount,Frenchcount; ali@68: }; ali@68: ali@68: struct warnings { ali@68: int shortline,longline,bin,dash,dotcomma,ast,fslash,digit,hyphen; ali@69: int endquote; ali@69: gboolean isDutch,isFrench; ali@68: }; ali@68: ali@68: struct counters { ali@68: long quot; ali@68: int c_unders,c_brack,s_brack,r_brack; ali@68: int open_single_quote,close_single_quote; ali@68: }; ali@68: ali@68: struct line_properties { ali@68: unsigned int len,blen; ali@68: char start; ali@68: }; ali@68: ali@68: struct parities { ali@68: int dquote,squote; ali@68: }; ali@68: ali@68: struct pending { ali@69: char *dquote,*squote,*rbrack,*sbrack,*cbrack,*unders; ali@68: long squot; ali@68: }; ali@0: ali@69: void parse_options(int *argc,char ***argv) ali@0: { ali@69: GError *err=NULL; ali@69: GOptionContext *context; ali@69: context=g_option_context_new( ali@69: "file - looks for errors in Project Gutenberg(TM) etexts"); ali@69: g_option_context_add_main_entries(context,options,NULL); ali@69: if (!g_option_context_parse(context,argc,argv,&err)) ali@69: { ali@69: g_printerr("Bookloupe: %s\n",err->message); ali@69: g_printerr("Use \"%s --help\" for help\n",(*argv)[0]); ali@69: exit(1); ali@69: } ali@40: /* Paranoid checking is turned OFF, not on, by its switch */ ali@69: pswit[PARANOID_SWITCH]=!pswit[PARANOID_SWITCH]; ali@40: if (pswit[PARANOID_SWITCH]) ali@69: /* if running in paranoid mode, typo checks default to enabled */ ali@69: pswit[TYPO_SWITCH]=!pswit[TYPO_SWITCH]; ali@40: /* Line-end checking is turned OFF, not on, by its switch */ ali@69: pswit[LINE_END_SWITCH]=!pswit[LINE_END_SWITCH]; ali@40: /* Echoing is turned OFF, not on, by its switch */ ali@69: pswit[ECHO_SWITCH]=!pswit[ECHO_SWITCH]; ali@40: if (pswit[OVERVIEW_SWITCH]) ali@40: /* just print summary; don't echo */ ali@69: pswit[ECHO_SWITCH]=FALSE; ali@40: /* ali@40: * Web uploads - for the moment, this is really just a placeholder ali@40: * until we decide what processing we really want to do on web uploads ali@40: */ ali@40: if (pswit[WEB_SWITCH]) ali@40: { ali@40: /* specific override for web uploads */ ali@69: pswit[ECHO_SWITCH]=TRUE; ali@69: pswit[SQUOTE_SWITCH]=FALSE; ali@69: pswit[TYPO_SWITCH]=TRUE; ali@69: pswit[QPARA_SWITCH]=FALSE; ali@69: pswit[PARANOID_SWITCH]=TRUE; ali@69: pswit[LINE_END_SWITCH]=FALSE; ali@69: pswit[OVERVIEW_SWITCH]=FALSE; ali@69: pswit[STDOUT_SWITCH]=FALSE; ali@69: pswit[HEADER_SWITCH]=TRUE; ali@69: pswit[VERBOSE_SWITCH]=FALSE; ali@69: pswit[MARKUP_SWITCH]=FALSE; ali@69: pswit[USERTYPO_SWITCH]=FALSE; ali@69: pswit[DP_SWITCH]=FALSE; ali@40: } ali@69: if (*argc<2) ali@40: { ali@69: proghelp(context); ali@69: exit(1); ali@40: } ali@69: g_option_context_free(context); ali@69: } ali@69: ali@69: /* ali@69: * read_user_scannos: ali@69: * ali@69: * Read in the user-defined stealth scanno list. ali@69: */ ali@69: void read_user_scannos(void) ali@69: { ali@69: GError *err=NULL; ali@69: gchar *usertypo_file; ali@69: gboolean okay; ali@69: int i; ali@69: gsize len; ali@69: gchar *contents,**lines; ali@69: usertypo_file=g_strdup("bookloupe.typ"); ali@69: okay=file_get_contents_text(usertypo_file,&contents,&len,&err); ali@69: if (g_error_matches(err,G_FILE_ERROR,G_FILE_ERROR_NOENT)) ali@69: { ali@69: g_clear_error(&err); ali@69: g_free(usertypo_file); ali@69: usertypo_file=g_build_filename(running_from,"bookloupe.typ",NULL); ali@69: okay=file_get_contents_text(usertypo_file,&contents,&len,&err); ali@69: } ali@69: if (g_error_matches(err,G_FILE_ERROR,G_FILE_ERROR_NOENT)) ali@69: { ali@69: g_clear_error(&err); ali@69: g_free(usertypo_file); ali@69: usertypo_file=g_strdup("gutcheck.typ"); ali@69: okay=file_get_contents_text(usertypo_file,&contents,&len,&err); ali@69: } ali@69: if (g_error_matches(err,G_FILE_ERROR,G_FILE_ERROR_NOENT)) ali@69: { ali@69: g_clear_error(&err); ali@69: g_free(usertypo_file); ali@69: usertypo_file=g_build_filename(running_from,"gutcheck.typ",NULL); ali@69: okay=file_get_contents_text(usertypo_file,&contents,&len,&err); ali@69: } ali@69: if (g_error_matches(err,G_FILE_ERROR,G_FILE_ERROR_NOENT)) ali@69: { ali@69: g_free(usertypo_file); ali@69: printf(" --> I couldn't find bookloupe.typ " ali@69: "-- proceeding without user typos.\n"); ali@69: return; ali@69: } ali@69: else if (!okay) ali@69: { ali@69: fprintf(stderr,"%s: %s\n",usertypo_file,err->message); ali@69: g_free(usertypo_file); ali@69: g_clear_error(&err); ali@69: exit(1); ali@69: } ali@69: lines=g_strsplit(contents,"\n",0); ali@69: usertypo=g_tree_new_full((GCompareDataFunc)strcmp,NULL,g_free,NULL); ali@69: for (i=0;lines[i];i++) ali@69: if (*(unsigned char *)lines[i]>'!') ali@69: g_tree_insert(usertypo,lines[i],GINT_TO_POINTER(1)); ali@69: else ali@69: g_free(lines[i]); ali@69: g_free(lines); ali@69: } ali@69: ali@69: #if 0 ali@69: /* ali@69: * read_etext: ali@69: * ali@69: * Read an etext returning an array of lines. Lines are normally expected ali@69: * to be terminated by CR LF. Solitary LFs delimit lines but are left ali@69: * embedded at the end of the line for further processing. Solitary CRs ali@69: * do not delimit lines. ali@69: */ ali@69: gchar **read_etext(const char *filename,GError **err) ali@69: { ali@69: int i; ali@69: const char *s,*t; ali@69: gchar *contents; ali@69: gchar **raw_lines; ali@69: GPtrArray *lines; ali@69: gsize len; ali@69: if (!g_file_get_contents(filename,&contents,&len,err)) ali@69: return NULL; ali@69: raw_lines=g_strsplit(contents,"\r\n",0); ali@69: lines=g_ptr_array_sized_new(g_strv_length(raw_lines)+1); ali@69: for (i=0;raw_lines[i];i++) ali@69: { ali@69: t=strchr(raw_lines[i],'\n'); ali@69: if (t) ali@69: { ali@69: s=raw_lines[i]; ali@69: while ((t=strchr(s,'\n'))) ali@69: { ali@69: g_ptr_array_add(lines,g_strndup(s,t-s+1)); ali@69: s=t+1; ali@69: } ali@69: g_ptr_array_add(lines,g_strdup(s)); ali@69: g_free(raw_lines[i]); ali@69: } ali@69: else ali@69: g_ptr_array_add(lines,raw_lines[i]); ali@69: } ali@69: g_free(raw_lines); ali@69: g_ptr_array_add(lines,NULL); ali@69: return (gchar **)g_ptr_array_free(lines,FALSE); ali@69: } ali@69: #else ali@69: /* ali@69: * read_etext: ali@69: * ali@69: * Read an etext returning a newly allocated string containing the file ali@69: * contents or NULL on error. ali@69: */ ali@69: gchar *read_etext(const char *filename,GError **err) ali@69: { ali@69: gchar *contents; ali@69: gsize len; ali@69: if (!g_file_get_contents(filename,&contents,&len,err)) ali@69: return NULL; ali@69: return contents; ali@69: } ali@69: #endif ali@69: ali@69: int main(int argc,char **argv) ali@69: { ali@69: running_from=g_path_get_dirname(argv[0]); ali@69: parse_options(&argc,&argv); ali@40: if (pswit[USERTYPO_SWITCH]) ali@69: read_user_scannos(); ali@40: fprintf(stderr,"bookloupe: Check and report on an e-text\n"); ali@69: procfile(argv[1]); ali@40: if (pswit[OVERVIEW_SWITCH]) ali@40: { ali@40: printf(" Checked %ld lines of %ld (head+foot = %ld)\n\n", ali@40: checked_linecnt,linecnt,linecnt-checked_linecnt); ali@68: printf(" --------------- Queries found --------------\n"); ali@68: if (cnt_long) ali@68: printf(" Long lines: %14ld\n",cnt_long); ali@68: if (cnt_short) ali@68: printf(" Short lines: %14ld\n",cnt_short); ali@68: if (cnt_lineend) ali@68: printf(" Line-end problems: %14ld\n",cnt_lineend); ali@68: if (cnt_word) ali@68: printf(" Common typos: %14ld\n",cnt_word); ali@68: if (cnt_dquot) ali@68: printf(" Unmatched quotes: %14ld\n",cnt_dquot); ali@68: if (cnt_squot) ali@68: printf(" Unmatched SingleQuotes: %14ld\n",cnt_squot); ali@68: if (cnt_brack) ali@68: printf(" Unmatched brackets: %14ld\n",cnt_brack); ali@68: if (cnt_bin) ali@68: printf(" Non-ASCII characters: %14ld\n",cnt_bin); ali@68: if (cnt_odd) ali@68: printf(" Proofing characters: %14ld\n",cnt_odd); ali@68: if (cnt_punct) ali@40: printf(" Punctuation & spacing queries: %14ld\n",cnt_punct); ali@68: if (cnt_dash) ali@68: printf(" Non-standard dashes: %14ld\n",cnt_dash); ali@68: if (cnt_html) ali@68: printf(" Possible HTML tags: %14ld\n",cnt_html); ali@68: printf("\n"); ali@68: printf(" TOTAL QUERIES %14ld\n", ali@68: cnt_dquot+cnt_squot+cnt_brack+cnt_bin+cnt_odd+cnt_long+ ali@68: cnt_short+cnt_punct+cnt_dash+cnt_word+cnt_html+cnt_lineend); ali@40: } ali@69: g_free(running_from); ali@69: if (usertypo) ali@69: g_tree_unref(usertypo); ali@40: return 0; ali@0: } ali@0: ali@40: /* ali@41: * first_pass: ali@40: * ali@41: * Run a first pass - verify that it's a valid PG ali@41: * file, decide whether to report some things that ali@41: * occur many times in the text like long or short ali@41: * lines, non-standard dashes, etc. ali@40: */ ali@69: struct first_pass_results *first_pass(const char *etext) ali@0: { ali@54: char laststart=CHAR_SPACE; ali@54: const char *s; ali@69: gchar *lc_line; ali@69: int i,j,llen; ali@69: gchar **lines; ali@41: unsigned int lastlen=0,lastblen=0; ali@41: long spline=0,nspline=0; ali@41: static struct first_pass_results results={0}; ali@69: gchar *inword; ali@69: lines=g_strsplit(etext,"\n",0); ali@69: for (j=0;lines[j];j++) ali@40: { ali@69: llen=strlen(lines[j]); ali@69: while(lines[j][llen-1]=='\r') ali@69: lines[j][llen--]='\0'; ali@68: linecnt++; ali@69: if (strstr(lines[j],"*END") && strstr(lines[j],"SMALL PRINT") && ali@69: (strstr(lines[j],"PUBLIC DOMAIN") || strstr(lines[j],"COPYRIGHT"))) ali@40: { ali@68: if (spline) ali@68: printf(" --> Duplicate header?\n"); ali@68: spline=linecnt+1; /* first line of non-header text, that is */ ali@40: } ali@69: if (!strncmp(lines[j],"*** START",9) && ali@69: strstr(lines[j],"PROJECT GUTENBERG")) ali@40: { ali@68: if (nspline) ali@68: printf(" --> Duplicate header?\n"); ali@68: nspline=linecnt+1; /* first line of non-header text, that is */ ali@40: } ali@68: if (spline || nspline) ali@40: { ali@69: lc_line=g_ascii_strdown(lines[j],llen); ali@69: if (strstr(lc_line,"end") && strstr(lc_line,"project gutenberg")) ali@40: { ali@69: if (strstr(lc_line,"end") Duplicate footer?\n"); ali@40: } ali@68: else ali@68: results.footerline=linecnt; ali@40: } ali@40: } ali@69: g_free(lc_line); ali@40: } ali@68: if (spline) ali@41: results.firstline=spline; ali@68: if (nspline) ali@41: results.firstline=nspline; /* override with new */ ali@68: if (results.footerline) ali@40: continue; /* don't count the boilerplate in the footer */ ali@68: results.totlen+=llen; ali@68: for (i=0;i127) ali@41: results.binlen++; ali@69: if (gcisalpha(lines[j][i])) ali@41: results.alphalen++; ali@69: if (i>0 && lines[j][i]==CHAR_DQUOTE && isalpha(lines[j][i-1])) ali@41: results.endquote_count++; ali@40: } ali@69: if (llen>2 && lastlen>2 && lastlen2 && ali@69: lastblen>SHORTEST_PG_LINE && laststart!=CHAR_SPACE) ali@41: results.shortline++; ali@69: if (llen>0 && (unsigned char)lines[j][llen-1]<=CHAR_SPACE) ali@40: cnt_spacend++; ali@69: if (strstr(lines[j],".,")) ali@41: results.dotcomma++; ali@68: /* only count ast lines for ignoring purposes where there is */ ali@68: /* locase text on the line */ ali@69: if (strchr(lines[j],'*')) ali@40: { ali@69: for (s=lines[j];*s;s++) ali@68: if (*s>='a' && *s<='z') ali@68: break; ali@68: if (*s) ali@41: results.astline++; ali@40: } ali@69: if (strchr(lines[j],'/')) ali@68: results.fslashline++; ali@69: for (i=llen-1;i>0 && (unsigned char)lines[j][i]<=CHAR_SPACE;i--) ali@40: ; ali@69: if (i>1 && lines[j][i]=='-' && lines[j][i-1]!='-') ali@41: results.hyphens++; ali@68: if (llen>LONGEST_PG_LINE) ali@41: results.longline++; ali@68: if (llen>WAY_TOO_LONG) ali@41: results.verylongline++; ali@69: if (strchr(lines[j],'<') && strchr(lines[j],'>')) ali@40: { ali@69: i=(int)(strchr(lines[j],'>')-strchr(lines[j],'<')+1); ali@68: if (i>0) ali@68: results.htmcount++; ali@69: if (strstr(lines[j],"")) ali@41: results.htmcount+=4; /* bonus marks! */ ali@40: } ali@68: /* Check for spaced em-dashes */ ali@69: if (lines[j][0] && (s=strstr(lines[j]+1,"--"))) ali@40: { ali@68: results.emdash++; ali@69: if (s[-1]==CHAR_SPACE || (s[2]==CHAR_SPACE)) ali@41: results.space_emdash++; ali@69: if (s[-1]==CHAR_SPACE && (s[2]==CHAR_SPACE)) ali@40: /* count of em-dashes with spaces both sides */ ali@41: results.non_PG_space_emdash++; ali@69: if (s[-1]!=CHAR_SPACE && (s[2]!=CHAR_SPACE)) ali@40: /* count of PG-type em-dashes with no spaces */ ali@41: results.PG_space_emdash++; ali@40: } ali@69: for (s=lines[j];*s;) ali@40: { ali@69: inword=getaword(&s); ali@68: if (!strcmp(inword,"hij") || !strcmp(inword,"niet")) ali@68: results.Dutchcount++; ali@68: if (!strcmp(inword,"dans") || !strcmp(inword,"avec")) ali@68: results.Frenchcount++; ali@68: if (!strcmp(inword,"0") || !strcmp(inword,"1")) ali@68: results.standalone_digit++; ali@69: g_free(inword); ali@40: } ali@68: /* Check for spaced dashes */ ali@69: if (strstr(lines[j]," -") && *(strstr(lines[j]," -")+2)!='-') ali@41: results.spacedash++; ali@68: lastblen=lastlen; ali@69: lastlen=llen; ali@69: laststart=lines[j][0]; ali@40: } ali@69: g_strfreev(lines); ali@41: return &results; ali@41: } ali@41: ali@42: /* ali@42: * report_first_pass: ali@42: * ali@42: * Make some snap decisions based on the first pass results. ali@42: */ ali@42: struct warnings *report_first_pass(struct first_pass_results *results) ali@42: { ali@42: static struct warnings warnings={0}; ali@42: if (cnt_spacend>0) ali@68: printf(" --> %ld lines in this file have white space at end\n", ali@42: cnt_spacend); ali@42: warnings.dotcomma=1; ali@42: if (results->dotcomma>5) ali@42: { ali@68: warnings.dotcomma=0; ali@68: printf(" --> %ld lines in this file contain '.,'. " ali@42: "Not reporting them.\n",results->dotcomma); ali@42: } ali@42: /* ali@42: * If more than 50 lines, or one-tenth, are short, ali@42: * don't bother reporting them. ali@42: */ ali@42: warnings.shortline=1; ali@42: if (results->shortline>50 || results->shortline*10>linecnt) ali@42: { ali@68: warnings.shortline=0; ali@68: printf(" --> %ld lines in this file are short. " ali@42: "Not reporting short lines.\n",results->shortline); ali@42: } ali@42: /* ali@42: * If more than 50 lines, or one-tenth, are long, ali@42: * don't bother reporting them. ali@42: */ ali@42: warnings.longline=1; ali@42: if (results->longline>50 || results->longline*10>linecnt) ali@42: { ali@68: warnings.longline=0; ali@68: printf(" --> %ld lines in this file are long. " ali@42: "Not reporting long lines.\n",results->longline); ali@42: } ali@42: /* If more than 10 lines contain asterisks, don't bother reporting them. */ ali@42: warnings.ast=1; ali@42: if (results->astline>10) ali@42: { ali@68: warnings.ast=0; ali@68: printf(" --> %ld lines in this file contain asterisks. " ali@42: "Not reporting them.\n",results->astline); ali@42: } ali@42: /* ali@42: * If more than 10 lines contain forward slashes, ali@42: * don't bother reporting them. ali@42: */ ali@42: warnings.fslash=1; ali@42: if (results->fslashline>10) ali@42: { ali@68: warnings.fslash=0; ali@68: printf(" --> %ld lines in this file contain forward slashes. " ali@42: "Not reporting them.\n",results->fslashline); ali@42: } ali@42: /* ali@42: * If more than 20 lines contain unpunctuated endquotes, ali@42: * don't bother reporting them. ali@42: */ ali@42: warnings.endquote=1; ali@42: if (results->endquote_count>20) ali@42: { ali@68: warnings.endquote=0; ali@68: printf(" --> %ld lines in this file contain unpunctuated endquotes. " ali@42: "Not reporting them.\n",results->endquote_count); ali@42: } ali@42: /* ali@42: * If more than 15 lines contain standalone digits, ali@42: * don't bother reporting them. ali@42: */ ali@42: warnings.digit=1; ali@42: if (results->standalone_digit>10) ali@42: { ali@68: warnings.digit=0; ali@68: printf(" --> %ld lines in this file contain standalone 0s and 1s. " ali@42: "Not reporting them.\n",results->standalone_digit); ali@42: } ali@42: /* ali@42: * If more than 20 lines contain hyphens at end, ali@42: * don't bother reporting them. ali@42: */ ali@42: warnings.hyphen=1; ali@42: if (results->hyphens>20) ali@42: { ali@68: warnings.hyphen=0; ali@68: printf(" --> %ld lines in this file have hyphens at end. " ali@42: "Not reporting them.\n",results->hyphens); ali@42: } ali@42: if (results->htmcount>20 && !pswit[MARKUP_SWITCH]) ali@42: { ali@68: printf(" --> Looks like this is HTML. Switching HTML mode ON.\n"); ali@68: pswit[MARKUP_SWITCH]=1; ali@42: } ali@42: if (results->verylongline>0) ali@68: printf(" --> %ld lines in this file are VERY long!\n", ali@42: results->verylongline); ali@42: /* ali@42: * If there are more non-PG spaced dashes than PG em-dashes, ali@42: * assume it's deliberate. ali@42: * Current PG guidelines say don't use them, but older texts do, ali@42: * and some people insist on them whatever the guidelines say. ali@42: */ ali@42: warnings.dash=1; ali@42: if (results->spacedash+results->non_PG_space_emdash> ali@42: results->PG_space_emdash) ali@42: { ali@68: warnings.dash=0; ali@68: printf(" --> There are %ld spaced dashes and em-dashes. " ali@42: "Not reporting them.\n", ali@42: results->spacedash+results->non_PG_space_emdash); ali@42: } ali@42: /* If more than a quarter of characters are hi-bit, bug out. */ ali@42: warnings.bin=1; ali@42: if (results->binlen*4>results->totlen) ali@42: { ali@68: printf(" --> This file does not appear to be ASCII. " ali@42: "Terminating. Best of luck with it!\n"); ali@68: exit(1); ali@42: } ali@42: if (results->alphalen*4totlen) ali@42: { ali@68: printf(" --> This file does not appear to be text. " ali@42: "Terminating. Best of luck with it!\n"); ali@68: exit(1); ali@42: } ali@42: if (results->binlen*100>results->totlen || results->binlen>100) ali@42: { ali@68: printf(" --> There are a lot of foreign letters here. " ali@42: "Not reporting them.\n"); ali@68: warnings.bin=0; ali@42: } ali@69: warnings.isDutch=FALSE; ali@42: if (results->Dutchcount>50) ali@42: { ali@69: warnings.isDutch=TRUE; ali@68: printf(" --> This looks like Dutch - " ali@42: "switching off dashes and warnings for 's Middags case.\n"); ali@42: } ali@69: warnings.isFrench=FALSE; ali@42: if (results->Frenchcount>50) ali@42: { ali@69: warnings.isFrench=TRUE; ali@68: printf(" --> This looks like French - " ali@42: "switching off some doublepunct.\n"); ali@42: } ali@42: if (results->firstline && results->footerline) ali@68: printf(" The PG header and footer appear to be already on.\n"); ali@42: else ali@42: { ali@68: if (results->firstline) ali@68: printf(" The PG header is on - no footer.\n"); ali@68: if (results->footerline) ali@68: printf(" The PG footer is on - no header.\n"); ali@42: } ali@42: printf("\n"); ali@42: if (pswit[VERBOSE_SWITCH]) ali@42: { ali@68: warnings.bin=1; ali@68: warnings.shortline=1; ali@68: warnings.dotcomma=1; ali@68: warnings.longline=1; ali@68: warnings.dash=1; ali@68: warnings.digit=1; ali@68: warnings.ast=1; ali@68: warnings.fslash=1; ali@68: warnings.hyphen=1; ali@68: warnings.endquote=1; ali@68: printf(" *** Verbose output is ON -- you asked for it! ***\n"); ali@42: } ali@42: if (warnings.isDutch) ali@68: warnings.dash=0; ali@42: if (results->footerline>0 && results->firstline>0 && ali@42: results->footerline>results->firstline && ali@42: results->footerline-results->firstline<100) ali@42: { ali@68: printf(" --> I don't really know where this text starts. \n"); ali@68: printf(" There are no reference points.\n"); ali@68: printf(" I'm going to have to report the header and footer " ali@42: "as well.\n"); ali@68: results->firstline=0; ali@42: } ali@42: return &warnings; ali@42: } ali@42: ali@43: /* ali@43: * analyse_quotes: ali@43: * ali@43: * Look along the line, accumulate the count of quotes, and see ali@43: * if this is an empty line - i.e. a line with nothing on it ali@43: * but spaces. ali@43: * If line has just spaces, period, * and/or - on it, don't ali@43: * count it, since empty lines with asterisks or dashes to ali@43: * separate sections are common. ali@43: * ali@69: * Returns: TRUE if the line is empty. ali@43: */ ali@69: gboolean analyse_quotes(const char *aline,struct counters *counters) ali@43: { ali@68: int guessquote=0; ali@69: /* assume the line is empty until proven otherwise */ ali@69: gboolean isemptyline=TRUE; ali@69: const char *s=aline; ali@43: while (*s) ali@43: { ali@43: if (*s==CHAR_DQUOTE) ali@43: counters->quot++; ali@43: if (*s==CHAR_SQUOTE || *s==CHAR_OPEN_SQUOTE) ali@43: { ali@43: if (s==aline) ali@43: { ali@43: /* ali@43: * At start of line, it can only be an openquote. ali@43: * Hardcode a very common exception! ali@43: */ ali@43: if (strncmp(s+2,"tis",3) && strncmp(s+2,"Tis",3)) ali@43: counters->open_single_quote++; ali@43: } ali@43: else if (gcisalpha(s[-1]) && gcisalpha(s[1])) ali@43: /* Do nothing! it's definitely an apostrophe, not a quote */ ali@43: ; ali@43: /* it's outside a word - let's check it out */ ali@43: else if (*s==CHAR_OPEN_SQUOTE || gcisalpha(s[1])) ali@43: { ali@43: /* it damwell better BE an openquote */ ali@43: if (strncmp(s+1,"tis",3) && strncmp(s+1,"Tis",3)) ali@43: /* hardcode a very common exception! */ ali@43: counters->open_single_quote++; ali@43: } ali@43: else ali@43: { ali@43: /* now - is it a closequote? */ ali@43: guessquote=0; /* accumulate clues */ ali@43: if (gcisalpha(s[-1])) ali@43: { ali@43: /* it follows a letter - could be either */ ali@43: guessquote++; ali@43: if (s[-1]=='s') ali@43: { ali@43: /* looks like a plural apostrophe */ ali@43: guessquote-=3; ali@43: if (s[1]==CHAR_SPACE) /* bonus marks! */ ali@43: guessquote-=2; ali@43: } ali@43: } ali@43: /* it doesn't have a letter either side */ ali@43: else if (strchr(".?!,;:",s[-1]) && strchr(".?!,;: ",s[1])) ali@43: guessquote+=8; /* looks like a closequote */ ali@43: else ali@43: guessquote++; ali@43: if (counters->open_single_quote>counters->close_single_quote) ali@43: /* ali@43: * Give it the benefit of some doubt, ali@43: * if a squote is already open. ali@43: */ ali@43: guessquote++; ali@43: else ali@43: guessquote--; ali@43: if (guessquote>=0) ali@43: counters->close_single_quote++; ali@43: } ali@43: } ali@43: if (*s!=CHAR_SPACE && *s!='-' && *s!='.' && *s!=CHAR_ASTERISK && ali@43: *s!=13 && *s!=10) ali@69: isemptyline=FALSE; /* ignore lines like * * * as spacers */ ali@43: if (*s==CHAR_UNDERSCORE) ali@43: counters->c_unders++; ali@43: if (*s==CHAR_OPEN_CBRACK) ali@43: counters->c_brack++; ali@43: if (*s==CHAR_CLOSE_CBRACK) ali@43: counters->c_brack--; ali@43: if (*s==CHAR_OPEN_RBRACK) ali@43: counters->r_brack++; ali@43: if (*s==CHAR_CLOSE_RBRACK) ali@43: counters->r_brack--; ali@43: if (*s==CHAR_OPEN_SBRACK) ali@43: counters->s_brack++; ali@43: if (*s==CHAR_CLOSE_SBRACK) ali@43: counters->s_brack--; ali@43: s++; ali@43: } ali@43: return isemptyline; ali@43: } ali@43: ali@41: /* ali@67: * check_for_control_characters: ali@67: * ali@67: * Check for invalid or questionable characters in the line ali@67: * Anything above 127 is invalid for plain ASCII, and ali@67: * non-printable control characters should also be flagged. ali@67: * Tabs should generally not be there. ali@67: */ ali@67: void check_for_control_characters(const char *aline) ali@67: { ali@67: unsigned char c; ali@67: const char *s; ali@67: for (s=aline;*s;s++) ali@67: { ali@67: c=*(unsigned char *)s; ali@67: if (c127)) ali@44: { ali@44: if (pswit[ECHO_SWITCH]) ali@44: printf("\n%s\n",aline); ali@44: if (!pswit[OVERVIEW_SWITCH]) ali@44: if (c>127 && c<160) ali@44: printf(" Line %ld column %d - " ali@44: "Non-ISO-8859 character %d\n",linecnt,(int)(s-aline)+1,c); ali@44: else ali@44: printf(" Line %ld column %d - Non-ASCII character %d\n", ali@44: linecnt,(int)(s-aline)+1,c); ali@44: else ali@44: cnt_bin++; ali@44: eNon_A=1; ali@44: } ali@44: if (!eTab && *s==CHAR_TAB) ali@44: { ali@44: if (pswit[ECHO_SWITCH]) ali@44: printf("\n%s\n",aline); ali@44: if (!pswit[OVERVIEW_SWITCH]) ali@44: printf(" Line %ld column %d - Tab character?\n", ali@44: linecnt,(int)(s-aline)+1); ali@44: else ali@44: cnt_odd++; ali@44: eTab=1; ali@44: } ali@44: if (!eTilde && *s==CHAR_TILDE) ali@44: { ali@44: /* ali@44: * Often used by OCR software to indicate an ali@44: * unrecognizable character. ali@44: */ ali@44: if (pswit[ECHO_SWITCH]) ali@44: printf("\n%s\n",aline); ali@44: if (!pswit[OVERVIEW_SWITCH]) ali@44: printf(" Line %ld column %d - Tilde character?\n", ali@44: linecnt,(int)(s-aline)+1); ali@44: else ali@44: cnt_odd++; ali@44: eTilde=1; ali@44: } ali@44: if (!eCarat && *s==CHAR_CARAT) ali@44: { ali@44: if (pswit[ECHO_SWITCH]) ali@44: printf("\n%s\n",aline); ali@44: if (!pswit[OVERVIEW_SWITCH]) ali@44: printf(" Line %ld column %d - Carat character?\n", ali@44: linecnt,(int)(s-aline)+1); ali@44: else ali@44: cnt_odd++; ali@44: eCarat=1; ali@44: } ali@44: if (!eFSlash && *s==CHAR_FORESLASH && warnings->fslash) ali@44: { ali@44: if (pswit[ECHO_SWITCH]) ali@44: printf("\n%s\n",aline); ali@44: if (!pswit[OVERVIEW_SWITCH]) ali@44: printf(" Line %ld column %d - Forward slash?\n", ali@44: linecnt,(int)(s-aline)+1); ali@44: else ali@44: cnt_odd++; ali@44: eFSlash=1; ali@44: } ali@44: /* ali@44: * Report asterisks only in paranoid mode, ali@44: * since they're often deliberate. ali@44: */ ali@44: if (!eAst && pswit[PARANOID_SWITCH] && warnings->ast && !isemptyline && ali@44: *s==CHAR_ASTERISK) ali@44: { ali@44: if (pswit[ECHO_SWITCH]) ali@44: printf("\n%s\n",aline); ali@44: if (!pswit[OVERVIEW_SWITCH]) ali@44: printf(" Line %ld column %d - Asterisk?\n", ali@44: linecnt,(int)(s-aline)+1); ali@44: else ali@44: cnt_odd++; ali@44: eAst=1; ali@44: } ali@44: } ali@44: } ali@44: ali@44: /* ali@45: * check_for_long_line: ali@45: * ali@45: * Check for line too long. ali@45: */ ali@45: void check_for_long_line(const char *aline) ali@45: { ali@45: if (strlen(aline)>LONGEST_PG_LINE) ali@45: { ali@45: if (pswit[ECHO_SWITCH]) ali@45: printf("\n%s\n",aline); ali@45: if (!pswit[OVERVIEW_SWITCH]) ali@45: printf(" Line %ld column %d - Long line %d\n", ali@68: linecnt,(int)strlen(aline),(int)strlen(aline)); ali@45: else ali@45: cnt_long++; ali@45: } ali@45: } ali@45: ali@45: /* ali@45: * check_for_short_line: ali@45: * ali@45: * Check for line too short. ali@45: * ali@45: * This one is a bit trickier to implement: we don't want to ali@45: * flag the last line of a paragraph for being short, so we ali@45: * have to wait until we know that our current line is a ali@45: * "normal" line, then report the _previous_ line if it was too ali@45: * short. We also don't want to report indented lines like ali@45: * chapter heads or formatted quotations. We therefore keep ali@45: * last->len as the length of the last line examined, and ali@45: * last->blen as the length of the last but one, and try to ali@45: * suppress unnecessary warnings by checking that both were of ali@45: * "normal" length. We keep the first character of the last ali@45: * line in last->start, and if it was a space, we assume that ali@45: * the formatting is deliberate. I can't figure out a way to ali@45: * distinguish something like a quoted verse left-aligned or ali@45: * the header or footer of a letter from a paragraph of short ali@45: * lines - maybe if I examined the whole paragraph, and if the ali@45: * para has less than, say, 8 lines and if all lines are short, ali@45: * then just assume it's OK? Need to look at some texts to see ali@45: * how often a formula like this would get the right result. ali@45: */ ali@45: void check_for_short_line(const char *aline,const struct line_properties *last) ali@45: { ali@45: if (strlen(aline)>1 && last->len>1 && last->lenblen>1 && last->blen>SHORTEST_PG_LINE && last->start!=CHAR_SPACE) ali@45: { ali@45: if (pswit[ECHO_SWITCH]) ali@45: printf("\n%s\n",prevline); ali@45: if (!pswit[OVERVIEW_SWITCH]) ali@45: printf(" Line %ld column %d - Short line %d?\n", ali@68: linecnt-1,(int)strlen(prevline),(int)strlen(prevline)); ali@45: else ali@45: cnt_short++; ali@45: } ali@45: } ali@45: ali@45: /* ali@46: * check_for_starting_punctuation: ali@46: * ali@46: * Look for punctuation other than full ellipses at start of line. ali@46: */ ali@46: void check_for_starting_punctuation(const char *aline) ali@46: { ali@46: if (*aline && strchr(".?!,;:",aline[0]) && strncmp(". . .",aline,5)) ali@46: { ali@46: if (pswit[ECHO_SWITCH]) ali@46: printf("\n%s\n",aline); ali@46: if (!pswit[OVERVIEW_SWITCH]) ali@46: printf(" Line %ld column 1 - Begins with punctuation?\n", ali@46: linecnt); ali@46: else ali@46: cnt_punct++; ali@46: } ali@46: } ali@46: ali@46: /* ali@47: * check_for_spaced_emdash: ali@47: * ali@47: * Check for spaced em-dashes. ali@47: * ali@47: * We must check _all_ occurrences of "--" on the line ali@47: * hence the loop - even if the first double-dash is OK ali@47: * there may be another that's wrong later on. ali@47: */ ali@47: void check_for_spaced_emdash(const char *aline) ali@47: { ali@47: const char *s,*t; ali@47: s=aline; ali@47: while ((t=strstr(s,"--"))) ali@47: { ali@47: if (t>aline && t[-1]==CHAR_SPACE || t[2]==CHAR_SPACE) ali@47: { ali@47: if (pswit[ECHO_SWITCH]) ali@47: printf("\n%s\n",aline); ali@47: if (!pswit[OVERVIEW_SWITCH]) ali@47: printf(" Line %ld column %d - Spaced em-dash?\n", ali@47: linecnt,(int)(t-aline)+1); ali@47: else ali@47: cnt_dash++; ali@47: } ali@47: s=t+2; ali@47: } ali@47: } ali@47: ali@47: /* ali@47: * check_for_spaced_dash: ali@47: * ali@47: * Check for spaced dashes. ali@47: */ ali@47: void check_for_spaced_dash(const char *aline) ali@47: { ali@47: const char *s; ali@47: if ((s=strstr(aline," -"))) ali@47: { ali@47: if (s[2]!='-') ali@47: { ali@47: if (pswit[ECHO_SWITCH]) ali@47: printf("\n%s\n",aline); ali@47: if (!pswit[OVERVIEW_SWITCH]) ali@47: printf(" Line %ld column %d - Spaced dash?\n", ali@47: linecnt,(int)(s-aline)+1); ali@47: else ali@47: cnt_dash++; ali@47: } ali@47: } ali@47: else if ((s=strstr(aline,"- "))) ali@47: { ali@47: if (s==aline || s[-1]!='-') ali@47: { ali@47: if (pswit[ECHO_SWITCH]) ali@47: printf("\n%s\n",aline); ali@47: if (!pswit[OVERVIEW_SWITCH]) ali@47: printf(" Line %ld column %d - Spaced dash?\n", ali@47: linecnt,(int)(s-aline)+1); ali@47: else ali@47: cnt_dash++; ali@47: } ali@47: } ali@47: } ali@47: ali@47: /* ali@48: * check_for_unmarked_paragraphs: ali@48: * ali@48: * Check for unmarked paragraphs indicated by separate speakers. ali@48: * ali@48: * May well be false positive: ali@48: * "Bravo!" "Wonderful!" called the crowd. ali@48: * but useful all the same. ali@48: */ ali@48: void check_for_unmarked_paragraphs(const char *aline) ali@48: { ali@48: const char *s; ali@48: s=strstr(aline,"\" \""); ali@48: if (!s) ali@48: s=strstr(aline,"\" \""); ali@48: if (s) ali@48: { ali@48: if (pswit[ECHO_SWITCH]) ali@48: printf("\n%s\n",aline); ali@48: if (!pswit[OVERVIEW_SWITCH]) ali@48: printf(" Line %ld column %d - Query missing paragraph break?\n", ali@48: linecnt,(int)(s-aline)+1); ali@48: else ali@48: cnt_punct++; ali@48: } ali@48: } ali@48: ali@48: /* ali@49: * check_for_jeebies: ali@49: * ali@49: * Check for "to he" and other easy h/b errors. ali@49: * ali@49: * This is a very inadequate effort on the h/b problem, ali@49: * but the phrase "to he" is always an error, whereas "to ali@49: * be" is quite common. ali@49: * Similarly, '"Quiet!", be said.' is a non-be error ali@49: * "to he" is _not_ always an error!: ali@49: * "Where they went to he couldn't say." ali@49: * Another false positive: ali@49: * What would "Cinderella" be without the . . . ali@49: * and another: "If he wants to he can see for himself." ali@49: */ ali@49: void check_for_jeebies(const char *aline) ali@49: { ali@49: const char *s; ali@49: s=strstr(aline," be could "); ali@49: if (!s) ali@49: s=strstr(aline," be would "); ali@49: if (!s) ali@49: s=strstr(aline," was be "); ali@49: if (!s) ali@49: s=strstr(aline," be is "); ali@49: if (!s) ali@49: s=strstr(aline," is be "); ali@49: if (!s) ali@49: s=strstr(aline,"\", be "); ali@49: if (!s) ali@49: s=strstr(aline,"\" be "); ali@49: if (!s) ali@49: s=strstr(aline,"\" be "); ali@49: if (!s) ali@49: s=strstr(aline," to he "); ali@49: if (s) ali@49: { ali@49: if (pswit[ECHO_SWITCH]) ali@49: printf("\n%s\n",aline); ali@49: if (!pswit[OVERVIEW_SWITCH]) ali@49: printf(" Line %ld column %d - Query he/be error?\n", ali@49: linecnt,(int)(s-aline)+1); ali@49: else ali@49: cnt_word++; ali@49: } ali@49: s=strstr(aline," the had "); ali@49: if (!s) ali@49: s=strstr(aline," a had "); ali@49: if (!s) ali@49: s=strstr(aline," they bad "); ali@49: if (!s) ali@49: s=strstr(aline," she bad "); ali@49: if (!s) ali@49: s=strstr(aline," he bad "); ali@49: if (!s) ali@49: s=strstr(aline," you bad "); ali@49: if (!s) ali@49: s=strstr(aline," i bad "); ali@49: if (s) ali@49: { ali@49: if (pswit[ECHO_SWITCH]) ali@49: printf("\n%s\n",aline); ali@49: if (!pswit[OVERVIEW_SWITCH]) ali@49: printf(" Line %ld column %d - Query had/bad error?\n", ali@49: linecnt,(int)(s-aline)+1); ali@49: else ali@49: cnt_word++; ali@49: } ali@49: s=strstr(aline,"; hut "); ali@49: if (!s) ali@49: s=strstr(aline,", hut "); ali@49: if (s) ali@49: { ali@49: if (pswit[ECHO_SWITCH]) ali@49: printf("\n%s\n",aline); ali@49: if (!pswit[OVERVIEW_SWITCH]) ali@49: printf(" Line %ld column %d - Query hut/but error?\n", ali@49: linecnt,(int)(s-aline)+1); ali@49: else ali@49: cnt_word++; ali@49: } ali@49: } ali@49: ali@49: /* ali@50: * check_for_mta_from: ali@50: * ali@50: * Special case - angled bracket in front of "From" placed there by an ali@50: * MTA when sending an e-mail. ali@50: */ ali@50: void check_for_mta_from(const char *aline) ali@50: { ali@50: const char *s; ali@50: s=strstr(aline,">From"); ali@50: if (s) ali@50: { ali@50: if (pswit[ECHO_SWITCH]) ali@50: printf("\n%s\n",aline); ali@50: if (!pswit[OVERVIEW_SWITCH]) ali@50: printf(" Line %ld column %d - Query angled bracket with From\n", ali@50: linecnt,(int)(s-aline)+1); ali@50: else ali@50: cnt_punct++; ali@50: } ali@50: } ali@50: ali@50: /* ali@51: * check_for_orphan_character: ali@51: * ali@51: * Check for a single character line - ali@51: * often an overflow from bad wrapping. ali@51: */ ali@51: void check_for_orphan_character(const char *aline) ali@51: { ali@51: if (*aline && !aline[1]) ali@51: { ali@51: if (*aline=='I' || *aline=='V' || *aline=='X' || *aline=='L' || ali@51: gcisdigit(*aline)) ali@51: ; /* Nothing - ignore numerals alone on a line. */ ali@51: else ali@51: { ali@51: if (pswit[ECHO_SWITCH]) ali@51: printf("\n%s\n",aline); ali@51: if (!pswit[OVERVIEW_SWITCH]) ali@51: printf(" Line %ld column 1 - Query single character line\n", ali@51: linecnt); ali@51: else ali@51: cnt_punct++; ali@51: } ali@51: } ali@51: } ali@51: ali@51: /* ali@52: * check_for_pling_scanno: ali@52: * ali@52: * Check for I" - often should be ! ali@52: */ ali@52: void check_for_pling_scanno(const char *aline) ali@52: { ali@52: const char *s; ali@52: s=strstr(aline," I\""); ali@52: if (s) ali@52: { ali@52: if (pswit[ECHO_SWITCH]) ali@52: printf("\n%s\n",aline); ali@52: if (!pswit[OVERVIEW_SWITCH]) ali@52: printf(" Line %ld column %ld - Query I=exclamation mark?\n", ali@52: linecnt,s-aline); ali@52: else ali@52: cnt_punct++; ali@52: } ali@52: } ali@52: ali@52: /* ali@53: * check_for_extra_period: ali@53: * ali@53: * Check for period without a capital letter. Cut-down from gutspell. ali@53: * Only works when it happens on a single line. ali@53: */ ali@53: void check_for_extra_period(const char *aline,const struct warnings *warnings) ali@53: { ali@53: const char *s,*t,*s1; ali@69: int i; ali@69: gboolean istypo; ali@69: gchar *testword; ali@53: if (pswit[PARANOID_SWITCH]) ali@53: { ali@69: for (t=aline;strstr(t,". ");) ali@53: { ali@53: t=strstr(t,". "); ali@69: if (t==aline) ali@53: { ali@53: t++; ali@53: /* start of line punctuation is handled elsewhere */ ali@53: continue; ali@53: } ali@53: if (!gcisalpha(t[-1])) ali@53: { ali@53: t++; ali@53: continue; ali@53: } ali@53: if (warnings->isDutch) ali@53: { ali@53: /* For Frank & Jeroen -- 's Middags case */ ali@53: if (t[2]==CHAR_SQUOTE && t[3]>='a' && t[3]<='z' && ali@53: t[4]==CHAR_SPACE && t[5]>='A' && t[5]<='Z') ali@53: { ali@53: t++; ali@53: continue; ali@53: } ali@53: } ali@53: s1=t+2; ali@53: while (*s1 && !gcisalpha(*s1) && !isdigit(*s1)) ali@53: s1++; ali@53: if (*s1>='a' && *s1<='z') ali@53: { ali@53: /* we have something to investigate */ ali@69: istypo=TRUE; ali@53: /* so let's go back and find out */ ali@69: for (s1=t-1;s1>=aline && ali@53: (gcisalpha(*s1) || gcisdigit(*s1) || *s1==CHAR_SQUOTE && ali@53: gcisalpha(s1[1]) && gcisalpha(s1[-1]));s1--) ali@53: ; ali@53: s1++; ali@69: s=strchr(s1,'.'); ali@69: if (s) ali@69: testword=g_strndup(s1,s-s1); ali@69: else ali@69: testword=g_strdup(s1); ali@53: for (i=0;*abbrev[i];i++) ali@53: if (!strcmp(testword,abbrev[i])) ali@69: istypo=FALSE; ali@53: if (gcisdigit(*testword)) ali@69: istypo=FALSE; ali@53: if (!testword[1]) ali@69: istypo=FALSE; ali@53: if (isroman(testword)) ali@69: istypo=FALSE; ali@53: if (istypo) ali@53: { ali@69: istypo=FALSE; ali@53: for (i=0;testword[i];i++) ali@53: if (strchr(vowels,testword[i])) ali@69: istypo=TRUE; ali@53: } ali@69: if (istypo && ali@69: (pswit[VERBOSE_SWITCH] || !g_tree_lookup(qperiod,testword))) ali@53: { ali@69: g_tree_insert(qperiod,g_strdup(testword), ali@69: GINT_TO_POINTER(1)); ali@69: if (pswit[ECHO_SWITCH]) ali@69: printf("\n%s\n",aline); ali@69: if (!pswit[OVERVIEW_SWITCH]) ali@69: printf(" Line %ld column %d - Extra period?\n", ali@69: linecnt,(int)(t-aline)+1); ali@69: else ali@69: cnt_punct++; ali@53: } ali@69: g_free(testword); ali@53: } ali@53: t++; ali@53: } ali@53: } ali@53: } ali@53: ali@53: /* ali@54: * check_for_following_punctuation: ali@54: * ali@54: * Check for words usually not followed by punctuation. ali@54: */ ali@54: void check_for_following_punctuation(const char *aline) ali@54: { ali@54: int i; ali@54: const char *s,*wordstart; ali@69: gchar *inword,*t; ali@54: if (pswit[TYPO_SWITCH]) ali@54: { ali@54: for (s=aline;*s;) ali@54: { ali@54: wordstart=s; ali@69: t=getaword(&s); ali@69: if (!*t) ali@69: { ali@69: g_free(t); ali@54: continue; ali@69: } ali@69: inword=g_ascii_strdown(t,-1); ali@69: g_free(t); ali@54: for (i=0;*nocomma[i];i++) ali@54: if (!strcmp(inword,nocomma[i])) ali@54: { ali@54: if (*s==',' || *s==';' || *s==':') ali@54: { ali@54: if (pswit[ECHO_SWITCH]) ali@54: printf("\n%s\n",aline); ali@54: if (!pswit[OVERVIEW_SWITCH]) ali@54: printf(" Line %ld column %d - " ali@54: "Query punctuation after %s?\n", ali@54: linecnt,(int)(s-aline)+1,inword); ali@54: else ali@54: cnt_punct++; ali@54: } ali@54: } ali@54: for (i=0;*noperiod[i];i++) ali@54: if (!strcmp(inword,noperiod[i])) ali@54: { ali@54: if (*s=='.' || *s=='!') ali@54: { ali@54: if (pswit[ECHO_SWITCH]) ali@54: printf("\n%s\n",aline); ali@54: if (!pswit[OVERVIEW_SWITCH]) ali@54: printf(" Line %ld column %d - " ali@54: "Query punctuation after %s?\n", ali@54: linecnt,(int)(s-aline)+1,inword); ali@54: else ali@54: cnt_punct++; ali@54: } ali@54: } ali@69: g_free(inword); ali@54: } ali@54: } ali@54: } ali@54: ali@54: /* ali@55: * check_for_typos: ali@55: * ali@55: * Check for commonly mistyped words, ali@55: * and digits like 0 for O in a word. ali@55: */ ali@55: void check_for_typos(const char *aline,struct warnings *warnings) ali@55: { ali@55: const char *s,*wordstart; ali@69: gchar *inword,*testword; ali@69: int i,alower,vowel,consonant,*dupcnt; ali@69: gboolean isdup,istypo; ali@55: for (s=aline;*s;) ali@55: { ali@55: wordstart=s; ali@69: inword=getaword(&s); ali@55: if (!*inword) ali@69: { ali@69: g_free(inword); ali@55: continue; /* don't bother with empty lines */ ali@69: } ali@55: if (mixdigit(inword)) ali@55: { ali@55: if (pswit[ECHO_SWITCH]) ali@55: printf("\n%s\n",aline); ali@55: if (!pswit[OVERVIEW_SWITCH]) ali@55: printf(" Line %ld column %d - Query digit in %s\n", ali@55: linecnt,(int)(wordstart-aline)+1,inword); ali@55: else ali@55: cnt_word++; ali@55: } ali@55: /* ali@55: * Put the word through a series of tests for likely typos and OCR ali@55: * errors. ali@55: */ ali@69: if (pswit[TYPO_SWITCH] || pswit[USERTYPO_SWITCH]) ali@55: { ali@69: istypo=FALSE; ali@69: testword=g_strdup(inword); ali@55: alower=0; ali@68: for (i=0;i<(int)strlen(testword);i++) ali@55: { ali@55: /* lowercase for testing */ ali@55: if (testword[i]>='a' && testword[i]<='z') ali@55: alower=1; ali@55: if (alower && testword[i]>='A' && testword[i]<='Z') ali@55: { ali@55: /* ali@55: * We have an uppercase mid-word. However, there are ali@55: * common cases: ali@55: * Mac and Mc like McGill ali@55: * French contractions like l'Abbe ali@55: */ ali@55: if (i==2 && testword[0]=='m' && testword[1]=='c' || ali@55: i==3 && testword[0]=='m' && testword[1]=='a' && ali@55: testword[2]=='c' || i>0 && testword[i-1]==CHAR_SQUOTE) ali@55: ; /* do nothing! */ ali@55: else ali@69: istypo=TRUE; ali@55: } ali@55: testword[i]=(char)tolower(testword[i]); ali@55: } ali@69: } ali@69: if (pswit[TYPO_SWITCH]) ali@69: { ali@55: /* ali@55: * Check for certain unlikely two-letter combinations at word ali@55: * start and end. ali@55: */ ali@55: if (strlen(testword)>1) ali@55: { ali@55: for (i=0;*nostart[i];i++) ali@55: if (!strncmp(testword,nostart[i],2)) ali@69: istypo=TRUE; ali@55: for (i=0;*noend[i];i++) ali@55: if (!strncmp(testword+strlen(testword)-2,noend[i],2)) ali@69: istypo=TRUE; ali@55: } ali@55: /* ght is common, gbt never. Like that. */ ali@55: if (strstr(testword,"cb")) ali@69: istypo=TRUE; ali@55: if (strstr(testword,"gbt")) ali@69: istypo=TRUE; ali@55: if (strstr(testword,"pbt")) ali@69: istypo=TRUE; ali@55: if (strstr(testword,"tbs")) ali@69: istypo=TRUE; ali@55: if (strstr(testword,"mrn")) ali@69: istypo=TRUE; ali@55: if (strstr(testword,"ahle")) ali@69: istypo=TRUE; ali@55: if (strstr(testword,"ihle")) ali@69: istypo=TRUE; ali@55: /* ali@55: * "TBE" does happen - like HEARTBEAT - but uncommon. ali@55: * Also "TBI" - frostbite, outbid - but uncommon. ali@55: * Similarly "ii" like Hawaii, or Pompeii, and in Roman ali@55: * numerals, but "ii" is a common scanno. ali@55: */ ali@55: if (strstr(testword,"tbi")) ali@69: istypo=TRUE; ali@55: if (strstr(testword,"tbe")) ali@69: istypo=TRUE; ali@55: if (strstr(testword,"ii")) ali@69: istypo=TRUE; ali@55: /* ali@55: * Check for no vowels or no consonants. ali@55: * If none, flag a typo. ali@55: */ ali@55: if (!istypo && strlen(testword)>1) ali@55: { ali@55: vowel=consonant=0; ali@55: for (i=0;testword[i];i++) ali@55: { ali@55: if (testword[i]=='y' || gcisdigit(testword[i])) ali@55: { ali@55: /* Yah, this is loose. */ ali@55: vowel++; ali@55: consonant++; ali@55: } ali@55: else if (strchr(vowels,testword[i])) ali@55: vowel++; ali@55: else ali@55: consonant++; ali@55: } ali@55: if (!vowel || !consonant) ali@69: istypo=TRUE; ali@55: } ali@55: /* ali@55: * Now exclude the word from being reported if it's in ali@55: * the okword list. ali@55: */ ali@55: for (i=0;*okword[i];i++) ali@55: if (!strcmp(testword,okword[i])) ali@69: istypo=FALSE; ali@55: /* ali@55: * What looks like a typo may be a Roman numeral. ali@55: * Exclude these. ali@55: */ ali@55: if (istypo && isroman(testword)) ali@69: istypo=FALSE; ali@55: /* Check the manual list of typos. */ ali@55: if (!istypo) ali@55: for (i=0;*typo[i];i++) ali@55: if (!strcmp(testword,typo[i])) ali@69: istypo=TRUE; ali@55: /* ali@55: * Check lowercase s, l, i and m - special cases. ali@55: * "j" - often a semi-colon gone wrong. ali@55: * "d" for a missing apostrophe - he d ali@55: * "n" for "in" ali@55: */ ali@55: if (!istypo && strlen(testword)==1 && strchr("slmijdn",*inword)) ali@69: istypo=TRUE; ali@55: if (istypo) ali@55: { ali@69: dupcnt=g_tree_lookup(qword,testword); ali@69: if (dupcnt) ali@69: { ali@69: (*dupcnt)++; ali@69: isdup=!pswit[VERBOSE_SWITCH]; ali@69: } ali@69: else ali@69: { ali@69: dupcnt=g_new0(int,1); ali@69: g_tree_insert(qword,g_strdup(testword),dupcnt); ali@69: isdup=FALSE; ali@69: } ali@55: if (!isdup) ali@55: { ali@55: if (pswit[ECHO_SWITCH]) ali@55: printf("\n%s\n",aline); ali@55: if (!pswit[OVERVIEW_SWITCH]) ali@55: { ali@55: printf(" Line %ld column %d - Query word %s", ali@55: linecnt,(int)(wordstart-aline)+1,inword); ali@69: if (!pswit[VERBOSE_SWITCH]) ali@55: printf(" - not reporting duplicates"); ali@55: printf("\n"); ali@55: } ali@55: else ali@55: cnt_word++; ali@55: } ali@55: } ali@55: } ali@55: /* check the user's list of typos */ ali@69: if (!istypo && usertypo && g_tree_lookup(usertypo,testword)) ali@69: { ali@69: if (pswit[ECHO_SWITCH]) ali@69: printf("\n%s\n",aline); ali@69: if (!pswit[OVERVIEW_SWITCH]) ali@69: printf(" Line %ld column %d - Query possible scanno %s\n", ali@69: linecnt,(int)(wordstart-aline)+2,inword); ali@69: } ali@69: if (pswit[TYPO_SWITCH] || pswit[USERTYPO_SWITCH]) ali@69: g_free(testword); ali@55: if (pswit[PARANOID_SWITCH] && warnings->digit) ali@55: { ali@55: /* In paranoid mode, query all 0 and 1 standing alone. */ ali@55: if (!strcmp(inword,"0") || !strcmp(inword,"1")) ali@55: { ali@55: if (pswit[ECHO_SWITCH]) ali@55: printf("\n%s\n",aline); ali@55: if (!pswit[OVERVIEW_SWITCH]) ali@55: printf(" Line %ld column %d - Query standalone %s\n", ali@55: linecnt,(int)(wordstart-aline)+2,inword); ali@55: else ali@55: cnt_word++; ali@55: } ali@55: } ali@69: g_free(inword); ali@55: } ali@55: } ali@55: ali@56: /* ali@56: * check_for_misspaced_punctuation: ali@56: * ali@56: * Look for added or missing spaces around punctuation and quotes. ali@56: * If there is a punctuation character like ! with no space on ali@56: * either side, suspect a missing!space. If there are spaces on ali@56: * both sides , assume a typo. If we see a double quote with no ali@56: * space or punctuation on either side of it, assume unspaced ali@56: * quotes "like"this. ali@56: */ ali@56: void check_for_misspaced_punctuation(const char *aline, ali@69: struct parities *parities,gboolean isemptyline) ali@56: { ali@69: int i,llen; ali@69: gboolean isacro,isellipsis; ali@56: const char *s; ali@56: llen=strlen(aline); ali@56: for (i=1;i2 && aline[i-2]=='.') ali@69: isacro=TRUE; ali@56: if (i+22 && aline[i-2]=='.') ali@69: isellipsis=TRUE; ali@56: if (i+2dquote=!parities->dquote; ali@56: if (!parities->dquote) ali@56: { ali@56: /* parity even */ ali@56: if (!strchr("_-.'`/,;:!?)]} ",s[1])) ali@56: { ali@56: if (pswit[ECHO_SWITCH]) ali@56: printf("\n%s\n",aline); ali@56: if (!pswit[OVERVIEW_SWITCH]) ali@56: printf(" Line %ld column %d - " ali@56: "Wrongspaced quotes?\n",linecnt,(int)(s-aline)+1); ali@56: else ali@56: cnt_punct++; ali@56: } ali@56: } ali@56: else ali@56: { ali@56: /* parity odd */ ali@56: if (!gcisalpha(s[1]) && !isdigit(s[1]) && ali@56: !strchr("_-/.'`([{$",s[1]) || !s[1]) ali@56: { ali@56: if (pswit[ECHO_SWITCH]) ali@56: printf("\n%s\n",aline); ali@56: if (!pswit[OVERVIEW_SWITCH]) ali@56: printf(" Line %ld column %d - " ali@56: "Wrongspaced quotes?\n",linecnt,(int)(s-aline)+1); ali@56: else ali@56: cnt_punct++; ali@56: } ali@56: } ali@56: } ali@56: } ali@56: if (*aline==CHAR_DQUOTE) ali@56: { ali@56: if (strchr(",;:!?)]} ",aline[1])) ali@56: { ali@56: if (pswit[ECHO_SWITCH]) ali@56: printf("\n%s\n",aline); ali@56: if (!pswit[OVERVIEW_SWITCH]) ali@56: printf(" Line %ld column 1 - Wrongspaced quotes?\n", ali@56: linecnt); ali@56: else ali@56: cnt_punct++; ali@56: } ali@56: } ali@56: if (pswit[SQUOTE_SWITCH]) ali@56: { ali@56: for (s=aline;*s;s++) ali@56: { ali@56: if ((*s==CHAR_SQUOTE || *s==CHAR_OPEN_SQUOTE) && ali@56: (s==aline || s>aline && !gcisalpha(s[-1]) || ali@56: !gcisalpha(s[1]))) ali@56: { ali@56: parities->squote=!parities->squote; ali@56: if (!parities->squote) ali@56: { ali@56: /* parity even */ ali@56: if (!strchr("_-.'`/\",;:!?)]} ",s[1])) ali@56: { ali@56: if (pswit[ECHO_SWITCH]) ali@56: printf("\n%s\n",aline); ali@56: if (!pswit[OVERVIEW_SWITCH]) ali@56: printf(" Line %ld column %d - " ali@56: "Wrongspaced singlequotes?\n", ali@56: linecnt,(int)(s-aline)+1); ali@56: else ali@56: cnt_punct++; ali@56: } ali@56: } ali@56: else ali@56: { ali@56: /* parity odd */ ali@56: if (!gcisalpha(s[1]) && !isdigit(s[1]) && ali@56: !strchr("_-/\".'`",s[1]) || !s[1]) ali@56: { ali@56: if (pswit[ECHO_SWITCH]) ali@56: printf("\n%s\n",aline); ali@56: if (!pswit[OVERVIEW_SWITCH]) ali@56: printf(" Line %ld column %d - " ali@56: "Wrongspaced singlequotes?\n", ali@56: linecnt,(int)(s-aline)+1); ali@56: else ali@56: cnt_punct++; ali@56: } ali@56: } ali@56: } ali@56: } ali@56: } ali@56: } ali@56: ali@55: /* ali@57: * check_for_double_punctuation: ali@57: * ali@57: * Look for double punctuation like ,. or ,, ali@57: * Thanks to DW for the suggestion! ali@57: * In books with references, ".," and ".;" are common ali@57: * e.g. "etc., etc.," and vol. 1.; vol 3.; ali@57: * OTOH, from my initial tests, there are also fairly ali@57: * common errors. What to do? Make these cases paranoid? ali@57: * ".," is the most common, so warnings->dotcomma is used ali@57: * to suppress detailed reporting if it occurs often. ali@57: */ ali@57: void check_for_double_punctuation(const char *aline,struct warnings *warnings) ali@57: { ali@57: int i,llen; ali@57: llen=strlen(aline); ali@57: for (i=0;idotcomma && aline[i]=='.' && aline[i+1]==',' || ali@57: warnings->isFrench && !strncmp(aline+i,",...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...,",4) || ali@57: warnings->isFrench && !strncmp(aline+i,";...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...;",4) || ali@57: warnings->isFrench && !strncmp(aline+i,":...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...:",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"!...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...!",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"?...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...?",4)) ali@57: { ali@57: if (warnings->isFrench && !strncmp(aline+i,",...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...,",4) || ali@57: warnings->isFrench && !strncmp(aline+i,";...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...;",4) || ali@57: warnings->isFrench && !strncmp(aline+i,":...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...:",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"!...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...!",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"?...",4) || ali@57: warnings->isFrench && !strncmp(aline+i,"...?",4)) ali@57: i+=4; ali@57: ; /* do nothing for .. !! and ?? which can be legit */ ali@57: } ali@57: else ali@57: { ali@57: if (pswit[ECHO_SWITCH]) ali@57: printf("\n%s\n",aline); ali@57: if (!pswit[OVERVIEW_SWITCH]) ali@57: printf(" Line %ld column %d - Double punctuation?\n", ali@57: linecnt,i+1); ali@57: else ali@57: cnt_punct++; ali@57: } ali@57: } ali@57: } ali@57: } ali@57: ali@57: /* ali@58: * check_for_spaced_quotes: ali@58: */ ali@58: void check_for_spaced_quotes(const char *aline) ali@58: { ali@58: const char *s,*t; ali@58: s=aline; ali@58: while ((t=strstr(s," \" "))) ali@58: { ali@58: if (pswit[ECHO_SWITCH]) ali@58: printf("\n%s\n",aline); ali@58: if (!pswit[OVERVIEW_SWITCH]) ali@58: printf(" Line %ld column %d - Spaced doublequote?\n", ali@58: linecnt,(int)(t-aline+1)); ali@58: else ali@58: cnt_punct++; ali@58: s=t+2; ali@58: } ali@58: s=aline; ali@58: while ((t=strstr(s," ' "))) ali@58: { ali@58: if (pswit[ECHO_SWITCH]) ali@58: printf("\n%s\n",aline); ali@58: if (!pswit[OVERVIEW_SWITCH]) ali@58: printf(" Line %ld column %d - Spaced singlequote?\n", ali@58: linecnt,(int)(t-aline+1)); ali@58: else ali@58: cnt_punct++; ali@58: s=t+2; ali@58: } ali@58: s=aline; ali@58: while ((t=strstr(s," ` "))) ali@58: { ali@58: if (pswit[ECHO_SWITCH]) ali@58: printf("\n%s\n",aline); ali@58: if (!pswit[OVERVIEW_SWITCH]) ali@58: printf(" Line %ld column %d - Spaced singlequote?\n", ali@58: linecnt,(int)(t-aline+1)); ali@58: else ali@58: cnt_punct++; ali@58: s=t+2; ali@58: } ali@58: } ali@58: ali@58: /* ali@59: * check_for_miscased_genative: ali@59: * ali@59: * Check special case of 'S instead of 's at end of word. ali@59: */ ali@59: void check_for_miscased_genative(const char *aline) ali@59: { ali@59: const char *s; ali@69: if (!*aline) ali@69: return; ali@59: s=aline+1; ali@59: while (*s) ali@59: { ali@59: if (*s==CHAR_SQUOTE && s[1]=='S' && s[-1]>='a' && s[-1]<='z') ali@59: { ali@59: if (pswit[ECHO_SWITCH]) ali@59: printf("\n%s\n",aline); ali@59: if (!pswit[OVERVIEW_SWITCH]) ali@59: printf(" Line %ld column %d - Capital \"S\"?\n", ali@59: linecnt,(int)(s-aline+2)); ali@59: else ali@59: cnt_punct++; ali@59: } ali@59: s++; ali@59: } ali@59: } ali@59: ali@59: /* ali@60: * check_end_of_line: ali@60: * ali@60: * Now check special cases - start and end of line - ali@60: * for single and double quotes. Start is sometimes [sic] ali@60: * but better to query it anyway. ali@60: * While we're here, check for dash at end of line. ali@60: */ ali@60: void check_end_of_line(const char *aline,struct warnings *warnings) ali@60: { ali@60: int i,llen; ali@60: llen=strlen(aline); ali@60: if (llen>1) ali@60: { ali@60: if (aline[llen-1]==CHAR_DQUOTE || aline[llen-1]==CHAR_SQUOTE || ali@60: aline[llen-1]==CHAR_OPEN_SQUOTE) ali@60: if (aline[llen-2]==CHAR_SPACE) ali@60: { ali@60: if (pswit[ECHO_SWITCH]) ali@60: printf("\n%s\n",aline); ali@60: if (!pswit[OVERVIEW_SWITCH]) ali@60: printf(" Line %ld column %d - Spaced quote?\n", ali@60: linecnt,llen); ali@60: else ali@60: cnt_punct++; ali@60: } ali@60: if ((aline[0]==CHAR_SQUOTE || aline[0]==CHAR_OPEN_SQUOTE) && ali@60: aline[1]==CHAR_SPACE) ali@60: { ali@60: if (pswit[ECHO_SWITCH]) ali@60: printf("\n%s\n",aline); ali@60: if (!pswit[OVERVIEW_SWITCH]) ali@60: printf(" Line %ld column 1 - Spaced quote?\n",linecnt); ali@60: else ali@60: cnt_punct++; ali@60: } ali@60: /* ali@60: * Dash at end of line may well be legit - paranoid mode only ali@60: * and don't report em-dash at line-end. ali@60: */ ali@60: if (pswit[PARANOID_SWITCH] && warnings->hyphen) ali@60: { ali@60: for (i=llen-1;i>0 && (unsigned char)aline[i]<=CHAR_SPACE;i--) ali@60: ; ali@60: if (aline[i]=='-' && aline[i-1]!='-') ali@60: { ali@60: if (pswit[ECHO_SWITCH]) ali@60: printf("\n%s\n",aline); ali@60: if (!pswit[OVERVIEW_SWITCH]) ali@60: printf(" Line %ld column %d - Hyphen at end of line?\n", ali@60: linecnt,i); ali@60: } ali@60: } ali@60: } ali@60: } ali@60: ali@60: /* ali@61: * check_for_unspaced_bracket: ali@61: * ali@61: * Brackets are often unspaced, but shouldn't be surrounded by alpha. ali@61: * If so, suspect a scanno like "a]most". ali@61: */ ali@61: void check_for_unspaced_bracket(const char *aline) ali@61: { ali@61: int i,llen; ali@61: llen=strlen(aline); ali@61: for (i=1;i. ali@63: * ali@63: * If there is a < in the line, followed at some point ali@63: * by a > then we suspect HTML. ali@63: */ ali@63: void check_for_html_tag(const char *aline) ali@63: { ali@63: int i; ali@63: const char *open,*close; ali@63: open=strstr(aline,"<"); ali@63: if (open) ali@63: { ali@63: close=strstr(aline,">"); ali@63: if (close) ali@63: { ali@68: i=(int)(close-open+1); ali@63: if (i>0) ali@63: { ali@63: if (pswit[ECHO_SWITCH]) ali@63: printf("\n%s\n",aline); ali@63: if (!pswit[OVERVIEW_SWITCH]) ali@69: printf(" Line %ld column %d - HTML Tag? %*.*s \n", ali@69: linecnt,(int)(open-aline)+1,i,i,open); ali@63: else ali@63: cnt_html++; ali@63: } ali@63: } ali@63: } ali@63: } ali@63: ali@63: /* ali@64: * check_for_html_entity: ali@64: * ali@64: * Check for &symbol; HTML. ali@64: * ali@64: * If there is a & in the line, followed at ali@64: * some point by a ; then we suspect HTML. ali@64: */ ali@64: void check_for_html_entity(const char *aline) ali@64: { ali@64: int i; ali@64: const char *s,*amp,*scolon; ali@64: amp=strstr(aline,"&"); ali@64: if (amp) ali@64: { ali@64: scolon=strstr(aline,";"); ali@64: if (scolon) ali@64: { ali@64: i=(int)(scolon-amp+1); ali@64: for (s=amp;s0) ali@64: { ali@64: if (pswit[ECHO_SWITCH]) ali@64: printf("\n%s\n",aline); ali@64: if (!pswit[OVERVIEW_SWITCH]) ali@69: printf(" Line %ld column %d - HTML symbol? %*.*s \n", ali@69: linecnt,(int)(amp-aline)+1,i,i,amp); ali@64: else ali@64: cnt_html++; ali@64: } ali@64: } ali@64: } ali@64: } ali@64: ali@65: /* ali@65: * print_pending: ali@65: * ali@65: * If we are in a state of unbalanced quotes, and this line ali@65: * doesn't begin with a quote, output the stored error message. ali@65: * If the -P switch was used, print the warning even if the ali@65: * new para starts with quotes. ali@65: */ ali@65: void print_pending(const char *aline,const char *parastart, ali@65: struct pending *pending) ali@65: { ali@65: const char *s; ali@65: s=aline; ali@65: while (*s==' ') ali@65: s++; ali@69: if (pending->dquote) ali@69: { ali@65: if (*s!=CHAR_DQUOTE || pswit[QPARA_SWITCH]) ali@65: { ali@65: if (!pswit[OVERVIEW_SWITCH]) ali@65: { ali@65: if (pswit[ECHO_SWITCH]) ali@65: printf("\n%s\n",parastart); ali@65: puts(pending->dquote); ali@65: } ali@65: else ali@65: cnt_dquot++; ali@65: } ali@69: g_free(pending->dquote); ali@69: pending->dquote=NULL; ali@69: } ali@69: if (pending->squote) ali@65: { ali@65: if (*s!=CHAR_SQUOTE && *s!=CHAR_OPEN_SQUOTE || pswit[QPARA_SWITCH] || ali@65: pending->squot) ali@65: { ali@65: if (!pswit[OVERVIEW_SWITCH]) ali@65: { ali@65: if (pswit[ECHO_SWITCH]) ali@65: printf("\n%s\n",parastart); ali@65: puts(pending->squote); ali@65: } ali@65: else ali@65: cnt_squot++; ali@65: } ali@69: g_free(pending->squote); ali@69: pending->squote=NULL; ali@65: } ali@69: if (pending->rbrack) ali@65: { ali@65: if (!pswit[OVERVIEW_SWITCH]) ali@65: { ali@65: if (pswit[ECHO_SWITCH]) ali@65: printf("\n%s\n",parastart); ali@65: puts(pending->rbrack); ali@65: } ali@65: else ali@65: cnt_brack++; ali@69: g_free(pending->rbrack); ali@69: pending->rbrack=NULL; ali@65: } ali@69: if (pending->sbrack) ali@65: { ali@65: if (!pswit[OVERVIEW_SWITCH]) ali@65: { ali@65: if (pswit[ECHO_SWITCH]) ali@65: printf("\n%s\n",parastart); ali@65: puts(pending->sbrack); ali@65: } ali@65: else ali@65: cnt_brack++; ali@69: g_free(pending->sbrack); ali@69: pending->sbrack=NULL; ali@65: } ali@69: if (pending->cbrack) ali@65: { ali@65: if (!pswit[OVERVIEW_SWITCH]) ali@65: { ali@65: if (pswit[ECHO_SWITCH]) ali@65: printf("\n%s\n",parastart); ali@65: puts(pending->cbrack); ali@65: } ali@65: else ali@65: cnt_brack++; ali@69: g_free(pending->cbrack); ali@69: pending->cbrack=NULL; ali@65: } ali@69: if (pending->unders) ali@65: { ali@65: if (!pswit[OVERVIEW_SWITCH]) ali@65: { ali@65: if (pswit[ECHO_SWITCH]) ali@65: printf("\n%s\n",parastart); ali@65: puts(pending->unders); ali@65: } ali@65: else ali@65: cnt_brack++; ali@69: g_free(pending->unders); ali@69: pending->unders=NULL; ali@65: } ali@65: } ali@65: ali@65: /* ali@65: * check_for_mismatched_quotes: ali@65: * ali@65: * At end of paragraph, check for mismatched quotes. ali@65: * ali@65: * We don't want to report an error immediately, since it is a ali@65: * common convention to omit the quotes at end of paragraph if ali@65: * the next paragraph is a continuation of the same speaker. ali@65: * Where this is the case, the next para should begin with a ali@65: * quote, so we store the warning message and only display it ali@65: * at the top of the next iteration if the new para doesn't ali@65: * start with a quote. ali@65: * The -p switch overrides this default, and warns of unclosed ali@65: * quotes on _every_ paragraph, whether the next begins with a ali@65: * quote or not. ali@65: */ ali@65: void check_for_mismatched_quotes(const struct counters *counters, ali@65: struct pending *pending) ali@65: { ali@65: if (counters->quot%2) ali@69: pending->dquote= ali@69: g_strdup_printf(" Line %ld - Mismatched quotes",linecnt); ali@65: if (pswit[SQUOTE_SWITCH] && counters->open_single_quote && ali@65: counters->open_single_quote!=counters->close_single_quote) ali@69: pending->squote= ali@69: g_strdup_printf(" Line %ld - Mismatched singlequotes?",linecnt); ali@65: if (pswit[SQUOTE_SWITCH] && counters->open_single_quote && ali@65: counters->open_single_quote!=counters->close_single_quote && ali@65: counters->open_single_quote!=counters->close_single_quote+1) ali@65: /* ali@65: * Flag it to be noted regardless of the ali@65: * first char of the next para. ali@65: */ ali@65: pending->squot=1; ali@65: if (counters->r_brack) ali@69: pending->rbrack= ali@69: g_strdup_printf(" Line %ld - Mismatched round brackets?",linecnt); ali@65: if (counters->s_brack) ali@69: pending->sbrack= ali@69: g_strdup_printf(" Line %ld - Mismatched square brackets?",linecnt); ali@65: if (counters->c_brack) ali@69: pending->cbrack= ali@69: g_strdup_printf(" Line %ld - Mismatched curly brackets?",linecnt); ali@65: if (counters->c_unders%2) ali@69: pending->unders= ali@69: g_strdup_printf(" Line %ld - Mismatched underscores?",linecnt); ali@65: } ali@65: ali@64: /* ali@66: * check_for_omitted_punctuation: ali@66: * ali@66: * Check for omitted punctuation at end of paragraph by working back ali@66: * through prevline. DW. ali@66: * Need to check this only for "normal" paras. ali@66: * So what is a "normal" para? ali@66: * Not normal if one-liner (chapter headings, etc.) ali@66: * Not normal if doesn't contain at least one locase letter ali@66: * Not normal if starts with space ali@66: */ ali@66: void check_for_omitted_punctuation(const char *prevline, ali@66: struct line_properties *last,int start_para_line) ali@66: { ali@66: int i; ali@66: const char *s; ali@66: for (s=prevline,i=0;*s && !i;s++) ali@66: if (gcisletter(*s)) ali@66: /* use i to indicate the presence of a letter on the line */ ali@66: i=1; ali@66: /* ali@66: * This next "if" is a problem. ali@66: * If we say "start_para_line <= linecnt - 1", that includes ali@66: * one-line "paragraphs" like chapter heads. Lotsa false positives. ali@66: * If we say "start_para_line < linecnt - 1" it doesn't, but then it ali@66: * misses genuine one-line paragraphs. ali@66: */ ali@66: if (i && last->blen>2 && start_para_lineCHAR_SPACE) ali@66: { ali@66: for (i=strlen(prevline)-1; ali@66: (prevline[i]==CHAR_DQUOTE || prevline[i]==CHAR_SQUOTE) && ali@66: prevline[i]>CHAR_SPACE && i>0; ali@66: i--) ali@66: ; ali@66: for (;i>0;i--) ali@66: { ali@66: if (gcisalpha(prevline[i])) ali@66: { ali@66: if (pswit[ECHO_SWITCH]) ali@66: printf("\n%s\n",prevline); ali@66: if (!pswit[OVERVIEW_SWITCH]) ali@66: printf(" Line %ld column %d - " ali@66: "No punctuation at para end?\n", ali@68: linecnt-1,(int)strlen(prevline)); ali@66: else ali@66: cnt_punct++; ali@66: break; ali@66: } ali@66: if (strchr("-.:!([{?}])",prevline[i])) ali@66: break; ali@66: } ali@66: } ali@66: } ali@66: ali@69: gboolean report_duplicate_queries(gpointer key,gpointer value,gpointer data) ali@69: { ali@69: const char *word=key; ali@69: int *dupcnt=value; ali@69: if (*dupcnt) ali@69: printf("\nNote: Queried word %s was duplicated %d times\n", ali@69: word,*dupcnt); ali@69: return FALSE; ali@69: } ali@69: ali@66: /* ali@41: * procfile: ali@41: * ali@41: * Process one file. ali@41: */ ali@69: void procfile(const char *filename) ali@41: { ali@65: const char *s; ali@69: gchar *parastart=NULL; /* first line of current para */ ali@69: gchar *etext,*aline; ali@69: gchar *etext_ptr; ali@69: GError *err=NULL; ali@41: struct first_pass_results *first_pass_results; ali@42: struct warnings *warnings; ali@43: struct counters counters={0}; ali@45: struct line_properties last={0}; ali@56: struct parities parities={0}; ali@69: struct pending pending={0}; ali@69: gboolean isemptyline; ali@68: long start_para_line=0; ali@69: gboolean isnewpara=FALSE,enddash=FALSE; ali@45: last.start=CHAR_SPACE; ali@68: linecnt=checked_linecnt=0; ali@69: etext=read_etext(filename,&err); ali@69: if (!etext) ali@41: { ali@68: if (pswit[STDOUT_SWITCH]) ali@69: fprintf(stdout,"bookloupe: %s: %s\n",filename,err->message); ali@68: else ali@69: fprintf(stderr,"bookloupe: %s: %s\n",filename,err->message); ali@41: exit(1); ali@41: } ali@41: fprintf(stdout,"\n\nFile: %s\n\n",filename); ali@69: first_pass_results=first_pass(etext); ali@42: warnings=report_first_pass(first_pass_results); ali@69: qword=g_tree_new_full((GCompareDataFunc)strcmp,NULL,g_free,g_free); ali@69: qperiod=g_tree_new_full((GCompareDataFunc)strcmp,NULL,g_free,NULL); ali@40: /* ali@40: * Here we go with the main pass. Hold onto yer hat! ali@40: */ ali@65: linecnt=0; ali@69: etext_ptr=etext; ali@69: while ((aline=flgets(&etext_ptr,linecnt+1))) ali@40: { ali@68: linecnt++; ali@68: if (linecnt==1) ali@69: isnewpara=TRUE; ali@68: if (pswit[DP_SWITCH] && !strncmp(aline,"-----File: ",11)) ali@40: continue; // skip DP page separators completely ali@68: if (linecntfirstline || ali@41: (first_pass_results->footerline>0 && ali@41: linecnt>first_pass_results->footerline)) ali@40: { ali@68: if (pswit[HEADER_SWITCH]) ali@40: { ali@68: if (!strncmp(aline,"Title:",6)) ali@68: printf(" %s\n",aline); ali@68: if (!strncmp(aline,"Author:",7)) ali@68: printf(" %s\n",aline); ali@68: if (!strncmp(aline,"Release Date:",13)) ali@68: printf(" %s\n",aline); ali@68: if (!strncmp(aline,"Edition:",8)) ali@68: printf(" %s\n\n",aline); ali@40: } ali@68: continue; /* skip through the header */ ali@40: } ali@68: checked_linecnt++; ali@65: print_pending(aline,parastart,&pending); ali@65: memset(&pending,0,sizeof(pending)); ali@43: isemptyline=analyse_quotes(aline,&counters); ali@68: if (isnewpara && !isemptyline) ali@40: { ali@40: /* This line is the start of a new paragraph. */ ali@68: start_para_line=linecnt; ali@40: /* Capture its first line in case we want to report it later. */ ali@69: g_free(parastart); ali@69: parastart=g_strdup(aline); ali@56: memset(&parities,0,sizeof(parities)); /* restart the quote count */ ali@68: s=aline; ali@68: while (!gcisalpha(*s) && !gcisdigit(*s) && *s) ali@40: s++; ali@68: if (*s>='a' && *s<='z') ali@40: { ali@40: /* and its first letter is lowercase */ ali@68: if (pswit[ECHO_SWITCH]) ali@40: printf("\n%s\n",aline); ali@68: if (!pswit[OVERVIEW_SWITCH]) ali@68: printf(" Line %ld column %d - " ali@40: "Paragraph starts with lower-case\n", ali@40: linecnt,(int)(s-aline)+1); ali@68: else ali@68: cnt_punct++; ali@40: } ali@69: isnewpara=FALSE; /* Signal the end of new para processing. */ ali@40: } ali@68: /* Check for an em-dash broken at line end. */ ali@68: if (enddash && *aline=='-') ali@40: { ali@68: if (pswit[ECHO_SWITCH]) ali@40: printf("\n%s\n",aline); ali@68: if (!pswit[OVERVIEW_SWITCH]) ali@68: printf(" Line %ld column 1 - Broken em-dash?\n",linecnt); ali@68: else ali@68: cnt_punct++; ali@40: } ali@69: enddash=FALSE; ali@68: for (s=aline+strlen(aline)-1;*s==' ' && s>aline;s--) ali@40: ; ali@68: if (s>=aline && *s=='-') ali@69: enddash=TRUE; ali@67: check_for_control_characters(aline); ali@68: if (warnings->bin) ali@44: check_for_odd_characters(aline,warnings,isemptyline); ali@68: if (warnings->longline) ali@45: check_for_long_line(aline); ali@68: if (warnings->shortline) ali@45: check_for_short_line(aline,&last); ali@68: last.blen=last.len; ali@68: last.len=strlen(aline); ali@68: last.start=aline[0]; ali@46: check_for_starting_punctuation(aline); ali@68: if (warnings->dash) ali@40: { ali@47: check_for_spaced_emdash(aline); ali@47: check_for_spaced_dash(aline); ali@40: } ali@48: check_for_unmarked_paragraphs(aline); ali@49: check_for_jeebies(aline); ali@50: check_for_mta_from(aline); ali@51: check_for_orphan_character(aline); ali@52: check_for_pling_scanno(aline); ali@53: check_for_extra_period(aline,warnings); ali@54: check_for_following_punctuation(aline); ali@55: check_for_typos(aline,warnings); ali@56: check_for_misspaced_punctuation(aline,&parities,isemptyline); ali@57: check_for_double_punctuation(aline,warnings); ali@58: check_for_spaced_quotes(aline); ali@59: check_for_miscased_genative(aline); ali@60: check_end_of_line(aline,warnings); ali@61: check_for_unspaced_bracket(aline); ali@68: if (warnings->endquote) ali@62: check_for_unpunctuated_endquote(aline); ali@63: check_for_html_tag(aline); ali@64: check_for_html_entity(aline); ali@68: if (isemptyline) ali@40: { ali@65: check_for_mismatched_quotes(&counters,&pending); ali@43: memset(&counters,0,sizeof(counters)); ali@40: /* let the next iteration know that it's starting a new para */ ali@69: isnewpara=TRUE; ali@69: if (prevline) ali@69: check_for_omitted_punctuation(prevline,&last,start_para_line); ali@40: } ali@69: g_free(prevline); ali@69: prevline=g_strdup(aline); ali@0: } ali@69: if (prevline) ali@69: { ali@69: g_free(prevline); ali@69: prevline=NULL; ali@69: } ali@69: g_free(parastart); ali@69: g_free(prevline); ali@69: g_free(etext); ali@0: if (!pswit[OVERVIEW_SWITCH]) ali@69: g_tree_foreach(qword,report_duplicate_queries,NULL); ali@69: g_tree_unref(qword); ali@69: g_tree_unref(qperiod); ali@0: } ali@0: ali@40: /* ali@40: * flgets: ali@40: * ali@69: * Get one line from the input text, checking for ali@40: * the existence of exactly one CR/LF line-end per line. ali@40: * ali@40: * Returns: a pointer to the line. ali@40: */ ali@69: char *flgets(char **etext,long lcnt) ali@0: { ali@0: char c; ali@69: int len; ali@69: gboolean isCR=FALSE; ali@69: char *theline=*etext; ali@69: len=0; ali@69: for(;;) ali@40: { ali@69: c=*(*etext)++; ali@69: if (!c) ali@68: return NULL; ali@40: /* either way, it's end of line */ ali@69: if (c=='\n') ali@40: { ali@68: if (isCR) ali@68: break; ali@68: else ali@40: { ali@40: /* Error - a LF without a preceding CR */ ali@68: if (pswit[LINE_END_SWITCH]) ali@40: { ali@68: if (pswit[ECHO_SWITCH]) ali@69: printf("\n%*.*s\n",len,len,theline); ali@68: if (!pswit[OVERVIEW_SWITCH]) ali@68: printf(" Line %ld - No CR?\n",lcnt); ali@68: else ali@68: cnt_lineend++; ali@40: } ali@68: break; ali@40: } ali@40: } ali@69: if (c=='\r') ali@40: { ali@68: if (isCR) ali@40: { ali@40: /* Error - two successive CRs */ ali@68: if (pswit[LINE_END_SWITCH]) ali@40: { ali@68: if (pswit[ECHO_SWITCH]) ali@69: printf("\n%*.*s\n",len,len,theline); ali@68: if (!pswit[OVERVIEW_SWITCH]) ali@68: printf(" Line %ld - Two successive CRs?\n",lcnt); ali@68: else ali@68: cnt_lineend++; ali@40: } ali@40: } ali@69: isCR=TRUE; ali@40: } ali@68: else ali@40: { ali@68: if (pswit[LINE_END_SWITCH] && isCR) ali@40: { ali@68: if (pswit[ECHO_SWITCH]) ali@69: printf("\n%*.*s\n",len,len,theline); ali@68: if (!pswit[OVERVIEW_SWITCH]) ali@68: printf(" Line %ld column %d - CR without LF?\n", ali@40: lcnt,len+1); ali@68: else ali@68: cnt_lineend++; ali@69: theline[len]=' '; ali@40: } ali@69: isCR=FALSE; ali@68: len++; ali@40: } ali@69: } ali@69: theline[len]='\0'; ali@0: if (pswit[MARKUP_SWITCH]) ali@68: postprocess_for_HTML(theline); ali@0: if (pswit[DP_SWITCH]) ali@68: postprocess_for_DP(theline); ali@40: return theline; ali@0: } ali@0: ali@40: /* ali@40: * mixdigit: ali@40: * ali@40: * Takes a "word" as a parameter, and checks whether it ali@40: * contains a mixture of alpha and digits. Generally, this is an ali@40: * error, but may not be for cases like 4th or L5 12s. 3d. ali@40: * ali@40: * Returns: 0 if no error found, 1 if error. ali@40: */ ali@69: int mixdigit(const char *checkword) ali@0: { ali@40: int wehaveadigit,wehavealetter,firstdigits,query,wl; ali@69: const char *s; ali@40: wehaveadigit=wehavealetter=query=0; ali@40: for (s=checkword;*s;s++) ali@68: if (gcisalpha(*s)) ali@68: wehavealetter=1; ali@68: else ali@68: if (gcisdigit(*s)) ali@68: wehaveadigit=1; ali@40: if (wehaveadigit && wehavealetter) ali@40: { ali@40: /* Now exclude common legit cases, like "21st" and "12l. 3s. 11d." */ ali@68: query=1; ali@68: wl=strlen(checkword); ali@68: for (firstdigits=0;gcisdigit(checkword[firstdigits]);firstdigits++) ali@68: ; ali@68: /* digits, ending in st, rd, nd, th of either case */ ali@69: if (firstdigits+2==wl && (!g_ascii_strcasecmp(checkword+wl-2,"st") || ali@69: !g_ascii_strcasecmp(checkword+wl-2,"rd") || ali@69: !g_ascii_strcasecmp(checkword+wl-2,"nd") || ali@69: !g_ascii_strcasecmp(checkword+wl-2,"th"))) ali@40: query=0; ali@69: if (firstdigits+3==wl && (!g_ascii_strcasecmp(checkword+wl-3,"sts") || ali@69: !g_ascii_strcasecmp(checkword+wl-3,"rds") || ali@69: !g_ascii_strcasecmp(checkword+wl-3,"nds") || ali@69: !g_ascii_strcasecmp(checkword+wl-3,"ths"))) ali@40: query=0; ali@69: if (firstdigits+3==wl && (!g_ascii_strcasecmp(checkword+wl-4,"stly") || ali@69: !g_ascii_strcasecmp(checkword+wl-4,"rdly") || ali@69: !g_ascii_strcasecmp(checkword+wl-4,"ndly") || ali@69: !g_ascii_strcasecmp(checkword+wl-4,"thly"))) ali@40: query=0; ali@68: /* digits, ending in l, L, s or d */ ali@68: if (firstdigits+1==wl && (checkword[wl-1]=='l' || ali@40: checkword[wl-1]=='L' || checkword[wl-1]=='s' || checkword[wl-1]=='d')) ali@40: query=0; ali@68: /* ali@40: * L at the start of a number, representing Britsh pounds, like L500. ali@68: * This is cute. We know the current word is mixeddigit. If the first ali@68: * letter is L, there must be at least one digit following. If both ali@68: * digits and letters follow, we have a genuine error, else we have a ali@68: * capital L followed by digits, and we accept that as a non-error. ali@40: */ ali@68: if (checkword[0]=='L' && !mixdigit(checkword+1)) ali@40: query=0; ali@40: } ali@40: return query; ali@0: } ali@0: ali@40: /* ali@40: * getaword: ali@40: * ali@69: * Extracts the first/next "word" from the line, and returns it. ali@69: * A word is defined as one English word unit--or at least that's the aim. ali@69: * "ptr" is advanced to the position in the line where we will start ali@69: * looking for the next word. ali@40: * ali@69: * Returns: A newly-allocated string. ali@40: */ ali@69: gchar *getaword(const char **ptr) ali@0: { ali@69: int i; ali@54: const char *s; ali@69: GString *word; ali@69: word=g_string_new(NULL); ali@69: for (;!gcisdigit(**ptr) && !gcisalpha(**ptr) && **ptr;(*ptr)++) ali@40: ; ali@40: /* ali@40: * Use a look-ahead to handle exceptions for numbers like 1,000 and 1.35. ali@40: * Especially yucky is the case of L1,000 ali@40: * This section looks for a pattern of characters including a digit ali@40: * followed by a comma or period followed by one or more digits. ali@40: * If found, it returns this whole pattern as a word; otherwise we discard ali@40: * the results and resume our normal programming. ali@40: */ ali@69: s=*ptr; ali@69: for (;gcisdigit(*s) || gcisalpha(*s) || *s==',' || *s=='.';s++) ali@69: g_string_append_c(word,*s); ali@69: for (i=1;i+1len;i++) ali@40: { ali@69: if (word->str[i]=='.' || word->str[i]==',') ali@40: { ali@69: if (gcisdigit(word->str[i-1]) && gcisdigit(word->str[i-1])) ali@40: { ali@69: *ptr=s; ali@69: return g_string_free(word,FALSE); ali@40: } ali@40: } ali@40: } ali@0: /* we didn't find a punctuated number - do the regular getword thing */ ali@69: g_string_truncate(word,0); ali@69: for (;gcisdigit(**ptr) || gcisalpha(**ptr) || **ptr=='\'';(*ptr)++) ali@69: g_string_append_c(word,**ptr); ali@69: return g_string_free(word,FALSE); ali@0: } ali@0: ali@40: /* ali@40: * isroman: ali@40: * ali@40: * Is this word a Roman Numeral? ali@40: * ali@40: * It doesn't actually validate that the number is a valid Roman Numeral--for ali@40: * example it will pass MXXXXXXXXXX as a valid Roman Numeral, but that's not ali@40: * what we're here to do. If it passes this, it LOOKS like a Roman numeral. ali@40: * Anyway, the actual Romans were pretty tolerant of bad arithmetic, or ali@40: * expressions thereof, except when it came to taxes. Allow any number of M, ali@40: * an optional D, an optional CM or CD, any number of optional Cs, an optional ali@40: * XL or an optional XC, an optional IX or IV, an optional V and any number ali@40: * of optional Is. ali@40: */ ali@69: gboolean isroman(const char *t) ali@0: { ali@69: const char *s; ali@40: if (!t || !*t) ali@69: return FALSE; ali@40: s=t; ali@40: while (*t=='m' && *t) ali@40: t++; ali@40: if (*t=='d') ali@40: t++; ali@40: if (*t=='c' && t[1]=='m') ali@40: t+=2; ali@40: if (*t=='c' && t[1]=='d') ali@40: t+=2; ali@40: while (*t=='c' && *t) ali@40: t++; ali@40: if (*t=='x' && t[1]=='l') ali@40: t+=2; ali@40: if (*t=='x' && t[1]=='c') ali@40: t+=2; ali@40: if (*t=='l') ali@40: t++; ali@40: while (*t=='x' && *t) ali@40: t++; ali@40: if (*t=='i' && t[1]=='x') ali@40: t+=2; ali@40: if (*t=='i' && t[1]=='v') ali@40: t+=2; ali@40: if (*t=='v') ali@40: t++; ali@40: while (*t=='i' && *t) ali@40: t++; ali@40: return !*t; ali@0: } ali@0: ali@40: /* ali@40: * gcisalpha: ali@40: * ali@40: * A version of isalpha() that is somewhat lenient on 8-bit texts. ali@40: * If we use the standard function, 8-bit accented characters break ali@40: * words, so that tete with accented characters appears to be two words, "t" ali@40: * and "t", with 8-bit characters between them. This causes over-reporting of ali@40: * errors. gcisalpha() recognizes accented letters from the CP1252 (Windows) ali@40: * and ISO-8859-1 character sets, which are the most common PG 8-bit types. ali@40: */ ali@69: gboolean gcisalpha(unsigned char c) ali@0: { ali@40: if (c>='a' && c<='z') ali@69: return TRUE; ali@40: if (c>='A' && c<='Z') ali@69: return TRUE; ali@40: if (c<140) ali@69: return FALSE; ali@40: if (c>=192 && c!=208 && c!=215 && c!=222 && c!=240 && c!=247 && c!=254) ali@69: return TRUE; ali@40: if (c==140 || c==142 || c==156 || c==158 || c==159) ali@69: return TRUE; ali@69: return FALSE; ali@0: } ali@0: ali@40: /* ali@40: * gcisdigit: ali@40: * ali@40: * A version of isdigit() that doesn't get confused in 8-bit texts. ali@40: */ ali@69: gboolean gcisdigit(unsigned char c) ali@0: { ali@40: return c>='0' && c<='9'; ali@0: } ali@0: ali@40: /* ali@40: * gcisletter: ali@40: * ali@40: * A version of isletter() that doesn't get confused in 8-bit texts. ali@40: * NB: this is ISO-8891-1-specific. ali@40: */ ali@69: gboolean gcisletter(unsigned char c) ali@0: { ali@40: return c>='A' && c<='Z' || c>='a' && c<='z' || c>=192; ali@0: } ali@0: ali@40: /* ali@40: * postprocess_for_DP: ali@40: * ali@40: * Invoked with the -d switch from flgets(). ali@40: * It simply "removes" from the line a hard-coded set of common ali@40: * DP-specific tags, so that the line passed to the main routine has ali@40: * been pre-cleaned of DP markup. ali@40: */ ali@0: void postprocess_for_DP(char *theline) ali@0: { ali@40: char *s,*t; ali@0: int i; ali@0: if (!*theline) ali@68: return; ali@40: for (i=0;*DPmarkup[i];i++) ali@40: { ali@68: s=strstr(theline,DPmarkup[i]); ali@68: while (s) ali@40: { ali@68: t=s+strlen(DPmarkup[i]); ali@68: while (*t) ali@40: { ali@68: *s=*t; ali@68: t++; ali@40: s++; ali@40: } ali@68: *s=0; ali@68: s=strstr(theline,DPmarkup[i]); ali@40: } ali@40: } ali@0: } ali@0: ali@40: /* ali@40: * postprocess_for_HTML: ali@40: * ali@40: * Invoked with the -m switch from flgets(). ali@40: * It simply "removes" from the line a hard-coded set of common ali@40: * HTML tags and "replaces" a hard-coded set of common HTML ali@40: * entities, so that the line passed to the main routine has ali@40: * been pre-cleaned of HTML. ali@40: */ ali@0: void postprocess_for_HTML(char *theline) ali@0: { ali@69: if (strchr(theline,'<') && strchr(theline,'>')) ali@68: while (losemarkup(theline)) ali@68: ; ali@0: while (loseentities(theline)) ali@68: ; ali@0: } ali@0: ali@0: char *losemarkup(char *theline) ali@0: { ali@40: char *s,*t; ali@0: int i; ali@0: if (!*theline) ali@68: return NULL; ali@40: s=strstr(theline,"<"); ali@40: t=strstr(theline,">"); ali@40: if (!s || !t) ali@40: return NULL; ali@40: for (i=0;*markup[i];i++) ali@68: if (!tagcomp(s+1,markup[i])) ali@40: { ali@68: if (!t[1]) ali@40: { ali@68: *s=0; ali@68: return s; ali@40: } ali@68: else if (t>s) ali@40: { ali@40: strcpy(s,t+1); ali@40: return s; ali@40: } ali@68: } ali@40: /* It's an unrecognized . */ ali@40: return NULL; ali@0: } ali@0: ali@0: char *loseentities(char *theline) ali@0: { ali@0: int i; ali@40: char *s,*t; ali@0: if (!*theline) ali@68: return NULL; ali@40: for (i=0;*entities[i].htmlent;i++) ali@40: { ali@68: s=strstr(theline,entities[i].htmlent); ali@68: if (s) ali@40: { ali@68: t=malloc((size_t)strlen(s)); ali@68: if (!t) ali@40: return NULL; ali@68: strcpy(t,s+strlen(entities[i].htmlent)); ali@68: strcpy(s,entities[i].textent); ali@68: strcat(s,t); ali@68: free(t); ali@68: return theline; ali@40: } ali@40: } ali@40: for (i=0;*entities[i].htmlnum;i++) ali@40: { ali@68: s=strstr(theline,entities[i].htmlnum); ali@68: if (s) ali@40: { ali@68: t=malloc((size_t)strlen(s)); ali@68: if (!t) ali@40: return NULL; ali@68: strcpy(t,s+strlen(entities[i].htmlnum)); ali@68: strcpy(s,entities[i].textent); ali@68: strcat(s,t); ali@68: free(t); ali@68: return theline; ali@40: } ali@40: } ali@40: return NULL; ali@0: } ali@0: ali@69: int tagcomp(const char *strin,const char *basetag) ali@0: { ali@69: const char *s,*t; ali@40: s=basetag; ali@40: t=strin; ali@40: if (*t=='/') ali@40: t++; /* ignore a slash */ ali@40: while (*s && *t) ali@40: { ali@68: if (tolower(*s)!=tolower(*t)) ali@40: return 1; ali@68: s++; ali@40: t++; ali@40: } ali@40: return 0; ali@0: } ali@0: ali@69: void proghelp(GOptionContext *context) ali@0: { ali@69: gchar *help; ali@40: fputs("Bookloupe version " PACKAGE_VERSION ".\n",stderr); ali@40: fputs("Copyright 2000-2005 Jim Tinsley .\n",stderr); ali@40: fputs("Copyright 2012- J. Ali Harlow .\n",stderr); ali@40: fputs("Bookloupe comes wih ABSOLUTELY NO WARRANTY. " ali@40: "For details, read the file COPYING.\n",stderr); ali@40: fputs("This is Free Software; " ali@40: "you may redistribute it under certain conditions (GPL);\n",stderr); ali@40: fputs("read the file COPYING for details.\n\n",stderr); ali@69: help=g_option_context_get_help(context,TRUE,NULL); ali@69: fputs(help,stderr); ali@69: g_free(help); ali@69: fputs("Sample usage: bookloupe warpeace.txt\n\n",stderr); ali@40: fputs("Bookloupe queries anything it thinks shouldn't be in a PG text; " ali@40: "non-ASCII\n",stderr); ali@40: fputs("characters like accented letters, " ali@40: "lines longer than 75 or shorter than 55,\n",stderr); ali@40: fputs("unbalanced quotes or brackets, " ali@40: "a variety of badly formatted punctuation, \n",stderr); ali@40: fputs("HTML tags, some likely typos. " ali@40: "It is NOT a substitute for human judgement.\n",stderr); ali@0: fputs("\n",stderr); ali@0: }