New functions.
authorTor Lillqvist <tml@src.gnome.org>
Sat, 31 Jul 1999 21:45:21 +0000 (21:45 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Sat, 31 Jul 1999 21:45:21 +0000 (21:45 +0000)
* gstrfuncs.c (g_strccpy, g_strecpy): New functions.

* glib.h: Declare and document them. Define the deprecated
g_strescape as a macro that calls g_strecpy.

* tests/strfunc-test.c (main): Test them.

* makefile.{cygwin,msc}.in
* tests/makefile.{cygwin,msc}.in: Remove gstack and its test
program.

* glib.def: Additions and removals.

* README.win32: Improve gcc build instructions.

* build-dll: Also build import library for MSVC.

22 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
README.win32
build-dll
glib.def
glib.h
glib/glib.def
glib/glib.h
glib/gstrfuncs.c
glib/makefile.msc.in
gstrfuncs.c
makefile.cygwin.in
makefile.msc.in
tests/makefile.cygwin.in
tests/makefile.msc.in
tests/strfunc-test.c

index c2cddd8..9f3113e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+1999-08-01  Tor Lillqvist  <tml@iki.fi>
+
+       * gstrfuncs.c (g_strccpy, g_strecpy): New functions.
+
+       * glib.h: Declare and document them. Define the deprecated
+       g_strescape as a macro that calls g_strecpy.
+
+       * tests/strfunc-test.c (main): Test them.
+
+       * makefile.{cygwin,msc}.in
+       * tests/makefile.{cygwin,msc}.in: Remove gstack and its test
+       program.
+
+       * glib.def: Additions and removals.
+
+       * README.win32: Improve gcc build instructions.
+
+       * build-dll: Also build import library for MSVC.
+
 Sat Jul 24 20:11:35 1999  Tim Janik  <timj@gtk.org>
 
        * merged GLib 1.3.0 with glib-1.2.3 from Fri Jul 16 22:18:36.
index c2cddd8..9f3113e 100644 (file)
@@ -1,3 +1,22 @@
+1999-08-01  Tor Lillqvist  <tml@iki.fi>
+
+       * gstrfuncs.c (g_strccpy, g_strecpy): New functions.
+
+       * glib.h: Declare and document them. Define the deprecated
+       g_strescape as a macro that calls g_strecpy.
+
+       * tests/strfunc-test.c (main): Test them.
+
+       * makefile.{cygwin,msc}.in
+       * tests/makefile.{cygwin,msc}.in: Remove gstack and its test
+       program.
+
+       * glib.def: Additions and removals.
+
+       * README.win32: Improve gcc build instructions.
+
+       * build-dll: Also build import library for MSVC.
+
 Sat Jul 24 20:11:35 1999  Tim Janik  <timj@gtk.org>
 
        * merged GLib 1.3.0 with glib-1.2.3 from Fri Jul 16 22:18:36.
index c2cddd8..9f3113e 100644 (file)
@@ -1,3 +1,22 @@
+1999-08-01  Tor Lillqvist  <tml@iki.fi>
+
+       * gstrfuncs.c (g_strccpy, g_strecpy): New functions.
+
+       * glib.h: Declare and document them. Define the deprecated
+       g_strescape as a macro that calls g_strecpy.
+
+       * tests/strfunc-test.c (main): Test them.
+
+       * makefile.{cygwin,msc}.in
+       * tests/makefile.{cygwin,msc}.in: Remove gstack and its test
+       program.
+
+       * glib.def: Additions and removals.
+
+       * README.win32: Improve gcc build instructions.
+
+       * build-dll: Also build import library for MSVC.
+
 Sat Jul 24 20:11:35 1999  Tim Janik  <timj@gtk.org>
 
        * merged GLib 1.3.0 with glib-1.2.3 from Fri Jul 16 22:18:36.
index c2cddd8..9f3113e 100644 (file)
@@ -1,3 +1,22 @@
+1999-08-01  Tor Lillqvist  <tml@iki.fi>
+
+       * gstrfuncs.c (g_strccpy, g_strecpy): New functions.
+
+       * glib.h: Declare and document them. Define the deprecated
+       g_strescape as a macro that calls g_strecpy.
+
+       * tests/strfunc-test.c (main): Test them.
+
+       * makefile.{cygwin,msc}.in
+       * tests/makefile.{cygwin,msc}.in: Remove gstack and its test
+       program.
+
+       * glib.def: Additions and removals.
+
+       * README.win32: Improve gcc build instructions.
+
+       * build-dll: Also build import library for MSVC.
+
 Sat Jul 24 20:11:35 1999  Tim Janik  <timj@gtk.org>
 
        * merged GLib 1.3.0 with glib-1.2.3 from Fri Jul 16 22:18:36.
index c2cddd8..9f3113e 100644 (file)
@@ -1,3 +1,22 @@
+1999-08-01  Tor Lillqvist  <tml@iki.fi>
+
+       * gstrfuncs.c (g_strccpy, g_strecpy): New functions.
+
+       * glib.h: Declare and document them. Define the deprecated
+       g_strescape as a macro that calls g_strecpy.
+
+       * tests/strfunc-test.c (main): Test them.
+
+       * makefile.{cygwin,msc}.in
+       * tests/makefile.{cygwin,msc}.in: Remove gstack and its test
+       program.
+
+       * glib.def: Additions and removals.
+
+       * README.win32: Improve gcc build instructions.
+
+       * build-dll: Also build import library for MSVC.
+
 Sat Jul 24 20:11:35 1999  Tim Janik  <timj@gtk.org>
 
        * merged GLib 1.3.0 with glib-1.2.3 from Fri Jul 16 22:18:36.
index c2cddd8..9f3113e 100644 (file)
@@ -1,3 +1,22 @@
+1999-08-01  Tor Lillqvist  <tml@iki.fi>
+
+       * gstrfuncs.c (g_strccpy, g_strecpy): New functions.
+
+       * glib.h: Declare and document them. Define the deprecated
+       g_strescape as a macro that calls g_strecpy.
+
+       * tests/strfunc-test.c (main): Test them.
+
+       * makefile.{cygwin,msc}.in
+       * tests/makefile.{cygwin,msc}.in: Remove gstack and its test
+       program.
+
+       * glib.def: Additions and removals.
+
+       * README.win32: Improve gcc build instructions.
+
+       * build-dll: Also build import library for MSVC.
+
 Sat Jul 24 20:11:35 1999  Tim Janik  <timj@gtk.org>
 
        * merged GLib 1.3.0 with glib-1.2.3 from Fri Jul 16 22:18:36.
index c2cddd8..9f3113e 100644 (file)
@@ -1,3 +1,22 @@
+1999-08-01  Tor Lillqvist  <tml@iki.fi>
+
+       * gstrfuncs.c (g_strccpy, g_strecpy): New functions.
+
+       * glib.h: Declare and document them. Define the deprecated
+       g_strescape as a macro that calls g_strecpy.
+
+       * tests/strfunc-test.c (main): Test them.
+
+       * makefile.{cygwin,msc}.in
+       * tests/makefile.{cygwin,msc}.in: Remove gstack and its test
+       program.
+
+       * glib.def: Additions and removals.
+
+       * README.win32: Improve gcc build instructions.
+
+       * build-dll: Also build import library for MSVC.
+
 Sat Jul 24 20:11:35 1999  Tim Janik  <timj@gtk.org>
 
        * merged GLib 1.3.0 with glib-1.2.3 from Fri Jul 16 22:18:36.
index c2cddd8..9f3113e 100644 (file)
@@ -1,3 +1,22 @@
+1999-08-01  Tor Lillqvist  <tml@iki.fi>
+
+       * gstrfuncs.c (g_strccpy, g_strecpy): New functions.
+
+       * glib.h: Declare and document them. Define the deprecated
+       g_strescape as a macro that calls g_strecpy.
+
+       * tests/strfunc-test.c (main): Test them.
+
+       * makefile.{cygwin,msc}.in
+       * tests/makefile.{cygwin,msc}.in: Remove gstack and its test
+       program.
+
+       * glib.def: Additions and removals.
+
+       * README.win32: Improve gcc build instructions.
+
+       * build-dll: Also build import library for MSVC.
+
 Sat Jul 24 20:11:35 1999  Tim Janik  <timj@gtk.org>
 
        * merged GLib 1.3.0 with glib-1.2.3 from Fri Jul 16 22:18:36.
index 36b9b51..693fea4 100644 (file)
@@ -10,12 +10,11 @@ library is used.
 
 To build GLib on Win32, you can use either the Microsoft compiler and
 tools, or gcc. Both the compiler from MSVC 5.0 and from MSVC 6.0 have
-been used successfully. With gcc I mean the gcc-2.95 pre-release as
-distributed by Mumit Khan, running under cygwin-b20.1. To successfully
-use gcc, follow the instructions below. We want to use gcc
--mno-cygwin, i.e. produce executables (.exe and .dll files) that do
-*not* require the cygwin runtime library. This is sometimes called
-"mingw32".
+been used successfully. With gcc I mean gcc-2.95 as distributed by
+Mumit Khan, running under cygwin-b20.1. To successfully use gcc,
+follow the instructions below. We want to use gcc -mno-cygwin,
+i.e. produce executables (.exe and .dll files) that do *not* require
+the cygwin runtime library. This is sometimes called "mingw32".
 
 To test the GLib functions, go to the tests subdirectory and enter
 `nmake -f makefile.msc check` or `make -f makefile.cygwin check`.
@@ -94,48 +93,24 @@ The gcc support was added quite recently, but seems to work. Debugging
 with gdb works. I use the latest and greatest gcc and mingw32.
 Somewhat earlier versions will also work, but you are on your own.
 
-Fetch the gcc-2.95 developer snapshot from
-ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/snapshots/gcc-2.95-19990715/.
-Install it somewhere, for instance \gcc-2.95.
-
-Fetch the mingw runtime snapshot from 1999-07-15 from
-ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/runtime/. You
-must fix two bugs in it:
-
-1) Fix the prototype and call to __getmainargs() in init.c to include
-one more parameter, an int *, which should be passed the address of a
-zero int. Code snippets below:
-
-...
-#ifdef __MSVCRT__
-extern void __getmainargs(int *, char***, char***, int, int *);
-#else
-...
-#ifdef __MSVCRT__
-       int newmode = 0;
-       (void) __getmainargs(&_argc, &_argv, &dummy_environ, _CRT_glob, &newmode);
-#else
-...
-
-2) Fix the type of the function __p___argv() in stdlib.h to be char***,
-not char**.
-
-Build the mingw32 runtime and install the libraries in the
-gcc-2.95\H-i586-cygwin32\lib directory, and the headers in the
-gcc-2.95\H-i586-cygwin32\i586-cygwin32\include\mingw32 directory.
-Remember to build and install also the w32api import libraries and
-headers.
-
-I prefer to use the msvcrt runtime and not the default
-crtdll. Especially, as the pthread library also uses msvcrt, using
-crtdll would probably not be a good idea at all. Using msvcrt can be
-achieved by applying a few changes to the specs file.
-
-The specs file is in gcc-2.95\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\2.95
-
-The necessary changes are: replace -lcrtdll with -lmsvcrt, replace
-crt1 with crt2, change -lmoldname to -lmoldname-msvc, and define
-__MSVCRT__.
+Read and understand these instruction carefully. If you don't
+understand or can't follow the instructions, you probably shouldn't
+want to build glib (or gtk or gimp) yourself anyway.
+
+Fetch gcc-2.95 built for cygwin from
+ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95/gcc-2.95-cygb20.tar.gz
+Install it somewhere, for instance "C:\gcc-2.95" (/gcc-2.95 as seen
+from cygwin). We call this directory $GCCDIR below. You will have
+subdirectories "H-i586-cygwin32" and "include" under $GCCDIR.
+
+Next, you need to modify the gcc setup to use the msvcrt runtime
+instead of crtdll. Also, the mingw32 and win32 API headers and import
+libraries need to be added. I have collected all the necessary
+additions in the file
+http://www.iki.fi/tml/gimp/win32/gcc-2.95-additions.zip . Install that
+in $GCCDIR. If you really want to do everything by yourself, follow
+the instructions in
+http://www.iki.fi/tml/gimp/win32/gcc-environment-setup.html
 
 Next, go back to the GLib directory and build using `make -f
 makefile.cygwin`.  Building the dlls uses the script build-dll which
