Blame src/mktable.c

Packit b89d10
/**********************************************************************
Packit b89d10
  mktable.c
Packit b89d10
**********************************************************************/
Packit b89d10
/*-
Packit b89d10
 * Copyright (c) 2002-2016  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
Packit b89d10
 * All rights reserved.
Packit b89d10
 *
Packit b89d10
 * Redistribution and use in source and binary forms, with or without
Packit b89d10
 * modification, are permitted provided that the following conditions
Packit b89d10
 * are met:
Packit b89d10
 * 1. Redistributions of source code must retain the above copyright
Packit b89d10
 *    notice, this list of conditions and the following disclaimer.
Packit b89d10
 * 2. Redistributions in binary form must reproduce the above copyright
Packit b89d10
 *    notice, this list of conditions and the following disclaimer in the
Packit b89d10
 *    documentation and/or other materials provided with the distribution.
Packit b89d10
 *
Packit b89d10
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
Packit b89d10
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit b89d10
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit b89d10
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
Packit b89d10
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit b89d10
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit b89d10
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit b89d10
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit b89d10
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit b89d10
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit b89d10
 * SUCH DAMAGE.
Packit b89d10
 */
Packit b89d10
Packit b89d10
#include <stdlib.h>
Packit b89d10
#include <stdio.h>
Packit b89d10
#include <locale.h>
Packit b89d10
Packit b89d10
#ifndef __USE_ISOC99
Packit b89d10
#define __USE_ISOC99
Packit b89d10
#endif
Packit b89d10
Packit b89d10
#include <ctype.h>
Packit b89d10
Packit b89d10
#include "regenc.h"
Packit b89d10
Packit b89d10
#define ASCII                0
Packit b89d10
#define UNICODE_ISO_8859_1   1
Packit b89d10
#define ISO_8859_1           2
Packit b89d10
#define ISO_8859_2           3
Packit b89d10
#define ISO_8859_3           4
Packit b89d10
#define ISO_8859_4           5
Packit b89d10
#define ISO_8859_5           6
Packit b89d10
#define ISO_8859_6           7
Packit b89d10
#define ISO_8859_7           8
Packit b89d10
#define ISO_8859_8           9
Packit b89d10
#define ISO_8859_9          10
Packit b89d10
#define ISO_8859_10         11
Packit b89d10
#define ISO_8859_11         12
Packit b89d10
#define ISO_8859_13         13
Packit b89d10
#define ISO_8859_14         14
Packit b89d10
#define ISO_8859_15         15
Packit b89d10
#define ISO_8859_16         16
Packit b89d10
#define KOI8                17
Packit b89d10
#define KOI8_R              18
Packit b89d10
Packit b89d10
typedef struct {
Packit b89d10
  int   num;
Packit b89d10
  char* name;
Packit b89d10
} ENC_INFO;
Packit b89d10
Packit b89d10
static ENC_INFO Info[] = {
Packit b89d10
  { ASCII,               "ASCII" },
Packit b89d10
  { UNICODE_ISO_8859_1,  "UNICODE_ISO_8859_1"  },
Packit b89d10
  { ISO_8859_1,  "ISO_8859_1"  },
Packit b89d10
  { ISO_8859_2,  "ISO_8859_2"  },
Packit b89d10
  { ISO_8859_3,  "ISO_8859_3"  },
Packit b89d10
  { ISO_8859_4,  "ISO_8859_4"  },
Packit b89d10
  { ISO_8859_5,  "ISO_8859_5"  },
Packit b89d10
  { ISO_8859_6,  "ISO_8859_6"  },
Packit b89d10
  { ISO_8859_7,  "ISO_8859_7"  },
Packit b89d10
  { ISO_8859_8,  "ISO_8859_8"  },
Packit b89d10
  { ISO_8859_9,  "ISO_8859_9"  },
Packit b89d10
  { ISO_8859_10, "ISO_8859_10" },
Packit b89d10
  { ISO_8859_11, "ISO_8859_11" },
Packit b89d10
  { ISO_8859_13, "ISO_8859_13" },
Packit b89d10
  { ISO_8859_14, "ISO_8859_14" },
Packit b89d10
  { ISO_8859_15, "ISO_8859_15" },
Packit b89d10
  { ISO_8859_16, "ISO_8859_16" },
Packit b89d10
  { KOI8,        "KOI8" },
Packit b89d10
  { KOI8_R,      "KOI8_R" }
Packit b89d10
};
Packit b89d10
Packit b89d10
Packit b89d10
static int IsAlpha(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return isalpha(c);
Packit b89d10
Packit b89d10
  if (c >= 0x41 && c <= 0x5a) return 1;
Packit b89d10
  if (c >= 0x61 && c <= 0x7a) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c == 0xba) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_2:
Packit b89d10
    if (c == 0xa1 || c == 0xa3) return 1;
Packit b89d10
    if (c == 0xa5 || c == 0xa6) return 1;
