aboutsummaryrefslogtreecommitdiffstats
path: root/trio/strio.h
blob: d90cfcfd8a60833c525d68a476630a559ecf4b0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*************************************************************************
 *
 * $Id: strio.h,v 1.11 2001/12/27 17:29:20 breese Exp $
 *
 * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
 * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
 *
 ************************************************************************
 *
 * This maintains backwards compatibility with the strio functions.
 *
 ************************************************************************/

#ifndef TRIO_STRIO_H
#define TRIO_STRIO_H

#if !(defined(DEBUG) || defined(NDEBUG))
# define NDEBUG
#endif
#include "triostr.h"

enum {
  STRIO_HASH_NONE = TRIO_HASH_NONE,
  STRIO_HASH_PLAIN = TRIO_HASH_PLAIN,
  STRIO_HASH_TWOSIGNED = TRIO_HASH_TWOSIGNED
};

#define StrAlloc(n) trio_create(n)
#define StrAppend(x,y) ((void)trio_append((x),(y)),(x))
#define StrAppendMax(x,n,y) ((void)trio_append_max((x),(n),(y)),(x))
#define StrContains(x,y) trio_contains((x),(y))
#define StrCopy(x,y) ((void)trio_copy((x),(y)),(x))
#define StrCopyMax(x,n,y) ((void)trio_copy_max((x),(n),(y)),(x))
#define StrDuplicate(x) trio_duplicate(x)
#define StrDuplicateMax(x,n) trio_duplicate((x),(n))
#define StrEqual(x,y) trio_equal((x),(y))
#define StrEqualCase(x,y) trio_equal_case((x),(y))
#define StrEqualCaseMax(x,n,y) trio_equal_case_max((x),(n),(y))
#define StrEqualLocale(x,y) trio_equal_locale((x),(y))
#define StrEqualMax(x,n,y) trio_equal_max((x),(n),(y))
#define StrError(n) trio_error(n)
#define StrFree(x) trio_destroy(x)
#define StrFormat trio_sprintf
#define StrFormatAlloc trio_aprintf
#define StrFormatAppendMax trio_snprintfcat
#define StrFormatDateMax(x,n,y,t) trio_format_date_max((x),(n),(y),(t))
#define StrFormatMax trio_snprintf
#define StrHash(x,n) trio_hash((x),(n))
#define StrIndex(x,y) trio_index((x),(y))
#define StrIndexLast(x,y) trio_index_last((x),(y))
#define StrLength(x) trio_length((x))
#define StrMatch(x,y) trio_match((x),(y))
#define StrMatchCase(x,y) trio_match_case((x),(y))
#define StrScan trio_sscanf
#define StrSpanFunction(x,f) trio_span_function((x),(f))
#define StrSubstring(x,y) trio_substring((x),(y))
#define StrSubstringMax(x,n,y) trio_substring_max((x),(n),(y))
#define StrToDouble(x,y) trio_to_double((x),(y))
#define StrToFloat(x,y) trio_to_float((x),(y))
#define StrTokenize(x,y) trio_tokenize((x),(y))
#define StrToLong(x,y,n) trio_to_long((x),(y),(n))
#define StrToUnsignedLong(x,y,n) trio_to_unsigned_long((x),(n),(y))
#define StrToUpper(x) trio_upper(x)

#endif /* TRIO_STRIO_H */
n class="cpf"><unistd.h> #endif #include "fetchmail.h" #include "i18n.h" #define INPUT_BUF_SIZE PASSWORDLEN #if defined(HAVE_TERMIOS_H) && defined(HAVE_TCSETATTR) # include <termios.h> #else #if defined(HAVE_TERMIO_H) # include <sys/ioctl.h> # include <termio.h> #else #if defined(HAVE_SGTTY_H) # include <sgtty.h> #endif #endif #endif static int ttyfd; #if defined(HAVE_TCSETATTR) static struct termios termb; static tcflag_t flags; #else #if defined(HAVE_TERMIO_H) static struct termio termb; static unsigned short flags; #else #if defined(HAVE_STTY) static struct sgttyb ttyb; static int flags; #endif #endif #endif static void save_tty_state(void); static void disable_tty_echo(void); static void restore_tty_state(void); static RETSIGTYPE sigint_handler(int); char *fm_getpassword(char *prompt) { #if !(defined(HAVE_TCSETATTR) || defined(HAVE_TERMIO_H) || defined(HAVE_STTY)) #if defined(HAVE_GETPASS) char *getpass(); return getpass(prompt); #else fputs(GT_("ERROR: no support for getpassword() routine\n"),stderr); exit(1); #endif #else register char *p; register int c; FILE *fi; static char pbuf[INPUT_BUF_SIZE]; SIGHANDLERTYPE sig = 0; /* initialization pacifies -Wall */ int istty = isatty(0); /* get the file descriptor for the actual input device if it's a tty */ if (istty) { if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL) fi = stdin; else setbuf(fi, (char *)NULL); } else fi = stdin; /* store descriptor for the tty */ ttyfd = fileno(fi); if (istty) { /* preserve tty state before turning off echo */ save_tty_state(); /* now that we have the current tty state, we can catch SIGINT and exit gracefully */ sig = set_signal_handler(SIGINT, sigint_handler); /* turn off echo on the tty */ disable_tty_echo(); /* display the prompt and get the input string */ fprintf(stderr, "%s", prompt); } for (p = pbuf; (c = getc(fi))!='\n' && c!=EOF;) { if (p < &pbuf[INPUT_BUF_SIZE - 1]) *p++ = c; } *p = '\0'; /* write a newline so cursor won't appear to hang */ if (fi != stdin) fprintf(stderr, "\n"); if (istty) { /* restore previous state of the tty */ restore_tty_state(); /* restore previous state of SIGINT */ set_signal_handler(SIGINT, sig); } if (fi != stdin) fclose(fi); /* not checking should be safe, file mode was "r" */ return(pbuf); #endif /* !(defined(HAVE_TCSETATTR) || ... */ } static void save_tty_state (void) { #if defined(HAVE_TCSETATTR) tcgetattr(ttyfd, &termb); flags = termb.c_lflag; #else #if defined(HAVE_TERMIO_H) ioctl(ttyfd, TCGETA, (char *) &termb); flags = termb.c_lflag; #else /* we HAVE_STTY */ gtty(ttyfd, &ttyb); flags = ttyb.sg_flags; #endif #endif } static void disable_tty_echo(void) { /* turn off echo on the tty */ #if defined(HAVE_TCSETATTR) termb.c_lflag &= ~ECHO; tcsetattr(ttyfd, TCSAFLUSH, &termb); #else #if defined(HAVE_TERMIO_H) termb.c_lflag &= ~ECHO; ioctl(ttyfd, TCSETA, (char *) &termb); #else /* we HAVE_STTY */ ttyb.sg_flags &= ~ECHO; stty(ttyfd, &ttyb); #endif #endif } static void restore_tty_state(void) { /* restore previous tty echo state */ #if defined(HAVE_TCSETATTR) termb.c_lflag = flags; tcsetattr(ttyfd, TCSAFLUSH, &termb); #else #if defined(HAVE_TERMIO_H) termb.c_lflag = flags; ioctl(ttyfd, TCSETA, (char *) &termb); #else /* we HAVE_STTY */ ttyb.sg_flags = flags; stty(ttyfd, &ttyb); #endif #endif } static RETSIGTYPE sigint_handler(int signum) { (void)signum; restore_tty_state(); report(stderr, GT_("\nCaught SIGINT... bailing out.\n")); exit(1); } /* getpass.c ends here */