cmap.cpp revision 114411
160484Sobrien// -*- C++ -*-
260484Sobrien/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
360484Sobrien     Written by James Clark (jjc@jclark.com)
460484Sobrien
560484SobrienThis file is part of groff.
660484Sobrien
760484Sobriengroff is free software; you can redistribute it and/or modify it under
860484Sobrienthe terms of the GNU General Public License as published by the Free
960484SobrienSoftware Foundation; either version 2, or (at your option) any later
1060484Sobrienversion.
1160484Sobrien
1260484Sobriengroff is distributed in the hope that it will be useful, but WITHOUT ANY
1360484SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or
1460484SobrienFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1560484Sobrienfor more details.
1660484Sobrien
1760484SobrienYou should have received a copy of the GNU General Public License along
1860484Sobrienwith groff; see the file COPYING.  If not, write to the Free Software
1960484SobrienFoundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2060484Sobrien
2160484Sobrien/* $FreeBSD: head/contrib/groff/src/libs/libgroff/cmap.cpp 114411 2003-05-01 13:18:55Z ru $ */
2260484Sobrien
2360484Sobrien#include <ctype.h>
2460484Sobrien#ifdef __FreeBSD__
2560484Sobrien#include <locale.h>
2660484Sobrien#endif
2760484Sobrien#include "cmap.h"
2860484Sobrien
2960484Sobriencmap cmlower(CMAP_BUILTIN);
3060484Sobriencmap cmupper(CMAP_BUILTIN);
3160484Sobrien
3260484Sobrien#if defined(isascii) && !defined(__FreeBSD__)
3360484Sobrien#define ISASCII(c) isascii(c)
3460484Sobrien#else
3560484Sobrien#define ISASCII(c) (1)
3660484Sobrien#endif
3760484Sobrien
3860484Sobriencmap::cmap()
3960484Sobrien{
4060484Sobrien  unsigned char *p = v;
4160484Sobrien  for (int i = 0; i <= UCHAR_MAX; i++)
4260484Sobrien    p[i] = i;
4360484Sobrien}
4460484Sobrien
4560484Sobriencmap::cmap(cmap_builtin)
4660484Sobrien{
4760484Sobrien  // these are initialised by cmap_init::cmap_init()
4860484Sobrien}
4960484Sobrien
5060484Sobrienint cmap_init::initialised = 0;
5160484Sobrien
5260484Sobriencmap_init::cmap_init()
5360484Sobrien{
5460484Sobrien  if (initialised)
5560484Sobrien    return;
5660484Sobrien  initialised = 1;
5760484Sobrien#ifdef __FreeBSD__
5860484Sobrien  (void) setlocale(LC_CTYPE, "");
5960484Sobrien#endif
6060484Sobrien  for (int i = 0; i <= UCHAR_MAX; i++) {
6160484Sobrien    cmupper.v[i] = ISASCII(i) && islower(i) ? toupper(i) : i;
6260484Sobrien    cmlower.v[i] = ISASCII(i) && isupper(i) ? tolower(i) : i;
6360484Sobrien  }
6460484Sobrien}
6560484Sobrien