Packit b89d10
    if (c >= 0xa9 && c <= 0xac) return 1;
Packit b89d10
    if (c >= 0xae && c <= 0xaf) return 1;
Packit b89d10
    if (c == 0xb1 || c == 0xb3) return 1;
Packit b89d10
    if (c == 0xb5 || c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xbc) return 1;
Packit b89d10
    if (c >= 0xbe && c <= 0xbf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_3:
Packit b89d10
    if (c == 0xa1) return 1;
Packit b89d10
    if (c == 0xa6) return 1;
Packit b89d10
    if (c >= 0xa9 && c <= 0xac) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c == 0xb1) return 1;
Packit b89d10
    if (c == 0xb5 || c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xbc) return 1;
Packit b89d10
    if (c == 0xbf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xc2) return 1;
Packit b89d10
    if (c >= 0xc4 && c <= 0xcf) return 1;
Packit b89d10
    if (c >= 0xd1 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xe2) return 1;
Packit b89d10
    if (c >= 0xe4 && c <= 0xef) return 1;
Packit b89d10
    if (c >= 0xf1 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_4:
Packit b89d10
    if (c >= 0xa1 && c <= 0xa3) return 1;
Packit b89d10
    if (c == 0xa5 || c == 0xa6) return 1;
Packit b89d10
    if (c >= 0xa9 && c <= 0xac) return 1;
Packit b89d10
    if (c == 0xae) return 1;
Packit b89d10
    if (c == 0xb1 || c == 0xb3) return 1;
Packit b89d10
    if (c == 0xb5 || c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xbf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_5:
Packit b89d10
    if (c >= 0xa1 && c <= 0xcf && c != 0xad) return 1;
Packit b89d10
    if (c >= 0xd0 && c <= 0xff && c != 0xf0 && c != 0xfd) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_6:
Packit b89d10
    if (c >= 0xc1 && c <= 0xda) return 1;
Packit b89d10
    if (c >= 0xe0 && c <= 0xf2) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_7:
Packit b89d10
    if (c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb8 && c <= 0xba) return 1;
Packit b89d10
    if (c == 0xbc) return 1;
Packit b89d10
    if (c >= 0xbe && c <= 0xbf) return 1;
Packit b89d10
    if (c == 0xc0) return 1;
Packit b89d10
    if (c >= 0xc1 && c <= 0xdb && c != 0xd2) return 1;
Packit b89d10
    if (c >= 0xdc && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_8:
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c >= 0xe0 && c <= 0xfa) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_10:
Packit b89d10
    if (c >= 0xa1 && c <= 0xa6) return 1;
Packit b89d10
    if (c >= 0xa8 && c <= 0xac) return 1;
Packit b89d10
    if (c == 0xae || c == 0xaf) return 1;
Packit b89d10
    if (c >= 0xb1 && c <= 0xb6) return 1;
Packit b89d10
    if (c >= 0xb8 && c <= 0xbc) return 1;
Packit b89d10
    if (c >= 0xbe && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_11:
Packit b89d10
    if (c >= 0xa1 && c <= 0xda) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xfb) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_13:
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c == 0xb8) return 1;
Packit b89d10
    if (c == 0xba) return 1;
Packit b89d10
    if (c >= 0xbf && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_14:
Packit b89d10
    if (c == 0xa1 || c == 0xa2) return 1;
Packit b89d10
    if (c == 0xa4 || c == 0xa5) return 1;
Packit b89d10
    if (c == 0xa6 || c == 0xa8) return 1;
Packit b89d10
    if (c >= 0xaa && c <= 0xac) return 1;
Packit b89d10
    if (c >= 0xaf && c <= 0xb5) return 1;
Packit b89d10
    if (c >= 0xb7 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_15:
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c == 0xba) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xff) return 1;
Packit b89d10
    if (c == 0xa6) return 1;
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xb4) return 1;
Packit b89d10
    if (c == 0xb8) return 1;
Packit b89d10
    if (c == 0xbc) return 1;
Packit b89d10
    if (c == 0xbd) return 1;
Packit b89d10
    if (c == 0xbe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_16:
Packit b89d10
    if (c == 0xa1) return 1;
Packit b89d10
    if (c == 0xa2) return 1;
Packit b89d10
    if (c == 0xa3) return 1;
Packit b89d10
    if (c == 0xa6) return 1;
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xac) return 1;
Packit b89d10
    if (c == 0xae) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c == 0xb2) return 1;
Packit b89d10
    if (c == 0xb3) return 1;
Packit b89d10
    if (c == 0xb4) return 1;
Packit b89d10
    if (c >= 0xb8 && c <= 0xba) return 1;
Packit b89d10
    if (c == 0xbc) return 1;
Packit b89d10
    if (c == 0xbd) return 1;
Packit b89d10
    if (c == 0xbe) return 1;
Packit b89d10
    if (c == 0xbf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xde) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c == 0xa3 || c == 0xb3) return 1;