index 958b45f..ef3aa73 100644 (file)
--- a/build-dll
+++ b/build-dll
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 # Temporary hack until building dlls or executables with exported
 # entry points is easier with gcc -mno-cygwin ("mingw32").
@@ -36,4 +36,12 @@ $DLLTOOL --as=$AS --dllname $dllfile $defswitch --base-file $library.base --outp
 $GCC -mdll -mno-cygwin -Wl,$library.exp -o $dllfile $ldargs &&
 $DLLTOOL --as=$AS --dllname $dllfile $defswitch --output-lib lib$libname.a $objs
 
+# Finally, also build import libraries for the Microsoft linker. You
+# will either need to have some decent version of MSVC, or get lib.exe
+# (and link.exe) from the (freely downloadable) Microsoft Platform SDK.
+
+if type -p lib.exe && [ -n "$def" -a "$def" != '-' ]; then
+    lib -name:$libname.dll -def:$def -out:$libname.lib
+fi
+
 rm $library.base $library.exp 2>/dev/null
index 7e63907..fc6882b 100644 (file)
--- a/glib.def
+++ b/glib.def
@@ -58,10 +58,10 @@ EXPORTS
        g_date_julian
        g_date_monday_week_of_year
        g_date_monday_weeks_in_year
+       g_date_month
        g_date_new
        g_date_new_dmy
        g_date_new_julian
