Author: cazfi Date: Fri Sep 30 06:20:23 2016 New Revision: 33949 URL: http://svn.gna.org/viewcvs/freeciv?rev=33949&view=rev Log: Moved make_escapes() and remove_escapes() to support.c.
See patch #7734 Modified: branches/S2_6/utility/registry_ini.c branches/S2_6/utility/section_file.c branches/S2_6/utility/support.c branches/S2_6/utility/support.h Modified: branches/S2_6/utility/registry_ini.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/registry_ini.c?rev=33949&r1=33948&r2=33949&view=diff ============================================================================== --- branches/S2_6/utility/registry_ini.c (original) +++ branches/S2_6/utility/registry_ini.c Fri Sep 30 06:20:23 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>.) @@ -188,39 +188,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: branches/S2_6/utility/section_file.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/section_file.c?rev=33949&r1=33948&r2=33949&view=diff ============================================================================== --- branches/S2_6/utility/section_file.c (original) +++ branches/S2_6/utility/section_file.c Fri Sep 30 06:20:23 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 @@ -127,39 +127,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: branches/S2_6/utility/support.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/support.c?rev=33949&r1=33948&r2=33949&view=diff ============================================================================== --- branches/S2_6/utility/support.c (original) +++ branches/S2_6/utility/support.c Fri Sep 30 06:20:23 2016 @@ -159,6 +159,71 @@ return ((int) (unsigned char) fc_tolower(*str0)) - ((int) (unsigned char) fc_tolower(*str1)); #endif /* HAVE_STRNCASECMP */ +} + +/**************************************************************************** + 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: branches/S2_6/utility/support.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/support.h?rev=33949&r1=33948&r2=33949&view=diff ============================================================================== --- branches/S2_6/utility/support.h (original) +++ branches/S2_6/utility/support.h Fri Sep 30 06:20:23 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 @@ -175,6 +175,10 @@ const char *fc_basename(const char *path); +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