Changeset: 0e1940f2a7e2 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0e1940f2a7e2
Modified Files:
clients/src/mapiclient/prompt.c
Branch: Oct2010
Log Message:
On Windows, don't read from stdin, but from the console, and don't echo
passwords.
diffs (72 lines):
diff -r dc782206f49e -r 0e1940f2a7e2 clients/src/mapiclient/prompt.c
--- a/clients/src/mapiclient/prompt.c Mon Sep 20 16:17:22 2010 +0200
+++ b/clients/src/mapiclient/prompt.c Mon Sep 20 16:18:23 2010 +0200
@@ -24,13 +24,16 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
+#ifndef _MSC_VER
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
+#endif
#include "mprompt.h"
#ifdef _MSC_VER
#define fileno _fileno
+#include <conio.h>
#endif
#ifndef HAVE_GETLOGIN
@@ -56,6 +59,46 @@
#endif
}
+#ifdef _MSC_VER
+char *
+simple_prompt(const char *prompt, int maxlen, int echo, const char *def)
+{
+ size_t length = 0;
+ char *destination = NULL;
+
+ destination = (char *) malloc(maxlen + 2);
+ if (!destination)
+ return NULL;
+
+ if (prompt) {
+ _cputs(prompt);
+ if (def) {
+ _cputs("(");
+ _cputs(def);
+ _cputs(")");
+ }
+ _cputs(":");
+ }
+ if (echo) {
+ _cgets_s(destination, maxlen, &length);
+ while (length > 0 &&
+ (destination[length - 1] == '\n' ||
+ destination[length - 1] == '\r'))
+ destination[--length] = 0;
+ } else {
+ int c;
+
+ while ((c = _getch()) != '\r' && c != '\n') {
+ if (length < (size_t) maxlen)
+ destination[length++] = c;
+ }
+ destination[length] = 0;
+ }
+ if (length == 0 && def)
+ strcpy(destination, def);
+ return destination;
+}
+#else
char *
simple_prompt(const char *prompt, int maxlen, int echo, const char *def)
{
@@ -132,3 +175,4 @@
strcpy(destination, def);
return destination;
}
+#endif /* _MSC_VER */
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list