1/******************************************************************************
2 *
3 * Module Name: ahmain - Main module for the acpi help utility
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2011, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions, and the following disclaimer,
16 *    without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 *    substantially similar to the "NO WARRANTY" disclaimer below
19 *    ("Disclaimer") and any redistribution must be conditioned upon
20 *    including a substantially similar Disclaimer requirement for further
21 *    binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 *    of any contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include "acpihelp.h"
45
46
47/* Local prototypes */
48
49static void
50AhDisplayUsage (
51    void);
52
53
54/******************************************************************************
55 *
56 * FUNCTION:    AhDisplayUsage
57 *
58 * DESCRIPTION: Usage message
59 *
60 ******************************************************************************/
61
62static void
63AhDisplayUsage (
64    void)
65{
66
67    printf ("\n");
68    printf ("Usage: acpihelp <options> [NamePrefix | HexValue]\n\n");
69    printf ("Where: -k [NamePrefix]     Find/Display ASL non-operator keyword(s)\n");
70    printf ("       -m [NamePrefix]     Find/Display AML opcode name(s)\n");
71    printf ("       -o [HexValue]       Decode hex AML opcode\n");
72    printf ("       -p [NamePrefix]     Find/Display ASL predefined method name(s)\n");
73    printf ("       -s [NamePrefix]     Find/Display ASL operator name(s)\n");
74    printf ("\nNamePrefix/HexValue not specified means \"Display All\"\n");
75    printf ("\nDefault search with NamePrefix and no options:\n");
76    printf ("    Find ASL operator names - if NamePrefix does not start with underscore\n");
77    printf ("    Find ASL predefined method names - if NamePrefix starts with underscore\n");
78    printf ("\n");
79}
80
81
82/******************************************************************************
83 *
84 * FUNCTION:    main
85 *
86 * DESCRIPTION: C main function for AcpiHelp utility.
87 *
88 ******************************************************************************/
89
90int ACPI_SYSTEM_XFACE
91main (
92    int                     argc,
93    char                    *argv[])
94{
95    char                    *Name;
96    UINT32                  DecodeType;
97    int                     j;
98
99
100    printf (ACPI_COMMON_SIGNON ("ACPI Help Utility"));
101    DecodeType = AH_DECODE_DEFAULT;
102
103    if (argc < 2)
104    {
105        AhDisplayUsage ();
106        return (0);
107    }
108
109    /* Command line options */
110
111    while ((j = AcpiGetopt (argc, argv, "hkmops")) != EOF) switch (j)
112    {
113    case 'k':
114        DecodeType = AH_DECODE_ASL_KEYWORD;
115        break;
116
117    case 'm':
118        DecodeType = AH_DECODE_AML;
119        break;
120
121    case 'o':
122        DecodeType = AH_DECODE_AML_OPCODE;
123        break;
124
125    case 'p':
126        DecodeType = AH_DECODE_PREDEFINED_NAME;
127        break;
128
129    case 's':
130        DecodeType = AH_DECODE_ASL;
131        break;
132
133    case 'h':
134    default:
135        AhDisplayUsage ();
136        return (-1);
137    }
138
139    /* Missing (null) name means "display all" */
140
141    Name = argv[AcpiGbl_Optind];
142
143    switch (DecodeType)
144    {
145    case AH_DECODE_AML:
146        AhFindAmlOpcode (Name);
147        break;
148
149    case AH_DECODE_AML_OPCODE:
150        AhDecodeAmlOpcode (Name);
151        break;
152
153    case AH_DECODE_PREDEFINED_NAME:
154        AhFindPredefinedNames (Name);
155        break;
156
157    case AH_DECODE_ASL:
158        AhFindAslOperators (Name);
159        break;
160
161    case AH_DECODE_ASL_KEYWORD:
162        AhFindAslKeywords (Name);
163        break;
164
165    default:
166        if (!Name)
167        {
168            AhFindAslOperators (Name);
169            break;
170        }
171
172        if (*Name == '_')
173        {
174            AhFindPredefinedNames (Name);
175        }
176        else
177        {
178            AhFindAslOperators (Name);
179        }
180        break;
181    }
182
183    return (0);
184}
185
186
187/*******************************************************************************
188 *
189 * FUNCTION:    AhStrupr (strupr)
190 *
191 * PARAMETERS:  SrcString           - The source string to convert
192 *
193 * RETURN:      None
194 *
195 * DESCRIPTION: Convert string to uppercase
196 *
197 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
198 *
199 ******************************************************************************/
200
201void
202AhStrupr (
203    char                    *SrcString)
204{
205    char                    *String;
206
207
208    if (!SrcString)
209    {
210        return;
211    }
212
213    /* Walk entire string, uppercasing the letters */
214
215    for (String = SrcString; *String; String++)
216    {
217        *String = (char) toupper ((int) *String);
218    }
219
220    return;
221}
222