X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fprompter.c;h=795e4724d4966061c274ef7423606896a15ad555;hb=884c2f0375bc6108a9902bf0971844d34585c418;hp=fa1bfae8ec5f807c4ef90517dd61d65b0df710b2;hpb=1691e80890e5d8ba258c51c214a3e91880e1db2b;p=mmh diff --git a/uip/prompter.c b/uip/prompter.c index fa1bfae..795e472 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -2,7 +2,9 @@ /* * prompter.c -- simple prompting editor front-end * - * $Id$ + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include @@ -12,15 +14,7 @@ #include #include -#ifdef HAVE_TERMIOS_H -# include -#else -# ifdef HAVE_TERMIO_H -# include -# else -# include -# endif -#endif +#include #define QUOTE '\\' @@ -56,31 +50,15 @@ static struct swit switches[] = { #define VERSIONSW 10 { "version", 0 }, #define HELPSW 11 - { "help", 4 }, + { "help", 0 }, { NULL, 0 } }; -extern int errno; -#ifdef HAVE_TERMIOS_H static struct termios tio; -# define ERASE tio.c_cc[VERASE] -# define KILL tio.c_cc[VKILL] -# define INTR tio.c_cc[VINTR] -#else -# ifdef HAVE_TERMIO_H -static struct termio tio; -# define ERASE tio.c_cc[VERASE] -# define KILL tio.c_cc[VKILL] -# define INTR tio.c_cc[VINTR] -# else -static struct sgttyb tio; -static struct tchars tc; -# define ERASE tio.sg_erase -# define KILL tio.sg_kill -# define INTR tc.t_intrc -# endif -#endif +#define ERASE tio.c_cc[VERASE] +#define KILL tio.c_cc[VKILL] +#define INTR tio.c_cc[VINTR] static int wtuser = 0; static int sigint = 0; @@ -92,7 +70,7 @@ static jmp_buf sigenv; int getln (char *, int); static int chrcnv (char *); static void chrdsp (char *, char); -static RETSIGTYPE intrser (int); +static void intrser (int); int @@ -105,6 +83,7 @@ main (int argc, char **argv) char buffer[BUFSIZ], tmpfil[BUFSIZ]; char **arguments, **argp; FILE *in, *out; + char *tfile = NULL; #ifdef LOCALE setlocale(LC_ALL, ""); @@ -130,10 +109,10 @@ main (int argc, char **argv) snprintf (buffer, sizeof(buffer), "%s [switches] file", invo_name); print_help (buffer, switches, 1); - done (1); + done (0); case VERSIONSW: print_version(invo_name); - done (1); + done (0); case ERASESW: if (!(erasep = *argp++) || *erasep == '-') @@ -182,32 +161,19 @@ main (int argc, char **argv) if ((in = fopen (drft, "r")) == NULL) adios (drft, "unable to open"); - strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil)); - if ((out = fopen (tmpfil, "w")) == NULL) - adios (tmpfil, "unable to create"); + tfile = m_mktemp2(NULL, invo_name, NULL, &out); + if (tfile == NULL) adios("prompter", "unable to create temporary file"); chmod (tmpfil, 0600); + strncpy (tmpfil, tfile, sizeof(tmpfil)); /* * Are we changing the kill or erase character? */ if (killp || erasep) { -#ifdef HAVE_TERMIOS_H cc_t save_erase, save_kill; -#else - int save_erase, save_kill; -#endif /* get the current terminal attributes */ -#ifdef HAVE_TERMIOS_H tcgetattr(0, &tio); -#else -# ifdef HAVE_TERMIO_H - ioctl(0, TCGETA, &tio); -# else - ioctl (0, TIOCGETP, (char *) &tio); - ioctl (0, TIOCGETC, (char *) &tc); -# endif -#endif /* save original kill, erase character for later */ save_kill = KILL; @@ -218,15 +184,7 @@ main (int argc, char **argv) ERASE = erasep ? chrcnv (erasep) : save_erase; /* set the new terminal attributes */ -#ifdef HAVE_TERMIOS_H tcsetattr(0, TCSADRAIN, &tio); -#else -# ifdef HAVE_TERMIO_H - ioctl(0, TCSETAW, &tio); -# else - ioctl (0, TIOCSETN, (char *) &tio); -# endif -#endif /* print out new kill erase characters */ chrdsp ("erase", ERASE); @@ -281,15 +239,7 @@ main (int argc, char **argv) if (i == -1) { abort: if (killp || erasep) { -#ifdef HAVE_TERMIOS_H tcsetattr(0, TCSADRAIN, &tio); -#else -# ifdef HAVE_TERMIO - ioctl (0, TCSETA, &tio); -# else - ioctl (0, TIOCSETN, (char *) &tio); -# endif -#endif } unlink (tmpfil); done (1); @@ -376,15 +326,7 @@ no_body: SIGNAL (SIGINT, SIG_IGN); if (killp || erasep) { -#ifdef HAVE_TERMIOS_H tcsetattr(0, TCSADRAIN, &tio); -#else -# ifdef HAVE_TERMIO_H - ioctl (0, TCSETAW, &tio); -# else - ioctl (0, TIOCSETN, (char *) &tio); -# endif -#endif } if ((fdi = open (tmpfil, O_RDONLY)) == NOTOK) @@ -398,6 +340,7 @@ no_body: context_save (); /* save the context file */ done (0); + return 1; } @@ -450,12 +393,10 @@ getln (char *buffer, int n) } -static RETSIGTYPE +static void intrser (int i) { -#ifndef RELIABLE_SIGNALS - SIGNAL (SIGINT, intrser); -#endif + NMH_UNUSED (i); if (wtuser) longjmp (sigenv, NOTOK);