Merge branch 'linux1'
[oweals/cde.git] / cde / programs / dthelp / parser / pass2 / util / paramu.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: paramu.c /main/3 1995/11/08 11:07:11 rswiston $ */
24 /*
25               Copyright 1986 Tandem Computers Incorporated.
26 This product and information is proprietary of Tandem Computers Incorporated.
27                    Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co.
28 */
29
30 /* Paramu.c contains functions for programs ELTDEF and PARSER
31    relevant to checking parameter values. */
32
33 /* Check to see if string is a valid value for parameter par.  If so
34    return a pointer to the keyword if it's a keyword parameter and otherwise
35    a pointer to string.  If not valid, return FALSE. */
36 #if defined(M_PROTO)
37 const M_WCHAR *m_partype(const int par , const M_WCHAR *string )
38 #else
39 M_WCHAR *m_partype(par, string)
40   int par ;
41   M_WCHAR *string ;
42 #endif /* M_PROTO */
43   {
44     LOGICAL first = TRUE ;
45     int kw ;
46     const M_WCHAR *p = string ;
47     int len ;
48
49     if (m_parameter[par - 1].type == M_KEYWORD) {
50       for (kw = m_parameter[par - 1].kwlist ; kw ; kw = m_ptype[kw - 1].next)
51         if (! m_wcupstrcmp(&m_keyword[m_ptype[kw - 1].keyword], string))
52           return(&m_keyword[m_ptype[kw - 1].keyword]) ;
53       return(FALSE) ;
54       }
55     if (m_parameter[par - 1].type == M_CDATT) return(string) ;
56     if (! *string) return(FALSE) ;
57     if (m_allwhite(string)) return(FALSE) ;
58     len = 0 ;
59     for ( ; *p ; p++)
60       switch (m_cttype(*p)) {
61         case M_NONNAME:
62           switch (m_parameter[par - 1].type) {
63             case M_ID:
64             case M_IDRF:
65             case M_NAMEPAR:
66             case M_NMTOKEN:
67             case M_NUMBER:
68             case M_NUTOKEN:
69             case M_ENTATT:
70               return(FALSE) ;
71             default:
72               len = 0 ;
73               if (! m_whitespace(*p)) return(FALSE) ;
74             }
75           first = TRUE ;
76           break ;
77         case M_NMSTART:
78           len++ ;
79           if (len > M_NAMELEN) return(FALSE) ;
80           if (m_parameter[par - 1].type == M_NUMBER ||
81               m_parameter[par - 1].type == M_NUMS) return(FALSE) ;
82           first = FALSE ;
83           break ;
84         case M_NAMECHAR:
85           len++ ;
86           if (len > M_NAMELEN) return(FALSE) ;
87           switch (m_parameter[par - 1].type) {
88             case M_ID:
89             case M_IDRF:
90             case M_IDRFS:
91             case M_NAMEPAR:
92             case M_NAMES:
93             case M_ENTATT:
94               if (first) return(FALSE) ;
95               break ;
96             case M_NMTOKEN:
97             case M_NMSTOKEN:
98               break ;
99             case M_NUMBER:
100             case M_NUMS:
101               return(FALSE) ;
102             case M_NUTOKEN:
103             case M_NUSTOKEN:
104               if (first) return(FALSE) ;
105               break ;
106             default:
107               m_error("Undefined parameter type") ;
108               m_exit(TRUE) ;
109             }
110           break ;
111         case M_DIGIT:
112           len++ ;
113           if (len > M_NAMELEN) return(FALSE) ;
114           switch (m_parameter[par - 1].type) {
115             case M_ID:
116             case M_IDRF:
117             case M_IDRFS:
118             case M_NAMEPAR:
119             case M_NAMES:
120             case M_ENTATT:
121               if (first) return(FALSE) ;
122               break ;
123             case M_NUMBER:
124             case M_NUMS:
125               break ;
126             case M_NMTOKEN:
127             case M_NMSTOKEN:
128             case M_NUTOKEN:
129             case M_NUSTOKEN:
130               first = FALSE ;
131               break ;
132             default:
133               m_error("Undefined parameter type") ;
134               m_exit(TRUE) ;
135             }
136           break ;
137         default:
138           m_error("Undefined character type") ;
139           m_exit(TRUE) ;
140         }
141     if (m_parameter[par - 1].type == M_ENTATT) {
142       if ((M_ENTITY *) m_lookfortrie(string, m_enttrie))
143         return(string) ;
144       else return(FALSE) ;
145       }
146     return(string) ;
147     }