2004-03-03 21:24:06 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Scan expr for vars, return in vector
|
|
|
|
//
|
|
|
|
// Input: Expression on stack
|
|
|
|
//
|
|
|
|
// Output: Vector
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
#include "stdafx.h"
|
2004-03-03 21:24:06 +01:00
|
|
|
#include "defs.h"
|
2005-08-06 22:57:37 +02:00
|
|
|
static void scan(U *);
|
2004-03-03 21:24:06 +01:00
|
|
|
static int __cmp(const void *, const void *);
|
|
|
|
static int h;
|
|
|
|
|
|
|
|
void
|
|
|
|
variables(void)
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
save();
|
|
|
|
p1 = pop();
|
|
|
|
h = tos;
|
2005-08-06 22:57:37 +02:00
|
|
|
scan(p1);
|
2004-03-03 21:24:06 +01:00
|
|
|
n = tos - h;
|
|
|
|
if (n > 1)
|
|
|
|
qsort(stack + h, n, sizeof (U *), __cmp);
|
|
|
|
p1 = alloc_tensor(n);
|
|
|
|
p1->u.tensor->ndim = 1;
|
|
|
|
p1->u.tensor->dim[0] = n;
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
p1->u.tensor->elem[i] = stack[i];
|
|
|
|
tos = h;
|
|
|
|
push(p1);
|
|
|
|
restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-08-06 22:57:37 +02:00
|
|
|
scan(U *p)
|
2004-03-03 21:24:06 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (iscons(p)) {
|
2005-08-06 22:57:37 +02:00
|
|
|
p = cdr(p);
|
2004-03-03 21:24:06 +01:00
|
|
|
while (iscons(p)) {
|
2005-08-06 22:57:37 +02:00
|
|
|
scan(car(p));
|
2004-03-03 21:24:06 +01:00
|
|
|
p = cdr(p);
|
|
|
|
}
|
|
|
|
} else if (issymbol(p) && p != symbol(E)) {
|
|
|
|
for (i = h; i < tos; i++)
|
|
|
|
if (stack[i] == p)
|
|
|
|
return;
|
|
|
|
push(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
__cmp(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
return cmp_expr(*((U **) p1), *((U **) p2));
|
|
|
|
}
|