[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 724d5d9 1/3: Refactor duplicative std::fputs(
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 724d5d9 1/3: Refactor duplicative std::fputs() usage |
Date: |
Sat, 4 May 2019 16:22:20 -0400 (EDT) |
branch: master
commit 724d5d9db623cf29cab13bc337faf5d411f13606
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Refactor duplicative std::fputs() usage
Combined scattered, identical std::fputs() and fputc() calls into a new
safely_show_on_stderr() function.
---
alert.cpp | 22 ++++++++++++++++------
alert.hpp | 2 ++
alert_cgi.cpp | 11 +----------
alert_cli.cpp | 12 ++----------
alert_wx.cpp | 11 +----------
5 files changed, 22 insertions(+), 36 deletions(-)
diff --git a/alert.cpp b/alert.cpp
index 43b5483..e720c2b 100644
--- a/alert.cpp
+++ b/alert.cpp
@@ -23,12 +23,11 @@
#include "alert.hpp"
-#if !defined LMI_MSW
-# include <cstdio>
-#else // defined LMI_MSW
+#if defined LMI_MSW
# include <windows.h>
#endif // defined LMI_MSW
+#include <cstdio> // fputc(), fputs()
#include <ios>
#include <sstream> // stringbuf
#include <stdexcept>
@@ -70,9 +69,7 @@ inline bool any_function_pointer_has_been_set()
void report_catastrophe(char const* message)
{
#if !defined LMI_MSW
- std::fputs(message, stderr);
- std::fputc('\n' , stderr);
- std::fflush(stderr);
+ safely_show_on_stderr(message);
#else // defined LMI_MSW
::MessageBoxA
(0
@@ -223,6 +220,19 @@ std::ostream& alarum()
return alert_stream<alarum_buf>();
}
+void safely_show_on_stderr(char const* message)
+{
+ std::fputs(message, stderr);
+ std::fputc('\n' , stderr);
+ // Flush explicitly. C99 7.19.3/7 says only that stderr is
+ // "not fully buffered", not that it is 'unbuffered'. See:
+ // http://article.gmane.org/gmane.comp.gnu.mingw.user/14358
+ // [2004-12-20T09:07:24Z from Danny Smith]
+ // http://article.gmane.org/gmane.comp.gnu.mingw.user/15063
+ // [2005-02-10T17:23:09Z from Greg Chicares]
+ std::fflush(stderr);
+}
+
void safely_show_message(char const* message)
{
if(nullptr == safe_message_alert_function)
diff --git a/alert.hpp b/alert.hpp
index 7b32ec9..1cd130b 100644
--- a/alert.hpp
+++ b/alert.hpp
@@ -163,6 +163,8 @@ std::ostream& LMI_SO warning();
std::ostream& LMI_SO hobsons_choice();
std::ostream& LMI_SO alarum();
+void LMI_SO safely_show_on_stderr(char const*);
+
void LMI_SO safely_show_message(char const*);
void LMI_SO safely_show_message(std::string const&);
diff --git a/alert_cgi.cpp b/alert_cgi.cpp
index e4c739e..fc9284c 100644
--- a/alert_cgi.cpp
+++ b/alert_cgi.cpp
@@ -23,7 +23,6 @@
#include "alert.hpp"
-#include <cstdio> // fputs()
#include <stdexcept>
namespace
@@ -66,13 +65,5 @@ void alarum_alert(std::string const& s)
void safe_message_alert(char const* message)
{
- std::fputs(message, stderr);
- std::fputc('\n', stderr);
- // Flush explicitly. C99 7.19.3/7 says only that stderr is
- // "not fully buffered", not that it is 'unbuffered'. See:
- // http://article.gmane.org/gmane.comp.gnu.mingw.user/14358
- // [2004-12-20T09:07:24Z from Danny Smith]
- // http://article.gmane.org/gmane.comp.gnu.mingw.user/15063
- // [2005-02-10T17:23:09Z from Greg Chicares]
- std::fflush(stderr);
+ safely_show_on_stderr(message);
}
diff --git a/alert_cli.cpp b/alert_cli.cpp
index 8ff349a..c71dc9e 100644
--- a/alert_cli.cpp
+++ b/alert_cli.cpp
@@ -23,7 +23,7 @@
#include "alert.hpp"
-#include <cstdio> // fputs(), getchar()
+#include <cstdio> // getchar()
#include <iostream>
#include <stdexcept>
@@ -99,13 +99,5 @@ void alarum_alert(std::string const& s)
void safe_message_alert(char const* message)
{
- std::fputs(message, stderr);
- std::fputc('\n', stderr);
- // Flush explicitly. C99 7.19.3/7 says only that stderr is
- // "not fully buffered", not that it is 'unbuffered'. See:
- // http://article.gmane.org/gmane.comp.gnu.mingw.user/14358
- // [2004-12-20T09:07:24Z from Danny Smith]
- // http://article.gmane.org/gmane.comp.gnu.mingw.user/15063
- // [2005-02-10T17:23:09Z from Greg Chicares]
- std::fflush(stderr);
+ safely_show_on_stderr(message);
}
diff --git a/alert_wx.cpp b/alert_wx.cpp
index 9f8144c..88411b0 100644
--- a/alert_wx.cpp
+++ b/alert_wx.cpp
@@ -33,7 +33,6 @@
# include <wx/msw/wrapwin.h> // HWND etc.
#endif // defined LMI_MSW
-#include <cstdio>
#include <stdexcept>
LMI_FORCE_LINKING_IN_SITU(alert_wx)
@@ -149,15 +148,7 @@ void alarum_alert(std::string const& s)
void safe_message_alert(char const* message)
{
#if !defined LMI_MSW
- std::fputs(message, stderr);
- std::fputc('\n' , stderr);
- // Flush explicitly. C99 7.19.3/7 says only that stderr is
- // "not fully buffered", not that it is 'unbuffered'. See:
- // http://article.gmane.org/gmane.comp.gnu.mingw.user/14358
- // [2004-12-20T09:07:24Z from Danny Smith]
- // http://article.gmane.org/gmane.comp.gnu.mingw.user/15063
- // [2005-02-10T17:23:09Z from Greg Chicares]
- std::fflush(stderr);
+ safely_show_on_stderr(message);
#else // defined LMI_MSW
HWND handle = 0;
if(wxTheApp && wxTheApp->GetTopWindow())