Packit b89d10
    /* fall */
Packit b89d10
  case KOI8:
Packit b89d10
    if (c >= 0xc0 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsBlank(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return isblank(c);
Packit b89d10
Packit b89d10
  if (c == 0x09	|| c == 0x20) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_2:
Packit b89d10
  case ISO_8859_3:
Packit b89d10
  case ISO_8859_4:
Packit b89d10
  case ISO_8859_5:
Packit b89d10
  case ISO_8859_6:
Packit b89d10
  case ISO_8859_7:
Packit b89d10
  case ISO_8859_8:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
  case ISO_8859_10:
Packit b89d10
  case ISO_8859_11:
Packit b89d10
  case ISO_8859_13:
Packit b89d10
  case ISO_8859_14:
Packit b89d10
  case ISO_8859_15:
Packit b89d10
  case ISO_8859_16:
Packit b89d10
  case KOI8:
Packit b89d10
    if (c == 0xa0) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c == 0x9a) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsCntrl(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return iscntrl(c);
Packit b89d10
Packit b89d10
  if (c >= 0x00	&& c <= 0x1F) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
    if (c == 0xad) return 1;
Packit b89d10
    /* fall */
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_2:
Packit b89d10
  case ISO_8859_3:
Packit b89d10
  case ISO_8859_4:
Packit b89d10
  case ISO_8859_5:
Packit b89d10
  case ISO_8859_6:
Packit b89d10
  case ISO_8859_7:
Packit b89d10
  case ISO_8859_8:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
  case ISO_8859_10:
Packit b89d10
  case ISO_8859_11:
Packit b89d10
  case ISO_8859_13:
Packit b89d10
  case ISO_8859_14:
Packit b89d10
  case ISO_8859_15:
Packit b89d10
  case ISO_8859_16:
Packit b89d10
  case KOI8:
Packit b89d10
    if (c >= 0x7f && c <= 0x9F) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c == 0x7f) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsDigit(int enc ARG_UNUSED, int c)
Packit b89d10
{
Packit b89d10
  if (c >= 0x30 && c <= 0x39) return 1;
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsGraph(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return isgraph(c);
Packit b89d10
Packit b89d10
  if (c >= 0x21 && c <= 0x7e) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_2:
Packit b89d10
  case ISO_8859_4:
Packit b89d10
  case ISO_8859_5:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
  case ISO_8859_10:
Packit b89d10
  case ISO_8859_13:
Packit b89d10
  case ISO_8859_14:
Packit b89d10
  case ISO_8859_15:
Packit b89d10
  case ISO_8859_16:
Packit b89d10
    if (c >= 0xa1 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_3:
Packit b89d10
    if (c >= 0xa1) {
Packit b89d10
      if (c == 0xa5 || c == 0xae || c == 0xbe || c == 0xc3 || c == 0xd0 ||
Packit b89d10
	  c == 0xe3 || c == 0xf0)
Packit b89d10
	return 0;
Packit b89d10
      else
Packit b89d10
	return 1;
Packit b89d10
    }
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_6:
Packit b89d10
    if (c == 0xa4 || c == 0xac || c == 0xad || c == 0xbb || c == 0xbf)
Packit b89d10
      return 1;
Packit b89d10
    if (c >= 0xc1 && c <= 0xda) return 1;
Packit b89d10
    if (c >= 0xe0 && c <= 0xf2) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_7:
Packit b89d10
    if (c >= 0xa1 && c <= 0xfe &&
Packit b89d10
	c != 0xa4 && c != 0xa5 && c != 0xaa &&
Packit b89d10
	c != 0xae && c != 0xd2) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_8:
Packit b89d10
    if (c >= 0xa2 && c <= 0xfa) {
Packit b89d10
      if (c >= 0xbf && c <= 0xde) return 0;
Packit b89d10
      return 1;
Packit b89d10
    }
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_11:
Packit b89d10
    if (c >= 0xa1 && c <= 0xda) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xfb) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8:
Packit b89d10
    if (c >= 0xc0 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c >= 0x80 && c <= 0xff && c != 0x9a) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsLower(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return islower(c);
Packit b89d10
Packit b89d10
  if (c >= 0x61 && c <= 0x7a) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c == 0xba) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_2:
Packit b89d10
    if (c == 0xb1 || c == 0xb3) return 1;
Packit b89d10
    if (c == 0xb5 || c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xbc) return 1;
Packit b89d10
    if (c >= 0xbe && c <= 0xbf) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_3:
Packit b89d10
    if (c == 0xb1) return 1;
Packit b89d10
    if (c == 0xb5 || c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xbc) return 1;
Packit b89d10
    if (c == 0xbf) return 1;
Packit b89d10
    if (c == 0xdf) return 1;
Packit b89d10
    if (c >= 0xe0 && c <= 0xe2) return 1;
Packit b89d10
    if (c >= 0xe4 && c <= 0xef) return 1;
Packit b89d10
    if (c >= 0xf1 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_4:
Packit b89d10
    if (c == 0xa2) return 1;
Packit b89d10
    if (c == 0xb1 || c == 0xb3) return 1;
Packit b89d10
    if (c == 0xb5 || c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xbc) return 1;
Packit b89d10
    if (c >= 0xbe && c <= 0xbf) return 1;
Packit b89d10
    if (c == 0xdf) return 1;
Packit b89d10
    if (c >= 0xe0 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_5:
Packit b89d10
    if (c >= 0xd0 && c <= 0xff && c != 0xf0 && c != 0xfd) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_6:
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_7:
Packit b89d10
    if (c == 0xc0) return 1;
Packit b89d10
    if (c >= 0xdc && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_8:
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_10:
Packit b89d10
    if (c >= 0xb1 && c <= 0xb6) return 1;
Packit b89d10
    if (c >= 0xb8 && c <= 0xbc) return 1;
Packit b89d10
    if (c == 0xbe || c == 0xbf) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_11:
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_13:
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c == 0xb8) return 1;
Packit b89d10
    if (c == 0xba) return 1;
Packit b89d10
    if (c == 0xbf) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_14:
Packit b89d10
    if (c == 0xa2) return 1;
Packit b89d10
    if (c == 0xa5) return 1;
Packit b89d10
    if (c == 0xab) return 1;
Packit b89d10
    if (c == 0xb1 || c == 0xb3 || c == 0xb5) return 1;
Packit b89d10
    if (c >= 0xb8 && c <= 0xba) return 1;
Packit b89d10
    if (c == 0xbc) return 1;
Packit b89d10
    if (c == 0xbe || c == 0xbf) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_15:
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c == 0xba) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xff) return 1;
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xb8) return 1;
Packit b89d10
    if (c == 0xbd) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_16:
Packit b89d10
    if (c == 0xa2) return 1;
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xae) return 1;
Packit b89d10
    if (c == 0xb3) return 1;
Packit b89d10
    if (c >= 0xb8 && c <= 0xba) return 1;
Packit b89d10
    if (c == 0xbd) return 1;
Packit b89d10
    if (c == 0xbf) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c == 0xa3) return 1;
