|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T g
Length: 1646 (0x66e)
Types: TextFile
Names: »getans.c«
└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit
└─⟦3658e588a⟧ »EurOpenD3/mail/mh/mh-6.7.tar.Z«
└─⟦c75e36ecb⟧
└─⟦this⟧ »mh-6.7/sbr/getans.c«
/* getans.c - get an answer from the user and return a string array */
#include "../h/mh.h"
#ifdef BSD42
#include <setjmp.h>
#endif BSD42
#include <signal.h>
#include <stdio.h>
static char ansbuf[BUFSIZ];
#ifndef BSD42
static int interrupted;
#else BSD42
static jmp_buf sigenv;
#endif BSD42
static int intrser ();
char **getans (prompt, ansp)
char *prompt;
struct swit *ansp;
{
int i;
TYPESIG (*istat) ();
char *cp,
**cpp;
#ifndef BSD42
interrupted = 0;
istat = signal (SIGINT, intrser);
#else BSD42
switch (setjmp (sigenv)) {
case OK:
istat = signal (SIGINT, intrser);
break;
default:
(void) signal (SIGINT, istat);
return NULL;
}
#endif BSD42
for (;;) {
printf ("%s", prompt);
(void) fflush (stdout);
cp = ansbuf;
while ((i = getchar ()) != '\n') {
#ifndef BSD42
if (i == EOF || interrupted) {
interrupted = 0;
(void) signal (SIGINT, istat);
return NULL;
}
#else BSD42
if (i == EOF)
longjmp (sigenv, DONE);
#endif BSD42
if (cp < &ansbuf[sizeof ansbuf - 1])
*cp++ = i;
}
*cp = 0;
if (ansbuf[0] == '?' || cp == ansbuf) {
printf ("Options are:\n");
printsw (ALL, ansp, "");
continue;
}
cpp = brkstring (ansbuf, " ", NULLCP);
switch (smatch (*cpp, ansp)) {
case AMBIGSW:
ambigsw (*cpp, ansp);
continue;
case UNKWNSW:
printf (" -%s unknown. Hit <CR> for help.\n", *cpp);
continue;
default:
(void) signal (SIGINT, istat);
return cpp;
}
}
}
static int intrser () {
#ifndef BSD42
(void) signal(SIGINT, intrser);
interrupted = 1;
#else BSD42
longjmp (sigenv, NOTOK);
#endif BSD42
}