=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/bc/bc.y,v retrieving revision 1.23 retrieving revision 1.24 diff -c -r1.23 -r1.24 *** src/usr.bin/bc/bc.y 2004/02/18 07:43:58 1.23 --- src/usr.bin/bc/bc.y 2004/10/19 07:36:51 1.24 *************** *** 1,5 **** %{ ! /* $OpenBSD: bc.y,v 1.23 2004/02/18 07:43:58 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek --- 1,5 ---- %{ ! /* $OpenBSD: bc.y,v 1.24 2004/10/19 07:36:51 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek *************** *** 31,37 **** */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: bc.y,v 1.23 2004/02/18 07:43:58 otto Exp $"; #endif /* not lint */ #include --- 31,37 ---- */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: bc.y,v 1.24 2004/10/19 07:36:51 otto Exp $"; #endif /* not lint */ #include *************** *** 62,67 **** --- 62,73 ---- int yyparse(void); int yywrap(void); + int fileindex; + int sargc; + char **sargv; + char *filename; + char *cmdexpr; + static void grow(void); static ssize_t cs(const char *); static ssize_t as(const char *); *************** *** 94,103 **** static ssize_t epilogue; static bool st_has_continue; static char str_table[UCHAR_MAX][2]; - static int fileindex; - static int sargc; - static char **sargv; - static char *filename; static bool do_fork = true; static u_short var_count; --- 100,105 ---- *************** *** 921,946 **** epilogue = node(epilogue, cs("L"), n, cs("s."), END_NODE); } - int - yywrap(void) - { - if (fileindex < sargc) { - filename = sargv[fileindex++]; - yyin = fopen(filename, "r"); - lineno = 1; - if (yyin == NULL) - err(1, "cannot open %s", filename); - return 0; - } else if (fileindex == sargc) { - fileindex++; - yyin = stdin; - lineno = 1; - filename = "stdin"; - return 0; - } - return 1; - } - void yyerror(char *s) { --- 923,928 ---- *************** *** 994,1000 **** static __dead void usage(void) { ! fprintf(stderr, "%s: usage: [-cl] [file ...]\n", __progname); exit(1); } --- 976,983 ---- static __dead void usage(void) { ! fprintf(stderr, "%s: usage: [-cl] [-e expression] [file ...]\n", ! __progname); exit(1); } *************** *** 1058,1063 **** --- 1041,1047 ---- { int i, ch, ret; int p[2]; + char *q; init(); setlinebuf(stdout); *************** *** 1066,1077 **** if (sargv == NULL) err(1, NULL); ! /* The d debug option is 4.4 BSD dc(1) compatible */ ! while ((ch = getopt(argc, argv, "cdl")) != -1) { switch (ch) { case 'c': case 'd': do_fork = false; break; case 'l': sargv[sargc++] = _PATH_LIBB; --- 1050,1069 ---- if (sargv == NULL) err(1, NULL); ! if ((cmdexpr = strdup("")) == NULL) ! err(1, NULL); ! /* The d debug option is 4.4 BSD bc(1) compatible */ ! while ((ch = getopt(argc, argv, "cde:l")) != -1) { switch (ch) { case 'c': case 'd': do_fork = false; + break; + case 'e': + q = cmdexpr; + if (asprintf(&cmdexpr, "%s%s\n", cmdexpr, optarg) == -1) + err(1, NULL); + free(q); break; case 'l': sargv[sargc++] = _PATH_LIBB;