-       g_date_month
        g_date_set_day
        g_date_set_dmy
        g_date_set_julian
@@ -121,12 +121,12 @@ EXPORTS
        g_hook_get
        g_hook_insert_before
        g_hook_insert_sorted
+       g_hook_list_clear
        g_hook_list_init
        g_hook_list_invoke
        g_hook_list_invoke_check
        g_hook_list_marshal
        g_hook_list_marshal_check
-       g_hook_list_clear
        g_hook_next_valid
        g_hook_prepend
        g_hook_ref
@@ -190,8 +190,8 @@ EXPORTS
        g_main_iteration
        g_main_new
        g_main_pending
-       g_main_remove_poll
        g_main_quit
+       g_main_remove_poll
        g_main_run
        g_main_set_poll_func
        g_malloc
@@ -255,6 +255,19 @@ EXPORTS
        g_quark_from_string
        g_quark_to_string
        g_quark_try_string
+       g_queue_create
+       g_queue_free
+       g_queue_is_empty
+       g_queue_peek_head
+       g_queue_peek_tail
+       g_queue_pop_head
+       g_queue_pop_head_link
+       g_queue_pop_tail
+       g_queue_pop_tail_link
+       g_queue_push_head
+       g_queue_push_head_link
+       g_queue_push_tail
+       g_queue_push_tail_link
        g_rand_double
        g_rand_double_range
        g_rand_free
