[PATCH 47] Refactored ft_getnames() and used the new function in
com_let().
This commit is contained in:
parent
016c558d77
commit
018025df1e
|
|
@ -17,7 +17,6 @@ com_let(wordlist *wl)
|
||||||
char *p, *q, *s;
|
char *p, *q, *s;
|
||||||
int indices[MAXDIMS];
|
int indices[MAXDIMS];
|
||||||
int numdims;
|
int numdims;
|
||||||
wordlist fake_wl;
|
|
||||||
int need_open;
|
int need_open;
|
||||||
int offset, length;
|
int offset, length;
|
||||||
struct pnode *names;
|
struct pnode *names;
|
||||||
|
|
@ -27,7 +26,6 @@ com_let(wordlist *wl)
|
||||||
int newvec;
|
int newvec;
|
||||||
char *rhs;
|
char *rhs;
|
||||||
|
|
||||||
fake_wl.wl_next = NULL;
|
|
||||||
|
|
||||||
if (!wl) {
|
if (!wl) {
|
||||||
com_display(NULL);
|
com_display(NULL);
|
||||||
|
|
@ -80,8 +78,7 @@ com_let(wordlist *wl)
|
||||||
|
|
||||||
/* evaluate expression between s and q */
|
/* evaluate expression between s and q */
|
||||||
/* va, indexing */
|
/* va, indexing */
|
||||||
fake_wl.wl_word = s;
|
names = ft_getpnames_from_string(s, TRUE);
|
||||||
names = ft_getpnames(&fake_wl, TRUE);
|
|
||||||
if (!names) {
|
if (!names) {
|
||||||
/* XXX error message */
|
/* XXX error message */
|
||||||
tfree(p);
|
tfree(p);
|
||||||
|
|
@ -130,10 +127,9 @@ com_let(wordlist *wl)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* evaluate rhs */
|
/* evaluate rhs */
|
||||||
fake_wl.wl_word = rhs;
|
names = ft_getpnames_from_string(rhs, TRUE);
|
||||||
names = ft_getpnames(&fake_wl, TRUE);
|
|
||||||
if (names == NULL) {
|
if (names == NULL) {
|
||||||
/* XXX error message */
|
fprintf(cp_err, "Error: RHS \"%s\" invalid\n", rhs);
|
||||||
tfree(p);
|
tfree(p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -812,7 +812,7 @@ op_ind(struct pnode *arg1, struct pnode *arg2)
|
||||||
|
|
||||||
/* Apply a function to an argument. Complex functions are called as follows:
|
/* Apply a function to an argument. Complex functions are called as follows:
|
||||||
* cx_something(data, type, length, &newlength, &newtype),
|
* cx_something(data, type, length, &newlength, &newtype),
|
||||||
* and returns a char * that is cast to complex or double.
|
* and returns a void * that is cast to complex or double.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
|
|
|
||||||
|
|
@ -30,26 +30,16 @@ void db_print_pnode_tree(struct pnode *p, char *print);
|
||||||
|
|
||||||
|
|
||||||
struct pnode *
|
struct pnode *
|
||||||
ft_getpnames(wordlist *wl, bool check)
|
ft_getpnames_from_string(const char *sz, bool check)
|
||||||
{
|
{
|
||||||
struct pnode *pn = NULL;
|
struct pnode *pn;
|
||||||
char *xsbuf, *sbuf;
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
if (!wl) {
|
/* The first argument to PPparse is not const char **, but it does not
|
||||||
fprintf(cp_err, "Warning: NULL arithmetic expression\n");
|
* appear to modify the string that is being parsed */
|
||||||
return (NULL);
|
if (PPparse((char **) &sz, &pn) != 0) {
|
||||||
|
return (struct pnode *) NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
xsbuf = sbuf = wl_flatten(wl);
|
|
||||||
|
|
||||||
rv = PPparse(&sbuf, &pn);
|
|
||||||
|
|
||||||
tfree(xsbuf);
|
|
||||||
|
|
||||||
if (rv)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
/* If validation is requested, do it and return NULL on failure. The
|
/* If validation is requested, do it and return NULL on failure. The
|
||||||
* structure must also be freed if the check fails since it is not
|
* structure must also be freed if the check fails since it is not
|
||||||
* being returned. */
|
* being returned. */
|
||||||
|
|
@ -58,7 +48,26 @@ ft_getpnames(wordlist *wl, bool check)
|
||||||
return (struct pnode *) NULL;
|
return (struct pnode *) NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (pn);
|
return pn;
|
||||||
|
} /* end of function ft_getpnames_from_string */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct pnode *
|
||||||
|
ft_getpnames(const wordlist *wl, bool check)
|
||||||
|
{
|
||||||
|
/* Validate input */
|
||||||
|
if (!wl) {
|
||||||
|
(void) fprintf(cp_err, "Warning: NULL arithmetic expression\n");
|
||||||
|
return (struct pnode *) NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the list to a string then parse the string */
|
||||||
|
const char * const sz = wl_flatten(wl);
|
||||||
|
struct pnode * const pn = ft_getpnames_from_string(sz, check);
|
||||||
|
txfree((void *) sz);
|
||||||
|
|
||||||
|
return pn; /* Return the parsed result */
|
||||||
} /* end of function ft_getpnames */
|
} /* end of function ft_getpnames */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,8 @@ extern bool ft_stricterror;
|
||||||
extern struct func ft_funcs[];
|
extern struct func ft_funcs[];
|
||||||
extern struct func func_not;
|
extern struct func func_not;
|
||||||
extern struct func func_uminus;
|
extern struct func func_uminus;
|
||||||
extern struct pnode *ft_getpnames(wordlist *wl, bool check);
|
extern struct pnode *ft_getpnames(const wordlist *wl, bool check);
|
||||||
|
struct pnode *ft_getpnames_from_string(const char *sz, bool check);
|
||||||
extern struct pnode *alloc_pnode(void);
|
extern struct pnode *alloc_pnode(void);
|
||||||
#define free_pnode(ptr) \
|
#define free_pnode(ptr) \
|
||||||
do { \
|
do { \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue