evalstring(strcpy(stalloc(strlen(s) + 1), s));
evalstring(strcpy(stalloc(strlen(s) + 1), s), ~0);
histcmd(int argc, char **argv){	int ch;	const char *editor = NULL;	HistEvent he;	int lflg = 0, nflg = 0, rflg = 0, sflg = 0;	int i, retval;	const char *firststr, *laststr;	int first, last, direction;	char *pat = NULL, *repl;	/* ksh "fc old=new" crap */	static int active = 0;	struct jmploc jmploc;	struct jmploc *volatile savehandler;	char editfile[MAXPATHLEN + 1];	FILE *efp;#ifdef __GNUC__	/* Avoid longjmp clobbering */	(void) &editor;	(void) &lflg;	(void) &nflg;	(void) &rflg;	(void) &sflg;	(void) &firststr;	(void) &laststr;	(void) &pat;	(void) &repl;	(void) &efp;	(void) &argc;	(void) &argv;#endif	if (hist == NULL)		sh_error("history not active");	if (argc == 1)		sh_error("missing history argument");#ifdef __GLIBC__	optind = 0;#else	optreset = 1; optind = 1; /* initialize getopt */#endif	while (not_fcnumber(argv[optind]) &&	      (ch = getopt(argc, argv, ":e:lnrs")) != -1)		switch ((char)ch) {		case 'e':			editor = optionarg;			break;		case 'l':			lflg = 1;			break;		case 'n':			nflg = 1;			break;		case 'r':			rflg = 1;			break;		case 's':			sflg = 1;			break;		case ':':			sh_error("option -%c expects argument", optopt);			/* NOTREACHED */		case '?':		default:			sh_error("unknown option: -%c", optopt);			/* NOTREACHED */		}	argc -= optind, argv += optind;	/*	 * If executing...	 */	if (lflg == 0 || editor || sflg) {		lflg = 0;	/* ignore */		editfile[0] = '\0';		/*		 * Catch interrupts to reset active counter and		 * cleanup temp files.		 */		if (setjmp(jmploc.loc)) {			active = 0;			if (*editfile)				unlink(editfile);			handler = savehandler;			longjmp(handler->loc, 1);		}		savehandler = handler;		handler = &jmploc;		if (++active > MAXHISTLOOPS) {			active = 0;			displayhist = 0;			sh_error("called recursively too many times");		}		/*		 * Set editor.		 */		if (sflg == 0) {			if (editor == NULL &&			    (editor = bltinlookup("FCEDIT")) == NULL &&			    (editor = bltinlookup("EDITOR")) == NULL)				editor = DEFEDITOR;			if (editor[0] == '-' && editor[1] == '\0') {				sflg = 1;	/* no edit */				editor = NULL;			}		}	}	/*	 * If executing, parse [old=new] now	 */	if (lflg == 0 && argc > 0 &&	     ((repl = strchr(argv[0], '=')) != NULL)) {		pat = argv[0];		*repl++ = '\0';		argc--, argv++;	}	/*	 * determine [first] and [last]	 */	switch (argc) {	case 0:		firststr = lflg ? "-16" : "-1";		laststr = "-1";		break;	case 1:		firststr = argv[0];		laststr = lflg ? "-1" : argv[0];		break;	case 2:		firststr = argv[0];		laststr = argv[1];		break;	default:		sh_error("too many args");		/* NOTREACHED */	}	/*	 * Turn into event numbers.	 */	first = str_to_event(firststr, 0);	last = str_to_event(laststr, 1);	if (rflg) {		i = last;		last = first;		first = i;	}	/*	 * XXX - this should not depend on the event numbers	 * always increasing.  Add sequence numbers or offset	 * to the history element in next (diskbased) release.	 */	direction = first < last ? H_PREV : H_NEXT;	/*	 * If editing, grab a temp file.	 */	if (editor) {		int fd;		INTOFF;		/* easier */		sprintf(editfile, "%s_shXXXXXX", _PATH_TMP);		if ((fd = mkstemp(editfile)) < 0)			sh_error("can't create temporary file %s", editfile);		if ((efp = fdopen(fd, "w")) == NULL) {			close(fd);			sh_error("can't allocate stdio buffer for temp");		}	}	/*	 * Loop through selected history events.  If listing or executing,	 * do it now.  Otherwise, put into temp file and call the editor	 * after.	 *	 * The history interface needs rethinking, as the following	 * convolutions will demonstrate.	 */	history(hist, &he, H_FIRST);	retval = history(hist, &he, H_NEXT_EVENT, first);	for (;retval != -1; retval = history(hist, &he, direction)) {		if (lflg) {			if (!nflg)				out1fmt("%5d ", he.num);			out1str(he.str);		} else {			const char *s = pat ?			   fc_replace(he.str, pat, repl) : he.str;			if (sflg) {				if (displayhist) {					out2str(s);				}				evalstring(strcpy(stalloc(strlen(s) + 1), s));				if (displayhist && hist) {					/*					 *  XXX what about recursive and					 *  relative histnums.					 */					history(hist, &he, H_ENTER, s);				}			} else				fputs(s, efp);		}		/*		 * At end?  (if we were to lose last, we'd sure be		 * messed up).		 */		if (he.num == last)			break;	}	if (editor) {		char *editcmd;		fclose(efp);		editcmd = stalloc(strlen(editor) + strlen(editfile) + 2);		sprintf(editcmd, "%s %s", editor, editfile);		evalstring(editcmd, 0);	/* XXX - should use no JC command */		INTON;		readcmdfile(editfile);	/* XXX - should read back - quick tst */		unlink(editfile);	}	if (lflg == 0 && active > 0)		--active;	if (displayhist)		displayhist = 0;	return 0;}