Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dthelp / parser / pass2 / parser / findpar.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: findpar.c /main/3 1995/11/08 10:52:30 rswiston $ */
24 /*
25                    Copyright 1989 Hewlett-Packard Co.
26 */
27
28 #include <stdio.h>
29 #include "basic.h"
30 #include "trie.h"
31 #include "dtdext.h"
32 #include "parser.h"
33
34 /* Function callable by interface designers.  Returns index in parameter
35    list of a specified parameter for an element (i.e., 1 for first parameter
36    specified in the DTD, 2 for second, etc.).  First parameter, elt, is
37    the name of the element.  Second parameter is the name of the parameter
38    or NULL.  Third parameter is used only if second parameter is NULL.  In
39    the latter case, function returns first keyword parameter, if any, for
40    which the specified  value is a legal value and otherwise first
41    Returns 0 if elt is not a valid element name, if param is specified
42    but is not a valid parameter name, or if param is NULL and value is
43    not a valid value of any of elt's parameters. */
44 #if defined(M_PROTO)
45 int m_findpar( const char *elt , const char *param , const M_WCHAR *value )
46 #else
47 int m_findpar(elt, param, value)
48 char *elt ;
49 char *param ;
50 M_WCHAR *value ;
51 #endif /* M_PROTO */
52 {
53 M_ELEMENT eltid ;
54 int par ;
55 int i ;
56 M_WCHAR *wc_elt;
57
58 wc_elt = MakeWideCharString(elt);
59 if (! (eltid = m_packedlook(m_entree, wc_elt)))
60     {
61     m_free(wc_elt,"wide character string");
62     return(M_NULLVAL) ;
63     }
64 m_free(wc_elt,"wide character string");
65
66 /* A parameter name specified */
67 if (param)
68     {
69     for (par = m_element[eltid - 1].parptr, i = 1 ;
70
71     i <= m_element[eltid - 1].parcount ;
72     par++, i++)
73     if (!m_wcmbupstrcmp(&m_pname[m_parameter[par - 1].paramname], param))
74     return(i) ;
75     return(M_NULLVAL) ;
76     }
77
78 /* No parameter name specified */
79
80 /* First check is it a valid keyword? */
81 for (par = m_element[eltid - 1].parptr, i = 1 ;
82      i <= m_element[eltid - 1].parcount ;
83      par++, i++)
84 if (m_parameter[par - 1].type == M_KEYWORD)
85 if (m_partype(par, value)) return(i) ;
86
87 /* It wasn't a keyword.  Check for valid value for some other parameter.*/
88 for (par = m_element[eltid - 1].parptr, i = 1 ;
89 i <= m_element[eltid - 1].parcount ;
90 par++, i++)
91     {
92     if (m_parameter[par - 1].type == M_KEYWORD) continue ;
93     if (m_partype(par, value)) return(i) ;
94     }
95
96 /* Not a valid value for any parameter */
97 return(M_NULLVAL) ;
98 }
99