Deleted Added
full compact
run.c (201989) run.c (221381)
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

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

18SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
20IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
22THIS SOFTWARE.
23****************************************************************/
24
25#include <sys/cdefs.h>
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

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

18SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
20IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
22THIS SOFTWARE.
23****************************************************************/
24
25#include <sys/cdefs.h>
26__FBSDID("$FreeBSD: head/contrib/one-true-awk/run.c 201989 2010-01-10 08:02:07Z ru $");
26__FBSDID("$FreeBSD: head/contrib/one-true-awk/run.c 221381 2011-05-03 11:47:19Z ru $");
27
28#define DEBUG
29#include <stdio.h>
30#include <ctype.h>
31#include <setjmp.h>
32#include <limits.h>
33#include <math.h>
34#include <string.h>

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

64/* #endif */
65/* */
66/* #ifndef RAND_MAX */
67/* #define RAND_MAX 32767 */ /* all that ansi guarantees */
68/* #endif */
69
70jmp_buf env;
71extern int pairstack[];
27
28#define DEBUG
29#include <stdio.h>
30#include <ctype.h>
31#include <setjmp.h>
32#include <limits.h>
33#include <math.h>
34#include <string.h>

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

64/* #endif */
65/* */
66/* #ifndef RAND_MAX */
67/* #define RAND_MAX 32767 */ /* all that ansi guarantees */
68/* #endif */
69
70jmp_buf env;
71extern int pairstack[];
72extern Awkfloat srand_seed;
72
73Node *winner = NULL; /* root of parse tree */
74Cell *tmps; /* free temporary cells for execution */
75
76static Cell truecell ={ OBOOL, BTRUE, 0, 0, 1.0, NUM };
77Cell *True = &truecell;
78static Cell falsecell ={ OBOOL, BFALSE, 0, 0, 0.0, NUM };
79Cell *False = &falsecell;

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

1464 return True;
1465}
1466
1467Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg list */
1468{
1469 Cell *x, *y;
1470 Awkfloat u;
1471 int t;
73
74Node *winner = NULL; /* root of parse tree */
75Cell *tmps; /* free temporary cells for execution */
76
77static Cell truecell ={ OBOOL, BTRUE, 0, 0, 1.0, NUM };
78Cell *True = &truecell;
79static Cell falsecell ={ OBOOL, BFALSE, 0, 0, 0.0, NUM };
80Cell *False = &falsecell;

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

1465 return True;
1466}
1467
1468Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg list */
1469{
1470 Cell *x, *y;
1471 Awkfloat u;
1472 int t;
1473 Awkfloat tmp;
1472 char *p, *buf;
1473 Node *nextarg;
1474 FILE *fp;
1475 void flush_all(void);
1476
1477 t = ptoi(a[0]);
1478 x = execute(a[1]);
1479 nextarg = a[1]->nnext;

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

1515 /* in principle, rand() returns something in 0..RAND_MAX */
1516 u = (Awkfloat) (rand() % RAND_MAX) / RAND_MAX;
1517 break;
1518 case FSRAND:
1519 if (isrec(x)) /* no argument provided */
1520 u = time((time_t *)0);
1521 else
1522 u = getfval(x);
1474 char *p, *buf;
1475 Node *nextarg;
1476 FILE *fp;
1477 void flush_all(void);
1478
1479 t = ptoi(a[0]);
1480 x = execute(a[1]);
1481 nextarg = a[1]->nnext;

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

1517 /* in principle, rand() returns something in 0..RAND_MAX */
1518 u = (Awkfloat) (rand() % RAND_MAX) / RAND_MAX;
1519 break;
1520 case FSRAND:
1521 if (isrec(x)) /* no argument provided */
1522 u = time((time_t *)0);
1523 else
1524 u = getfval(x);
1525 tmp = u;
1523 srand((unsigned int) u);
1526 srand((unsigned int) u);
1527 u = srand_seed;
1528 srand_seed = tmp;
1524 break;
1525 case FTOUPPER:
1526 case FTOLOWER:
1527 buf = tostring(getsval(x));
1528 if (t == FTOUPPER) {
1529 for (p = buf; *p; p++)
1530 if (islower((uschar) *p))
1531 *p = toupper((uschar)*p);

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

1885 FATAL("gsub result1 %.30s too big; can't happen", buf);
1886 mflag = 1;
1887 }
1888 } while (pmatch(pfa,t));
1889 sptr = t;
1890 adjbuf(&buf, &bufsz, 1+strlen(sptr)+pb-buf, 0, &pb, "gsub");
1891 while ((*pb++ = *sptr++) != 0)
1892 ;
1529 break;
1530 case FTOUPPER:
1531 case FTOLOWER:
1532 buf = tostring(getsval(x));
1533 if (t == FTOUPPER) {
1534 for (p = buf; *p; p++)
1535 if (islower((uschar) *p))
1536 *p = toupper((uschar)*p);

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

1890 FATAL("gsub result1 %.30s too big; can't happen", buf);
1891 mflag = 1;
1892 }
1893 } while (pmatch(pfa,t));
1894 sptr = t;
1895 adjbuf(&buf, &bufsz, 1+strlen(sptr)+pb-buf, 0, &pb, "gsub");
1896 while ((*pb++ = *sptr++) != 0)
1897 ;
1893 done: if (pb > buf + bufsz)
1894 FATAL("gsub result2 %.30s too big; can't happen", buf);
1895 *pb = '\0';
1898 done: if (pb < buf + bufsz)
1899 *pb = '\0';
1900 else if (*(pb-1) != '\0')
1901 FATAL("gsub result2 %.30s truncated; can't happen", buf);
1896 setsval(x, buf); /* BUG: should be able to avoid copy + free */
1897 pfa->initstat = tempstat;
1898 }
1899 tempfree(x);
1900 tempfree(y);
1901 x = gettemp();
1902 x->tval = NUM;
1903 x->fval = num;

--- 29 unchanged lines hidden ---
1902 setsval(x, buf); /* BUG: should be able to avoid copy + free */
1903 pfa->initstat = tempstat;
1904 }
1905 tempfree(x);
1906 tempfree(y);
1907 x = gettemp();
1908 x->tval = NUM;
1909 x->fval = num;

--- 29 unchanged lines hidden ---