# # # patch "win32/cputime.cc" # from [bd11f4649bfb4b8054d00b0c0531584c6286a5de] # to [56dfac2d26ef8f396831f0167ecfe1476a22af71] # # patch "win32/fs.cc" # from [0dc1c6a7dcf5bb4552c96aca16faaf7cea90c434] # to [8bc32fb3d17cb65315ac3107b20ec312092a23ad] # # patch "win32/get_system_flavour.cc" # from [cedc2f9d3e2ff48e7f99447c51671152e18dea39] # to [3ef9fa6a5e3cde262aee295e2a52d2e114715ae7] # # patch "win32/inodeprint.cc" # from [a869cdcc78fecf0ad1d94a2ccf2d9ef40f9b9048] # to [57864bd6598b9c011c15df890b8560be887dca3b] # # patch "win32/make_io_binary.cc" # from [e1ab402f330f608d17714ec0d04878b99feebc97] # to [6a63b6cec2798a3d95f2ebab79aa00c3e94f03ea] # # patch "win32/os_strerror.cc" # from [db47c358d71ed575eb64a372ce2275244a6af4f2] # to [417539d4636bc491b1dccd5777e101afafc1ae00] # # patch "win32/process.cc" # from [c46b3a202b67753c4a8b36e7317668d9b5ee0e49] # to [4ad144502cc101e4b35702c0a8891c50cf2286cc] # # patch "win32/read_password.cc" # from [5186f3e5fd834027192f0731b5a7168259da4099] # to [9f04873e6719de568125c7c99120d797777c6e41] # # patch "win32/terminal.cc" # from [cd2e5bedabc938989240544f8e371735bd2957e1] # to [e1aec71c6323e2a70d404d0748d9b4fdf5581879] # ============================================================ --- win32/cputime.cc bd11f4649bfb4b8054d00b0c0531584c6286a5de +++ win32/cputime.cc 56dfac2d26ef8f396831f0167ecfe1476a22af71 @@ -9,7 +9,8 @@ #include "numeric_vocab.hh" -u64 to_ticks(FILETIME const & ft) +static u64 +to_ticks(FILETIME const & ft) { u64 ticks = ft.dwHighDateTime; ticks <<= 32; ============================================================ --- win32/fs.cc 0dc1c6a7dcf5bb4552c96aca16faaf7cea90c434 +++ win32/fs.cc 8bc32fb3d17cb65315ac3107b20ec312092a23ad @@ -14,7 +14,6 @@ #include #include -//#include "vocab.hh" #include "sanity.hh" #include "platform.hh" @@ -23,10 +22,11 @@ get_current_working_dir() std::string get_current_working_dir() { - char buffer[4096]; - E(getcwd(buffer, 4096), + std::vector buffer; + buffer.resize(4096); + E(getcwd(&*buffer.begin(), buffer.size()), F("cannot get working directory: %s") % strerror(errno)); - std::string str(buffer); + std::string str(&*buffer.begin()); if (str[str.size() - 1] == '\\') str = str.substr(0, str.size() - 1); return str; @@ -39,20 +39,22 @@ change_current_working_dir(std::string c F("cannot change to directory %s: %s") % to % strerror(errno)); } +static std::string +get_default_confdir_base() +{ + char * appdata = getenv("APPDATA"); + if (appdata != NULL) + return appdata; + TCHAR szPath[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath))) + return szPath; + return ""; +} + std::string get_default_confdir() { - std::string base; - char * appdata; - appdata = getenv("APPDATA"); - if (appdata != NULL) - base = appdata; - else - { - TCHAR szPath[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath))) - base = szPath; - } + std::string base = get_default_confdir_base(); N(!base.empty(), F("could not determine configuration path")); return base + "\\monotone"; } @@ -69,12 +71,11 @@ get_homedir() // file for the discussion). For consistency, we now calculate the user's // home path using the same technique that Qt's QDir::homePath() uses on // Windows. - char * home; - home = getenv("HOME"); + char * home = getenv("HOME"); if (home != NULL) { L(FL("Home directory from HOME\n")); - return std::string(home); + return home; } // Otherwise, try USERPROFILE. We could also use SHGetFolderPath() to get // at USERPROFILE without requiring it to be set as an environment @@ -83,7 +84,7 @@ get_homedir() if (userprofile != NULL) { L(FL("Home directory from USERPROFILE\n")); - return std::string(userprofile); + return userprofile; } // Try concatenating HOMEDRIVE and HOMEPATH char * homedrive = getenv("HOMEDRIVE"); @@ -91,15 +92,15 @@ get_homedir() if (homedrive != NULL && homepath != NULL) { L(FL("Home directory from HOMEDRIVE+HOMEPATH\n")); - return std::string(homedrive) + std::string(homepath); + return std::string(homedrive) + homepath; } char * systemdrive = getenv("SystemDrive"); if (systemdrive != NULL) { L(FL("Home directory from SystemDrive\n")); - return std::string(systemdrive); + return systemdrive; } - return std::string("C:"); + return "C:"; } std::string @@ -139,7 +140,7 @@ static bool } static bool -rename_clobberingly_impl(const char * from, const char * to) +rename_clobberingly_impl(std::string const & from, std::string const & to) { // MoveFileEx is only available on NT-based systems. We will revert to a // more compatible DeleteFile/MoveFile pair as a compatibility fall-back. @@ -163,7 +164,7 @@ rename_clobberingly_impl(const char * fr if (MoveFileExAvailable) { - if (fnMoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)) + if (fnMoveFileEx(from.c_str(), to.c_str(), MOVEFILE_REPLACE_EXISTING)) return true; else if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { @@ -174,8 +175,8 @@ rename_clobberingly_impl(const char * fr else { // This is not even remotely atomic, but what can you do? - DeleteFile(to); - if (MoveFile(from, to)) + DeleteFile(to.c_str()); + if (MoveFile(from.c_str(), to.c_str())) return true; } return false; @@ -192,17 +193,18 @@ rename_clobberingly(std::string const & // (arbitrary) maximum of 16 attempts. This is a gross hack to work // around the common problem where another process (e.g. a virus checker) // will exclusive open a file you've just touched. - for (int i = 0; i < renameAttempts; ++i) { - if (rename_clobberingly_impl(from.c_str(), to.c_str())) - return; - lastError = GetLastError(); - L(FL("attempted rename of '%s' to '%s' failed: (%s) %d") - % from % to % os_strerror(lastError) % lastError); - Sleep(sleepTime); - if (sleepTime < 250) - sleepTime *= 2; - } + for (int i = 0; i < renameAttempts; ++i) + { + if (rename_clobberingly_impl(from, to)) + return; + lastError = GetLastError(); + L(FL("attempted rename of '%s' to '%s' failed: (%s) %d") + % from % to % os_strerror(lastError) % lastError); + Sleep(sleepTime); + if (sleepTime < 250) + sleepTime *= 2; + } E(false, F("renaming '%s' to '%s' failed: %s (%d)") % from % to - % os_strerror(lastError) % lastError); + % os_strerror(lastError) % lastError); } ============================================================ --- win32/get_system_flavour.cc cedc2f9d3e2ff48e7f99447c51671152e18dea39 +++ win32/get_system_flavour.cc 3ef9fa6a5e3cde262aee295e2a52d2e114715ae7 @@ -12,13 +12,14 @@ struct table_entry struct table_entry { unsigned long key; - char *val; + char * val; }; -void key_to_string(unsigned long key, - table_entry *table, - std::string & str, - std::string const & def) +void +key_to_string(unsigned long key, + table_entry * table, + std::string & str, + std::string const & def) { while (table->val != 0) { @@ -71,10 +72,9 @@ static table_entry processor_types[] = { { 0, 0 } }; - static table_entry processors[] = { #ifdef PROCESSOR_ARCHITECTURE_INTEL - { PROCESSOR_ARCHITECTURE_INTEL, "ia32" }, + { PROCESSOR_ARCHITECTURE_INTEL, "ia32" }, #endif #ifdef PROCESSOR_ARCHITECTURE_IA64 { PROCESSOR_ARCHITECTURE_IA64, "ia64" }, @@ -103,7 +103,6 @@ static table_entry processors[] = { { 0, 0 } }; - static table_entry families[] = { #ifdef VER_PLATFORM_WIN32s { VER_PLATFORM_WIN32s, "32s/3.1" }, @@ -112,7 +111,7 @@ static table_entry families[] = { { VER_PLATFORM_WIN32_WINDOWS, "95/98/SE/ME" }, #endif #ifdef VER_PLATFORM_WIN32_NT - { VER_PLATFORM_WIN32_NT, "NT/2000/XP/2003" }, + { VER_PLATFORM_WIN32_NT, "NT/2000/XP/2003/Vista" }, #endif #ifdef VER_PLATFORM_WIN32_CE { VER_PLATFORM_WIN32_CE, "CE" }, @@ -120,9 +119,9 @@ static table_entry families[] = { { 0, 0 } }; -void get_system_flavour(std::string & ident) +void +get_system_flavour(std::string & ident) { - SYSTEM_INFO si; OSVERSIONINFO vi; @@ -130,7 +129,7 @@ void get_system_flavour(std::string & id GetSystemInfo(&si); I(GetVersionEx(&vi)); - + std::string family, processor; key_to_string(vi.dwPlatformId, families, family, "unknown"); @@ -161,7 +160,7 @@ void get_system_flavour(std::string & id } ident = (F("Windows %s (%d.%d, build %d, %s) on %s") - % family + % family % vi.dwMajorVersion % vi.dwMinorVersion % vi.dwBuildNumber ============================================================ --- win32/inodeprint.cc a869cdcc78fecf0ad1d94a2ccf2d9ef40f9b9048 +++ win32/inodeprint.cc 57864bd6598b9c011c15df890b8560be887dca3b @@ -10,7 +10,8 @@ #include "platform.hh" #include "sanity.hh" -inline double difftime(FILETIME now, FILETIME then) +inline double +difftime(FILETIME now, FILETIME then) { // 100 ns (1e-7 second) resolution double out = now.dwHighDateTime - then.dwHighDateTime; @@ -20,20 +21,22 @@ inline double difftime(FILETIME now, FIL return out * 1e-7; } -inline bool is_nowish(FILETIME now, FILETIME then) +inline bool +is_nowish(FILETIME now, FILETIME then) { double diff = difftime(now, then); return (diff >= -3 && diff <= 3); } -inline bool is_future(FILETIME now, FILETIME then) +inline bool +is_future(FILETIME now, FILETIME then) { double diff = difftime(now, then); return (diff < 0); } - -bool inodeprint_file(std::string const & file, inodeprint_calculator & calc) +bool +inodeprint_file(std::string const & file, inodeprint_calculator & calc) { struct _stati64 st; if (_stati64(file.c_str(), &st) < 0) @@ -50,7 +53,8 @@ bool inodeprint_file(std::string const & calc.add_item(st.st_dev); calc.add_item(st.st_size); - HANDLE filehandle = CreateFile(file.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE filehandle = CreateFile(file.c_str(), GENERIC_READ, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (filehandle == INVALID_HANDLE_VALUE) return false; ============================================================ --- win32/make_io_binary.cc e1ab402f330f608d17714ec0d04878b99feebc97 +++ win32/make_io_binary.cc 6a63b6cec2798a3d95f2ebab79aa00c3e94f03ea @@ -6,9 +6,9 @@ #include "platform.hh" -void make_io_binary() +void +make_io_binary() { _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); } - ============================================================ --- win32/os_strerror.cc db47c358d71ed575eb64a372ce2275244a6af4f2 +++ win32/os_strerror.cc 417539d4636bc491b1dccd5777e101afafc1ae00 @@ -1,4 +1,4 @@ -// Copyright (C) 2006 Matthew Gregan +// Copyright (C) 2006 Matthew Gregan // all rights reserved. // licensed to the public under the terms of the GNU GPL (>= 2) // see the file COPYING for details ============================================================ --- win32/process.cc c46b3a202b67753c4a8b36e7317668d9b5ee0e49 +++ win32/process.cc 4ad144502cc101e4b35702c0a8891c50cf2286cc @@ -130,7 +130,8 @@ process_spawn(const char * const argv[]) L(FL("searching for exe: %s\n") % realexe); char * filepart; - if (SearchPath(NULL, argv[0], ".exe", realexe.size(), &*realexe.begin(), &filepart) == 0) + if (SearchPath(NULL, argv[0], ".exe", realexe.size(), &*realexe.begin(), + &filepart) == 0) { os_err_t errnum = GetLastError(); L(FL("SearchPath failed, err=%s (%d)\n") % os_strerror(errnum) % errnum); @@ -147,7 +148,8 @@ process_spawn(const char * const argv[]) si.cb = sizeof(STARTUPINFO); /* We don't need to set any of the STARTUPINFO members */ - if (CreateProcess(realexe, (char *) cmd.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi) == 0) + if (CreateProcess(realexe, const_cast(cmd.c_str()), NULL, NULL, TRUE, + 0, NULL, NULL, &si, &pi) == 0) { os_err_t errnum = GetLastError(); L(FL("CreateProcess failed, err=%s (%d)\n") % os_strerror(errnum) % errnum); ============================================================ --- win32/read_password.cc 5186f3e5fd834027192f0731b5a7168259da4099 +++ win32/read_password.cc 9f04873e6719de568125c7c99120d797777c6e41 @@ -12,7 +12,7 @@ #include "sanity.hh" -void +void read_password(std::string const & prompt, char * buf, size_t bufsz) { HANDLE mt_stdin; @@ -22,17 +22,19 @@ read_password(std::string const & prompt mt_stdin = GetStdHandle(STD_INPUT_HANDLE); I(mt_stdin != INVALID_HANDLE_VALUE); - I(mt_stdin != NULL); // NULL is non-interactive. Can't get a passphrase if we're non-interactive + // NULL is non-interactive. Can't get a passphrase if we're + // non-interactive + I(mt_stdin != NULL); if (GetConsoleMode(mt_stdin, &origmode) == 0) - { - /* This looks like we're not a real windows console. - Possibly MSYS or Cygwin. We'll do the best we can - to make the password invisible in the absence of tcsetattr, - namely emitting vt100 codes to change the foreground and - background colour to the same thing. If someone knows a - better way, be my guest. */ - mt_stdin = NULL; - } + { + /* This looks like we're not a real windows console. + Possibly MSYS or Cygwin. We'll do the best we can + to make the password invisible in the absence of tcsetattr, + namely emitting vt100 codes to change the foreground and + background colour to the same thing. If someone knows a + better way, be my guest. */ + mt_stdin = NULL; + } else pwmode = origmode & (~ENABLE_ECHO_INPUT); @@ -41,22 +43,22 @@ read_password(std::string const & prompt std::cout.flush(); if (mt_stdin != NULL) - { - I(SetConsoleMode(mt_stdin, pwmode) != 0); - std::cin.getline(buf, bufsz, '\n'); - I(SetConsoleMode(mt_stdin, origmode) != 0); - } + { + I(SetConsoleMode(mt_stdin, pwmode) != 0); + std::cin.getline(buf, bufsz, '\n'); + I(SetConsoleMode(mt_stdin, origmode) != 0); + } else - { - std::cout << "\x1B\x37\x1B[30;40m"; - std::cout.flush(); - fgets(buf, bufsz, stdin); /* Sorry, but cin.getline just doesn't work under MinGW's rxvt */ - std::cout << "\x1B[0m\x1B\x38"; - std::cout.flush(); + { + std::cout << "\x1B\x37\x1B[30;40m"; + std::cout.flush(); + fgets(buf, bufsz, stdin); /* Sorry, but cin.getline just doesn't work under MinGW's rxvt */ + std::cout << "\x1B[0m\x1B\x38"; + std::cout.flush(); - /* ...and fgets gives us an LF we don't want */ - size_t bufend = strlen(buf)-1; - if (buf[bufend]=='\x0A') - buf[bufend] = '\0'; - } + /* ...and fgets gives us an LF we don't want */ + size_t bufend = strlen(buf) - 1; + if (buf[bufend] == '\x0A') + buf[bufend] = '\0'; + } } ============================================================ --- win32/terminal.cc cd2e5bedabc938989240544f8e371735bd2957e1 +++ win32/terminal.cc e1aec71c6323e2a70d404d0748d9b4fdf5581879 @@ -12,10 +12,11 @@ #include "platform.hh" -bool have_smart_terminal() +bool +have_smart_terminal() { std::string term; - if (const char* term_cstr = getenv("TERM")) + if (char const * term_cstr = getenv("TERM")) term = term_cstr; else term = ""; @@ -29,7 +30,8 @@ bool have_smart_terminal() return true; } -unsigned int terminal_width() +unsigned int +terminal_width() { HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); if (h != INVALID_HANDLE_VALUE) @@ -40,7 +42,7 @@ unsigned int terminal_width() return static_cast(ci.dwSize.X); } } - + // default to 80 columns if the width query failed. return 80; }