evalue.c: evalue_sum: split into orthants + some refactoring
[barvinok.git] / evalue_read.c
blob99968a5eace5ddd6db402ac69ebaa8b9a36c14f2
1 #include <barvinok/util.h>
2 #include "evalue_read.h"
4 #define ALLOC(type) (type*)malloc(sizeof(type))
5 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
7 enum token_type { TOKEN_UNKNOWN = 256, TOKEN_VALUE, TOKEN_IDENT, TOKEN_GE,
8 TOKEN_NE, TOKEN_UNION, TOKEN_VARS };
10 struct token {
11 enum token_type type;
13 int line;
14 int col;
16 union {
17 Value v;
18 char *s;
19 } u;
22 static struct token *token_new(int line, int col)
24 struct token *tok = ALLOC(struct token);
25 tok->line = line;
26 tok->col = col;
27 return tok;
30 void token_free(struct token *tok)
32 if (tok->type == TOKEN_VALUE)
33 value_clear(tok->u.v);
34 else if (tok->type == TOKEN_IDENT)
35 free(tok->u.s);
36 free(tok);
39 struct stream {
40 FILE *file;
41 const char *str;
42 int line;
43 int col;
44 int eof;
46 char *buffer;
47 size_t size;
48 size_t len;
49 int c;
51 struct token *tokens[5];
52 int n_token;
55 static struct stream* stream_new()
57 int i;
58 struct stream *s = ALLOC(struct stream);
59 s->size = 256;
60 s->file = NULL;
61 s->str = NULL;
62 s->buffer = (char*)malloc(s->size);
63 s->len = 0;
64 s->line = 1;
65 s->col = 0;
66 s->eof = 0;
67 s->c = -1;
68 for (i = 0; i < 5; ++i)
69 s->tokens[i] = NULL;
70 s->n_token = 0;
71 return s;
74 static struct stream* stream_new_file(FILE *file)
76 struct stream *s = stream_new();
77 s->file = file;
78 return s;
81 static struct stream* stream_new_str(const char *str)
83 struct stream *s = stream_new();
84 s->str = str;
85 return s;
88 static int stream_getc(struct stream *s)
90 int c;
91 if (s->eof)
92 return -1;
93 if (s->file)
94 c = fgetc(s->file);
95 else {
96 c = *s->str++;
97 if (c == '\0')
98 c = -1;
100 if (c == -1)
101 s->eof = 1;
102 if (!s->eof) {
103 if (s->c == '\n') {
104 s->line++;
105 s->col = 0;
106 } else
107 s->col++;
109 s->c = c;
110 return c;
113 static void stream_ungetc(struct stream *s, int c)
115 if (s->file)
116 ungetc(c, s->file);
117 else
118 --s->str;
119 s->c = -1;
122 static void stream_push_char(struct stream *s, int c)
124 if (s->len >= s->size) {
125 s->size = (3*s->size)/2;
126 s->buffer = (char*)realloc(s->buffer, s->size);
128 s->buffer[s->len++] = c;
131 static struct token *stream_push_token(struct stream *s, struct token *tok)
133 assert(s->n_token < 5);
134 s->tokens[s->n_token++] = tok;
137 static struct token *stream_next_token(struct stream *s)
139 int c;
140 struct token *tok;
141 int line, col;
143 if (s->n_token)
144 return s->tokens[--s->n_token];
146 s->len = 0;
148 /* skip spaces */
149 while ((c = stream_getc(s)) != -1 && isspace(c))
150 /* nothing */
153 line = s->line;
154 col = s->col;
156 if (c == -1)
157 return NULL;
158 if (c == '(' ||
159 c == ')' ||
160 c == '+' ||
161 c == '/' ||
162 c == '*' ||
163 c == '^' ||
164 c == '=' ||
165 c == ',' ||
166 c == '_' ||
167 c == '[' ||
168 c == ']' ||
169 c == '{' ||
170 c == '}') {
171 tok = token_new(line, col);
172 tok->type = (enum token_type)c;
173 return tok;
175 if (c == '-' || isdigit(c)) {
176 tok = token_new(line, col);
177 tok->type = TOKEN_VALUE;
178 value_init(tok->u.v);
179 stream_push_char(s, c);
180 while ((c = stream_getc(s)) != -1 && isdigit(c))
181 stream_push_char(s, c);
182 if (c != -1)
183 stream_ungetc(s, c);
184 if (s->len == 1 && s->buffer[0] == '-')
185 value_set_si(tok->u.v, -1);
186 else {
187 stream_push_char(s, '\0');
188 mpz_set_str(tok->u.v, s->buffer, 0);
190 return tok;
192 if (c == '#' || isalpha(c)) {
193 tok = token_new(line, col);
194 stream_push_char(s, c);
195 while ((c = stream_getc(s)) != -1 && isalnum(c))
196 stream_push_char(s, c);
197 if (c != -1)
198 stream_ungetc(s, c);
199 stream_push_char(s, '\0');
200 if (!strcmp(s->buffer, "#variables")) {
201 tok->type = TOKEN_VARS;
202 } else if (s->buffer[0] == '#') {
203 tok->type = TOKEN_UNKNOWN;
204 } else if (!strcmp(s->buffer, "UNION")) {
205 tok->type = TOKEN_UNION;
206 } else {
207 tok->type = TOKEN_IDENT;
208 tok->u.s = strdup(s->buffer);
210 return tok;
212 if (c == '>') {
213 if ((c = stream_getc(s)) == '=') {
214 tok = token_new(line, col);
215 tok->type = TOKEN_GE;
216 return tok;
218 if (c != -1)
219 stream_ungetc(s, c);
221 if (c == '!') {
222 if ((c = stream_getc(s)) == '=') {
223 tok = token_new(line, col);
224 tok->type = TOKEN_NE;
225 return tok;
227 if (c != -1)
228 stream_ungetc(s, c);
231 tok = token_new(line, col);
232 tok->type = TOKEN_UNKNOWN;
233 return tok;
236 void stream_error(struct stream *s, struct token *tok, char *msg)
238 int line = tok ? tok->line : s->line;
239 int col = tok ? tok->col : s->col;
240 fprintf(stderr, "syntax error (%d, %d): %s\n", line, col, msg);
241 if (tok) {
242 if (tok->type < 256)
243 fprintf(stderr, "got '%c'\n", tok->type);
244 else
245 fprintf(stderr, "got token type %d\n", tok->type);
249 static void stream_free(struct stream *s)
251 free(s->buffer);
252 if (s->n_token != 0) {
253 struct token *tok = stream_next_token(s);
254 stream_error(s, tok, "unexpected token");
256 free(s);
259 struct parameter {
260 char *name;
261 int pos;
262 struct parameter *next;
265 struct parameter *parameter_new(char *name, int pos, struct parameter *next)
267 struct parameter *p = ALLOC(struct parameter);
268 p->name = strdup(name);
269 p->pos = pos;
270 p->next = next;
271 return p;
274 static int parameter_pos(struct parameter **p, const char *s, int len)
276 int pos = *p ? (*p)->pos+1 : 0;
277 struct parameter *q;
279 if (len == -1)
280 len = strlen(s);
281 for (q = *p; q; q = q->next) {
282 if (strncmp(q->name, s, len) == 0)
283 break;
285 if (q)
286 pos = q->pos;
287 else
288 *p = parameter_new(s, pos, *p);
289 return pos;
292 static int optional_power(struct stream *s)
294 int pow;
295 struct token *tok;
296 tok = stream_next_token(s);
297 if (!tok)
298 return 1;
299 if (tok->type != '^') {
300 stream_push_token(s, tok);
301 return 1;
303 token_free(tok);
304 tok = stream_next_token(s);
305 if (!tok || tok->type != TOKEN_VALUE) {
306 stream_error(s, tok, "expecting exponent");
307 if (tok)
308 stream_push_token(s, tok);
309 return 1;
311 pow = VALUE_TO_INT(tok->u.v);
312 token_free(tok);
313 return pow;
316 static evalue *evalue_read_factor(struct stream *s, struct parameter **p);
317 static evalue *evalue_read_term(struct stream *s, struct parameter **p);
319 static evalue *create_fract_like(struct stream *s, evalue *arg, enode_type type,
320 struct parameter **p)
322 evalue *e;
323 int pow;
324 pow = optional_power(s);
326 e = ALLOC(evalue);
327 value_init(e->d);
328 e->x.p = new_enode(type, pow+2, -1);
329 value_clear(e->x.p->arr[0].d);
330 e->x.p->arr[0] = *arg;
331 free(arg);
332 evalue_set_si(&e->x.p->arr[1+pow], 1, 1);
333 while (--pow >= 0)
334 evalue_set_si(&e->x.p->arr[1+pow], 0, 1);
336 return e;
339 static evalue *create_relation(evalue *arg, int ne)
341 evalue *e;
343 e = ALLOC(evalue);
344 value_init(e->d);
345 e->x.p = new_enode(relation, 2+ne, 0);
346 value_clear(e->x.p->arr[0].d);
347 e->x.p->arr[0] = *arg;
348 free(arg);
349 if (ne)
350 evalue_set_si(&e->x.p->arr[1], 0, 1);
351 evalue_set_si(&e->x.p->arr[1+ne], 1, 1);
353 return e;
356 static evalue *read_fract(struct stream *s, struct token *tok, struct parameter **p)
358 evalue *arg;
360 tok = stream_next_token(s);
361 assert(tok);
362 assert(tok->type == '{');
364 token_free(tok);
365 arg = evalue_read_term(s, p);
366 tok = stream_next_token(s);
367 if (!tok || tok->type != '}') {
368 stream_error(s, tok, "expecting \"}\"");
369 if (tok)
370 stream_push_token(s, tok);
371 } else
372 token_free(tok);
374 return create_fract_like(s, arg, fractional, p);
377 static evalue *read_periodic(struct stream *s, struct parameter **p)
379 evalue **list;
380 int len;
381 int n;
382 evalue *e = NULL;
384 struct token *tok;
385 tok = stream_next_token(s);
386 assert(tok && tok->type == '[');
387 token_free(tok);
389 len = 100;
390 list = (evalue **)malloc(len * sizeof(evalue *));
391 n = 0;
393 for (;;) {
394 evalue *e = evalue_read_term(s, p);
395 if (!e) {
396 stream_error(s, NULL, "missing argument or list element");
397 goto out;
399 if (n >= len) {
400 len = (3*len)/2;
401 list = (evalue **)realloc(list, len * sizeof(evalue *));
403 list[n++] = e;
405 tok = stream_next_token(s);
406 if (!tok) {
407 stream_error(s, NULL, "unexpected EOF");
408 goto out;
410 if (tok->type != ',')
411 break;
412 token_free(tok);
415 if (n == 1 && (tok->type == '=' || tok->type == TOKEN_NE)) {
416 int ne = tok->type == TOKEN_NE;
417 token_free(tok);
418 tok = stream_next_token(s);
419 if (!tok || tok->type != TOKEN_VALUE) {
420 stream_error(s, tok, "expecting \"0\"");
421 if (tok)
422 stream_push_token(s, tok);
423 goto out;
425 token_free(tok);
426 tok = stream_next_token(s);
427 if (!tok || tok->type != ']') {
428 stream_error(s, tok, "expecting \"]\"");
429 if (tok)
430 stream_push_token(s, tok);
431 goto out;
433 token_free(tok);
434 e = create_relation(list[0], ne);
435 n = 0;
436 goto out;
439 if (tok->type != ']') {
440 stream_error(s, tok, "expecting \"]\"");
441 stream_push_token(s, tok);
442 goto out;
445 token_free(tok);
447 tok = stream_next_token(s);
448 if (tok && tok->type == '_') {
449 int pos;
450 token_free(tok);
451 tok = stream_next_token(s);
452 if (!tok || tok->type != TOKEN_IDENT) {
453 stream_error(s, tok, "expecting identifier");
454 if (tok)
455 stream_push_token(s, tok);
456 goto out;
458 e = ALLOC(evalue);
459 value_init(e->d);
460 pos = parameter_pos(p, tok->u.s, -1);
461 token_free(tok);
462 e->x.p = new_enode(periodic, n, pos+1);
463 while (--n >= 0) {
464 value_clear(e->x.p->arr[n].d);
465 e->x.p->arr[n] = *list[n];
466 free(list[n]);
468 } else if (n == 1) {
469 if (tok)
470 stream_push_token(s, tok);
471 e = create_fract_like(s, list[0], flooring, p);
472 n = 0;
473 } else {
474 stream_error(s, tok, "unexpected token");
475 if (tok)
476 stream_push_token(s, tok);
479 out:
480 while (--n >= 0) {
481 free_evalue_refs(list[n]);
482 free(list[n]);
484 free(list);
485 return e;
488 static evalue *evalue_read_factor(struct stream *s, struct parameter **p)
490 struct token *tok;
491 evalue *e = NULL;
493 tok = stream_next_token(s);
494 if (!tok)
495 return NULL;
497 if (tok->type == '(') {
498 token_free(tok);
499 e = evalue_read_term(s, p);
500 tok = stream_next_token(s);
501 if (!tok || tok->type != ')') {
502 stream_error(s, tok, "expecting \")\"");
503 if (tok)
504 stream_push_token(s, tok);
505 } else
506 token_free(tok);
507 } else if (tok->type == TOKEN_VALUE) {
508 e = ALLOC(evalue);
509 value_init(e->d);
510 value_set_si(e->d, 1);
511 value_init(e->x.n);
512 value_assign(e->x.n, tok->u.v);
513 token_free(tok);
514 tok = stream_next_token(s);
515 if (tok && tok->type == '/') {
516 token_free(tok);
517 tok = stream_next_token(s);
518 if (!tok || tok->type != TOKEN_VALUE) {
519 stream_error(s, tok, "expecting denominator");
520 if (tok)
521 stream_push_token(s, tok);
522 return NULL;
524 value_assign(e->d, tok->u.v);
525 token_free(tok);
526 } else if (tok)
527 stream_push_token(s, tok);
528 } else if (tok->type == TOKEN_IDENT) {
529 int pos = parameter_pos(p, tok->u.s, -1);
530 int pow = optional_power(s);
531 token_free(tok);
532 e = ALLOC(evalue);
533 value_init(e->d);
534 e->x.p = new_enode(polynomial, pow+1, pos+1);
535 evalue_set_si(&e->x.p->arr[pow], 1, 1);
536 while (--pow >= 0)
537 evalue_set_si(&e->x.p->arr[pow], 0, 1);
538 } else if (tok->type == '[') {
539 stream_push_token(s, tok);
540 e = read_periodic(s, p);
541 } else if (tok->type == '{') {
542 stream_push_token(s, tok);
543 e = read_fract(s, tok, p);
546 tok = stream_next_token(s);
547 if (tok && tok->type == '*') {
548 evalue *e2;
549 token_free(tok);
550 e2 = evalue_read_factor(s, p);
551 if (!e2) {
552 stream_error(s, NULL, "unexpected EOF");
553 return NULL;
555 emul(e2, e);
556 free_evalue_refs(e2);
557 free(e2);
558 } else if (tok)
559 stream_push_token(s, tok);
561 return e;
564 static evalue *evalue_read_term(struct stream *s, struct parameter **p)
566 struct token *tok;
567 evalue *e = NULL;
569 e = evalue_read_factor(s, p);
570 if (!e)
571 return NULL;
573 tok = stream_next_token(s);
574 if (!tok)
575 return e;
577 if (tok->type == '+') {
578 evalue *e2;
579 token_free(tok);
580 e2 = evalue_read_term(s, p);
581 if (!e2) {
582 stream_error(s, NULL, "unexpected EOF");
583 return NULL;
585 eadd(e2, e);
586 free_evalue_refs(e2);
587 free(e2);
588 } else
589 stream_push_token(s, tok);
591 return e;
594 struct constraint {
595 int type;
596 Vector *v;
597 struct constraint *next;
598 struct constraint *union_next;
601 static struct constraint *constraint_new()
603 struct constraint *c = ALLOC(struct constraint);
604 c->type = -1;
605 c->v = Vector_Alloc(16);
606 c->next = NULL;
607 c->union_next = NULL;
608 return c;
611 static void constraint_free(struct constraint *c)
613 while (c) {
614 struct constraint *next = c->next ? c->next : c->union_next;
615 Vector_Free(c->v);
616 free(c);
617 c = next;
621 static void constraint_extend(struct constraint *c, int pos)
623 Vector *v;
624 if (pos < c->v->Size)
625 return;
627 v = Vector_Alloc((3*c->v->Size)/2);
628 Vector_Copy(c->v->p, v->p, c->v->Size);
629 Vector_Free(c->v);
630 c->v = v;
633 static int evalue_read_constraint(struct stream *s, struct parameter **p,
634 struct constraint **constraints,
635 struct constraint *union_next)
637 struct token *tok;
638 struct constraint *c = NULL;
640 while ((tok = stream_next_token(s))) {
641 struct token *tok2;
642 int pos;
643 if (tok->type == '+')
644 token_free(tok);
645 else if (tok->type == TOKEN_IDENT) {
646 if (!c)
647 c = constraint_new();
648 pos = parameter_pos(p, tok->u.s, -1);
649 constraint_extend(c, 1+pos);
650 value_set_si(c->v->p[1+pos], 1);
651 token_free(tok);
652 } else if (tok->type == TOKEN_VALUE) {
653 if (!c)
654 c = constraint_new();
655 tok2 = stream_next_token(s);
656 if (tok2 && tok2->type == TOKEN_IDENT) {
657 pos = parameter_pos(p, tok2->u.s, -1);
658 constraint_extend(c, 1+pos);
659 value_assign(c->v->p[1+pos], tok->u.v);
660 token_free(tok);
661 token_free(tok2);
662 } else {
663 if (tok2)
664 stream_push_token(s, tok2);
665 value_assign(c->v->p[0], tok->u.v);
666 token_free(tok);
668 } else if (tok->type == TOKEN_GE || tok->type == '=') {
669 int type = tok->type == TOKEN_GE;
670 token_free(tok);
671 tok = stream_next_token(s);
672 if (!tok || tok->type != TOKEN_VALUE || value_notzero_p(tok->u.v)) {
673 stream_error(s, tok, "expecting \"0\"");
674 if (tok)
675 stream_push_token(s, tok);
676 *constraints = NULL;
677 } else {
678 c->type = type;
679 c->next = *constraints;
680 c->union_next = union_next;
681 *constraints = c;
682 token_free(tok);
684 break;
685 } else {
686 if (!c)
687 stream_push_token(s, tok);
688 else {
689 stream_error(s, tok, "unexpected token");
690 *constraints = NULL;
692 return 0;
695 return tok != NULL;
698 static struct constraint *evalue_read_domain(struct stream *s, struct parameter **p,
699 unsigned MaxRays)
701 struct constraint *constraints = NULL;
702 struct constraint *union_next = NULL;
703 struct token *tok;
704 int line;
706 tok = stream_next_token(s);
707 if (!tok)
708 return NULL;
709 stream_push_token(s, tok);
711 line = tok->line;
712 while (evalue_read_constraint(s, p, &constraints, union_next)) {
713 tok = stream_next_token(s);
714 if (tok) {
715 if (tok->type == TOKEN_UNION) {
716 token_free(tok);
717 tok = stream_next_token(s);
718 if (!tok) {
719 stream_error(s, NULL, "unexpected EOF");
720 return constraints;
722 stream_push_token(s, tok);
723 union_next = constraints;
724 constraints = NULL;
725 } else {
726 union_next = NULL;
727 stream_push_token(s, tok);
728 /* empty line separates domain from evalue */
729 if (tok->line > line+1)
730 break;
732 line = tok->line;
735 return constraints;
738 struct section {
739 struct constraint *constraints;
740 evalue *e;
741 struct section *next;
744 static char **extract_parameters(struct parameter *p, unsigned *nparam)
746 int i;
747 char **params;
749 *nparam = p ? p->pos+1 : 0;
750 params = ALLOCN(char *, *nparam);
751 for (i = 0; i < *nparam; ++i) {
752 struct parameter *next = p->next;
753 params[p->pos] = p->name;
754 free(p);
755 p = next;
757 return params;
760 static Polyhedron *constraints2domain(struct constraint *constraints,
761 unsigned nparam, unsigned MaxRays)
763 Polyhedron *D;
764 Matrix *M;
765 int n;
766 struct constraint *c;
767 struct constraint *union_next = NULL;
769 for (n = 0, c = constraints; c; ++n, c = c->next)
771 M = Matrix_Alloc(n, 1+nparam+1);
772 while (--n >= 0) {
773 struct constraint *next = constraints->next;
774 union_next = constraints->union_next;
775 Vector_Copy(constraints->v->p+1, M->p[n]+1, nparam);
776 if (constraints->type)
777 value_set_si(M->p[n][0], 1);
778 value_assign(M->p[n][1+nparam], constraints->v->p[0]);
779 constraints->next = NULL;
780 constraints->union_next = NULL;
781 constraint_free(constraints);
782 constraints = next;
784 D = Constraints2Polyhedron(M, MaxRays);
785 Matrix_Free(M);
787 if (union_next)
788 D = DomainConcat(D, constraints2domain(union_next, nparam, MaxRays));
789 return D;
792 static evalue *evalue_read_partition(struct stream *s, struct parameter *p,
793 char ***ppp,
794 unsigned *nparam, unsigned MaxRays)
796 struct section *part = NULL;
797 struct constraint *constraints;
798 evalue *e = NULL;
799 int m = 0;
801 while ((constraints = evalue_read_domain(s, &p, MaxRays))) {
802 evalue *e = evalue_read_term(s, &p);
803 if (!e) {
804 stream_error(s, NULL, "missing evalue");
805 break;
807 struct section *sect = ALLOC(struct section);
808 sect->constraints = constraints;
809 sect->e = e;
810 sect->next = part;
811 part = sect;
812 ++m;
815 if (part) {
816 Polyhedron *D;
817 int j;
819 *ppp = extract_parameters(p, nparam);
820 e = ALLOC(evalue);
821 value_init(e->d);
822 e->x.p = new_enode(partition, 2*m, *nparam);
824 for (j = 0; j < m; ++j) {
825 int n;
826 struct section *next = part->next;
827 constraints = part->constraints;
828 D = constraints2domain(part->constraints, *nparam, MaxRays);
829 EVALUE_SET_DOMAIN(e->x.p->arr[2*j], D);
830 value_clear(e->x.p->arr[2*j+1].d);
831 e->x.p->arr[2*j+1] = *part->e;
832 free(part->e);
833 free(part);
834 part = next;
837 return e;
840 static evalue *evalue_read(struct stream *s, const char *var_list, char ***ppp,
841 unsigned *nvar, unsigned *nparam, unsigned MaxRays)
843 struct token *tok;
844 evalue *e;
845 struct parameter *p = NULL;
846 char *next;
847 int nv;
849 if (var_list) {
850 while ((next = strchr(var_list, ','))) {
851 if (next > var_list)
852 parameter_pos(&p, var_list, next-var_list);
853 var_list = next+1;
855 if (strlen(var_list) > 0)
856 parameter_pos(&p, var_list, -1);
857 nv = p ? p->pos+1 : 0;
858 } else
859 nv = -1;
861 if (!(tok = stream_next_token(s)))
862 return NULL;
864 if (tok->type == TOKEN_VARS) {
865 token_free(tok);
866 for (;;) {
867 tok = stream_next_token(s);
868 if (!tok || tok->type != TOKEN_IDENT) {
869 stream_error(s, tok, "expecting identifier");
870 break;
872 if (nv == -1)
873 parameter_pos(&p, tok->u.s, -1);
874 token_free(tok);
875 tok = stream_next_token(s);
876 if (!tok || tok->type != ',')
877 break;
878 token_free(tok);
880 if (!tok)
881 return NULL;
882 if (nv = -1)
883 nv = p ? p->pos+1 : 0;
886 if (tok->type == '(') {
887 stream_push_token(s, tok);
888 e = evalue_read_term(s, &p);
889 *ppp = extract_parameters(p, nparam);
890 } else if (tok->type == TOKEN_VALUE) {
891 struct token *tok2 = stream_next_token(s);
892 if (tok2)
893 stream_push_token(s, tok2);
894 stream_push_token(s, tok);
895 if (tok2 && (tok2->type == TOKEN_IDENT || tok2->type == TOKEN_GE))
896 e = evalue_read_partition(s, p, ppp, nparam, MaxRays);
897 else {
898 e = evalue_read_term(s, &p);
899 *ppp = extract_parameters(p, nparam);
901 } else if (tok->type == TOKEN_IDENT) {
902 stream_push_token(s, tok);
903 e = evalue_read_partition(s, p, ppp, nparam, MaxRays);
904 } else {
905 stream_error(s, tok, "unexpected token");
906 *nparam = nv == -1 ? 0 : nv;
907 e = NULL;
909 if (nv == -1)
910 *nvar = *nparam;
911 else
912 *nvar = nv;
913 *nparam -= *nvar;
914 return e;
917 evalue *evalue_read_from_file(FILE *in, const char *var_list, char ***ppp,
918 unsigned *nvar, unsigned *nparam, unsigned MaxRays)
920 evalue *e;
921 struct stream *s = stream_new_file(in);
922 e = evalue_read(s, var_list, ppp, nvar, nparam, MaxRays);
923 stream_free(s);
924 return e;
927 evalue *evalue_read_from_str(const char *str, const char *var_list, char ***ppp,
928 unsigned *nvar, unsigned *nparam, unsigned MaxRays)
930 evalue *e;
931 struct stream *s = stream_new_str(str);
932 e = evalue_read(s, var_list, ppp, nvar, nparam, MaxRays);
933 stream_free(s);
934 return e;