/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* This module implements execution of MH format strings. */
#include <mh.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
typedef struct /* A string object type */
{
int size; /* Allocated size or 0 for static storage */
char *ptr; /* Actual data */
} strobj_t;
struct mh_machine
{
strobj_t reg_str; /* String register */
int reg_num; /* Numeric register */
strobj_t arg_str; /* String argument */
long arg_num; /* Numeric argument */
size_t pc; /* Program counter */
size_t progsize; /* Size of allocated program*/
mh_instr_t *prog; /* Program itself */
int stop; /* Stop execution immediately */
char *outbuf; /* Output buffer */
size_t width; /* Output buffer size */
size_t ind; /* Output buffer index */
int fmtflags; /* Current formatting flags */
message_t message; /* Current message */
size_t msgno; /* Its number */
};
static char *_get_builtin_name __P((mh_builtin_fp ptr));
/* Functions for handling string objects. */
void
strobj_free (strobj_t *obj)
{
if (obj->size)
free (obj->ptr);
obj->size = 0;
obj->ptr = NULL;
}
#define strobj_ptr(p) ((p)->ptr ? (p)->ptr : "")
#define strobj_len(p) (strobj_is_null(p) ? 0 : strlen((p)->ptr))
#define strobj_is_null(p) ((p)->ptr == NULL)
#define strobj_is_static(p) ((p)->size == 0)
static void
strobj_create (strobj_t *lvalue, char *str)
{
if (!str)
{
lvalue->size = 0;
lvalue->ptr = NULL;
}
else
{
lvalue->size = strlen (str) + 1;
lvalue->ptr = xmalloc (lvalue->size);
memcpy (lvalue->ptr, str, lvalue->size);
}
}
static void
strobj_set (strobj_t *lvalue, char *str)
{
lvalue->size = 0;
lvalue->ptr = str;
}
static void
strobj_assign (strobj_t *lvalue, strobj_t *rvalue)
{
strobj_free (lvalue);
*lvalue = *rvalue;
rvalue->size = 0;
rvalue->ptr = NULL;
}
static void
strobj_copy (strobj_t *lvalue, strobj_t *rvalue)
{
if (strobj_is_null (rvalue))
strobj_free (lvalue);
else if
|