On 04/12/14 21:36, Isaac Dunham wrote: > On Mon, Apr 07, 2014 at 06:57:19PM +0530, Ashwini Sharma wrote: >> if (isatty(1)) xprintf("\033c\033(B\033[0m\033[J\033[?25h"); >> fflush(stdout); >> // set the terminal to sane settings >> xexec(args); > > Ick. > This is the sort of thing OLDTOY() is for; it belongs in an OLDTOY of > stty.
Yes and no. We haven't got an stty implementation yet, and xexec() should call the built-in one without doing an exec if it's built in. So it's not all that bad. That said, the code stty is _doing_ to make a terminal "sane" is also at least partly in init function reset_term(), so it's common enough it should probably be a helper function in lib/lib.c. But I'd have to see/write an stty implementation to know how _much_ can be shared, and what the callers of said shared infrastructure need from it... > If you would like an example, see toys/posix/id.c; I'd expect the code to be > something like this: More recently I upgraded the infrastructure to let you have two NEWTOY() in the same .c file. I posted an explanation and an updated hello.c implementing two commands at once here: http://lists.landley.net/pipermail/toybox-landley.net/2014-February/001580.html I haven't upgraded the code.html file yet though. My bad. (I alson eed to upgrade scripts/single.sh so it can build the rest of the commands.) > USE_STTY(NEWTOY(stty, ...)) > USE_STTY(OLDTOY(reset, stty, NULL, ...)) > ... > if (toys.which->name[0] == 'r') > xprintf("\033c\033(B\033[0m\033[J\033[?25h"); > if ((toys.which->name[0]=='r') || !strcmp(toys.optargs[0], "sane")) { > //stty sane code goes here > } Now that they can have different "main" functions, it might be easier to have reset_main() call stty_main(). Or just put the "sane" part in a shared helper function. (Or putting the tty fiddling should go in a helper function in lib...) Rob _______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net