format.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-25 23:54:38
  5. * @LastEditTime: 2020-06-17 15:22:42
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. #ifndef _FORMAT_H_
  9. #define _FORMAT_H_
  10. #include <stdarg.h>
  11. #define FORMAT_BUF_LEN 12
  12. /* Format states */
  13. #define S_DEFAULT 0
  14. #define S_FLAGS 1
  15. #define S_WIDTH 2
  16. #define S_PRECIS 3
  17. #define S_LENGTH 4
  18. #define S_CONV 5
  19. /* Lenght flags */
  20. #define L_CHAR 1
  21. #define L_SHORT 2
  22. #define L_LONG 3
  23. #define L_LLONG 4
  24. #define L_DOUBLE 5
  25. #define F_ALTERNATE 0001 // put 0x infront 16, 0 on octals, b on binary
  26. #define F_ZEROPAD 0002 // value should be zero padded
  27. #define F_LEFT 0004 // left justified if set, otherwise right justified
  28. #define F_SPACE 0010 // place a space before positive number
  29. #define F_PLUS 0020 // show +/- on signed numbers, default only for -
  30. #define F_SIGNED 0040 // is an unsigned number?
  31. #define F_SMALL 0100 // use lowercase for hex?
  32. #define is_digit(c) (c >= '0' && c <= '9')
  33. int salof_format_nstr(char *buf, unsigned int size, const char *fmt, va_list ap);
  34. #endif // !_FORMAT_H_