Packit b89d10
    /* fall */
Packit b89d10
  case KOI8:
Packit b89d10
    if (c >= 0xc0 && c <= 0xdf) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsPrint(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return isprint(c);
Packit b89d10
Packit b89d10
  if (c >= 0x20 && c <= 0x7e) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
    if (c >= 0x09 && c <= 0x0d) return 1;
Packit b89d10
    if (c == 0x85) return 1;
Packit b89d10
    /* fall */
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_2:
Packit b89d10
  case ISO_8859_4:
Packit b89d10
  case ISO_8859_5:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
  case ISO_8859_10:
Packit b89d10
  case ISO_8859_13:
Packit b89d10
  case ISO_8859_14:
Packit b89d10
  case ISO_8859_15:
Packit b89d10
  case ISO_8859_16:
Packit b89d10
    if (c >= 0xa0 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_3:
Packit b89d10
    if (c >= 0xa0) {
Packit b89d10
      if (c == 0xa5 || c == 0xae || c == 0xbe || c == 0xc3 || c == 0xd0 ||
Packit b89d10
	  c == 0xe3 || c == 0xf0)
Packit b89d10
	return 0;
Packit b89d10
      else
Packit b89d10
	return 1;
Packit b89d10
    }
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_6:
Packit b89d10
    if (c == 0xa0) return 1;
Packit b89d10
    if (c == 0xa4 || c == 0xac || c == 0xad || c == 0xbb || c == 0xbf)
Packit b89d10
      return 1;
Packit b89d10
    if (c >= 0xc1 && c <= 0xda) return 1;
Packit b89d10
    if (c >= 0xe0 && c <= 0xf2) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_7:
Packit b89d10
    if (c >= 0xa0 && c <= 0xfe &&
Packit b89d10
	c != 0xa4 && c != 0xa5 && c != 0xaa &&
Packit b89d10
	c != 0xae && c != 0xd2) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_8:
Packit b89d10
    if (c >= 0xa0 && c <= 0xfa) {
Packit b89d10
      if (c >= 0xbf && c <= 0xde) return 0;
Packit b89d10
      if (c == 0xa1) return 0;
Packit b89d10
      return 1;
Packit b89d10
    }
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_11:
Packit b89d10
    if (c >= 0xa0 && c <= 0xda) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xfb) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8:
Packit b89d10
    if (c == 0xa0) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c >= 0x80 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsPunct(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return ispunct(c);
Packit b89d10
Packit b89d10
  if (enc == UNICODE_ISO_8859_1) {
Packit b89d10
    if (c == 0x24 || c == 0x2b || c == 0x5e || c == 0x60 ||
Packit b89d10
        c == 0x7c || c == 0x7e) return 1;
Packit b89d10
    if (c >= 0x3c && c <= 0x3e) return 1;
Packit b89d10
  }
Packit b89d10
Packit b89d10
  if (c >= 0x21 && c <= 0x2f) return 1;
Packit b89d10
  if (c >= 0x3a && c <= 0x40) return 1;
Packit b89d10
  if (c >= 0x5b && c <= 0x60) return 1;
Packit b89d10
  if (c >= 0x7b && c <= 0x7e) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
  case ISO_8859_15:
Packit b89d10
    if (c == 0xad) return 1;
Packit b89d10
    /* fall */
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
    if (c == 0xa1) return 1;
Packit b89d10
    if (c == 0xab) return 1;
Packit b89d10
    if (c == 0xb7) return 1;
Packit b89d10
    if (c == 0xbb) return 1;
Packit b89d10
    if (c == 0xbf) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_2:
Packit b89d10
  case ISO_8859_4:
Packit b89d10
  case ISO_8859_5:
Packit b89d10
  case ISO_8859_14:
Packit b89d10
    if (c == 0xad) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_3:
Packit b89d10
  case ISO_8859_10:
Packit b89d10
    if (c == 0xad) return 1;
Packit b89d10
    if (c == 0xb7) return 1;
Packit b89d10
    if (c == 0xbd) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_6:
Packit b89d10
    if (c == 0xac) return 1;
Packit b89d10
    if (c == 0xad) return 1;
Packit b89d10
    if (c == 0xbb) return 1;
Packit b89d10
    if (c == 0xbf) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_7:
Packit b89d10
    if (c == 0xa1 || c == 0xa2) return 1;
Packit b89d10
    if (c == 0xab) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c == 0xad) return 1;
Packit b89d10
    if (c == 0xb7 || c == 0xbb) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_8:
Packit b89d10
    if (c == 0xab) return 1;
Packit b89d10
    if (c == 0xad) return 1;
Packit b89d10
    if (c == 0xb7) return 1;
Packit b89d10
    if (c == 0xbb) return 1;
Packit b89d10
    if (c == 0xdf) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_13:
Packit b89d10
    if (c == 0xa1 || c == 0xa5) return 1;
Packit b89d10
    if (c == 0xab || c == 0xad) return 1;
Packit b89d10
    if (c == 0xb4 || c == 0xb7) return 1;
Packit b89d10
    if (c == 0xbb) return 1;
Packit b89d10
    if (c == 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_16:
Packit b89d10
    if (c == 0xa5) return 1;
Packit b89d10
    if (c == 0xab) return 1;
Packit b89d10
    if (c == 0xad) return 1;
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c == 0xb7) return 1;
Packit b89d10
    if (c == 0xbb) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c == 0x9e) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_11:
