[PATCH setup 0/7] Fix building inilint

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH setup 0/7] Fix building inilint

Jon TURNEY
I have a vague aspiration to add some automated tests to setup.

This is a first step on that long road, by restoring building a command line
tool using a component which has existing moderately good isolation, the
iniparser.

Jon Turney (7):
  More updates for "using namespace std;" removal
  Pull yyerror() handling up into IniParseFeedback
  Add CliParseFeedback class
  Restore abstract base class IniDBBuilder
  Fix building inilint
  Pass a "Install for all users" flag into setDefaultSecurity()
  Make inilint do something slightly useful

 CliParseFeedback.cc   | 54 ++++++++++++++++++++++++++++++++++++++++
 CliParseFeedback.h    | 28 +++++++++++++++++++++
 IniDBBuilder.h        | 58 +++++++++++++++++++++++++++++++++++++++++++
 IniDBBuilderLint.h    | 55 ++++++++++++++++++++++++++++++++++++++++
 IniDBBuilderPackage.h |  6 ++---
 IniParseFeedback.cc   | 24 ------------------
 IniParseFeedback.h    | 13 +++++-----
 Makefile.am           | 32 +++++++++---------------
 configure.ac          | 13 ----------
 ini.cc                | 46 ++++++++++++++++++++++++----------
 ini.h                 | 13 +++-------
 inilex.ll             | 24 +++---------------
 inilintmain.cc        | 48 +++++++++++++++++++----------------
 iniparse.yy           |  4 +--
 main.cc               |  2 +-
 win32.cc              |  5 ++--
 win32.h               |  2 +-
 17 files changed, 288 insertions(+), 139 deletions(-)
 create mode 100644 CliParseFeedback.cc
 create mode 100644 CliParseFeedback.h
 create mode 100644 IniDBBuilder.h
 create mode 100644 IniDBBuilderLint.h
 delete mode 100644 IniParseFeedback.cc

--
2.21.0

Reply | Threaded
Open this post in threaded view
|

[PATCH setup 1/7] More updates for "using namespace std;" removal

Jon TURNEY
overlooked in 155eacb6
---
 inilintmain.cc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/inilintmain.cc b/inilintmain.cc
