version 1.15, 2003/06/10 22:20:50 |
version 1.16, 2003/10/07 17:56:26 |
|
|
static char *compile_tr(char *, char **); |
static char *compile_tr(char *, char **); |
static struct s_command |
static struct s_command |
**compile_stream(struct s_command **); |
**compile_stream(struct s_command **); |
static char *duptoeol(char *, char *); |
static char *duptoeol(char *, char *, char **); |
static void enterlabel(struct s_command *); |
static void enterlabel(struct s_command *); |
static struct s_command |
static struct s_command |
*findlabel(char *); |
*findlabel(char *); |
|
|
EATSPACE(); |
EATSPACE(); |
if (*p == '\0') |
if (*p == '\0') |
err(COMPILE, "filename expected"); |
err(COMPILE, "filename expected"); |
cmd->t = duptoeol(p, "w command"); |
cmd->t = duptoeol(p, "w command", NULL); |
if (aflag) |
if (aflag) |
cmd->u.fd = -1; |
cmd->u.fd = -1; |
else if ((cmd->u.fd = open(p, |
else if ((cmd->u.fd = open(p, |
|
|
case RFILE: /* r */ |
case RFILE: /* r */ |
p++; |
p++; |
EATSPACE(); |
EATSPACE(); |
cmd->t = duptoeol(p, "read command"); |
cmd->t = duptoeol(p, "read command", NULL); |
break; |
break; |
case BRANCH: /* b t */ |
case BRANCH: /* b t */ |
p++; |
p++; |
|
|
if (*p == '\0') |
if (*p == '\0') |
cmd->t = NULL; |
cmd->t = NULL; |
else |
else |
cmd->t = duptoeol(p, "branch"); |
cmd->t = duptoeol(p, "branch", &p); |
|
if (*p == ';') { |
|
p++; |
|
goto semicolon; |
|
} |
break; |
break; |
case LABEL: /* : */ |
case LABEL: /* : */ |
p++; |
p++; |
EATSPACE(); |
EATSPACE(); |
cmd->t = duptoeol(p, "label"); |
cmd->t = duptoeol(p, "label", &p); |
if (strlen(p) == 0) |
if (strlen(cmd->t) == 0) |
err(COMPILE, "empty label"); |
err(COMPILE, "empty label"); |
enterlabel(cmd); |
enterlabel(cmd); |
|
if (*p == ';') { |
|
p++; |
|
goto semicolon; |
|
} |
break; |
break; |
case SUBST: /* s */ |
case SUBST: /* s */ |
p++; |
p++; |
|
|
* Return a copy of all the characters up to \n or \0. |
* Return a copy of all the characters up to \n or \0. |
*/ |
*/ |
static char * |
static char * |
duptoeol(char *s, char *ctype) |
duptoeol(char *s, char *ctype, char **semi) |
{ |
{ |
size_t len; |
size_t len; |
int ws; |
int ws; |
char *start; |
char *start; |
|
|
ws = 0; |
ws = 0; |
for (start = s; *s != '\0' && *s != '\n'; ++s) |
if (semi) { |
ws = isspace(*s); |
for (start = s; *s != '\0' && *s != '\n' && *s != ';'; ++s) |
*s = '\0'; |
ws = isspace(*s); |
|
} else { |
|
for (start = s; *s != '\0' && *s != '\n'; ++s) |
|
ws = isspace(*s); |
|
*s = '\0'; |
|
} |
if (ws) |
if (ws) |
err(WARNING, "whitespace after %s", ctype); |
err(WARNING, "whitespace after %s", ctype); |
len = s - start + 1; |
len = s - start + 1; |
return (memmove(xmalloc(len), start, len)); |
if (semi) |
|
*semi = s; |
|
s = xmalloc(len); |
|
strlcpy(s, start, len); |
|
return (s); |
} |
} |
|
|
/* |
/* |