diff options
author | Bruno Haible <bruno@clisp.org> | 2020-09-06 22:42:44 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2022-10-09 09:30:42 +0200 |
commit | aeacb83880a4c6bd32fc8b28489e019e32da094e (patch) | |
tree | 590037b11b8ab2838ed2e5f7ed7e72041b41c7cb /gettext-tools/src | |
parent | bb3944c16c158c476187ce1bcc809fb7db735e28 (diff) | |
download | gettext-aeacb83880a4c6bd32fc8b28489e019e32da094e.tar.gz |
Fix "warning: cast from 'const char *' to 'char *' drops const qualifier".
* gettext-tools/src/str-list.h (string_list_append_unique_desc,
string_list_member_desc): New declarations.
* gettext-tools/src/str-list.c (string_list_append_unique_desc,
string_list_member_desc): New functions.
* gettext-tools/src/msgfmt.c (add_languages): Don't modify the contents of
'line'.
Diffstat (limited to 'gettext-tools/src')
-rw-r--r-- | gettext-tools/src/msgfmt.c | 11 | ||||
-rw-r--r-- | gettext-tools/src/str-list.c | 45 | ||||
-rw-r--r-- | gettext-tools/src/str-list.h | 6 |
3 files changed, 55 insertions, 7 deletions
diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index f990152d2..cabb88685 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -1408,12 +1408,12 @@ static void add_languages (string_list_ty *languages, string_list_ty *desired_languages, const char *line, size_t length) { - char *start; + const char *start; /* Split the line by whitespace and build the languages list. */ - for (start = (char *) line; start - line < length; ) + for (start = line; start - line < length; ) { - char *p; + const char *p; /* Skip whitespace before the string. */ while (*start == ' ' || *start == '\t') @@ -1423,10 +1423,9 @@ add_languages (string_list_ty *languages, string_list_ty *desired_languages, while (*p != '\0' && *p != ' ' && *p != '\t') p++; - *p = '\0'; if (desired_languages == NULL - || string_list_member (desired_languages, start)) - string_list_append_unique (languages, start); + || string_list_member_desc (desired_languages, start, p - start)) + string_list_append_unique_desc (languages, start, p - start); start = p + 1; } } diff --git a/gettext-tools/src/str-list.c b/gettext-tools/src/str-list.c index b2c9cf24c..4909edc23 100644 --- a/gettext-tools/src/str-list.c +++ b/gettext-tools/src/str-list.c @@ -82,7 +82,7 @@ string_list_append_unique (string_list_ty *slp, const char *s) { size_t j; - /* Do not if the string is already in the list. */ + /* Do nothing if the string is already in the list. */ for (j = 0; j < slp->nitems; ++j) if (strcmp (slp->item[j], s) == 0) return; @@ -100,6 +100,37 @@ string_list_append_unique (string_list_ty *slp, const char *s) slp->item[slp->nitems++] = xstrdup (s); } +/* Likewise with a string descriptor as argument. */ +void +string_list_append_unique_desc (string_list_ty *slp, + const char *s, size_t s_len) +{ + size_t j; + + /* Do nothing if the string is already in the list. */ + for (j = 0; j < slp->nitems; ++j) + if (strlen (slp->item[j]) == s_len && memcmp (slp->item[j], s, s_len) == 0) + return; + + /* Grow the list. */ + if (slp->nitems >= slp->nitems_max) + { + slp->nitems_max = slp->nitems_max * 2 + 4; + slp->item = (const char **) xrealloc (slp->item, + slp->nitems_max + * sizeof (slp->item[0])); + } + + /* Add a copy of the string to the end of the list. */ + { + char *copy = XNMALLOC (s_len + 1, char); + memcpy (copy, s, s_len); + copy[s_len] = '\0'; + + slp->item[slp->nitems++] = copy; + } +} + /* Destroy a list of strings. */ void @@ -236,6 +267,18 @@ string_list_member (const string_list_ty *slp, const char *s) return false; } +/* Likewise with a string descriptor as argument. */ +bool +string_list_member_desc (const string_list_ty *slp, const char *s, size_t s_len) +{ + size_t j; + + for (j = 0; j < slp->nitems; ++j) + if (strlen (slp->item[j]) == s_len && memcmp (slp->item[j], s, s_len) == 0) + return true; + return false; +} + /* Remove s from the list of strings. Return the removed string or NULL. */ const char * diff --git a/gettext-tools/src/str-list.h b/gettext-tools/src/str-list.h index 483d3c2b1..a39f65823 100644 --- a/gettext-tools/src/str-list.h +++ b/gettext-tools/src/str-list.h @@ -54,6 +54,9 @@ extern void string_list_append (string_list_ty *slp, const char *s); /* Append a single string to the end of a list of strings, unless it is already contained in the list. */ extern void string_list_append_unique (string_list_ty *slp, const char *s); +/* Likewise with a string descriptor as argument. */ +extern void string_list_append_unique_desc (string_list_ty *slp, + const char *s, size_t s_len); /* Destroy a list of strings. */ extern void string_list_destroy (string_list_ty *slp); @@ -79,6 +82,9 @@ extern char *string_list_join (const string_list_ty *slp, const char *separator, /* Return 1 if s is contained in the list of strings, 0 otherwise. */ extern bool string_list_member (const string_list_ty *slp, const char *s); +/* Likewise with a string descriptor as argument. */ +extern bool string_list_member_desc (const string_list_ty *slp, + const char *s, size_t s_len); /* Remove s from the list of strings. Return the removed string or NULL. */ extern const char * string_list_remove (string_list_ty *slp, const char *s); |