index 33239fb..a4c4cb1 100644
--- a/inilintmain.cc
+++ b/inilintmain.cc
@@ -27,8 +27,8 @@ yyerror (const std::string& s)
 {
   std::ostringstream buf;
   buf << "setup.ini line " << yylineno << ": ";
-  buf << s << endl;
-  cout << buf;
+  buf << s << std::endl;
+  std::cout << buf;
   error_buf << buf;
   error_count++;
   /* TODO: is return 0 correct? */
@@ -38,8 +38,8 @@ yyerror (const std::string& s)
 void
 show_help()
 {
-  cout << "inilint checks cygwin setup.ini files and reports any errors with" << endl;
-  cout << "diagnostics" << endl;
+  std::cout << "inilint checks cygwin setup.ini files and reports any errors with" << std::endl;
+  std::cout << "diagnostics" << std::endl;
 }
 
 int
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

[PATCH setup 2/7] Pull yyerror() handling up into IniParseFeedback

Jon TURNEY
In reply to this post by Jon TURNEY
Pull yyerror() handling up into IniParseFeedback
Collect the parser errors in IniParseFeedback
Make IniParseFeedback an abstract base class
---
 IniParseFeedback.cc | 24 ------------------------
 IniParseFeedback.h  | 13 +++++++------
 Makefile.am         |  2 --
 ini.cc              | 44 +++++++++++++++++++++++++++++++++-----------
 ini.h               |  9 ---------
 inilex.ll           | 20 ++------------------
 6 files changed, 42 insertions(+), 70 deletions(-)
 delete mode 100644 IniParseFeedback.cc

diff --git a/IniParseFeedback.cc b/IniParseFeedback.cc
deleted file mode 100644
index 8b7ebd1..0000000
--- a/IniParseFeedback.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2002 Robert Collins.
- *
- *     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/
- *
- * Written by Robert Collins <[hidden email]>
- *
- */
-
-#include "IniParseFeedback.h"
-
-IniParseFeedback::~IniParseFeedback(){}
-
-void IniParseFeedback::progress(unsigned long const, unsigned long const) {}
-void IniParseFeedback::iniName (const std::string& ) {}
-void IniParseFeedback::babble(const std::string& ) const {}
-void IniParseFeedback::warning (const std::string& ) const {}
-void IniParseFeedback::error(const std::string& ) const {}
diff --git a/IniParseFeedback.h b/IniParseFeedback.h
index 23f9d31..c3c7803 100644
--- a/IniParseFeedback.h
+++ b/IniParseFeedback.h
@@ -26,12 +26,13 @@
 class IniParseFeedback
 {
 public:
-  virtual void progress (unsigned long const, unsigned long const);
-  virtual void iniName (const std::string& );
-  virtual void babble (const std::string& ) const;
-  virtual void warning (const std::string& ) const;
-  virtual void error (const std::string& ) const;
-  virtual ~ IniParseFeedback ();
+  virtual void progress (unsigned long const, unsigned long const) = 0;
+  virtual void iniName (const std::string& ) = 0;
+  virtual void babble (const std::string& ) const = 0;
+  virtual void warning (const std::string& ) const = 0;
+  virtual void show_errors () const = 0;
+  virtual void note_error(int lineno, const std::string &error) = 0;
+  virtual bool has_errors () const = 0;
 };
 
 #endif /* SETUP_INIPARSEFEEDBACK_H */
diff --git a/Makefile.am b/Makefile.am
index 3c41389..cc869e0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -75,7 +75,6 @@ inilint_SOURCES = \
  inilintmain.cc \
  inilex.ll \
  iniparse.yy \
- IniParseFeedback.cc \
  IniParseFeedback.h \
  io_stream.h \
  io_stream.cc \
@@ -162,7 +161,6 @@ inilint_SOURCES = \
  IniDBBuilderPackage.h \
  inilex.ll \
  iniparse.yy \
- IniParseFeedback.cc \
  IniParseFeedback.h \
  install.cc \
  io_stream.cc \
diff --git a/ini.cc b/ini.cc
index 78684a7..2c568e1 100644
--- a/ini.cc
+++ b/ini.cc
@@ -66,8 +66,6 @@ static BoolOption NoVersionCheckOption (false, '\0', "no-version-check", "Suppre
 
 extern int yyparse ();
 
-/*extern int yydebug;*/
-
 class GuiParseFeedback : public IniParseFeedback
 {
 public:
@@ -76,6 +74,9 @@ public:
       Progress.SetText2 ("");
       Progress.SetText3 ("");
       Progress.SetText4 ("Progress:");
+
+      yyerror_count = 0;
+      yyerror_messages.clear ();
     }
   virtual void progress (unsigned long const pos, unsigned long const max)
     {
@@ -102,6 +103,7 @@ public:
       Progress.SetText1 ("Parsing...");
       Progress.SetText2 (name.c_str ());
       Progress.SetText3 ("");
+      filename = name;
     }
   virtual void babble (const std::string& message)const
     {
@@ -111,9 +113,26 @@ public:
     {
       mbox (Progress.GetHWND(), message.c_str (), "Warning", 0);
     }
-  virtual void error (const std::string& message)const
+  virtual void note_error(int lineno, const std::string &error)
+    {
+      char tmp[16];
+      sprintf (tmp, "%d", lineno);
+
+      std::string e = filename + " line " + tmp + ": " + error;
+
+      if (!yyerror_messages.empty ())
+        yyerror_messages += "\n";
+
+      yyerror_messages += e;
+      yyerror_count++;
+    }
+  virtual bool has_errors () const
+    {
+      return (yyerror_count > 0);
+    }
+  virtual void show_errors () const
     {
-      mbox (Progress.GetHWND(), message.c_str (), "Parse Errors", 0);
+      mbox (Progress.GetHWND(), yyerror_messages.c_str (), "Parse Errors", 0);
     }
   virtual ~ GuiParseFeedback ()
     {
@@ -121,10 +140,13 @@ public:
     }
 private:
   unsigned int lastpct;
+  std::string filename;
+  std::string yyerror_messages;
+  int yyerror_count;
 };
 
 static io_stream*
-decompress_ini (io_stream *ini_file)
+decompress_ini (io_stream *ini_file, std::string &current_ini_name)
 {
   // Replace the current compressed setup stream with its decompressed
   // version.  Which decompressor to use is determined by file magic.
@@ -228,7 +250,7 @@ do_local_ini (HWND owner)
       ini_file = check_ini_sig (ini_file, ini_sig_file, sig_fail,
  "localdir", current_ini_sig_name.c_str (), owner);
       if (ini_file)
- ini_file = decompress_ini (ini_file);
+ ini_file = decompress_ini (ini_file, current_ini_name);
       if (!ini_file || sig_fail)
  {
   // no setup found or signature invalid
@@ -247,9 +269,9 @@ do_local_ini (HWND owner)
     rfc1738_unescape (current_ini_name.substr (ldl, cap - ldl));
   ini_init (ini_file, &aBuilder, myFeedback);
 
-  if (yyparse () || yyerror_count > 0)
+  if (yyparse () || myFeedback.has_errors())
     {
-      myFeedback.error (yyerror_messages);
+      myFeedback.show_errors ();
       ini_error = true;
     }
 
@@ -299,7 +321,7 @@ do_remote_ini (HWND owner)
     break;
  }
       if (ini_file)
- ini_file = decompress_ini (ini_file);
+ ini_file = decompress_ini (ini_file, current_ini_name);
       if (!ini_file || sig_fail)
  {
   // no setup found or signature invalid
@@ -313,9 +335,9 @@ do_remote_ini (HWND owner)
   aBuilder.parse_mirror = n->url;
   ini_init (ini_file, &aBuilder, myFeedback);
 
-  if (yyparse () || yyerror_count > 0)
+  if (yyparse () || myFeedback.has_errors())
     {
-      myFeedback.error (yyerror_messages);
+      myFeedback.show_errors ();
       ini_error = true;
     }
   else
diff --git a/ini.h b/ini.h
index 07e1a46..3ff9617 100644
--- a/ini.h
+++ b/ini.h
@@ -42,15 +42,6 @@ void ini_init (io_stream *, IniDBBuilderPackage *, IniParseFeedback &);
    packages (the chosen "install" field).  install.cc installs
    selected packages. */
 
-/* The following three vars are used to facilitate error handling between the
-   parser/lexer and its callers, namely ini.cc:do_remote_ini() and
-   IniParseFindVisitor::visitFile().  */
-
-extern std::string current_ini_name;  /* current filename/URL being parsed */
-extern std::string current_ini_sig_name;  /* current filename/URL for sig file */
-extern std::string yyerror_messages;  /* textual parse error messages */
-extern int yyerror_count;             /* number of parse errors */
-
 /* The following definitions are used in the parser implementation */
 
 #define hexnibble(val)  ('\xff' & (val > '9') ? val - 'a' + 10 : val - '0')
diff --git a/inilex.ll b/inilex.ll
index 209152f..0147b4d 100644
--- a/inilex.ll
+++ b/inilex.ll
@@ -168,8 +168,6 @@ B64 [a-zA-Z0-9_-]
 static io_stream *input_stream = 0;
 extern IniDBBuilderPackage *iniBuilder;
 static IniParseFeedback *iniFeedback;
-std::string current_ini_name, yyerror_messages;
-int yyerror_count;
 
 void
 ini_init(io_stream *stream, IniDBBuilderPackage *aBuilder, IniParseFeedback &aFeedback)
@@ -179,8 +177,6 @@ ini_init(io_stream *stream, IniDBBuilderPackage *aBuilder, IniParseFeedback &aFe
   iniFeedback = &aFeedback;
   YY_FLUSH_BUFFER;
   yylineno = 1;
-  yyerror_count = 0;
-  yyerror_messages.clear ();
 }
 
 static int
@@ -214,20 +210,8 @@ ignore_line ()
     }
 }
 
-int
+void
 yyerror (const std::string& s)
 {
-  char tmp[16];
-  sprintf (tmp, "%d", yylineno - (!!YY_AT_BOL ()));
-  
-  std::string e = current_ini_name + " line " + tmp + ": " + s;
-  
-  if (!yyerror_messages.empty ())
-    yyerror_messages += "\n";
-
-  yyerror_messages += e;
-  // OutputDebugString (e.c_str ());
-  yyerror_count++;
-  /* TODO: is return 0 correct? */
-  return 0;
+  iniFeedback->note_error(yylineno - (!!YY_AT_BOL ()), s);
 }
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

[PATCH setup 3/7] Add CliParseFeedback class

Jon TURNEY
In reply to this post by Jon TURNEY
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

Reply | Threaded
Open this post in threaded view
|

[PATCH setup 4/7] Restore abstract base class IniDBBuilder

Jon TURNEY
In reply to this post by Jon TURNEY
This effectively reverts commit 618bd457849ed44d301d27d81d3b2f262f798897.
---
 IniDBBuilder.h        | 58 +++++++++++++++++++++++++++++++++++++++++++
 IniDBBuilderPackage.h |  6 ++---
 ini.h                 |  4 +--
 inilex.ll             |  4 +--
 iniparse.yy           |  4 +--
 5 files changed, 66 insertions(+), 10 deletions(-)
 create mode 100644 IniDBBuilder.h

diff --git a/IniDBBuilder.h b/IniDBBuilder.h
new file mode 100644
index 0000000..3b89041
--- /dev/null
+++ b/IniDBBuilder.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2002, Robert Collins.
+ *
+ *     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/
+ *
+ * Written by Robert Collins  <[hidden email]>
+ *
+ */
+
+#ifndef SETUP_INIDBBUILDER_H
+#define SETUP_INIDBBUILDER_H
+
+#include "PackageSpecification.h"
+#include "PackageTrust.h"
+
+enum class hashType { none, md5, sha512 };
+
+class IniDBBuilder
+{
+public:
+  virtual ~IniDBBuilder() {};
+
+  virtual void buildTimestamp (const std::string& ) = 0;
+  virtual void buildVersion (const std::string& ) = 0;
+  virtual const std::string buildMinimumVersion(const std::string &) = 0;
+  virtual void buildPackage (const std::string& ) = 0;
+  virtual void buildPackageVersion (const std::string& ) = 0;
+  virtual void buildPackageSDesc (const std::string& ) = 0;
+  virtual void buildPackageLDesc (const std::string& ) = 0;
+  virtual void buildPackageInstall (const std::string&, const std::string&,
+                                    char *, hashType) = 0;
+  virtual void buildPackageSource (const std::string&, const std::string&,
+                                   char *, hashType) = 0;
+  virtual void buildPackageTrust (trusts) = 0;
+  virtual void buildPackageCategory (const std::string& ) = 0;
+  virtual void buildBeginDepends () = 0;
+  virtual void buildBeginBuildDepends () = 0;
+  virtual void buildBeginObsoletes () = 0;
+  virtual void buildBeginProvides () = 0;
+  virtual void buildBeginConflicts () = 0;
+  virtual void buildMessage (const std::string&, const std::string&) = 0;
+  virtual void buildSourceName (const std::string& ) = 0;
+  virtual void buildSourceNameVersion (const std::string& ) = 0;
+  virtual void buildPackageListNode (const std::string& ) = 0;
+  virtual void buildPackageListOperator (PackageSpecification::_operators const &) = 0;
+  virtual void buildPackageListOperatorVersion (const std::string& ) = 0;
+  virtual void buildPackageReplaceVersionsList (const std::string& ) = 0;
+  virtual void set_arch (const std::string& a) = 0;
+  virtual void set_release (const std::string& rel) = 0;
+};
+
+#endif /* SETUP_INIDBBUILDER_H */
diff --git a/IniDBBuilderPackage.h b/IniDBBuilderPackage.h
index e5d3662..3e3a9e4 100644
--- a/IniDBBuilderPackage.h
+++ b/IniDBBuilderPackage.h
@@ -16,20 +16,18 @@
 #ifndef SETUP_INIDBBUILDERPACKAGE_H
 #define SETUP_INIDBBUILDERPACKAGE_H
 
+#include "IniDBBuilder.h"
 #include <vector>
 #include <set>
 
 #include "package_message.h"
-#include "PackageTrust.h"
 #include "String++.h"
 #include "libsolv.h"
 
 class IniParseFeedback;
 class packagesource;
 
-enum class hashType { none, md5, sha512 };
-
-class IniDBBuilderPackage
+class IniDBBuilderPackage:public IniDBBuilder
 {
 public:
   IniDBBuilderPackage (IniParseFeedback const &);
diff --git a/ini.h b/ini.h
index 3ff9617..1e4f889 100644
--- a/ini.h
+++ b/ini.h
@@ -30,9 +30,9 @@ extern std::string SetupIniDir;
 extern std::string SetupBaseName;
 
 class IniState;
-class IniDBBuilderPackage;
+class IniDBBuilder;
 class IniParseFeedback;
-void ini_init (io_stream *, IniDBBuilderPackage *, IniParseFeedback &);
+void ini_init (io_stream *, IniDBBuilder *, IniParseFeedback &);
 #define YYSTYPE char *
 
 /* When setup.ini is parsed, the information is stored according to
diff --git a/inilex.ll b/inilex.ll
index 0147b4d..26a95e3 100644
--- a/inilex.ll
+++ b/inilex.ll
@@ -166,11 +166,11 @@ B64 [a-zA-Z0-9_-]
 #include "io_stream.h"
 
 static io_stream *input_stream = 0;
-extern IniDBBuilderPackage *iniBuilder;
+extern IniDBBuilder *iniBuilder;
 static IniParseFeedback *iniFeedback;
 
 void
-ini_init(io_stream *stream, IniDBBuilderPackage *aBuilder, IniParseFeedback &aFeedback)
+ini_init(io_stream *stream, IniDBBuilder *aBuilder, IniParseFeedback &aFeedback)
 {
   input_stream = stream;
   iniBuilder = aBuilder;
diff --git a/iniparse.yy b/iniparse.yy
index f85fe13..ca9b8a7 100644
--- a/iniparse.yy
+++ b/iniparse.yy
@@ -25,13 +25,13 @@
 extern int yyerror (const std::string& s);
 int yylex ();
 
-#include "IniDBBuilderPackage.h"
+#include "IniDBBuilder.h"
 
 #define YYERROR_VERBOSE 1
 #define YYINITDEPTH 1000
 /*#define YYDEBUG 1*/
 
-IniDBBuilderPackage *iniBuilder;
+IniDBBuilder *iniBuilder;
 extern int yylineno;
 %}
 
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

[PATCH setup 5/7] Fix building inilint

Jon TURNEY
In reply to this post by Jon TURNEY
Fix Makefile.am for inilint
Always build inilint, so it doesn't rust again
---
 Makefile.am  | 24 ++----------------------
 configure.ac | 13 -------------
 2 files changed, 2 insertions(+), 35 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 0ef3d6e..04bb668 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,10 +33,7 @@ AM_CPPFLAGS = -DLZMA_API_STATIC -I$(srcdir)/libgetopt++/include \
 
 inilex_CXXFLAGS:=-Wno-sign-compare
 
-noinst_PROGRAMS = @SETUP@$(EXEEXT) @INILINT@
-
-EXTRA_PROGRAMS = inilint
-## noinst_PROGRAMS +=inilint
+noinst_PROGRAMS = @SETUP@$(EXEEXT) inilint
 
 EXTRA_DIST = \
  CHANGES \
@@ -62,34 +59,17 @@ CLEANFILES = setup_version.c
 
 inilint_LDADD = \
  libgetopt++/libgetopt++.la
+
 inilint_SOURCES = \
  CliParseFeedback.cc \
  CliParseFeedback.h \
- filemanip.cc \
- filemanip.h \
- find.cc \
- find.h \
- FindVisitor.cc \
- FindVisitor.h \
  LogSingleton.cc \
  LogSingleton.h \
  IniDBBuilder.h \
  inilintmain.cc \
  inilex.ll \
  iniparse.yy \
- io_stream.h \
- io_stream.cc \
- io_stream_file.h \
- io_stream_file.cc \
- IOStreamProvider.h \
- mkdir.cc \
- mkdir.h \
- mklink2.cc \
- PackageSpecification.cc \
- PackageSpecification.h \
  PackageTrust.h \
- csu_util/rfc1738.cc \
- csu_util/rfc1738.h \
  String++.cc \
  String++.h
 
diff --git a/configure.ac b/configure.ac
index 08fe16b..ab6f3ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,19 +23,6 @@ dnl AM_CONFIG_HEADER(include/autoconf.h)
 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES(yes)])
 AC_CONFIG_SRCDIR([Makefile.in])
 
