transargv.c
Go to the documentation of this file.
1 /*
2  Arguments converter for C programming of EUSLISP
3  By M.Inaba
4  */
5 #include "../c/eus.h"
6 #include "euslocal.h"
7 #define TRUE 1
8 #define NULL 0
9 #define is_view_num(v) \
10  (isnum(v)|| isstring(v) || ((v)== T) || ((v) == NIL))
11 
13  pointer v;
14 {
15  if (isint(v)) return(intval(v));
16  else if (isflt(v)) return(fltval(v));
17  else if (isstring(v)) return((int)(v->c.str.chars));
18  else if (T == v) return(TRUE);
19  else if (NIL == v) return(NULL);
20  else error(E_NONUMBER);
21 }
22 float cknumtoflt(v)
23  pointer v;
24 {
25  if (isint(v)) return((float)intval(v));
26  else if (isflt(v)) return(fltval(v));
27  else error(E_NONUMBER);
28 }
29 
31  long v;
32 {
33  if (v) return(T);
34  else return(NIL);
35 }
36 
38  register long v;
39 {
40  pointer b;
41  int w;
42  w = -v;
43  if ((v > 0) && (v > 0x1fffffff)) {
44  b = makevector(C_INTVECTOR,1);
45  b -> c.ivec.iv[0] = v;
46  }
47  else if ((w > 0) && (w > 0x1fffffff)) {
48  b = makevector(C_INTVECTOR,1);
49  b -> c.ivec.iv[0] = v;
50  }
51  else b = makeint(v);
52  return(b);
53 }
54 
55 
56 static int argc;
57 static float *fargv;
58 static int *iargv;
59 
60 trans_argv_iargv(n,argv,main_iargv)
61  register int n;
62  register pointer argv[];
63  register int main_iargv[];
64 {
65  iargv = main_iargv;
66  argc = 0;
67  while (n-- >0) trans_argv_iargv_aux(*argv++);
68  return(argc);
69 }
71  register pointer a;
72 {
73  register int j,size;
74  if (is_view_num(a)) { *iargv++ = cknumtoint(a); argc++;}
75  else if (T == a) { *iargv++ = TRUE; argc++; }
76  else if (NIL == a) { *iargv++ = NULL; argc++; }
77  else if (isfltvector(a)) {
78  size=vecsize(a); argc+= size;
79  for (j=0; j<size; j++) *iargv++ = (int)a->c.fvec.fv[j];
80  }
81  else if (isintvector(a)) {
82  size=vecsize(a); argc+= size;
83  for (j=0; j<size; j++) *iargv++ = (int)a->c.ivec.iv[j];
84  }
85  else if (isarray(a)) {
86  trans_argv_iargv_aux(a->c.ary.entity);
87  }
88  else if (isvector(a)) {
89  size=vecsize(a);
90  for (j=0; j<size; j++) trans_argv_iargv_aux(a->c.vec.v[j]);
91  }
92  else if (islist(a)) {
93  while (islist(a)) {
94  trans_argv_iargv_aux(ccar(a));
95  a=ccdr(a);}
96  }
97  else error(E_NOINT);
98 }
99 
100 trans_argv_fargv(n,argv,main_fargv)
101  register int n;
102  register pointer argv[];
103  register float main_fargv[];
104 {
105  fargv = main_fargv;
106  argc = 0;
107  while (n-- >0) trans_argv_fargv_aux(*argv++);
108  return(argc);
109 }
111  register pointer a;
112 {
113  register int j,size;
114  if (is_view_num(a)) {
115  *fargv++ = (float)cknumtoflt(a); argc++;
116  }
117  else if (isfltvector(a)) {
118  size=vecsize(a); argc += size;
119  for (j=0; j<size; j++) *fargv++ = a->c.fvec.fv[j];
120  }
121  else if (isintvector(a)) {
122  size=vecsize(a); argc+= size;
123  for (j=0; j<size; j++) *fargv++ = (float)a->c.ivec.iv[j];
124  }
125  else if (isarray(a)) {
126  trans_argv_fargv_aux(a->c.ary.entity);
127  }
128  else if (isvector(a)) {
129  size=vecsize(a);
130  for (j=0; j<size; j++) trans_argv_fargv_aux(a->c.vec.v[j]);
131  }
132  else if (islist(a)) {
133  while (islist(a)) {
134  trans_argv_fargv_aux(ccar(a));
135  a=ccdr(a);
136  }
137  }
138  else error(E_NONUMBER);
139 }
140 
141 trans_argv_farrayargv(n,argv,dimension,farrayargv)
142  register int n;
143  register pointer *argv;
144  register float *farrayargv;
145  register int dimension;
146 {
147  register float fargv[3*256];
148  register int i,j,size,rem;
149  size=trans_argv_fargv(n,argv,fargv);
150  /*
151  printf("size=%d,dim=%d,amari=%d\n",size,dimension,size%dimension);
152  */
153  if ((size % dimension) != 0) error(E_MISMATCHARG);
154  size /= dimension;
155  for (j=0; j<dimension; j++) {
156  for (i=0; i<size; i++)
157  *farrayargv++ = fargv[i*dimension + j];
158  }
159  return(size);
160 }
161 
162 largv2cargv(n,argv,cargv,from,to)
163  register int n;
164  register pointer argv[];
165  register long cargv[];
166  int from,to;
167 {
168  register int i,cargc=0;
169  register pointer l;
170  cargc = trans_argv_iargv(n,argv,cargv);
171  if ((cargc<from) || (cargc>to)) error(E_MISMATCHARG);
172  return(cargc);
173 }
#define makeint(v)
Definition: sfttest.c:2
largv2cargv(int n, argv, cargv, int from, int to)
Definition: transargv.c:162
pointer T
Definition: eus.c:110
pointer makebnum(long v)
Definition: transargv.c:37
GLfloat n[6][3]
Definition: cube.c:15
static int argc
Definition: transargv.c:56
trans_argv_iargv(int n, argv, main_iargv)
Definition: transargv.c:60
#define intval(p)
Definition: sfttest.c:1
static float * fargv
Definition: transargv.c:57
static int * iargv
Definition: transargv.c:58
cknumtoint(pointer v)
Definition: transargv.c:12
pointer makevector(pointer, int)
Definition: makes.c:417
trans_argv_iargv_aux(pointer a)
Definition: transargv.c:70
trans_argv_fargv_aux(pointer a)
Definition: transargv.c:110
long l
Definition: structsize.c:3
trans_argv_fargv(int n, argv, main_fargv)
Definition: transargv.c:100
Definition: eus.h:379
#define is_view_num(v)
Definition: transargv.c:9
#define TRUE
Definition: transargv.c:7
trans_argv_farrayargv(int n, pointer *argv, int dimension, float *farrayargv)
Definition: transargv.c:141
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
Definition: eus.c:297
float fltval()
#define NULL
Definition: transargv.c:8
pointer C_INTVECTOR
Definition: eus.c:146
GLfloat v[8][3]
Definition: cube.c:21
float cknumtoflt(pointer v)
Definition: transargv.c:22
pointer makebool(long v)
Definition: transargv.c:30
pointer NIL
Definition: eus.c:110
Definition: eus.h:952
char a[26]
Definition: freq.c:4


euslisp
Author(s): Toshihiro Matsui
autogenerated on Fri Feb 21 2020 03:20:54