history+readline+ncurses

L

lnatz

Hi,
I am writing a shell(project). I would like to use readline, ncurses
and/or history to search history. I want to write a function that
would recognize the KEY_UP and KEY_DOWN,and search the history. I want
the upand down key to act the same as it would in a unix terminal. If
anyone could help me, I would greatly appreciate it.

Thank you in advance,
Natalie
 
W

Walter Roberson

I am writing a shell(project). I would like to use readline, ncurses
and/or history to search history.


The answer is the same as when you asked yesterday: you can't do
that in standard C. You need system-specific extensions to do that,
and we don't support system-specific extensions in comp.lang.c .
You need to consult with a newsgroup that deals with whatever
operating system you are using.
 
I

Ian Collins

lnatz said:
Hi,
I am writing a shell(project). I would like to use readline, ncurses
and/or history to search history. I want to write a function that
would recognize the KEY_UP and KEY_DOWN,and search the history. I want
the upand down key to act the same as it would in a unix terminal. If
anyone could help me, I would greatly appreciate it.
Please don't multi-post the same question to more than one group. It
wastes everybody's time, including yours.
 
T

Thomas Dickey

The answer is the same as when you asked yesterday: you can't do
that in standard C. You need system-specific extensions to do that,
and we don't support system-specific extensions in comp.lang.c .

comp.unix.programmer deals with POSIX, for instance.

There's nothing in the question that requires the comment regarding
"system-specific extensions", since there's a well-known cross-platform
interface, even if it may not happen to apply to _your_ particular system.

ignore comp.programmer and comp.shell, since they're usually irrelevant.
 
K

Kenny McCormack

comp.unix.programmer deals with POSIX, for instance.

There's nothing in the question that requires the comment regarding
"system-specific extensions", since there's a well-known cross-platform
interface, even if it may not happen to apply to _your_ particular system.

It is routine for the dickwads here (and in some other dickwad-inhabited
NGs) to refer to something as "system-specific" when it works on
100-epsilon percent of the systems out there (regardless of how small epsilon
may be [as long as it is > 0]).

Calling it "non-standard" is, of course, OK; I have no problem with that.
But "system-specific" is over-indulgent.
 
W

Walter Roberson

There's nothing in the question that requires the comment regarding
"system-specific extensions", since there's a well-known cross-platform
interface, even if it may not happen to apply to _your_ particular system.

o Embedded systems, display panels, telex and text terminals --
no certainty that there *is* a suitable display on any given system,
and no C mechanism to probe to determine whether such a display is
present.

o VT52, VT100, ANSI, xterm, Adm3a, Tek4014 -- very different
control sequences even when they do exist, and no C mechanism to probe
to determine the required control sequence format

o Speaking of Tek4014: drawable displays don't necessarily mean
you can erase in place without erasing the whole screen and redrawing
the changed version; and no C mechanism to probe this kind of
characteristic

o termio, termios, whatever DOS used, whatever modern Windows used --
quite different APIs to be able to control character-by-character
interactions even when such facilities exist; and no C mechanism to
probe to see what the API is


Libraries such as ncurses and gnu readline merely encapsulate
useful related functionality, and do a lot of conditional compiling
to implement some of the more common cases... provided that what
people have implemented in the past is able to make useful guesses
about what kind of configuration and OS the program will be used on.
They do not remove the need for system-specific extensions; at best
they have done useful parts of the work for you.

The original poster hinted that she is using a "unix/linux OS",
but does not actually say so, and does not make clear whether
she is trying for a Unix implementation or a Linux implementation.
There have been major differences in the mechanisms for Unix;
I don't know whether this is one of the many interfaces changed
in Linux. Certainly there has been more than one "Linux"; we
haven't been given enough information to determine whether
she is implementing on a RedHat 9 server or a uLinux wireless
access point.

