[PATCH setup 3/7] Add CliParseFeedback class

Jon Turney jon.turney@dronecode.org.uk
Sat Feb 15 17:04:00 GMT 2020


Move the yyerror() handling from inilint into that class
---
 CliParseFeedback.cc | 54 +++++++++++++++++++++++++++++++++++++++++++++
 CliParseFeedback.h  | 28 +++++++++++++++++++++++
 Makefile.am         |  3 ++-
 inilintmain.cc      | 19 ----------------
 4 files changed, 84 insertions(+), 20 deletions(-)
 create mode 100644 CliParseFeedback.cc
 create mode 100644 CliParseFeedback.h

diff --git a/CliParseFeedback.cc b/CliParseFeedback.cc
new file mode 100644
index 0000000..6dc48ba
--- /dev/null
+++ b/CliParseFeedback.cc
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2020 Jon Turney
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ */
+
+#include "CliParseFeedback.h"
+#include "LogSingleton.h"
+#include <sstream>
+#include <iostream>
+
+void CliParseFeedback::progress (unsigned long const pos, unsigned long const max)
+{
+  std::cout << pos << "/" << max << std::endl;
+}
+
+void CliParseFeedback::iniName (const std::string& name)
+{
+}
+
+void CliParseFeedback::babble (const std::string& message) const
+{
+  Log (LOG_BABBLE) << message << endLog;
+}
+
+void CliParseFeedback::warning (const std::string& message) const
+{
+  std::cout << "Warning: " << message << std::endl;
+}
+
+void CliParseFeedback::show_errors () const
+{
+}
+
+void CliParseFeedback::note_error(int lineno, const std::string &s)
+{
+  std::ostringstream buf;
+  buf << "line " << lineno << ": ";
+  buf << s << std::endl;
+  std::cout << buf.str();
+  error_count++;
+}
+
+bool CliParseFeedback::has_errors () const
+{
+  return (error_count > 0);
+}
diff --git a/CliParseFeedback.h b/CliParseFeedback.h
new file mode 100644
index 0000000..a19659e
--- /dev/null
+++ b/CliParseFeedback.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2020 Jon Turney
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ */
+
+#include "IniParseFeedback.h"
+
+class CliParseFeedback : public IniParseFeedback
+{
+public:
+  virtual void progress (unsigned long const pos, unsigned long const max);
+  virtual void iniName (const std::string& name);
+  virtual void babble (const std::string& message) const;
+  virtual void warning (const std::string& message) const;
+  virtual void show_errors () const;
+  virtual void note_error(int lineno, const std::string &s);
+  virtual bool has_errors () const;
+private:
+  int error_count = 0;
+};
diff --git a/Makefile.am b/Makefile.am
index cc869e0..0ef3d6e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -63,6 +63,8 @@ CLEANFILES = setup_version.c
 inilint_LDADD = \
 	libgetopt++/libgetopt++.la
 inilint_SOURCES = \
+	CliParseFeedback.cc \
+	CliParseFeedback.h \
 	filemanip.cc \
 	filemanip.h \
 	find.cc \
@@ -75,7 +77,6 @@ inilint_SOURCES = \
 	inilintmain.cc \
 	inilex.ll \
 	iniparse.yy \
-	IniParseFeedback.h \
 	io_stream.h \
 	io_stream.cc \
 	io_stream_file.h \
diff --git a/inilintmain.cc b/inilintmain.cc
index a4c4cb1..7ae98ff 100644
--- a/inilintmain.cc
+++ b/inilintmain.cc
@@ -15,25 +15,6 @@
 
 #include "getopt++/GetOption.h"
 #include <iostream>
-#include <sstream>
-
-extern int yylineno;
-
-static std::ostringstream error_buf;
-static int error_count = 0;
-
-extern int
-yyerror (const std::string& s)
-{
-  std::ostringstream buf;
-  buf << "setup.ini line " << yylineno << ": ";
-  buf << s << std::endl;
-  std::cout << buf;
-  error_buf << buf; 
-  error_count++;
-  /* TODO: is return 0 correct? */
-  return 0;
-}
 
 void
 show_help()
-- 
2.21.0



More information about the Cygwin-apps mailing list