From 5c862b0615341b239a0deba145a0718945592f09 Mon Sep 17 00:00:00 2001 From: Devin Torres Date: Fri, 27 Sep 2013 17:53:14 -0500 Subject: [PATCH] Improve MSVC support Closes #18. --- Makefile.win | 2 +- src/autolink.c | 6 +++--- src/buffer.c | 22 ++++------------------ src/buffer.h | 2 +- src/html_smartypants.c | 4 ++-- src/markdown.c | 2 +- 6 files changed, 12 insertions(+), 26 deletions(-) diff --git a/Makefile.win b/Makefile.win index 4be255c..27bcc13 100644 --- a/Makefile.win +++ b/Makefile.win @@ -1,5 +1,5 @@ CC = cl -CFLAGS = /O2 /EHsc /I"src/" +CFLAGS = /O2 /sdl /Isrc /D_CRT_SECURE_NO_WARNINGS HOEDOWN_SRC = \ src\autolink.obj \ diff --git a/src/autolink.c b/src/autolink.c index 8687270..883a2ff 100644 --- a/src/autolink.c +++ b/src/autolink.c @@ -5,7 +5,7 @@ #include #include -#if defined(_WIN32) +#ifdef _MSC_VER #define strncasecmp _strnicmp #endif @@ -190,7 +190,7 @@ hoedown_autolink__email( int nb = 0, np = 0; for (rewind = 0; rewind < max_rewind; ++rewind) { - uint8_t c = data[-rewind - 1]; + uint8_t c = data[-1 - rewind]; if (isalnum(c)) continue; @@ -247,7 +247,7 @@ hoedown_autolink__url( if (size < 4 || data[1] != '/' || data[2] != '/') return 0; - while (rewind < max_rewind && isalpha(data[-rewind - 1])) + while (rewind < max_rewind && isalpha(data[-1 - rewind])) rewind++; if (!hoedown_autolink_is_safe(data - rewind, size + rewind)) diff --git a/src/buffer.c b/src/buffer.c index 8f64feb..5df1a92 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1,5 +1,3 @@ -#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) /* 16mb */ - #include "buffer.h" #include @@ -7,12 +5,7 @@ #include #include -/* MSVC compat */ -#if defined(_MSC_VER) -# define _buf_vsnprintf _vsnprintf -#else -# define _buf_vsnprintf vsnprintf -#endif +#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) /* 16mb */ /* hoedown_buffer_new: allocation of a new buffer */ struct hoedown_buffer * @@ -176,25 +169,18 @@ hoedown_buffer_printf(struct hoedown_buffer *buf, const char *fmt, ...) return; va_start(ap, fmt); - n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap); + n = vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap); va_end(ap); - if (n < 0) { -#ifdef _MSC_VER - va_start(ap, fmt); - n = _vscprintf(fmt, ap); - va_end(ap); -#else + if (n < 0) return; -#endif - } if ((size_t)n >= buf->asize - buf->size) { if (hoedown_buffer_grow(buf, buf->size + n + 1) < 0) return; va_start(ap, fmt); - n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap); + n = vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap); va_end(ap); } diff --git a/src/buffer.h b/src/buffer.h index d9ff55f..fc2c97b 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -13,7 +13,7 @@ extern "C" { #if defined(_MSC_VER) #define __attribute__(x) -#define inline +#define inline __inline #endif typedef enum { diff --git a/src/html_smartypants.c b/src/html_smartypants.c index 0ce3efd..81d4a1b 100644 --- a/src/html_smartypants.c +++ b/src/html_smartypants.c @@ -5,8 +5,8 @@ #include #include -#if defined(_WIN32) -#define snprintf _snprintf +#ifdef _MSC_VER +#define snprintf _snprintf #endif struct smartypants_data { diff --git a/src/markdown.c b/src/markdown.c index 5f51967..3981a6c 100644 --- a/src/markdown.c +++ b/src/markdown.c @@ -9,7 +9,7 @@ #include "stack.h" -#if defined(_WIN32) +#ifdef _MSC_VER #define strncasecmp _strnicmp #endif