Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1498 | serge | 1 | |
2 | * |
||
3 | * Module Name: asmain - Main module for the acpi source processor utility |
||
4 | * |
||
5 | *****************************************************************************/ |
||
6 | |||
7 | |||
8 | * |
||
9 | * 1. Copyright Notice |
||
10 | * |
||
11 | * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. |
||
12 | * All rights reserved. |
||
13 | * |
||
14 | * 2. License |
||
15 | * |
||
16 | * 2.1. This is your license from Intel Corp. under its intellectual property |
||
17 | * rights. You may have additional license terms from the party that provided |
||
18 | * you this software, covering your right to use that party's intellectual |
||
19 | * property rights. |
||
20 | * |
||
21 | * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a |
||
22 | * copy of the source code appearing in this file ("Covered Code") an |
||
23 | * irrevocable, perpetual, worldwide license under Intel's copyrights in the |
||
24 | * base code distributed originally by Intel ("Original Intel Code") to copy, |
||
25 | * make derivatives, distribute, use and display any portion of the Covered |
||
26 | * Code in any form, with the right to sublicense such rights; and |
||
27 | * |
||
28 | * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent |
||
29 | * license (with the right to sublicense), under only those claims of Intel |
||
30 | * patents that are infringed by the Original Intel Code, to make, use, sell, |
||
31 | * offer to sell, and import the Covered Code and derivative works thereof |
||
32 | * solely to the minimum extent necessary to exercise the above copyright |
||
33 | * license, and in no event shall the patent license extend to any additions |
||
34 | * to or modifications of the Original Intel Code. No other license or right |
||
35 | * is granted directly or by implication, estoppel or otherwise; |
||
36 | * |
||
37 | * The above copyright and patent license is granted only if the following |
||
38 | * conditions are met: |
||
39 | * |
||
40 | * 3. Conditions |
||
41 | * |
||
42 | * 3.1. Redistribution of Source with Rights to Further Distribute Source. |
||
43 | * Redistribution of source code of any substantial portion of the Covered |
||
44 | * Code or modification with rights to further distribute source must include |
||
45 | * the above Copyright Notice, the above License, this list of Conditions, |
||
46 | * and the following Disclaimer and Export Compliance provision. In addition, |
||
47 | * Licensee must cause all Covered Code to which Licensee contributes to |
||
48 | * contain a file documenting the changes Licensee made to create that Covered |
||
49 | * Code and the date of any change. Licensee must include in that file the |
||
50 | * documentation of any changes made by any predecessor Licensee. Licensee |
||
51 | * must include a prominent statement that the modification is derived, |
||
52 | * directly or indirectly, from Original Intel Code. |
||
53 | * |
||
54 | * 3.2. Redistribution of Source with no Rights to Further Distribute Source. |
||
55 | * Redistribution of source code of any substantial portion of the Covered |
||
56 | * Code or modification without rights to further distribute source must |
||
57 | * include the following Disclaimer and Export Compliance provision in the |
||
58 | * documentation and/or other materials provided with distribution. In |
||
59 | * addition, Licensee may not authorize further sublicense of source of any |
||
60 | * portion of the Covered Code, and must include terms to the effect that the |
||
61 | * license from Licensee to its licensee is limited to the intellectual |
||
62 | * property embodied in the software Licensee provides to its licensee, and |
||
63 | * not to intellectual property embodied in modifications its licensee may |
||
64 | * make. |
||
65 | * |
||
66 | * 3.3. Redistribution of Executable. Redistribution in executable form of any |
||
67 | * substantial portion of the Covered Code or modification must reproduce the |
||
68 | * above Copyright Notice, and the following Disclaimer and Export Compliance |
||
69 | * provision in the documentation and/or other materials provided with the |
||
70 | * distribution. |
||
71 | * |
||
72 | * 3.4. Intel retains all right, title, and interest in and to the Original |
||
73 | * Intel Code. |
||
74 | * |
||
75 | * 3.5. Neither the name Intel nor any other trademark owned or controlled by |
||
76 | * Intel shall be used in advertising or otherwise to promote the sale, use or |
||
77 | * other dealings in products derived from or relating to the Covered Code |
||
78 | * without prior written authorization from Intel. |
||
79 | * |
||
80 | * 4. Disclaimer and Export Compliance |
||
81 | * |
||
82 | * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED |
||
83 | * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE |
||
84 | * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, |
||
85 | * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY |
||
86 | * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY |
||
87 | * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A |
||
88 | * PARTICULAR PURPOSE. |
||
89 | * |
||
90 | * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES |
||
91 | * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR |
||
92 | * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, |
||
93 | * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY |
||
94 | * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL |
||
95 | * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS |
||
96 | * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY |
||
97 | * LIMITED REMEDY. |
||
98 | * |
||
99 | * 4.3. Licensee shall not export, either directly or indirectly, any of this |
||
100 | * software or system incorporating such software without first obtaining any |
||
101 | * required license or other approval from the U. S. Department of Commerce or |
||
102 | * any other agency or department of the United States Government. In the |
||
103 | * event Licensee exports any such software from the United States or |
||
104 | * re-exports any such software from a foreign destination, Licensee shall |
||
105 | * ensure that the distribution and export/re-export of the software is in |
||
106 | * compliance with all laws, regulations, orders, or other restrictions of the |
||
107 | * U.S. Export Administration Regulations. Licensee agrees that neither it nor |
||
108 | * any of its subsidiaries will export/re-export any technical data, process, |
||
109 | * software, or service, directly or indirectly, to any country for which the |
||
110 | * United States government or any agency thereof requires an export license, |
||
111 | * other governmental approval, or letter of assurance, without first obtaining |
||
112 | * such license, approval or letter. |
||
113 | * |
||
114 | *****************************************************************************/ |
||
115 | |||
116 | |||
117 | |||
118 | #include "acapps.h" |
||
119 | |||
120 | |||
121 | |||
122 | |||
123 | AsStricmp ( |
||
124 | char *String1, |
||
125 | char *String2); |
||
126 | |||
127 | |||
128 | AsExaminePaths ( |
||
129 | ACPI_CONVERSION_TABLE *ConversionTable, |
||
130 | char *Source, |
||
131 | char *Target, |
||
132 | UINT32 *SourceFileType); |
||
133 | |||
134 | |||
135 | AsDisplayStats ( |
||
136 | void); |
||
137 | |||
138 | |||
139 | AsDisplayUsage ( |
||
140 | void); |
||
141 | |||
142 | |||
143 | |||
144 | |||
145 | UINT32 Gbl_MissingBraces = 0; |
||
146 | UINT32 Gbl_NonAnsiComments = 0; |
||
147 | UINT32 Gbl_Files = 0; |
||
148 | UINT32 Gbl_WhiteLines = 0; |
||
149 | UINT32 Gbl_CommentLines = 0; |
||
150 | UINT32 Gbl_SourceLines = 0; |
||
151 | UINT32 Gbl_LongLines = 0; |
||
152 | UINT32 Gbl_TotalLines = 0; |
||
153 | UINT32 Gbl_TotalSize = 0; |
||
154 | UINT32 Gbl_HeaderLines = 0; |
||
155 | UINT32 Gbl_HeaderSize = 0; |
||
156 | void *Gbl_StructDefs = NULL; |
||
157 | |||
158 | |||
159 | char *Gbl_FileBuffer; |
||
160 | UINT32 Gbl_FileSize; |
||
161 | UINT32 Gbl_FileType; |
||
162 | BOOLEAN Gbl_VerboseMode = FALSE; |
||
163 | BOOLEAN Gbl_QuietMode = FALSE; |
||
164 | BOOLEAN Gbl_BatchMode = FALSE; |
||
165 | BOOLEAN Gbl_DebugStatementsMode = FALSE; |
||
166 | BOOLEAN Gbl_MadeChanges = FALSE; |
||
167 | BOOLEAN Gbl_Overwrite = FALSE; |
||
168 | BOOLEAN Gbl_WidenDeclarations = FALSE; |
||
169 | BOOLEAN Gbl_IgnoreLoneLineFeeds = FALSE; |
||
170 | BOOLEAN Gbl_HasLoneLineFeeds = FALSE; |
||
171 | |||
172 | |||
173 | |||
174 | * |
||
175 | * FUNCTION: AsStricmp |
||
176 | * |
||
177 | * DESCRIPTION: Implementation of the non-ANSI stricmp function (compare |
||
178 | * strings with no case sensitivity) |
||
179 | * |
||
180 | ******************************************************************************/ |
||
181 | |||
182 | |||
183 | AsStricmp ( |
||
184 | char *String1, |
||
185 | char *String2) |
||
186 | { |
||
187 | int c1; |
||
188 | int c2; |
||
189 | |||
190 | |||
191 | |||
192 | { |
||
193 | c1 = tolower ((int) *String1); |
||
194 | c2 = tolower ((int) *String2); |
||
195 | |||
196 | |||
197 | String2++; |
||
198 | } |
||
199 | while ((c1 == c2) && (c1)); |
||
200 | |||
201 | |||
202 | } |
||
203 | |||
204 | |||
205 | |||
206 | * |
||
207 | * FUNCTION: AsExaminePaths |
||
208 | * |
||
209 | * DESCRIPTION: Source and Target pathname verification and handling |
||
210 | * |
||
211 | ******************************************************************************/ |
||
212 | |||
213 | |||
214 | AsExaminePaths ( |
||
215 | ACPI_CONVERSION_TABLE *ConversionTable, |
||
216 | char *Source, |
||
217 | char *Target, |
||
218 | UINT32 *SourceFileType) |
||
219 | { |
||
220 | int Status; |
||
221 | char Response; |
||
222 | |||
223 | |||
224 | |||
225 | if (Status) |
||
226 | { |
||
227 | printf ("Source path \"%s\" does not exist\n", Source); |
||
228 | return -1; |
||
229 | } |
||
230 | |||
231 | |||
232 | |||
233 | |||
234 | if (Gbl_StatBuf.st_mode & S_IFDIR) |
||
235 | { |
||
236 | *SourceFileType = S_IFDIR; |
||
237 | } |
||
238 | |||
239 | |||
240 | * If we are in no-output mode or in batch mode, we are done |
||
241 | */ |
||
242 | if ((ConversionTable->Flags & FLG_NO_FILE_OUTPUT) || |
||
243 | (Gbl_BatchMode)) |
||
244 | { |
||
245 | return 0; |
||
246 | } |
||
247 | |||
248 | |||
249 | { |
||
250 | printf ("Target path is the same as the source path, overwrite?\n"); |
||
251 | scanf ("%c", &Response); |
||
252 | |||
253 | |||
254 | |||
255 | |||
256 | { |
||
257 | return -1; |
||
258 | } |
||
259 | |||
260 | |||
261 | } |
||
262 | else |
||
263 | { |
||
264 | Status = stat (Target, &Gbl_StatBuf); |
||
265 | if (!Status) |
||
266 | { |
||
267 | printf ("Target path already exists, overwrite?\n"); |
||
268 | scanf ("%c", &Response); |
||
269 | |||
270 | |||
271 | |||
272 | |||
273 | { |
||
274 | return -1; |
||
275 | } |
||
276 | } |
||
277 | } |
||
278 | |||
279 | |||
280 | } |
||
281 | |||
282 | |||
283 | |||
284 | * |
||
285 | * FUNCTION: AsDisplayStats |
||
286 | * |
||
287 | * DESCRIPTION: Display global statistics gathered during translation |
||
288 | * |
||
289 | ******************************************************************************/ |
||
290 | |||
291 | |||
292 | AsDisplayStats ( |
||
293 | void) |
||
294 | { |
||
295 | |||
296 | |||
297 | { |
||
298 | return; |
||
299 | } |
||
300 | |||
301 | |||
302 | printf ("%8u Files processed\n", Gbl_Files); |
||
303 | printf ("%8u Total bytes (%.1fK/file)\n", |
||
304 | Gbl_TotalSize, ((double) Gbl_TotalSize/Gbl_Files)/1024); |
||
305 | printf ("%8u Tabs found\n", Gbl_Tabs); |
||
306 | printf ("%8u Missing if/else braces\n", Gbl_MissingBraces); |
||
307 | printf ("%8u Non-ANSI comments found\n", Gbl_NonAnsiComments); |
||
308 | printf ("%8u Total Lines\n", Gbl_TotalLines); |
||
309 | printf ("%8u Lines of code\n", Gbl_SourceLines); |
||
310 | printf ("%8u Lines of non-comment whitespace\n", Gbl_WhiteLines); |
||
311 | printf ("%8u Lines of comments\n", Gbl_CommentLines); |
||
312 | printf ("%8u Long lines found\n", Gbl_LongLines); |
||
313 | printf ("%8.1f Ratio of code to whitespace\n", |
||
314 | ((float) Gbl_SourceLines / (float) Gbl_WhiteLines)); |
||
315 | printf ("%8.1f Ratio of code to comments\n", |
||
316 | ((float) Gbl_SourceLines / (float) (Gbl_CommentLines + Gbl_NonAnsiComments))); |
||
317 | printf (" %u%% code, %u%% comments, %u%% whitespace, %u%% headers\n", |
||
318 | (Gbl_SourceLines * 100) / Gbl_TotalLines, |
||
319 | (Gbl_CommentLines * 100) / Gbl_TotalLines, |
||
320 | (Gbl_WhiteLines * 100) / Gbl_TotalLines, |
||
321 | (Gbl_HeaderLines * 100) / Gbl_TotalLines); |
||
322 | return; |
||
323 | } |
||
324 | |||
325 | |||
326 | |||
327 | * |
||
328 | * FUNCTION: AsDisplayUsage |
||
329 | * |
||
330 | * DESCRIPTION: Usage message |
||
331 | * |
||
332 | ******************************************************************************/ |
||
333 | |||
334 | |||
335 | AsDisplayUsage ( |
||
336 | void) |
||
337 | { |
||
338 | |||
339 | |||
340 | printf ("Usage: acpisrc [-c|l|u] [-dsvy] |
||
341 | printf ("Where: -c Generate cleaned version of the source\n"); |
||
342 | printf (" -l Generate Linux version of the source\n"); |
||
343 | printf (" -u Generate Custom source translation\n"); |
||
344 | printf ("\n"); |
||
345 | printf (" -d Leave debug statements in code\n"); |
||
346 | printf (" -s Generate source statistics only\n"); |
||
347 | printf (" -v Verbose mode\n"); |
||
348 | printf (" -y Suppress file overwrite prompts\n"); |
||
349 | printf ("\n"); |
||
350 | return; |
||
351 | } |
||
352 | |||
353 | |||
354 | |||
355 | * |
||
356 | * FUNCTION: main |
||
357 | * |
||
358 | * DESCRIPTION: C main function |
||
359 | * |
||
360 | ******************************************************************************/ |
||
361 | |||
362 | |||
363 | main ( |
||
364 | int argc, |
||
365 | char *argv[]) |
||
366 | { |
||
367 | int j; |
||
368 | ACPI_CONVERSION_TABLE *ConversionTable = NULL; |
||
369 | char *SourcePath; |
||
370 | char *TargetPath; |
||
371 | UINT32 FileType; |
||
372 | |||
373 | |||
374 | |||
375 | printf (" version %8.8X", ((UINT32) ACPI_CA_VERSION)); |
||
376 | printf (" [%s]\n\n", __DATE__); |
||
377 | |||
378 | |||
379 | { |
||
380 | AsDisplayUsage (); |
||
381 | return 0; |
||
382 | } |
||
383 | |||
384 | |||
385 | |||
386 | |||
387 | { |
||
388 | case 'l': |
||
389 | /* Linux code generation */ |
||
390 | |||
391 | |||
392 | ConversionTable = &LinuxConversionTable; |
||
393 | Gbl_WidenDeclarations = TRUE; |
||
394 | Gbl_IgnoreLoneLineFeeds = TRUE; |
||
395 | break; |
||
396 | |||
397 | |||
398 | /* Cleanup code */ |
||
399 | |||
400 | |||
401 | ConversionTable = &CleanupConversionTable; |
||
402 | break; |
||
403 | |||
404 | |||
405 | /* Statistics only */ |
||
406 | |||
407 | |||
408 | |||
409 | |||
410 | /* custom conversion */ |
||
411 | |||
412 | |||
413 | ConversionTable = &CustomConversionTable; |
||
414 | break; |
||
415 | |||
416 | |||
417 | /* Verbose mode */ |
||
418 | |||
419 | |||
420 | break; |
||
421 | |||
422 | |||
423 | /* Batch mode */ |
||
424 | |||
425 | |||
426 | break; |
||
427 | |||
428 | |||
429 | /* Leave debug statements in */ |
||
430 | |||
431 | |||
432 | break; |
||
433 | |||
434 | |||
435 | /* Quiet mode */ |
||
436 | |||
437 | |||
438 | break; |
||
439 | |||
440 | |||
441 | AsDisplayUsage (); |
||
442 | return -1; |
||
443 | } |
||
444 | |||
445 | |||
446 | |||
447 | if (!SourcePath) |
||
448 | { |
||
449 | printf ("Missing source path\n"); |
||
450 | AsDisplayUsage (); |
||
451 | return -1; |
||
452 | } |
||
453 | |||
454 | |||
455 | |||
456 | |||
457 | { |
||
458 | /* Just generate statistics. Ignore target path */ |
||
459 | |||
460 | |||
461 | |||
462 | |||
463 | ConversionTable = &StatsConversionTable; |
||
464 | } |
||
465 | else if (!TargetPath) |
||
466 | { |
||
467 | TargetPath = SourcePath; |
||
468 | } |
||
469 | |||
470 | |||
471 | { |
||
472 | ConversionTable->SourceFunctions &= ~CVT_REMOVE_DEBUG_MACROS; |
||
473 | } |
||
474 | |||
475 | |||
476 | |||
477 | |||
478 | { |
||
479 | return -1; |
||
480 | } |
||
481 | |||
482 | |||
483 | |||
484 | |||
485 | { |
||
486 | /* Process the directory tree */ |
||
487 | |||
488 | |||
489 | } |
||
490 | else |
||
491 | { |
||
492 | /* Process a single file */ |
||
493 | |||
494 | |||
495 | |||
496 | |||
497 | { |
||
498 | AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_HEADER); |
||
499 | } |
||
500 | else |
||
501 | { |
||
502 | AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_SOURCE); |
||
503 | } |
||
504 | } |
||
505 | |||
506 | |||
507 | |||
508 | |||
509 | |||
510 | |||
511 | }> |
||
512 |