@@ -331,7 +344,6 @@ EXPORTS
        g_slist_reverse
        g_slist_sort
        g_snprintf
-        g_spaced_primes_closest
        g_source_add
        g_source_remove
        g_source_remove_by_source_data
@@ -355,12 +367,15 @@ EXPORTS
        g_strchomp
        g_strchug
        g_strconcat
+       g_strccpy
        g_strdelimit
        g_strdown
        g_strdup
        g_strdup_printf
        g_strdup_vprintf
+       g_strecpy
        g_strerror
+       g_strescape
        g_strfreev
        g_string_append
        g_string_append_c
@@ -377,17 +392,12 @@ EXPORTS
        g_string_new
        g_string_prepend
        g_string_prepend_c
-       g_string_readline
-       g_string_readline_buffered
        g_string_sized_new
        g_string_sprintf
        g_string_sprintfa
-       g_string_tokenise
-       g_string_tokenise_free
        g_string_truncate
        g_string_up
        g_strjoinv
-       g_strescape
        g_strncasecmp
        g_strndup
        g_strnfill
@@ -397,9 +407,11 @@ EXPORTS
        g_strtod
        g_strup
        g_thread_create
+       g_thread_functions_for_glib_use
        g_thread_join
        g_thread_self
        g_thread_set_priority
