Deleted Added
full compact
tran.c (172959) tran.c (224731)
1/****************************************************************
2Copyright (C) Lucent Technologies 1997
3All Rights Reserved
4
5Permission to use, copy, modify, and distribute this software and
6its documentation for any purpose and without fee is hereby
7granted, provided that the above copyright notice appear in all
8copies and that both that the copyright notice and this

--- 198 unchanged lines hidden (view full) ---

207
208Cell *setsymtab(const char *n, const char *s, Awkfloat f, unsigned t, Array *tp)
209{
210 int h;
211 Cell *p;
212
213 if (n != NULL && (p = lookup(n, tp)) != NULL) {
214 dprintf( ("setsymtab found %p: n=%s s=\"%s\" f=%g t=%o\n",
1/****************************************************************
2Copyright (C) Lucent Technologies 1997
3All Rights Reserved
4
5Permission to use, copy, modify, and distribute this software and
6its documentation for any purpose and without fee is hereby
7granted, provided that the above copyright notice appear in all
8copies and that both that the copyright notice and this

--- 198 unchanged lines hidden (view full) ---

207
208Cell *setsymtab(const char *n, const char *s, Awkfloat f, unsigned t, Array *tp)
209{
210 int h;
211 Cell *p;
212
213 if (n != NULL && (p = lookup(n, tp)) != NULL) {
214 dprintf( ("setsymtab found %p: n=%s s=\"%s\" f=%g t=%o\n",
215 p, NN(p->nval), NN(p->sval), p->fval, p->tval) );
215 (void*)p, NN(p->nval), NN(p->sval), p->fval, p->tval) );
216 return(p);
217 }
218 p = (Cell *) malloc(sizeof(Cell));
219 if (p == NULL)
220 FATAL("out of space for symbol table at %s", n);
221 p->nval = tostring(n);
222 p->sval = s ? tostring(s) : tostring("");
223 p->fval = f;
224 p->tval = t;
225 p->csub = CUNK;
226 p->ctype = OCELL;
227 tp->nelem++;
228 if (tp->nelem > FULLTAB * tp->size)
229 rehash(tp);
230 h = hash(n, tp->size);
231 p->cnext = tp->tab[h];
232 tp->tab[h] = p;
233 dprintf( ("setsymtab set %p: n=%s s=\"%s\" f=%g t=%o\n",
216 return(p);
217 }
218 p = (Cell *) malloc(sizeof(Cell));
219 if (p == NULL)
220 FATAL("out of space for symbol table at %s", n);
221 p->nval = tostring(n);
222 p->sval = s ? tostring(s) : tostring("");
223 p->fval = f;
224 p->tval = t;
225 p->csub = CUNK;
226 p->ctype = OCELL;
227 tp->nelem++;
228 if (tp->nelem > FULLTAB * tp->size)
229 rehash(tp);
230 h = hash(n, tp->size);
231 p->cnext = tp->tab[h];
232 tp->tab[h] = p;
233 dprintf( ("setsymtab set %p: n=%s s=\"%s\" f=%g t=%o\n",
234 p, p->nval, p->sval, p->fval, p->tval) );
234 (void*)p, p->nval, p->sval, p->fval, p->tval) );
235 return(p);
236}
237
238int hash(const char *s, int n) /* form hash value for string s */
239{
240 unsigned hashval;
241
242 for (hashval = 0; *s != '\0'; s++)

--- 50 unchanged lines hidden (view full) ---

293 } else if (isrec(vp)) {
294 donefld = 0; /* mark $1... invalid */
295 donerec = 1;
296 }
297 if (freeable(vp))
298 xfree(vp->sval); /* free any previous string */
299 vp->tval &= ~STR; /* mark string invalid */
300 vp->tval |= NUM; /* mark number ok */
235 return(p);
236}
237
238int hash(const char *s, int n) /* form hash value for string s */
239{
240 unsigned hashval;
241
242 for (hashval = 0; *s != '\0'; s++)

--- 50 unchanged lines hidden (view full) ---

293 } else if (isrec(vp)) {
294 donefld = 0; /* mark $1... invalid */
295 donerec = 1;
296 }
297 if (freeable(vp))
298 xfree(vp->sval); /* free any previous string */
299 vp->tval &= ~STR; /* mark string invalid */
300 vp->tval |= NUM; /* mark number ok */
301 dprintf( ("setfval %p: %s = %g, t=%o\n", vp, NN(vp->nval), f, vp->tval) );
301 dprintf( ("setfval %p: %s = %g, t=%o\n", (void*)vp, NN(vp->nval), f, vp->tval) );
302 return vp->fval = f;
303}
304
305void funnyvar(Cell *vp, const char *rw)
306{
307 if (isarr(vp))
308 FATAL("can't %s %s; it's an array name.", rw, vp->nval);
309 if (vp->tval & FCN)
310 FATAL("can't %s %s; it's a function.", rw, vp->nval);
311 WARNING("funny variable %p: n=%s s=\"%s\" f=%g t=%o",
312 vp, vp->nval, vp->sval, vp->fval, vp->tval);
313}
314
315char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
316{
317 char *t;
318 int fldno;
319
320 dprintf( ("starting setsval %p: %s = \"%s\", t=%o, r,f=%d,%d\n",
302 return vp->fval = f;
303}
304
305void funnyvar(Cell *vp, const char *rw)
306{
307 if (isarr(vp))
308 FATAL("can't %s %s; it's an array name.", rw, vp->nval);
309 if (vp->tval & FCN)
310 FATAL("can't %s %s; it's a function.", rw, vp->nval);
311 WARNING("funny variable %p: n=%s s=\"%s\" f=%g t=%o",
312 vp, vp->nval, vp->sval, vp->fval, vp->tval);
313}
314
315char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
316{
317 char *t;
318 int fldno;
319
320 dprintf( ("starting setsval %p: %s = \"%s\", t=%o, r,f=%d,%d\n",
321 vp, NN(vp->nval), s, vp->tval, donerec, donefld) );
321 (void*)vp, NN(vp->nval), s, vp->tval, donerec, donefld) );
322 if ((vp->tval & (NUM | STR)) == 0)
323 funnyvar(vp, "assign to");
324 if (isfld(vp)) {
325 donerec = 0; /* mark $0 invalid */
326 fldno = atoi(vp->nval);
327 if (fldno > *NF)
328 newfld(fldno);
329 dprintf( ("setting field %d to %s (%p)\n", fldno, s, s) );
330 } else if (isrec(vp)) {
331 donefld = 0; /* mark $1... invalid */
332 donerec = 1;
333 }
334 t = tostring(s); /* in case it's self-assign */
335 if (freeable(vp))
336 xfree(vp->sval);
337 vp->tval &= ~NUM;
338 vp->tval |= STR;
339 vp->tval &= ~DONTFREE;
340 dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n",
322 if ((vp->tval & (NUM | STR)) == 0)
323 funnyvar(vp, "assign to");
324 if (isfld(vp)) {
325 donerec = 0; /* mark $0 invalid */
326 fldno = atoi(vp->nval);
327 if (fldno > *NF)
328 newfld(fldno);
329 dprintf( ("setting field %d to %s (%p)\n", fldno, s, s) );
330 } else if (isrec(vp)) {
331 donefld = 0; /* mark $1... invalid */
332 donerec = 1;
333 }
334 t = tostring(s); /* in case it's self-assign */
335 if (freeable(vp))
336 xfree(vp->sval);
337 vp->tval &= ~NUM;
338 vp->tval |= STR;
339 vp->tval &= ~DONTFREE;
340 dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n",
341 vp, NN(vp->nval), t,t, vp->tval, donerec, donefld) );
341 (void*)vp, NN(vp->nval), t,t, vp->tval, donerec, donefld) );
342 return(vp->sval = t);
343}
344
345Awkfloat getfval(Cell *vp) /* get float val of a Cell */
346{
347 if ((vp->tval & (NUM | STR)) == 0)
348 funnyvar(vp, "read value of");
349 if (isfld(vp) && donefld == 0)
350 fldbld();
351 else if (isrec(vp) && donerec == 0)
352 recbld();
353 if (!isnum(vp)) { /* not a number */
354 vp->fval = atof(vp->sval); /* best guess */
355 if (is_number(vp->sval) && !(vp->tval&CON))
356 vp->tval |= NUM; /* make NUM only sparingly */
357 }
342 return(vp->sval = t);
343}
344
345Awkfloat getfval(Cell *vp) /* get float val of a Cell */
346{
347 if ((vp->tval & (NUM | STR)) == 0)
348 funnyvar(vp, "read value of");
349 if (isfld(vp) && donefld == 0)
350 fldbld();
351 else if (isrec(vp) && donerec == 0)
352 recbld();
353 if (!isnum(vp)) { /* not a number */
354 vp->fval = atof(vp->sval); /* best guess */
355 if (is_number(vp->sval) && !(vp->tval&CON))
356 vp->tval |= NUM; /* make NUM only sparingly */
357 }
358 dprintf( ("getfval %p: %s = %g, t=%o\n", vp, NN(vp->nval), vp->fval, vp->tval) );
358 dprintf( ("getfval %p: %s = %g, t=%o\n",
359 (void*)vp, NN(vp->nval), vp->fval, vp->tval) );
359 return(vp->fval);
360}
361
362static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cell */
363{
364 char s[100]; /* BUG: unchecked */
365 double dtemp;
366

--- 9 unchanged lines hidden (view full) ---

376 if (modf(vp->fval, &dtemp) == 0) /* it's integral */
377 sprintf(s, "%.30g", vp->fval);
378 else
379 sprintf(s, *fmt, vp->fval);
380 vp->sval = tostring(s);
381 vp->tval &= ~DONTFREE;
382 vp->tval |= STR;
383 }
360 return(vp->fval);
361}
362
363static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cell */
364{
365 char s[100]; /* BUG: unchecked */
366 double dtemp;
367

--- 9 unchanged lines hidden (view full) ---

377 if (modf(vp->fval, &dtemp) == 0) /* it's integral */
378 sprintf(s, "%.30g", vp->fval);
379 else
380 sprintf(s, *fmt, vp->fval);
381 vp->sval = tostring(s);
382 vp->tval &= ~DONTFREE;
383 vp->tval |= STR;
384 }
384 dprintf( ("getsval %p: %s = \"%s (%p)\", t=%o\n", vp, NN(vp->nval), vp->sval, vp->sval, vp->tval) );
385 dprintf( ("getsval %p: %s = \"%s (%p)\", t=%o\n",
386 (void*)vp, NN(vp->nval), vp->sval, vp->sval, vp->tval) );
385 return(vp->sval);
386}
387
388char *getsval(Cell *vp) /* get string val of a Cell */
389{
390 return get_str_val(vp, CONVFMT);
391}
392

--- 63 unchanged lines hidden ---
387 return(vp->sval);
388}
389
390char *getsval(Cell *vp) /* get string val of a Cell */
391{
392 return get_str_val(vp, CONVFMT);
393}
394

--- 63 unchanged lines hidden ---