From: Nicolas Boichat Date: Sat, 27 Aug 2005 14:33:39 +0000 (+0000) Subject: Add compatibility with Microsoft Visual C++ 2005 Express Edition Beta 2 (a complete... X-Git-Tag: Release-1.38.0~145 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4f114744bcff3d172562acc94128fbadbfb9363e;p=bacula%2Fbacula Add compatibility with Microsoft Visual C++ 2005 Express Edition Beta 2 (a complete VC++ IDE available for free). It should not break MSVC++ 2003 compatibility. (src/win32/README.vc8 will be completed later) git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2359 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index cd7d1fc229..23a9953511 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -796,7 +796,7 @@ static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service, /* connect to server */ if (connect(sockfd, ipaddr->get_sockaddr(), ipaddr->get_sockaddr_len()) < 0) { save_errno = errno; - close(sockfd); + socketClose(sockfd); continue; } *fatal = 0; diff --git a/bacula/src/lib/smartall.h b/bacula/src/lib/smartall.h index 98305061d5..c646888abe 100644 --- a/bacula/src/lib/smartall.h +++ b/bacula/src/lib/smartall.h @@ -100,12 +100,12 @@ public: void *operator new(size_t s, const char *fname, int line) { - void *p = sm_malloc(fname, line, s > sizeof(int) ? s : sizeof(int)); + void *p = sm_malloc(fname, line, s > sizeof(int) ? (unsigned int)s : sizeof(int)); return p; } void *operator new[](size_t s, const char *fname, int line) { - void *p = sm_malloc(fname, line, s > sizeof(int) ? s : sizeof(int)); + void *p = sm_malloc(fname, line, s > sizeof(int) ? (unsigned int)s : sizeof(int)); return p; } void operator delete(void *ptr) diff --git a/bacula/src/win32/.cvsignore b/bacula/src/win32/.cvsignore index db19a27fbe..aa50c9ae1c 100644 --- a/bacula/src/win32/.cvsignore +++ b/bacula/src/win32/.cvsignore @@ -2,3 +2,5 @@ install install-debug winbacula.nsi Makefile +bacula.ncb +bacula.suo \ No newline at end of file diff --git a/bacula/src/win32/README.vc8 b/bacula/src/win32/README.vc8 new file mode 100644 index 0000000000..33a9ed3608 --- /dev/null +++ b/bacula/src/win32/README.vc8 @@ -0,0 +1,3 @@ +Instructions to build Bacula with Microsoft Visual C++ 2005 Express Edition (free). +--- + diff --git a/bacula/src/win32/bacula.sln b/bacula/src/win32/bacula.sln new file mode 100644 index 0000000000..4300ccb513 --- /dev/null +++ b/bacula/src/win32/bacula.sln @@ -0,0 +1,32 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual C++ Express 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wx-console", "wx-console\wx-console.vcproj", "{9BA8E10D-0D82-4B25-8543-DE34641FBC10}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "baculafd", "baculafd\baculafd.vcproj", "{6A435DBB-4D3D-4DAE-8CB3-E0AF169A240B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "console", "console\console.vcproj", "{A0F65E06-9F18-40AC-81F6-A080852F1104}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9BA8E10D-0D82-4B25-8543-DE34641FBC10}.Debug|Win32.ActiveCfg = Debug|Win32 + {9BA8E10D-0D82-4B25-8543-DE34641FBC10}.Debug|Win32.Build.0 = Debug|Win32 + {9BA8E10D-0D82-4B25-8543-DE34641FBC10}.Release|Win32.ActiveCfg = Release|Win32 + {9BA8E10D-0D82-4B25-8543-DE34641FBC10}.Release|Win32.Build.0 = Release|Win32 + {6A435DBB-4D3D-4DAE-8CB3-E0AF169A240B}.Debug|Win32.ActiveCfg = Debug|Win32 + {6A435DBB-4D3D-4DAE-8CB3-E0AF169A240B}.Debug|Win32.Build.0 = Debug|Win32 + {6A435DBB-4D3D-4DAE-8CB3-E0AF169A240B}.Release|Win32.ActiveCfg = Release|Win32 + {6A435DBB-4D3D-4DAE-8CB3-E0AF169A240B}.Release|Win32.Build.0 = Release|Win32 + {A0F65E06-9F18-40AC-81F6-A080852F1104}.Debug|Win32.ActiveCfg = Debug|Win32 + {A0F65E06-9F18-40AC-81F6-A080852F1104}.Debug|Win32.Build.0 = Debug|Win32 + {A0F65E06-9F18-40AC-81F6-A080852F1104}.Release|Win32.ActiveCfg = Release|Win32 + {A0F65E06-9F18-40AC-81F6-A080852F1104}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/bacula/src/win32/baculafd/.cvsignore b/bacula/src/win32/baculafd/.cvsignore index ebb91b39d6..6139d5f367 100644 --- a/bacula/src/win32/baculafd/.cvsignore +++ b/bacula/src/win32/baculafd/.cvsignore @@ -1 +1,4 @@ bacula-fd.conf +Release +Debug +baculafd.vcproj.* \ No newline at end of file diff --git a/bacula/src/win32/baculafd/baculafd.vcproj b/bacula/src/win32/baculafd/baculafd.vcproj new file mode 100644 index 0000000000..0ea0595dad --- /dev/null +++ b/bacula/src/win32/baculafd/baculafd.vcproj @@ -0,0 +1,587 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bacula/src/win32/compat/compat.cpp b/bacula/src/win32/compat/compat.cpp index 9b0f3f0465..14c72df9f8 100644 --- a/bacula/src/win32/compat/compat.cpp +++ b/bacula/src/win32/compat/compat.cpp @@ -14,7 +14,7 @@ // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // the file LICENSE for additional details. // // Author : Christopher S. Hull @@ -37,7 +37,7 @@ extern void d_msg(const char *file, int line, int level, const char *fmt,...); extern DWORD g_platform_id; -extern int enable_vss; +extern int enable_vss; // from MicroSoft SDK (KES) is the diff between Jan 1 1601 and Jan 1 1970 #ifdef HAVE_MINGW @@ -80,7 +80,7 @@ void conv_unix_to_win32_path(const char *name, char *win32_name, DWORD dwSize) can get longer because VSS will make something like \\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy1\\bacula\\uninstall.exe from c:\bacula\uninstall.exe - */ + */ if (g_pVSSClient && enable_vss && g_pVSSClient->IsInitialized()) { POOLMEM *pszBuf = get_pool_memory (PM_FNAME); pszBuf = check_pool_memory_size(pszBuf, dwSize); @@ -91,10 +91,10 @@ void conv_unix_to_win32_path(const char *name, char *win32_name, DWORD dwSize) #endif } -int +int wchar_2_UTF8(char *pszUTF, const WCHAR *pszUCS, int cchChar) { - /* the return value is the number of bytes written to the buffer. + /* the return value is the number of bytes written to the buffer. The number includes the byte for the null terminator. */ if (p_WideCharToMultiByte) { @@ -106,17 +106,17 @@ wchar_2_UTF8(char *pszUTF, const WCHAR *pszUCS, int cchChar) return NULL; } -int +int UTF8_2_wchar(POOLMEM **ppszUCS, const char *pszUTF) { /* the return value is the number of wide characters written to the buffer. */ /* convert null terminated string from utf-8 to ucs2, enlarge buffer if necessary */ if (p_MultiByteToWideChar) { - /* strlen of UTF8 +1 is enough */ + /* strlen of UTF8 +1 is enough */ DWORD cchSize = (strlen(pszUTF)+1); *ppszUCS = check_pool_memory_size(*ppszUCS, cchSize*sizeof (WCHAR)); - + int nRet = p_MultiByteToWideChar(CP_UTF8, 0, pszUTF, -1, (LPWSTR) *ppszUCS,cchSize); ASSERT (nRet > 0); return nRet; @@ -151,10 +151,12 @@ wchar_win32_path(const char *name, WCHAR *win32_name) } } +#ifndef HAVE_VC8 int umask(int) { return 0; } +#endif int chmod(const char *, mode_t) { @@ -269,9 +271,9 @@ statDir(const char *file, struct stat *sb) // use unicode or ascii if (p_FindFirstFileW) { - POOLMEM* pwszBuf = get_pool_memory (PM_FNAME); + POOLMEM* pwszBuf = get_pool_memory (PM_FNAME); UTF8_2_wchar(&pwszBuf, file); - + h = p_FindFirstFileW((LPCWSTR) pwszBuf, &info_w); free_pool_memory(pwszBuf); @@ -338,7 +340,7 @@ stat2(const char *file, struct stat *sb) if (p_GetFileAttributesW) { POOLMEM* pwszBuf = get_pool_memory(PM_FNAME); UTF8_2_wchar(&pwszBuf, tmpbuf); - + attr = p_GetFileAttributesW((LPCWSTR) pwszBuf); free_pool_memory(pwszBuf); } else if (p_GetFileAttributesA) { @@ -442,12 +444,12 @@ stat(const char *file, struct stat *sb) if (p_GetFileAttributesExW) { /* dynamically allocate enough space for UCS2 filename */ - POOLMEM* pwszBuf = get_pool_memory (PM_FNAME); + POOLMEM* pwszBuf = get_pool_memory (PM_FNAME); UTF8_2_wchar(&pwszBuf, file); BOOL b = p_GetFileAttributesExW((LPCWSTR) pwszBuf, GetFileExInfoStandard, &data); free_pool_memory(pwszBuf); - + if (!b) { return stat2(file, sb); } @@ -585,7 +587,7 @@ strncasecmp(const char *s1, const char *s2, int len) s1++; s2++; if (ch1 == 0 || tolower(ch1) != tolower(ch2)) break; - } + } return (ch1 - ch2); } @@ -692,7 +694,7 @@ opendir(const char *path) if (p_FindFirstFileW) { POOLMEM* pwcBuf = get_pool_memory(PM_FNAME);; UTF8_2_wchar(&pwcBuf,rval->spec); - rval->dirh = p_FindFirstFileW((LPCWSTR)pwcBuf, &rval->data_w); + rval->dirh = p_FindFirstFileW((LPCWSTR)pwcBuf, &rval->data_w); free_pool_memory(pwcBuf); @@ -700,7 +702,7 @@ opendir(const char *path) rval->valid_w = 1; } else if (p_FindFirstFileA) { rval->dirh = p_FindFirstFileA(rval->spec, &rval->data_a); - + if (rval->dirh != INVALID_HANDLE_VALUE) rval->valid_a = 1; } else goto err; @@ -776,7 +778,7 @@ readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) _dir *dp = (_dir *)dirp; if (dp->valid_w || dp->valid_a) { entry->d_off = dp->offset; - + // copy unicode if (dp->valid_w) { char szBuf[MAX_PATH_UTF8]; @@ -785,7 +787,7 @@ readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) } else if (dp->valid_a) { // copy ansi (only 1 will be valid) dp->offset += copyin(*entry, dp->data_a.cFileName); } - + *result = entry; /* return entry address */ d_msg(__FILE__, __LINE__, 99, "readdir_r(%p, { d_name=\"%s\", d_reclen=%d, d_off=%d\n", @@ -797,7 +799,7 @@ readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) } // get next file, try unicode first - if (p_FindNextFileW) + if (p_FindNextFileW) dp->valid_w = p_FindNextFileW(dp->dirh, &dp->data_w); else if (p_FindNextFileA) dp->valid_a = p_FindNextFileA(dp->dirh, &dp->data_a); @@ -878,7 +880,7 @@ pathconf(const char *path, int name) case _PC_NAME_MAX : return 255; } - errno = ENOSYS; + errno = ENOSYS; return -1; } @@ -923,7 +925,7 @@ win32_chdir(const char *dir) } } else return -1; - + return 0; } @@ -935,11 +937,11 @@ win32_mkdir(const char *dir) UTF8_2_wchar(&pwszBuf, dir); int n=p_wmkdir((LPCWSTR)pwszBuf); - free_pool_memory(pwszBuf); + free_pool_memory(pwszBuf); return n; } - return _mkdir(dir); + return _mkdir(dir); } @@ -969,41 +971,41 @@ win32_getcwd(char *buf, int maxlen) return buf; } -int +int win32_fputs(const char *string, FILE *stream) { /* we use WriteConsoleA / WriteConsoleA so we can be sure that unicode support works on win32. with fallback if something fails - */ + */ HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE); - if (hOut && (hOut != INVALID_HANDLE_VALUE) && p_WideCharToMultiByte && + if (hOut && (hOut != INVALID_HANDLE_VALUE) && p_WideCharToMultiByte && p_MultiByteToWideChar && (stream == stdout)) { - + POOLMEM* pwszBuf = get_pool_memory(PM_MESSAGE); - + DWORD dwCharsWritten; DWORD dwChars; - + dwChars = UTF8_2_wchar(&pwszBuf, string); /* try WriteConsoleW */ if (WriteConsoleW (hOut, pwszBuf, dwChars-1, &dwCharsWritten, NULL)) { free_pool_memory(pwszBuf); - return dwCharsWritten; + return dwCharsWritten; } - - /* convert to local codepage and try WriteConsoleA */ - POOLMEM* pszBuf = get_pool_memory(PM_MESSAGE); + + /* convert to local codepage and try WriteConsoleA */ + POOLMEM* pszBuf = get_pool_memory(PM_MESSAGE); pszBuf = check_pool_memory_size(pszBuf, dwChars+1); - dwChars = p_WideCharToMultiByte(GetConsoleOutputCP(),0,(LPCWSTR) pwszBuf,-1,pszBuf,dwChars,NULL,NULL); + dwChars = p_WideCharToMultiByte(GetConsoleOutputCP(),0,(LPCWSTR) pwszBuf,-1,pszBuf,dwChars,NULL,NULL); free_pool_memory(pwszBuf); if (WriteConsoleA (hOut, pszBuf, dwChars-1, &dwCharsWritten, NULL)) { free_pool_memory(pszBuf); - return dwCharsWritten; + return dwCharsWritten; } } @@ -1017,15 +1019,15 @@ win32_cgets (char* buffer, int len) from the win32 console and fallback if seomething fails */ HANDLE hIn = GetStdHandle (STD_INPUT_HANDLE); - if (hIn && (hIn != INVALID_HANDLE_VALUE) && p_WideCharToMultiByte && p_MultiByteToWideChar) { + if (hIn && (hIn != INVALID_HANDLE_VALUE) && p_WideCharToMultiByte && p_MultiByteToWideChar) { DWORD dwRead; WCHAR wszBuf[1024]; - char szBuf[1024]; + char szBuf[1024]; /* nt and unicode conversion */ if (ReadConsoleW (hIn, wszBuf, 1024, &dwRead, NULL)) { - /* null terminate at end */ + /* null terminate at end */ if (wszBuf[dwRead-1] == L'\n') { wszBuf[dwRead-1] = L'\0'; dwRead --; @@ -1035,15 +1037,15 @@ win32_cgets (char* buffer, int len) wszBuf[dwRead-1] = L'\0'; dwRead --; } - + wchar_2_UTF8(buffer, wszBuf, len); return buffer; - } - + } + /* win 9x and unicode conversion */ if (ReadConsoleA (hIn, szBuf, 1024, &dwRead, NULL)) { - /* null terminate at end */ + /* null terminate at end */ if (szBuf[dwRead-1] == L'\n') { szBuf[dwRead-1] = L'\0'; dwRead --; @@ -1058,13 +1060,13 @@ win32_cgets (char* buffer, int len) p_MultiByteToWideChar(GetConsoleCP(), 0, szBuf, -1, wszBuf,1024); /* convert from WCHAR to UTF-8 */ if (wchar_2_UTF8(buffer, wszBuf, len)) - return buffer; + return buffer; } } /* fallback */ - if (fgets(buffer, len, stdin)) - return buffer; + if (fgets(buffer, len, stdin)) + return buffer; else return NULL; } @@ -1074,15 +1076,15 @@ win32_unlink(const char *filename) { int nRetCode; if (p_wunlink) { - POOLMEM* pwszBuf = get_pool_memory(PM_FNAME); + POOLMEM* pwszBuf = get_pool_memory(PM_FNAME); UTF8_2_wchar(&pwszBuf, filename); nRetCode = _wunlink((LPCWSTR) pwszBuf); - - /* special case if file is readonly, + + /* special case if file is readonly, we retry but unset attribute before */ if (nRetCode == -1 && errno == EACCES && p_SetFileAttributesW && p_GetFileAttributesW) { DWORD dwAttr = p_GetFileAttributesW((LPCWSTR)pwszBuf); - if (dwAttr != INVALID_FILE_ATTRIBUTES) { + if (dwAttr != INVALID_FILE_ATTRIBUTES) { if (p_SetFileAttributesW((LPCWSTR)pwszBuf, dwAttr & ~FILE_ATTRIBUTE_READONLY)) { nRetCode = _wunlink((LPCWSTR) pwszBuf); /* reset to original if it didn't help */ @@ -1095,11 +1097,11 @@ win32_unlink(const char *filename) } else { nRetCode = _unlink(filename); - /* special case if file is readonly, + /* special case if file is readonly, we retry but unset attribute before */ if (nRetCode == -1 && errno == EACCES && p_SetFileAttributesA && p_GetFileAttributesA) { DWORD dwAttr = p_GetFileAttributesA(filename); - if (dwAttr != INVALID_FILE_ATTRIBUTES) { + if (dwAttr != INVALID_FILE_ATTRIBUTES) { if (p_SetFileAttributesA(filename, dwAttr & ~FILE_ATTRIBUTE_READONLY)) { nRetCode = _unlink(filename); /* reset to original if it didn't help */ @@ -1108,7 +1110,7 @@ win32_unlink(const char *filename) } } } - } + } return nRetCode; } @@ -1188,7 +1190,8 @@ getArgv0(const char *cmdline) { int inquote = 0; - for (const char *cp = cmdline; *cp; cp++) + const char *cp; + for (cp = cmdline; *cp; cp++) { if (*cp == '"') { inquote = !inquote; @@ -1197,13 +1200,13 @@ getArgv0(const char *cmdline) break; } - + int len = cp - cmdline; char *rval = (char *)malloc(len+1); cp = cmdline; char *rp = rval; - + while (len--) *rp++ = *cp++; @@ -1256,12 +1259,12 @@ CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) char exeFile[256]; const char *comspec = getenv("COMSPEC"); - + if (comspec == NULL) // should never happen return INVALID_HANDLE_VALUE; char *cmdLine = (char *)alloca(strlen(cmdline) + strlen(comspec) + 16); - + strcpy(exeFile, comspec); strcpy(cmdLine, comspec); strcat(cmdLine, " /c "); @@ -1547,7 +1550,7 @@ utime(const char *fname, struct utimbuf *times) OPEN_EXISTING, 0, NULL); - + free_pool_memory(pwszBuf); } else if (p_CreateFileA) { h = p_CreateFileA(tmpbuf, @@ -1582,7 +1585,7 @@ int open(const char *file, int flags, int mode) { if (p_wopen) { - POOLMEM* pwszBuf = get_pool_memory(PM_FNAME); + POOLMEM* pwszBuf = get_pool_memory(PM_FNAME); UTF8_2_wchar(&pwszBuf, file); int nRet = p_wopen((LPCWSTR) pwszBuf, flags|_O_BINARY, mode); @@ -1596,10 +1599,11 @@ open(const char *file, int flags, int mode) /* * Note, this works only for a file. If you want - * to close a socket, use closesocket(). + * to close a socket, use closesocket(). * Bacula has been modified in src/lib/bnet.c * to use closesocket(). */ +#ifndef HAVE_VC8 int close(int fd) { @@ -1624,7 +1628,7 @@ write(int fd, const void *buf, ssize_t len) off_t lseek(int fd, off_t offset, int whence) { - return _lseeki64(fd, offset, whence); + return (off_t)_lseeki64(fd, offset, whence); } int @@ -1632,6 +1636,7 @@ dup2(int fd1, int fd2) { return _dup2(fd1, fd2); } +#endif #else int open(const char *file, int flags, int mode) @@ -1661,7 +1666,7 @@ open(const char *file, int flags, int mode) } if (p_CreateFileW) { - POOLMEM* pwszBuf = get_pool_memory(PM_FNAME); + POOLMEM* pwszBuf = get_pool_memory(PM_FNAME); UTF8_2_wchar(pwszBuf, file); foo = p_CreateFileW((LPCWSTR) pwszBuf, access, shareMode, NULL, create, msflags, NULL); diff --git a/bacula/src/win32/compat/compat.h b/bacula/src/win32/compat/compat.h index c88da60c3f..492cb2b0e9 100644 --- a/bacula/src/win32/compat/compat.h +++ b/bacula/src/win32/compat/compat.h @@ -34,11 +34,15 @@ #ifndef __COMPAT_H_ #define __COMPAT_H_ -#ifndef HAVE_MINGW -#ifndef HAVE_WXCONSOLE +#if (defined _MSC_VER) && (_MSC_VER >= 1400) // VC8+ +#pragma warning(disable : 4996) // Either disable all deprecation warnings, +// #define _CRT_SECURE_NO_DEPRECATE // Or just turn off warnings about the newly deprecated CRT functions. +#define HAVE_VC8 +#endif // VC8+ + +#if (!defined HAVE_MINGW) && (!defined HAVE_VC8) && (!defined HAVE_WXCONSOLE) #define __STDC__ 1 #endif -#endif #include #include @@ -92,9 +96,12 @@ typedef unsigned char uint8_t; typedef float float32_t; typedef unsigned short uint16_t; typedef signed short int16_t; -typedef long time_t; typedef signed char int8_t; +#ifndef HAVE_VC8 +typedef long time_t; +#endif + #if __STDC__ #ifndef HAVE_MINGW typedef _dev_t dev_t; @@ -136,7 +143,9 @@ typedef UINT32 gid_t; typedef UINT32 uid_t; typedef UINT32 gid_t; typedef UINT32 mode_t; +#ifndef _WX_DEFS_H_ /* ssize_t is defined in wx/defs.h */ typedef INT64 ssize_t; +#endif #endif //HAVE_MINGW struct dirent { @@ -240,17 +249,23 @@ struct stat #define iscsym __iscsym #endif - +#ifndef HAVE_VC8 int umask(int); +off_t lseek(int, off_t, int); +int dup2(int, int); +int close(int fd); +#ifndef HAVE_WXCONSOLE +ssize_t read(int fd, void *, ssize_t nbytes); +ssize_t write(int fd, const void *, ssize_t nbytes); +#endif +#endif int lchown(const char *, uid_t uid, gid_t gid); int chown(const char *, uid_t uid, gid_t gid); int chmod(const char *, mode_t mode); -off_t lseek(int, off_t, int); int inet_aton(const char *cp, struct in_addr *inp); int kill(int pid, int signo); int pipe(int []); int fork(); -int dup2(int, int); int waitpid(int, int *, int); #ifndef HAVE_MINGW @@ -268,12 +283,6 @@ int __snprintf(char *str, size_t count, const char *fmt, ...); #define sprintf __sprintf int __sprintf(char *str, const char *fmt, ...); -#ifndef HAVE_WXCONSOLE -ssize_t read(int fd, void *, ssize_t nbytes); -ssize_t write(int fd, const void *, ssize_t nbytes); -#endif - -int close(int fd); #endif //HAVE_MINGW diff --git a/bacula/src/win32/console/.cvsignore b/bacula/src/win32/console/.cvsignore index 126489d4fc..11649ec131 100644 --- a/bacula/src/win32/console/.cvsignore +++ b/bacula/src/win32/console/.cvsignore @@ -1 +1,4 @@ bconsole.conf +Debug +Release +console.vcproj.* \ No newline at end of file diff --git a/bacula/src/win32/console/console.vcproj b/bacula/src/win32/console/console.vcproj new file mode 100644 index 0000000000..7543904433 --- /dev/null +++ b/bacula/src/win32/console/console.vcproj @@ -0,0 +1,1034 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bacula/src/win32/wx-console/.cvsignore b/bacula/src/win32/wx-console/.cvsignore index 68f66b8a2d..0342a7a21c 100644 --- a/bacula/src/win32/wx-console/.cvsignore +++ b/bacula/src/win32/wx-console/.cvsignore @@ -1,2 +1,5 @@ *.idb wx-console.conf +Debug +Release +wx-console.vcproj.* diff --git a/bacula/src/win32/wx-console/wx-console.vcproj b/bacula/src/win32/wx-console/wx-console.vcproj new file mode 100644 index 0000000000..f07609aaa7 --- /dev/null +++ b/bacula/src/win32/wx-console/wx-console.vcproj @@ -0,0 +1,504 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bacula/src/wx-console/console_thread.cpp b/bacula/src/wx-console/console_thread.cpp index 9663dcd6da..b7b7271b7b 100644 --- a/bacula/src/wx-console/console_thread.cpp +++ b/bacula/src/wx-console/console_thread.cpp @@ -214,7 +214,7 @@ wxString console_thread::LoadConfig(wxString configfile) { } init_msg(NULL, msgs); - init_console_msg(console_thread::working_dir.mb_str(*wxConvCurrent)); + //init_console_msg(console_thread::working_dir.mb_str(*wxConvCurrent)); errmsg = wxT(""); if (!parse_config(configfile.mb_str(*wxConvCurrent), &scan_err)) { @@ -259,15 +259,14 @@ console_thread::~console_thread() { * Thread entry point */ void* console_thread::Entry() { - /* It seems we must redefine the locale on each thread. */ +#ifndef HAVE_WIN32 + /* It seems we must redefine the locale on each thread on wxGTK. + * On Win32 it makes wx-console crash. */ wxLocale m_locale; m_locale.Init(); m_locale.AddCatalog(wxT("bacula")); -#ifndef ENABLE_NLS -#undef LOCALEDIR -#define LOCALEDIR "." -#endif wxLocale::AddCatalogLookupPathPrefix(wxT(LOCALEDIR)); +#endif DIRRES* dir; if (!inited) { @@ -483,7 +482,7 @@ void* console_thread::Entry() { void console_thread::Write(const char* str) { if (UA_sock) { - UA_sock->msglen = strlen(str); + UA_sock->msglen = (int32_t)strlen(str); pm_strcpy(&UA_sock->msg, str); bnet_send(UA_sock); } else if (choosingdirector) { diff --git a/bacula/src/wx-console/wxbconfigfileeditor.cpp b/bacula/src/wx-console/wxbconfigfileeditor.cpp index 8d8481c18b..7ea7ccf7f1 100644 --- a/bacula/src/wx-console/wxbconfigfileeditor.cpp +++ b/bacula/src/wx-console/wxbconfigfileeditor.cpp @@ -35,6 +35,9 @@ enum BEGIN_EVENT_TABLE(wxbConfigFileEditor, wxDialog) EVT_BUTTON(Save, wxbConfigFileEditor::OnSave) EVT_BUTTON(Quit, wxbConfigFileEditor::OnQuit) +#ifdef HAVE_WIN32 + EVT_PAINT ( wxbConfigFileEditor::OnPaint) +#endif END_EVENT_TABLE() wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename): @@ -42,12 +45,42 @@ wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename): wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { this->filename = filename; - textCtrl = new wxTextCtrl(this,-1,wxT(""),wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH | wxTE_DONTWRAP); + wxString strbuf; + + wxFileName filen(filename); + + if (!filen.FileExists()) { + strbuf << wxT("#\n"); + strbuf << _("# Bacula wx-console Configuration File\n"); + strbuf << wxT("#\n"); + strbuf << wxT("\n"); + strbuf << wxT("Director {\n"); + strbuf << wxT(" Name = -dir\n"); + strbuf << wxT(" DIRport = 9101\n"); + strbuf << wxT(" address = \n"); + strbuf << wxT(" Password = \"\"\n"); + strbuf << wxT("}\n"); + } + else { + wxFile file(filename); + char buffer[2049]; + off_t len; + while ((len = file.Read(buffer, 2048)) > -1) { + buffer[len] = 0; + strbuf << wxString(buffer,wxConvUTF8); + if (file.Eof()) + break; + } + file.Close(); + } + + textCtrl = new wxTextCtrl(this,-1,strbuf,wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH2 | wxTE_DONTWRAP); wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL); #if defined __WXGTK12__ && !defined __WXGTK20__ // Fix for "chinese" fonts under gtk+ 1.2 font.SetDefaultEncoding(wxFONTENCODING_ISO8859_1); #endif textCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font)); + textCtrl->SetStyle(0, textCtrl->GetLastPosition(), wxTextAttr(*wxBLACK, wxNullColour, font)); wxFlexGridSizer *mainSizer = new wxFlexGridSizer(2, 1, 0, 0); mainSizer->AddGrowableCol(0); @@ -61,39 +94,24 @@ wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename): mainSizer->Add(bottomsizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); this->SetSizer(mainSizer); - - wxFileName filen(filename); - - if (!filen.FileExists()) { - (*textCtrl) << wxT("#\n"); - (*textCtrl) << _("# Bacula wx-console Configuration File\n"); - (*textCtrl) << wxT("#\n"); - (*textCtrl) << wxT("\n"); - (*textCtrl) << wxT("Director {\n"); - (*textCtrl) << wxT(" Name = -dir\n"); - (*textCtrl) << wxT(" DIRport = 9101\n"); - (*textCtrl) << wxT(" address = \n"); - (*textCtrl) << wxT(" Password = \"\"\n"); - (*textCtrl) << wxT("}\n"); - } - else { - wxFile file(filename); - char buffer[2049]; - off_t len; - while ((len = file.Read(buffer, 2048)) > -1) { - buffer[len] = 0; - (*textCtrl) << wxString(buffer,wxConvLocal); - if (file.Eof()) - break; - } - file.Close(); - } + + firstpaint = true; } wxbConfigFileEditor::~wxbConfigFileEditor() { } +/* Kludge for Win32, so the text control is not completely selected. */ +void wxbConfigFileEditor::OnPaint(wxPaintEvent& event) { + wxPaintDC dc(this); + + if (firstpaint) { + firstpaint = false; + textCtrl->SetSelection(0, 0); + } +} + void wxbConfigFileEditor::OnSave(wxCommandEvent& event) { wxFile file(filename, wxFile::write); if (!file.IsOpened()) { diff --git a/bacula/src/wx-console/wxbconfigfileeditor.h b/bacula/src/wx-console/wxbconfigfileeditor.h index 852d8d6457..10061b16d6 100644 --- a/bacula/src/wx-console/wxbconfigfileeditor.h +++ b/bacula/src/wx-console/wxbconfigfileeditor.h @@ -39,8 +39,11 @@ private: wxTextCtrl* textCtrl; + bool firstpaint; + void OnSave(wxCommandEvent& event); void OnQuit(wxCommandEvent& event); + void OnPaint(wxPaintEvent& event); DECLARE_EVENT_TABLE() }; diff --git a/bacula/src/wx-console/wxbmainframe.cpp b/bacula/src/wx-console/wxbmainframe.cpp index 66f3844246..e7b984dc0c 100644 --- a/bacula/src/wx-console/wxbmainframe.cpp +++ b/bacula/src/wx-console/wxbmainframe.cpp @@ -572,7 +572,11 @@ void wxbMainFrame::Print(wxString str, int status) consoleCtrl->AppendText(consoleBuffer); consoleBuffer = wxT(""); SetStatusText(_("Console thread terminated.")); +#ifndef HAVE_WIN32 consoleCtrl->PageDown(); +#else + consoleCtrl->ScrollLines(1); +#endif ct = NULL; DisablePanels(); int answer = wxMessageBox( _("Connection to the director lost. Quit program?"), @@ -616,7 +620,11 @@ void wxbMainFrame::Print(wxString str, int status) if (status == CS_DISCONNECTED) { consoleCtrl->AppendText(consoleBuffer); consoleBuffer = wxT(""); +#ifndef HAVE_WIN32 consoleCtrl->PageDown(); +#else + consoleCtrl->ScrollLines(1); +#endif SetStatusText(_("Disconnected of the director.")); DisablePanels(); return; @@ -691,7 +699,11 @@ void wxbMainFrame::Print(wxString str, int status) if (status == CS_DEBUG) { consoleCtrl->AppendText(consoleBuffer); consoleBuffer = wxT(""); +#ifndef HAVE_WIN32 consoleCtrl->PageDown(); +#else + consoleCtrl->ScrollLines(1); +#endif consoleCtrl->SetDefaultStyle(wxTextAttr(wxColour(0, 128, 0))); } else { @@ -708,24 +720,20 @@ void wxbMainFrame::Print(wxString str, int status) if ((status == CS_END) || (status == CS_PROMPT) || (str.Find(wxT("\n")) > -1)) { consoleCtrl->AppendText(consoleBuffer); consoleBuffer = wxT(""); - + +#ifndef HAVE_WIN32 consoleCtrl->PageDown(); +#else + consoleCtrl->ScrollLines(1); +#endif } - // consoleCtrl->ShowPosition(consoleCtrl->GetLastPosition()); + //consoleCtrl->ShowPosition(consoleCtrl->GetLastPosition()); /*if (status != CS_DEBUG) { consoleCtrl->AppendText("@"); }*/ //consoleCtrl->SetInsertionPointEnd(); - -/* if ((consoleCtrl->GetNumberOfLines()-1) > nlines) { - nlines = consoleCtrl->GetNumberOfLines()-1; - } - - if (status == CS_END) { - consoleCtrl->ShowPosition(nlines); - }*/ } /* @@ -738,7 +746,7 @@ void wxbMainFrame::Send(wxString str) typeCtrl->SetValue(wxT("")); consoleCtrl->SetDefaultStyle(wxTextAttr(*wxRED)); consoleCtrl->AppendText(wxbUtils::ConvertToPrintable(str)); - consoleCtrl->PageDown(); + //consoleCtrl->PageDown(); } /* if ((consoleCtrl->GetNumberOfLines()-1) > nlines) {