Packit b89d10
  case KOI8:
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsSpace(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return isspace(c);
Packit b89d10
Packit b89d10
  if (c >= 0x09 && c <= 0x0d) return 1;
Packit b89d10
  if (c == 0x20) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
    if (c == 0x85) return 1;
Packit b89d10
    /* fall */
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_2:
Packit b89d10
  case ISO_8859_3:
Packit b89d10
  case ISO_8859_4:
Packit b89d10
  case ISO_8859_5:
Packit b89d10
  case ISO_8859_6:
Packit b89d10
  case ISO_8859_7:
Packit b89d10
  case ISO_8859_8:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
  case ISO_8859_10:
Packit b89d10
  case ISO_8859_11:
Packit b89d10
  case ISO_8859_13:
Packit b89d10
  case ISO_8859_14:
Packit b89d10
  case ISO_8859_15:
Packit b89d10
  case ISO_8859_16:
Packit b89d10
  case KOI8:
Packit b89d10
    if (c == 0xa0) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c == 0x9a) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsUpper(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return isupper(c);
Packit b89d10
Packit b89d10
  if (c >= 0x41 && c <= 0x5a) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xde) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_2:
Packit b89d10
    if (c == 0xa1 || c == 0xa3) return 1;
Packit b89d10
    if (c == 0xa5 || c == 0xa6) return 1;
Packit b89d10
    if (c >= 0xa9 && c <= 0xac) return 1;
Packit b89d10
    if (c >= 0xae && c <= 0xaf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xde) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_3:
Packit b89d10
    if (c == 0xa1) return 1;
Packit b89d10
    if (c == 0xa6) return 1;
Packit b89d10
    if (c >= 0xa9 && c <= 0xac) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xc2) return 1;
Packit b89d10
    if (c >= 0xc4 && c <= 0xcf) return 1;
Packit b89d10
    if (c >= 0xd1 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xde) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_4:
Packit b89d10
    if (c == 0xa1 || c == 0xa3) return 1;
Packit b89d10
    if (c == 0xa5 || c == 0xa6) return 1;
Packit b89d10
    if (c >= 0xa9 && c <= 0xac) return 1;
