xref: /titanic_52/usr/src/lib/libxcurses/h/m_ord.h (revision 25c28e83beb90e7c80452a7c818c5e6f73a07dc8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1996, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * m_ord.h
31  *
32  * Copyright 1986, 1992 by Mortice Kern Systems Inc.  All rights reserved.
33  *
34  * $Header: /rd/h/rcs/m_ord.h 1.15 1994/05/29 16:17:02 mark Exp $
35  */
36 
37 #ifndef __M_M_ORD_H__
38 #define __M_M_ORD_H__
39 
40 #ifndef UCHAR_MAX
41 #include <limits.h>
42 #endif
43 
44 /*
45  * Used with CURSES in order to decern whether or not 'x' is a byte
46  * or a KEY_xxxx macro, which are defined to be values greater than
47  * UCHAR_MAX.
48  */
49 #define m_ischarset(x)	((unsigned)(x) <= UCHAR_MAX)
50 
51 #ifdef M_NOT_646
52 LEXTERN int m_ord ANSI((wint_t));
53 LEXTERN wint_t m_chr ANSI((int));
54 #else
55 /* ASCII based macros */
56 /*
57  * m_ord(c) : convert alpha character(case insensitive) to an an ordinal value.
58  *            if c is an alphabetic character (A-Z,a-z), this returns
59  *            a number between 1 and 26
60  * m_chr(i) : convert an ordinal value to its corresponding alpha character
61  *            using the reverse mapping as m_ord().
62  *            if i is a number between 1 and 26 it returns the corresponding
63  *  	      alphabetic character A to Z
64  */
65 #include <ctype.h>
66 #define m_ord(c) \
67 	(m_ischarset(c)&&('A'<=towupper(c)&&towupper(c)<='Z')?towupper(c)-'@':-1)
68 #define m_chr(c)	(1 <= c && c <= 26 ? c+'@' : -1)
69 #endif /* _POSIX_SOURCE */
70 
71 #endif /* __M_M_ORD_H__ */
72