acpixtract.c revision 1.7 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: acpixtract - convert ascii ACPI tables to binary
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.2 christos /*
8 1.6 christos * Copyright (C) 2000 - 2016, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.2 christos * Redistribution and use in source and binary forms, with or without
12 1.2 christos * modification, are permitted provided that the following conditions
13 1.2 christos * are met:
14 1.2 christos * 1. Redistributions of source code must retain the above copyright
15 1.2 christos * notice, this list of conditions, and the following disclaimer,
16 1.2 christos * without modification.
17 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.2 christos * including a substantially similar Disclaimer requirement for further
21 1.2 christos * binary redistribution.
22 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.2 christos * of any contributors may be used to endorse or promote products derived
24 1.2 christos * from this software without specific prior written permission.
25 1.2 christos *
26 1.2 christos * Alternatively, this software may be distributed under the terms of the
27 1.2 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.2 christos * Software Foundation.
29 1.2 christos *
30 1.2 christos * NO WARRANTY
31 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.2 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.2 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.2 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.2 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.2 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.2 christos */
43 1.2 christos
44 1.6 christos #include "acpixtract.h"
45 1.1 jruoho
46 1.1 jruoho
47 1.7 christos /* Local prototypes */
48 1.7 christos
49 1.7 christos static BOOLEAN
50 1.7 christos AxIsFileAscii (
51 1.7 christos FILE *Handle);
52 1.7 christos
53 1.7 christos
54 1.2 christos /******************************************************************************
55 1.2 christos *
56 1.6 christos * FUNCTION: AxExtractTables
57 1.2 christos *
58 1.6 christos * PARAMETERS: InputPathname - Filename for input acpidump file
59 1.6 christos * Signature - Requested ACPI signature to extract.
60 1.6 christos * NULL means extract ALL tables.
61 1.6 christos * MinimumInstances - Min instances that are acceptable
62 1.2 christos *
63 1.6 christos * RETURN: Status
64 1.2 christos *
65 1.6 christos * DESCRIPTION: Convert text ACPI tables to binary
66 1.2 christos *
67 1.2 christos ******************************************************************************/
68 1.2 christos
69 1.6 christos int
70 1.6 christos AxExtractTables (
71 1.6 christos char *InputPathname,
72 1.6 christos char *Signature,
73 1.6 christos unsigned int MinimumInstances)
74 1.2 christos {
75 1.6 christos FILE *InputFile;
76 1.6 christos FILE *OutputFile = NULL;
77 1.6 christos unsigned int BytesConverted;
78 1.6 christos unsigned int ThisTableBytesWritten = 0;
79 1.6 christos unsigned int FoundTable = 0;
80 1.6 christos unsigned int Instances = 0;
81 1.6 christos unsigned int ThisInstance;
82 1.7 christos char ThisSignature[5];
83 1.7 christos char UpperSignature[5];
84 1.6 christos int Status = 0;
85 1.6 christos unsigned int State = AX_STATE_FIND_HEADER;
86 1.2 christos
87 1.2 christos
88 1.6 christos /* Open input in text mode, output is in binary mode */
89 1.2 christos
90 1.6 christos InputFile = fopen (InputPathname, "rt");
91 1.6 christos if (!InputFile)
92 1.2 christos {
93 1.6 christos printf ("Could not open input file %s\n", InputPathname);
94 1.6 christos return (-1);
95 1.2 christos }
96 1.2 christos
97 1.7 christos if (!AxIsFileAscii (InputFile))
98 1.7 christos {
99 1.7 christos fclose (InputFile);
100 1.7 christos return (-1);
101 1.7 christos }
102 1.7 christos
103 1.6 christos if (Signature)
104 1.1 jruoho {
105 1.7 christos strncpy (UpperSignature, Signature, 4);
106 1.7 christos UpperSignature[4] = 0;
107 1.7 christos AcpiUtStrupr (UpperSignature);
108 1.7 christos
109 1.6 christos /* Are there enough instances of the table to continue? */
110 1.1 jruoho
111 1.7 christos AxNormalizeSignature (UpperSignature);
112 1.1 jruoho
113 1.7 christos Instances = AxCountTableInstances (InputPathname, UpperSignature);
114 1.6 christos if (Instances < MinimumInstances)
115 1.6 christos {
116 1.6 christos printf ("Table [%s] was not found in %s\n",
117 1.7 christos UpperSignature, InputPathname);
118 1.6 christos fclose (InputFile);
119 1.6 christos return (-1);
120 1.6 christos }
121 1.1 jruoho
122 1.6 christos if (Instances == 0)
123 1.6 christos {
124 1.6 christos fclose (InputFile);
125 1.6 christos return (-1);
126 1.6 christos }
127 1.1 jruoho }
128 1.1 jruoho
129 1.6 christos /* Convert all instances of the table to binary */
130 1.1 jruoho
131 1.6 christos while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
132 1.1 jruoho {
133 1.6 christos switch (State)
134 1.6 christos {
135 1.6 christos case AX_STATE_FIND_HEADER:
136 1.1 jruoho
137 1.6 christos if (!AxIsDataBlockHeader ())
138 1.6 christos {
139 1.6 christos continue;
140 1.6 christos }
141 1.1 jruoho
142 1.6 christos ACPI_MOVE_NAME (ThisSignature, Gbl_LineBuffer);
143 1.6 christos if (Signature)
144 1.6 christos {
145 1.6 christos /* Ignore signatures that don't match */
146 1.1 jruoho
147 1.7 christos if (!ACPI_COMPARE_NAME (ThisSignature, UpperSignature))
148 1.6 christos {
149 1.6 christos continue;
150 1.6 christos }
151 1.6 christos }
152 1.1 jruoho
153 1.6 christos /*
154 1.6 christos * Get the instance number for this signature. Only the
155 1.6 christos * SSDT and PSDT tables can have multiple instances.
156 1.6 christos */
157 1.6 christos ThisInstance = AxGetNextInstance (InputPathname, ThisSignature);
158 1.1 jruoho
159 1.6 christos /* Build an output filename and create/open the output file */
160 1.1 jruoho
161 1.6 christos if (ThisInstance > 0)
162 1.6 christos {
163 1.6 christos /* Add instance number to the output filename */
164 1.1 jruoho
165 1.6 christos sprintf (Gbl_OutputFilename, "%4.4s%u.dat",
166 1.6 christos ThisSignature, ThisInstance);
167 1.6 christos }
168 1.6 christos else
169 1.6 christos {
170 1.6 christos sprintf (Gbl_OutputFilename, "%4.4s.dat",
171 1.6 christos ThisSignature);
172 1.6 christos }
173 1.1 jruoho
174 1.6 christos AcpiUtStrlwr (Gbl_OutputFilename);
175 1.6 christos OutputFile = fopen (Gbl_OutputFilename, "w+b");
176 1.6 christos if (!OutputFile)
177 1.6 christos {
178 1.6 christos printf ("Could not open output file %s\n",
179 1.6 christos Gbl_OutputFilename);
180 1.6 christos fclose (InputFile);
181 1.6 christos return (-1);
182 1.6 christos }
183 1.1 jruoho
184 1.6 christos /*
185 1.6 christos * Toss this block header of the form "<sig> @ <addr>" line
186 1.6 christos * and move on to the actual data block
187 1.6 christos */
188 1.6 christos Gbl_TableCount++;
189 1.6 christos FoundTable = 1;
190 1.6 christos ThisTableBytesWritten = 0;
191 1.6 christos State = AX_STATE_EXTRACT_DATA;
192 1.6 christos continue;
193 1.1 jruoho
194 1.6 christos case AX_STATE_EXTRACT_DATA:
195 1.1 jruoho
196 1.6 christos /* Empty line or non-data line terminates the data block */
197 1.1 jruoho
198 1.6 christos BytesConverted = AxProcessOneTextLine (
199 1.6 christos OutputFile, ThisSignature, ThisTableBytesWritten);
200 1.6 christos switch (BytesConverted)
201 1.6 christos {
202 1.6 christos case 0:
203 1.1 jruoho
204 1.6 christos State = AX_STATE_FIND_HEADER; /* No more data block lines */
205 1.6 christos continue;
206 1.1 jruoho
207 1.6 christos case -1:
208 1.1 jruoho
209 1.6 christos goto CleanupAndExit; /* There was a write error */
210 1.1 jruoho
211 1.6 christos default: /* Normal case, get next line */
212 1.1 jruoho
213 1.6 christos ThisTableBytesWritten += BytesConverted;
214 1.6 christos continue;
215 1.6 christos }
216 1.1 jruoho
217 1.6 christos default:
218 1.1 jruoho
219 1.6 christos Status = -1;
220 1.6 christos goto CleanupAndExit;
221 1.1 jruoho }
222 1.1 jruoho }
223 1.1 jruoho
224 1.6 christos if (!FoundTable)
225 1.6 christos {
226 1.7 christos printf ("No ACPI tables were found in %s\n", InputPathname);
227 1.6 christos }
228 1.1 jruoho
229 1.1 jruoho
230 1.6 christos CleanupAndExit:
231 1.1 jruoho
232 1.6 christos if (State == AX_STATE_EXTRACT_DATA)
233 1.1 jruoho {
234 1.6 christos /* Received an input file EOF while extracting data */
235 1.1 jruoho
236 1.6 christos printf (AX_TABLE_INFO_FORMAT,
237 1.6 christos ThisSignature, ThisTableBytesWritten, Gbl_OutputFilename);
238 1.1 jruoho }
239 1.1 jruoho
240 1.6 christos if (Gbl_TableCount > 1)
241 1.1 jruoho {
242 1.7 christos printf ("\n%u binary ACPI tables extracted\n",
243 1.6 christos Gbl_TableCount);
244 1.1 jruoho }
245 1.1 jruoho
246 1.6 christos if (OutputFile)
247 1.1 jruoho {
248 1.6 christos fclose (OutputFile);
249 1.1 jruoho }
250 1.1 jruoho
251 1.6 christos fclose (InputFile);
252 1.6 christos return (Status);
253 1.1 jruoho }
254 1.1 jruoho
255 1.1 jruoho
256 1.1 jruoho /******************************************************************************
257 1.1 jruoho *
258 1.6 christos * FUNCTION: AxExtractToMultiAmlFile
259 1.1 jruoho *
260 1.6 christos * PARAMETERS: InputPathname - Filename for input acpidump file
261 1.1 jruoho *
262 1.1 jruoho * RETURN: Status
263 1.1 jruoho *
264 1.6 christos * DESCRIPTION: Convert all DSDT/SSDT tables to binary and append them all
265 1.6 christos * into a single output file. Used to simplify the loading of
266 1.6 christos * multiple/many SSDTs into a utility like acpiexec -- instead
267 1.6 christos * of creating many separate output files.
268 1.1 jruoho *
269 1.1 jruoho ******************************************************************************/
270 1.1 jruoho
271 1.1 jruoho int
272 1.6 christos AxExtractToMultiAmlFile (
273 1.6 christos char *InputPathname)
274 1.1 jruoho {
275 1.1 jruoho FILE *InputFile;
276 1.6 christos FILE *OutputFile;
277 1.6 christos int Status = 0;
278 1.6 christos unsigned int TotalBytesWritten = 0;
279 1.6 christos unsigned int ThisTableBytesWritten = 0;
280 1.6 christos unsigned int BytesConverted;
281 1.6 christos char ThisSignature[4];
282 1.2 christos unsigned int State = AX_STATE_FIND_HEADER;
283 1.1 jruoho
284 1.1 jruoho
285 1.6 christos strcpy (Gbl_OutputFilename, AX_MULTI_TABLE_FILENAME);
286 1.6 christos
287 1.6 christos /* Open the input file in text mode */
288 1.1 jruoho
289 1.1 jruoho InputFile = fopen (InputPathname, "rt");
290 1.1 jruoho if (!InputFile)
291 1.1 jruoho {
292 1.6 christos printf ("Could not open input file %s\n", InputPathname);
293 1.1 jruoho return (-1);
294 1.1 jruoho }
295 1.1 jruoho
296 1.7 christos if (!AxIsFileAscii (InputFile))
297 1.7 christos {
298 1.7 christos fclose (InputFile);
299 1.7 christos return (-1);
300 1.7 christos }
301 1.7 christos
302 1.6 christos /* Open the output file in binary mode */
303 1.6 christos
304 1.6 christos OutputFile = fopen (Gbl_OutputFilename, "w+b");
305 1.6 christos if (!OutputFile)
306 1.1 jruoho {
307 1.6 christos printf ("Could not open output file %s\n", Gbl_OutputFilename);
308 1.6 christos fclose (InputFile);
309 1.6 christos return (-1);
310 1.1 jruoho }
311 1.1 jruoho
312 1.6 christos /* Convert the DSDT and all SSDTs to binary */
313 1.1 jruoho
314 1.6 christos while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
315 1.1 jruoho {
316 1.1 jruoho switch (State)
317 1.1 jruoho {
318 1.2 christos case AX_STATE_FIND_HEADER:
319 1.2 christos
320 1.6 christos if (!AxIsDataBlockHeader ())
321 1.2 christos {
322 1.2 christos continue;
323 1.2 christos }
324 1.1 jruoho
325 1.6 christos ACPI_MOVE_NAME (ThisSignature, Gbl_LineBuffer);
326 1.1 jruoho
327 1.6 christos /* Only want DSDT and SSDTs */
328 1.1 jruoho
329 1.6 christos if (!ACPI_COMPARE_NAME (ThisSignature, ACPI_SIG_DSDT) &&
330 1.6 christos !ACPI_COMPARE_NAME (ThisSignature, ACPI_SIG_SSDT))
331 1.2 christos {
332 1.2 christos continue;
333 1.2 christos }
334 1.2 christos
335 1.1 jruoho /*
336 1.6 christos * Toss this block header of the form "<sig> @ <addr>" line
337 1.6 christos * and move on to the actual data block
338 1.1 jruoho */
339 1.6 christos Gbl_TableCount++;
340 1.6 christos ThisTableBytesWritten = 0;
341 1.2 christos State = AX_STATE_EXTRACT_DATA;
342 1.1 jruoho continue;
343 1.1 jruoho
344 1.2 christos case AX_STATE_EXTRACT_DATA:
345 1.1 jruoho
346 1.6 christos /* Empty line or non-data line terminates the data block */
347 1.1 jruoho
348 1.6 christos BytesConverted = AxProcessOneTextLine (
349 1.6 christos OutputFile, ThisSignature, ThisTableBytesWritten);
350 1.6 christos switch (BytesConverted)
351 1.1 jruoho {
352 1.6 christos case 0:
353 1.1 jruoho
354 1.6 christos State = AX_STATE_FIND_HEADER; /* No more data block lines */
355 1.1 jruoho continue;
356 1.1 jruoho
357 1.6 christos case -1:
358 1.1 jruoho
359 1.6 christos goto CleanupAndExit; /* There was a write error */
360 1.1 jruoho
361 1.6 christos default: /* Normal case, get next line */
362 1.1 jruoho
363 1.6 christos ThisTableBytesWritten += BytesConverted;
364 1.6 christos TotalBytesWritten += BytesConverted;
365 1.6 christos continue;
366 1.1 jruoho }
367 1.1 jruoho
368 1.1 jruoho default:
369 1.2 christos
370 1.1 jruoho Status = -1;
371 1.1 jruoho goto CleanupAndExit;
372 1.1 jruoho }
373 1.1 jruoho }
374 1.1 jruoho
375 1.1 jruoho
376 1.1 jruoho CleanupAndExit:
377 1.1 jruoho
378 1.6 christos if (State == AX_STATE_EXTRACT_DATA)
379 1.1 jruoho {
380 1.6 christos /* Received an input file EOF or error while writing data */
381 1.1 jruoho
382 1.6 christos printf (AX_TABLE_INFO_FORMAT,
383 1.6 christos ThisSignature, ThisTableBytesWritten, Gbl_OutputFilename);
384 1.1 jruoho }
385 1.1 jruoho
386 1.7 christos printf ("\n%u binary ACPI tables extracted and written to %s (%u bytes)\n",
387 1.6 christos Gbl_TableCount, Gbl_OutputFilename, TotalBytesWritten);
388 1.6 christos
389 1.1 jruoho fclose (InputFile);
390 1.6 christos fclose (OutputFile);
391 1.1 jruoho return (Status);
392 1.1 jruoho }
393 1.1 jruoho
394 1.1 jruoho
395 1.1 jruoho /******************************************************************************
396 1.1 jruoho *
397 1.2 christos * FUNCTION: AxListTables
398 1.1 jruoho *
399 1.1 jruoho * PARAMETERS: InputPathname - Filename for acpidump file
400 1.1 jruoho *
401 1.1 jruoho * RETURN: Status
402 1.1 jruoho *
403 1.1 jruoho * DESCRIPTION: Display info for all ACPI tables found in input. Does not
404 1.1 jruoho * perform an actual extraction of the tables.
405 1.1 jruoho *
406 1.1 jruoho ******************************************************************************/
407 1.1 jruoho
408 1.1 jruoho int
409 1.2 christos AxListTables (
410 1.1 jruoho char *InputPathname)
411 1.1 jruoho {
412 1.1 jruoho FILE *InputFile;
413 1.1 jruoho size_t HeaderSize;
414 1.1 jruoho unsigned char Header[48];
415 1.1 jruoho ACPI_TABLE_HEADER *TableHeader = (ACPI_TABLE_HEADER *) (void *) Header;
416 1.1 jruoho
417 1.1 jruoho
418 1.1 jruoho /* Open input in text mode, output is in binary mode */
419 1.1 jruoho
420 1.1 jruoho InputFile = fopen (InputPathname, "rt");
421 1.1 jruoho if (!InputFile)
422 1.1 jruoho {
423 1.6 christos printf ("Could not open input file %s\n", InputPathname);
424 1.1 jruoho return (-1);
425 1.1 jruoho }
426 1.1 jruoho
427 1.7 christos if (!AxIsFileAscii (InputFile))
428 1.7 christos {
429 1.7 christos fclose (InputFile);
430 1.7 christos return (-1);
431 1.7 christos }
432 1.7 christos
433 1.1 jruoho /* Dump the headers for all tables found in the input file */
434 1.1 jruoho
435 1.2 christos printf ("\nSignature Length Revision OemId OemTableId"
436 1.6 christos " OemRevision CompilerId CompilerRevision\n\n");
437 1.1 jruoho
438 1.6 christos while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
439 1.1 jruoho {
440 1.1 jruoho /* Ignore empty lines and lines that start with a space */
441 1.1 jruoho
442 1.6 christos if (AxIsEmptyLine (Gbl_LineBuffer) ||
443 1.6 christos (Gbl_LineBuffer[0] == ' '))
444 1.1 jruoho {
445 1.1 jruoho continue;
446 1.1 jruoho }
447 1.1 jruoho
448 1.1 jruoho /* Get the 36 byte header and display the fields */
449 1.1 jruoho
450 1.2 christos HeaderSize = AxGetTableHeader (InputFile, Header);
451 1.1 jruoho if (HeaderSize < 16)
452 1.1 jruoho {
453 1.1 jruoho continue;
454 1.1 jruoho }
455 1.1 jruoho
456 1.1 jruoho /* RSDP has an oddball signature and header */
457 1.1 jruoho
458 1.1 jruoho if (!strncmp (TableHeader->Signature, "RSD PTR ", 8))
459 1.1 jruoho {
460 1.2 christos AxCheckAscii ((char *) &Header[9], 6);
461 1.6 christos printf ("%7.4s \"%6.6s\"\n", "RSDP",
462 1.6 christos &Header[9]);
463 1.6 christos Gbl_TableCount++;
464 1.1 jruoho continue;
465 1.1 jruoho }
466 1.1 jruoho
467 1.1 jruoho /* Minimum size for table with standard header */
468 1.1 jruoho
469 1.2 christos if (HeaderSize < sizeof (ACPI_TABLE_HEADER))
470 1.1 jruoho {
471 1.1 jruoho continue;
472 1.1 jruoho }
473 1.1 jruoho
474 1.7 christos if (!AcpiUtValidNameseg (TableHeader->Signature))
475 1.7 christos {
476 1.7 christos continue;
477 1.7 christos }
478 1.7 christos
479 1.1 jruoho /* Signature and Table length */
480 1.1 jruoho
481 1.6 christos Gbl_TableCount++;
482 1.6 christos printf ("%7.4s 0x%8.8X", TableHeader->Signature,
483 1.6 christos TableHeader->Length);
484 1.1 jruoho
485 1.1 jruoho /* FACS has only signature and length */
486 1.1 jruoho
487 1.2 christos if (ACPI_COMPARE_NAME (TableHeader->Signature, "FACS"))
488 1.1 jruoho {
489 1.1 jruoho printf ("\n");
490 1.1 jruoho continue;
491 1.1 jruoho }
492 1.1 jruoho
493 1.1 jruoho /* OEM IDs and Compiler IDs */
494 1.1 jruoho
495 1.2 christos AxCheckAscii (TableHeader->OemId, 6);
496 1.2 christos AxCheckAscii (TableHeader->OemTableId, 8);
497 1.2 christos AxCheckAscii (TableHeader->AslCompilerId, 4);
498 1.1 jruoho
499 1.6 christos printf (
500 1.6 christos " 0x%2.2X \"%6.6s\" \"%8.8s\" 0x%8.8X"
501 1.6 christos " \"%4.4s\" 0x%8.8X\n",
502 1.1 jruoho TableHeader->Revision, TableHeader->OemId,
503 1.1 jruoho TableHeader->OemTableId, TableHeader->OemRevision,
504 1.1 jruoho TableHeader->AslCompilerId, TableHeader->AslCompilerRevision);
505 1.1 jruoho }
506 1.1 jruoho
507 1.7 christos printf ("\nFound %u ACPI tables in %s\n", Gbl_TableCount, InputPathname);
508 1.1 jruoho fclose (InputFile);
509 1.1 jruoho return (0);
510 1.1 jruoho }
511 1.7 christos
512 1.7 christos
513 1.7 christos /*******************************************************************************
514 1.7 christos *
515 1.7 christos * FUNCTION: AxIsFileAscii
516 1.7 christos *
517 1.7 christos * PARAMETERS: Handle - To open input file
518 1.7 christos *
519 1.7 christos * RETURN: TRUE if file is entirely ASCII and printable
520 1.7 christos *
521 1.7 christos * DESCRIPTION: Verify that the input file is entirely ASCII.
522 1.7 christos *
523 1.7 christos ******************************************************************************/
524 1.7 christos
525 1.7 christos static BOOLEAN
526 1.7 christos AxIsFileAscii (
527 1.7 christos FILE *Handle)
528 1.7 christos {
529 1.7 christos UINT8 Byte;
530 1.7 christos
531 1.7 christos
532 1.7 christos /* Read the entire file */
533 1.7 christos
534 1.7 christos while (fread (&Byte, 1, 1, Handle) == 1)
535 1.7 christos {
536 1.7 christos /* Check for an ASCII character */
537 1.7 christos
538 1.7 christos if (!ACPI_IS_ASCII (Byte))
539 1.7 christos {
540 1.7 christos goto ErrorExit;
541 1.7 christos }
542 1.7 christos
543 1.7 christos /* Ensure character is either printable or a "space" char */
544 1.7 christos
545 1.7 christos else if (!isprint (Byte) && !isspace (Byte))
546 1.7 christos {
547 1.7 christos goto ErrorExit;
548 1.7 christos }
549 1.7 christos }
550 1.7 christos
551 1.7 christos /* File is OK (100% ASCII) */
552 1.7 christos
553 1.7 christos fseek (Handle, 0, SEEK_SET);
554 1.7 christos return (TRUE);
555 1.7 christos
556 1.7 christos ErrorExit:
557 1.7 christos
558 1.7 christos printf ("File is binary (contains non-text or non-ascii characters)\n");
559 1.7 christos fseek (Handle, 0, SEEK_SET);
560 1.7 christos return (FALSE);
561 1.7 christos
562 1.7 christos }
563