Deleted Added
full compact
tran.c (107806) tran.c (146299)
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

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

46Awkfloat *NR; /* number of current record */
47Awkfloat *FNR; /* number of current record in current file */
48char **FILENAME; /* current filename argument */
49Awkfloat *ARGC; /* number of arguments from command line */
50char **SUBSEP; /* subscript separator for a[i,j,k]; default \034 */
51Awkfloat *RSTART; /* start of re matched with ~; origin 1 (!) */
52Awkfloat *RLENGTH; /* length of same */
53
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

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

46Awkfloat *NR; /* number of current record */
47Awkfloat *FNR; /* number of current record in current file */
48char **FILENAME; /* current filename argument */
49Awkfloat *ARGC; /* number of arguments from command line */
50char **SUBSEP; /* subscript separator for a[i,j,k]; default \034 */
51Awkfloat *RSTART; /* start of re matched with ~; origin 1 (!) */
52Awkfloat *RLENGTH; /* length of same */
53
54Cell *fsloc; /* FS */
54Cell *nrloc; /* NR */
55Cell *nfloc; /* NF */
56Cell *fnrloc; /* FNR */
57Array *ARGVtab; /* symbol table containing ARGV[...] */
58Array *ENVtab; /* symbol table containing ENVIRON[...] */
59Cell *rstartloc; /* RSTART */
60Cell *rlengthloc; /* RLENGTH */
61Cell *symtabloc; /* SYMTAB */

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

68
69void syminit(void) /* initialize symbol table with builtin vars */
70{
71 literal0 = setsymtab("0", "0", 0.0, NUM|STR|CON|DONTFREE, symtab);
72 /* this is used for if(x)... tests: */
73 nullloc = setsymtab("$zero&null", "", 0.0, NUM|STR|CON|DONTFREE, symtab);
74 nullnode = celltonode(nullloc, CCON);
75
55Cell *nrloc; /* NR */
56Cell *nfloc; /* NF */
57Cell *fnrloc; /* FNR */
58Array *ARGVtab; /* symbol table containing ARGV[...] */
59Array *ENVtab; /* symbol table containing ENVIRON[...] */
60Cell *rstartloc; /* RSTART */
61Cell *rlengthloc; /* RLENGTH */
62Cell *symtabloc; /* SYMTAB */

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

69
70void syminit(void) /* initialize symbol table with builtin vars */
71{
72 literal0 = setsymtab("0", "0", 0.0, NUM|STR|CON|DONTFREE, symtab);
73 /* this is used for if(x)... tests: */
74 nullloc = setsymtab("$zero&null", "", 0.0, NUM|STR|CON|DONTFREE, symtab);
75 nullnode = celltonode(nullloc, CCON);
76
76 FS = &setsymtab("FS", " ", 0.0, STR|DONTFREE, symtab)->sval;
77 fsloc = setsymtab("FS", " ", 0.0, STR|DONTFREE, symtab);
78 FS = &fsloc->sval;
77 RS = &setsymtab("RS", "\n", 0.0, STR|DONTFREE, symtab)->sval;
78 OFS = &setsymtab("OFS", " ", 0.0, STR|DONTFREE, symtab)->sval;
79 ORS = &setsymtab("ORS", "\n", 0.0, STR|DONTFREE, symtab)->sval;
80 OFMT = &setsymtab("OFMT", "%.6g", 0.0, STR|DONTFREE, symtab)->sval;
81 CONVFMT = &setsymtab("CONVFMT", "%.6g", 0.0, STR|DONTFREE, symtab)->sval;
82 FILENAME = &setsymtab("FILENAME", "", 0.0, STR|DONTFREE, symtab)->sval;
83 nfloc = setsymtab("NF", "", 0.0, NUM, symtab);
84 NF = &nfloc->fval;

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

310 vp, vp->nval, vp->sval, vp->fval, vp->tval);
311}
312
313char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
314{
315 char *t;
316 int fldno;
317
79 RS = &setsymtab("RS", "\n", 0.0, STR|DONTFREE, symtab)->sval;
80 OFS = &setsymtab("OFS", " ", 0.0, STR|DONTFREE, symtab)->sval;
81 ORS = &setsymtab("ORS", "\n", 0.0, STR|DONTFREE, symtab)->sval;
82 OFMT = &setsymtab("OFMT", "%.6g", 0.0, STR|DONTFREE, symtab)->sval;
83 CONVFMT = &setsymtab("CONVFMT", "%.6g", 0.0, STR|DONTFREE, symtab)->sval;
84 FILENAME = &setsymtab("FILENAME", "", 0.0, STR|DONTFREE, symtab)->sval;
85 nfloc = setsymtab("NF", "", 0.0, NUM, symtab);
86 NF = &nfloc->fval;

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

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
318 dprintf( ("starting setsval %p: %s = \"%s\", t=%o\n", vp, NN(vp->nval), s, vp->tval) );
320 dprintf( ("starting setsval %p: %s = \"%s\", t=%o, r,f=%d,%d\n",
321 vp, NN(vp->nval), s, vp->tval, donerec, donefld) );
319 if ((vp->tval & (NUM | STR)) == 0)
320 funnyvar(vp, "assign to");
321 if (isfld(vp)) {
322 donerec = 0; /* mark $0 invalid */
323 fldno = atoi(vp->nval);
324 if (fldno > *NF)
325 newfld(fldno);
326 dprintf( ("setting field %d to %s (%p)\n", fldno, s, s) );
327 } else if (isrec(vp)) {
328 donefld = 0; /* mark $1... invalid */
329 donerec = 1;
330 }
331 t = tostring(s); /* in case it's self-assign */
332 vp->tval &= ~NUM;
333 vp->tval |= STR;
334 if (freeable(vp))
335 xfree(vp->sval);
336 vp->tval &= ~DONTFREE;
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 vp->tval &= ~NUM;
336 vp->tval |= STR;
337 if (freeable(vp))
338 xfree(vp->sval);
339 vp->tval &= ~DONTFREE;
337 dprintf( ("setsval %p: %s = \"%s (%p)\", t=%o\n", vp, NN(vp->nval), t,t, vp->tval) );
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) );
338 return(vp->sval = t);
339}
340
341Awkfloat getfval(Cell *vp) /* get float val of a Cell */
342{
343 if ((vp->tval & (NUM | STR)) == 0)
344 funnyvar(vp, "read value of");
345 if (isfld(vp) && donefld == 0)

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

350 vp->fval = atof(vp->sval); /* best guess */
351 if (is_number(vp->sval) && !(vp->tval&CON))
352 vp->tval |= NUM; /* make NUM only sparingly */
353 }
354 dprintf( ("getfval %p: %s = %g, t=%o\n", vp, NN(vp->nval), vp->fval, vp->tval) );
355 return(vp->fval);
356}
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)

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

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) );
359 return(vp->fval);
360}
361
358 static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cell */
359
362static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cell */
360{
361 char s[100]; /* BUG: unchecked */
362 double dtemp;
363
364 if ((vp->tval & (NUM | STR)) == 0)
365 funnyvar(vp, "read value of");
366 if (isfld(vp) && donefld == 0)
367 fldbld();

--- 85 unchanged lines hidden ---
363{
364 char s[100]; /* BUG: unchecked */
365 double dtemp;
366
367 if ((vp->tval & (NUM | STR)) == 0)
368 funnyvar(vp, "read value of");
369 if (isfld(vp) && donefld == 0)
370 fldbld();

--- 85 unchanged lines hidden ---