Home | History | Annotate | Download | only in Ascii
      1 /*++
      2 
      3 Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
      4 This program and the accompanying materials
      5 are licensed and made available under the terms and conditions of the BSD License
      6 which accompanies this distribution.  The full text of the license may be found at
      7 http://opensource.org/licenses/bsd-license.php
      8 
      9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     11 
     12 Module Name:
     13 
     14   Sprint.c
     15 
     16 Abstract:
     17 
     18   Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
     19   simple implemenation of SPrint() and Print() to support debug.
     20 
     21   You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
     22   time. This makes the implementation very simple.
     23 
     24   VSPrint, Print, SPrint format specification has the follwoing form
     25 
     26   %[flags][width]type
     27 
     28   flags:
     29     '-' - Left justify
     30     '+' - Prefix a sign
     31     ' ' - Prefix a blank
     32     ',' - Place commas in numberss
     33     '0' - Prefix for width with zeros
     34     'l' - UINT64
     35     'L' - UINT64
     36 
     37   width:
     38     '*' - Get width from a UINTN argumnet from the argument list
     39     Decimal number that represents width of print
     40 
     41   type:
     42     'X' - argument is a UINTN hex number, prefix '0'
     43     'x' - argument is a hex number
     44     'd' - argument is a decimal number
     45     'a' - argument is an ascii string
     46     'S','s' - argument is an Unicode string
     47     'g' - argument is a pointer to an EFI_GUID
     48     't' - argument is a pointer to an EFI_TIME structure
     49     'c' - argument is an ascii character
     50     'r' - argument is EFI_STATUS
     51     '%' - Print a %
     52 
     53 --*/
     54 
     55 #include "TianoCommon.h"
     56 #include "PrintWidth.h"
     57 #include "EfiPrintLib.h"
     58 #include "Print.h"
     59 
     60 UINTN
     61 USPrint (
     62   OUT CHAR16        *Buffer,
     63   IN  UINTN         BufferSize,
     64   IN  CONST CHAR16  *Format,
     65   ...
     66   )
     67 /*++
     68 
     69 Routine Description:
     70 
     71   Process format and place the results in Buffer for wide chars.
     72 
     73 Arguments:
     74 
     75   Buffer      - Wide char buffer to print the results of the parsing of Format into.
     76   BufferSize  - Maximum number of characters to put into buffer.
     77   Format      - Format string
     78   ...         - Vararg list consumed by processing Format.
     79 
     80 Returns:
     81 
     82   Number of characters printed.
     83 
     84 --*/
     85 {
     86   UINTN   Return;
     87   VA_LIST Marker;
     88 
     89   VA_START (Marker, Format);
     90   Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
     91   VA_END (Marker);
     92 
     93   return Return;
     94 }
     95 
     96 UINTN
     97 UvSPrint (
     98   OUT CHAR16        *Buffer,
     99   IN  UINTN         BufferSize,
    100   IN  CONST CHAR16  *FormatString,
    101   IN  VA_LIST       Marker
    102   )
    103 /*++
    104 
    105 Routine Description:
    106 
    107   Internal implementation of USPrint.
    108   Process format and place the results in Buffer for wide chars.
    109 
    110 Arguments:
    111 
    112   Buffer        - Wide char buffer to print the results of the parsing of Format into.
    113   BufferSize    - Maximum number of characters to put into buffer.
    114   FormatString  - Format string
    115   Marker        - Vararg list consumed by processing Format.
    116 
    117 Returns:
    118 
    119   Number of characters printed.
    120 
    121 --*/
    122 {
    123   UINTN Index;
    124   CHAR8 AsciiFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
    125   CHAR8 AsciiResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
    126 
    127   for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
    128     AsciiFormat[Index] = (CHAR8) FormatString[Index];
    129   }
    130 
    131   AsciiFormat[Index]  = '\0';
    132 
    133   Index               = VSPrint (AsciiResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, AsciiFormat, Marker);
    134 
    135   for (Index = 0; (Index < (BufferSize - 1)) && AsciiResult[Index] != '\0'; Index++) {
    136     Buffer[Index] = (CHAR16) AsciiResult[Index];
    137   }
    138 
    139   Buffer[Index] = '\0';
    140 
    141   return Index++;
    142 }
    143