Skip to content

Commit

Permalink
windows: allow non-win32-specific build and address warnings
Browse files Browse the repository at this point in the history
on environments which can build ag for windows with the default Makefile, such
as MXE, print_w32.c was not built since it only appears at Makefile.w32, and so
the build failed.

include this file also at Makefile.am but put the whole of it in #idfef _WIN32.
also add correct includes, removed some unused variables, and initialize others
  • Loading branch information
avih committed Mar 29, 2015
1 parent 7921992 commit c248b51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
@@ -1,7 +1,7 @@
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}

bin_PROGRAMS = ag
ag_SOURCES = src/ignore.c src/ignore.h src/log.c src/log.h src/options.c src/options.h src/print.c src/print.h src/scandir.c src/scandir.h src/search.c src/search.h src/lang.c src/lang.h src/util.c src/util.h src/decompress.c src/decompress.h src/uthash.h src/main.c
ag_SOURCES = src/ignore.c src/ignore.h src/log.c src/log.h src/options.c src/options.h src/print.c src/print_w32.c src/print.h src/scandir.c src/scandir.h src/search.c src/search.h src/lang.c src/lang.h src/util.c src/util.h src/decompress.c src/decompress.h src/uthash.h src/main.c
ag_LDADD = ${PCRE_LIBS} ${LZMA_LIBS} ${ZLIB_LIBS} $(PTHREAD_LIBS)

dist_man_MANS = doc/ag.1
Expand Down
4 changes: 4 additions & 0 deletions src/print.h
Expand Up @@ -14,4 +14,8 @@ void print_column_number(const match_t matches[], size_t last_printed_match,
void print_file_separator(void);
const char *normalize_path(const char *path);

#ifdef _WIN32
int fprintf_w32(FILE* fp, const char* format, ...);
#endif

#endif
14 changes: 10 additions & 4 deletions src/print_w32.c
@@ -1,5 +1,10 @@
#ifdef _WIN32

#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <stdarg.h>
#include "print.h"

#ifndef FOREGROUND_MASK
#define FOREGROUND_MASK (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY)
Expand All @@ -10,8 +15,7 @@

int fprintf_w32(FILE *fp, const char *format, ...) {
va_list args;
int r;
char buf[BUFSIZ], *ptr = buf, *stop;
char buf[BUFSIZ], *ptr = buf;
static WORD attr_old;
static HANDLE stdo = INVALID_HANDLE_VALUE;
WORD attr;
Expand All @@ -21,7 +25,7 @@ int fprintf_w32(FILE *fp, const char *format, ...) {
COORD coord;

va_start(args, format);
r = vsnprintf(buf, sizeof(buf), format, args);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);

stdo = (HANDLE)_get_osfhandle(fileno(fp));
Expand All @@ -34,7 +38,7 @@ int fprintf_w32(FILE *fp, const char *format, ...) {
while (*ptr) {
if (*ptr == '\033') {
unsigned char c;
int i, n = 0, m, v[6], w, h;
int i, n = 0, m = '\0', v[6], w, h;
for (i = 0; i < 6; i++)
v[i] = -1;
ptr++;
Expand Down Expand Up @@ -286,3 +290,5 @@ int fprintf_w32(FILE *fp, const char *format, ...) {
SetConsoleTextAttribute(stdo, attr_old);
return ptr - buf;
}

#endif /* _WIN32 */

0 comments on commit c248b51

Please sign in to comment.