Date: Tue, 24 Jun 1997 08:43:17 -0400 (EDT) From: Tim Vanderhoek <hoek@hwcn.org> To: Steve Howe <un_x@anchorage.net> Cc: freebsd-hackers <hackers@FreeBSD.ORG> Subject: Re: BSD io Message-ID: <Pine.GSO.3.96.970624080450.9455A-100000@james.freenet.hamilton.on.ca> In-Reply-To: <Pine.BSF.3.95q.970623215859.7612A-100000@aak.anchorage.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 23 Jun 1997, Steve Howe wrote: > i remember i asked once how to read in a character mode > from the keyboard, and while i was, as always, humbled > by people reaching out to help, i ended up with 3 responses > with pages of source code each, and no real clear cut answer. I would guess that the question, or rather, the way it was worded, implied that you wanted to read directly from the keyboard. What you probably really wanted to do was to read input in terms of single characters instead of lines (ie. have getchar(), etc. return as soon as their is a single character available, instead of waiting until there is a whole line avaiable and then returning the first character in the line). To be even more general, this was probably for the purposes of some interactive program. However, when asked "How do I read a single character from the keyboard?" most people on this list would probably answer, strictly, how to read a character from the keyboard (in the most direct manner acceptable). However, when asked "How can I make my interactive program read single characters of input instead of whole lines", most would probably answer quickly "Oh! Just turn off canonical input processing." If they're talkative, they might even throw in a reference to man 4 termios, or suggest the use of ncurses to make the program easier to write. > #include <ncurses.h> and then use cbreak(); > OR > #include <stdlib.h> and then use system("stty cbreak"); #include <termios.h> #include <stdio.h> struct termios old, new; main(){ tcgetattr (fileno(stdin), &old); new = old; new &= ~(ICANON|ECHO); tcsetattr (fileno(stdin), TCSANOW, &new); /* Do my stuff */ tcsetattr (fileno(stdin), TCSANOW, &old); } /* Might want to fiddle MIN and TIME from man 4 termios, but in practice, it'll not matter much */ > because i find it more efficient to scan a screen for data entries > / error checking than to write code that deals, in a global sense, > with each field entered by a cursor. You don't want to scan the screen directly, you probably just want to throw what gets entered onscreen into a bunch of separate strings, and then scan those. I would guess that some interpreted your quote slightly differently, though. Incidentally, ncurses is distributed with a (completely-documented) libforms which (supposedly) makes it fairly easy to do that. I can't reccomend it, as I've never used it, though... (Also, libforms gets stripped from ncurses before ncurses is distributed with FreeBSD, so you have to grab and build ncurses yourself. I believe it builds out-of-box.) > since when does strings work on deleted files? > others say fsbs (whatever) will do the trick. Well, I'm using strings on /dev/wd0 right now to try and find any instances of the word "fuck" on my hdd. su; strings /dev/wd0 | more. I'm suprised, actually... It's been going for a while and still hasn't found anything (and all my MS programs are at the front of the disk! :)... Maybe it's getting screwed-up by case-sensitivity... <sigh> -- Outnumbered? Maybe. Outspoken? Never! tIM...HOEk
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.3.96.970624080450.9455A-100000>