diff --git a/Makefile.am b/Makefile.am index 66474b8..a988683 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ # $Id$ SUBDIRS = src examples test doc -DIST_SUBDIRS = $(SUBDIRS) autotools debian +DIST_SUBDIRS = $(SUBDIRS) autotools debian msvc EXTRA_DIST = BUGS NOTES bootstrap build-win32 caca-config.in libcaca.spec AUTOMAKE_OPTIONS = dist-bzip2 diff --git a/configure.ac b/configure.ac index fcc1c8b..8daa5d9 100644 --- a/configure.ac +++ b/configure.ac @@ -13,6 +13,9 @@ AM_PROG_CC_C_O AC_PROG_CPP AC_PROG_RANLIB +AC_C_CONST +AC_C_INLINE + dnl AC_PROG_EGREP only exists in autoconf 2.54+, so we use AC_EGREP_CPP right dnl now otherwise it might be set in an obscure if statement. AC_EGREP_CPP(foo, foo) @@ -28,8 +31,8 @@ AC_ARG_ENABLE(conio, AC_ARG_ENABLE(x11, [ --enable-x11 X11 support (autodetected)]) -AC_CHECK_HEADERS(inttypes.h endian.h) -AC_CHECK_FUNCS(vsnprintf getenv putenv strcasecmp usleep gettimeofday) +AC_CHECK_HEADERS(sys/time.h inttypes.h endian.h unistd.h) +AC_CHECK_FUNCS(vsnprintf _vsnprintf getenv putenv strcasecmp usleep gettimeofday) AC_MSG_CHECKING(for Sleep) AC_TRY_COMPILE([#include ],[Sleep(42);], [AC_MSG_RESULT(yes) @@ -191,6 +194,7 @@ AC_CONFIG_FILES([ doc/doxygen.cfg autotools/Makefile debian/Makefile + msvc/Makefile ]) AC_CONFIG_FILES([caca-config], [chmod 0755 caca-config]) AC_OUTPUT diff --git a/examples/aafire.c b/examples/aafire.c index 3ab0e97..e577bec 100644 --- a/examples/aafire.c +++ b/examples/aafire.c @@ -100,7 +100,7 @@ initialize (void) printf ("Failed to initialize libcaca\n"); exit (1); } - caca_set_delay(0); + caca_set_delay(10000); XSIZ = caca_get_width() * 2; YSIZ = caca_get_height() * 2 - 4; #else diff --git a/examples/cacaview.c b/examples/cacaview.c index 8d11e3d..5ee13af 100644 --- a/examples/cacaview.c +++ b/examples/cacaview.c @@ -26,7 +26,6 @@ #include #include #include -#include #if defined(HAVE_IMLIB2_H) # include diff --git a/msvc/Makefile.am b/msvc/Makefile.am new file mode 100644 index 0000000..68aa5f5 --- /dev/null +++ b/msvc/Makefile.am @@ -0,0 +1,16 @@ +# $Id$ + +NULL = + +EXTRA_DIST = \ + libcaca.sln \ + config.h \ + libcaca.vcproj \ + cacaball.vcproj \ + cacademo.vcproj \ + cacafire.vcproj \ + cacamoir.vcproj \ + cacaplas.vcproj \ + cacaview.vcproj \ + $(NULL) + diff --git a/msvc/cacaball.vcproj b/msvc/cacaball.vcproj new file mode 100644 index 0000000..4170ad7 --- /dev/null +++ b/msvc/cacaball.vcproj @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvc/cacademo.vcproj b/msvc/cacademo.vcproj new file mode 100644 index 0000000..aaa2737 --- /dev/null +++ b/msvc/cacademo.vcproj @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvc/cacafire.vcproj b/msvc/cacafire.vcproj new file mode 100644 index 0000000..410fa6e --- /dev/null +++ b/msvc/cacafire.vcproj @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvc/cacamoir.vcproj b/msvc/cacamoir.vcproj new file mode 100644 index 0000000..d49b664 --- /dev/null +++ b/msvc/cacamoir.vcproj @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvc/cacaplas.vcproj b/msvc/cacaplas.vcproj new file mode 100644 index 0000000..48f7479 --- /dev/null +++ b/msvc/cacaplas.vcproj @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvc/cacaview.vcproj b/msvc/cacaview.vcproj new file mode 100644 index 0000000..7879df9 --- /dev/null +++ b/msvc/cacaview.vcproj @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvc/config.h b/msvc/config.h new file mode 100644 index 0000000..c16bfe8 --- /dev/null +++ b/msvc/config.h @@ -0,0 +1,47 @@ +/* $Id$ */ + +#define ALLOCCONSOLE_IN_WINDOWS_H 1 +/* #undef HAVE_CONIO_H */ +/* #undef HAVE_ENDIAN_H */ +#define HAVE_GETENV 1 +/* #undef HAVE_GETTIMEOFDAY */ +/* #undef HAVE_IMLIB2_H */ +/* #undef HAVE_INTTYPES_H */ +#define HAVE_MEMORY_H 1 +/* #undef HAVE_NCURSES_H */ +#define HAVE_PUTENV 1 +/* #undef HAVE_SLANG_H */ +/* #undef HAVE_SLANG_SLANG_H */ +#define HAVE_SLEEP 1 +/* #undef HAVE_STDINT_H */ +#define HAVE_STDLIB_H 1 +/* #undef HAVE_STRCASECMP */ +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TYPES_H 1 +/* #undef HAVE_UNISTD_H */ +/* #undef HAVE_USLEEP */ +/* #undef HAVE_VSNPRINTF */ +#define HAVE_WINDOWS_H 1 +/* #undef HAVE_X11_XKBLIB_H */ +#define HAVE__VSNPRINTF 1 +/* #undef NO_MINUS_C_MINUS_O */ +#define PACKAGE "libcaca" +#define PACKAGE_BUGREPORT "" +#define PACKAGE_NAME "" +#define PACKAGE_STRING "" +#define PACKAGE_TARNAME "" +#define PACKAGE_VERSION "" +/* #undef SCREENUPDATE_IN_PC_H */ +#define STDC_HEADERS 1 +/* #undef USE_CONIO */ +/* #undef USE_NCURSES */ +/* #undef USE_SLANG */ +#define USE_WIN32 1 +/* #undef USE_X11 */ +#define VERSION "0.7" +/* #undef const */ +#ifndef __cplusplus +#define inline __inline +#endif diff --git a/msvc/libcaca.sln b/msvc/libcaca.sln new file mode 100644 index 0000000..c63b01e --- /dev/null +++ b/msvc/libcaca.sln @@ -0,0 +1,63 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcaca", "libcaca.vcproj", "{8951ECB0-7CFE-41AB-A426-98D7C441BEA4}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cacaview", "cacaview.vcproj", "{62E567BD-73B7-4C1E-9919-6423C8A8F72E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cacaball", "cacaball.vcproj", "{7C6ECE78-045C-458D-8B8F-DEC2C9CB9C14}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cacademo", "cacademo.vcproj", "{C2C2652D-A50D-4803-90B5-0DCD041980CF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cacafire", "cacafire.vcproj", "{F25D1237-9ED8-4343-B958-308C95FE392F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cacamoir", "cacamoir.vcproj", "{5D336F08-9B06-4C19-94C7-EB423296B83E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cacaplas", "cacaplas.vcproj", "{04CC61FD-CC15-4B08-9028-BD87A63E7365}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + {62E567BD-73B7-4C1E-9919-6423C8A8F72E}.0 = {8951ECB0-7CFE-41AB-A426-98D7C441BEA4} + {7C6ECE78-045C-458D-8B8F-DEC2C9CB9C14}.0 = {8951ECB0-7CFE-41AB-A426-98D7C441BEA4} + {C2C2652D-A50D-4803-90B5-0DCD041980CF}.0 = {8951ECB0-7CFE-41AB-A426-98D7C441BEA4} + {F25D1237-9ED8-4343-B958-308C95FE392F}.0 = {8951ECB0-7CFE-41AB-A426-98D7C441BEA4} + {5D336F08-9B06-4C19-94C7-EB423296B83E}.0 = {8951ECB0-7CFE-41AB-A426-98D7C441BEA4} + {04CC61FD-CC15-4B08-9028-BD87A63E7365}.0 = {8951ECB0-7CFE-41AB-A426-98D7C441BEA4} + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {8951ECB0-7CFE-41AB-A426-98D7C441BEA4}.Debug.ActiveCfg = Debug|Win32 + {8951ECB0-7CFE-41AB-A426-98D7C441BEA4}.Debug.Build.0 = Debug|Win32 + {8951ECB0-7CFE-41AB-A426-98D7C441BEA4}.Release.ActiveCfg = Release|Win32 + {8951ECB0-7CFE-41AB-A426-98D7C441BEA4}.Release.Build.0 = Release|Win32 + {62E567BD-73B7-4C1E-9919-6423C8A8F72E}.Debug.ActiveCfg = Debug|Win32 + {62E567BD-73B7-4C1E-9919-6423C8A8F72E}.Debug.Build.0 = Debug|Win32 + {62E567BD-73B7-4C1E-9919-6423C8A8F72E}.Release.ActiveCfg = Release|Win32 + {62E567BD-73B7-4C1E-9919-6423C8A8F72E}.Release.Build.0 = Release|Win32 + {7C6ECE78-045C-458D-8B8F-DEC2C9CB9C14}.Debug.ActiveCfg = Debug|Win32 + {7C6ECE78-045C-458D-8B8F-DEC2C9CB9C14}.Debug.Build.0 = Debug|Win32 + {7C6ECE78-045C-458D-8B8F-DEC2C9CB9C14}.Release.ActiveCfg = Release|Win32 + {7C6ECE78-045C-458D-8B8F-DEC2C9CB9C14}.Release.Build.0 = Release|Win32 + {C2C2652D-A50D-4803-90B5-0DCD041980CF}.Debug.ActiveCfg = Debug|Win32 + {C2C2652D-A50D-4803-90B5-0DCD041980CF}.Debug.Build.0 = Debug|Win32 + {C2C2652D-A50D-4803-90B5-0DCD041980CF}.Release.ActiveCfg = Release|Win32 + {C2C2652D-A50D-4803-90B5-0DCD041980CF}.Release.Build.0 = Release|Win32 + {F25D1237-9ED8-4343-B958-308C95FE392F}.Debug.ActiveCfg = Debug|Win32 + {F25D1237-9ED8-4343-B958-308C95FE392F}.Debug.Build.0 = Debug|Win32 + {F25D1237-9ED8-4343-B958-308C95FE392F}.Release.ActiveCfg = Release|Win32 + {F25D1237-9ED8-4343-B958-308C95FE392F}.Release.Build.0 = Release|Win32 + {5D336F08-9B06-4C19-94C7-EB423296B83E}.Debug.ActiveCfg = Debug|Win32 + {5D336F08-9B06-4C19-94C7-EB423296B83E}.Debug.Build.0 = Debug|Win32 + {5D336F08-9B06-4C19-94C7-EB423296B83E}.Release.ActiveCfg = Release|Win32 + {5D336F08-9B06-4C19-94C7-EB423296B83E}.Release.Build.0 = Release|Win32 + {04CC61FD-CC15-4B08-9028-BD87A63E7365}.Debug.ActiveCfg = Debug|Win32 + {04CC61FD-CC15-4B08-9028-BD87A63E7365}.Debug.Build.0 = Debug|Win32 + {04CC61FD-CC15-4B08-9028-BD87A63E7365}.Release.ActiveCfg = Release|Win32 + {04CC61FD-CC15-4B08-9028-BD87A63E7365}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/msvc/libcaca.vcproj b/msvc/libcaca.vcproj new file mode 100644 index 0000000..144402e --- /dev/null +++ b/msvc/libcaca.vcproj @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/caca.c b/src/caca.c index 51a07bd..50bf9f0 100644 --- a/src/caca.c +++ b/src/caca.c @@ -138,7 +138,7 @@ int caca_init(void) initscr(); keypad(stdscr, TRUE); nonl(); - cbreak(); + raw(); noecho(); nodelay(stdscr, TRUE); curs_set(0); @@ -172,6 +172,9 @@ int caca_init(void) #if defined(USE_WIN32) if(_caca_driver == CACA_DRIVER_WIN32) { + if(!AllocConsole()) + return -1; + win32_hin = GetStdHandle(STD_INPUT_HANDLE); win32_hout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, @@ -380,6 +383,7 @@ void caca_end(void) { mousemask(oldmask, NULL); curs_set(1); + noraw(); endwin(); } else diff --git a/src/graphics.c b/src/graphics.c index 1d61c8a..a0adcf3 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -64,7 +64,9 @@ typedef unsigned char uint8_t; #include /* BUFSIZ */ #include #include -#include +#if defined(HAVE_UNISTD_H) +# include +#endif #include #include "caca.h" @@ -818,18 +820,21 @@ int _caca_init_graphics(void) win32_front = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); - if(!win32_front) + if(!win32_front || win32_front == INVALID_HANDLE_VALUE) return -1; win32_back = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); - if(!win32_back) + if(!win32_back || win328back == INVALID_HANDLE_VALUE) return -1; if(!GetConsoleScreenBufferInfo(win32_hout, &csbi)) return -1; + /* Sample code to get the biggest possible window */ + //size = GetLargestConsoleWindowSize(win32_hout); + _caca_width = csbi.srWindow.Right - csbi.srWindow.Left + 1; _caca_height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; @@ -842,6 +847,7 @@ int _caca_init_graphics(void) SetConsoleMode(win32_back, 0); GetConsoleCursorInfo(win32_front, &cci); + cci.dwSize = 0; cci.bVisible = FALSE; SetConsoleCursorInfo(win32_front, &cci); SetConsoleCursorInfo(win32_back, &cci); @@ -859,7 +865,13 @@ int _caca_init_graphics(void) return -1; } -win32_buffer = malloc(sizeof(CHAR_INFO) * _caca_width * _caca_height); + win32_buffer = malloc(_caca_width * _caca_height * sizeof(CHAR_INFO)); + if(win32_buffer == NULL) + { + free(win32_attr); + free(win32_char); + return -1; + } memset(win32_char, 0, _caca_width * _caca_height * sizeof(int)); memset(win32_attr, 0, _caca_width * _caca_height * sizeof(int)); diff --git a/src/time.c b/src/time.c index 071234d..80c78ce 100644 --- a/src/time.c +++ b/src/time.c @@ -30,14 +30,18 @@ #include "config.h" #include -#include +#if defined(HAVE_SYS_TIME_H) +# include +#endif #include #if defined(USE_WIN32) # include #endif -#include +#if defined(HAVE_UNISTD_H) +# include +#endif #include "caca.h" #include "caca_internals.h" @@ -58,8 +62,8 @@ unsigned int _caca_getticks(struct caca_timer *timer) #if defined(HAVE_GETTIMEOFDAY) struct timeval tv; #elif defined(USE_WIN32) - static long long int freq = -1; - unsigned long long int usec; + static __int64 freq = -1; + unsigned __int64 usec; #endif unsigned int ticks = 0; int new_sec, new_usec; @@ -76,8 +80,8 @@ unsigned int _caca_getticks(struct caca_timer *timer) } QueryPerformanceCounter((LARGE_INTEGER *)&usec); - new_sec = usec * 1000000 / freq / 1000000; - new_usec = (usec * 1000000 / freq) % 1000000; + new_sec = (int)(usec * 1000000 / freq / 1000000); + new_usec = (int)((usec * 1000000 / freq) % 1000000); #endif if(timer->last_sec != 0)