static void init(void) { register Sfio_t** ss; register int c; ed.interactive = -1; ed.msg = sfstdout; ed.all = BLOCK_LINE; ed.page.size = BREAK_PAGE; ed.redisc.re_version = REG_VERSION; ed.redisc.re_errorf = errorf; ed.re.re_disc = &ed.redisc; ed.reflags = REG_DISCIPLINE|REG_DELIMITED; if (!conformance(0, 0)) ed.reflags |= REG_LENIENT; ed.verbose = 1; for (c = 0; c < elementsof(signals); c++) if (signal(signals[c], interrupt) == SIG_IGN) signal(signals[c], SIG_IGN); for (ss = (Sfio_t**)&ed.buffer; ss < (Sfio_t**)(((char*)&ed.buffer) + sizeof(ed.buffer)); ss++) { if (!(*ss = sfstropen())) error(ERROR_SYSTEM|3, "cannot initialize internal buffer"); sfputc(*ss, 0); sfstrseek(*ss, 0, SEEK_SET); } sfputr(ed.buffer.help, "?", 0); if (!(ed.zero = newof(NiL, Line_t, ed.all, 0))) error(ERROR_SYSTEM|3, "out of space [zero]"); }
int b_expr(int argc, char** argv, Shbltin_t* context) { State_t state; Node_t node; int n; cmdinit(argc, argv, context, ERROR_CATALOG, 0); state.standard = !!conformance(0, 0); #if 0 if (state.standard) state.arglist = argv+1; else #endif { while (n=optget(argv, usage)) { /* * NOTE: this loop ignores all but literal -- and -? * out of kindness for obsolescent usage * (and is ok with the standard) but strict * getopt conformance would give usage for all * unknown - options */ if(n=='?') error(ERROR_usage(2), "%s", opt_info.arg); if (opt_info.option[1] != '?') break; error(ERROR_usage(2), "%s", opt_info.arg); } if (error_info.errors) error(ERROR_usage(2),"%s",optusage((char*)0)); state.arglist = argv+opt_info.index; } if (expr_or(&state, &node)) error(ERROR_exit(2),"syntax error"); if (node.type&T_STR) { if (*node.str) sfprintf(sfstdout,"%s\n",node.str); } else sfprintf(sfstdout,"%d\n",node.num); return numeric(&node)?node.num==0:*node.str==0; }