]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/tools/acpihelp/ahmain.c
Import ACPICA 20120111.
[FreeBSD/FreeBSD.git] / source / tools / acpihelp / ahmain.c
1 /******************************************************************************
2  *
3  * Module Name: ahmain - Main module for the acpi help utility
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2012, 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
49 static void
50 AhDisplayUsage (
51     void);
52
53
54 /******************************************************************************
55  *
56  * FUNCTION:    AhDisplayUsage
57  *
58  * DESCRIPTION: Usage message
59  *
60  ******************************************************************************/
61
62 static void
63 AhDisplayUsage (
64     void)
65 {
66
67     ACPI_USAGE_HEADER ("acpihelp <options> [NamePrefix | HexValue]");
68     ACPI_OPTION ("-h",                      "Display help");
69     ACPI_OPTION ("-i",                      "Display known ACPI Device IDs (_HID)");
70     ACPI_OPTION ("-k [NamePrefix]",         "Find/Display ASL non-operator keyword(s)");
71     ACPI_OPTION ("-m [NamePrefix]",         "Find/Display AML opcode name(s)");
72     ACPI_OPTION ("-o [HexValue]",           "Decode hex AML opcode");
73     ACPI_OPTION ("-p [NamePrefix]",         "Find/Display ASL predefined method name(s)");
74     ACPI_OPTION ("-s [NamePrefix]",         "Find/Display ASL operator name(s)");
75     printf ("\nNamePrefix/HexValue not specified means \"Display All\"\n");
76     printf ("\nDefault search with NamePrefix and no options:\n");
77     printf ("    Find ASL operator names - if NamePrefix does not start with underscore\n");
78     printf ("    Find ASL predefined method names - if NamePrefix starts with underscore\n");
79 }
80
81
82 /******************************************************************************
83  *
84  * FUNCTION:    main
85  *
86  * DESCRIPTION: C main function for AcpiHelp utility.
87  *
88  ******************************************************************************/
89
90 int ACPI_SYSTEM_XFACE
91 main (
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, "hikmops")) != EOF) switch (j)
112     {
113     case 'i':
114         DecodeType = AH_DISPLAY_DEVICE_IDS;
115         break;
116
117     case 'k':
118         DecodeType = AH_DECODE_ASL_KEYWORD;
119         break;
120
121     case 'm':
122         DecodeType = AH_DECODE_AML;
123         break;
124
125     case 'o':
126         DecodeType = AH_DECODE_AML_OPCODE;
127         break;
128
129     case 'p':
130         DecodeType = AH_DECODE_PREDEFINED_NAME;
131         break;
132
133     case 's':
134         DecodeType = AH_DECODE_ASL;
135         break;
136
137     case 'h':
138     default:
139         AhDisplayUsage ();
140         return (-1);
141     }
142
143     /* Missing (null) name means "display all" */
144
145     Name = argv[AcpiGbl_Optind];
146
147     switch (DecodeType)
148     {
149     case AH_DECODE_AML:
150         AhFindAmlOpcode (Name);
151         break;
152
153     case AH_DECODE_AML_OPCODE:
154         AhDecodeAmlOpcode (Name);
155         break;
156
157     case AH_DECODE_PREDEFINED_NAME:
158         AhFindPredefinedNames (Name);
159         break;
160
161     case AH_DECODE_ASL:
162         AhFindAslOperators (Name);
163         break;
164
165     case AH_DECODE_ASL_KEYWORD:
166         AhFindAslKeywords (Name);
167         break;
168
169     case AH_DISPLAY_DEVICE_IDS:
170         AhDisplayDeviceIds ();
171         break;
172
173     default:
174         if (!Name)
175         {
176             AhFindAslOperators (Name);
177             break;
178         }
179
180         if (*Name == '_')
181         {
182             AhFindPredefinedNames (Name);
183         }
184         else
185         {
186             AhFindAslOperators (Name);
187         }
188         break;
189     }
190
191     return (0);
192 }
193
194
195 /*******************************************************************************
196  *
197  * FUNCTION:    AhStrupr (strupr)
198  *
199  * PARAMETERS:  SrcString           - The source string to convert
200  *
201  * RETURN:      None
202  *
203  * DESCRIPTION: Convert string to uppercase
204  *
205  * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
206  *
207  ******************************************************************************/
208
209 void
210 AhStrupr (
211     char                    *SrcString)
212 {
213     char                    *String;
214
215
216     if (!SrcString)
217     {
218         return;
219     }
220
221     /* Walk entire string, uppercasing the letters */
222
223     for (String = SrcString; *String; String++)
224     {
225         *String = (char) toupper ((int) *String);
226     }
227
228     return;
229 }