Commit 78f92501 78f92501613a377b4c5bb2680dc071e928a96855 by Sergey Poznyakoff

Remove dependency on obstack. Use mu_opool_t instead.

* include/mailutils/opool.h (mu_opool_alloc): New proto.
* libmailutils/base/opool.c (mu_opool_alloc): New function.
(mu_opool_appendz): Do not append trailing null character.
* libmailutils/cfg/parser.y (mu_cfg_tree_create_node): Reflect
the change in mu_opool_appendz.
* comsat/action.c: Use mu_opool_t instead of struct obstack.
* lib/mailcap.c: Likewise.
* libmailutils/url/urlstr.c: Likewise.
* mh/burst.c: Likewise.
* mh/mh_fmtgram.y: Likewise.
* mh/mh_format.c: Likewise.
* mh/mh_format.h: Likewise.
* mh/mhn.c: Likewise.
* mh/repl.c: Likewise.
* mh/whatnowenv.c: Likewise.
* mimeview/mimetypes.l: Likewise.
* mimeview/mimeview.h: Likewise.

* gnulib.modules: Remove obstack.
1 parent e9871d0f
......@@ -19,9 +19,7 @@
#include <mailutils/io.h>
#include <mailutils/argcv.h>
#include <mailutils/prog.h>
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include <obstack.h>
#include <mailutils/opool.h>
/* This module implements user-configurable actions for comsat. The
actions are kept in file .biffrc in the user's home directory and
......@@ -42,7 +40,7 @@
When omitted, they default to 400, 5. */
static int
expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
expand_escape (char **pp, mu_message_t msg, mu_opool_t pool)
{
char *p = *pp;
char *start, *sval, *namep;
......@@ -56,15 +54,13 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
switch (*++p) /* skip past $ */
{
case 'u':
len = strlen (username);
obstack_grow (stk, username, len);
mu_opool_appendz (pool, username);
*pp = p;
rc = 0;
break;
case 'h':
len = strlen (hostname);
obstack_grow (stk, hostname, len);
mu_opool_appendz (pool, hostname);
*pp = p;
rc = 0;
break;
......@@ -85,10 +81,7 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
namep[len] = 0;
if (mu_message_get_header (msg, &hdr) == 0
&& mu_header_aget_value (hdr, namep, &sval) == 0)
{
len = strlen (sval);
obstack_grow (stk, sval, len);
}
mu_opool_appendz (pool, sval);
free (namep);
*pp = p;
rc = 0;
......@@ -131,7 +124,7 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
size += s - q + 1;
q = s + 1;
}
obstack_grow (stk, buf, size);
mu_opool_append (pool, buf, size);
}
mu_stream_destroy (&stream);
free (buf);
......@@ -147,11 +140,11 @@ expand_line (const char *str, mu_message_t msg)
{
const char *p;
int c = 0;
struct obstack stk;
mu_opool_t pool;
if (!*str)
return NULL;
obstack_init (&stk);
mu_opool_create (&pool, 1);
for (p = str; *p; p++)
{
switch (*p)
......@@ -161,22 +154,22 @@ expand_line (const char *str, mu_message_t msg)
if (*p)
{
c = mu_wordsplit_c_unquote_char (*p);
obstack_1grow (&stk, c);
mu_opool_append_char (pool, c);
}
break;
case '$':
if (expand_escape ((char**)&p, msg, &stk) == 0)
if (expand_escape ((char**)&p, msg, pool) == 0)
break;
/*FALLTHRU*/
default:
obstack_1grow (&stk, *p);
mu_opool_append_char (pool, *p);
}
}
obstack_1grow (&stk, 0);
str = strdup (obstack_finish (&stk));
obstack_free (&stk, NULL);
mu_opool_append_char (pool, 0);
str = strdup (mu_opool_finish (pool, NULL));
mu_opool_destroy (&pool);
return (char *)str;
}
......
......@@ -14,6 +14,5 @@ mbchar
mbiter
mbslen
mbswidth
obstack
setenv
stdint
\ No newline at end of file
stdint
......
......@@ -42,6 +42,9 @@ void mu_opool_clear (mu_opool_t opool);
/* Destroy the pool, reclaim any memory associated with it. */
void mu_opool_destroy (mu_opool_t *popool);
/* Allocate SIZE bytes in the pool. */
int mu_opool_alloc (mu_opool_t opool, size_t size);
/* Append to the current object N bytes pointed to by STR. */
int mu_opool_append (mu_opool_t opool, const void *str, size_t n);
......
......@@ -19,9 +19,6 @@
#endif
#include <mailutils/mailutils.h>
#include <fnmatch.h>
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include <obstack.h>
#include <sys/wait.h>
#include <ctype.h>
......@@ -241,7 +238,7 @@ mime_context_get_temp_file (struct mime_context *ctx, char **ptr)
}
static struct obstack expand_stack;
static mu_opool_t expand_pool;
static int
expand_string (struct mime_context *ct, char **pstr)
......@@ -258,14 +255,14 @@ expand_string (struct mime_context *ct, char **pstr)
{
case 's':
mime_context_get_temp_file (ct, &s);
obstack_grow (&expand_stack, s, strlen (s));
mu_opool_appendz (expand_pool, s);
rc = 1;
p += 2;
break;
case 't':
mime_context_get_content_type (ct, &s);
obstack_grow (&expand_stack, s, strlen (s));
mu_opool_appendz (expand_pool, s);
p += 2;
break;
......@@ -281,7 +278,7 @@ expand_string (struct mime_context *ct, char **pstr)
if (mime_context_get_content_type_value (ct,
q, p-q,
&s, &n) == 0)
obstack_grow (&expand_stack, s, n);
mu_opool_append (expand_pool, s, n);
if (*p)
p++;
break;
......@@ -293,19 +290,19 @@ expand_string (struct mime_context *ct, char **pstr)
break;
default:
obstack_1grow (&expand_stack, p[0]);
mu_opool_append_char (expand_pool, p[0]);
}
break;
case '\\':
if (p[1])
{
obstack_1grow (&expand_stack, p[1]);
mu_opool_append_char (expand_pool, p[1]);
p += 2;
}
else
{
obstack_1grow (&expand_stack, p[0]);
mu_opool_append_char (expand_pool, p[0]);
p++;
}
break;
......@@ -313,23 +310,23 @@ expand_string (struct mime_context *ct, char **pstr)
case '"':
if (p[1] == p[0])
{
obstack_1grow (&expand_stack, '%');
mu_opool_append_char (expand_pool, '%');
p++;
}
else
{
obstack_1grow (&expand_stack, p[0]);
mu_opool_append_char (expand_pool, p[0]);
p++;
}
break;
default:
obstack_1grow (&expand_stack, p[0]);
mu_opool_append_char (expand_pool, p[0]);
p++;
}
}
obstack_1grow (&expand_stack, 0);
*pstr = obstack_finish (&expand_stack);
mu_opool_append_char (expand_pool, 0);
*pstr = mu_opool_finish (expand_pool, NULL);
return rc;
}
......@@ -514,8 +511,8 @@ run_test (mu_mailcap_entry_t entry, struct mime_context *ctx)
struct mu_wordsplit ws;
char *str;
obstack_blank (&expand_stack, size + 1);
str = obstack_finish (&expand_stack);
mu_opool_alloc (expand_pool, size + 1);
str = mu_opool_finish (expand_pool, NULL);
mu_mailcap_entry_get_test (entry, str, size + 1, NULL);
expand_string (ctx, &str);
......@@ -556,8 +553,8 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx)
if (mu_mailcap_entry_get_viewcommand (entry, NULL, 0, &size))
return 1;
size++;
obstack_blank (&expand_stack, size);
view_command = obstack_finish (&expand_stack);
mu_opool_alloc (expand_pool, size);
view_command = mu_opool_finish (expand_pool, NULL);
mu_mailcap_entry_get_viewcommand (entry, view_command, size, NULL);
}
else
......@@ -565,8 +562,8 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx)
if (mu_mailcap_entry_get_value (entry, "print", NULL, 0, &size))
return 1;
size++;
obstack_blank (&expand_stack, size);
view_command = obstack_finish (&expand_stack);
mu_opool_alloc (expand_pool, size);
view_command = mu_opool_finish (expand_pool, NULL);
mu_mailcap_entry_get_value (entry, "print", view_command, size, NULL);
}
......@@ -691,7 +688,7 @@ display_stream_mailcap (const char *ident, mu_stream_t stream, mu_header_t hdr,
mailcap_path = mailcap_path_tmp;
}
obstack_init (&expand_stack);
mu_opool_create (&expand_pool, 1);
ws.ws_delim = ":";
if (mu_wordsplit (mailcap_path, &ws,
......@@ -712,7 +709,7 @@ display_stream_mailcap (const char *ident, mu_stream_t stream, mu_header_t hdr,
}
mu_wordsplit_free (&ws);
}
obstack_free (&expand_stack, NULL);
mu_opool_destroy (&expand_pool);
free (mailcap_path_tmp);
mime_context_release (&ctx);
return rc;
......
......@@ -168,6 +168,25 @@ mu_opool_destroy (mu_opool_t *popool)
}
int
mu_opool_alloc (mu_opool_t opool, size_t size)
{
while (size)
{
size_t rest;
if (!opool->head || opool->tail->level == opool->tail->size)
if (alloc_pool (opool, opool->bucket_size))
return ENOMEM;
rest = opool->tail->size - opool->tail->level;
if (size < rest)
rest = size;
opool->tail->level += rest;
size -= rest;
}
return 0;
}
int
mu_opool_append (mu_opool_t opool, const void *str, size_t n)
{
const char *ptr = str;
......@@ -191,8 +210,7 @@ mu_opool_append_char (mu_opool_t opool, char c)
int
mu_opool_appendz (mu_opool_t opool, const char *str)
{
return mu_opool_append (opool, str, strlen (str))
|| mu_opool_append_char (opool, 0);
return mu_opool_append (opool, str, strlen (str));
}
size_t
......
......@@ -1475,6 +1475,7 @@ mu_cfg_tree_create_node (struct mu_cfg_tree *tree,
{
mu_opool_clear (tree->pool);
mu_opool_appendz (tree->pool, label);
mu_opool_append_char (tree->pool, 0);
val.v.string = mu_opool_finish (tree->pool, NULL);
np->label = config_value_dup (&val);
}
......
......@@ -35,27 +35,27 @@ url_reconstruct_to_pool (mu_url_t url, mu_opool_t pool)
{
int i;
mu_opool_append (pool, url->scheme, strlen (url->scheme));
mu_opool_appendz (pool, url->scheme);
mu_opool_append (pool, "://", 3);
if (url->flags & MU_URL_USER)
mu_opool_append (pool, url->user, strlen (url->user));
mu_opool_appendz (pool, url->user);
if (url->flags & MU_URL_SECRET)
mu_opool_append (pool, ":***", 4); /* FIXME: How about MU_URL_PARSE_HIDEPASS? */
if (url->flags & MU_URL_AUTH)
{
mu_opool_append (pool, AUTH_PFX, sizeof AUTH_PFX - 1);
mu_opool_append (pool, url->auth, strlen (url->auth));
mu_opool_appendz (pool, url->auth);
}
if (url->flags & MU_URL_HOST)
{
if (url->flags & (MU_URL_USER|MU_URL_SECRET|MU_URL_AUTH))
mu_opool_append_char (pool, '@');
mu_opool_append (pool, url->host, strlen (url->host));
mu_opool_appendz (pool, url->host);
if (url->flags & MU_URL_PORT)
{
mu_opool_append_char (pool, ':');
mu_opool_append (pool, url->portstr, strlen (url->portstr));
mu_opool_appendz (pool, url->portstr);
}
}
else if (url->flags & (MU_URL_USER|MU_URL_SECRET|MU_URL_AUTH))
......@@ -65,7 +65,7 @@ url_reconstruct_to_pool (mu_url_t url, mu_opool_t pool)
{
if (url->flags & MU_URL_HOST)
mu_opool_append_char (pool, '/');
mu_opool_append (pool, url->path, strlen (url->path));
mu_opool_appendz (pool, url->path);
}
if (url->flags & MU_URL_PARAM)
......@@ -93,7 +93,7 @@ url_reconstruct_to_pool (mu_url_t url, mu_opool_t pool)
}
else if (url->flags == MU_URL_PATH)
{
mu_opool_append (pool, url->path, strlen (url->path));
mu_opool_appendz (pool, url->path);
return 0;
}
return MU_ERR_URL_MISS_PARTS;
......
......@@ -17,9 +17,6 @@
/* MH burst command */
#include <mh.h>
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include <obstack.h>
static char doc[] = N_("GNU MH burst")"\v"
N_("Options marked with `*' are not yet implemented.\n\
......@@ -134,7 +131,7 @@ struct burst_map map; /* Currently built map */
struct burst_map *burst_map; /* Finished burst map */
size_t burst_count; /* Number of items in burst_map */
mu_mailbox_t tmpbox; /* Temporary mailbox */
struct obstack stk; /* Stack for building burst_map, etc. */
mu_opool_t pool; /* Object pool for building burst_map, etc. */
static int burst_or_copy (mu_message_t msg, int recursive, int copy);
......@@ -592,7 +589,7 @@ burst (size_t num, mu_message_t msg, void *data)
mu_umaxtostr (1, num)));
if (inplace)
{
obstack_grow (&stk, &map, sizeof map);
mu_opool_append (pool, &map, sizeof map);
burst_count++;
}
}
......@@ -752,7 +749,7 @@ main (int argc, char **argv)
mu_attribute_set_deleted (attr);
}
mu_mailbox_expunge (tmpbox);
obstack_init (&stk);
mu_opool_create (&pool, 1);
}
else
tmpbox = mbox;
......@@ -769,7 +766,7 @@ main (int argc, char **argv)
size_t count;
const char *dir;
burst_map = obstack_finish (&stk);
burst_map = mu_opool_finish (pool, NULL);
mu_mailbox_uidnext (mbox, &next_uid);
for (i = 0, last_uid = next_uid-1; i < burst_count; i++)
......
......@@ -17,9 +17,6 @@
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <mh.h>
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include <obstack.h>
int yyerror (const char *s);
int yylex ();
......@@ -27,7 +24,7 @@ int yylex ();
static mh_format_t format; /* Format structure being built */
static size_t pc; /* Program counter. Poins to current
cell in format.prog */
static struct obstack stack; /* Temporary token storage */
static mu_opool_t tokpool; /* Temporary token storage */
#define FORMAT_INC 64 /* Increase format.prog by that many
cells each time pc reaches
......@@ -459,16 +456,16 @@ yylex ()
if (*curp == '\\')
{
int c = backslash (*++curp);
obstack_1grow (&stack, c);
mu_opool_append_char (tokpool, c);
}
else
obstack_1grow (&stack, *curp);
mu_opool_append_char (tokpool, *curp);
curp++;
}
while (*curp && (expect_arg ? *curp != ')' : !isdelim(*curp)));
obstack_1grow (&stack, 0);
yylval.str = obstack_finish (&stack);
mu_opool_append_char (tokpool, 0);
yylval.str = mu_opool_finish (tokpool, NULL);
if (want_function)
{
......@@ -502,7 +499,7 @@ mh_format_parse (char *format_str, mh_format_t *fmt)
if (p)
yydebug = 1;
start = curp = format_str;
obstack_init (&stack);
mu_opool_create (&tokpool, 1);
format.prog = NULL;
format.progsize = 0;
pc = 0;
......@@ -513,7 +510,7 @@ mh_format_parse (char *format_str, mh_format_t *fmt)
rc = yyparse ();
mh_code_op (mhop_stop);
obstack_free (&stack, NULL);
mu_opool_destroy (&tokpool);
if (rc)
{
mh_format_free (&format);
......
......@@ -190,7 +190,7 @@ put_string (struct mh_machine *mach, char *str, int len)
{
if (len == 0)
return;
obstack_grow (&mach->stk, str, len);
mu_opool_append (mach->pool, str, len);
len = mbsnwidth (str, len, 0);
mach->ind += len;
}
......@@ -339,7 +339,7 @@ print_fmt_segment (struct mh_machine *mach, size_t fmtwidth, char *str,
fmtwidth -= width;
mach->ind += fmtwidth;
while (fmtwidth--)
obstack_1grow (&mach->stk, ' ');
mu_opool_append_char (mach->pool, ' ');
}
}
......@@ -394,7 +394,7 @@ format_num (struct mh_machine *mach, long num)
ptr = buf;
for (i = n; i < fmtwidth && mach->ind < mach->width;
i++, mach->ind++)
obstack_1grow (&mach->stk, padchar);
mu_opool_append_char (mach->pool, padchar);
}
}
else
......@@ -422,7 +422,7 @@ format_str (struct mh_machine *mach, char *str)
n = fmtwidth - len;
for (i = 0; i < n && mach->ind < mach->width;
i++, mach->ind++, fmtwidth--)
obstack_1grow (&mach->stk, padchar);
mu_opool_append_char (mach->pool, padchar);
}
print_fmt_string (mach, fmtwidth, str);
......@@ -491,7 +491,7 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno,
mach.width = width - 1; /* Count the newline */
mach.pc = 1;
obstack_init (&mach.stk);
mu_opool_create (&mach.pool, 1);
mu_list_create (&mach.addrlist);
reset_fmt_defaults (&mach);
......@@ -678,10 +678,10 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno,
if (pret)
{
obstack_1grow (&mach.stk, 0);
*pret = mu_strdup (obstack_finish (&mach.stk));
mu_opool_append_char (mach.pool, 0);
*pret = mu_strdup (mu_opool_finish (mach.pool, NULL));
}
obstack_free (&mach.stk, NULL);
mu_opool_destroy (&mach.pool);
return mach.ind;
}
......
......@@ -14,10 +14,6 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include <obstack.h>
typedef struct /* A string object type */
{
int size; /* Allocated size or 0 for static storage */
......@@ -43,7 +39,7 @@ struct mh_machine
mh_instr_t *prog; /* Program itself */
int stop; /* Stop execution immediately */
struct obstack stk; /* Output buffer */
mu_opool_t pool; /* Output buffer */
size_t width; /* Output buffer width */
size_t ind; /* Output buffer index */
......
......@@ -19,9 +19,6 @@
#include <mh.h>
#include <signal.h>
#include <mailutils/mime.h>
#define obstack_chunk_alloc mu_alloc
#define obstack_chunk_free free
#include <obstack.h>
#include <setjmp.h>
static char doc[] = N_("GNU MH mhn")"\v"
......@@ -541,7 +538,7 @@ msg_part_format (msg_part_t p)
}
void
msg_part_format_stk (struct obstack *stk, msg_part_t p)
msg_part_format_pool (mu_opool_t pool, msg_part_t p)
{
int i;
......@@ -551,11 +548,11 @@ msg_part_format_stk (struct obstack *stk, msg_part_t p)
const char *buf;
if (i > 1)
obstack_1grow (stk, '.');
mu_opool_append_char (pool, '.');
buf = mu_umaxtostr (0, p->part[i]);
len = strlen (buf);
obstack_grow (stk, buf, len);
mu_opool_append (pool, buf, len);
}
}
......@@ -634,7 +631,7 @@ mhn_compose_command (char *typestr, char *typeargs, int *flags, char *file)
const char *p, *str;
char *type, *subtype, **typeargv = NULL;
int typeargc = 0;
struct obstack stk;
mu_opool_t pool;
split_content (typestr, &type, &subtype);
str = _mhn_profile_get ("compose", type, subtype, NULL);
......@@ -647,7 +644,8 @@ mhn_compose_command (char *typestr, char *typeargs, int *flags, char *file)
%F %f, and stdout is not redirected
%s subtype */
obstack_init (&stk);
mu_opool_create (&pool, 1);
p = mu_str_skip_class (str, MU_CTYPE_SPACE);
if (*p == '|')
......@@ -671,8 +669,8 @@ mhn_compose_command (char *typestr, char *typeargs, int *flags, char *file)
for (i = 0; i < typeargc; i++)
{
if (i > 0)
obstack_1grow (&stk, ' ');
obstack_grow (&stk, typeargv[i], strlen (typeargv[i]));
mu_opool_append_char (pool, ' ');
mu_opool_appendz (pool, typeargv[i]);
}
}
break;
......@@ -682,36 +680,36 @@ mhn_compose_command (char *typestr, char *typeargs, int *flags, char *file)
*flags |= MHN_STDIN;
/*FALLTHRU*/
case 'f':
obstack_grow (&stk, file, strlen (file));
mu_opool_appendz (pool, file);
break;
case 's':
/* subtype */
obstack_grow (&stk, subtype, strlen (subtype));
mu_opool_appendz (pool, subtype);
break;
default:
obstack_1grow (&stk, *p);
mu_opool_append_char (pool, *p);
p++;
}
}
else
obstack_1grow (&stk, *p);
mu_opool_append_char (pool, *p);
}
obstack_1grow (&stk, 0);
mu_opool_append_char (pool, 0);
free (type);
free (subtype);
mu_argcv_free (typeargc, typeargv);
str = obstack_finish (&stk);
str = mu_opool_finish (pool, NULL);
p = mu_str_skip_class (str, MU_CTYPE_SPACE);
if (!*p)
str = NULL;
else
str = mu_strdup (p);
obstack_free (&stk, NULL);
mu_opool_destroy (&pool);
return (char*) str;
}
......@@ -767,7 +765,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
{
const char *p, *str, *tmp;
char *typestr, *type, *subtype, *typeargs;
struct obstack stk;
mu_opool_t pool;
mu_header_t hdr;
char *temp_cmd = NULL;
int typeargc = 0;
......@@ -827,7 +825,8 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
%s subtype
%d content description */
obstack_init (&stk);
mu_opool_create (&pool, 1);
p = mu_str_skip_class (str, MU_CTYPE_SPACE);
if (*p == '|')
......@@ -851,8 +850,8 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
for (i = 0; i < typeargc; i++)
{
if (i > 0)
obstack_1grow (&stk, ' ');
obstack_grow (&stk, typeargv[i], strlen (typeargv[i]));
mu_opool_append_char (pool, ' ');
mu_opool_appendz (pool, typeargv[i]);
}
}
break;
......@@ -866,7 +865,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
/* filename containing content */
if (!*tempfile)
mhn_tempfile_name (tempfile, type, subtype);
obstack_grow (&stk, *tempfile, strlen (*tempfile));
mu_opool_appendz (pool, *tempfile);
break;
case 'F':
......@@ -874,7 +873,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
*flags |= MHN_STDIN|MHN_EXCLUSIVE_EXEC;
if (!*tempfile)
mhn_tempfile_name (tempfile, type, subtype);
obstack_grow (&stk, *tempfile, strlen (*tempfile));
mu_opool_appendz (pool, *tempfile);
break;
case 'l':
......@@ -889,25 +888,25 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
case 's':
/* subtype */
obstack_grow (&stk, subtype, strlen (subtype));
mu_opool_appendz (pool, subtype);
break;
case 'd':
/* content description */
if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_DESCRIPTION,
&tmp) == 0)
obstack_grow (&stk, tmp, strlen (tmp));
mu_opool_appendz (pool, tmp);
break;
default:
obstack_1grow (&stk, *p);
mu_opool_append_char (pool, *p);
p++;
}
}
else
obstack_1grow (&stk, *p);
mu_opool_append_char (pool, *p);
}
obstack_1grow (&stk, 0);
mu_opool_append_char (pool, 0);
free (typestr);
free (type);
......@@ -915,14 +914,14 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
free (temp_cmd);
mu_argcv_free (typeargc, typeargv);
str = obstack_finish (&stk);
str = mu_opool_finish (pool, NULL);
p = mu_str_skip_class (str, MU_CTYPE_SPACE);
if (!*p)
str = NULL;
else
str = mu_strdup (p);
obstack_free (&stk, NULL);
mu_opool_destroy (&pool);
return (char*) str;
}
......@@ -941,7 +940,7 @@ mhn_store_command (mu_message_t msg, msg_part_t part, const char *name,
{
const char *p, *str, *tmp;
char *typestr, *type, *subtype, *typeargs;
struct obstack stk;
mu_opool_t pool;
mu_header_t hdr;
enum store_destination dest;
......@@ -998,7 +997,8 @@ mhn_store_command (mu_message_t msg, msg_part_t part, const char *name,
%p part
%s subtype */
obstack_init (&stk);
mu_opool_create (&pool, 1);
for (p = str; *p; p++)
{
if (*p == '%')
......@@ -1007,62 +1007,62 @@ mhn_store_command (mu_message_t msg, msg_part_t part, const char *name,
{
case 'a':
/* additional arguments */
obstack_grow (&stk, typeargs, strlen (typeargs));
mu_opool_appendz (pool, typeargs);
break;
case 'm':
if (name)
obstack_grow (&stk, name, strlen (name));
mu_opool_appendz (pool, name);
else
{
const char *buf = mu_umaxtostr (0, msg_part_subpart (part, 0));
obstack_grow (&stk, buf, strlen (buf));
mu_opool_appendz (pool, buf);
}
break;
case 'P':
if (msg_part_level (part) >= 1)
obstack_1grow (&stk, '.');
mu_opool_append_char (pool, '.');
/*FALLTHRU*/
case 'p':
if (msg_part_level (part) >= 1)
msg_part_format_stk (&stk, part);
msg_part_format_pool (pool, part);
break;
case 's':
/* subtype */
obstack_grow (&stk, subtype, strlen (subtype));
mu_opool_appendz (pool, subtype);
break;
case 'd':
/* content description */
if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_DESCRIPTION,
&tmp) == 0)
obstack_grow (&stk, tmp, strlen (tmp));
mu_opool_appendz (pool, tmp);
break;
default:
obstack_1grow (&stk, *p);
mu_opool_append_char (pool, *p);
p++;
}
}
else
obstack_1grow (&stk, *p);
mu_opool_append_char (pool, *p);
}
obstack_1grow (&stk, *p);
mu_opool_append_char (pool, *p);
free (typestr);
free (type);
free (subtype);
str = obstack_finish (&stk);
str = mu_opool_finish (pool, NULL);
p = mu_str_skip_class (str, MU_CTYPE_SPACE);
if (!*p)
*return_string = NULL;
else
*return_string = mu_strdup (p);
obstack_free (&stk, NULL);
mu_opool_destroy (&pool);
return dest;
}
......@@ -1932,7 +1932,7 @@ parse_brace (char **pval, char **cmd, int c, struct compose_env *env)
int
parse_content_type (struct compose_env *env,
struct obstack *stk, char **prest, char **id, char **descr)
mu_opool_t pool, char **prest, char **id, char **descr)
{
int status = 0, stop = 0;
char *rest = *prest;
......@@ -1990,12 +1990,12 @@ parse_content_type (struct compose_env *env,
break;
case ';':
obstack_1grow (stk, ';');
obstack_1grow (stk, ' ');
mu_opool_append_char (pool, ';');
mu_opool_append_char (pool, ' ');
skipws (rest);
sp = rest;
for (; *rest && !mu_isspace (*rest) && *rest != '='; rest++)
obstack_1grow (stk, *rest);
mu_opool_append_char (pool, *rest);
skipws (rest);
if (*rest != '=')
{
......@@ -2006,13 +2006,13 @@ parse_content_type (struct compose_env *env,
break;
}
rest++;
obstack_1grow (stk, '=');
mu_opool_append_char (pool, '=');
skipws (rest);
for (; *rest; rest++)
{
if (isdelim (*rest))
break;
obstack_1grow (stk, *rest);
mu_opool_append_char (pool, *rest);
}
break;
......@@ -2025,9 +2025,9 @@ parse_content_type (struct compose_env *env,
if (comment)
{
obstack_grow (stk, " (", 2);
obstack_grow (stk, comment, strlen (comment));
obstack_1grow (stk, ')');
mu_opool_append (pool, " (", 2);
mu_opool_appendz (pool, comment);
mu_opool_append_char (pool, ')');
free (comment);
}
*prest = rest;
......@@ -2048,7 +2048,7 @@ parse_type_command (char **pcmd, struct compose_env *env, mu_header_t hdr)
char *type = NULL;
char *subtype = NULL;
char *descr = NULL, *id = NULL;
struct obstack stk;
mu_opool_t pool;
char *rest = *pcmd;
skipws (rest);
......@@ -2068,15 +2068,17 @@ parse_type_command (char **pcmd, struct compose_env *env, mu_header_t hdr)
return 1;
}
obstack_init (&stk);
obstack_grow (&stk, type, strlen (type));
obstack_1grow (&stk, '/');
obstack_grow (&stk, subtype, strlen (subtype));
status = parse_content_type (env, &stk, &rest, &id, &descr);
obstack_1grow (&stk, 0);
mu_opool_create (&pool, 1);
mu_opool_appendz (pool, type);
mu_opool_append_char (pool, '/');
mu_opool_appendz (pool, subtype);
status = parse_content_type (env, pool, &rest, &id, &descr);
mu_opool_append_char (pool, 0);
mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE, obstack_finish (&stk), 1);
obstack_free (&stk, NULL);
mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE,
mu_opool_finish (pool, NULL), 1);
mu_opool_destroy (&pool);
if (!id)
id = mh_create_message_id (env->subpart);
......@@ -2217,7 +2219,7 @@ edit_extern (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
mu_header_t hdr, hdr2;
mu_body_t body;
mu_stream_t in, out = NULL;
struct obstack stk;
mu_opool_t pool;
if (!*msg)
mu_message_create (msg, NULL);
......@@ -2234,13 +2236,14 @@ edit_extern (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
mu_message_get_header (*msg, &hdr);
obstack_init (&stk);
obstack_grow (&stk, EXTCONTENT, sizeof (EXTCONTENT) - 1);
mu_opool_create (&pool, 1);
mu_opool_append (pool, EXTCONTENT, sizeof (EXTCONTENT) - 1);
*--rest = ';'; /* FIXME */
rc = parse_content_type (env, &stk, &rest, &id, NULL);
obstack_1grow (&stk, 0);
mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE, obstack_finish (&stk), 1);
obstack_free (&stk, NULL);
rc = parse_content_type (env, pool, &rest, &id, NULL);
mu_opool_append_char (pool, 0);
mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE,
mu_opool_finish (pool, NULL), 1);
mu_opool_destroy (&pool);
if (rc)
return 1;
......
......@@ -120,7 +120,7 @@ static char *mhl_filter = NULL; /* --filter flag */
static int annotate; /* --annotate flag */
static char *draftmessage = "new";
static const char *draftfolder = NULL;
static struct obstack fcc_stack;
static mu_opool_t fcc_pool;
static int has_fcc;
static int
......@@ -243,12 +243,12 @@ opt_handler (int key, char *arg, struct argp_state *state)
case ARG_FCC:
if (!has_fcc)
{
obstack_init (&fcc_stack);
mu_opool_create (&fcc_pool, 1);
has_fcc = 1;
}
else
obstack_grow (&fcc_stack, ", ", 2);
obstack_grow (&fcc_stack, arg, strlen (arg));
mu_opool_append (fcc_pool, ", ", 2);
mu_opool_appendz (fcc_pool, arg);
break;
case ARG_INPLACE:
......@@ -348,7 +348,7 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
mu_message_create_copy (&tmp_msg, msg);
mu_message_get_header (tmp_msg, &hdr);
text = obstack_finish (&fcc_stack);
text = mu_opool_finish (fcc_pool, NULL);
mu_header_set_value (hdr, MU_HEADER_FCC, text, 0);
mh_format (&format, tmp_msg, msgno, width, &buf);
mu_message_destroy (&tmp_msg, NULL);
......
......@@ -97,7 +97,7 @@ mh_whatnow_env_to_environ (struct mh_whatnow_env *wh)
if (prev_uid == 0)
{
s = mu_umaxtostr (0, uid);
mu_opool_append (opool, s, strlen (s));
mu_opool_appendz (opool, s);
mrange = 0;
}
else if (uid == prev_uid + 1)
......@@ -108,11 +108,11 @@ mh_whatnow_env_to_environ (struct mh_whatnow_env *wh)
{
mu_opool_append_char (opool, '-');
s = mu_umaxtostr (0, prev_uid);
mu_opool_append (opool, s, strlen (s));
mu_opool_appendz (opool, s);
}
mu_opool_append_char (opool, ' ');
s = mu_umaxtostr (0, uid);
mu_opool_append (opool, s, strlen (s));
mu_opool_appendz (opool, s);
mrange = 0;
}
}
......@@ -121,7 +121,7 @@ mh_whatnow_env_to_environ (struct mh_whatnow_env *wh)
{
mu_opool_append_char (opool, '-');
s = mu_umaxtostr (0, prev_uid);
mu_opool_append (opool, s, strlen (s));
mu_opool_appendz (opool, s);
}
mu_opool_append_char (opool, 0);
s = mu_opool_finish (opool, NULL);
......
......@@ -32,7 +32,7 @@ static int line_num;
static char *file_name;
static int file_name_alloc;
static struct obstack stack;
static mu_opool_t pool;
static int prev_state;
static unsigned
......@@ -56,25 +56,22 @@ WS [ \t]*
\n { line_num++; return EOL; }
{WS} ;
{IDENT} {
obstack_grow (&stack, yytext, yyleng);
yylval.string.len = obstack_object_size (&stack);
obstack_1grow (&stack, 0);
yylval.string.ptr = obstack_finish (&stack);
mu_opool_append (pool, yytext, yyleng);
mu_opool_append_char (pool, 0);
yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
return IDENT;
}
<INITIAL>{IDENT}"(" {
obstack_grow (&stack, yytext, yyleng-1);
yylval.string.len = obstack_object_size (&stack);
obstack_1grow (&stack, 0);
yylval.string.ptr = obstack_finish (&stack);
mu_opool_append (pool, yytext, yyleng-1);
mu_opool_append_char (pool, 0);
yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
BEGIN(ARGS);
return IDENT_L;
}
<INITIAL,ARGS>\"[^\\"\n]*\" {
obstack_grow (&stack, yytext+1, yyleng-2);
yylval.string.len = obstack_object_size (&stack);
obstack_1grow (&stack, 0);
yylval.string.ptr = obstack_finish (&stack);
mu_opool_append (pool, yytext+1, yyleng-2);
mu_opool_append_char (pool, 0);
yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
return STRING;
}
<INITIAL,ARGS>"<" {
......@@ -82,40 +79,36 @@ WS [ \t]*
BEGIN(HEX);
}
<ARGS>[^ \t<\\\n),]+/[),] {
obstack_grow (&stack, yytext, yyleng);
yylval.string.len = obstack_object_size (&stack);
obstack_1grow (&stack, 0);
yylval.string.ptr = obstack_finish (&stack);
mu_opool_append (pool, yytext, yyleng);
mu_opool_append_char (pool, 0);
yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
return STRING;
}
<ARGS>[^ \t<\\\n),]+< {
obstack_grow (&stack, yytext, yyleng);
mu_opool_append (pool, yytext, yyleng);
prev_state = YYSTATE;
BEGIN(HEX);
}
<INITIAL>[^ \t<\\\n)+,&]/[ \t\\\n)+,&] {
obstack_grow (&stack, yytext, yyleng);
yylval.string.len = obstack_object_size (&stack);
obstack_1grow (&stack, 0);
yylval.string.ptr = obstack_finish (&stack);
mu_opool_append (pool, yytext, yyleng);
mu_opool_append_char (pool, 0);
yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
return STRING;
}
<ARGS>[^ \t<\\\n),]/[ \t\\\n] {
obstack_grow (&stack, yytext, yyleng);
yylval.string.len = obstack_object_size (&stack);
obstack_1grow (&stack, 0);
yylval.string.ptr = obstack_finish (&stack);
mu_opool_append (pool, yytext, yyleng);
mu_opool_append_char (pool, 0);
yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
return STRING;
}
<HEX>{X}{X} {
int c = digit_to_number (yytext[0])*16 + digit_to_number (yytext[1]);
obstack_1grow (&stack, c);
mu_opool_append_char (pool, c);
}
<HEX>">"/[ \t\\\n,)] {
BEGIN(prev_state);
yylval.string.len = obstack_object_size (&stack);
obstack_1grow (&stack, 0);
yylval.string.ptr = obstack_finish (&stack);
mu_opool_append_char (pool, 0);
yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
return STRING;
}
<HEX>">" {
......@@ -174,7 +167,7 @@ mimetypes_open (const char *name)
return -1;
}
line_num = 1;
obstack_init (&stack);
mu_opool_create (&pool, 1);
return 0;
}
......@@ -210,25 +203,26 @@ mimetypes_append_string2 (struct mimetypes_string *s1,
struct mimetypes_string r;
r.len = s1->len + s2->len + 1;
obstack_grow (&stack, s1->ptr, s1->len);
obstack_1grow (&stack, c);
obstack_grow (&stack, s2->ptr, s2->len);
obstack_1grow (&stack, 0);
r.ptr = obstack_finish (&stack);
mu_opool_append (pool, s1->ptr, s1->len);
mu_opool_append_char (pool, c);
mu_opool_append (pool, s2->ptr, s2->len);
mu_opool_append_char (pool, 0);
r.ptr = mu_opool_finish (pool, NULL);
return r;
}
struct mimetypes_string *
mimetypes_string_dup (struct mimetypes_string *s)
{
obstack_grow (&stack, s, sizeof *s);
return obstack_finish (&stack);
mu_opool_append (pool, s, sizeof *s);
return mu_opool_finish (pool, NULL);
}
void *
mimetypes_malloc (size_t size)
{
return obstack_alloc(&stack, size);
mu_opool_alloc (pool, size);
return mu_opool_finish (pool, NULL);
}
void
......
......@@ -22,9 +22,6 @@
#endif
#include <mailutils/mailutils.h>
#include <fnmatch.h>
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include <obstack.h>
struct mimetypes_string
{
......