tc.nls.h revision 145479
1145479Smp/* $Header: /src/pub/tcsh/tc.nls.h,v 3.9 2005/03/03 15:52:20 kim Exp $ */
2145479Smp/*
3145479Smp * tc.nls.h: NLS support
4145479Smp *
5145479Smp */
6145479Smp/*-
7145479Smp * Copyright (c) 1980, 1991 The Regents of the University of California.
8145479Smp * All rights reserved.
9145479Smp *
10145479Smp * Redistribution and use in source and binary forms, with or without
11145479Smp * modification, are permitted provided that the following conditions
12145479Smp * are met:
13145479Smp * 1. Redistributions of source code must retain the above copyright
14145479Smp *    notice, this list of conditions and the following disclaimer.
15145479Smp * 2. Redistributions in binary form must reproduce the above copyright
16145479Smp *    notice, this list of conditions and the following disclaimer in the
17145479Smp *    documentation and/or other materials provided with the distribution.
18145479Smp * 3. Neither the name of the University nor the names of its contributors
19145479Smp *    may be used to endorse or promote products derived from this software
20145479Smp *    without specific prior written permission.
21145479Smp *
22145479Smp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23145479Smp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24145479Smp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25145479Smp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26145479Smp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27145479Smp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28145479Smp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29145479Smp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30145479Smp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31145479Smp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32145479Smp * SUCH DAMAGE.
33145479Smp */
34145479Smp#ifndef _h_tc_nls
35145479Smp#define _h_tc_nls
36145479Smp
37145479Smp#include "sh.h"
38145479Smp
39145479Smp#define NLSZEROT	((size_t)-1)
40145479Smp
41145479Smp#ifdef WIDE_STRINGS
42145479Smp
43145479Smp# define NLSSize(s, l) 1
44145479Smp# define NLSFrom(s, l, cp) (USE (l), (*(cp) = *(s) & CHAR), 1)
45145479Smp# define NLSFinished(s, l, c) (l != 0 && c != CHAR_ERR ? 2 : 1)
46145479Smp# define NLSChars(s) Strlen(s)
47145479Smp# define NLSQuote(s)
48145479Smp# define TRIM_AND_EXTEND(s, c) (c &= TRIM)
49145479Smp
50145479Smpextern int NLSWidth __P((NLSChar));
51145479Smpextern int NLSStringWidth __P((Char *));
52145479Smp
53145479Smp#define NLS_ILLEGAL INVALID_BYTE
54145479Smp
55145479Smp#else
56145479Smp# ifdef SHORT_STRINGS
57145479Smp
58145479Smpextern int NLSFrom __P((const Char *, size_t, NLSChar *));
59145479Smpextern int NLSFinished __P((Char *, size_t, eChar));
60145479Smpextern int NLSChars __P((Char *));
61145479Smpextern int NLSStringWidth __P((Char *));
62145479Smpextern int NLSWidth __P((NLSChar));
63145479Smpextern int NLSTo __P((Char *, NLSChar));
64145479Smpextern void NLSQuote __P((Char *));
65145479Smp
66145479Smp#define NLSSize(s, l) NLSFrom(s, l, (NLSChar *)0)
67145479Smp#define TRIM_AND_EXTEND(s, c) (s += NLSFrom(s - 1, NLSZEROT, &c) - 1)
68145479Smp#define NLS_ILLEGAL 0x40000000
69145479Smp
70145479Smp
71145479Smp# else
72145479Smp#  define NLSSize(s, l) 1
73145479Smp#  define NLSFrom(s, l, cp) (USE (l), (*(cp) = *(s) & CHAR), 1)
74145479Smp#  define NLSFinished(s, l, c) (l != 0 && c != CHAR_ERR ? 2 : 1)
75145479Smp#  define NLSChars(s) Strlen(s)
76145479Smp#  define NLSStringWidth(s) Strlen(s)
77145479Smp#  define NLSWidth(c) 1
78145479Smp#  define NLSQuote(s)
79145479Smp
80145479Smp#  define TRIM_AND_EXTEND(s, c) (c &= TRIM)
81145479Smp#  define NLS_ILLEGAL 0x40000000
82145479Smp# endif
83145479Smp#endif
84145479Smp
85145479Smpextern int NLSExtend __P((Char *, int, int));
86145479Smpextern Char *NLSChangeCase __P((Char *, int));
87145479Smpextern int NLSClassify __P((NLSChar, int));
88145479Smp
89145479Smp#define NLSCLASS_CTRL		(-1)
90145479Smp#define NLSCLASS_TAB		(-2)
91145479Smp#define NLSCLASS_NL		(-3)
92145479Smp#define NLSCLASS_ILLEGAL	(-4)
93145479Smp#define NLSCLASS_ILLEGAL2	(-5)
94145479Smp#define NLSCLASS_ILLEGAL3	(-6)
95145479Smp#define NLSCLASS_ILLEGAL4	(-7)
96145479Smp
97145479Smp#define NLSCLASS_ILLEGAL_SIZE(x) (-(x) - (-(NLSCLASS_ILLEGAL) - 1))
98145479Smp
99145479Smp#endif
100