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