Rev 1498 | Details | Compare with Previous | 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 - 2011, Intel Corp. |
||
2216 | Serge | 12 | * All rights reserved. |
1498 | serge | 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 (" -h Insert dual-license header into all modules\n"); |
||
2216 | Serge | 343 | printf (" -l Generate Linux version of the source\n"); |
1498 | serge | 344 | printf (" -u Generate Custom source translation\n"); |
345 | printf ("\n"); |
||
346 | printf (" -d Leave debug statements in code\n"); |
||
347 | printf (" -s Generate source statistics only\n"); |
||
348 | printf (" -v Verbose mode\n"); |
||
349 | printf (" -y Suppress file overwrite prompts\n"); |
||
350 | printf ("\n"); |
||
351 | return; |
||
352 | } |
||
353 | |||
354 | |||
355 | |||
356 | * |
||
357 | * FUNCTION: main |
||
358 | * |
||
359 | * DESCRIPTION: C main function |
||
360 | * |
||
361 | ******************************************************************************/ |
||
362 | |||
363 | |||
364 | main ( |
||
365 | int argc, |
||
366 | char *argv[]) |
||
367 | { |
||
368 | int j; |
||
369 | ACPI_CONVERSION_TABLE *ConversionTable = NULL; |
||
370 | char *SourcePath; |
||
371 | char *TargetPath; |
||
372 | UINT32 FileType; |
||
373 | |||
374 | |||
375 | |||
2216 | Serge | 376 | |
1498 | serge | 377 | |
378 | { |
||
379 | AsDisplayUsage (); |
||
380 | return 0; |
||
381 | } |
||
382 | |||
383 | |||
384 | |||
385 | |||
2216 | Serge | 386 | { |
1498 | serge | 387 | case 'l': |
388 | /* Linux code generation */ |
||
389 | |||
390 | |||
391 | ConversionTable = &LinuxConversionTable; |
||
392 | Gbl_WidenDeclarations = TRUE; |
||
393 | Gbl_IgnoreLoneLineFeeds = TRUE; |
||
394 | break; |
||
395 | |||
396 | |||
397 | /* Cleanup code */ |
||
398 | |||
399 | |||
400 | ConversionTable = &CleanupConversionTable; |
||
401 | break; |
||
402 | |||
403 | |||
2216 | Serge | 404 | /* Inject Dual-license header */ |
405 | |||
406 | |||
407 | ConversionTable = &LicenseConversionTable; |
||
408 | break; |
||
409 | |||
410 | |||
1498 | serge | 411 | /* Statistics only */ |
412 | |||
413 | |||
414 | |||
415 | |||
416 | /* custom conversion */ |
||
417 | |||
418 | |||
419 | ConversionTable = &CustomConversionTable; |
||
420 | break; |
||
421 | |||
422 | |||
423 | /* Verbose mode */ |
||
424 | |||
425 | |||
426 | break; |
||
427 | |||
428 | |||
429 | /* Batch mode */ |
||
430 | |||
431 | |||
432 | break; |
||
433 | |||
434 | |||
435 | /* Leave debug statements in */ |
||
436 | |||
437 | |||
438 | break; |
||
439 | |||
440 | |||
441 | /* Quiet mode */ |
||
442 | |||
443 | |||
444 | break; |
||
445 | |||
446 | |||
447 | AsDisplayUsage (); |
||
448 | return -1; |
||
449 | } |
||
450 | |||
451 | |||
452 | |||
453 | if (!SourcePath) |
||
454 | { |
||
455 | printf ("Missing source path\n"); |
||
456 | AsDisplayUsage (); |
||
457 | return -1; |
||
458 | } |
||
459 | |||
460 | |||
461 | |||
462 | |||
463 | { |
||
464 | /* Just generate statistics. Ignore target path */ |
||
465 | |||
466 | |||
467 | |||
468 | |||
469 | ConversionTable = &StatsConversionTable; |
||
470 | } |
||
471 | else if (!TargetPath) |
||
472 | { |
||
473 | TargetPath = SourcePath; |
||
474 | } |
||
475 | |||
476 | |||
477 | { |
||
478 | ConversionTable->SourceFunctions &= ~CVT_REMOVE_DEBUG_MACROS; |
||
479 | } |
||
480 | |||
481 | |||
482 | |||
483 | |||
484 | { |
||
485 | return -1; |
||
486 | } |
||
487 | |||
488 | |||
489 | |||
490 | |||
491 | { |
||
492 | /* Process the directory tree */ |
||
493 | |||
494 | |||
495 | } |
||
496 | else |
||
497 | { |
||
498 | /* Process a single file */ |
||
499 | |||
500 | |||
501 | |||
502 | |||
503 | { |
||
504 | AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_HEADER); |
||
505 | } |
||
506 | else |
||
507 | { |
||
508 | AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_SOURCE); |
||
509 | } |
||
510 | } |
||
511 | |||
512 | |||
513 | |||
514 | |||
515 | |||
516 | |||
517 | }> |
||
518 |