+       g_threads_got_initialized
        g_timeout_add
        g_timeout_add_full
        g_timer_destroy
@@ -426,8 +438,9 @@ EXPORTS
        glib_major_version
        glib_micro_version
        glib_minor_version
+       gwin_closedir
        gwin_ftruncate
        gwin_opendir
        gwin_readdir
        gwin_rewinddir
-       gwin_closedir
+        g_spaced_primes_closest
diff --git a/glib.h b/glib.h
index d04499a..fb69482 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -1515,9 +1515,25 @@ gchar*    g_strconcat            (const gchar *string1,
                                 ...); /* NULL terminated */
 gchar*   g_strjoin             (const gchar  *separator,
                                 ...); /* NULL terminated */
+/* Copy a string interpreting C string -style escape sequences.
+ * The recognized sequences are \b \f \n \r \t \\ \" and the octal format.
+ */
+gchar*   g_strccpy             (gchar       *dest,
+                                const gchar *source);
+/* Copy a string escaping nonprintable characters like in C strings.
+ * Inverse of g_strccpy. The exceptions parameter if non-NULL points
+ * to a string containing characters that are not escaped.
+ */
+gchar*   g_strecpy             (gchar       *dest,
+                                const gchar *source,
+                                const gchar *exceptions);
+
 /* deprecated function */
 gchar*  g_strescape            (gchar        *string);
 
+/* Define a macro for it */
+#define g_strescape(src) g_strecpy (g_malloc (strlen (src)*4+1), src, NULL)
+
 gpointer g_memdup              (gconstpointer mem,
                                 guint         byte_size);
 
index 7e63907..fc6882b 100644 (file)
@@ -58,10 +58,10 @@ EXPORTS
        g_date_julian
        g_date_monday_week_of_year
        g_date_monday_weeks_in_year
+       g_date_month
        g_date_new
        g_date_new_dmy
        g_date_new_julian
-       g_date_month
        g_date_set_day
        g_date_set_dmy
        g_date_set_julian
@@ -121,12 +121,12 @@ EXPORTS
        g_hook_get
        g_hook_insert_before
        g_hook_insert_sorted
+       g_hook_list_clear
        g_hook_list_init
        g_hook_list_invoke
        g_hook_list_invoke_check
        g_hook_list_marshal
        g_hook_list_marshal_check
-       g_hook_list_clear
        g_hook_next_valid
        g_hook_prepend
        g_hook_ref
@@ -190,8 +190,8 @@ EXPORTS
        g_main_iteration
        g_main_new
        g_main_pending
-       g_main_remove_poll
        g_main_quit
+       g_main_remove_poll
        g_main_run
        g_main_set_poll_func
        g_malloc
@@ -255,6 +255,19 @@ EXPORTS
        g_quark_from_string
        g_quark_to_string
        g_quark_try_string
+       g_queue_create
+       g_queue_free
+       g_queue_is_empty
+       g_queue_peek_head
+       g_queue_peek_tail
+       g_queue_pop_head
+       g_queue_pop_head_link
+       g_queue_pop_tail
+       g_queue_pop_tail_link
+       g_queue_push_head
+       g_queue_push_head_link
+       g_queue_push_tail
+       g_queue_push_tail_link
        g_rand_double
        g_rand_double_range
        g_rand_free
