tool_stdio.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef AFUN_STDIO_H
  2. #define AFUN_STDIO_H
  3. #include "aFunToolExport.h"
  4. #include "tool_macro.h"
  5. #include "tool.h"
  6. #ifdef __cplusplus
  7. #include <cstdio>
  8. #include <cinttypes>
  9. #else
  10. #include <stdio.h>
  11. #include <inttypes.h>
  12. #endif
  13. #ifndef AFUN_TOOL_C
  14. namespace aFuntool {
  15. #endif
  16. AFUN_TOOL_C_EXPORT_FUNC int fgets_stdin(char **dest, int len);
  17. AFUN_TOOL_C_EXPORT_FUNC bool checkStdin();
  18. AFUN_TOOL_C_EXPORT_FUNC bool fclear_stdin();
  19. AFUN_STATIC bool clear_ferror(FILE *file);
  20. AFUN_STATIC bool clear_stdin();
  21. #ifndef AFUN_TOOL_C
  22. }
  23. #endif
  24. #ifdef AFUN_WIN32_NO_CYGWIN
  25. #ifdef _MSC_VER
  26. #pragma warning(disable : 5105) // 关闭 5105 的警告输出 (Windows.h中使用)
  27. #endif
  28. #include <conio.h>
  29. #include <io.h>
  30. #include <Windows.h>
  31. #ifndef AFUN_TOOL_C
  32. namespace aFuntool {
  33. #endif
  34. AFUN_TOOL_C_EXPORT_FUNC void stdio_signal_init(bool signal);
  35. AFUN_TOOL_C_EXPORT_FUNC bool stdio_check_signal();
  36. AFUN_TOOL_C_EXPORT_FUNC int convertMultiByte(char **dest, const char *str, UINT from, UINT to); // win32 特有函数
  37. AFUN_TOOL_C_EXPORT_FUNC int convertWideByte(wchar_t **dest, const char *str, UINT from); // win32 特有函数
  38. AFUN_TOOL_C_EXPORT_FUNC int convertFromWideByte(char **dest, const wchar_t *str, UINT to);
  39. AFUN_TOOL_C_EXPORT_FUNC int fgetc_stdin();
  40. AFUN_TOOL_C_EXPORT_FUNC char *fgets_stdin_(char *buf, size_t len);
  41. AFUN_TOOL_C_EXPORT_FUNC int fungetc_stdin(int ch);
  42. AFUN_TOOL_C_EXPORT_FUNC int fputs_std_(const char *str, FILE *std);
  43. AFUN_STATIC int fputs_stdout(const char *str);
  44. AFUN_STATIC int fputs_stderr(const char *str);
  45. AFUN_TOOL_C_EXPORT_FUNC size_t vprintf_std_(FILE *std, size_t buf_len, const char *format, va_list ap);
  46. AFUN_STATIC size_t vprintf_stderr(size_t buf_len, const char *format, va_list ap);
  47. AFUN_STATIC size_t vprintf_stdout(size_t buf_len, const char *format, va_list ap);
  48. AFUN_STATIC size_t printf_stdout(size_t buf_len, const char *format, ...);
  49. AFUN_STATIC size_t printf_stderr(size_t buf_len, const char *format, ...);
  50. #ifndef AFUN_TOOL_C
  51. }
  52. #endif
  53. #else
  54. #ifndef AFUN_TOOL_C
  55. namespace aFuntool {
  56. #endif
  57. AFUN_STATIC int fgetc_stdin();
  58. AFUN_STATIC int fgets_stdin_(char *buf, int len, FILE *file);
  59. AFUN_STATIC int fungetc_stdin(char ch);
  60. AFUN_STATIC int fputs_stdout(const char *str);
  61. AFUN_STATIC int fputs_stderr(const char *str);
  62. AFUN_STATIC int vprintf_stdout(size_t, const char *format, va_list ap);
  63. AFUN_STATIC int vprintf_stderr(size_t, const char *format, va_list ap);
  64. AFUN_STATIC size_t printf_stdout(size_t, const char *format, ...);
  65. AFUN_STATIC size_t printf_stderr(size_t, const char *format, ...);
  66. #ifndef AFUN_TOOL_C
  67. }
  68. #endif
  69. #endif
  70. #ifdef __cplusplus
  71. #ifndef AFUN_TOOL_C
  72. namespace aFuntool {
  73. #endif
  74. class OutStream {
  75. typedef size_t PrintFunction(size_t, const char *, ...);
  76. PrintFunction *func;
  77. public:
  78. AFUN_INLINE explicit OutStream(PrintFunction *func_) noexcept;
  79. AFUN_INLINE OutStream &operator<<(char a);
  80. AFUN_INLINE OutStream &operator<<(signed char a);
  81. AFUN_INLINE OutStream &operator<<(short a);
  82. AFUN_INLINE OutStream &operator<<(int a);
  83. AFUN_INLINE OutStream &operator<<(long a);
  84. AFUN_INLINE OutStream &operator<<(long long a);
  85. AFUN_INLINE OutStream &operator<<(unsigned char a);
  86. AFUN_INLINE OutStream &operator<<(unsigned short a);
  87. AFUN_INLINE OutStream &operator<<(unsigned int a);
  88. AFUN_INLINE OutStream &operator<<(unsigned long a);
  89. AFUN_INLINE OutStream &operator<<(unsigned long long a);
  90. AFUN_INLINE OutStream &operator<<(float a);
  91. AFUN_INLINE OutStream &operator<<(double a);
  92. AFUN_INLINE OutStream &operator<<(long double a);
  93. AFUN_INLINE OutStream &operator<<(const char *a);
  94. AFUN_INLINE OutStream &operator<<(const std::string &a);
  95. AFUN_INLINE OutStream &operator<<(const void *a);
  96. };
  97. AFUN_TOOL_EXPORT extern OutStream cout;
  98. AFUN_TOOL_EXPORT extern OutStream cerr;
  99. #ifndef AFUN_TOOL_C
  100. }
  101. #endif
  102. #endif // __cplusplus
  103. #include "tool_stdio.inline.h"
  104. #endif //AFUN_STDIO_H