Enable use of a numeric .param as an integer:
.param xxx = 3.1459 echo $%xxx
This commit is contained in:
parent
b4c2660659
commit
011b6cea3f
|
|
@ -617,7 +617,8 @@ char cp_dol = '$';
|
||||||
* special...
|
* special...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define VALIDCHARS "$-_<#?@.()[]&"
|
/* mhx added %. */
|
||||||
|
#define VALIDCHARS "$-_<#?@.()[]&%"
|
||||||
|
|
||||||
char *
|
char *
|
||||||
span_var_expr(char *t)
|
span_var_expr(char *t)
|
||||||
|
|
@ -719,7 +720,8 @@ vareval(char *string)
|
||||||
char buf[BSIZE_SP], *s;
|
char buf[BSIZE_SP], *s;
|
||||||
char *oldstring = copy(string);
|
char *oldstring = copy(string);
|
||||||
char *range = NULL;
|
char *range = NULL;
|
||||||
int i, up, low, found;
|
#define INTEGER 0
|
||||||
|
int i, up, low, found, fmt = !INTEGER;
|
||||||
char *text, *snew = NULL;
|
char *text, *snew = NULL;
|
||||||
double val;
|
double val;
|
||||||
|
|
||||||
|
|
@ -786,6 +788,7 @@ vareval(char *string)
|
||||||
free_struct_variable(vfree); /* bug: free still used struct variable */
|
free_struct_variable(vfree); /* bug: free still used struct variable */
|
||||||
return (wl);
|
return (wl);
|
||||||
|
|
||||||
|
case '%': fmt = INTEGER; /* fall through */
|
||||||
case '.': /* mhx: evaluate a numeric/string .parameter */
|
case '.': /* mhx: evaluate a numeric/string .parameter */
|
||||||
string++;
|
string++;
|
||||||
val = nupa_get_param(string, &found, &text);
|
val = nupa_get_param(string, &found, &text);
|
||||||
|
|
@ -795,7 +798,9 @@ vareval(char *string)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (found == 'R')
|
if (found == 'R')
|
||||||
wl = wl_cons(tprintf("%20.16e", val), NULL);
|
wl = (fmt==INTEGER) ?
|
||||||
|
wl_cons(tprintf("%lld", (size_t)val), NULL) :
|
||||||
|
wl_cons(tprintf("%20.16e", val), NULL) ;
|
||||||
else if (text && found == 'S') {
|
else if (text && found == 'S') {
|
||||||
snew = copy(text + 1);
|
snew = copy(text + 1);
|
||||||
snew[MAX(0, strlen(snew) - 1)] = '\0'; /* strip leading and trailing quote */
|
snew[MAX(0, strlen(snew) - 1)] = '\0'; /* strip leading and trailing quote */
|
||||||
|
|
@ -809,6 +814,7 @@ vareval(char *string)
|
||||||
tfree(oldstring);
|
tfree(oldstring);
|
||||||
return (wl);
|
return (wl);
|
||||||
}
|
}
|
||||||
|
#undef INTEGER
|
||||||
|
|
||||||
/* The notation var[stuff] has two meanings... If this is a real
|
/* The notation var[stuff] has two meanings... If this is a real
|
||||||
* variable, then the [] denotes range, but if this is a strange
|
* variable, then the [] denotes range, but if this is a strange
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue