[beast: 18/20] SFI: avoid using Rapicorn in sfidl, cut-and-paste the few rquired functions
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 18/20] SFI: avoid using Rapicorn in sfidl, cut-and-paste the few rquired functions
- Date: Sun, 24 Sep 2017 00:21:09 +0000 (UTC)
commit 81df39c05957af97e1bbef86bfc09871f7b2eaf0
Author: Tim Janik <timj gnu org>
Date: Sun Sep 17 15:33:22 2017 +0200
SFI: avoid using Rapicorn in sfidl, cut-and-paste the few rquired functions
Signed-off-by: Tim Janik <timj gnu org>
sfi/sfidl-parser.hh | 10 +++---
sfi/sfidl-utils.cc | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++
sfi/sfidl-utils.hh | 13 ++++----
3 files changed, 89 insertions(+), 11 deletions(-)
---
diff --git a/sfi/sfidl-parser.hh b/sfi/sfidl-parser.hh
index 5113bea..742851c 100644
--- a/sfi/sfidl-parser.hh
+++ b/sfi/sfidl-parser.hh
@@ -265,11 +265,11 @@ protected:
static void scannerMsgHandler (GScanner *scanner, gchar *message, gboolean is_error);
- template<class... Args> void print_error (const char *format, const Args &...args)
- {
- if (scanner->parse_errors < scanner->max_parse_errors)
- g_scanner_error (scanner, "%s", string_format (format, args...).c_str());
- }
+#define print_error(...) ({ \
+ if (scanner->parse_errors < scanner->max_parse_errors) \
+ g_scanner_error (scanner, "%s", string_format (__VA_ARGS__).c_str()); \
+ })
+
template<class... Args> void print_warning (const char *format, const Args &...args)
{
g_scanner_warn (scanner, "%s", string_format (format, args...).c_str());
diff --git a/sfi/sfidl-utils.cc b/sfi/sfidl-utils.cc
index 3644c7a..ad0778c 100644
--- a/sfi/sfidl-utils.cc
+++ b/sfi/sfidl-utils.cc
@@ -2,6 +2,83 @@
namespace Sfidl {
+extern inline unichar unicode_tolower (unichar uc) { return g_unichar_tolower (uc); }
+
+String
+string_tolower (const String &str)
+{
+ String s (str);
+ for (size_t i = 0; i < s.size(); i++)
+ s[i] = unicode_tolower (s[i]);
+ return s;
+}
+
+#define LLI (long long int)
+#define LLU (long long unsigned int)
+
+String
+string_from_int (int64 value)
+{
+ return string_format ("%lld", LLI value);
+}
+
+String
+string_from_uint (uint64 value)
+{
+ return string_format ("%llu", LLU value);
+}
+
+static std::string
+string_vformat (const char *format, va_list argv)
+{
+ if (!format)
+ return "";
+ int l;
+ {
+ const int length = 256; // fast path, use small buffer
+ char buffer[length + 1] = { 0, }; // zero fill buffer
+ va_list argv2;
+ va_copy (argv2, argv);
+ l = vsnprintf (buffer, length, format, argv2);
+ va_end (argv2);
+ if (l >= 0 && l <= length)
+ return buffer;
+ }
+ if (l < 0)
+ return format;
+ l += 1; // avoid off-by-one errors in printf
+ std::string output;
+ output.resize (l + 1, 0);
+ va_list argv2;
+ va_copy (argv2, argv);
+ const int j = vsnprintf (&output[0], l, format, argv2);
+ va_end (argv2);
+ if (j < 0 || j > l)
+ return format;
+ return output;
+}
+
+std::string
+string_format (const char *format, ...)
+{
+ va_list argv;
+ va_start (argv, format);
+ std::string output = string_vformat (format, argv);
+ va_end (argv);
+ return output;
+}
+
+void
+printerr (const char *format, ...)
+{
+ va_list argv;
+ va_start (argv, format);
+ fflush (stdout);
+ vfprintf (stderr, format, argv);
+ fflush (stderr);
+ va_end (argv);
+}
+
/** returns true for C++ style identifiers (Foo::BAR) - only the colons are checked, not individual chars
*/
bool
diff --git a/sfi/sfidl-utils.hh b/sfi/sfidl-utils.hh
index 2a2b562..30b0345 100644
--- a/sfi/sfidl-utils.hh
+++ b/sfi/sfidl-utils.hh
@@ -9,12 +9,13 @@
/// The Sfidl namespace contains implementation and API of the Sfi IDL compiler.
namespace Sfidl {
-using Rapicorn::String;
-using Rapicorn::string_tolower;
-using Rapicorn::printerr;
-using Rapicorn::string_from_int;
-using Rapicorn::string_from_uint;
-using Rapicorn::string_format;
+using Bse::String;
+
+String string_tolower (const String &str);
+String string_from_int (int64 value);
+String string_from_uint (uint64 value);
+String string_format (const char *format, ...) __attribute__ ((__format__ (printf, 1, 2)));
+void printerr (const char *format, ...) __attribute__ ((__format__ (printf, 1, 2)));
/* common data structures */
using std::list;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]