From 0840de6605cf4ad83dc3c8d0797dfefeabdb3b53 Mon Sep 17 00:00:00 2001 From: hniksic <devnull@localhost> Date: Mon, 30 May 2005 06:31:24 -0700 Subject: [PATCH] [svn] Allow --header to contain ",". --- src/ChangeLog | 8 ++++++++ src/init.c | 15 ++++++++++++--- src/utils.c | 24 ++++++++++++++++++++++++ src/utils.h | 1 + 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f0c1488b..9625804f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2005-05-30 Hrvoje Niksic <hniksic@xemacs.org> + + * init.c (cmd_spec_header): Don't split the string along the + commas using cmd_vector; just append the new value using + vec_append instead. + + * utils.c (vec_append): New function. + 2005-05-27 Andreas Beckmann <debian@abeckmann.de> * html-url.c (tag_handle_link): Mark the content from the <link diff --git a/src/init.c b/src/init.c index e17510c3..b6347aa5 100644 --- a/src/init.c +++ b/src/init.c @@ -162,7 +162,7 @@ static struct { { "ftpproxy", &opt.ftp_proxy, cmd_string }, { "ftpuser", &opt.ftp_user, cmd_string }, { "glob", &opt.ftp_glob, cmd_boolean }, - { "header", &opt.user_headers, cmd_spec_header }, + { "header", NULL, cmd_spec_header }, { "htmlextension", &opt.html_extension, cmd_boolean }, { "htmlify", NULL, cmd_spec_htmlify }, { "httpkeepalive", &opt.http_keep_alive, cmd_boolean }, @@ -1118,15 +1118,24 @@ cmd_spec_dirstruct (const char *com, const char *val, void *place_ignored) } static int -cmd_spec_header (const char *com, const char *val, void *place) +cmd_spec_header (const char *com, const char *val, void *place_ignored) { + /* Empty value means reset the list of headers. */ + if (*val == '\0') + { + free_vec (opt.user_headers); + opt.user_headers = NULL; + return 1; + } + if (!check_user_specified_header (val)) { fprintf (stderr, _("%s: %s: Invalid header `%s'.\n"), exec_name, com, val); return 0; } - return cmd_vector (com, val, place); + opt.user_headers = vec_append (opt.user_headers, val); + return 1; } static int diff --git a/src/utils.c b/src/utils.c index 04968e62..549f7a47 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1085,6 +1085,30 @@ merge_vecs (char **v1, char **v2) xfree (v2); return v1; } + +/* Append a freshly allocated copy of STR to VEC. If VEC is NULL, it + is allocated as needed. Return the new value of the vector. */ + +char ** +vec_append (char **vec, const char *str) +{ + int cnt; /* count of vector elements, including + the one we're about to append */ + if (vec != NULL) + { + for (cnt = 0; vec[cnt]; cnt++) + ; + ++cnt; + } + else + cnt = 1; + /* Reallocate the array to fit the new element and the NULL. */ + vec = xrealloc (vec, (cnt + 1) * sizeof (char *)); + /* Append a copy of STR to the vector. */ + vec[cnt - 1] = xstrdup (str); + vec[cnt] = NULL; + return vec; +} /* Sometimes it's useful to create "sets" of strings, i.e. special hash tables where you want to store strings as keys and merely diff --git a/src/utils.h b/src/utils.h index 51816a08..9306b71d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -92,6 +92,7 @@ void read_file_free PARAMS ((struct file_memory *)); void free_vec PARAMS ((char **)); char **merge_vecs PARAMS ((char **, char **)); +char **vec_append PARAMS ((char **, const char *)); void string_set_add PARAMS ((struct hash_table *, const char *)); int string_set_contains PARAMS ((struct hash_table *, const char *));