From 6391823efb2b9012ec99a3524a61307931eb1ee5 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Fri, 3 May 2002 11:41:30 +0000 Subject: [PATCH] 2002-05-03 Robert Collins * String++.h: Declare a << operator that accepts String objects. * String++.cc: We need iostream for.. (operator <<): this. Provide a << operator that accepts String objects. * ini.cc (yyerror): Remove the "C" classifier - it's not needed. Change from vargs to a String parameter. * inilintmail.cc: Remove the gui related headers. (yyerror): Implement this for parsing. * iniparse.y: Use the new yyerror syntax. --- ChangeLog | 11 +++++++++++ String++.cc | 11 +++++++++++ String++.h | 4 ++++ ini.cc | 8 +++----- inilintmain.cc | 24 +++++++++++++++++++++--- iniparse.y | 4 ++-- 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 18250356..751cd31e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-05-03 Robert Collins + + * String++.h: Declare a << operator that accepts String objects. + * String++.cc: We need iostream for.. + (operator <<): this. Provide a << operator that accepts String objects. + * ini.cc (yyerror): Remove the "C" classifier - it's not needed. + Change from vargs to a String parameter. + * inilintmail.cc: Remove the gui related headers. + (yyerror): Implement this for parsing. + * iniparse.y: Use the new yyerror syntax. + 2002-05-03 Robert Collins * Makefile.am: Add IniState.h. diff --git a/String++.cc b/String++.cc index 90c8bdb8..eb0952db 100644 --- a/String++.cc +++ b/String++.cc @@ -20,6 +20,7 @@ #include #include "concat.h" #include "io_stream.h" +#include // _data @@ -227,3 +228,13 @@ String::casecompare (String const lhs, String const rhs) { return lhs.casecompare (rhs); } + +/* TODO: research how wide char and unicode interoperate with + * C++ streams + */ +ostream & +operator << (ostream &os, String const &theString) +{ + os << theString.cstr_oneuse(); + return os; +} diff --git a/String++.h b/String++.h index 5021349e..5faac97a 100644 --- a/String++.h +++ b/String++.h @@ -20,6 +20,7 @@ #include #include +#include class io_stream; class String { @@ -71,6 +72,9 @@ private: static String absorb (unsigned char *, size_t); }; +ostream & +operator << (ostream &os, String const &theString); + String::String() : theData (new _data) {} String::String(String const &aString) : theData (aString.theData) { diff --git a/ini.cc b/ini.cc index e6baa553..478c705f 100644 --- a/ini.cc +++ b/ini.cc @@ -253,15 +253,13 @@ do_ini (HINSTANCE h, HWND owner) extern int yylineno; -extern "C" int -yyerror (char *s, ...) +extern int +yyerror (String const &s) { char buf[1000]; int len; sprintf (buf, "setup.ini line %d: ", yylineno); - va_list args; - va_start (args, s); - vsprintf (buf + strlen (buf), s, args); + sprintf (buf + strlen (buf), s.cstr_oneuse()); OutputDebugString (buf); if (error_buf) { diff --git a/inilintmain.cc b/inilintmain.cc index ae4acf4d..5edd96ff 100644 --- a/inilintmain.cc +++ b/inilintmain.cc @@ -18,10 +18,28 @@ static const char *cvsid = "\n%%% $Id$\n"; #endif -#include "win32.h" -#include - #include "getopt++/GetOption.h" +#include "String++.h" +#include +#include + +extern int yylineno; + +static ostrstream error_buf; +static int error_count = 0; + +extern int +yyerror (String const &s) +{ + ostrstream buf; + buf << "setup.ini line " << yylineno << ": "; + buf << s << endl; + cout << buf; + error_buf << buf; + error_count++; + /* TODO: is return 0 correct? */ + return 0; +} int main (int argc, char **argv) diff --git a/iniparse.y b/iniparse.y index fc139220..17f8a909 100644 --- a/iniparse.y +++ b/iniparse.y @@ -27,7 +27,7 @@ #include "iniparse.h" #include "filemanip.h" -extern "C" int yyerror (char const *s, ...); +extern int yyerror (String const &s); int yylex (); #include "port.h" @@ -109,7 +109,7 @@ simple_line | T_UNKNOWN { trust = TRUST_UNKNOWN; } | /* empty */ | error '\n' { yylineno --; - yyerror ("unrecognized line in package %s (do you have the latest setup?)", cp->name.cstr_oneuse()); + yyerror (String("unrecognized line in package ") + cp->name + " (do you have the latest setup?)"); yylineno ++; } ; -- 2.43.5