# HG changeset patch # User Markus Bröker # Date 1229187493 -3600 # Node ID 5fec678f931b3c2958457deba082b1c7dab20dfc # Parent 933d86c1ff714238c5017cac75bfb188d942b6b4 getpass for windows does not work committer: Markus Bröker diff --git a/db_bridge/Makefile b/db_bridge/Makefile --- a/db_bridge/Makefile +++ b/db_bridge/Makefile @@ -4,6 +4,10 @@ mysql_db \ postgresql_db +OBJECTS=\ + main.o \ + console.o + .SUFFIXES: .cpp .cpp.o: @@ -11,13 +15,13 @@ all: $(TARGET) -mysql_db: mysql_db.o main.o - $(CC) $< main.o -lmysqlclient -o $@ +mysql_db: mysql_db.o $(OBJECTS) + $(CC) $< $(OBJECTS) -lmysqlclient -o $@ rm -f main.o -postgresql_db: postgresql_db.o main.cpp +postgresql_db: postgresql_db.o $(OBJECTS) $(CC) -c $(CFLAGS) -DWITH_POSTGRESQL main.cpp - $(CC) $< main.o -lpq -o $@ + $(CC) $< $(OBJECTS) -lpq -o $@ rm -f main.o .PHONY: clean diff --git a/db_bridge/console.cpp b/db_bridge/console.cpp --- a/db_bridge/console.cpp +++ b/db_bridge/console.cpp @@ -1,5 +1,14 @@ #include +#include +#ifdef WIN32 +#include +int Console::getch () +{ + return::getch (); +} +#else +#include int Console::getch () { static int ch = -1, fd = 0; @@ -14,6 +23,7 @@ tcsetattr (fd, TCSANOW, &alt); return ch; } +#endif void Console::getpass (std::string & password) { @@ -21,9 +31,9 @@ int c; char buffer[17]; - while ((c = getch ()) != '\n' && i < 17) { + while ((c = Console::getch ()) != '\n' && i < 17) { buffer[i++] = c; - std::cout << "*"; + std::cout << "\b*"; } buffer[i] = 0; diff --git a/db_bridge/include/console.h b/db_bridge/include/console.h --- a/db_bridge/include/console.h +++ b/db_bridge/include/console.h @@ -2,7 +2,6 @@ #define CONSOLE_H #include -#include namespace Console { int getch (); diff --git a/db_bridge/mysql_db.cpp b/db_bridge/mysql_db.cpp --- a/db_bridge/mysql_db.cpp +++ b/db_bridge/mysql_db.cpp @@ -4,6 +4,7 @@ */ #include +#include MySQL_DB::MySQL_DB (std::string srv, std::string usr, std::string pwd, std::string db) { @@ -15,7 +16,7 @@ if (server != "" && pwd == "") { std::cout << "Passwort von " << user << "@" << server << ": "; - std::getline (std::cin, password); + Console::getpass (password); } } diff --git a/db_bridge/postgresql_db.cpp b/db_bridge/postgresql_db.cpp --- a/db_bridge/postgresql_db.cpp +++ b/db_bridge/postgresql_db.cpp @@ -5,6 +5,7 @@ #include #include +#include PostgreSQL_DB::PostgreSQL_DB (std::string srv, std::string usr, std::string pwd, std::string db) { @@ -17,7 +18,7 @@ if (server != "" && pwd == "") { std::cout << "Passwort von " << user << "@" << server << ": "; - std::getline (std::cin, password); + Console::getpass (password); conninfo += " host=" + server + " password=" + password; } } diff --git a/urandom.c b/urandom.c --- a/urandom.c +++ b/urandom.c @@ -1,5 +1,5 @@ /** - * test/demos/tree.c + * test/demos/urandom.c * Copyright (C) 2008 Markus Broeker */ @@ -28,6 +28,7 @@ elements = read (fd, numbers, 255); numbers[elements] = 0; + close (fd); qsort (numbers, elements, sizeof (unsigned char), (void *)&compare); @@ -35,7 +36,5 @@ printf ("Number: %d\n", numbers[i]); } - close (fd); - return EXIT_SUCCESS; }