Packit b89d10
    if (c == 0xae) return 1;
Packit b89d10
    if (c == 0xbd) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xde) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_5:
Packit b89d10
    if (c >= 0xa1 && c <= 0xcf && c != 0xad) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_6:
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_7:
Packit b89d10
    if (c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb8 && c <= 0xba) return 1;
Packit b89d10
    if (c == 0xbc) return 1;
Packit b89d10
    if (c >= 0xbe && c <= 0xbf) return 1;
Packit b89d10
    if (c >= 0xc1 && c <= 0xdb && c != 0xd2) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_8:
Packit b89d10
  case ISO_8859_11:
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_10:
Packit b89d10
    if (c >= 0xa1 && c <= 0xa6) return 1;
Packit b89d10
    if (c >= 0xa8 && c <= 0xac) return 1;
Packit b89d10
    if (c == 0xae || c == 0xaf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xde) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_13:
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xde) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_14:
Packit b89d10
    if (c == 0xa1) return 1;
Packit b89d10
    if (c == 0xa4 || c == 0xa6) return 1;
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xaa || c == 0xac) return 1;
Packit b89d10
    if (c == 0xaf || c == 0xb0) return 1;
Packit b89d10
    if (c == 0xb2 || c == 0xb4 || c == 0xb7) return 1;
Packit b89d10
    if (c == 0xbb || c == 0xbd) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xde) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_15:
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xde) return 1;
Packit b89d10
    if (c == 0xa6) return 1;
Packit b89d10
    if (c == 0xb4) return 1;
Packit b89d10
    if (c == 0xbc) return 1;
Packit b89d10
    if (c == 0xbe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_16:
Packit b89d10
    if (c == 0xa1) return 1;
Packit b89d10
    if (c == 0xa3) return 1;
Packit b89d10
    if (c == 0xa6) return 1;
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xac) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c == 0xb2) return 1;
Packit b89d10
    if (c == 0xb4) return 1;
Packit b89d10
    if (c == 0xbc) return 1;
Packit b89d10
    if (c == 0xbe) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xde) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c == 0xb3) return 1;
Packit b89d10
    /* fall */
Packit b89d10
  case KOI8:
