Author: cazfi
Date: Fri Sep 30 06:20:15 2016
New Revision: 33948

URL: http://svn.gna.org/viewcvs/freeciv?rev=33948&view=rev
Log:
Moved make_escapes() and remove_escapes() to support.c.

See patch #7734

Modified:
    trunk/utility/registry_ini.c
    trunk/utility/section_file.c
    trunk/utility/support.c
    trunk/utility/support.h

Modified: trunk/utility/registry_ini.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/registry_ini.c?rev=33948&r1=33947&r2=33948&view=diff
==============================================================================
--- trunk/utility/registry_ini.c        (original)
+++ trunk/utility/registry_ini.c        Fri Sep 30 06:20:15 2016
@@ -51,7 +51,7 @@
   can, but they have no particular significance.  There can be
   optional whitespace before and/or after the equals sign.
   You can put a newline after (but not before) the equals sign.
-  
+
   Backslash is an escape character in strings (double-quoted strings
   only, not names); recognised escapes are \n, \\, and \".
   (Any other \<char> is just treated as <char>.)
@@ -221,39 +221,6 @@
 
 static struct entry *section_entry_filereference_new(struct section *psection,
                                                      const char *name, const 
char *value);
-
-/****************************************************************************
-  Copies a string and convert the following characters:
-  - '\n' to "\\n".
-  - '\\' to "\\\\".
-  - '\"' to "\\\"".
-  See also remove_escapes().
-****************************************************************************/
-static void make_escapes(const char *str, char *buf, size_t buf_len)
-{
-  char *dest = buf;
-  /* Sometimes we insert 2 characters at once ('\n' -> "\\n"), so keep
-   * place for '\0' and an extra character. */
-  const char *const max = buf + buf_len - 2;
-
-  while (*str != '\0' && dest < max) {
-    switch (*str) {
-    case '\n':
-      *dest++ = '\\';
-      *dest++ = 'n';
-      str++;
-      break;
-    case '\\':
-    case '\"':
-      *dest++ = '\\';
-      /* Fallthrough. */
-    default:
-      *dest++ = *str++;
-      break;
-    }
-  }
-  *dest = 0;
-}
 
 /***************************************************************************
   Simplification of fileinfoname().

Modified: trunk/utility/section_file.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/section_file.c?rev=33948&r1=33947&r2=33948&view=diff
==============================================================================
--- trunk/utility/section_file.c        (original)
+++ trunk/utility/section_file.c        Fri Sep 30 06:20:15 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -128,39 +128,6 @@
   secfile->allow_digital_boolean = allow_digital_boolean;
 }
 
-/****************************************************************************
-  Copies a string. Backslash followed by a genuine newline always
-  removes the newline.
-  If full_escapes is TRUE:
-    - '\n' -> newline translation.
-    - Other '\c' sequences (any character 'c') are just passed
-      through with the '\' removed (eg, includes '\\', '\"').
-  See also make_escapes().
-****************************************************************************/
-static void remove_escapes(const char *str, bool full_escapes,
-                           char *buf, size_t buf_len)
-{
-  char *dest = buf;
-  const char *const max = buf + buf_len - 1;
-
-  while (*str != '\0' && dest < max) {
-    if (*str == '\\' && *(str + 1) == '\n') {
-      /* Escape followed by newline. Skip both */
-      str += 2;
-    } else if (full_escapes && *str == '\\') {
-      str++;
-      if (*str == 'n') {
-        *dest++ = '\n';
-        str++;
-      }
-    } else {
-      *dest++ = *str++;
-    }
-  }
-  *dest = '\0';
-}
-
-
 /**************************************************************************
   Add entry to section from token.
 **************************************************************************/

Modified: trunk/utility/support.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/support.c?rev=33948&r1=33947&r2=33948&view=diff
==============================================================================
--- trunk/utility/support.c     (original)
+++ trunk/utility/support.c     Fri Sep 30 06:20:15 2016
@@ -270,6 +270,71 @@
   fc_release_mutex(&cmp_buffer_mutex);
 
   return ret;
+}
+
+/****************************************************************************
+  Copies a string and convert the following characters:
+  - '\n' to "\\n".
+  - '\\' to "\\\\".
+  - '\"' to "\\\"".
+  See also remove_escapes().
+****************************************************************************/
+void make_escapes(const char *str, char *buf, size_t buf_len)
+{
+  char *dest = buf;
+  /* Sometimes we insert 2 characters at once ('\n' -> "\\n"), so keep
+   * place for '\0' and an extra character. */
+  const char *const max = buf + buf_len - 2;
+
+  while (*str != '\0' && dest < max) {
+    switch (*str) {
+    case '\n':
+      *dest++ = '\\';
+      *dest++ = 'n';
+      str++;
+      break;
+    case '\\':
+    case '\"':
+      *dest++ = '\\';
+      /* Fallthrough. */
+    default:
+      *dest++ = *str++;
+      break;
+    }
+  }
+  *dest = 0;
+}
+
+/****************************************************************************
+  Copies a string. Backslash followed by a genuine newline always
+  removes the newline.
+  If full_escapes is TRUE:
+    - '\n' -> newline translation.
+    - Other '\c' sequences (any character 'c') are just passed
+      through with the '\' removed (eg, includes '\\', '\"').
+  See also make_escapes().
+****************************************************************************/
+void remove_escapes(const char *str, bool full_escapes,
+                    char *buf, size_t buf_len)
+{
+  char *dest = buf;
+  const char *const max = buf + buf_len - 1;
+
+  while (*str != '\0' && dest < max) {
+    if (*str == '\\' && *(str + 1) == '\n') {
+      /* Escape followed by newline. Skip both */
+      str += 2;
+    } else if (full_escapes && *str == '\\') {
+      str++;
+      if (*str == 'n') {
+        *dest++ = '\n';
+        str++;
+      }
+    } else {
+      *dest++ = *str++;
+    }
+  }
+  *dest = '\0';
 }
 
 /***************************************************************

Modified: trunk/utility/support.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/support.h?rev=33948&r1=33947&r2=33948&view=diff
==============================================================================
--- trunk/utility/support.h     (original)
+++ trunk/utility/support.h     Fri Sep 30 06:20:15 2016
@@ -1,4 +1,4 @@
-/**********************************************************************
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -187,6 +187,10 @@
 #endif /* WORDS_BIGENDIAN */
 }
 
+void make_escapes(const char *str, char *buf, size_t buf_len);
+void remove_escapes(const char *str, bool full_escapes,
+                    char *buf, size_t buf_len);
+
 int fc_at_quick_exit(void (*func)(void));
 
 #ifdef __cplusplus


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to