*/
#include <h/mh.h>
+#include <h/utils.h>
#include <h/addrsbr.h>
#include <h/tws.h>
#include <h/fmt_scan.h>
#include <h/fmt_compile.h>
+#include <ctype.h>
+#include <sysexits.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
/* Add new component to the hash table */
#define NEWCOMP(cm,name) do { \
- cm = ((struct comp *) calloc(1, sizeof (struct comp)));\
+ cm = (mh_xcalloc(1, sizeof (struct comp)));\
cm->c_name = name;\
ncomp++;\
i = CHASH(name);\
static struct ftable *
lookup(char *name)
{
- register struct ftable *t = functable;
- register char *nm;
- register char c = *name;
+ struct ftable *t = functable;
+ char *nm;
+ char c = *name;
while ((nm = t->name)) {
if (*nm == c && strcmp(nm, name) == 0)
}
advise(NULL, "\"%s\": format compile error - %s",
- &usr_fstring[errpos-errctx], str);
- adios(NULL, "%*s", errctx+1, "^");
+ &usr_fstring[errpos-errctx], str);
+ adios(EX_SOFTWARE, NULL, "%*s", errctx+1, "^");
}
/*
int
fmt_compile(char *fstring, struct format **fmt)
{
- register char *cp;
+ char *cp;
size_t i;
if (format_string)
- free(format_string);
- format_string = getcpy(fstring);
+ mh_free0(&format_string);
+ format_string = mh_xstrdup(fstring);
usr_fstring = fstring;
/* init the component hash table. */
i = strlen(fstring)/2 + 1;
if (i == 1)
i++;
- next_fp = formatvec = (struct format *)calloc((size_t) i,
- sizeof(struct format));
+ next_fp = formatvec = mh_xcalloc(i, sizeof(struct format));
if (next_fp == NULL)
- adios(NULL, "unable to allocate format storage");
+ adios(EX_OSERR, NULL, "unable to allocate format storage");
ncomp = 0;
infunction = 0;
static char *
compile(char *sp)
{
- register char *cp = sp;
- register int c;
+ char *cp = sp;
+ int c;
for (;;) {
sp = cp;
static char *
do_spec(char *sp)
{
- register char *cp = sp;
- register int c;
-#ifndef lint
- register int ljust = 0;
-#endif /* not lint */
- register int wid = 0;
- register char fill = ' ';
+ char *cp = sp;
+ int c;
+ int ljust = 0;
+ int wid = 0;
+ char fill = ' ';
c = *cp++;
if (c == '-') {
static char *
do_name(char *sp, int preprocess)
{
- register char *cp = sp;
- register int c;
- register int i;
+ char *cp = sp;
+ int c;
+ int i;
static int primed = 0;
while (isalnum(c = *cp++) || c == '-' || c == '_')
if (cm->c_type & CT_ADDR) {
CERROR("component used as both date and address");
}
- cm->c_tws = (struct tws *)
- calloc((size_t) 1, sizeof(*cm->c_tws));
+ cm->c_tws = mh_xcalloc(1, sizeof(*cm->c_tws));
fp->f_type = preprocess;
PUTCOMP(sp);
cm->c_type |= CT_DATE;
static char *
do_func(char *sp)
{
- register char *cp = sp;
- register int c;
- register struct ftable *t;
- register int n;
+ char *cp = sp;
+ int c;
+ struct ftable *t;
+ int n;
int mflag; /* minus sign in NUM */
infunction++;
static char *
do_expr(char *sp, int preprocess)
{
- register char *cp = sp;
- register int c;
+ char *cp = sp;
+ int c;
if ((c = *cp++) == '{') {
cp = do_name(cp, preprocess);
static char *
do_loop(char *sp)
{
- register char *cp = sp;
+ char *cp = sp;
struct format *floop;
floop = next_fp;
static char *
do_if(char *sp)
{
- register char *cp = sp;
- register struct format *fexpr, *fif = (struct format *)NULL;
- register int c = '<';
+ char *cp = sp;
+ struct format *fexpr, *fif = (struct format *)NULL;
+ int c = '<';
for (;;) {
if (c == '<') { /* doing an IF */