From: Dale Weiler Date: Fri, 11 Oct 2013 07:59:25 +0000 (-0400) Subject: More cleanups X-Git-Tag: 0.3.5~35^2~2^2~9 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=033cf7c7d397c3fdc23a1448b0068000219efef6;p=xonotic%2Fgmqcc.git More cleanups --- diff --git a/Makefile b/Makefile index 341be42..0b57b9c 100644 --- a/Makefile +++ b/Makefile @@ -153,7 +153,7 @@ ansi.o: platform.h util.o: gmqcc.h opts.def stat.o: gmqcc.h opts.def fs.o: gmqcc.h opts.def platform.h -conout.o: gmqcc.h opts.def +conout.o: gmqcc.h opts.def platform.h opts.o: gmqcc.h opts.def platform.h test.o: gmqcc.h opts.def platform.h main.o: gmqcc.h opts.def lexer.h diff --git a/ansi.c b/ansi.c index 26604fe..a6b2eda 100644 --- a/ansi.c +++ b/ansi.c @@ -96,6 +96,10 @@ size_t platform_fwrite(const void *ptr, size_t size, size_t count, FILE *stream) return fwrite(ptr, size, count, stream); } +int platform_fflush(FILE *stream) { + return fflush(stream); +} + int platform_vfprintf(FILE *stream, const char *format, va_list arg) { return vfprintf(stream, format, arg); } diff --git a/code.c b/code.c index 5703e50..05ffe70 100644 --- a/code.c +++ b/code.c @@ -401,7 +401,7 @@ static bool code_write_memory(code_t *code, uint8_t **datmem, size_t *sizedat, u bool code_write(code_t *code, const char *filename, const char *lnofile) { prog_header_t code_header; - FILE *fp = NULL; + fs_file_t *fp = NULL; code_create_header(code, &code_header, filename, lnofile); diff --git a/conout.c b/conout.c index bc55b04..5f8454d 100644 --- a/conout.c +++ b/conout.c @@ -20,156 +20,20 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include - #include "gmqcc.h" #include "platform.h" -#define GMQCC_IS_STDOUT(X) ((FILE*)((void*)X) == stdout) -#define GMQCC_IS_STDERR(X) ((FILE*)((void*)X) == stderr) +#define GMQCC_IS_STDOUT(X) ((fs_file_t*)((void*)X) == (fs_file_t*)stdout) +#define GMQCC_IS_STDERR(X) ((fs_file_t*)((void*)X) == (fs_file_t*)stderr) #define GMQCC_IS_DEFINE(X) (GMQCC_IS_STDERR(X) || GMQCC_IS_STDOUT(X)) typedef struct { - FILE *handle_err; - FILE *handle_out; - - int color_err; - int color_out; + fs_file_t *handle_err; + fs_file_t *handle_out; + int color_err; + int color_out; } con_t; -/* - * Doing colored output on windows is fucking stupid. The linux way is - * the real way. So we emulate it on windows :) - */ -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include - -/* - * Windows doesn't have constants for FILENO, sadly but the docs tell - * use the constant values. - */ -#undef STDERR_FILENO -#undef STDOUT_FILENO -#define STDERR_FILENO 2 -#define STDOUT_FILENO 1 - -enum { - RESET = 0, - BOLD = 1, - BLACK = 30, - RED, - GREEN, - YELLOW, - BLUE, - MAGENTA, - CYAN, - GRAY, - WHITE = GRAY -}; - -enum { - WBLACK, - WBLUE, - WGREEN = 2, - WRED = 4, - WINTENSE = 8, - WCYAN = WBLUE | WGREEN, - WMAGENTA = WBLUE | WRED, - WYELLOW = WGREEN | WRED, - WWHITE = WBLUE | WGREEN | WRED -}; - -static const int ansi2win[] = { - WBLACK, - WRED, - WGREEN, - WYELLOW, - WBLUE, - WMAGENTA, - WCYAN, - WWHITE -}; - -static int win_fputs(FILE *h, const char *str) { - /* state for translate */ - int acolor = 0; - int wcolor = 0; - int icolor = 0; - int state = 0; - - /* attributes */ - int intense = -1; - int colors[] = {-1, -1 }; - int colorpos = 1; - int length = 0; - CONSOLE_SCREEN_BUFFER_INFO cinfo; - GetConsoleScreenBufferInfo ( - (GMQCC_IS_STDOUT(h)) ? - GetStdHandle(STD_OUTPUT_HANDLE) : - GetStdHandle(STD_ERROR_HANDLE), &cinfo - ); - icolor = cinfo.wAttributes; - - while (*str) { - if (*str == '\x1B') - state = '\x1B'; - else if (state == '\x1B' && *str == '[') - state = '['; - else if (state == '[') { - if (*str != 'm') { - colors[colorpos] = *str; - colorpos--; - } else { - int find; - int mult; - for (find = colorpos + 1, acolor = 0, mult = 1; find < 2; find++) { - acolor += (colors[find] - 48) * mult; - mult *= 10; - } - - /* convert to windows color */ - if (acolor == BOLD) - intense = WINTENSE; - else if (acolor == RESET) { - intense = WBLACK; - wcolor = icolor; - } - else if (BLACK <= acolor && acolor <= WHITE) - wcolor = ansi2win[acolor - 30]; - else if (acolor == 90) { - /* special gray really white man */ - wcolor = WWHITE; - intense = WBLACK; - } - - SetConsoleTextAttribute ( - (GMQCC_IS_STDOUT(h)) ? - GetStdHandle(STD_OUTPUT_HANDLE) : - GetStdHandle(STD_ERROR_HANDLE), - - wcolor | intense | (icolor & 0xF0) - ); - colorpos = 1; - state = -1; - } - } else { - fs_file_write(str, 1, 1, stdout); - length ++; - } - str++; - } - /* restore */ - SetConsoleTextAttribute( - (GMQCC_IS_STDOUT(h)) ? - GetStdHandle(STD_OUTPUT_HANDLE) : - GetStdHandle(STD_ERROR_HANDLE), - icolor - ); - return length; -} -#endif - /* * We use standard files as default. These can be changed at any time * with con_change(F, F) @@ -185,9 +49,9 @@ static con_t console; * checks. */ static void con_enablecolor(void) { - if (console.handle_err == stderr || console.handle_err == stdout) + if (console.handle_err == (fs_file_t*)stderr || console.handle_err == (fs_file_t*)stdout) console.color_err = !!(platform_isatty(STDERR_FILENO)); - if (console.handle_out == stderr || console.handle_out == stdout) + if (console.handle_out == (fs_file_t*)stderr || console.handle_out == (fs_file_t*)stdout) console.color_out = !!(platform_isatty(STDOUT_FILENO)); } @@ -196,19 +60,8 @@ static void con_enablecolor(void) { * arguments. This colorizes for windows as well via translate * step. */ -static int con_write(FILE *handle, const char *fmt, va_list va) { - int ln; - #ifndef _WIN32 - ln = vfprintf(handle, fmt, va); - #else - { - char data[4096]; - memset(data, 0, sizeof(data)); - platform_vsnprintf(data, sizeof(data), fmt, va); - ln = (GMQCC_IS_DEFINE(handle)) ? win_fputs(handle, data) : fs_file_puts(handle, data); - } - #endif - return ln; +static int con_write(fs_file_t *handle, const char *fmt, va_list va) { + return vfprintf((FILE*)handle, fmt, va); } /********************************************************************** @@ -232,8 +85,8 @@ void con_color(int state) { } void con_init() { - console.handle_err = stderr; - console.handle_out = stdout; + console.handle_err = (fs_file_t*)stderr; + console.handle_out = (fs_file_t*)stdout; con_enablecolor(); } @@ -255,16 +108,16 @@ void con_reset() { int con_change(const char *out, const char *err) { con_close(); - if (!out) out = (const char *)((!console.handle_out) ? stdout : console.handle_out); - if (!err) err = (const char *)((!console.handle_err) ? stderr : console.handle_err); + if (!out) out = (const char *)((!console.handle_out) ? (fs_file_t*)stdout : console.handle_out); + if (!err) err = (const char *)((!console.handle_err) ? (fs_file_t*)stderr : console.handle_err); if (GMQCC_IS_DEFINE(out)) { - console.handle_out = GMQCC_IS_STDOUT(out) ? stdout : stderr; + console.handle_out = (fs_file_t*)(GMQCC_IS_STDOUT(out) ? stdout : stderr); con_enablecolor(); } else if (!(console.handle_out = fs_file_open(out, "w"))) return 0; if (GMQCC_IS_DEFINE(err)) { - console.handle_err = GMQCC_IS_STDOUT(err) ? stdout : stderr; + console.handle_err = (fs_file_t*)(GMQCC_IS_STDOUT(err) ? stdout : stderr); con_enablecolor(); } else if (!(console.handle_err = fs_file_open(err, "w"))) return 0; @@ -275,11 +128,11 @@ int con_change(const char *out, const char *err) { * Defaultizer because stdio.h shouldn't be used anywhere except here * and inside file.c To prevent mis-match of wrapper-interfaces. */ -FILE *con_default_out() { - return (console.handle_out = stdout); +fs_file_t *con_default_out() { + return (fs_file_t*)(console.handle_out = (fs_file_t*)stdout); } -FILE *con_default_err() { - return (console.handle_err = stderr); +fs_file_t *con_default_err() { + return (fs_file_t*)(console.handle_err = (fs_file_t*)stderr); } int con_verr(const char *fmt, va_list va) { @@ -323,10 +176,10 @@ static void con_vprintmsg_c(int level, const char *name, size_t line, size_t col CON_RED }; - int err = !!(level == LVL_ERROR); - int color = (err) ? console.color_err : console.color_out; - int (*print) (const char *, ...) = (err) ? &con_err : &con_out; - int (*vprint)(const char *, va_list) = (err) ? &con_verr : &con_vout; + int err = !!(level == LVL_ERROR); + int color = (err) ? console.color_err : console.color_out; + int (*print) (const char *, ...) = (err) ? &con_err : &con_out; + int (*vprint)(const char *, va_list) = (err) ? &con_verr : &con_vout; if (color) print("\033[0;%dm%s:%d:%d: \033[0;%dm%s: \033[0m", CON_CYAN, name, (int)line, (int)column, sel[level], msgtype); diff --git a/exec.c b/exec.c index 8f68d5c..92d1e24 100644 --- a/exec.c +++ b/exec.c @@ -53,9 +53,9 @@ static void qcvmerror(qc_program_t *prog, const char *fmt, ...) qc_program_t* prog_load(const char *filename, bool skipversion) { - qc_program_t *prog; prog_header_t header; - FILE *file = fs_file_open(filename, "rb"); + qc_program_t *prog; + fs_file_t *file = fs_file_open(filename, "rb"); if (!file) return NULL; @@ -351,7 +351,7 @@ static void trace_print_global(qc_program_t *prog, unsigned int glob, int vtype) done: if (len < (int)sizeof(spaces)-1) { spaces[sizeof(spaces)-1-len] = 0; - fs_file_puts(stdout, spaces); + fs_file_puts((fs_file_t*)stdout, spaces); spaces[sizeof(spaces)-1-len] = ' '; } } diff --git a/fs.c b/fs.c index beb4819..c91805e 100644 --- a/fs.c +++ b/fs.c @@ -23,62 +23,66 @@ #include "gmqcc.h" #include "platform.h" -FILE *fs_file_open(const char *filename, const char *mode) { - return platform_fopen(filename, mode); +fs_file_t *fs_file_open(const char *filename, const char *mode) { + return (fs_file_t*)platform_fopen(filename, mode); } -size_t fs_file_read(void *buffer, size_t size, size_t count, FILE *fp) { - return platform_fread(buffer, size, count, fp); +size_t fs_file_read(void *buffer, size_t size, size_t count, fs_file_t *fp) { + return platform_fread(buffer, size, count, (FILE*)fp); } -int fs_file_printf(FILE *fp, const char *format, ...) { +int fs_file_printf(fs_file_t *fp, const char *format, ...) { int rt; va_list va; va_start(va, format); - rt = platform_vfprintf(fp, format, va); + rt = platform_vfprintf((FILE*)fp, format, va); va_end (va); return rt; } -void fs_file_close(FILE *fp) { - platform_fclose (fp); +void fs_file_close(fs_file_t *fp) { + platform_fclose((FILE*)fp); } size_t fs_file_write ( const void *buffer, size_t size, size_t count, - FILE *fp + fs_file_t *fp ) { - return platform_fwrite(buffer, size, count, fp); + return platform_fwrite(buffer, size, count, (FILE*)fp); } -int fs_file_error(FILE *fp) { - return platform_ferror(fp); +int fs_file_error(fs_file_t *fp) { + return platform_ferror((FILE*)fp); } -int fs_file_getc(FILE *fp) { - return platform_fgetc(fp); +int fs_file_getc(fs_file_t *fp) { + return platform_fgetc((FILE*)fp); } -int fs_file_puts(FILE *fp, const char *str) { - return platform_fputs(str, fp); +int fs_file_puts(fs_file_t *fp, const char *str) { + return platform_fputs(str, (FILE*)fp); } -int fs_file_seek(FILE *fp, long int off, int whence) { - return platform_fseek(fp, off, whence); +int fs_file_seek(fs_file_t *fp, long int off, int whence) { + return platform_fseek((FILE*)fp, off, whence); } -long int fs_file_tell(FILE *fp) { - return platform_ftell(fp); +long int fs_file_tell(fs_file_t *fp) { + return platform_ftell((FILE*)fp); +} + +int fs_file_flush(fs_file_t *fp) { + return platform_fflush((FILE*)fp); } /* * Implements libc getline for systems that don't have it, which is * assmed all. This works the same as getline(). */ -int fs_file_getline(char **lineptr, size_t *n, FILE *stream) { +int fs_file_getline(char **lineptr, size_t *n, fs_file_t *stream) { int chr; int ret; char *pos; @@ -104,7 +108,7 @@ int fs_file_getline(char **lineptr, size_t *n, FILE *stream) { pos = *n - chr + *lineptr; } - if (ferror(stream)) + if (fs_file_error(stream)) return -1; if (c == EOF) { if (pos == *lineptr) @@ -126,14 +130,14 @@ int fs_dir_make(const char *path) { return platform_mkdir(path, 0700); } -DIR *fs_dir_open(const char *name) { - return platform_opendir(name); +fs_dir_t *fs_dir_open(const char *name) { + return (fs_dir_t*)platform_opendir(name); } -int fs_dir_close(DIR *dir) { - return platform_closedir(dir); +int fs_dir_close(fs_dir_t *dir) { + return platform_closedir((DIR*)dir); } -struct dirent *fs_dir_read(DIR *dir) { - return platform_readdir(dir); +fs_dirent_t *fs_dir_read(fs_dir_t *dir) { + return (fs_dirent_t*)platform_readdir((DIR*)dir); } diff --git a/ftepp.c b/ftepp.c index b07fa97..e3cbb0d 100644 --- a/ftepp.c +++ b/ftepp.c @@ -1273,7 +1273,7 @@ static void unescape(const char *str, char *out) { static char *ftepp_include_find_path(const char *file, const char *pathfile) { - FILE *fp; + fs_file_t *fp; char *filename = NULL; const char *last_slash; size_t len; diff --git a/gmqcc.h b/gmqcc.h index 43e2aa0..b7f1f8f 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -252,43 +252,6 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \ # endif #endif /*! !defined (PLATFORM_BYTE_ORDER) */ -/* - * On windows systems where we're not compiling with MING32 we need a - * little extra help on dependinces for implementing our own dirent.h - * in fs.c. - */ -#if defined(_WIN32) && !defined(__MINGW32__) -# define _WIN32_LEAN_AND_MEAN -# include -# include -# include - - struct dirent { - long d_ino; - unsigned short d_reclen; - unsigned short d_namlen; - char d_name[FILENAME_MAX]; - }; - - typedef struct { - struct _finddata_t dd_dta; - struct dirent dd_dir; - long dd_handle; - int dd_stat; - char dd_name[1]; - } DIR; - /* - * Visual studio also lacks S_ISDIR for sys/stat.h, so we emulate this as well - * which is not hard at all. - */ -# ifdef S_ISDIR -# undef S_ISDIR -# endif /*! S_ISDIR */ -# define S_ISDIR(X) ((X)&_S_IFDIR) -#else -# include -#endif /*! _WIN32 && !defined(__MINGW32__) */ - /* stat.c */ void stat_info (void); char *stat_mem_strdup (const char *, size_t, const char *, bool); @@ -425,24 +388,29 @@ void *util_htgeth(hash_table_t *ht, const char *key, size_t hash); /* fs.c */ -void fs_file_close (FILE *); -int fs_file_error (FILE *); -int fs_file_getc (FILE *); -int fs_file_printf (FILE *, const char *, ...); -int fs_file_puts (FILE *, const char *); -int fs_file_seek (FILE *, long int, int); -long int fs_file_tell (FILE *); +typedef struct fs_dir_s fs_dir_t; +typedef struct fs_file_s fs_file_t; +typedef struct dirent fs_dirent_t; + +void fs_file_close (fs_file_t *); +int fs_file_error (fs_file_t *); +int fs_file_getc (fs_file_t *); +int fs_file_printf (fs_file_t *, const char *, ...); +int fs_file_puts (fs_file_t *, const char *); +int fs_file_seek (fs_file_t *, long int, int); +long fs_file_tell (fs_file_t *); +int fs_file_flush (fs_file_t *); -size_t fs_file_read (void *, size_t, size_t, FILE *); -size_t fs_file_write (const void *, size_t, size_t, FILE *); +size_t fs_file_read (void *, size_t, size_t, fs_file_t *); +size_t fs_file_write (const void *, size_t, size_t, fs_file_t *); -FILE *fs_file_open (const char *, const char *); -int fs_file_getline(char **, size_t *, FILE *); +fs_file_t *fs_file_open (const char *, const char *); +int fs_file_getline(char **, size_t *, fs_file_t *); int fs_dir_make (const char *); -DIR *fs_dir_open (const char *); -int fs_dir_close (DIR *); -struct dirent *fs_dir_read (DIR *); +fs_dir_t *fs_dir_open (const char *); +int fs_dir_close (fs_dir_t *); +fs_dirent_t *fs_dir_read (fs_dir_t *); /* correct.c */ typedef struct correct_trie_s { @@ -780,8 +748,8 @@ enum { LVL_ERROR }; -FILE *con_default_out(void); -FILE *con_default_err(void); +fs_file_t *con_default_out(void); +fs_file_t *con_default_err(void); void con_vprintmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, va_list ap); void con_printmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, ...); diff --git a/lexer.c b/lexer.c index 03c27d1..7f49652 100644 --- a/lexer.c +++ b/lexer.c @@ -181,8 +181,8 @@ static void lex_token_new(lex_file *lex) lex_file* lex_open(const char *file) { - lex_file *lex; - FILE *in = fs_file_open(file, "rb"); + lex_file *lex; + fs_file_t *in = fs_file_open(file, "rb"); if (!in) { lexerror(NULL, "open failed: '%s'\n", file); diff --git a/lexer.h b/lexer.h index 24e29dd..3184fcc 100644 --- a/lexer.h +++ b/lexer.h @@ -105,7 +105,7 @@ typedef struct { } frame_macro; typedef struct lex_file_s { - FILE *file; + fs_file_t *file; const char *open_string; size_t open_string_length; size_t open_string_pos; diff --git a/main.c b/main.c index 9a76706..74d927d 100644 --- a/main.c +++ b/main.c @@ -531,7 +531,7 @@ static bool options_parse(int argc, char **argv) { } /* returns the line number, or -1 on error */ -static bool progs_nextline(char **out, size_t *alen,FILE *src) { +static bool progs_nextline(char **out, size_t *alen, fs_file_t *src) { int len; char *line; char *start; @@ -562,7 +562,7 @@ int main(int argc, char **argv) { bool opts_output_free = false; bool operators_free = false; bool progs_src = false; - FILE *outfile = NULL; + fs_file_t *outfile = NULL; struct parser_s *parser = NULL; struct ftepp_s *ftepp = NULL; @@ -667,10 +667,10 @@ int main(int argc, char **argv) { } if (!vec_size(items)) { - FILE *src; - char *line = NULL; - size_t linelen = 0; - bool hasline = false; + fs_file_t *src; + char *line = NULL; + size_t linelen = 0; + bool hasline = false; progs_src = true; diff --git a/msvc.c b/msvc.c index 54543ff..225cd1c 100644 --- a/msvc.c +++ b/msvc.c @@ -130,6 +130,10 @@ size_t platform_fwrite(const void *ptr, size_t size, size_t count, FILE *stream) return fwrite(ptr, size, count, stream); } +int platform_fflush(FILE *stream) { + return fflush(stream); +} + int platform_vfprintf(FILE *stream, const char *format, va_list arg) { return vfprintf_s(stream, format, arg); } diff --git a/opts.c b/opts.c index fd10233..6c30225 100644 --- a/opts.c +++ b/opts.c @@ -214,7 +214,7 @@ static char *opts_ini_next(const char *s, char c) { } static size_t opts_ini_parse ( - FILE *filehandle, + fs_file_t *filehandle, char *(*loadhandle)(const char *, const char *, const char *), char **errorhandle ) { @@ -381,7 +381,7 @@ void opts_ini_init(const char *file) { */ char *error = NULL; size_t line; - FILE *ini; + fs_file_t *ini; if (!file) { /* try ini */ diff --git a/pak.c b/pak.c index ba820ef..c7974b5 100644 --- a/pak.c +++ b/pak.c @@ -125,7 +125,7 @@ static void pak_tree_build(const char *entry) { typedef struct { pak_directory_t *directories; pak_header_t header; - FILE *handle; + fs_file_t *handle; bool insert; } pak_file_t; @@ -267,7 +267,7 @@ static bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdi pak_directory_t *dir = NULL; unsigned char *dat = NULL; char *local = NULL; - FILE *out = NULL; + fs_file_t *out = NULL; if (!pak_exists(pak, file, &dir)) { return false; @@ -334,7 +334,7 @@ static bool pak_insert_one(pak_file_t *pak, const char *file) { pak_directory_t dir; unsigned char *dat; long len; - FILE *fp; + fs_file_t *fp; /* * We don't allow insertion on files that already exist within the diff --git a/platform.h b/platform.h index 2602636..e2aee71 100644 --- a/platform.h +++ b/platform.h @@ -27,11 +27,46 @@ #include #include -#ifndef _MSC_VER +#ifdef _WIN32 +# undef STDERR_FILENO +# undef STDOUT_FILENO +# define STDERR_FILENO 2 +# define STDOUT_FILENO 1 + +# ifndef __MINGW32__ +# define _WIN32_LEAN_AND_MEAN +# include +# include +# include + + struct dirent { + long d_ino; + unsigned short d_reclen; + unsigned short d_namlen; + char d_name[FILENAME_MAX]; + }; + + typedef struct { + struct _finddata_t dd_dta; + struct dirent dd_dir; + long dd_handle; + int dd_stat; + char dd_name[1]; + } DIR; + +# ifdef S_ISDIR +# undef S_ISDIR +# endif /*! S_ISDIR */ +# define S_ISDIR(X) ((X)&_S_IFDIR) +# else +# include +# endif /*!__MINGW32__*/ +#else # include # include +# include # include -#endif +#endif /*!_WIN32*/ int platform_vsnprintf(char *buffer, size_t bytes, const char *format, va_list arg); int platform_sscanf(const char *str, const char *format, ...); @@ -47,6 +82,7 @@ const char *platform_strerror(int err); FILE *platform_fopen(const char *filename, const char *mode); size_t platform_fread(void *ptr, size_t size, size_t count, FILE *stream); size_t platform_fwrite(const void *ptr, size_t size, size_t count, FILE *stream); +int platform_fflush(FILE *stream); int platform_vfprintf(FILE *stream, const char *format, va_list arg); int platform_fclose(FILE *stream); int platform_ferror(FILE *stream); diff --git a/test.c b/test.c index a0484be..77ce860 100644 --- a/test.c +++ b/test.c @@ -52,15 +52,15 @@ static const char *task_bins[] = { #include #include typedef struct { - FILE *handles[3]; - int pipes [3]; + fs_file_t *handles[3]; + int pipes [3]; int stderr_fd; int stdout_fd; int pid; } popen_t; -static FILE ** task_popen(const char *command, const char *mode) { +static fs_file_t **task_popen(const char *command, const char *mode) { int inhandle [2]; int outhandle [2]; int errhandle [2]; @@ -102,9 +102,9 @@ static FILE ** task_popen(const char *command, const char *mode) { data->pipes [1] = outhandle[0]; data->pipes [2] = errhandle[0]; - data->handles[0] = fdopen(inhandle [1], "w"); - data->handles[1] = fdopen(outhandle[0], mode); - data->handles[2] = fdopen(errhandle[0], mode); + data->handles[0] = (fs_file_t*)fdopen(inhandle [1], "w"); + data->handles[1] = (fs_file_t*)fdopen(outhandle[0], mode); + data->handles[2] = (fs_file_t*)fdopen(errhandle[0], mode); /* sigh */ vec_free(argv); @@ -136,7 +136,7 @@ task_popen_error_0: return NULL; } -static int task_pclose(FILE **handles) { +static int task_pclose(fs_file_t **handles) { popen_t *data = (popen_t*)handles; int status = 0; @@ -152,12 +152,12 @@ static int task_pclose(FILE **handles) { } #else typedef struct { - FILE *handles[3]; - char name_err[L_tmpnam]; - char name_out[L_tmpnam]; + fs_file_t *handles[3]; + char name_err[L_tmpnam]; + char name_out[L_tmpnam]; } popen_t; - static FILE **task_popen(const char *command, const char *mode) { + static fs_file_t **task_popen(const char *command, const char *mode) { char *cmd = NULL; popen_t *open = (popen_t*)mem_a(sizeof(popen_t)); @@ -178,10 +178,12 @@ static int task_pclose(FILE **handles) { return open->handles; } - static int task_pclose(FILE **files) { + static int task_pclose(fs_file_t **files) { popen_t *open = ((popen_t*)files); + fs_file_close(files[1]); fs_file_close(files[2]); + remove(open->name_err); remove(open->name_out); @@ -357,7 +359,7 @@ static bool task_template_generate(task_template_t *tmpl, char tag, const char * return true; } -static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *fp, size_t *pad) { +static bool task_template_parse(const char *file, task_template_t *tmpl, fs_file_t *fp, size_t *pad) { char *data = NULL; char *back = NULL; size_t size = 0; @@ -498,7 +500,7 @@ static task_template_t *task_template_compile(const char *file, const char *dir, /* a page should be enough */ char fullfile[4096]; size_t filepadd = 0; - FILE *tempfile = NULL; + fs_file_t *tempfile = NULL; task_template_t *tmpl = NULL; platform_snprintf(fullfile, sizeof(fullfile), "%s/%s", dir, file); @@ -653,9 +655,9 @@ static void task_template_destroy(task_template_t *tmpl) { */ typedef struct { task_template_t *tmpl; - FILE **runhandles; - FILE *stderrlog; - FILE *stdoutlog; + fs_file_t **runhandles; + fs_file_t *stderrlog; + fs_file_t *stdoutlog; char *stdoutlogfile; char *stderrlogfile; bool compiled; @@ -669,8 +671,8 @@ static task_t *task_tasks = NULL; */ static bool task_propagate(const char *curdir, size_t *pad, const char *defs) { bool success = true; - DIR *dir; - struct dirent *files; + fs_dir_t *dir; + fs_dirent_t *files; struct stat directory; char buffer[4096]; size_t found = 0; @@ -866,9 +868,9 @@ static bool task_propagate(const char *curdir, size_t *pad, const char *defs) { * left behind from a previous invoke of the test-suite. */ static void task_precleanup(const char *curdir) { - DIR *dir; - struct dirent *files; - char buffer[4096]; + fs_dir_t *dir; + fs_dirent_t *files; + char buffer[4096]; dir = fs_dir_open(curdir); @@ -934,7 +936,7 @@ static bool task_trymatch(size_t i, char ***line) { bool success = true; bool process = true; int retval = EXIT_SUCCESS; - FILE *execute; + fs_file_t *execute; char buffer[4096]; task_template_t *tmpl = task_tasks[i].tmpl; @@ -958,7 +960,7 @@ static bool task_trymatch(size_t i, char ***line) { ); } - execute = popen(buffer, "r"); + execute = (fs_file_t*)popen(buffer, "r"); if (!execute) return false; } else if (!strcmp(tmpl->proceduretype, "-pp")) { @@ -1000,7 +1002,7 @@ static bool task_trymatch(size_t i, char ***line) { if (!process) fs_file_close(execute); else - pclose(execute); + pclose((FILE*)execute); return false; } @@ -1060,7 +1062,7 @@ static bool task_trymatch(size_t i, char ***line) { } if (process) - retval = pclose(execute); + retval = pclose((FILE*)execute); else fs_file_close(execute); @@ -1147,7 +1149,7 @@ static size_t task_schedualize(size_t *pad) { } fs_file_puts (task_tasks[i].stderrlog, data); - fflush(task_tasks[i].stderrlog); /* fast flush for read */ + fs_file_flush(task_tasks[i].stderrlog); /* fast flush for read */ } if (!task_tasks[i].compiled && strcmp(task_tasks[i].tmpl->proceduretype, "-fail")) {