The original poster needs to find a newsgroup or systems administrator
that deals with the kind of OS and implementation environment
that she wants to deal with, and ask her questions there, making
clear what environment she is talking about. The answer -might-
come back as "Use gnu readline()", or it might not; even those
amongst us [if any] who know gnu readline() well haven't been given
enough information about the requirements to know whether that
would be an answer, and it does not fall within the usual boundaries
of comp.lang.c to discuss operating environments enough to
determine exactly which (if any) cross-platform library would be
suitable for the task in whatever the OP's target environment turns
out to be.
 
K

Keith Thompson

Thomas Dickey said:
comp.unix.programmer deals with POSIX, for instance.

There's nothing in the question that requires the comment regarding
"system-specific extensions", since there's a well-known cross-platform
interface, even if it may not happen to apply to _your_ particular system.

It's a system-specific extension even if it happens to exist on
multiple systems. Call it "systems-specific" if you prefer. Yes, the
'P' in POSIX stands for "Portable", but it originated as a definition
of the Unix interface, which is certainly system-specific. (Some
other operating systems do support POSIX, though.)

<OT>
And I don't think POSIX specifies the curses interface; at least a
search on the opengroup.org web site only turned up a couple of
non-normative references to curses.
</OT>
 
T

Thomas Dickey

It's a system-specific extension even if it happens to exist on
multiple systems. Call it "systems-specific" if you prefer. Yes, the
'P' in POSIX stands for "Portable", but it originated as a definition
of the Unix interface, which is certainly system-specific. (Some
other operating systems do support POSIX, though.)

fine.

However, the notion that frequent posters to comp.lang.c are _entitled_
to be rude warrants a comment: in "real" life if I were to state that
you talk with a funny accent, and just go away, even the lowest posters
on this group would point out that I'm rude. However, providing useful
information on where to go is deemed unworthy of the _frequent_ posters.

regards.

<OT>
And I don't think POSIX specifies the curses interface; at least a
search on the opengroup.org web site only turned up a couple of
non-normative references to curses.
</OT>

no, it does not (as is well-known). It specifies the interface that
the programmer can use to develop libraries such as ncurses - without
"system-specific extensions".

(twist the words around however you wish)
 
C

CBFalconer

Thomas said:
.... snip ...

However, the notion that frequent posters to comp.lang.c are
_entitled_ to be rude warrants a comment: in "real" life if I
were to state that you talk with a funny accent, and just go
away, even the lowest posters on this group would point out
that I'm rude. However, providing useful information on where
to go is deemed unworthy of the _frequent_ posters.

If you get off your high horse you will see that most posts about
non-topicality do contain suggestions about where to look. The
actual rudeness is on the part of the newbie, posting without
lurking and finding out the subject of the newsgroup, and on the
part of responders who corrupt the newsgroup by answering off-topic
questions.

Posix is not topical here. Code, written in standard C, to
implement history, readline, ncurses (if possible) is. You have
already been told where you can find discussions on the use and
availability of thos functions.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
W

Walter Roberson

Thomas Dickey said:
However, the notion that frequent posters to comp.lang.c are _entitled_
to be rude warrants a comment: in "real" life if I were to state that
you talk with a funny accent, and just go away, even the lowest posters
on this group would point out that I'm rude. However, providing useful
information on where to go is deemed unworthy of the _frequent_ posters.

As you started by replying to me, commenting on my choice of the phrase
"system-specific", the implication is that I was rude and did
not provide useful information on where to go. If, however, you
check back to the thread the OP started a day earlier, you will find
that I redirected the OP to comp.unix.programming and did so less
than 4 minutes after the OP's post. Other people also responded
with redirects. The OP did not respond or ask for clarification:
the OP instead reposted the original question about a day after
their original posted. The appearance was that the OP was hoping
for a different answer the second time.
 
K

Kenny McCormack

As you started by replying to me, commenting on my choice of the phrase
"system-specific", the implication is that I was rude and did
not provide useful information on where to go. If, however, you

(blah, blah, blah - snipped)