Packit b89d10
    if (c >= 0xe0 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsXDigit(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII)
Packit b89d10
    return isxdigit(c);
Packit b89d10
Packit b89d10
  if (c >= 0x30 && c <= 0x39) return 1;
Packit b89d10
  if (c >= 0x41 && c <= 0x46) return 1;
Packit b89d10
  if (c >= 0x61 && c <= 0x66) return 1;
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsWord(int enc, int c)
Packit b89d10
{
Packit b89d10
  if (enc == ASCII) {
Packit b89d10
    return (isalpha(c) || isdigit(c) || c == 0x5f);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  if (c >= 0x30 && c <= 0x39) return 1;
Packit b89d10
  if (c >= 0x41 && c <= 0x5a) return 1;
Packit b89d10
  if (c == 0x5f) return 1;
Packit b89d10
  if (c >= 0x61 && c <= 0x7a) return 1;
Packit b89d10
Packit b89d10
  switch (enc) {
Packit b89d10
  case UNICODE_ISO_8859_1:
Packit b89d10
  case ISO_8859_1:
Packit b89d10
  case ISO_8859_9:
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c >= 0xb2 && c <= 0xb3) return 1;
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xba) return 1;
Packit b89d10
    if (c >= 0xbc && c <= 0xbe) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_2:
Packit b89d10
    if (c == 0xa1 || c == 0xa3) return 1;
Packit b89d10
    if (c == 0xa5 || c == 0xa6) return 1;
Packit b89d10
    if (c >= 0xa9 && c <= 0xac) return 1;
Packit b89d10
    if (c >= 0xae && c <= 0xaf) return 1;
Packit b89d10
    if (c == 0xb1 || c == 0xb3) return 1;
Packit b89d10
    if (c == 0xb5 || c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xbc) return 1;
Packit b89d10
    if (c >= 0xbe && c <= 0xbf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_3:
Packit b89d10
    if (c == 0xa1) return 1;
Packit b89d10
    if (c == 0xa6) return 1;
Packit b89d10
    if (c >= 0xa9 && c <= 0xac) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c >= 0xb1 && c <= 0xb3) return 1;
Packit b89d10
    if (c == 0xb5 || c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xbd) return 1;
Packit b89d10
    if (c == 0xbf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xc2) return 1;
Packit b89d10
    if (c >= 0xc4 && c <= 0xcf) return 1;
Packit b89d10
    if (c >= 0xd1 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xe2) return 1;
Packit b89d10
    if (c >= 0xe4 && c <= 0xef) return 1;
Packit b89d10
    if (c >= 0xf1 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_4:
Packit b89d10
    if (c >= 0xa1 && c <= 0xa3) return 1;
Packit b89d10
    if (c == 0xa5 || c == 0xa6) return 1;
Packit b89d10
    if (c >= 0xa9 && c <= 0xac) return 1;
Packit b89d10
    if (c == 0xae) return 1;
Packit b89d10
    if (c == 0xb1 || c == 0xb3) return 1;
Packit b89d10
    if (c == 0xb5 || c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xbf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_5:
Packit b89d10
    if (c >= 0xa1 && c <= 0xcf && c != 0xad) return 1;
Packit b89d10
    if (c >= 0xd0 && c <= 0xff && c != 0xf0 && c != 0xfd) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_6:
Packit b89d10
    if (c >= 0xc1 && c <= 0xda) return 1;
Packit b89d10
    if (c >= 0xe0 && c <= 0xea) return 1;
Packit b89d10
    if (c >= 0xeb && c <= 0xf2) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_7:
Packit b89d10
    if (c == 0xb2 || c == 0xb3) return 1;
Packit b89d10
    if (c == 0xb6) return 1;
Packit b89d10
    if (c >= 0xb8 && c <= 0xba) return 1;
Packit b89d10
    if (c >= 0xbc && c <= 0xbf) return 1;
Packit b89d10
    if (c == 0xc0) return 1;
Packit b89d10
    if (c >= 0xc1 && c <= 0xdb && c != 0xd2) return 1;
Packit b89d10
    if (c >= 0xdc && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_8:
Packit b89d10
    if (c == 0xb2 || c == 0xb3 || c == 0xb5 || c == 0xb9) return 1;
Packit b89d10
    if (c >= 0xbc && c <= 0xbe) return 1;
Packit b89d10
    if (c >= 0xe0 && c <= 0xfa) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_10:
Packit b89d10
    if (c >= 0xa1 && c <= 0xff) {
Packit b89d10
      if (c != 0xa7 && c != 0xad && c != 0xb0 && c != 0xb7 && c != 0xbd)
Packit b89d10
	return 1;
Packit b89d10
    }
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_11:
Packit b89d10
    if (c >= 0xa1 && c <= 0xda) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xfb) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_13:
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c == 0xb2 || c == 0xb3 || c == 0xb5 || c == 0xb9) return 1;
Packit b89d10
    if (c >= 0xbc && c <= 0xbe) return 1;
Packit b89d10
    if (c == 0xb8) return 1;
Packit b89d10
    if (c == 0xba) return 1;
Packit b89d10
    if (c >= 0xbf && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xfe) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_14:
Packit b89d10
    if (c >= 0xa1 && c <= 0xff) {
Packit b89d10
      if (c == 0xa3 || c == 0xa7 || c == 0xa9 || c == 0xad || c == 0xae ||
Packit b89d10
	  c == 0xb6) return 0;
Packit b89d10
      return 1;
Packit b89d10
    }
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_15:
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c >= 0xb2 && c <= 0xb3) return 1;
Packit b89d10
    if (c == 0xb5) return 1;
Packit b89d10
    if (c >= 0xb9 && c <= 0xba) return 1;
Packit b89d10
    if (c >= 0xbc && c <= 0xbe) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xd6) return 1;
Packit b89d10
    if (c >= 0xd8 && c <= 0xf6) return 1;
Packit b89d10
    if (c >= 0xf8 && c <= 0xff) return 1;
Packit b89d10
    if (c == 0xa6) return 1;
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xb4) return 1;
Packit b89d10
    if (c == 0xb8) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case ISO_8859_16:
Packit b89d10
    if (c == 0xa1) return 1;
Packit b89d10
    if (c == 0xa2) return 1;
Packit b89d10
    if (c == 0xa3) return 1;
Packit b89d10
    if (c == 0xa6) return 1;
Packit b89d10
    if (c == 0xa8) return 1;
Packit b89d10
    if (c == 0xaa) return 1;
Packit b89d10
    if (c == 0xac) return 1;
Packit b89d10
    if (c == 0xae) return 1;
Packit b89d10
    if (c == 0xaf) return 1;
Packit b89d10
    if (c == 0xb2) return 1;
Packit b89d10
    if (c == 0xb3) return 1;
Packit b89d10
    if (c == 0xb4) return 1;
Packit b89d10
    if (c >= 0xb8 && c <= 0xba) return 1;
Packit b89d10
    if (c == 0xbc) return 1;
Packit b89d10
    if (c == 0xbd) return 1;
Packit b89d10
    if (c == 0xbe) return 1;
Packit b89d10
    if (c == 0xbf) return 1;
Packit b89d10
    if (c >= 0xc0 && c <= 0xde) return 1;
