Author: mfilka
Date: Thu May 10 12:16:00 2012
New Revision: 68131
URL: http://svn.opensuse.org/viewcvs/yast?rev=68131&view=rev
Log:
support for shell like quoting/unquoting and escaping/unescaping in ag_ini
Added:
trunk/core/agent-ini/src/glib/
trunk/core/agent-ini/src/glib/glibconfig.h
trunk/core/agent-ini/src/glib/gmacros.h
trunk/core/agent-ini/src/glib/gmem.c
trunk/core/agent-ini/src/glib/gmem.h
trunk/core/agent-ini/src/glib/gshell.c
trunk/core/agent-ini/src/glib/gshell.h
trunk/core/agent-ini/src/glib/gslice.c
trunk/core/agent-ini/src/glib/gslice.h
trunk/core/agent-ini/src/glib/gstrfuncs.c
trunk/core/agent-ini/src/glib/gstrfuncs.h
trunk/core/agent-ini/src/glib/gstring.c
trunk/core/agent-ini/src/glib/gstring.h
trunk/core/agent-ini/src/glib/gtypes.h
trunk/core/agent-ini/testsuite/tests/shellquotes.err
trunk/core/agent-ini/testsuite/tests/shellquotes.in
trunk/core/agent-ini/testsuite/tests/shellquotes.out
trunk/core/agent-ini/testsuite/tests/shellquotes.scr
trunk/core/agent-ini/testsuite/tests/shellquotes.ycp
Modified:
trunk/core/VERSION
trunk/core/agent-ini/src/IniParser.cc
trunk/core/agent-ini/src/IniParser.h
trunk/core/agent-ini/src/Makefile.am
trunk/core/agent-ini/testsuite/tests/multiline1.out (props changed)
trunk/core/package/yast2-core.changes
Modified: trunk/core/VERSION
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/VERSION?rev=68131&r1=68130&r2=68131&view=diff
==============================================================================
--- trunk/core/VERSION (original)
+++ trunk/core/VERSION Thu May 10 12:16:00 2012
@@ -1 +1 @@
-2.22.5
+2.23.0
Modified: trunk/core/agent-ini/src/IniParser.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/IniParser.cc?rev=68131&r1=68130&r2=68131&view=diff
==============================================================================
--- trunk/core/agent-ini/src/IniParser.cc (original)
+++ trunk/core/agent-ini/src/IniParser.cc Thu May 10 12:16:00 2012
@@ -25,6 +25,7 @@
#include "IniParser.h"
#include "IniFile.h"
+#include "glib/gshell.h"
IMPL_BASE_POINTER (Regex_t);
@@ -174,7 +175,7 @@
//
ignore_case_regexps = ignore_case = prefer_uppercase = first_upper = line_can_continue = no_nested_sections =
global_values = repeat_names = comments_last = join_multiline =
- no_finalcomment_kill = read_only = flat = false;
+ no_finalcomment_kill = read_only = flat = shell_quoted_value = false;
// read the options
YCPValue v = scr->value(YCPString("options"));
@@ -204,6 +205,7 @@
COMPARE_OPTION (no_finalcomment_kill)
COMPARE_OPTION (read_only)
COMPARE_OPTION (flat)
+ COMPARE_OPTION (shell_quoted_value)
y2error ("Option not implemented yet: %s", sv.c_str());
#undef COMPARE_OPTION
}
@@ -561,6 +563,34 @@
return 0;
}
+string IniParser::quote_value( const char * value) const
+{
+ if( !shell_quoted_value)
+ return string( value);
+
+ char * qstr = NULL;
+ qstr = g_shell_quote( value);
+
+ string ret = qstr;
+ g_free( qstr);
+
+ return ret;
+}
+
+string IniParser::unquote_value( const char * value) const
+{
+ if( !shell_quoted_value)
+ return string( value);
+
+ char * ustr = NULL;
+ ustr = g_shell_unquote( value);
+
+ string ret = ustr;
+ g_free( ustr);
+
+ return ret;
+}
+
int IniParser::parse_helper(IniSection&ini)
{
string comment = "";
@@ -631,10 +661,13 @@
if (!global_values)
scanner_error ("%s: values at the top level not allowed.", key.c_str ());
else
- ini.initValue (key, val, comment, matched_by);
+ {
+ ini.initValue (key, unquote_value( val.c_str()), comment, matched_by);
+ }
}
- else {
- open_sections.front()->initValue(key, val, comment, matched_by);
+ else
+ {
+ open_sections.front()->initValue(key, unquote_value( val.c_str()), comment, matched_by);
}
comment = "";
}
@@ -803,11 +836,13 @@
if (!global_values)
scanner_error ("%s: values at the top level not allowed.", key.c_str ());
else
- ini.initValue (key, val, comment, i);
+ {
+ ini.initValue (key, unquote_value( val.c_str()), comment, i);
+ }
}
else
{
- open_sections.front()->initValue(key, val, comment, i);
+ open_sections.front()->initValue(key, unquote_value( val.c_str()), comment, i);
}
comment = "";
}
@@ -1053,9 +1088,10 @@
IniEntry&e = ci->e ();
if (e.getComment ()[0])
of << e.getComment();
- if (e.getReadBy()>=0 && e.getReadBy() < (int)params.size ()) {
+ if (e.getReadBy()>=0 && e.getReadBy() < (int)params.size ())
+ {
// bnc#492859, a fixed buffer is too small
- asprintf (&out_buffer, params[e.getReadBy ()].line.out.c_str (), e.getName(), e.getValue());
+ asprintf (&out_buffer, params[e.getReadBy ()].line.out.c_str (), e.getName(), quote_value( e.getValue()).c_str());
of << indent2 << out_buffer << "\n";
free(out_buffer);
}
@@ -1074,6 +1110,7 @@
ini.clean();
return 0;
}
+
string IniParser::getFileName (const string&sec, int rb) const
{
string file = sec;
Modified: trunk/core/agent-ini/src/IniParser.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/IniParser.h?rev=68131&r1=68130&r2=68131&view=diff
==============================================================================
--- trunk/core/agent-ini/src/IniParser.h (original)
+++ trunk/core/agent-ini/src/IniParser.h Thu May 10 12:16:00 2012
@@ -300,6 +300,8 @@
bool read_only;
/** ini file sections are created in flat-mode */
bool flat;
+ /** assume that value is shell string - quoted on write, unquoted on read */
+ bool shell_quoted_value;
/** this string is printed before each line in subsections */
string subindent;
@@ -377,6 +379,16 @@
* Write one ini file.
*/
int write_helper(IniSection&ini, ofstream&of,int depth);
+
+ /**
+ * Creates copy of the value. The result is shell safe.
+ */
+ string quote_value( const char * value) const;
+
+ /**
+ * Creates copy of the value. Removes quotes and escape sequences according shell rules.
+ */
+ string unquote_value( const char * value) const;
public:
/**
* If Write (.s.section_name, nil) was called in multiple files mode,
Modified: trunk/core/agent-ini/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/Makefile.am?rev=68131&r1=68130&r2=68131&view=diff
==============================================================================
--- trunk/core/agent-ini/src/Makefile.am (original)
+++ trunk/core/agent-ini/src/Makefile.am Thu May 10 12:16:00 2012
@@ -13,7 +13,20 @@
IniParser.cc \
IniParser.h \
IniFile.cc \
- IniFile.h
+ IniFile.h \
+ glib/gstrfuncs.c \
+ glib/gtypes.h \
+ glib/gshell.c \
+ glib/gstring.h \
+ glib/gstring.c \
+ glib/glibconfig.h \
+ glib/gshell.h \
+ glib/gmem.c \
+ glib/gstrfuncs.h \
+ glib/gslice.h \
+ glib/gslice.c \
+ glib/gmacros.h \
+ glib/gmem.h
liby2ag_ini_la_LDFLAGS = -version-info 2:0
liby2ag_ini_la_LIBADD = @AGENT_LIBADD@
Added: trunk/core/agent-ini/src/glib/glibconfig.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/glibconfig.h?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/glibconfig.h (added)
+++ trunk/core/agent-ini/src/glib/glibconfig.h Thu May 10 12:16:00 2012
@@ -0,0 +1,22 @@
+/* glibconfig.h
+ *
+ * This is a generated file. Please modify 'configure.ac'
+ */
+
+#ifndef __GLIBCONFIG_H__
+#define __GLIBCONFIG_H__
+
+#include "gmacros.h"
+
+G_BEGIN_DECLS
+
+typedef signed long gssize;
+typedef unsigned long gsize;
+
+#define G_MAXSIZE G_MAXULONG
+
+#define g_memmove(dest,src,len) G_STMT_START { memmove ((dest), (src), (len)); } G_STMT_END
+
+G_END_DECLS
+
+#endif /* __GLIBCONFIG_H__ */
Added: trunk/core/agent-ini/src/glib/gmacros.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gmacros.h?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gmacros.h (added)
+++ trunk/core/agent-ini/src/glib/gmacros.h Thu May 10 12:16:00 2012
@@ -0,0 +1,339 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+/* This file must not include any other glib header file and must thus
+ * not refer to variables from glibconfig.h
+ */
+
+#ifndef __G_MACROS_H__
+#define __G_MACROS_H__
+
+/* We include stddef.h to get the system's definition of NULL
+ */
+#include
+
+/* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
+ * where this is valid. This allows for warningless compilation of
+ * "long long" types even in the presence of '-ansi -pedantic'.
+ */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
+# define G_GNUC_EXTENSION __extension__
+#else
+# define G_GNUC_EXTENSION
+#endif
+
+/* Provide macros to feature the GCC function attribute.
+ */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+#define G_GNUC_PURE \
+ __attribute__((__pure__))
+#define G_GNUC_MALLOC \
+ __attribute__((__malloc__))
+#else
+#define G_GNUC_PURE
+#define G_GNUC_MALLOC
+#endif
+
+#if __GNUC__ >= 4
+#define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
+#else
+#define G_GNUC_NULL_TERMINATED
+#endif
+
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
+#define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
+#else
+#define G_GNUC_ALLOC_SIZE(x)
+#define G_GNUC_ALLOC_SIZE2(x,y)
+#endif
+
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
+#define G_GNUC_PRINTF( format_idx, arg_idx ) \
+ __attribute__((__format__ (__printf__, format_idx, arg_idx)))
+#define G_GNUC_SCANF( format_idx, arg_idx ) \
+ __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
+#define G_GNUC_FORMAT( arg_idx ) \
+ __attribute__((__format_arg__ (arg_idx)))
+#define G_GNUC_NORETURN \
+ __attribute__((__noreturn__))
+#define G_GNUC_CONST \
+ __attribute__((__const__))
+#define G_GNUC_UNUSED \
+ __attribute__((__unused__))
+#define G_GNUC_NO_INSTRUMENT \
+ __attribute__((__no_instrument_function__))
+#else /* !__GNUC__ */
+#define G_GNUC_PRINTF( format_idx, arg_idx )
+#define G_GNUC_SCANF( format_idx, arg_idx )
+#define G_GNUC_FORMAT( arg_idx )
+#define G_GNUC_NORETURN
+#define G_GNUC_CONST
+#define G_GNUC_UNUSED
+#define G_GNUC_NO_INSTRUMENT
+#endif /* !__GNUC__ */
+
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+#define G_GNUC_DEPRECATED \
+ __attribute__((__deprecated__))
+#else
+#define G_GNUC_DEPRECATED
+#endif /* __GNUC__ */
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#define G_GNUC_DEPRECATED_FOR(f) \
+ __attribute__((deprecated("Use " #f " instead")))
+#else
+#define G_GNUC_DEPRECATED_FOR(f) G_GNUC_DEPRECATED
+#endif /* __GNUC__ */
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+#define G_GNUC_END_IGNORE_DEPRECATIONS \
+ _Pragma ("GCC diagnostic pop")
+#else
+#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+#define G_GNUC_END_IGNORE_DEPRECATIONS
+#endif
+
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+# define G_GNUC_MAY_ALIAS __attribute__((may_alias))
+#else
+# define G_GNUC_MAY_ALIAS
+#endif
+
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#define G_GNUC_WARN_UNUSED_RESULT \
+ __attribute__((warn_unused_result))
+#else
+#define G_GNUC_WARN_UNUSED_RESULT
+#endif /* __GNUC__ */
+
+#ifndef G_DISABLE_DEPRECATED
+/* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
+ * macros, so we can refer to them as strings unconditionally.
+ * usage not-recommended since gcc-3.0
+ */
+#if defined (__GNUC__) && (__GNUC__ < 3)
+#define G_GNUC_FUNCTION __FUNCTION__
+#define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
+#else /* !__GNUC__ */
+#define G_GNUC_FUNCTION ""
+#define G_GNUC_PRETTY_FUNCTION ""
+#endif /* !__GNUC__ */
+#endif /* !G_DISABLE_DEPRECATED */
+
+#define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
+#define G_STRINGIFY_ARG(contents) #contents
+
+#ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
+#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
+#define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
+#ifdef __COUNTER__
+#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1]
+#else
+#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1]
+#endif
+#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
+#endif
+
+/* Provide a string identifying the current code position */
+#if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
+# define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
+#else
+# define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
+#endif
+
+/* Provide a string identifying the current function, non-concatenatable */
+#if defined (__GNUC__)
+# define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__))
+#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 19901L
+# define G_STRFUNC ((const char*) (__func__))
+#elif defined(_MSC_VER) && (_MSC_VER > 1300)
+# define G_STRFUNC ((const char*) (__FUNCTION__))
+#else
+# define G_STRFUNC ((const char*) ("???"))
+#endif
+
+/* Guard C code in headers, while including them from C++ */
+#ifdef __cplusplus
+# define G_BEGIN_DECLS extern "C" {
+# define G_END_DECLS }
+#else
+# define G_BEGIN_DECLS
+# define G_END_DECLS
+#endif
+
+/* Provide definitions for some commonly used macros.
+ * Some of them are only provided if they haven't already
+ * been defined. It is assumed that if they are already
+ * defined then the current definition is correct.
+ */
+#ifndef NULL
+# ifdef __cplusplus
+# define NULL (0L)
+# else /* !__cplusplus */
+# define NULL ((void*) 0)
+# endif /* !__cplusplus */
+#endif
+
+#ifndef FALSE
+#define FALSE (0)
+#endif
+
+#ifndef TRUE
+#define TRUE (!FALSE)
+#endif
+
+#undef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+
+#undef MIN
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+
+#undef ABS
+#define ABS(a) (((a) < 0) ? -(a) : (a))
+
+#undef CLAMP
+#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
+
+/* Count the number of elements in an array. The array must be defined
+ * as such; using this with a dynamically allocated array will give
+ * incorrect results.
+ */
+#define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
+
+/* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
+ */
+#define GPOINTER_TO_SIZE(p) ((gsize) (p))
+#define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
+
+/* Provide convenience macros for handling structure
+ * fields through their offsets.
+ */
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+# define G_STRUCT_OFFSET(struct_type, member) \
+ ((glong) offsetof (struct_type, member))
+#else
+# define G_STRUCT_OFFSET(struct_type, member) \
+ ((glong) ((guint8*) &((struct_type*) 0)->member))
+#endif
+
+#define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
+ ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
+#define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
+ (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
+
+/* Provide simple macro statement wrappers:
+ * G_STMT_START { statements; } G_STMT_END;
+ * This can be used as a single statement, like:
+ * if (x) G_STMT_START { ... } G_STMT_END; else ...
+ * This intentionally does not use compiler extensions like GCC's '({...})' to
+ * avoid portability issue or side effects when compiled with different compilers.
+ */
+#if !(defined (G_STMT_START) && defined (G_STMT_END))
+# define G_STMT_START do
+# define G_STMT_END while (0)
+#endif
+
+/* Deprecated -- do not use. */
+#ifndef G_DISABLE_DEPRECATED
+#ifdef G_DISABLE_CONST_RETURNS
+#define G_CONST_RETURN
+#else
+#define G_CONST_RETURN const
+#endif
+#endif
+
+/*
+ * The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
+ * the compiler about the expected result of an expression. Some compilers
+ * can use this information for optimizations.
+ *
+ * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
+ * putting assignments in g_return_if_fail ().
+ */
+#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
+#define _G_BOOLEAN_EXPR(expr) \
+ G_GNUC_EXTENSION ({ \
+ int _g_boolean_var_; \
+ if (expr) \
+ _g_boolean_var_ = 1; \
+ else \
+ _g_boolean_var_ = 0; \
+ _g_boolean_var_; \
+})
+#define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
+#define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
+#else
+#define G_LIKELY(expr) (expr)
+#define G_UNLIKELY(expr) (expr)
+#endif
+
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+#define G_DEPRECATED __attribute__((__deprecated__))
+#elif defined(_MSC_VER) && (_MSC_VER >= 1300)
+#define G_DEPRECATED __declspec(deprecated)
+#else
+#define G_DEPRECATED
+#endif
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
+#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
+#define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))
+#else
+#define G_DEPRECATED_FOR(f) G_DEPRECATED
+#endif
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#define G_UNAVAILABLE(maj,min) __attribute__((deprecated("Not available before " #maj "." #min)))
+#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
+#define G_UNAVAILABLE(maj,min) __declspec(deprecated("is not available before " #maj "." #min))
+#else
+#define G_UNAVAILABLE(maj,min)
+#endif
+
+/* These macros are used to mark deprecated functions in GLib headers,
+ * and thus have to be exposed in installed headers. But please
+ * do *not* use them in other projects. Instead, use G_DEPRECATED
+ * or define your own wrappers around it.
+ */
+
+#ifdef GLIB_DISABLE_DEPRECATION_WARNINGS
+#define GLIB_DEPRECATED
+#define GLIB_DEPRECATED_FOR(f)
+#define GLIB_UNAVAILABLE(maj,min)
+#else
+#define GLIB_DEPRECATED G_DEPRECATED
+#define GLIB_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f)
+#define GLIB_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min)
+#endif
+
+#endif /* __G_MACROS_H__ */
Added: trunk/core/agent-ini/src/glib/gmem.c
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gmem.c?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gmem.c (added)
+++ trunk/core/agent-ini/src/glib/gmem.c Thu May 10 12:16:00 2012
@@ -0,0 +1,157 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+/*
+ * MT safe
+ */
+
+#include "gmem.h"
+
+#include
+
+#define standard_malloc malloc
+#define standard_realloc realloc
+#define standard_free free
+
+/* --- variables --- */
+static GMemVTable glib_mem_vtable = {
+ standard_malloc,
+ standard_realloc,
+ standard_free,
+ NULL,
+ NULL,
+ NULL
+};
+
+/**
+ * SECTION:memory
+ * @Short_Description: general memory-handling
+ * @Title: Memory Allocation
+ *
+ * These functions provide support for allocating and freeing memory.
+ *
+ * <note>
+ * If any call to allocate memory fails, the application is terminated.
+ * This also means that there is no need to check if the call succeeded.
+ * </note>
+ *
+ * <note>
+ * It's important to match g_malloc() with g_free(), plain malloc() with free(),
+ * and (if you're using C++) new with delete and new[] with delete[]. Otherwise
+ * bad things can happen, since these allocators may use different memory
+ * pools (and new/delete call constructors and destructors). See also
+ * g_mem_set_vtable().
+ * </note>
+ */
+
+/* --- functions --- */
+/**
+ * g_malloc:
+ * @n_bytes: the number of bytes to allocate
+ *
+ * Allocates @n_bytes bytes of memory.
+ * If @n_bytes is 0 it returns %NULL.
+ *
+ * Returns: a pointer to the allocated memory
+ */
+gpointer
+g_malloc (gsize n_bytes)
+{
+ if (G_LIKELY (n_bytes))
+ {
+ gpointer mem;
+
+ mem = glib_mem_vtable.malloc (n_bytes);
+ if (mem)
+ return mem;
+ }
+
+ return NULL;
+}
+
+/**
+ * g_realloc:
+ * @mem: the memory to reallocate
+ * @n_bytes: new size of the memory in bytes
+ *
+ * Reallocates the memory pointed to by @mem, so that it now has space for
+ * @n_bytes bytes of memory. It returns the new address of the memory, which may
+ * have been moved. @mem may be %NULL, in which case it's considered to
+ * have zero-length. @n_bytes may be 0, in which case %NULL will be returned
+ * and @mem will be freed unless it is %NULL.
+ *
+ * Returns: the new address of the allocated memory
+ */
+gpointer
+g_realloc (gpointer mem,
+ gsize n_bytes)
+{
+ gpointer newmem;
+
+ if (G_LIKELY (n_bytes))
+ {
+ newmem = glib_mem_vtable.realloc (mem, n_bytes);
+ if (newmem)
+ return newmem;
+ }
+
+ if (mem)
+ glib_mem_vtable.free (mem);
+
+ return NULL;
+}
+
+/**
+ * g_free:
+ * @mem: the memory to free
+ *
+ * Frees the memory pointed to by @mem.
+ * If @mem is %NULL it simply returns.
+ */
+void
+g_free (gpointer mem)
+{
+ if (G_LIKELY (mem))
+ glib_mem_vtable.free (mem);
+}
+
+/**
+ * g_malloc_n:
+ * @n_blocks: the number of blocks to allocate
+ * @n_block_bytes: the size of each block in bytes
+ *
+ * This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
+ * but care is taken to detect possible overflow during multiplication.
+ *
+ * Since: 2.24
+ * Returns: a pointer to the allocated memory
+ */
+gpointer
+g_malloc_n (gsize n_blocks,
+ gsize n_block_bytes)
+{
+ return g_malloc (n_blocks * n_block_bytes);
+}
Added: trunk/core/agent-ini/src/glib/gmem.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gmem.h?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gmem.h (added)
+++ trunk/core/agent-ini/src/glib/gmem.h Thu May 10 12:16:00 2012
@@ -0,0 +1,100 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef __G_MEM_H__
+#define __G_MEM_H__
+
+#include "gtypes.h"
+
+G_BEGIN_DECLS
+
+/**
+ * GMemVTable:
+ * @malloc: function to use for allocating memory.
+ * @realloc: function to use for reallocating memory.
+ * @free: function to use to free memory.
+ * @calloc: function to use for allocating zero-filled memory.
+ * @try_malloc: function to use for allocating memory without a default error handler.
+ * @try_realloc: function to use for reallocating memory without a default error handler.
+ *
+ * A set of functions used to perform memory allocation. The same #GMemVTable must
+ * be used for all allocations in the same program; a call to g_mem_set_vtable(),
+ * if it exists, should be prior to any use of GLib.
+ */
+typedef struct _GMemVTable GMemVTable;
+
+void g_free (gpointer mem);
+
+gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+gpointer g_realloc (gpointer mem,
+ gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT;
+
+gpointer g_malloc_n (gsize n_blocks,
+ gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
+
+#define _G_NEW(struct_type, n_structs, func) \
+ ((struct_type *) g_##func##_n ((n_structs), sizeof (struct_type)))
+#define _G_RENEW(struct_type, mem, n_structs, func) \
+ ((struct_type *) g_##func##_n (mem, (n_structs), sizeof (struct_type)))
+
+/**
+ * g_new:
+ * @struct_type: the type of the elements to allocate
+ * @n_structs: the number of elements to allocate
+ *
+ * Allocates @n_structs elements of type @struct_type.
+ * The returned pointer is cast to a pointer to the given type.
+ * If @n_structs is 0 it returns %NULL.
+ * Care is taken to avoid overflow when calculating the size of the allocated block.
+ *
+ * Since the returned pointer is already casted to the right type,
+ * it is normally unnecessary to cast it explicitly, and doing
+ * so might hide memory allocation errors.
+ *
+ * Returns: a pointer to the allocated memory, cast to a pointer to @struct_type
+ */
+#define g_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc)
+
+/* Memory allocation virtualization for debugging purposes
+ * g_mem_set_vtable() has to be the very first GLib function called
+ * if being used
+ */
+struct _GMemVTable {
+ gpointer (*malloc) (gsize n_bytes);
+ gpointer (*realloc) (gpointer mem,
+ gsize n_bytes);
+ void (*free) (gpointer mem);
+ /* optional; set to NULL if not used ! */
+ gpointer (*calloc) (gsize n_blocks,
+ gsize n_block_bytes);
+ gpointer (*try_malloc) (gsize n_bytes);
+ gpointer (*try_realloc) (gpointer mem,
+ gsize n_bytes);
+};
+
+G_END_DECLS
+
+#endif /* __G_MEM_H__ */
Added: trunk/core/agent-ini/src/glib/gshell.c
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gshell.c?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gshell.c (added)
+++ trunk/core/agent-ini/src/glib/gshell.c Thu May 10 12:16:00 2012
@@ -0,0 +1,283 @@
+/* gshell.c - Shell-related utilities
+ *
+ * Copyright 2000 Red Hat, Inc.
+ * g_execvpe implementation based on GNU libc execvp:
+ * Copyright 1991, 92, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
+ *
+ * GLib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * GLib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GLib; see the file COPYING.LIB. If not, write
+ * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include
+
+#include "gshell.h"
+
+#include "gstrfuncs.h"
+#include "gstring.h"
+#include "gmem.h"
+
+static gboolean
+unquote_string_inplace (gchar* str, gchar** end)
+{
+ gchar* dest;
+ gchar* s;
+ gchar quote_char;
+
+ if( ( end == NULL) || ( str == NULL))
+ return FALSE;
+
+ dest = s = str;
+
+ quote_char = *s;
+
+ if (!(*s == '"' || *s == '\''))
+ {
+ *end = str;
+ return FALSE;
+ }
+
+ /* Skip the initial quote mark */
+ ++s;
+
+ if (quote_char == '"')
+ {
+ while (*s)
+ {
+ switch (*s)
+ {
+ case '"':
+ /* End of the string, return now */
+ *dest = '\0';
+ ++s;
+ *end = s;
+ return TRUE;
+ break;
+
+ case '\\':
+ /* Possible escaped quote or \ */
+ ++s;
+ switch (*s)
+ {
+ case '"':
+ case '\\':
+ case '`':
+ case '$':
+ case '\n':
+ *dest = *s;
+ ++s;
+ ++dest;
+ break;
+
+ default:
+ /* not an escaped char */
+ *dest = '\\';
+ ++dest;
+ /* ++s already done. */
+ break;
+ }
+ break;
+
+ default:
+ *dest = *s;
+ ++dest;
+ ++s;
+ break;
+ }
+ }
+ }
+ else
+ {
+ int escape = 0;
+
+ while (*s)
+ {
+ if ( (*s == '\'') && !escape)
+ {
+ /* End of the string, return now */
+ *dest = '\0';
+ ++s;
+ *end = s;
+ return TRUE;
+ }
+ else
+ {
+ escape = *s == '\\' ? 1 : 0;
+ *dest = *s;
+ ++dest;
+ ++s;
+ }
+ }
+ }
+
+ /* If we reach here this means the close quote was never encountered */
+
+ *dest = '\0';
+ *end = s;
+
+ return FALSE;
+}
+
+/**
+ * g_shell_quote:
+ * @unquoted_string: a literal string
+ *
+ * Quotes a string so that the shell (/bin/sh) will interpret the
+ * quoted string to mean @unquoted_string. If you pass a filename to
+ * the shell, for example, you should first quote it with this
+ * function. The return value must be freed with g_free(). The
+ * quoting style used is undefined (single or double quotes may be
+ * used).
+ *
+ * Return value: quoted string
+ **/
+gchar*
+g_shell_quote (const gchar *unquoted_string)
+{
+ /* We always use single quotes, because the algorithm is cheesier.
+ * We could use double if we felt like it, that might be more
+ * human-readable.
+ */
+
+ const gchar *p;
+ GString *dest;
+
+ if( unquoted_string == NULL)
+ return NULL;
+
+ dest = g_string_new ("'");
+
+ p = unquoted_string;
+
+ /* could speed this up a lot by appending chunks of text at a
+ * time.
+ */
+ while (*p)
+ {
+ /* Replace literal ' with a close ', a \', and a open ' */
+ if (*p == '\'')
+ g_string_append (dest, "'\\''");
+ else
+ g_string_append_c (dest, *p);
+
+ ++p;
+ }
+
+ /* close the quote */
+ g_string_append_c (dest, '\'');
+
+ return g_string_free (dest, FALSE);
+}
+
+/**
+ * g_shell_unquote:
+ * @quoted_string: shell-quoted string
+ * @error: error return location or NULL
+ *
+ * Unquotes a string as the shell (/bin/sh) would. Only handles
+ * quotes; if a string contains file globs, arithmetic operators,
+ * variables, backticks, redirections, or other special-to-the-shell
+ * features, the result will be different from the result a real shell
+ * would produce (the variables, backticks, etc. will be passed
+ * through literally instead of being expanded). This function is
+ * guaranteed to succeed if applied to the result of
+ * g_shell_quote(). If it fails, it returns %NULL and sets the
+ * error. The @quoted_string need not actually contain quoted or
+ * escaped text; g_shell_unquote() simply goes through the string and
+ * unquotes/unescapes anything that the shell would. Both single and
+ * double quotes are handled, as are escapes including escaped
+ * newlines. The return value must be freed with g_free(). Possible
+ * errors are in the #G_SHELL_ERROR domain.
+ *
+ * Shell quoting rules are a bit strange. Single quotes preserve the
+ * literal string exactly. escape sequences are not allowed; not even
+ * \' - if you want a ' in the quoted text, you have to do something
+ * like 'foo'\''bar'. Double quotes allow $, `, ", \, and newline to
+ * be escaped with backslash. Otherwise double quotes preserve things
+ * literally.
+ *
+ * Return value: an unquoted string
+ **/
+gchar*
+g_shell_unquote (const gchar *quoted_string)
+{
+ gchar *unquoted;
+ gchar *end;
+ gchar *start;
+ GString *retval;
+
+ if( quoted_string == NULL)
+ return NULL;
+
+ unquoted = g_strdup (quoted_string);
+
+ start = unquoted;
+ end = unquoted;
+ retval = g_string_new (NULL);
+
+ /* The loop allows cases such as
+ * "foo"blah blah'bar'woo foo"baz"la la la\'\''foo'
+ */
+ while (*start)
+ {
+ /* Append all non-quoted chars, honoring backslash escape
+ */
+
+ while (*start && !(*start == '"' || *start == '\''))
+ {
+ if (*start == '\\')
+ {
+ /* all characters can get escaped by backslash,
+ * except newline, which is removed if it follows
+ * a backslash outside of quotes
+ */
+
+ ++start;
+ if (*start)
+ {
+ if (*start != '\n')
+ g_string_append_c (retval, *start);
+ ++start;
+ }
+ }
+ else
+ {
+ g_string_append_c (retval, *start);
+ ++start;
+ }
+ }
+
+ if (*start)
+ {
+ if (!unquote_string_inplace (start, &end))
+ {
+ goto error;
+ }
+ else
+ {
+ g_string_append (retval, start);
+ start = end;
+ }
+ }
+ }
+
+ g_free (unquoted);
+ return g_string_free (retval, FALSE);
+
+ error:
+ g_free (unquoted);
+ g_string_free (retval, TRUE);
+
+ return NULL;
+}
Added: trunk/core/agent-ini/src/glib/gshell.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gshell.h?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gshell.h (added)
+++ trunk/core/agent-ini/src/glib/gshell.h Thu May 10 12:16:00 2012
@@ -0,0 +1,41 @@
+/* gshell.h - Shell-related utilities
+ *
+ * SUSE:
+ * Minimal subset which supports shell like quoting/unquoting. Extracted
+ * from GLib with minor modifications.
+ *
+ * Copyright 2000 Red Hat, Inc.
+ *
+ * GLib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * GLib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GLib; see the file COPYING.LIB. If not, write
+ * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __G_SHELL_H__
+#define __G_SHELL_H__
+
+#include "gtypes.h"
+#include "gmem.h"
+
+G_BEGIN_DECLS
+
+gchar* g_shell_quote (const gchar *unquoted_string);
+gchar* g_shell_unquote (const gchar *quoted_string);
+gboolean g_shell_parse_argv (const gchar *command_line,
+ gint *argcp,
+ gchar ***argvp);
+
+G_END_DECLS
+
+#endif /* __G_SHELL_H__ */
Added: trunk/core/agent-ini/src/glib/gslice.c
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gslice.c?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gslice.c (added)
+++ trunk/core/agent-ini/src/glib/gslice.c Thu May 10 12:16:00 2012
@@ -0,0 +1,73 @@
+/* GLIB sliced memory - fast concurrent memory chunk allocator
+ * Copyright (C) 2005 Tim Janik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+/* MT safe */
+
+#include "gmem.h" /* gslice.h */
+#include "gslice.h"
+
+/**
+ * g_slice_alloc:
+ * @block_size: the number of bytes to allocate
+ *
+ * Allocates a block of memory from the slice allocator.
+ * The block adress handed out can be expected to be aligned
+ * to at least <literal>1 * sizeof (void*)</literal>,
+ * though in general slices are 2 * sizeof (void*) bytes aligned,
+ * if a malloc() fallback implementation is used instead,
+ * the alignment may be reduced in a libc dependent fashion.
+ * Note that the underlying slice allocation mechanism can
+ * be changed with the <link linkend="G_SLICE">G_SLICE=always-malloc</link>
+ * environment variable.
+ *
+ * Returns: a pointer to the allocated memory block
+ *
+ * Since: 2.10
+ */
+gpointer
+g_slice_alloc (gsize mem_size)
+{
+ gpointer mem;
+ mem = g_malloc (mem_size);
+
+ return mem;
+}
+
+/**
+ * g_slice_free1:
+ * @block_size: the size of the block
+ * @mem_block: a pointer to the block to free
+ *
+ * Frees a block of memory.
+ *
+ * The memory must have been allocated via g_slice_alloc() or
+ * g_slice_alloc0() and the @block_size has to match the size
+ * specified upon allocation. Note that the exact release behaviour
+ * can be changed with the
+ * <link linkend="G_DEBUG">G_DEBUG=gc-friendly</link> environment
+ * variable, also see <link linkend="G_SLICE">G_SLICE</link> for
+ * related debugging options.
+ *
+ * Since: 2.10
+ */
+void
+g_slice_free1 (gsize mem_size,
+ gpointer mem_block)
+{
+ g_free (mem_block);
+}
Added: trunk/core/agent-ini/src/glib/gslice.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gslice.h?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gslice.h (added)
+++ trunk/core/agent-ini/src/glib/gslice.h Thu May 10 12:16:00 2012
@@ -0,0 +1,40 @@
+/* GLIB sliced memory - fast threaded memory chunk allocator
+ * Copyright (C) 2005 Tim Janik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __G_SLICE_H__
+#define __G_SLICE_H__
+
+#include "gtypes.h"
+
+G_BEGIN_DECLS
+
+/* slices - fast allocation/release of small memory blocks
+ */
+gpointer g_slice_alloc (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+void g_slice_free1 (gsize block_size,
+ gpointer mem_block);
+#define g_slice_new(type) ((type*) g_slice_alloc (sizeof (type)))
+#define g_slice_free(type, mem) do { \
+ if (1) g_slice_free1 (sizeof (type), (mem)); \
+ else (void) ((type*) 0 == (mem)); \
+} while (0)
+
+G_END_DECLS
+
+#endif /* __G_SLICE_H__ */
Added: trunk/core/agent-ini/src/glib/gstrfuncs.c
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gstrfuncs.c?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gstrfuncs.c (added)
+++ trunk/core/agent-ini/src/glib/gstrfuncs.c Thu May 10 12:16:00 2012
@@ -0,0 +1,65 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+/*
+ * MT safe
+ */
+
+#include
+#include
+
+/* do not include here, it may interfere with g_strsignal() */
+
+#include "gstrfuncs.h"
+#include "gmem.h"
+
+/**
+ * g_strdup:
+ * @str: the string to duplicate
+ *
+ * Duplicates a string. If @str is %NULL it returns %NULL.
+ * The returned string should be freed with g_free()
+ * when no longer needed.
+ *
+ * Returns: a newly-allocated copy of @str
+ */
+gchar*
+g_strdup (const gchar *str)
+{
+ gchar *new_str;
+ gsize length;
+
+ if (str)
+ {
+ length = strlen (str) + 1;
+ new_str = g_new (char, length);
+ memcpy (new_str, str, length);
+ }
+ else
+ new_str = NULL;
+
+ return new_str;
+}
Added: trunk/core/agent-ini/src/glib/gstrfuncs.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gstrfuncs.h?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gstrfuncs.h (added)
+++ trunk/core/agent-ini/src/glib/gstrfuncs.h Thu May 10 12:16:00 2012
@@ -0,0 +1,41 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef __G_STRFUNCS_H__
+#define __G_STRFUNCS_H__
+
+#include "gtypes.h"
+
+G_BEGIN_DECLS
+
+/* String utility functions that return a newly allocated string which
+ * ought to be freed with g_free from the caller at some point.
+ */
+gchar* g_strdup (const gchar *str) G_GNUC_MALLOC;
+
+G_END_DECLS
+
+#endif /* __G_STRFUNCS_H__ */
Added: trunk/core/agent-ini/src/glib/gstring.c
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gstring.c?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gstring.c (added)
+++ trunk/core/agent-ini/src/glib/gstring.c Thu May 10 12:16:00 2012
@@ -0,0 +1,397 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+/*
+ * MT safe
+ */
+
+#include
+#include
+
+#include "gstring.h"
+#include "gmem.h"
+#include "gslice.h"
+
+/**
+ * SECTION:strings
+ * @title: Strings
+ * @short_description: text buffers which grow automatically
+ * as text is added
+ *
+ * A #GString is an object that handles the memory management
+ * of a C string for you. You can think of it as similar to a
+ * Java StringBuffer. In addition to the string itself, GString
+ * stores the length of the string, so can be used for binary
+ * data with embedded nul bytes. To access the C string managed
+ * by the GString @string, simply use @string->str.
+ */
+
+/**
+ * GString:
+ * @str: points to the character data. It may move as text is added.
+ * The @str field is null-terminated and so
+ * can be used as an ordinary C string.
+ * @len: contains the length of the string, not including the
+ * terminating nul byte.
+ * @allocated_len: the number of bytes that can be stored in the
+ * string before it needs to be reallocated. May be larger than @len.
+ *
+ * The GString struct contains the public fields of a GString.
+ */
+
+
+#define MY_MAXSIZE ((gsize)-1)
+
+static inline gsize
+nearest_power (gsize base, gsize num)
+{
+ if (num > MY_MAXSIZE / 2)
+ {
+ return MY_MAXSIZE;
+ }
+ else
+ {
+ gsize n = base;
+
+ while (n < num)
+ n <<= 1;
+
+ return n;
+ }
+}
+
+static void
+g_string_maybe_expand (GString *string,
+ gsize len)
+{
+ if (string->len + len >= string->allocated_len)
+ {
+ string->allocated_len = nearest_power (1, string->len + len + 1);
+ string->str = g_realloc (string->str, string->allocated_len);
+ }
+}
+
+/**
+ * g_string_sized_new:
+ * @dfl_size: the default size of the space allocated to
+ * hold the string
+ *
+ * Creates a new #GString, with enough space for @dfl_size
+ * bytes. This is useful if you are going to add a lot of
+ * text to the string and don't want it to be reallocated
+ * too often.
+ *
+ * Returns: the new #GString
+ */
+static GString *
+g_string_sized_new (gsize dfl_size)
+{
+ GString *string = g_slice_new (GString);
+
+ string->allocated_len = 0;
+ string->len = 0;
+ string->str = NULL;
+
+ g_string_maybe_expand (string, MAX (dfl_size, 2));
+ string->str[0] = 0;
+
+ return string;
+}
+
+/**
+ * g_string_new:
+ * @init: the initial text to copy into the string
+ *
+ * Creates a new #GString, initialized with the given string.
+ *
+ * Returns: the new #GString
+ */
+GString *
+g_string_new (const gchar *init)
+{
+ GString *string;
+
+ if (init == NULL || *init == '\0')
+ string = g_string_sized_new (2);
+ else
+ {
+ gint len;
+
+ len = strlen (init);
+ string = g_string_sized_new (len + 2);
+
+ g_string_append_len (string, init, len);
+ }
+
+ return string;
+}
+
+/**
+ * g_string_free:
+ * @string: a #GString
+ * @free_segment: if %TRUE, the actual character data is freed as well
+ *
+ * Frees the memory allocated for the #GString.
+ * If @free_segment is %TRUE it also frees the character data. If
+ * it's %FALSE, the caller gains ownership of the buffer and must
+ * free it after use with g_free().
+ *
+ * Returns: the character data of @string
+ * (i.e. %NULL if @free_segment is %TRUE)
+ */
+gchar *
+g_string_free (GString *string,
+ gboolean free_segment)
+{
+ gchar *segment;
+
+ if( string == NULL)
+ return NULL;
+
+ if (free_segment)
+ {
+ g_free (string->str);
+ segment = NULL;
+ }
+ else
+ segment = string->str;
+
+ g_slice_free (GString, string);
+
+ return segment;
+}
+
+/**
+ * g_string_insert_len:
+ * @string: a #GString
+ * @pos: position in @string where insertion should
+ * happen, or -1 for at the end
+ * @val: bytes to insert
+ * @len: number of bytes of @val to insert
+ *
+ * Inserts @len bytes of @val into @string at @pos.
+ * Because @len is provided, @val may contain embedded
+ * nuls and need not be nul-terminated. If @pos is -1,
+ * bytes are inserted at the end of the string.
+ *
+ * Since this function does not stop at nul bytes, it is
+ * the caller's responsibility to ensure that @val has at
+ * least @len addressable bytes.
+ *
+ * Returns: @string
+ */
+static GString *
+g_string_insert_len (GString *string,
+ gssize pos,
+ const gchar *val,
+ gssize len)
+{
+ if( string == NULL)
+ return NULL;
+ if( ( len != 0) && ( val == NULL))
+ return string;
+
+ if (len == 0)
+ return string;
+
+ if (len < 0)
+ len = strlen (val);
+
+ if (pos < 0)
+ pos = string->len;
+ else
+ {
+ if( pos > string->len)
+ return string;
+ }
+
+ /* Check whether val represents a substring of string.
+ * This test probably violates chapter and verse of the C standards,
+ * since ">=" and "<=" are only valid when val really is a substring.
+ * In practice, it will work on modern archs.
+ */
+ if (val >= string->str && val <= string->str + string->len)
+ {
+ gsize offset = val - string->str;
+ gsize precount = 0;
+
+ g_string_maybe_expand (string, len);
+ val = string->str + offset;
+ /* At this point, val is valid again. */
+
+ /* Open up space where we are going to insert. */
+ if (pos < string->len)
+ g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
+
+ /* Move the source part before the gap, if any. */
+ if (offset < pos)
+ {
+ precount = MIN (len, pos - offset);
+ memcpy (string->str + pos, val, precount);
+ }
+
+ /* Move the source part after the gap, if any. */
+ if (len > precount)
+ memcpy (string->str + pos + precount,
+ val + /* Already moved: */ precount + /* Space opened up: */ len,
+ len - precount);
+ }
+ else
+ {
+ g_string_maybe_expand (string, len);
+
+ /* If we aren't appending at the end, move a hunk
+ * of the old string to the end, opening up space
+ */
+ if (pos < string->len)
+ g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
+
+ /* insert the new string */
+ if (len == 1)
+ string->str[pos] = *val;
+ else
+ memcpy (string->str + pos, val, len);
+ }
+
+ string->len += len;
+
+ string->str[string->len] = 0;
+
+ return string;
+}
+
+/**
+ * g_string_append:
+ * @string: a #GString
+ * @val: the string to append onto the end of @string
+ *
+ * Adds a string onto the end of a #GString, expanding
+ * it if necessary.
+ *
+ * Returns: @string
+ */
+GString *
+g_string_append (GString *string,
+ const gchar *val)
+{
+ if( string == NULL)
+ return NULL;
+ if( val == NULL)
+ return string;
+
+ return g_string_insert_len (string, -1, val, -1);
+}
+
+/**
+ * g_string_append_len:
+ * @string: a #GString
+ * @val: bytes to append
+ * @len: number of bytes of @val to use
+ *
+ * Appends @len bytes of @val to @string. Because @len is
+ * provided, @val may contain embedded nuls and need not
+ * be nul-terminated.
+ *
+ * Since this function does not stop at nul bytes, it is
+ * the caller's responsibility to ensure that @val has at
+ * least @len addressable bytes.
+ *
+ * Returns: @string
+ */
+GString *
+g_string_append_len (GString *string,
+ const gchar *val,
+ gssize len)
+{
+ if( string == NULL)
+ return NULL;
+ if( ( len != 0) && (val == NULL) )
+ return string;
+
+ return g_string_insert_len (string, -1, val, len);
+}
+
+/**
+ * g_string_append_c:
+ * @string: a #GString
+ * @c: the byte to append onto the end of @string
+ *
+ * Adds a byte onto the end of a #GString, expanding
+ * it if necessary.
+ *
+ * Returns: @string
+ */
+#undef g_string_append_c
+GString *
+g_string_append_c (GString *string,
+ gchar c)
+{
+ if( string == NULL)
+ return NULL;
+
+ return g_string_insert_c (string, -1, c);
+}
+
+/**
+ * g_string_insert_c:
+ * @string: a #GString
+ * @pos: the position to insert the byte
+ * @c: the byte to insert
+ *
+ * Inserts a byte into a #GString, expanding it if necessary.
+ *
+ * Returns: @string
+ */
+GString *
+g_string_insert_c (GString *string,
+ gssize pos,
+ gchar c)
+{
+ if( string == NULL)
+ return NULL;
+
+ g_string_maybe_expand (string, 1);
+
+ if (pos < 0)
+ pos = string->len;
+ else
+ {
+ if( pos > string->len)
+ return string;
+ }
+
+ /* If not just an append, move the old stuff */
+ if (pos < string->len)
+ g_memmove (string->str + pos + 1, string->str + pos, string->len - pos);
+
+ string->str[pos] = c;
+
+ string->len += 1;
+
+ string->str[string->len] = 0;
+
+ return string;
+}
Added: trunk/core/agent-ini/src/glib/gstring.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gstring.h?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gstring.h (added)
+++ trunk/core/agent-ini/src/glib/gstring.h Thu May 10 12:16:00 2012
@@ -0,0 +1,61 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef __G_STRING_H__
+#define __G_STRING_H__
+
+#include "gtypes.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GString GString;
+
+struct _GString
+{
+ gchar *str;
+ gsize len;
+ gsize allocated_len;
+};
+
+GString* g_string_new (const gchar *init);
+
+gchar* g_string_free (GString *string,
+ gboolean free_segment);
+GString* g_string_append (GString *string,
+ const gchar *val);
+GString* g_string_append_len (GString *string,
+ const gchar *val,
+ gssize len);
+GString* g_string_append_c (GString *string,
+ gchar c);
+
+GString* g_string_insert_c (GString *string,
+ gssize pos,
+ gchar c);
+
+G_END_DECLS
+
+#endif /* __G_STRING_H__ */
Added: trunk/core/agent-ini/src/glib/gtypes.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/src/glib/gtypes.h?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/src/glib/gtypes.h (added)
+++ trunk/core/agent-ini/src/glib/gtypes.h Thu May 10 12:16:00 2012
@@ -0,0 +1,50 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef __G_TYPES_H__
+#define __G_TYPES_H__
+
+#include "glibconfig.h"
+#include "gmacros.h"
+
+G_BEGIN_DECLS
+
+/* Provide type definitions for commonly used types.
+ * These are useful because a "gint8" can be adjusted
+ * to be 1 byte (8 bits) on all platforms. Similarly and
+ * more importantly, "gint32" can be adjusted to be
+ * 4 bytes (32 bits) on all platforms.
+ */
+
+typedef char gchar;
+typedef int gint;
+typedef gint gboolean;
+
+typedef void* gpointer;
+
+G_END_DECLS
+
+#endif /* __G_TYPES_H__ */
Added: trunk/core/agent-ini/testsuite/tests/shellquotes.err
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/testsuite/tests/shellquotes.err?rev=68131&view=auto
==============================================================================
(empty)
Added: trunk/core/agent-ini/testsuite/tests/shellquotes.in
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/testsuite/tests/shellquotes.in?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/testsuite/tests/shellquotes.in (added)
+++ trunk/core/agent-ini/testsuite/tests/shellquotes.in Thu May 10 12:16:00 2012
@@ -0,0 +1,4 @@
+Val1="string"
+Val2="string1"'string2'
+Val3="shell_quoted_value's \"speciality\""
+
Added: trunk/core/agent-ini/testsuite/tests/shellquotes.out
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/testsuite/tests/shellquotes.out?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/testsuite/tests/shellquotes.out (added)
+++ trunk/core/agent-ini/testsuite/tests/shellquotes.out Thu May 10 12:16:00 2012
@@ -0,0 +1,5 @@
+([])
+Val1='string'
+Val2='string1string2'
+Val3='shell_quoted_value'\''s "speciality"'
+Val4=''\''written'\'' "value"'
Added: trunk/core/agent-ini/testsuite/tests/shellquotes.scr
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/testsuite/tests/shellquotes.scr?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/testsuite/tests/shellquotes.scr (added)
+++ trunk/core/agent-ini/testsuite/tests/shellquotes.scr Thu May 10 12:16:00 2012
@@ -0,0 +1,16 @@
+.
+
+`ag_ini(
+ `IniAgent( "tests/shellquotes.in.test",
+ $[
+ /* values at the top level, allow comments after value */
+ "options" : [ "global_values", "shell_quoted_value" ],
+ /* empty lines, comments after value and whole-line comments */
+ "comments" : [ "^[ \t]*$", "[ \t]*#.*$", "^[ \t]*#.*$" ],
+ /* matching rules */
+ "params" : [
+ /* VAR1="val1 'bal x" */
+ $[ "match" : [ "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)=(.*)", "%s=%s" ] ],
+ ],
+ ]
+))
Added: trunk/core/agent-ini/testsuite/tests/shellquotes.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-ini/testsuite/tests/shellquotes.ycp?rev=68131&view=auto
==============================================================================
--- trunk/core/agent-ini/testsuite/tests/shellquotes.ycp (added)
+++ trunk/core/agent-ini/testsuite/tests/shellquotes.ycp Thu May 10 12:16:00 2012
@@ -0,0 +1,9 @@
+{
+ // multiline values example, does not join values
+
+ // The file is not saved if not changed. We must change something
+ // and flush it!
+// SCR::Write (., "force");
+ SCR::Write (.v.Val4, "'written'\ \"value\"");
+ return SCR::Dir (.s);
+}
Modified: trunk/core/package/yast2-core.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/package/yast2-core.changes?rev=68131&r1=68130&r2=68131&view=diff
==============================================================================
--- trunk/core/package/yast2-core.changes (original)
+++ trunk/core/package/yast2-core.changes Thu May 10 12:16:00 2012
@@ -1,4 +1,10 @@
-------------------------------------------------------------------
+Fri May 4 10:58:48 UTC 2012 - mfilka@suse.com
+
+- added support for shell like (un)quoting and (un)escaping of values
+- 2.23.0
+
+-------------------------------------------------------------------
Mon Mar 19 11:18:22 CET 2012 - aschnell@suse.de
- fixed for gcc 4.7
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org