A better analogy would be an old-fashioned (not self-service) store,
where you have to ask the clerk to get your items. You go into the
store and see clearly on the shelf what you want; you know it is there,
you know they could sell it to you; in fact, you may even have seen them
sell it to other (presumably, privileged) people. But, when you ask for
it, they say "Nope, we don't have it. We never have and never will.
Furthermore, you can probably get it at 'XYZ' store, which is 3 miles
away".

Somehow, the advice seems a little less than well-intentioned.
 
T

Thomas Dickey

Walter Roberson said:
As you started by replying to me, commenting on my choice of the phrase
"system-specific", the implication is that I was rude and did
not provide useful information on where to go. If, however, you
check back to the thread the OP started a day earlier, you will find

That's a different thread. You're implying that you're polite on occasion.
(your followups are a different matter)
 
W

Walter Roberson

That's a different thread. You're implying that you're polite on occasion.
(your followups are a different matter)

Closer would be that I can be -impolite- on occasion; I am, after all,
only human. In this thread, I was not impolite; I was merely terse.

Posting the same question a day later without having learned anything
from the prior (valid) responses: some people would consider that
to be impolite.
 
T

Thomas Dickey

Walter Roberson said:
Posting the same question a day later without having learned anything
from the prior (valid) responses: some people would consider that
to be impolite.

OP appears to be a student, with all that implies.
 
K

Kenny McCormack

(your followups are a different matter)

Closer would be that I can be -impolite- on occasion; I am, after all,
only human. In this thread, I was not impolite; I was merely terse.[/QUOTE]

I call BS on this. Hint: No one ever says "Yes, I was impolite" (they
might say, "I was wrong" or other admissions of fault, but never this).
It is always "I was not impolite, blah, blah, blah".
Posting the same question a day later without having learned anything
from the prior (valid) responses: some people would consider that
to be impolite.

More likely, the OP is "coming back tomorrow, hoping for more sane
clerks to be on duty" (see my "store analogy"). This is not uncommon
behavior; if you go into a store and the clerks act nutsoid, the best
thing to do is to come back tomorrow and hope more rational people are
on duty then.
 
F

Flash Gordon

Thomas Dickey wrote, On 10/02/07 19:13:
OP appears to be a student, with all that implies.

Are you suggesting that students are not polite or that they do not have
to follow accepted conventions on news groups? I know a few students who
would consider such suggestions to be wrong and possibly insulting.

Actually students should be trying to learn, and a significant part of
that is taking note of advice given, the evidence is that this student
(unlike those I know) is not doing this.
 
K

Keith Thompson

Thomas Dickey said:
fine.

However, the notion that frequent posters to comp.lang.c are _entitled_
to be rude warrants a comment: in "real" life if I were to state that
you talk with a funny accent, and just go away, even the lowest posters
on this group would point out that I'm rude. However, providing useful
information on where to go is deemed unworthy of the _frequent_ posters.

I saw no rudeness. The OP was redirected to a more appropriate
newsgroup; in this case, that's the very best help we can possibly
offer.
no, it does not (as is well-known). It specifies the interface that
the programmer can use to develop libraries such as ncurses - without
"system-specific extensions".

It may or may not be "well-known" that POSIX doesn't specify the
curses interface. Personally, I didn't know that until I looked it
up.

It is not possible to implement the curses interface without using
system-specific extensions (yes, POSIX is system-specific as far as
standard C is concerned). In most cases, though, it's not necessary
to do so, because curses is already implemented on many systems. On
others, there are similar alternatives.
(twist the words around however you wish)

I twisted no words, and I have no idea what you're talking about.
 
K

Kenny McCormack

Keith "Sergeant Schultz" Thompson said:
I saw no rudeness.

Quelle surprise!
The OP was redirected to a more appropriate
newsgroup; in this case, that's the very best help we can possibly
offer.

This is a FAQ: Please see under "store analogy".

....
I twisted no words, and I have no idea what you're talking about.

Quelle surprise!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top