xitoa.h
Upload User: zcw0111
Upload Date: 2021-05-17
Package Size: 48k
Code Size: 3k
Category:

3G develop

Development Platform:

C/C++

  1. /*---------------------------------------------------------------------------
  2.    Extended itoa, puts and printf                    (C)ChaN, 2006
  3. -----------------------------------------------------------------------------*/
  4. #ifndef XITOA
  5. #define XITOA
  6. #include <avr/pgmspace.h>
  7. extern void (*xfunc_out)(char);
  8. /* This is a pointer to user defined output function. It must be initialized
  9.    before using this modle.
  10. */
  11. void xputc(char chr);
  12. /* This is a stub function to forward outputs to user defined output function.
  13.    All outputs from this module are output via this function.
  14. */
  15. /*-----------------------------------------------------------------------------*/
  16. void xputs(const prog_char *string);
  17. /*  The string placed in the ROM is forwarded to xputc() directly.
  18. */
  19. /*-----------------------------------------------------------------------------*/
  20. void xitoa(long value, char radix, char width);
  21. /* Extended itoa().
  22.       value  radix  width   output
  23.         100     10      6   "   100"
  24.         100     10     -6   "000100"
  25.         100     10      0   "100"
  26.  4294967295     10      0   "4294967295"
  27.  4294967295    -10      0   "-1"
  28.      655360     16     -8   "000A0000"
  29.        1024     16      0   "400"
  30.        0x55      2     -8   "01010101"
  31. */
  32. /*-----------------------------------------------------------------------------*/
  33. void xprintf(const prog_char *format, ...);
  34. /* Format string is placed in the ROM. The format flags is similar to printf().
  35.    %[flag][width][size]type
  36.    flag
  37.      A '0' means filled with '0' when output is shorter than width.
  38.      ' ' is used in default. This is effective only numeral type.
  39.    width
  40.      Minimum width in decimal number. This is effective only numeral type.
  41.      Default width is zero.
  42.    size
  43.      A 'l' means the argument is long(32bit). Default is short(16bit).
  44.      This is effective only numeral type.
  45.    type
  46.      'c' : Character, argument is the value
  47.      's' : String placed on the RAM, argument is the pointer
  48.      'S' : String placed on the ROM, argument is the pointer
  49.      'd' : Signed decimal, argument is the value
  50.      'u' : Unsigned decimal, argument is the value
  51.      'X' : Hex decimal, argument is the value
  52.      'b' : Binary, argument is the value
  53.      '%' : '%'
  54. */
  55. /*-----------------------------------------------------------------------------*/
  56. char xatoi(char **str, long *ret);
  57. /* Get value of the numeral string. 
  58.   str
  59.     Pointer to pointer to source string
  60.     "0b11001010" binary
  61.     "0377" octal
  62.     "0xff800" hexdecimal
  63.     "1250000" decimal
  64.     "-25000" decimal
  65.   ret
  66.     Pointer to return value
  67. */
  68. #endif /* XITOA */