@@ -331,7 +344,6 @@ EXPORTS
        g_slist_reverse
        g_slist_sort
        g_snprintf
-        g_spaced_primes_closest
        g_source_add
        g_source_remove
        g_source_remove_by_source_data
@@ -355,12 +367,15 @@ EXPORTS
        g_strchomp
        g_strchug
        g_strconcat
+       g_strccpy
        g_strdelimit
        g_strdown
        g_strdup
        g_strdup_printf
        g_strdup_vprintf
+       g_strecpy
        g_strerror
+       g_strescape
        g_strfreev
        g_string_append
        g_string_append_c
@@ -377,17 +392,12 @@ EXPORTS
        g_string_new
        g_string_prepend
        g_string_prepend_c
-       g_string_readline
-       g_string_readline_buffered
        g_string_sized_new
        g_string_sprintf
        g_string_sprintfa
-       g_string_tokenise
-       g_string_tokenise_free
        g_string_truncate
        g_string_up
        g_strjoinv
-       g_strescape
        g_strncasecmp
        g_strndup
        g_strnfill
@@ -397,9 +407,11 @@ EXPORTS
        g_strtod
        g_strup
        g_thread_create
+       g_thread_functions_for_glib_use
        g_thread_join
        g_thread_self
        g_thread_set_priority
+       g_threads_got_initialized
        g_timeout_add
        g_timeout_add_full
        g_timer_destroy
@@ -426,8 +438,9 @@ EXPORTS
        glib_major_version
        glib_micro_version
        glib_minor_version
+       gwin_closedir
        gwin_ftruncate
        gwin_opendir
        gwin_readdir
        gwin_rewinddir
-       gwin_closedir
+        g_spaced_primes_closest
index d04499a..fb69482 100644 (file)
@@ -1515,9 +1515,25 @@ gchar*    g_strconcat            (const gchar *string1,
                                 ...); /* NULL terminated */
 gchar*   g_strjoin             (const gchar  *separator,
                                 ...); /* NULL terminated */
+/* Copy a string interpreting C string -style escape sequences.
+ * The recognized sequences are \b \f \n \r \t \\ \" and the octal format.
+ */
+gchar*   g_strccpy             (gchar       *dest,
+                                const gchar *source);
+/* Copy a string escaping nonprintable characters like in C strings.
+ * Inverse of g_strccpy. The exceptions parameter if non-NULL points
+ * to a string containing characters that are not escaped.
+ */
+gchar*   g_strecpy             (gchar       *dest,
+                                const gchar *source,
+                                const gchar *exceptions);
+
 /* deprecated function */
 gchar*  g_strescape            (gchar        *string);
 
+/* Define a macro for it */
+#define g_strescape(src) g_strecpy (g_malloc (strlen (src)*4+1), src, NULL)
+
 gpointer g_memdup              (gconstpointer mem,
                                 guint         byte_size);
 
index 37df963..1ed8a2d 100644 (file)
@@ -1073,6 +1073,137 @@ g_strdelimit (gchar       *string,
 }
 
 gchar*