-AC_MSG_CHECKING([Whether to build inilint])
-AC_ARG_ENABLE(inilint,
-    AC_HELP_STRING([--enable-inilint],
-   [Build the inilint tool]),
-    ac_cv_enable_inilint=$enableval, ac_cv_enable_inilint=no)
-AC_MSG_RESULT([$ac_cv_enable_inilint])
-if test $ac_cv_enable_inilint = yes; then
-  INILINT="inilint\$(EXEEXT)"
-else
-  INILINT=
-fi
-AC_SUBST(INILINT)
-
 AC_LANG_CPLUSPLUS
 AC_PROG_CXX
 AM_PROG_CC_C_O
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

[PATCH setup 6/7] Pass a "Install for all users" flag into setDefaultSecurity()

Jon TURNEY
In reply to this post by Jon TURNEY
Pass an "Install for all users" flag into setDefaultSecurity(), rather
than evaluating it there, for better decoupling from settings & UI.
---
 main.cc  | 2 +-
 win32.cc | 5 ++---
 win32.h  | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/main.cc b/main.cc
index 749b00c..5de1f36 100644
--- a/main.cc
+++ b/main.cc
@@ -355,7 +355,7 @@ WinMain (HINSTANCE h,
     else
       {
  /* Set default DACL and Group. */
- nt_sec.setDefaultSecurity ();
+ nt_sec.setDefaultSecurity ((root_scope == IDC_ROOT_SYSTEM));
 
  UserSettings Settings (local_dir);
  main_display ();
diff --git a/win32.cc b/win32.cc
index 0981355..6a551ba 100644
--- a/win32.cc
+++ b/win32.cc
@@ -18,7 +18,6 @@
 #include <malloc.h>
 #include "LogFile.h"
 #include "resource.h"
-#include "state.h"
 #include "ini.h"
 #include <sys/stat.h>
 
@@ -308,7 +307,7 @@ NTSecurity::setAdminGroup ()
 }
 
 void
-NTSecurity::setDefaultSecurity ()
+NTSecurity::setDefaultSecurity (bool isAdmin)
 {
   /* Get the processes access token. */
   if (!OpenProcessToken (GetCurrentProcess (),
@@ -359,7 +358,7 @@ NTSecurity::setDefaultSecurity ()
   /* Try to set the primary group to the Administrators group, but only if
      "Install for all users" has been chosen.  If it doesn't work, we're
      no admin and that's all there's to say about it. */
-  if (root_scope == IDC_ROOT_SYSTEM)
+  if (isAdmin)
     setAdminGroup ();
 }
 
diff --git a/win32.h b/win32.h
index c866790..1b9db49 100644
--- a/win32.h
+++ b/win32.h
@@ -130,7 +130,7 @@ public:
   void resetPrimaryGroup();
   void setAdminGroup ();
   void initialiseWellKnownSIDs ();
-  void setDefaultSecurity();
+  void setDefaultSecurity(bool isAdmin);
   bool isRunAsAdmin ();
 private:
   void NoteFailedAPI (const std::string &);
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

[PATCH setup 7/7] Make inilint do something slightly useful

Jon TURNEY
In reply to this post by Jon TURNEY
Add IniDBBuilderLint, a do-nothing subclass of InitDBBuilder
Use CliParseFeedback for parser feedback
---
 IniDBBuilderLint.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 Makefile.am        | 17 ++++++++++++--
 ini.cc             |  2 --
 ini.h              |  2 ++
 inilintmain.cc     | 31 ++++++++++++++++++++++----
 5 files changed, 99 insertions(+), 8 deletions(-)
 create mode 100644 IniDBBuilderLint.h

diff --git a/IniDBBuilderLint.h b/IniDBBuilderLint.h
new file mode 100644
index 0000000..29a98ee
--- /dev/null
+++ b/IniDBBuilderLint.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2002, Robert Collins.
+ *
+ *     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/
+ *
+ * Written by Robert Collins  <[hidden email]>
+ *
+ */
+
+#ifndef SETUP_INIDBBUILDERLINT_H
+#define SETUP_INIDBBUILDERLINT_H
+
+#include "IniDBBuilder.h"
+
+class IniDBBuilderLint:public IniDBBuilder
+{
+public:
+  virtual ~IniDBBuilderLint() {};
+
+  virtual void buildTimestamp (const std::string& ) {};
+  virtual void buildVersion (const std::string& ) {};
+  virtual const std::string buildMinimumVersion(const std::string &s) { return ""; }
+  virtual void buildPackage (const std::string& ) {};
+  virtual void buildPackageVersion (const std::string& ) {};
+  virtual void buildPackageSDesc (const std::string& ) {};
+  virtual void buildPackageLDesc (const std::string& ) {};
+  virtual void buildPackageInstall (const std::string&, const std::string&,
+                                    char *, hashType) {};
+  virtual void buildPackageSource (const std::string&, const std::string&,
+                                   char *, hashType) {};
+  virtual void buildPackageTrust (trusts) {};
+  virtual void buildPackageCategory (const std::string& ) {};
+  virtual void buildBeginDepends () {};
+  virtual void buildBeginBuildDepends () {};
+  virtual void buildBeginObsoletes () {};
+  virtual void buildBeginProvides () {};
+  virtual void buildBeginConflicts () {};
+  virtual void buildMessage (const std::string&, const std::string&) {};
+  virtual void buildSourceName (const std::string& ) {};
+  virtual void buildSourceNameVersion (const std::string& ) {};
+  virtual void buildPackageListNode (const std::string& ) {};
+  virtual void buildPackageListOperator (PackageSpecification::_operators const &) {};
+  virtual void buildPackageListOperatorVersion (const std::string& ) {};
+  virtual void buildPackageReplaceVersionsList (const std::string& ) {};
+  virtual void set_arch (const std::string& a) {};
+  virtual void set_release (const std::string& rel) {};
+};
+
+#endif /* SETUP_INIDBBUILDERLINT_H */
diff --git a/Makefile.am b/Makefile.am
index 04bb668..4ceeb98 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -58,9 +58,12 @@ BUILT_SOURCES = \
 CLEANFILES = setup_version.c
 
 inilint_LDADD = \
- libgetopt++/libgetopt++.la
+ libgetopt++/libgetopt++.la \
+ -lntdll -luuid
 
 inilint_SOURCES = \
+ filemanip.cc \
+ filemanip.h \
  CliParseFeedback.cc \
  CliParseFeedback.h \
  LogSingleton.cc \
@@ -69,9 +72,19 @@ inilint_SOURCES = \
  inilintmain.cc \
  inilex.ll \
  iniparse.yy \
+ io_stream.cc \
+ io_stream.h \
+ io_stream_file.cc \
+ io_stream_file.h \
+ mkdir.cc \
+ mkdir.h \
+ mklink2.cc \
+ mklink2.h \
  PackageTrust.h \
  String++.cc \
- String++.h
+ String++.h \
+ win32.cc \
+ win32.h
 
 @SETUP@_LDADD = \
  libgetopt++/libgetopt++.la \
diff --git a/ini.cc b/ini.cc
index 2c568e1..ee9c648 100644
--- a/ini.cc
+++ b/ini.cc
@@ -64,8 +64,6 @@ IniList setup_ext_list (setup_exts,
 static BoolOption NoVerifyOption (false, 'X', "no-verify", "Don't verify setup.ini signatures");
 static BoolOption NoVersionCheckOption (false, '\0', "no-version-check", "Suppress checking if a newer version of setup is available");
 
-extern int yyparse ();
-
 class GuiParseFeedback : public IniParseFeedback
 {
 public:
diff --git a/ini.h b/ini.h
index 1e4f889..ecc4b78 100644
--- a/ini.h
+++ b/ini.h
@@ -42,6 +42,8 @@ void ini_init (io_stream *, IniDBBuilder *, IniParseFeedback &);
    packages (the chosen "install" field).  install.cc installs
    selected packages. */
 
+extern int yyparse ();
+
 /* The following definitions are used in the parser implementation */
 
 #define hexnibble(val)  ('\xff' & (val > '9') ? val - 'a' + 10 : val - '0')
diff --git a/inilintmain.cc b/inilintmain.cc
index 7ae98ff..f31e5eb 100644
--- a/inilintmain.cc
+++ b/inilintmain.cc
@@ -13,23 +13,46 @@
  *
  */
 
-#include "getopt++/GetOption.h"
+#include "io_stream.h"
+#include "IniDBBuilderLint.h"
+#include "CliParseFeedback.h"
+#include "ini.h"
 #include <iostream>
+#include <sstream>
+#include "LogSingleton.h"
 
 void
 show_help()
 {
-  std::cout << "inilint checks cygwin setup.ini files and reports any errors with" << std::endl;
-  std::cout << "diagnostics" << std::endl;
+  std::cout << "inilint checks cygwin setup.ini files and reports any errors" << std::endl;
 }
 
 int
 main (int argc, char **argv)
 {
-  if (!GetOption::GetInstance().Process (argc,argv,NULL))
+  if (argc != 2)
     {
       show_help();
       return 1;
     }
+
+  std::string inifilename = argv[1];
+
+  // Note: this only accepts absolute pathnames
+  io_stream *ini_file = io_stream::open ("file://" + inifilename, "rb", 0);
+  if (!ini_file)
+    {
+      std::cerr << "could not open " << inifilename << std::endl;
+      return 1;
+    }
+
+  CliParseFeedback feedback;
+  IniDBBuilderLint builder;
+  ini_init(ini_file, &builder, feedback);
+
+  // Note: unrecognized lines are ignored by ignore_line(), so this is currently
+  // only useful for finding where recognized lines don't fit the grammar.
+  yyparse();
+
   return 0;
 }
--
2.21.0