From ec21450522e3c2124f3510eef5cfd88420483248 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 26 Jun 2014 18:18:01 -0700 Subject: Low hanging fruit --- src/io/cxxstdio.cpp | 2 +- src/io/cxxstdio.hpp | 82 ++------------------------------------------------- src/io/line_test.cpp | 3 ++ src/io/read_test.cpp | 3 ++ src/io/write_test.cpp | 3 ++ 5 files changed, 12 insertions(+), 81 deletions(-) (limited to 'src/io') diff --git a/src/io/cxxstdio.cpp b/src/io/cxxstdio.cpp index fbfdd46..8b18701 100644 --- a/src/io/cxxstdio.cpp +++ b/src/io/cxxstdio.cpp @@ -1,5 +1,5 @@ #include "cxxstdio.hpp" -// cxxstdio.cpp - pass C++ types through scanf/printf +// cxxstdio.cpp - pass C++ types through printf // // Copyright © 2013 Ben Longbons // diff --git a/src/io/cxxstdio.hpp b/src/io/cxxstdio.hpp index c040d90..fc5829f 100644 --- a/src/io/cxxstdio.hpp +++ b/src/io/cxxstdio.hpp @@ -1,6 +1,6 @@ #ifndef TMWA_IO_CXXSTDIO_HPP #define TMWA_IO_CXXSTDIO_HPP -// cxxstdio.hpp - pass C++ types through scanf/printf +// cxxstdio.hpp - pass C++ types through printf // // Copyright © 2011-2013 Ben Longbons // @@ -31,30 +31,13 @@ namespace cxxstdio { - // other implementations of do_vprint or do_vscan are injected by ADL. + // other implementations of do_vprint are injected by ADL. inline __attribute__((format(printf, 2, 0))) int do_vprint(FILE *out, const char *fmt, va_list ap) { return vfprintf(out, fmt, ap); } - inline __attribute__((format(scanf, 2, 0))) - int do_vscan(FILE *in, const char *fmt, va_list ap) - { - return vfscanf(in, fmt, ap); - } - -# if 0 - inline __attribute__((format(scanf, 2, 0))) - int do_vscan(const char *in, const char *fmt, va_list ap) - { - return vsscanf(in, fmt, ap); - } -# else - inline - int do_vscan(const char *, const char *, va_list) = delete; -# endif - template inline __attribute__((format(printf, 2, 3))) int do_print(T&& t, const char *fmt, ...) @@ -67,19 +50,6 @@ namespace cxxstdio return rv; } - template - inline __attribute__((format(scanf, 2, 3))) - int do_scan(T&& t, const char *fmt, ...) - { - int rv; - va_list ap; - va_start(ap, fmt); - rv = do_vscan(std::forward(t), fmt, ap); - va_end(ap); - return rv; - } - - template::value>::type> typename remove_enum::type decay_for_printf(T v) { @@ -93,16 +63,8 @@ namespace cxxstdio return std::forward(v); } - template::value>::type> - T& convert_for_scanf(T& v) - { - return v; - } - inline const char *convert_for_printf(const char *) = delete; - inline - char *convert_for_scanf(char *) = delete; # if 0 template @@ -180,12 +142,6 @@ namespace cxxstdio } }; - template::value>::type> - EnumConverter convert_for_scanf(T& v) - { - return v; - } - template class PrintFormatter { @@ -201,21 +157,6 @@ namespace cxxstdio } }; - template - class ScanFormatter - { - public: - template - static - int scan(T&& t, A&&... a) - { - constexpr static - const char *scan_format = Format::scan_format().format_string(); - return do_scan(std::forward(t), scan_format, - &convert_for_scanf(*a)...); - } - }; - # define XPRINTF(out, fmt, ...) \ ({ \ struct format_impl \ @@ -226,29 +167,10 @@ namespace cxxstdio cxxstdio::PrintFormatter::print(out, ## __VA_ARGS__); \ }) -# if 0 -# define XSCANF(out, fmt, ...) \ - ({ \ - struct format_impl \ - { \ - constexpr static \ - FormatString scan_format() { return fmt; } \ - }; \ - cxxstdio::ScanFormatter::scan(out, ## __VA_ARGS__); \ - }) -# endif - # define FPRINTF(file, fmt, ...) XPRINTF(/*no_cast*/(file), fmt, ## __VA_ARGS__) -# if 0 -# define FSCANF(file, fmt, ...) XSCANF(no_cast(file), fmt, ## __VA_ARGS__) -# endif # define PRINTF(fmt, ...) FPRINTF(stdout, fmt, ## __VA_ARGS__) # define SPRINTF(str, fmt, ...) XPRINTF(base_cast(str), fmt, ## __VA_ARGS__) # define SNPRINTF(str, n, fmt, ...) XPRINTF(base_cast&>(str), fmt, ## __VA_ARGS__) -# if 0 -# define SCANF(fmt, ...) FSCANF(stdin, fmt, ## __VA_ARGS__) -# define SSCANF(str, fmt, ...) XSCANF(maybe_cast(str), fmt, ## __VA_ARGS__) -# endif # define STRPRINTF(fmt, ...) \ ({ \ diff --git a/src/io/line_test.cpp b/src/io/line_test.cpp index 6a4a55c..d6efa67 100644 --- a/src/io/line_test.cpp +++ b/src/io/line_test.cpp @@ -25,6 +25,9 @@ #include "../poison.hpp" + +#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" + static io::FD string_pipe(ZString sz) { diff --git a/src/io/read_test.cpp b/src/io/read_test.cpp index 77b2286..8cf7d7a 100644 --- a/src/io/read_test.cpp +++ b/src/io/read_test.cpp @@ -26,6 +26,9 @@ #include "../poison.hpp" + +#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" + static io::FD string_pipe(ZString sz) { diff --git a/src/io/write_test.cpp b/src/io/write_test.cpp index 970be42..ff2553a 100644 --- a/src/io/write_test.cpp +++ b/src/io/write_test.cpp @@ -30,6 +30,9 @@ #include "../poison.hpp" + +#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" + static io::FD pipew(io::FD& rfd) { -- cgit v1.2.3-70-g09d2