
C++ and Unix Shell Question
Quote:
> I'm trying to develop a small application that is interactive in the
> same way as, say, gnuplot.The user types commands at a command prompt.
> The only thing I know how to use is scanf. So I would like to learn
Don't use scanf(). Ever. If you must do something similar, use
fgets() and sscanf(). This prevents scanf() reading right over the
newline in order to satisfy an input and confusing the poor person
typing at it.
Quote:
> answers to the following questions.
> (I understand that answers to some of these questions maybe quite
> involved so please feel free to direct me to a source rather than answer
> the question!)
> 1) How to read "arrow" keys.
Use the "readline" library.
Quote:
> 2) I notice that in certain shells backspace works, in others doesn't.
> What parameter or variable is responsible for that?
All of them should understand the setting used in your stty(1)
settings, but some of them are set up to understand both ASCII 8
(backspace) and ASCII 127 (delete) as "delete the last character".
Quote:
> 3) How do I enable emacs bindings?
Use the GNU "readline" library.
Quote:
> 4) I don't know if this is a tcsh feature (which is the shell that I
> prefer), but my shell stops taking input either after 1024 or 2048
> characters. How do I change that?
But your program has nothing whatsoever to do with the shell. The
shell's limitations will not be the limitations of your program.
There is no need to worry about that issue.
Quote:
> I know it's quite obnoxious to ask 4 questions in the same message,
> so sorry and thanks a lot in advance!
I wouldn't say it's obnoxious. It's certainly bandwidth-efficient.
At least the 4 questions were related...
--