projects
/
mmh
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move #include from h/mh.h to source files
[mmh]
/
uip
/
prompter.c
diff --git
a/uip/prompter.c
b/uip/prompter.c
index
e1f0bff
..
2bcd92a
100644
(file)
--- a/
uip/prompter.c
+++ b/
uip/prompter.c
@@
-12,6
+12,10
@@
#include <errno.h>
#include <signal.h>
#include <setjmp.h>
#include <errno.h>
#include <signal.h>
#include <setjmp.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <locale.h>
static struct swit switches[] = {
#define PREPSW 0
static struct swit switches[] = {
#define PREPSW 0
@@
-34,8
+38,8
@@
static struct swit switches[] = {
};
};
-static int wtuser = 0;
-static int sigint = 0;
+volatile sig_atomic_t wtuser = 0;
+volatile sig_atomic_t sigint = 0;
static jmp_buf sigenv;
/*
static jmp_buf sigenv;
/*
@@
-57,9
+61,7
@@
main(int argc, char **argv)
FILE *in, *out;
char *tfile = NULL;
FILE *in, *out;
char *tfile = NULL;
-#ifdef LOCALE
setlocale(LC_ALL, "");
setlocale(LC_ALL, "");
-#endif
invo_name = mhbasename(argv[0]);
/* read user profile/context */
invo_name = mhbasename(argv[0]);
/* read user profile/context */
@@
-73,7
+75,7
@@
main(int argc, char **argv)
switch (smatch(++cp, switches)) {
case AMBIGSW:
ambigsw(cp, switches);
switch (smatch(++cp, switches)) {
case AMBIGSW:
ambigsw(cp, switches);
- done(1);
+ exit(1);
case UNKWNSW:
adios(NULL, "-%s unknown", cp);
case UNKWNSW:
adios(NULL, "-%s unknown", cp);
@@
-82,10
+84,10
@@
main(int argc, char **argv)
"%s [switches] file",
invo_name);
print_help(buffer, switches, 1);
"%s [switches] file",
invo_name);
print_help(buffer, switches, 1);
- done(1);
+ exit(0);
case VERSIONSW:
print_version(invo_name);
case VERSIONSW:
print_version(invo_name);
- done(1);
+ exit(0);
case PREPSW:
prepend++;
case PREPSW:
prepend++;
@@
-162,7
+164,8
@@
main(int argc, char **argv)
if (i == -1) {
abort:
unlink(tmpfil);
if (i == -1) {
abort:
unlink(tmpfil);
- done(1);
+ /* sysexits.h EX_DATAERR */
+ exit(1);
}
if (i || (field[0]!='\n' && field[0]!='\0')) {
fprintf(out, "%s:", name);
}
if (i || (field[0]!='\n' && field[0]!='\0')) {
fprintf(out, "%s:", name);
@@
-256,8
+259,7
@@
has_no_body:
unlink(tmpfil);
context_save(); /* save the context file */
unlink(tmpfil);
context_save(); /* save the context file */
- done(0);
- return 1;
+ return 0;
}
}
@@
-265,23
+267,26
@@
int
getln(char *buffer, int n)
{
int c;
getln(char *buffer, int n)
{
int c;
+ sig_atomic_t psigint;
char *cp;
cp = buffer;
*cp = '\0';
switch (setjmp(sigenv)) {
char *cp;
cp = buffer;
*cp = '\0';
switch (setjmp(sigenv)) {
- case OK:
+ case 0:
wtuser = 1;
wtuser = 1;
+ psigint = sigint;
break;
break;
- case DONE:
- wtuser = 0;
- return 0;
-
default:
wtuser = 0;
default:
wtuser = 0;
- return NOTOK;
+ if (sigint == psigint) {
+ return 0;
+ } else {
+ sigint = psigint;
+ return NOTOK;
+ }
}
for (;;) {
}
for (;;) {
@@
-313,7
+318,8
@@
getln(char *buffer, int n)
static void
intrser(int i)
{
static void
intrser(int i)
{
- if (wtuser)
- longjmp(sigenv, NOTOK);
+ if (wtuser) {
+ close(STDIN_FILENO);
+ }
sigint++;
}
sigint++;
}