+g_strccpy (gchar       *dest,
+          const gchar *source)
+{
+  const gchar *p = source;
+  gchar *q = dest;
+
+  g_return_val_if_fail (dest != NULL, NULL);
+
+  while (*p)
+    {
+      if (*p == '\\')
+       {
+         p++;
+         switch (*p)
+           {
+           case '0':  case '1':  case '2':  case '3':  case '4':
+           case '5':  case '6':  case '7':
+             *q = 0;
+             while ((*p >= '0') && (*p <= '7'))
+               {
+                 *q = (*q * 8) + (*p - '0');
+                 p++;
+               }
+             q++;
+             p--;
+             break;
+           case 'b':
+             *q++ = '\b';
+             break;
+           case 'f':
+             *q++ = '\f';
+             break;
+           case 'n':
+             *q++ = '\n';
+             break;
+           case 'r':
+             *q++ = '\r';
+             break;
+           case 't':
+             *q++ = '\t';
+             break;
+           default:            /* Also handles \" and \\ */
+             *q++ = *p;
+             break;
+           }
+       }
+      else
+       *q++ = *p;
+      p++;
+    }
+  *q = 0;
+  return dest;
+}
+
+gchar *
+g_strecpy (gchar       *dest,
+          const gchar *src,
+          const gchar *exceptions)
+{
+  const guchar *p = (guchar *) src;
+  gchar *q = dest;
+  guchar excmap[256];
+
+  memset (excmap, 0, 256);
+  if (exceptions)
+    {
+      guchar *e = (guchar *) exceptions;
+
+      while (*e)
+       {
+         excmap[*e] = 1;
+         e++;
+       }
+    }
+
+  while (*p)
+    {
+      if (excmap[*p])
+       *q++ = *p;
+      else
+       {
+         switch (*p)
+           {
+           case '\b':
+             *q++ = '\\';
+             *q++ = 'b';
+             break;
+           case '\f':
+             *q++ = '\\';
+             *q++ = 'f';
+             break;
+           case '\n':
+             *q++ = '\\';
+             *q++ = 'n';
+             break;
+           case '\r':
+             *q++ = '\\';
+             *q++ = 'r';
+             break;
+           case '\t':
+             *q++ = '\\';
+             *q++ = 't';
+             break;
+           case '\\':
+             *q++ = '\\';
+             *q++ = '\\';
+             break;
+           case '"':
+             *q++ = '\\';
+             *q++ = '"';
+             break;
+           default:
+             if ((*p < ' ') || (*p >= 0177))
+               {
+                 *q++ = '\\';
+                 *q++ = '0' + (((*p) >> 6)&07);
+                 *q++ = '0' + (((*p) >> 3)&07);
+                 *q++ = '0' + ((*p)&07);
+               }
+             else
+               *q++ = *p;
+             break;
+           }
+       }
+      p++;
+    }
+  *q = 0;
+  return dest;
+}
+
+gchar*
 g_strescape (gchar *string)
 {
   gchar *q;
index 9776a75..ecf6e1c 100644 (file)
@@ -74,7 +74,6 @@ glib_OBJECTS = \
        gqueue.obj      \
        grand.obj       \
        gslist.obj      \
-       gstack.obj      \
        gthread.obj     \
        gtimer.obj      \
        gtree.obj       \
index 37df963..1ed8a2d 100644 (file)
@@ -1073,6 +1073,137 @@ g_strdelimit (gchar       *string,
 }
 
 gchar*
+g_strccpy (gchar       *dest,
+          const gchar *source)
+{
+  const gchar *p = source;
+  gchar *q = dest;
+
+  g_return_val_if_fail (dest != NULL, NULL);
+
+  while (*p)
+    {
+      if (*p == '\\')
+       {
+         p++;
+         switch (*p)
+           {
+           case '0':  case '1':  case '2':  case '3':  case '4':
+           case '5':  case '6':  case '7':
+             *q = 0;
+             while ((*p >= '0') && (*p <= '7'))
+               {
+                 *q = (*q * 8) + (*p - '0');
+                 p++;
+               }
+             q++;
+             p--;
+             break;
+           case 'b':
+             *q++ = '\b';
+             break;
+           case 'f':
+             *q++ = '\f';
+             break;
+           case 'n':
+             *q++ = '\n';
+             break;
+           case 'r':
+             *q++ = '\r';
+             break;
+           case 't':
+             *q++ = '\t';
+             break;
+           default:            /* Also handles \" and \\ */
+             *q++ = *p;
+             break;
+           }
+       }
+      else
+       *q++ = *p;
+      p++;
+    }
+  *q = 0;
+  return dest;
+}
+
+gchar *
+g_strecpy (gchar       *dest,
+          const gchar *src,
+          const gchar *exceptions)
+{
+  const guchar *p = (guchar *) src;
+  gchar *q = dest;
+  guchar excmap[256];
+
+  memset (excmap, 0, 256);
+  if (exceptions)
+    {
+      guchar *e = (guchar *) exceptions;
+
+      while (*e)
+       {
+         excmap[*e] = 1;
+         e++;
+       }
+    }
+
+  while (*p)
+    {
+      if (excmap[*p])
+       *q++ = *p;
+      else
+       {
+         switch (*p)
+           {
+           case '\b':
+             *q++ = '\\';
+             *q++ = 'b';
+             break;
+           case '\f':
+             *q++ = '\\';
+             *q++ = 'f';
+             break;
+           case '\n':
+             *q++ = '\\';
+             *q++ = 'n';
+             break;
+           case '\r':
+             *q++ = '\\';
+             *q++ = 'r';
+             break;
+           case '\t':
+             *q++ = '\\';
+             *q++ = 't';
+             break;
+           case '\\':
+             *q++ = '\\';
+             *q++ = '\\';
+             break;
+           case '"':
+             *q++ = '\\';
+             *q++ = '"';
+             break;
+           default:
+             if ((*p < ' ') || (*p >= 0177))
+               {
+                 *q++ = '\\';
+                 *q++ = '0' + (((*p) >> 6)&07);
+                 *q++ = '0' + (((*p) >> 3)&07);
+                 *q++ = '0' + ((*p)&07);
+               }
+             else
+               *q++ = *p;
+             break;
+           }
+       }
+      p++;
+    }
+  *q = 0;
+  return dest;
+}
+
+gchar*
 g_strescape (gchar *string)
 {
   gchar *q;
index f12e9be..11435d0 100644 (file)
@@ -67,7 +67,6 @@ glib_OBJECTS = \
        gqueue.o        \
        grand.o         \
        gslist.o        \
-       gstack.o        \
        gthread.o       \
        gtimer.o        \
        gtree.o         \
index 9776a75..ecf6e1c 100644 (file)
@@ -74,7 +74,6 @@ glib_OBJECTS = \
        gqueue.obj      \
        grand.obj       \
        gslist.obj      \
-       gstack.obj      \
        gthread.obj     \
        gtimer.obj      \
        gtree.obj       \
index 9f02e15..641b7ce 100644 (file)
@@ -24,9 +24,8 @@ TESTS = \
        rand-test.exe   \
        relation-test.exe\
        slist-test.exe  \
-       stack-test.exe  \
-       string-test.exe \
        strfunc-test.exe\
+       string-test.exe \
        thread-test.exe \
        tree-test.exe   \
        type-test.exe
index 1a91929..0cff24a 100644 (file)
@@ -26,9 +26,8 @@ TESTS = \
        rand-test.exe   \
        relation-test.exe\
        slist-test.exe  \
-       stack-test.exe  \
-       string-test.exe \
        strfunc-test.exe\
+       string-test.exe \
        thread-test.exe \
        tree-test.exe   \
        type-test.exe
index f50a037..16d5584 100644 (file)
@@ -99,6 +99,17 @@ main (int   argc,
   g_assert (strcmp(string, "00021 test ") == 0);
   g_free (string);
 
+  g_assert (strcmp(g_strccpy(g_malloc(100),
+                            "abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313"),
+                  "abc\\\"\b\f\n\r\t\003\177\234\313") == 0);
+  g_assert (strcmp(g_strecpy(g_malloc(100),
+                            "abc\\\"\b\f\n\r\t\003\177\234\313",
+                            NULL),
+                  "abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313") == 0);
+  g_assert (strcmp(g_strecpy(g_malloc(100),"abc\\\"\b\f\n\r\t\003\177\234\313",
+                            "\b\f\001\002\003\004"),
+                  "abc\\\\\\\"\b\f\\n\\r\\t\003\\177\\234\\313") == 0);
+
   return 0;
 }