diff --git a/libtcc.c b/libtcc.c index c25fb2c..e29fc35 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1,4 +1,4 @@ -/* +/* vim:ts=8:sw=4:et: * TCC - Tiny C Compiler * * Copyright (c) 2001-2004 Fabrice Bellard @@ -269,6 +269,8 @@ static Sym *global_identifier_push(int v, int t, int c); static void sym_pop(Sym **ptop, Sym *b); BufferedFile *tcc_open(TCCState *s1, const char *filename); +BufferedFile *tcc_open_handle(TCCState*, FILE*); + void tcc_close(BufferedFile *bf); static int tcc_compile(TCCState *s1); @@ -1182,6 +1184,27 @@ static void sym_pop(Sym **ptop, Sym *b) /* I/O layer */ +BufferedFile *tcc_open_handle(TCCState* s1, FILE* fd) +{ + BufferedFile *bf; + bf = tcc_malloc(sizeof(BufferedFile)); + + + bf->fd = (int) fd; + bf->buf_ptr = bf->buffer; + bf->buf_end = bf->buffer; + bf->buffer[0] = CH_EOB; /* put eob symbol */ + +#ifdef _WIN32 + normalize_slashes(bf->filename); +#endif + bf->line_num = 1; + bf->ifndef_macro = 0; + bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; + + return(bf); +} + BufferedFile *tcc_open(TCCState *s1, const char *filename) { int fd; @@ -1196,20 +1219,11 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename) (int)(s1->include_stack_ptr - s1->include_stack), "", filename); if (fd < 0) return NULL; - bf = tcc_malloc(sizeof(BufferedFile)); - bf->fd = fd; - bf->buf_ptr = bf->buffer; - bf->buf_end = bf->buffer; - bf->buffer[0] = CH_EOB; /* put eob symbol */ + + + bf = tcc_open_handle(s1, (FILE*) fd); pstrcpy(bf->filename, sizeof(bf->filename), filename); -#ifdef _WIN32 - normalize_slashes(bf->filename); -#endif - bf->line_num = 1; - bf->ifndef_macro = 0; - bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; - // printf("opening '%s'\n", filename); - return bf; + return(bf); } void tcc_close(BufferedFile *bf) @@ -1325,6 +1339,17 @@ static int tcc_compile(TCCState *s1) return s1->nb_errors != 0 ? -1 : 0; } +int tcc_compile_stream(TCCState *s, FILE* fp) +{ + fprintf(stderr, "tcc_compile_stream: init file\n"); + + file=tcc_open_handle( s, fp ); + + fprintf(stderr, "tcc_compile_stream: compiling\n"); + return( tcc_compile(s) ); + +} + int tcc_compile_string(TCCState *s, const char *str) { BufferedFile bf1, *bf = &bf1; @@ -1899,9 +1924,14 @@ TCCState *tcc_new(void) #else tcc_define_symbol(s, "__WCHAR_TYPE__", "int"); #endif - + + + #ifndef TCC_TARGET_PE /* default library paths */ +#ifdef PREFIX + tcc_add_library_path(s, CONFIG_SYSROOT PREFIX "/lib"); +#endif tcc_add_library_path(s, CONFIG_SYSROOT "/usr/local/lib"); tcc_add_library_path(s, CONFIG_SYSROOT "/usr/lib"); tcc_add_library_path(s, CONFIG_SYSROOT "/lib"); diff --git a/libtcc.h b/libtcc.h index 96070e2..6fea4fd 100644 --- a/libtcc.h +++ b/libtcc.h @@ -1,5 +1,7 @@ #ifndef LIBTCC_H #define LIBTCC_H +#include + #ifdef LIBTCC_AS_DLL #define LIBTCCAPI __declspec(dllexport) @@ -57,6 +59,9 @@ LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename); error. */ LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf); + +LIBTCCAPI int tcc_compile_stream(TCCState *s, FILE* file); + /*****************************/ /* linking commands */ diff --git a/tcc.h b/tcc.h index bf242e5..a27a193 100644 --- a/tcc.h +++ b/tcc.h @@ -1,4 +1,4 @@ -/* +/* vim:ts=8:sw=4:et: * TCC - Tiny C Compiler * * Copyright (c) 2001-2004 Fabrice Bellard