From: Bruce Momjian Date: Fri, 8 Aug 2003 20:20:49 +0000 (+0000) Subject: Remove simple_prompt from /contrib C files, now that it is in /port. X-Git-Tag: REL7_4_BETA2~115 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b2440ebec237d39619d5ad083a7818f016ae5a9;p=postgresql Remove simple_prompt from /contrib C files, now that it is in /port. They had the old versions anyway. --- diff --git a/contrib/dbase/dbf2pg.c b/contrib/dbase/dbf2pg.c index d679eed1ad..294dcd8689 100644 --- a/contrib/dbase/dbf2pg.c +++ b/contrib/dbase/dbf2pg.c @@ -65,7 +65,6 @@ char *convert_charset(char *string); void usage(void); unsigned int isinteger(char *); -char *simple_prompt(const char *prompt, int maxlen, bool echo); unsigned int @@ -565,114 +564,6 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh) } -/* - * simple_prompt --- borrowed from psql - * - * Generalized function especially intended for reading in usernames and - * password interactively. Reads from /dev/tty or stdin/stderr. - * - * prompt: The prompt to print - * maxlen: How many characters to accept - * echo: Set to false if you want to hide what is entered (for passwords) - * - * Returns a malloc()'ed string with the input (w/o trailing newline). - */ -static bool prompt_state = false; - -char * -simple_prompt(const char *prompt, int maxlen, bool echo) -{ - int length; - char *destination; - FILE *termin, - *termout; - -#ifdef HAVE_TERMIOS_H - struct termios t_orig, - t; -#endif - - destination = (char *) malloc(maxlen + 2); - if (!destination) - return NULL; - - prompt_state = true; /* disable SIGINT */ - - /* - * Do not try to collapse these into one "w+" mode file. Doesn't work - * on some platforms (eg, HPUX 10.20). - */ - termin = fopen("/dev/tty", "r"); - termout = fopen("/dev/tty", "w"); - if (!termin || !termout) - { - if (termin) - fclose(termin); - if (termout) - fclose(termout); - termin = stdin; - termout = stderr; - } - -#ifdef HAVE_TERMIOS_H - if (!echo) - { - tcgetattr(fileno(termin), &t); - t_orig = t; - t.c_lflag &= ~ECHO; - tcsetattr(fileno(termin), TCSAFLUSH, &t); - } -#endif - - if (prompt) - { - fputs(gettext(prompt), termout); - fflush(termout); - } - - if (fgets(destination, maxlen, termin) == NULL) - destination[0] = '\0'; - - length = strlen(destination); - if (length > 0 && destination[length - 1] != '\n') - { - /* eat rest of the line */ - char buf[128]; - int buflen; - - do - { - if (fgets(buf, sizeof(buf), termin) == NULL) - break; - buflen = strlen(buf); - } while (buflen > 0 && buf[buflen - 1] != '\n'); - } - - if (length > 0 && destination[length - 1] == '\n') - /* remove trailing newline */ - destination[length - 1] = '\0'; - -#ifdef HAVE_TERMIOS_H - if (!echo) - { - tcsetattr(fileno(termin), TCSAFLUSH, &t_orig); - fputs("\n", termout); - fflush(termout); - } -#endif - - if (termin != stdin) - { - fclose(termin); - fclose(termout); - } - - prompt_state = false; /* SIGINT okay again */ - - return destination; -} - - int main(int argc, char **argv) { diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c index 3db7cb9c71..3a111afca2 100644 --- a/contrib/vacuumlo/vacuumlo.c +++ b/contrib/vacuumlo/vacuumlo.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.22 2003/08/04 22:03:39 tgl Exp $ + * $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.23 2003/08/08 20:20:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -44,118 +44,9 @@ struct _param }; int vacuumlo(char *, struct _param *); -char *simple_prompt(const char *prompt, int, int); void usage(void); -/* - * simple_prompt - * - * Generalized function especially intended for reading in usernames and - * password interactively. Reads from /dev/tty or stdin/stderr. - * - * prompt: The prompt to print - * maxlen: How many characters to accept - * echo: Set to 0 if you want to hide what is entered (for passwords) - * - * Returns a malloc()'ed string with the input (w/o trailing newline). - */ -static int prompt_state = 0; - -char * -simple_prompt(const char *prompt, int maxlen, int echo) -{ - int length; - char *destination; - FILE *termin, - *termout; - -#ifdef HAVE_TERMIOS_H - struct termios t_orig, - t; -#endif - - destination = (char *) malloc(maxlen + 2); - if (!destination) - return NULL; - - prompt_state = 1; /* disable SIGINT */ - - /* - * Do not try to collapse these into one "w+" mode file. Doesn't work - * on some platforms (eg, HPUX 10.20). - */ - termin = fopen("/dev/tty", "r"); - termout = fopen("/dev/tty", "w"); - if (!termin || !termout) - { - if (termin) - fclose(termin); - if (termout) - fclose(termout); - termin = stdin; - termout = stderr; - } - -#ifdef HAVE_TERMIOS_H - if (!echo) - { - tcgetattr(fileno(termin), &t); - t_orig = t; - t.c_lflag &= ~ECHO; - tcsetattr(fileno(termin), TCSAFLUSH, &t); - } -#endif - - if (prompt) - { - fputs(prompt, termout); - fflush(termout); - } - - if (fgets(destination, maxlen, termin) == NULL) - destination[0] = '\0'; - - length = strlen(destination); - if (length > 0 && destination[length - 1] != '\n') - { - /* eat rest of the line */ - char buf[128]; - int buflen; - - do - { - if (fgets(buf, sizeof(buf), termin) == NULL) - break; - buflen = strlen(buf); - } while (buflen > 0 && buf[buflen - 1] != '\n'); - } - - if (length > 0 && destination[length - 1] == '\n') - /* remove trailing newline */ - destination[length - 1] = '\0'; - -#ifdef HAVE_TERMIOS_H - if (!echo) - { - tcsetattr(fileno(termin), TCSAFLUSH, &t_orig); - fputs("\n", termout); - fflush(termout); - } -#endif - - if (termin != stdin) - { - fclose(termin); - fclose(termout); - } - - prompt_state = 0; /* SIGINT okay again */ - - return destination; -} - - /* * This vacuums LOs of one database. It returns 0 on success, -1 on failure.