![]() |
|
|||
File indexing completed on 2025-05-11 08:24:04
0001 /****************************************************************************** 0002 * 0003 * Module Name: utprint - Formatted printing routines 0004 * 0005 *****************************************************************************/ 0006 0007 /****************************************************************************** 0008 * 0009 * 1. Copyright Notice 0010 * 0011 * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp. 0012 * All rights reserved. 0013 * 0014 * 2. License 0015 * 0016 * 2.1. This is your license from Intel Corp. under its intellectual property 0017 * rights. You may have additional license terms from the party that provided 0018 * you this software, covering your right to use that party's intellectual 0019 * property rights. 0020 * 0021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 0022 * copy of the source code appearing in this file ("Covered Code") an 0023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 0024 * base code distributed originally by Intel ("Original Intel Code") to copy, 0025 * make derivatives, distribute, use and display any portion of the Covered 0026 * Code in any form, with the right to sublicense such rights; and 0027 * 0028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 0029 * license (with the right to sublicense), under only those claims of Intel 0030 * patents that are infringed by the Original Intel Code, to make, use, sell, 0031 * offer to sell, and import the Covered Code and derivative works thereof 0032 * solely to the minimum extent necessary to exercise the above copyright 0033 * license, and in no event shall the patent license extend to any additions 0034 * to or modifications of the Original Intel Code. No other license or right 0035 * is granted directly or by implication, estoppel or otherwise; 0036 * 0037 * The above copyright and patent license is granted only if the following 0038 * conditions are met: 0039 * 0040 * 3. Conditions 0041 * 0042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 0043 * Redistribution of source code of any substantial portion of the Covered 0044 * Code or modification with rights to further distribute source must include 0045 * the above Copyright Notice, the above License, this list of Conditions, 0046 * and the following Disclaimer and Export Compliance provision. In addition, 0047 * Licensee must cause all Covered Code to which Licensee contributes to 0048 * contain a file documenting the changes Licensee made to create that Covered 0049 * Code and the date of any change. Licensee must include in that file the 0050 * documentation of any changes made by any predecessor Licensee. Licensee 0051 * must include a prominent statement that the modification is derived, 0052 * directly or indirectly, from Original Intel Code. 0053 * 0054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 0055 * Redistribution of source code of any substantial portion of the Covered 0056 * Code or modification without rights to further distribute source must 0057 * include the following Disclaimer and Export Compliance provision in the 0058 * documentation and/or other materials provided with distribution. In 0059 * addition, Licensee may not authorize further sublicense of source of any 0060 * portion of the Covered Code, and must include terms to the effect that the 0061 * license from Licensee to its licensee is limited to the intellectual 0062 * property embodied in the software Licensee provides to its licensee, and 0063 * not to intellectual property embodied in modifications its licensee may 0064 * make. 0065 * 0066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 0067 * substantial portion of the Covered Code or modification must reproduce the 0068 * above Copyright Notice, and the following Disclaimer and Export Compliance 0069 * provision in the documentation and/or other materials provided with the 0070 * distribution. 0071 * 0072 * 3.4. Intel retains all right, title, and interest in and to the Original 0073 * Intel Code. 0074 * 0075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 0076 * Intel shall be used in advertising or otherwise to promote the sale, use or 0077 * other dealings in products derived from or relating to the Covered Code 0078 * without prior written authorization from Intel. 0079 * 0080 * 4. Disclaimer and Export Compliance 0081 * 0082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 0083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 0084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 0085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 0086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 0087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 0088 * PARTICULAR PURPOSE. 0089 * 0090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 0091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 0092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 0093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 0094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 0095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 0096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 0097 * LIMITED REMEDY. 0098 * 0099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 0100 * software or system incorporating such software without first obtaining any 0101 * required license or other approval from the U. S. Department of Commerce or 0102 * any other agency or department of the United States Government. In the 0103 * event Licensee exports any such software from the United States or 0104 * re-exports any such software from a foreign destination, Licensee shall 0105 * ensure that the distribution and export/re-export of the software is in 0106 * compliance with all laws, regulations, orders, or other restrictions of the 0107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 0108 * any of its subsidiaries will export/re-export any technical data, process, 0109 * software, or service, directly or indirectly, to any country for which the 0110 * United States government or any agency thereof requires an export license, 0111 * other governmental approval, or letter of assurance, without first obtaining 0112 * such license, approval or letter. 0113 * 0114 ***************************************************************************** 0115 * 0116 * Alternatively, you may choose to be licensed under the terms of the 0117 * following license: 0118 * 0119 * Redistribution and use in source and binary forms, with or without 0120 * modification, are permitted provided that the following conditions 0121 * are met: 0122 * 1. Redistributions of source code must retain the above copyright 0123 * notice, this list of conditions, and the following disclaimer, 0124 * without modification. 0125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 0126 * substantially similar to the "NO WARRANTY" disclaimer below 0127 * ("Disclaimer") and any redistribution must be conditioned upon 0128 * including a substantially similar Disclaimer requirement for further 0129 * binary redistribution. 0130 * 3. Neither the names of the above-listed copyright holders nor the names 0131 * of any contributors may be used to endorse or promote products derived 0132 * from this software without specific prior written permission. 0133 * 0134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0145 * 0146 * Alternatively, you may choose to be licensed under the terms of the 0147 * GNU General Public License ("GPL") version 2 as published by the Free 0148 * Software Foundation. 0149 * 0150 *****************************************************************************/ 0151 0152 #include "acpi.h" 0153 #include "accommon.h" 0154 0155 #define _COMPONENT ACPI_UTILITIES 0156 ACPI_MODULE_NAME ("utprint") 0157 0158 0159 #define ACPI_FORMAT_SIGN 0x01 0160 #define ACPI_FORMAT_SIGN_PLUS 0x02 0161 #define ACPI_FORMAT_SIGN_PLUS_SPACE 0x04 0162 #define ACPI_FORMAT_ZERO 0x08 0163 #define ACPI_FORMAT_LEFT 0x10 0164 #define ACPI_FORMAT_UPPER 0x20 0165 #define ACPI_FORMAT_PREFIX 0x40 0166 0167 0168 /* Local prototypes */ 0169 0170 static ACPI_SIZE 0171 AcpiUtBoundStringLength ( 0172 const char *String, 0173 ACPI_SIZE Count); 0174 0175 static char * 0176 AcpiUtBoundStringOutput ( 0177 char *String, 0178 const char *End, 0179 char c); 0180 0181 static char * 0182 AcpiUtFormatNumber ( 0183 char *String, 0184 char *End, 0185 UINT64 Number, 0186 UINT8 Base, 0187 INT32 Width, 0188 INT32 Precision, 0189 UINT8 Type); 0190 0191 static char * 0192 AcpiUtPutNumber ( 0193 char *String, 0194 UINT64 Number, 0195 UINT8 Base, 0196 BOOLEAN Upper); 0197 0198 0199 /******************************************************************************* 0200 * 0201 * FUNCTION: AcpiUtBoundStringLength 0202 * 0203 * PARAMETERS: String - String with boundary 0204 * Count - Boundary of the string 0205 * 0206 * RETURN: Length of the string. Less than or equal to Count. 0207 * 0208 * DESCRIPTION: Calculate the length of a string with boundary. 0209 * 0210 ******************************************************************************/ 0211 0212 static ACPI_SIZE 0213 AcpiUtBoundStringLength ( 0214 const char *String, 0215 ACPI_SIZE Count) 0216 { 0217 UINT32 Length = 0; 0218 0219 0220 while (*String && Count) 0221 { 0222 Length++; 0223 String++; 0224 Count--; 0225 } 0226 0227 return (Length); 0228 } 0229 0230 0231 /******************************************************************************* 0232 * 0233 * FUNCTION: AcpiUtBoundStringOutput 0234 * 0235 * PARAMETERS: String - String with boundary 0236 * End - Boundary of the string 0237 * c - Character to be output to the string 0238 * 0239 * RETURN: Updated position for next valid character 0240 * 0241 * DESCRIPTION: Output a character into a string with boundary check. 0242 * 0243 ******************************************************************************/ 0244 0245 static char * 0246 AcpiUtBoundStringOutput ( 0247 char *String, 0248 const char *End, 0249 char c) 0250 { 0251 0252 if (String < End) 0253 { 0254 *String = c; 0255 } 0256 0257 ++String; 0258 return (String); 0259 } 0260 0261 0262 /******************************************************************************* 0263 * 0264 * FUNCTION: AcpiUtPutNumber 0265 * 0266 * PARAMETERS: String - Buffer to hold reverse-ordered string 0267 * Number - Integer to be converted 0268 * Base - Base of the integer 0269 * Upper - Whether or not using upper cased digits 0270 * 0271 * RETURN: Updated position for next valid character 0272 * 0273 * DESCRIPTION: Convert an integer into a string, note that, the string holds a 0274 * reversed ordered number without the trailing zero. 0275 * 0276 ******************************************************************************/ 0277 0278 static char * 0279 AcpiUtPutNumber ( 0280 char *String, 0281 UINT64 Number, 0282 UINT8 Base, 0283 BOOLEAN Upper) 0284 { 0285 const char *Digits; 0286 UINT64 DigitIndex; 0287 char *Pos; 0288 0289 0290 Pos = String; 0291 Digits = Upper ? AcpiGbl_UpperHexDigits : AcpiGbl_LowerHexDigits; 0292 0293 if (Number == 0) 0294 { 0295 *(Pos++) = '0'; 0296 } 0297 else 0298 { 0299 while (Number) 0300 { 0301 (void) AcpiUtDivide (Number, Base, &Number, &DigitIndex); 0302 *(Pos++) = Digits[DigitIndex]; 0303 } 0304 } 0305 0306 /* *(Pos++) = '0'; */ 0307 return (Pos); 0308 } 0309 0310 0311 /******************************************************************************* 0312 * 0313 * FUNCTION: AcpiUtScanNumber 0314 * 0315 * PARAMETERS: String - String buffer 0316 * NumberPtr - Where the number is returned 0317 * 0318 * RETURN: Updated position for next valid character 0319 * 0320 * DESCRIPTION: Scan a string for a decimal integer. 0321 * 0322 ******************************************************************************/ 0323 0324 const char * 0325 AcpiUtScanNumber ( 0326 const char *String, 0327 UINT64 *NumberPtr) 0328 { 0329 UINT64 Number = 0; 0330 0331 0332 while (isdigit ((int) *String)) 0333 { 0334 AcpiUtShortMultiply (Number, 10, &Number); 0335 Number += *(String++) - '0'; 0336 } 0337 0338 *NumberPtr = Number; 0339 return (String); 0340 } 0341 0342 0343 /******************************************************************************* 0344 * 0345 * FUNCTION: AcpiUtPrintNumber 0346 * 0347 * PARAMETERS: String - String buffer 0348 * Number - The number to be converted 0349 * 0350 * RETURN: Updated position for next valid character 0351 * 0352 * DESCRIPTION: Print a decimal integer into a string. 0353 * 0354 ******************************************************************************/ 0355 0356 const char * 0357 AcpiUtPrintNumber ( 0358 char *String, 0359 UINT64 Number) 0360 { 0361 char AsciiString[20]; 0362 const char *Pos1; 0363 char *Pos2; 0364 0365 0366 Pos1 = AcpiUtPutNumber (AsciiString, Number, 10, FALSE); 0367 Pos2 = String; 0368 0369 while (Pos1 != AsciiString) 0370 { 0371 *(Pos2++) = *(--Pos1); 0372 } 0373 0374 *Pos2 = 0; 0375 return (String); 0376 } 0377 0378 0379 /******************************************************************************* 0380 * 0381 * FUNCTION: AcpiUtFormatNumber 0382 * 0383 * PARAMETERS: String - String buffer with boundary 0384 * End - Boundary of the string 0385 * Number - The number to be converted 0386 * Base - Base of the integer 0387 * Width - Field width 0388 * Precision - Precision of the integer 0389 * Type - Special printing flags 0390 * 0391 * RETURN: Updated position for next valid character 0392 * 0393 * DESCRIPTION: Print an integer into a string with any base and any precision. 0394 * 0395 ******************************************************************************/ 0396 0397 static char * 0398 AcpiUtFormatNumber ( 0399 char *String, 0400 char *End, 0401 UINT64 Number, 0402 UINT8 Base, 0403 INT32 Width, 0404 INT32 Precision, 0405 UINT8 Type) 0406 { 0407 char *Pos; 0408 char Sign; 0409 char Zero; 0410 BOOLEAN NeedPrefix; 0411 BOOLEAN Upper; 0412 INT32 i; 0413 char ReversedString[66]; 0414 0415 0416 /* Parameter validation */ 0417 0418 if (Base < 2 || Base > 16) 0419 { 0420 return (NULL); 0421 } 0422 0423 if (Type & ACPI_FORMAT_LEFT) 0424 { 0425 Type &= ~ACPI_FORMAT_ZERO; 0426 } 0427 0428 NeedPrefix = ((Type & ACPI_FORMAT_PREFIX) && Base != 10) ? TRUE : FALSE; 0429 Upper = (Type & ACPI_FORMAT_UPPER) ? TRUE : FALSE; 0430 Zero = (Type & ACPI_FORMAT_ZERO) ? '0' : ' '; 0431 0432 /* Calculate size according to sign and prefix */ 0433 0434 Sign = '\0'; 0435 if (Type & ACPI_FORMAT_SIGN) 0436 { 0437 if ((INT64) Number < 0) 0438 { 0439 Sign = '-'; 0440 Number = - (INT64) Number; 0441 Width--; 0442 } 0443 else if (Type & ACPI_FORMAT_SIGN_PLUS) 0444 { 0445 Sign = '+'; 0446 Width--; 0447 } 0448 else if (Type & ACPI_FORMAT_SIGN_PLUS_SPACE) 0449 { 0450 Sign = ' '; 0451 Width--; 0452 } 0453 } 0454 if (NeedPrefix) 0455 { 0456 Width--; 0457 if (Base == 16) 0458 { 0459 Width--; 0460 } 0461 } 0462 0463 /* Generate full string in reverse order */ 0464 0465 Pos = AcpiUtPutNumber (ReversedString, Number, Base, Upper); 0466 i = (INT32) ACPI_PTR_DIFF (Pos, ReversedString); 0467 0468 /* Printing 100 using %2d gives "100", not "00" */ 0469 0470 if (i > Precision) 0471 { 0472 Precision = i; 0473 } 0474 0475 Width -= Precision; 0476 0477 /* Output the string */ 0478 0479 if (!(Type & (ACPI_FORMAT_ZERO | ACPI_FORMAT_LEFT))) 0480 { 0481 while (--Width >= 0) 0482 { 0483 String = AcpiUtBoundStringOutput (String, End, ' '); 0484 } 0485 } 0486 if (Sign) 0487 { 0488 String = AcpiUtBoundStringOutput (String, End, Sign); 0489 } 0490 if (NeedPrefix) 0491 { 0492 String = AcpiUtBoundStringOutput (String, End, '0'); 0493 if (Base == 16) 0494 { 0495 String = AcpiUtBoundStringOutput ( 0496 String, End, Upper ? 'X' : 'x'); 0497 } 0498 } 0499 if (!(Type & ACPI_FORMAT_LEFT)) 0500 { 0501 while (--Width >= 0) 0502 { 0503 String = AcpiUtBoundStringOutput (String, End, Zero); 0504 } 0505 } 0506 0507 while (i <= --Precision) 0508 { 0509 String = AcpiUtBoundStringOutput (String, End, '0'); 0510 } 0511 while (--i >= 0) 0512 { 0513 String = AcpiUtBoundStringOutput (String, End, 0514 ReversedString[i]); 0515 } 0516 while (--Width >= 0) 0517 { 0518 String = AcpiUtBoundStringOutput (String, End, ' '); 0519 } 0520 0521 return (String); 0522 } 0523 0524 0525 /******************************************************************************* 0526 * 0527 * FUNCTION: vsnprintf 0528 * 0529 * PARAMETERS: String - String with boundary 0530 * Size - Boundary of the string 0531 * Format - Standard printf format 0532 * Args - Argument list 0533 * 0534 * RETURN: Number of bytes actually written. 0535 * 0536 * DESCRIPTION: Formatted output to a string using argument list pointer. 0537 * 0538 ******************************************************************************/ 0539 0540 int 0541 vsnprintf ( 0542 char *String, 0543 ACPI_SIZE Size, 0544 const char *Format, 0545 va_list Args) 0546 { 0547 UINT8 Base; 0548 UINT8 Type; 0549 INT32 Width; 0550 INT32 Precision; 0551 char Qualifier; 0552 UINT64 Number; 0553 char *Pos; 0554 char *End; 0555 char c; 0556 const char *s; 0557 const void *p; 0558 INT32 Length; 0559 int i; 0560 0561 0562 Pos = String; 0563 0564 0565 if (Size != ACPI_UINT32_MAX) { 0566 End = String + Size; 0567 } else { 0568 End = ACPI_CAST_PTR(char, ACPI_UINT32_MAX); 0569 } 0570 0571 for (; *Format; ++Format) 0572 { 0573 if (*Format != '%') 0574 { 0575 Pos = AcpiUtBoundStringOutput (Pos, End, *Format); 0576 continue; 0577 } 0578 0579 Type = 0; 0580 Base = 10; 0581 0582 /* Process sign */ 0583 0584 do 0585 { 0586 ++Format; 0587 if (*Format == '#') 0588 { 0589 Type |= ACPI_FORMAT_PREFIX; 0590 } 0591 else if (*Format == '0') 0592 { 0593 Type |= ACPI_FORMAT_ZERO; 0594 } 0595 else if (*Format == '+') 0596 { 0597 Type |= ACPI_FORMAT_SIGN_PLUS; 0598 } 0599 else if (*Format == ' ') 0600 { 0601 Type |= ACPI_FORMAT_SIGN_PLUS_SPACE; 0602 } 0603 else if (*Format == '-') 0604 { 0605 Type |= ACPI_FORMAT_LEFT; 0606 } 0607 else 0608 { 0609 break; 0610 } 0611 0612 } while (1); 0613 0614 /* Process width */ 0615 0616 Width = -1; 0617 if (isdigit ((int) *Format)) 0618 { 0619 Format = AcpiUtScanNumber (Format, &Number); 0620 Width = (INT32) Number; 0621 } 0622 else if (*Format == '*') 0623 { 0624 ++Format; 0625 Width = va_arg (Args, int); 0626 if (Width < 0) 0627 { 0628 Width = -Width; 0629 Type |= ACPI_FORMAT_LEFT; 0630 } 0631 } 0632 0633 /* Process precision */ 0634 0635 Precision = -1; 0636 if (*Format == '.') 0637 { 0638 ++Format; 0639 if (isdigit ((int) *Format)) 0640 { 0641 Format = AcpiUtScanNumber (Format, &Number); 0642 Precision = (INT32) Number; 0643 } 0644 else if (*Format == '*') 0645 { 0646 ++Format; 0647 Precision = va_arg (Args, int); 0648 } 0649 0650 if (Precision < 0) 0651 { 0652 Precision = 0; 0653 } 0654 } 0655 0656 /* Process qualifier */ 0657 0658 Qualifier = -1; 0659 if (*Format == 'h' || *Format == 'l' || *Format == 'L') 0660 { 0661 Qualifier = *Format; 0662 ++Format; 0663 0664 if (Qualifier == 'l' && *Format == 'l') 0665 { 0666 Qualifier = 'L'; 0667 ++Format; 0668 } 0669 } 0670 0671 switch (*Format) 0672 { 0673 case '%': 0674 0675 Pos = AcpiUtBoundStringOutput (Pos, End, '%'); 0676 continue; 0677 0678 case 'c': 0679 0680 if (!(Type & ACPI_FORMAT_LEFT)) 0681 { 0682 while (--Width > 0) 0683 { 0684 Pos = AcpiUtBoundStringOutput (Pos, End, ' '); 0685 } 0686 } 0687 0688 c = (char) va_arg (Args, int); 0689 Pos = AcpiUtBoundStringOutput (Pos, End, c); 0690 0691 while (--Width > 0) 0692 { 0693 Pos = AcpiUtBoundStringOutput (Pos, End, ' '); 0694 } 0695 continue; 0696 0697 case 's': 0698 0699 s = va_arg (Args, char *); 0700 if (!s) 0701 { 0702 s = "<NULL>"; 0703 } 0704 Length = (INT32) AcpiUtBoundStringLength (s, Precision); 0705 if (!(Type & ACPI_FORMAT_LEFT)) 0706 { 0707 while (Length < Width--) 0708 { 0709 Pos = AcpiUtBoundStringOutput (Pos, End, ' '); 0710 } 0711 } 0712 0713 for (i = 0; i < Length; ++i) 0714 { 0715 Pos = AcpiUtBoundStringOutput (Pos, End, *s); 0716 ++s; 0717 } 0718 0719 while (Length < Width--) 0720 { 0721 Pos = AcpiUtBoundStringOutput (Pos, End, ' '); 0722 } 0723 continue; 0724 0725 case 'o': 0726 0727 Base = 8; 0728 break; 0729 0730 case 'X': 0731 0732 Type |= ACPI_FORMAT_UPPER; 0733 ACPI_FALLTHROUGH; 0734 0735 case 'x': 0736 0737 Base = 16; 0738 break; 0739 0740 case 'd': 0741 case 'i': 0742 0743 Type |= ACPI_FORMAT_SIGN; 0744 0745 case 'u': 0746 0747 break; 0748 0749 case 'p': 0750 0751 if (Width == -1) 0752 { 0753 Width = 2 * sizeof (void *); 0754 Type |= ACPI_FORMAT_ZERO; 0755 } 0756 0757 p = va_arg (Args, void *); 0758 Pos = AcpiUtFormatNumber ( 0759 Pos, End, ACPI_TO_INTEGER (p), 16, Width, Precision, Type); 0760 continue; 0761 0762 default: 0763 0764 Pos = AcpiUtBoundStringOutput (Pos, End, '%'); 0765 if (*Format) 0766 { 0767 Pos = AcpiUtBoundStringOutput (Pos, End, *Format); 0768 } 0769 else 0770 { 0771 --Format; 0772 } 0773 continue; 0774 } 0775 0776 if (Qualifier == 'L') 0777 { 0778 Number = va_arg (Args, UINT64); 0779 if (Type & ACPI_FORMAT_SIGN) 0780 { 0781 Number = (INT64) Number; 0782 } 0783 } 0784 else if (Qualifier == 'l') 0785 { 0786 Number = va_arg (Args, unsigned long); 0787 if (Type & ACPI_FORMAT_SIGN) 0788 { 0789 Number = (INT32) Number; 0790 } 0791 } 0792 else if (Qualifier == 'h') 0793 { 0794 Number = (UINT16) va_arg (Args, int); 0795 if (Type & ACPI_FORMAT_SIGN) 0796 { 0797 Number = (INT16) Number; 0798 } 0799 } 0800 else 0801 { 0802 Number = va_arg (Args, unsigned int); 0803 if (Type & ACPI_FORMAT_SIGN) 0804 { 0805 Number = (signed int) Number; 0806 } 0807 } 0808 0809 Pos = AcpiUtFormatNumber (Pos, End, Number, Base, 0810 Width, Precision, Type); 0811 } 0812 0813 if (Size > 0) 0814 { 0815 if (Pos < End) 0816 { 0817 *Pos = '\0'; 0818 } 0819 else 0820 { 0821 End[-1] = '\0'; 0822 } 0823 } 0824 0825 return ((int) ACPI_PTR_DIFF (Pos, String)); 0826 } 0827 0828 0829 /******************************************************************************* 0830 * 0831 * FUNCTION: snprintf 0832 * 0833 * PARAMETERS: String - String with boundary 0834 * Size - Boundary of the string 0835 * Format, ... - Standard printf format 0836 * 0837 * RETURN: Number of bytes actually written. 0838 * 0839 * DESCRIPTION: Formatted output to a string. 0840 * 0841 ******************************************************************************/ 0842 0843 int 0844 snprintf ( 0845 char *String, 0846 ACPI_SIZE Size, 0847 const char *Format, 0848 ...) 0849 { 0850 va_list Args; 0851 int Length; 0852 0853 0854 va_start (Args, Format); 0855 Length = vsnprintf (String, Size, Format, Args); 0856 va_end (Args); 0857 0858 return (Length); 0859 } 0860 0861 0862 /******************************************************************************* 0863 * 0864 * FUNCTION: sprintf 0865 * 0866 * PARAMETERS: String - String with boundary 0867 * Format, ... - Standard printf format 0868 * 0869 * RETURN: Number of bytes actually written. 0870 * 0871 * DESCRIPTION: Formatted output to a string. 0872 * 0873 ******************************************************************************/ 0874 0875 int 0876 sprintf ( 0877 char *String, 0878 const char *Format, 0879 ...) 0880 { 0881 va_list Args; 0882 int Length; 0883 0884 0885 va_start (Args, Format); 0886 Length = vsnprintf (String, ACPI_UINT32_MAX, Format, Args); 0887 va_end (Args); 0888 0889 return (Length); 0890 } 0891 0892 0893 #ifdef ACPI_APPLICATION 0894 /******************************************************************************* 0895 * 0896 * FUNCTION: vprintf 0897 * 0898 * PARAMETERS: Format - Standard printf format 0899 * Args - Argument list 0900 * 0901 * RETURN: Number of bytes actually written. 0902 * 0903 * DESCRIPTION: Formatted output to stdout using argument list pointer. 0904 * 0905 ******************************************************************************/ 0906 0907 int 0908 vprintf ( 0909 const char *Format, 0910 va_list Args) 0911 { 0912 ACPI_CPU_FLAGS Flags; 0913 int Length; 0914 0915 0916 Flags = AcpiOsAcquireLock (AcpiGbl_PrintLock); 0917 Length = vsnprintf (AcpiGbl_PrintBuffer, 0918 sizeof (AcpiGbl_PrintBuffer), Format, Args); 0919 0920 (void) fwrite (AcpiGbl_PrintBuffer, Length, 1, ACPI_FILE_OUT); 0921 AcpiOsReleaseLock (AcpiGbl_PrintLock, Flags); 0922 0923 return (Length); 0924 } 0925 0926 0927 /******************************************************************************* 0928 * 0929 * FUNCTION: printf 0930 * 0931 * PARAMETERS: Format, ... - Standard printf format 0932 * 0933 * RETURN: Number of bytes actually written. 0934 * 0935 * DESCRIPTION: Formatted output to stdout. 0936 * 0937 ******************************************************************************/ 0938 0939 int 0940 printf ( 0941 const char *Format, 0942 ...) 0943 { 0944 va_list Args; 0945 int Length; 0946 0947 0948 va_start (Args, Format); 0949 Length = vprintf (Format, Args); 0950 va_end (Args); 0951 0952 return (Length); 0953 } 0954 0955 0956 /******************************************************************************* 0957 * 0958 * FUNCTION: vfprintf 0959 * 0960 * PARAMETERS: File - File descriptor 0961 * Format - Standard printf format 0962 * Args - Argument list 0963 * 0964 * RETURN: Number of bytes actually written. 0965 * 0966 * DESCRIPTION: Formatted output to a file using argument list pointer. 0967 * 0968 ******************************************************************************/ 0969 0970 int 0971 vfprintf ( 0972 FILE *File, 0973 const char *Format, 0974 va_list Args) 0975 { 0976 ACPI_CPU_FLAGS Flags; 0977 int Length; 0978 0979 0980 Flags = AcpiOsAcquireLock (AcpiGbl_PrintLock); 0981 Length = vsnprintf (AcpiGbl_PrintBuffer, 0982 sizeof (AcpiGbl_PrintBuffer), Format, Args); 0983 0984 (void) fwrite (AcpiGbl_PrintBuffer, Length, 1, File); 0985 AcpiOsReleaseLock (AcpiGbl_PrintLock, Flags); 0986 0987 return (Length); 0988 } 0989 0990 0991 /******************************************************************************* 0992 * 0993 * FUNCTION: fprintf 0994 * 0995 * PARAMETERS: File - File descriptor 0996 * Format, ... - Standard printf format 0997 * 0998 * RETURN: Number of bytes actually written. 0999 * 1000 * DESCRIPTION: Formatted output to a file. 1001 * 1002 ******************************************************************************/ 1003 1004 int 1005 fprintf ( 1006 FILE *File, 1007 const char *Format, 1008 ...) 1009 { 1010 va_list Args; 1011 int Length; 1012 1013 1014 va_start (Args, Format); 1015 Length = vfprintf (File, Format, Args); 1016 va_end (Args); 1017 1018 return (Length); 1019 } 1020 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |