summaryrefslogtreecommitdiff
path: root/src/io
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-06-27 19:16:45 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-06-27 19:33:42 -0700
commit7af4c5b5c561362cb1135ab504095ae667a9270a (patch)
tree49ffd3008d7634ba36f3951493a68e928407ce89 /src/io
parent8d7f1dadeeb1dc1609b72de5a4ee3a5247b0e9e6 (diff)
downloadtmwa-7af4c5b5c561362cb1135ab504095ae667a9270a.tar.gz
tmwa-7af4c5b5c561362cb1135ab504095ae667a9270a.tar.bz2
tmwa-7af4c5b5c561362cb1135ab504095ae667a9270a.tar.xz
tmwa-7af4c5b5c561362cb1135ab504095ae667a9270a.zip
This is more reliable
Diffstat (limited to 'src/io')
-rw-r--r--src/io/cxxstdio.hpp47
-rw-r--r--src/io/fd.hpp31
-rw-r--r--src/io/fwd.hpp7
-rw-r--r--src/io/line.hpp15
-rw-r--r--src/io/lock.hpp11
-rw-r--r--src/io/read.hpp11
-rw-r--r--src/io/tty.hpp27
-rw-r--r--src/io/write.hpp13
8 files changed, 69 insertions, 93 deletions
diff --git a/src/io/cxxstdio.hpp b/src/io/cxxstdio.hpp
index 6e49c11..66c2aa8 100644
--- a/src/io/cxxstdio.hpp
+++ b/src/io/cxxstdio.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_IO_CXXSTDIO_HPP
-#define TMWA_IO_CXXSTDIO_HPP
+#pragma once
// cxxstdio.hpp - pass C++ types through printf
//
// Copyright © 2011-2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,14 +18,14 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include "fwd.hpp"
+#include "fwd.hpp"
-# include <cstdarg>
-# include <cstdio>
+#include <cstdarg>
+#include <cstdio>
-# include "../compat/cast.hpp"
+#include "../compat/cast.hpp"
-# include "../generic/enum.hpp"
+#include "../generic/enum.hpp"
namespace tmwa
@@ -68,7 +67,7 @@ namespace cxxstdio
inline
const char *convert_for_printf(const char *) = delete;
-# if 0
+#if 0
template<class E>
constexpr
E get_enum_min_value(decltype(E::min_value))
@@ -94,7 +93,7 @@ namespace cxxstdio
{
return def;
}
-# else
+#else
template<class E>
constexpr
E get_enum_min_value(E)
@@ -107,24 +106,24 @@ namespace cxxstdio
{
return E::max_value;
}
-# endif
+#endif
template<class E>
class EnumConverter
{
E& out;
typedef typename underlying_type<E>::type U;
-# if 0
+#if 0
constexpr static
U min_value = U(get_enum_min_value<E>(E(std::numeric_limits<U>::min())));
constexpr static
U max_value = U(get_enum_max_value<E>(E(std::numeric_limits<U>::max())));
-# else
+#else
constexpr static
U min_value = U(get_enum_min_value(E()));
constexpr static
U max_value = U(get_enum_max_value(E()));
-# endif
+#endif
U mid;
public:
EnumConverter(E& e)
@@ -132,10 +131,10 @@ namespace cxxstdio
{}
~EnumConverter()
{
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wtype-limits"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
if (min_value <= mid && mid <= max_value)
-# pragma GCC diagnostic pop
+#pragma GCC diagnostic pop
out = E(mid);
}
U *operator &()
@@ -159,7 +158,7 @@ namespace cxxstdio
}
};
-# define XPRINTF(out, fmt, ...) \
+#define XPRINTF(out, fmt, ...) \
({ \
struct format_impl \
{ \
@@ -169,19 +168,19 @@ namespace cxxstdio
cxxstdio::PrintFormatter<format_impl>::print(out, ## __VA_ARGS__); \
})
-# define FPRINTF(file, fmt, ...) XPRINTF(/*no_cast<FILE *>*/(file), fmt, ## __VA_ARGS__)
-# define PRINTF(fmt, ...) FPRINTF(stdout, fmt, ## __VA_ARGS__)
-# define SPRINTF(str, fmt, ...) XPRINTF(base_cast<AString&>(str), fmt, ## __VA_ARGS__)
-# define SNPRINTF(str, n, fmt, ...) XPRINTF(base_cast<VString<n-1>&>(str), fmt, ## __VA_ARGS__)
+#define FPRINTF(file, fmt, ...) XPRINTF(/*no_cast<FILE *>*/(file), fmt, ## __VA_ARGS__)
+#define PRINTF(fmt, ...) FPRINTF(stdout, fmt, ## __VA_ARGS__)
+#define SPRINTF(str, fmt, ...) XPRINTF(base_cast<AString&>(str), fmt, ## __VA_ARGS__)
+#define SNPRINTF(str, n, fmt, ...) XPRINTF(base_cast<VString<n-1>&>(str), fmt, ## __VA_ARGS__)
-# define STRPRINTF(fmt, ...) \
+#define STRPRINTF(fmt, ...) \
({ \
AString _out_impl; \
SPRINTF(_out_impl, fmt, ## __VA_ARGS__); \
_out_impl; \
})
-# define STRNPRINTF(n, fmt, ...) \
+#define STRNPRINTF(n, fmt, ...) \
({ \
VString<n - 1> _out_impl; \
SNPRINTF(_out_impl, n, fmt, ## __VA_ARGS__); \
@@ -190,5 +189,3 @@ namespace cxxstdio
} // namespace cxxstdio
} // namespace tmwa
-
-#endif // TMWA_IO_CXXSTDIO_HPP
diff --git a/src/io/fd.hpp b/src/io/fd.hpp
index 9ea4d41..d725c8a 100644
--- a/src/io/fd.hpp
+++ b/src/io/fd.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_IO_FD_HPP
-#define TMWA_IO_FD_HPP
+#pragma once
// io/fd.hpp - typesafe (but not scopesafe) file descriptors
//
// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,12 +18,12 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include "fwd.hpp"
+#include "fwd.hpp"
-# include <sys/select.h>
-# include <sys/socket.h>
+#include <sys/select.h>
+#include <sys/socket.h>
-# include "../strings/fwd.hpp"
+#include "../strings/fwd.hpp"
namespace tmwa
@@ -138,24 +137,24 @@ namespace io
}
void clr(FD fd)
{
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wold-style-cast"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
FD_CLR(fd.uncast_dammit(), &fds);
-# pragma GCC diagnostic pop
+#pragma GCC diagnostic pop
}
bool isset(FD fd)
{
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wold-style-cast"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
return FD_ISSET(fd.uncast_dammit(), &fds);
-# pragma GCC diagnostic pop
+#pragma GCC diagnostic pop
}
void set(FD fd)
{
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wold-style-cast"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
FD_SET(fd.uncast_dammit(), &fds);
-# pragma GCC diagnostic pop
+#pragma GCC diagnostic pop
}
static
@@ -165,5 +164,3 @@ namespace io
};
} // namespace io
} // namespace tmwa
-
-#endif // TMWA_IO_FD_HPP
diff --git a/src/io/fwd.hpp b/src/io/fwd.hpp
index 2032c3b..deeb08c 100644
--- a/src/io/fwd.hpp
+++ b/src/io/fwd.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_IO_FWD_HPP
-#define TMWA_IO_FWD_HPP
+#pragma once
// io/fwd.hpp - Forward declarations of I/O classes
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,7 +18,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include "../sanity.hpp"
+#include "../sanity.hpp"
namespace tmwa
@@ -31,5 +30,3 @@ namespace io
class AppendFile;
} // namespace io
} // namespace tmwa
-
-#endif // TMWA_IO_FWD_HPP
diff --git a/src/io/line.hpp b/src/io/line.hpp
index f481505..8244c5e 100644
--- a/src/io/line.hpp
+++ b/src/io/line.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_IO_LINE_HPP
-#define TMWA_IO_LINE_HPP
+#pragma once
// io/line.hpp - Input from files, line-by-line
//
// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,13 +18,13 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include "fwd.hpp"
+#include "fwd.hpp"
-# include "../strings/rstring.hpp"
-# include "../strings/zstring.hpp"
-# include "../strings/literal.hpp"
+#include "../strings/rstring.hpp"
+#include "../strings/zstring.hpp"
+#include "../strings/literal.hpp"
-# include "read.hpp"
+#include "read.hpp"
namespace tmwa
@@ -106,5 +105,3 @@ namespace io
};
} // namespace io
} // namespace tmwa
-
-#endif // TMWA_IO_LINE_HPP
diff --git a/src/io/lock.hpp b/src/io/lock.hpp
index e4ec153..005b371 100644
--- a/src/io/lock.hpp
+++ b/src/io/lock.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_IO_LOCK_HPP
-#define TMWA_IO_LOCK_HPP
+#pragma once
// io/lock.hpp - Output to files with atomic replacement and backups.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,11 +18,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include "fwd.hpp"
+#include "fwd.hpp"
-# include "write.hpp"
+#include "write.hpp"
-# include "../strings/rstring.hpp"
+#include "../strings/rstring.hpp"
namespace tmwa
@@ -41,5 +40,3 @@ namespace io
};
} // namespace io
} // namespace tmwa
-
-#endif // TMWA_IO_LOCK_HPP
diff --git a/src/io/read.hpp b/src/io/read.hpp
index 6757496..6a44de6 100644
--- a/src/io/read.hpp
+++ b/src/io/read.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_IO_READ_HPP
-#define TMWA_IO_READ_HPP
+#pragma once
// io/read.hpp - Input from files.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,11 +18,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include "fwd.hpp"
+#include "fwd.hpp"
-# include "../strings/fwd.hpp"
+#include "../strings/fwd.hpp"
-# include "fd.hpp"
+#include "fd.hpp"
namespace tmwa
{
@@ -52,5 +51,3 @@ namespace io
};
} // namespace io
} // namespace tmwa
-
-#endif // TMWA_IO_READ_HPP
diff --git a/src/io/tty.hpp b/src/io/tty.hpp
index 86dc6d5..f754b91 100644
--- a/src/io/tty.hpp
+++ b/src/io/tty.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_IO_TTY_HPP
-#define TMWA_IO_TTY_HPP
+#pragma once
// io/tty.hpp - terminal escape sequences
//
// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,23 +18,21 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include "fwd.hpp"
+#include "fwd.hpp"
namespace tmwa
{
-# define SGR_BLACK "\e[30m"
-# define SGR_RED "\e[31m"
-# define SGR_GREEN "\e[32m"
-# define SGR_YELLOW "\e[33m"
-# define SGR_BLUE "\e[34m"
-# define SGR_MAGENTA "\e[35m"
-# define SGR_CYAN "\e[36m"
-# define SGR_WHITE "\e[37m"
+#define SGR_BLACK "\e[30m"
+#define SGR_RED "\e[31m"
+#define SGR_GREEN "\e[32m"
+#define SGR_YELLOW "\e[33m"
+#define SGR_BLUE "\e[34m"
+#define SGR_MAGENTA "\e[35m"
+#define SGR_CYAN "\e[36m"
+#define SGR_WHITE "\e[37m"
-# define SGR_BOLD "\e[1m"
+#define SGR_BOLD "\e[1m"
-# define SGR_RESET "\e[0m"
+#define SGR_RESET "\e[0m"
} // namespace tmwa
-
-#endif // TMWA_IO_TTY_HPP
diff --git a/src/io/write.hpp b/src/io/write.hpp
index 7e57841..11bc679 100644
--- a/src/io/write.hpp
+++ b/src/io/write.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_IO_WRITE_HPP
-#define TMWA_IO_WRITE_HPP
+#pragma once
// io/write.hpp - Output to files.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,13 +18,13 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include "fwd.hpp"
+#include "fwd.hpp"
-# include <cstdarg>
+#include <cstdarg>
-# include "../strings/fwd.hpp"
+#include "../strings/fwd.hpp"
-# include "fd.hpp"
+#include "fd.hpp"
namespace tmwa
@@ -68,5 +67,3 @@ namespace io
int do_vprint(WriteFile& out, const char *fmt, va_list ap);
} // namespace io
} // namespace tmwa
-
-#endif // TMWA_IO_WRITE_HPP