=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/awk/run.c,v retrieving revision 1.32 retrieving revision 1.33 diff -c -r1.32 -r1.33 *** src/usr.bin/awk/run.c 2011/04/20 22:28:39 1.32 --- src/usr.bin/awk/run.c 2011/09/28 19:27:18 1.33 *************** *** 1,4 **** ! /* $OpenBSD: run.c,v 1.32 2011/04/20 22:28:39 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved --- 1,4 ---- ! /* $OpenBSD: run.c,v 1.33 2011/09/28 19:27:18 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved *************** *** 68,73 **** --- 68,74 ---- jmp_buf env; int use_arc4 = 1; extern int pairstack[]; + extern Awkfloat srand_seed; Node *winner = NULL; /* root of parse tree */ Cell *tmps; /* free temporary cells for execution */ *************** *** 1243,1248 **** --- 1244,1255 ---- ap->sval = (char *) makesymtab(NSYMTAB); n = 0; + if (arg3type == REGEXPR && strlen((char*)((fa*)a[2])->restr) == 0) { + /* split(s, a, //); have to arrange that it looks like empty sep */ + arg3type = 0; + fs = ""; + sep = 0; + } if (*s != '\0' && (strlen(fs) > 1 || arg3type == REGEXPR)) { /* reg expr */ fa *pfa; if (arg3type == REGEXPR) { /* it's ready already */ *************** *** 1474,1483 **** Cell *x, *y; Awkfloat u; int t; char *p, *buf; Node *nextarg; FILE *fp; - static Awkfloat old_seed = 1; t = ptoi(a[0]); x = execute(a[1]); --- 1481,1490 ---- Cell *x, *y; Awkfloat u; int t; + Awkfloat tmp; char *p, *buf; Node *nextarg; FILE *fp; t = ptoi(a[0]); x = execute(a[1]); *************** *** 1581,1593 **** u = (Awkfloat) (random() % RAND_MAX) / RAND_MAX; break; case FSRAND: - u = old_seed; if (isrec(x)) /* no argument provided, want arc4random() */ use_arc4 = 1; else { - old_seed = getfval(x); - srandom((unsigned int) old_seed); use_arc4 = 0; } break; case FTOUPPER: --- 1588,1602 ---- u = (Awkfloat) (random() % RAND_MAX) / RAND_MAX; break; case FSRAND: if (isrec(x)) /* no argument provided, want arc4random() */ use_arc4 = 1; else { use_arc4 = 0; + u = getfval(x); + tmp = u; + srandom((unsigned int) u); + u = srand_seed; + srand_seed = tmp; } break; case FTOUPPER: *************** *** 1684,1700 **** FILE *fp; const char *fname; int mode; /* '|', 'a', 'w' => LE/LT, GT */ ! } files[FOPEN_MAX] ={ ! { NULL, "/dev/stdin", LT }, /* watch out: don't free this! */ ! { NULL, "/dev/stdout", GT }, ! { NULL, "/dev/stderr", GT } ! }; void stdinit(void) /* in case stdin, etc., are not constants */ { ! files[0].fp = stdin; ! files[1].fp = stdout; ! files[2].fp = stderr; } FILE *openfile(int a, const char *us) --- 1693,1717 ---- FILE *fp; const char *fname; int mode; /* '|', 'a', 'w' => LE/LT, GT */ ! } *files; + int nfiles; + void stdinit(void) /* in case stdin, etc., are not constants */ { ! nfiles = FOPEN_MAX; ! files = calloc(nfiles, sizeof(*files)); ! if (files == NULL) ! FATAL("can't allocate file memory for %u files", nfiles); ! files[0].fp = stdin; ! files[0].fname = "/dev/stdin"; ! files[0].mode = LT; ! files[1].fp = stdout; ! files[1].fname = "/dev/stdout"; ! files[1].mode = GT; ! files[2].fp = stderr; ! files[2].fname = "/dev/stderr"; ! files[2].mode = GT; } FILE *openfile(int a, const char *us) *************** *** 1705,1711 **** if (*s == '\0') FATAL("null file name in print or getline"); ! for (i=0; i < FOPEN_MAX; i++) if (files[i].fname && strcmp(s, files[i].fname) == 0) { if (a == files[i].mode || (a==APPEND && files[i].mode==GT)) return files[i].fp; --- 1722,1728 ---- if (*s == '\0') FATAL("null file name in print or getline"); ! for (i=0; i < nfiles; i++) if (files[i].fname && strcmp(s, files[i].fname) == 0) { if (a == files[i].mode || (a==APPEND && files[i].mode==GT)) return files[i].fp; *************** *** 1715,1725 **** if (a == FFLUSH) /* didn't find it, so don't create it! */ return NULL; ! for (i=0; i < FOPEN_MAX; i++) if (files[i].fp == 0) break; ! if (i >= FOPEN_MAX) ! FATAL("%s makes too many open files", s); fflush(stdout); /* force a semblance of order */ m = a; if (a == GT) { --- 1732,1750 ---- if (a == FFLUSH) /* didn't find it, so don't create it! */ return NULL; ! for (i=0; i < nfiles; i++) if (files[i].fp == 0) break; ! if (i >= nfiles) { ! struct files *nf; ! int nnf = nfiles + FOPEN_MAX; ! nf = realloc(files, nnf * sizeof(*nf)); ! if (nf == NULL) ! FATAL("cannot grow files for %s and %d files", s, nnf); ! memset(&nf[nfiles], 0, FOPEN_MAX * sizeof(*nf)); ! nfiles = nnf; ! files = nf; ! } fflush(stdout); /* force a semblance of order */ m = a; if (a == GT) { *************** *** 1747,1753 **** { int i; ! for (i = 0; i < FOPEN_MAX; i++) if (fp == files[i].fp) return files[i].fname; return "???"; --- 1772,1778 ---- { int i; ! for (i = 0; i < nfiles; i++) if (fp == files[i].fp) return files[i].fname; return "???"; *************** *** 1762,1768 **** x = execute(a[0]); getsval(x); stat = -1; ! for (i = 0; i < FOPEN_MAX; i++) { if (files[i].fname && strcmp(x->sval, files[i].fname) == 0) { if (ferror(files[i].fp)) WARNING( "i/o error occurred on %s", files[i].fname ); --- 1787,1793 ---- x = execute(a[0]); getsval(x); stat = -1; ! for (i = 0; i < nfiles; i++) { if (files[i].fname && strcmp(x->sval, files[i].fname) == 0) { if (ferror(files[i].fp)) WARNING( "i/o error occurred on %s", files[i].fname ); *************** *** 1806,1812 **** { int i; ! for (i = 0; i < FOPEN_MAX; i++) if (files[i].fp) fflush(files[i].fp); } --- 1831,1837 ---- { int i; ! for (i = 0; i < nfiles; i++) if (files[i].fp) fflush(files[i].fp); }