Packit b89d10
    if (c >= 0xdf && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  case KOI8_R:
Packit b89d10
    if (c == 0x9d) return 1;
Packit b89d10
    if (c == 0xa3 || c == 0xb3) return 1;
Packit b89d10
    /* fall */
Packit b89d10
  case KOI8:
Packit b89d10
    if (c >= 0xc0 && c <= 0xff) return 1;
Packit b89d10
    break;
Packit b89d10
Packit b89d10
  default:
Packit b89d10
    exit(-1);
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsAscii(int enc ARG_UNUSED, int c)
Packit b89d10
{
Packit b89d10
  if (c >= 0x00 && c <= 0x7f) return 1;
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int IsNewline(int enc ARG_UNUSED, int c)
Packit b89d10
{
Packit b89d10
  if (c == 0x0a) return 1;
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
static int exec(FILE* fp, ENC_INFO* einfo)
Packit b89d10
{
Packit b89d10
#define NCOL  8
Packit b89d10
Packit b89d10
  int c, val, enc;
Packit b89d10
  int r;
Packit b89d10
Packit b89d10
  enc = einfo->num;
Packit b89d10
Packit b89d10
  r = fprintf(fp, "static const unsigned short Enc%s_CtypeTable[256] = {\n",
Packit b89d10
              einfo->name);
Packit b89d10
  if (r < 0) return -1;
Packit b89d10
Packit b89d10
  for (c = 0; c < 256; c++) {
Packit b89d10
    val = 0;
Packit b89d10
    if (IsNewline(enc, c))  val |= BIT_CTYPE_NEWLINE;
Packit b89d10
    if (IsAlpha (enc, c))   val |= (BIT_CTYPE_ALPHA | BIT_CTYPE_ALNUM);
Packit b89d10
    if (IsBlank (enc, c))   val |= BIT_CTYPE_BLANK;
Packit b89d10
    if (IsCntrl (enc, c))   val |= BIT_CTYPE_CNTRL;
Packit b89d10
    if (IsDigit (enc, c))   val |= (BIT_CTYPE_DIGIT | BIT_CTYPE_ALNUM);
Packit b89d10
    if (IsGraph (enc, c))   val |= BIT_CTYPE_GRAPH;
Packit b89d10
    if (IsLower (enc, c))   val |= BIT_CTYPE_LOWER;
Packit b89d10
    if (IsPrint (enc, c))   val |= BIT_CTYPE_PRINT;
Packit b89d10
    if (IsPunct (enc, c))   val |= BIT_CTYPE_PUNCT;
Packit b89d10
    if (IsSpace (enc, c))   val |= BIT_CTYPE_SPACE;
Packit b89d10
    if (IsUpper (enc, c))   val |= BIT_CTYPE_UPPER;
Packit b89d10
    if (IsXDigit(enc, c))   val |= BIT_CTYPE_XDIGIT;
Packit b89d10
    if (IsWord  (enc, c))   val |= BIT_CTYPE_WORD;
Packit b89d10
    if (IsAscii (enc, c))   val |= BIT_CTYPE_ASCII;
Packit b89d10
Packit b89d10
    if (c % NCOL == 0) {
Packit b89d10
      r = fputs("  ", fp);
Packit b89d10
      if (r < 0) return -1;
Packit b89d10
    }
Packit b89d10
    r = fprintf(fp, "0x%04x", val);
Packit b89d10
    if (r < 0) return -1;
Packit b89d10
Packit b89d10
    if (c != 255) {
Packit b89d10
      r = fputs(",", fp);
Packit b89d10
      if (r < 0) return -1;
Packit b89d10
    }
Packit b89d10
    if (c != 0 && c % NCOL == (NCOL-1))
Packit b89d10
      r = fputs("\n", fp);
Packit b89d10
    else
Packit b89d10
      r = fputs(" ", fp);
Packit b89d10
Packit b89d10
    if (r < 0) return -1;
Packit b89d10
  }
Packit b89d10
  r = fprintf(fp, "};\n");
Packit b89d10
  if (r < 0) return -1;
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}
Packit b89d10
Packit b89d10
extern int main(int argc ARG_UNUSED, char* argv[] ARG_UNUSED)
Packit b89d10
{
Packit b89d10
  int r;
Packit b89d10
  int i;
Packit b89d10
  FILE* fp = stdout;
Packit b89d10
Packit b89d10
  setlocale(LC_ALL, "C");
Packit b89d10
  /* setlocale(LC_ALL, "POSIX"); */
Packit b89d10
  /* setlocale(LC_ALL, "en_GB.iso88591"); */
Packit b89d10
  /* setlocale(LC_ALL, "de_BE.iso88591"); */
Packit b89d10
  /* setlocale(LC_ALL, "fr_FR.iso88591"); */
Packit b89d10
Packit b89d10
  for (i = 0; i < (int )(sizeof(Info)/sizeof(ENC_INFO)); i++) {
Packit b89d10
    r = exec(fp, &Info[i]);
Packit b89d10
    if (r < 0) {
Packit b89d10
      fprintf(stderr, "FAIL exec(): %d\n", r);
Packit b89d10
      return -1;
Packit b89d10
    }
Packit b89d10
  }
Packit b89d10
Packit b89d10
  return 0;
Packit b89d10
}