define.c, whitespace cleanup
This commit is contained in:
parent
38ce3b6142
commit
1fbc4d62cc
|
|
@ -23,7 +23,7 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
|
||||||
|
|
||||||
#include "completion.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/* static declarations */
|
|
||||||
static void savetree(struct pnode *pn);
|
static void savetree(struct pnode *pn);
|
||||||
static void prdefs(char *name);
|
static void prdefs(char *name);
|
||||||
static void prtree(struct udfunc *ud);
|
static void prtree(struct udfunc *ud);
|
||||||
|
|
@ -31,9 +31,9 @@ static void prtree1(struct pnode *pn, FILE *fp);
|
||||||
static struct pnode * trcopy(struct pnode *tree, char *args, struct pnode *nn);
|
static struct pnode * trcopy(struct pnode *tree, char *args, struct pnode *nn);
|
||||||
static struct pnode * ntharg(int num, struct pnode *args);
|
static struct pnode * ntharg(int num, struct pnode *args);
|
||||||
|
|
||||||
|
|
||||||
static struct udfunc *udfuncs = NULL;
|
static struct udfunc *udfuncs = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* Set up a function definition. */
|
/* Set up a function definition. */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -57,9 +57,11 @@ com_define(wordlist *wlist)
|
||||||
* to try really hard to break this here.
|
* to try really hard to break this here.
|
||||||
*/
|
*/
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
for (wl = wlist; wl && (strchr(wl->wl_word, /* ( */ ')') == NULL);
|
for (wl = wlist; wl && (strchr(wl->wl_word, /* ( */ ')') == NULL);
|
||||||
wl = wl->wl_next)
|
wl = wl->wl_next)
|
||||||
(void) strcat(buf, wl->wl_word);
|
(void) strcat(buf, wl->wl_word);
|
||||||
|
|
||||||
if (wl) {
|
if (wl) {
|
||||||
for (t = buf; *t; t++)
|
for (t = buf; *t; t++)
|
||||||
;
|
;
|
||||||
|
|
@ -83,11 +85,13 @@ com_define(wordlist *wlist)
|
||||||
* there isn't a predefined function of the same name).
|
* there isn't a predefined function of the same name).
|
||||||
*/
|
*/
|
||||||
(void) strcpy(tbuf, buf);
|
(void) strcpy(tbuf, buf);
|
||||||
|
|
||||||
for (b = tbuf; *b; b++)
|
for (b = tbuf; *b; b++)
|
||||||
if (isspace(*b) || (*b == '(' /* ) */)) {
|
if (isspace(*b) || (*b == '(' /* ) */)) {
|
||||||
*b = '\0';
|
*b = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; ft_funcs[i].fu_name; i++)
|
for (i = 0; ft_funcs[i].fu_name; i++)
|
||||||
if (eq(ft_funcs[i].fu_name, tbuf)) {
|
if (eq(ft_funcs[i].fu_name, tbuf)) {
|
||||||
fprintf(cp_err, "Error: %s is a predefined function.\n",
|
fprintf(cp_err, "Error: %s is a predefined function.\n",
|
||||||
|
|
@ -122,26 +126,31 @@ com_define(wordlist *wlist)
|
||||||
arity++;
|
arity++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (udf = udfuncs; udf; udf = udf->ud_next)
|
for (udf = udfuncs; udf; udf = udf->ud_next)
|
||||||
if (prefix(b, udf->ud_name) && (arity == udf->ud_arity))
|
if (prefix(b, udf->ud_name) && (arity == udf->ud_arity))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (udf == NULL) {
|
if (udf == NULL) {
|
||||||
udf = alloc(struct udfunc);
|
udf = alloc(struct udfunc);
|
||||||
if (udfuncs == NULL) {
|
if (udfuncs == NULL) {
|
||||||
udfuncs = udf;
|
udfuncs = udf;
|
||||||
udf->ud_next = NULL;
|
udf->ud_next = NULL;
|
||||||
} else {
|
} else {
|
||||||
udf->ud_next = udfuncs;
|
udf->ud_next = udfuncs;
|
||||||
udfuncs = udf;
|
udfuncs = udf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
udf->ud_text = pn;
|
udf->ud_text = pn;
|
||||||
udf->ud_name = b;
|
udf->ud_name = b;
|
||||||
udf->ud_arity = arity;
|
udf->ud_arity = arity;
|
||||||
|
|
||||||
cp_addkword(CT_UDFUNCS, b);
|
cp_addkword(CT_UDFUNCS, b);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Kludge. */
|
/* Kludge. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -156,7 +165,7 @@ savetree(struct pnode *pn)
|
||||||
d = pn->pn_value;
|
d = pn->pn_value;
|
||||||
if ((d->v_length != 0) || eq(d->v_name, "list")) {
|
if ((d->v_length != 0) || eq(d->v_name, "list")) {
|
||||||
pn->pn_value = alloc(struct dvec);
|
pn->pn_value = alloc(struct dvec);
|
||||||
ZERO(pn->pn_value, struct dvec);
|
ZERO(pn->pn_value, struct dvec);
|
||||||
pn->pn_value->v_name = copy(d->v_name);
|
pn->pn_value->v_name = copy(d->v_name);
|
||||||
pn->pn_value->v_length = d->v_length;
|
pn->pn_value->v_length = d->v_length;
|
||||||
pn->pn_value->v_type = d->v_type;
|
pn->pn_value->v_type = d->v_type;
|
||||||
|
|
@ -165,13 +174,13 @@ savetree(struct pnode *pn)
|
||||||
if (isreal(d)) {
|
if (isreal(d)) {
|
||||||
pn->pn_value->v_realdata = TMALLOC(double, d->v_length);
|
pn->pn_value->v_realdata = TMALLOC(double, d->v_length);
|
||||||
bcopy(d->v_realdata,
|
bcopy(d->v_realdata,
|
||||||
pn->pn_value->v_realdata,
|
pn->pn_value->v_realdata,
|
||||||
sizeof (double) * (size_t) d->v_length);
|
sizeof (double) * (size_t) d->v_length);
|
||||||
} else {
|
} else {
|
||||||
pn->pn_value->v_compdata = TMALLOC(ngcomplex_t, d->v_length);
|
pn->pn_value->v_compdata = TMALLOC(ngcomplex_t, d->v_length);
|
||||||
bcopy(d->v_compdata,
|
bcopy(d->v_compdata,
|
||||||
pn->pn_value->v_compdata,
|
pn->pn_value->v_compdata,
|
||||||
sizeof(ngcomplex_t) * (size_t) d->v_length);
|
sizeof(ngcomplex_t) * (size_t) d->v_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (pn->pn_op) {
|
} else if (pn->pn_op) {
|
||||||
|
|
@ -184,6 +193,7 @@ savetree(struct pnode *pn)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* A bunch of junk to print out nodes. */
|
/* A bunch of junk to print out nodes. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -197,6 +207,7 @@ prdefs(char *name)
|
||||||
if (s)
|
if (s)
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name && *name) { /* You never know what people will do */
|
if (name && *name) { /* You never know what people will do */
|
||||||
for (udf = udfuncs; udf; udf = udf->ud_next)
|
for (udf = udfuncs; udf; udf = udf->ud_next)
|
||||||
if (eq(name, udf->ud_name))
|
if (eq(name, udf->ud_name))
|
||||||
|
|
@ -207,6 +218,7 @@ prdefs(char *name)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Print out one definition. */
|
/* Print out one definition. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -236,6 +248,7 @@ prtree(struct udfunc *ud)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
prtree1(struct pnode *pn, FILE *fp)
|
prtree1(struct pnode *pn, FILE *fp)
|
||||||
{
|
{
|
||||||
|
|
@ -260,6 +273,7 @@ prtree1(struct pnode *pn, FILE *fp)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct pnode *
|
struct pnode *
|
||||||
ft_substdef(const char *name, struct pnode *args)
|
ft_substdef(const char *name, struct pnode *args)
|
||||||
{
|
{
|
||||||
|
|
@ -271,9 +285,11 @@ ft_substdef(const char *name, struct pnode *args)
|
||||||
|
|
||||||
if (args)
|
if (args)
|
||||||
arity = 1;
|
arity = 1;
|
||||||
|
|
||||||
for (tp = args; tp && tp->pn_op && (tp->pn_op->op_num == PT_OP_COMMA); tp =
|
for (tp = args; tp && tp->pn_op && (tp->pn_op->op_num == PT_OP_COMMA); tp =
|
||||||
tp->pn_right)
|
tp->pn_right)
|
||||||
arity++;
|
arity++;
|
||||||
|
|
||||||
for (udf = udfuncs; udf; udf = udf->ud_next)
|
for (udf = udfuncs; udf; udf = udf->ud_next)
|
||||||
if (eq(name, udf->ud_name)) {
|
if (eq(name, udf->ud_name)) {
|
||||||
if (arity == udf->ud_arity)
|
if (arity == udf->ud_arity)
|
||||||
|
|
@ -283,13 +299,15 @@ ft_substdef(const char *name, struct pnode *args)
|
||||||
rarity = udf->ud_arity;
|
rarity = udf->ud_arity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (udf == NULL) {
|
if (udf == NULL) {
|
||||||
if (found)
|
if (found)
|
||||||
fprintf(cp_err,
|
fprintf(cp_err,
|
||||||
"Warning: the user-defined function %s has %d args\n",
|
"Warning: the user-defined function %s has %d args\n",
|
||||||
name, rarity);
|
name, rarity);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (s = udf->ud_name; *s; s++)
|
for (s = udf->ud_name; *s; s++)
|
||||||
;
|
;
|
||||||
s++;
|
s++;
|
||||||
|
|
@ -300,6 +318,7 @@ ft_substdef(const char *name, struct pnode *args)
|
||||||
return (trcopy(udf->ud_text, s, args));
|
return (trcopy(udf->ud_text, s, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Copy the tree and replace formal args with the right stuff. The way
|
/* Copy the tree and replace formal args with the right stuff. The way
|
||||||
* we know that something might be a formal arg is when it is a dvec
|
* we know that something might be a formal arg is when it is a dvec
|
||||||
* with length 0 and a name that isn't "list". I hope nobody calls their
|
* with length 0 and a name that isn't "list". I hope nobody calls their
|
||||||
|
|
@ -315,7 +334,9 @@ trcopy(struct pnode *tree, char *args, struct pnode *nn)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (tree->pn_value) {
|
if (tree->pn_value) {
|
||||||
|
|
||||||
d = tree->pn_value;
|
d = tree->pn_value;
|
||||||
|
|
||||||
if ((d->v_length == 0) && strcmp(d->v_name, "list")) {
|
if ((d->v_length == 0) && strcmp(d->v_name, "list")) {
|
||||||
/* Yep, it's a formal parameter. Substitute for it.
|
/* Yep, it's a formal parameter. Substitute for it.
|
||||||
* IMPORTANT: we never free parse trees, so we
|
* IMPORTANT: we never free parse trees, so we
|
||||||
|
|
@ -337,44 +358,48 @@ trcopy(struct pnode *tree, char *args, struct pnode *nn)
|
||||||
return (tree);
|
return (tree);
|
||||||
} else
|
} else
|
||||||
return (tree);
|
return (tree);
|
||||||
|
|
||||||
} else if (tree->pn_func) {
|
} else if (tree->pn_func) {
|
||||||
|
|
||||||
pn = alloc(struct pnode);
|
pn = alloc(struct pnode);
|
||||||
pn->pn_use = 0;
|
pn->pn_use = 0;
|
||||||
pn->pn_name = NULL;
|
pn->pn_name = NULL;
|
||||||
pn->pn_value = NULL;
|
pn->pn_value = NULL;
|
||||||
/* pn_func are pointers to a global constant struct */
|
/* pn_func are pointers to a global constant struct */
|
||||||
pn->pn_func = tree->pn_func;
|
pn->pn_func = tree->pn_func;
|
||||||
pn->pn_op = NULL;
|
pn->pn_op = NULL;
|
||||||
pn->pn_left = trcopy(tree->pn_left, args, nn);
|
pn->pn_left = trcopy(tree->pn_left, args, nn);
|
||||||
pn->pn_left->pn_use++;
|
pn->pn_left->pn_use++;
|
||||||
pn->pn_right = NULL;
|
pn->pn_right = NULL;
|
||||||
pn->pn_next = NULL;
|
pn->pn_next = NULL;
|
||||||
|
|
||||||
} else if (tree->pn_op) {
|
} else if (tree->pn_op) {
|
||||||
|
|
||||||
pn = alloc(struct pnode);
|
pn = alloc(struct pnode);
|
||||||
pn->pn_use = 0;
|
pn->pn_use = 0;
|
||||||
pn->pn_name = NULL;
|
pn->pn_name = NULL;
|
||||||
pn->pn_value = NULL;
|
pn->pn_value = NULL;
|
||||||
pn->pn_func = NULL;
|
pn->pn_func = NULL;
|
||||||
/* pn_op are pointers to a global constant struct */
|
/* pn_op are pointers to a global constant struct */
|
||||||
pn->pn_op = tree->pn_op;
|
pn->pn_op = tree->pn_op;
|
||||||
pn->pn_left = trcopy(tree->pn_left, args, nn);
|
pn->pn_left = trcopy(tree->pn_left, args, nn);
|
||||||
pn->pn_left->pn_use++;
|
pn->pn_left->pn_use++;
|
||||||
if (pn->pn_op->op_arity == 2) {
|
if (pn->pn_op->op_arity == 2) {
|
||||||
pn->pn_right = trcopy(tree->pn_right, args, nn);
|
pn->pn_right = trcopy(tree->pn_right, args, nn);
|
||||||
pn->pn_right->pn_use++;
|
pn->pn_right->pn_use++;
|
||||||
} else
|
} else
|
||||||
pn->pn_right = NULL;
|
pn->pn_right = NULL;
|
||||||
pn->pn_next = NULL;
|
pn->pn_next = NULL;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(cp_err, "trcopy: Internal Error: bad parse node\n");
|
fprintf(cp_err, "trcopy: Internal Error: bad parse node\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (pn);
|
return (pn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Find the n'th arg in the arglist, returning NULL if there isn't one.
|
/* Find the n'th arg in the arglist, returning NULL if there isn't one.
|
||||||
* Since comma has such a low priority and associates to the right,
|
* Since comma has such a low priority and associates to the right,
|
||||||
* we can just follow the right branch of the tree num times.
|
* we can just follow the right branch of the tree num times.
|
||||||
|
|
@ -387,23 +412,27 @@ ntharg(int num, struct pnode *args)
|
||||||
struct pnode *ptry;
|
struct pnode *ptry;
|
||||||
|
|
||||||
ptry = args;
|
ptry = args;
|
||||||
|
|
||||||
if (num > 1) {
|
if (num > 1) {
|
||||||
while (--num > 0) {
|
while (--num > 0) {
|
||||||
if (ptry && ptry->pn_op &&
|
if (ptry && ptry->pn_op &&
|
||||||
(ptry->pn_op->op_num != PT_OP_COMMA)) {
|
(ptry->pn_op->op_num != PT_OP_COMMA)) {
|
||||||
if (num == 1)
|
if (num == 1)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
ptry = ptry->pn_right;
|
ptry = ptry->pn_right;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptry && ptry->pn_op && (ptry->pn_op->op_num == PT_OP_COMMA))
|
if (ptry && ptry->pn_op && (ptry->pn_op->op_num == PT_OP_COMMA))
|
||||||
ptry = ptry->pn_left;
|
ptry = ptry->pn_left;
|
||||||
|
|
||||||
return (ptry);
|
return (ptry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
com_undefine(wordlist *wlist)
|
com_undefine(wordlist *wlist)
|
||||||
{
|
{
|
||||||
|
|
@ -411,10 +440,12 @@ com_undefine(wordlist *wlist)
|
||||||
|
|
||||||
if (!wlist)
|
if (!wlist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (*wlist->wl_word == '*') {
|
if (*wlist->wl_word == '*') {
|
||||||
udfuncs = NULL; /* Be sloppy. */
|
udfuncs = NULL; /* Be sloppy. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (wlist) {
|
while (wlist) {
|
||||||
ludf = NULL;
|
ludf = NULL;
|
||||||
for (udf = udfuncs; udf; udf = udf->ud_next) {
|
for (udf = udfuncs; udf; udf = udf->ud_next) {
|
||||||
|
|
@ -432,6 +463,7 @@ com_undefine(wordlist *wlist)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef LINT
|
#ifndef LINT
|
||||||
|
|
||||||
/* Watch out, this is not at all portable. It's only here so I can
|
/* Watch out, this is not at all portable. It's only here so I can
|
||||||
|
|
@ -445,4 +477,3 @@ ft_pnode(struct pnode *pn)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue