From: Dale Weiler Date: Fri, 11 Oct 2013 10:36:05 +0000 (-0400) Subject: Some more cleanup X-Git-Tag: 0.3.5~35^2~2^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=63fdab8422684395fa3b599a26f16c3eedb15cc8;p=xonotic%2Fgmqcc.git Some more cleanup --- diff --git a/conout.c b/conout.c index 1176e9b..c22758b 100644 --- a/conout.c +++ b/conout.c @@ -20,9 +20,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#define GMQCC_PLATFORM_HEADER +#include #include "gmqcc.h" -#include "platform.h" #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) @@ -50,10 +49,8 @@ static con_t console; * checks. */ static void con_enablecolor(void) { - 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 == (fs_file_t*)stderr || console.handle_out == (fs_file_t*)stdout) - console.color_out = !!(platform_isatty(STDOUT_FILENO)); + console.color_err = util_isatty(console.handle_err); + console.color_out = util_isatty(console.handle_out); } /* diff --git a/gmqcc.h b/gmqcc.h index ad8948c..9d00687 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -312,6 +312,9 @@ const char *util_strerror(int err); const struct tm *util_localtime(const time_t *timer); const char *util_ctime (const time_t *timer); +typedef struct fs_file_s fs_file_t; +int util_isatty (fs_file_t *); + /* * A flexible vector implementation: all vector pointers contain some * data about themselfs exactly - sizeof(vector_t) behind the pointer @@ -404,7 +407,7 @@ int util_snprintf(char *str, size_t, const char *fmt, ...); #define FS_FILE_EOF -1 typedef struct fs_dir_s fs_dir_t; -typedef struct fs_file_s fs_file_t; +/*typedef struct fs_file_s fs_file_t;*/ typedef struct dirent fs_dirent_t; void fs_file_close (fs_file_t *); diff --git a/platform.h b/platform.h index bde63d7..5360572 100644 --- a/platform.h +++ b/platform.h @@ -75,9 +75,71 @@ # include #endif /*!_WIN32*/ +/* + * Function: platform_vsnprintf + * Write formatted output using a pointer to a lis of arguments. + * + * Parameters: + * buffer - Storage location for output. + * bytes - Maximum number of characters to write. + * format - Format specification. + * arg - Variable argument list. + * + * Returns: + * The number of characters written if the number of characters to write + * is less than or equal to `bytes`; if the number of characters to write + * is greater than `bytes`, this function returns -1 indicating that the + * output has been truncated. The return value does not include the + * terminating null, if one is written. + * + * Remarks: + * Function takes pointer to an argument list, then formats the data, + * and writes up to `bytes` characters to the memory pointed to by + * `buffer`. If there is room at the end (that is, if the number of + * character to write is less than `bytes`), the buffer will be null-terminated. + */ int platform_vsnprintf(char *buffer, size_t bytes, const char *format, va_list arg); -int platform_vsscanf(const char *str, const char *format, va_list arg); + +/* + * Function: platform_vsscanf + * Reads formatted data from a string. + * + * Parameters: + * buffer - Stored data to read. + * format - Format specification. + * arg - Variable argument list. + * + * Returns: + * The number of fields that are successfully converted and assigned; + * the return value does not include fields that were read but not + * assigned. A return vlaue of 0 indicated that no fields were assigned. + * The return value if EOF for error or if the end of the string is + * reached before the first conversion. + * + * Remarks: + * Reads data from `buffer` into the locations that are given by each + * argument in the `arg` argument list. Every argument in the list must + * be a pointer to a variable that has a type that corresponds to a + * type specifier in `format`. The `format` argument controls th + * interpretation of the input fields and has the same form and function + * as the `format` argument for the *scanf* function. If copying takes + * place between strings that overlap, the behaviour is undefined. + */ +int platform_vsscanf(const char *buffer, const char *format, va_list arg); + +/* + * Function: platform_localtime + * Convert a time value and correct for the local time zone. + * + * Parameters + * timer - Pointer to stored time. + * + * Returns: + * A pointer to a structure result, or NULL if the date passed to + * the function is before midnight, January 1, 1970. + */ const struct tm *platform_localtime(const time_t *timer); + const char *platform_ctime(const time_t *timer); char *platform_strncat(char *dest, const char *src, size_t num); const char *platform_tmpnam(char *str); diff --git a/test.c b/test.c index 75f7b3b..2672cb6 100644 --- a/test.c +++ b/test.c @@ -20,7 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#define GMQCC_PLATFORM_HEADER +#define GMQCC_PLATFORM_HEADER /* TODO: eliminate! */ #include #include diff --git a/util.c b/util.c index 32051a3..baff4a4 100644 --- a/util.c +++ b/util.c @@ -280,6 +280,12 @@ const char *util_ctime(const time_t *timer) { return platform_ctime(timer); } +bool util_isatty(fs_file_t *file) { + if (file == (fs_file_t*)stdout) return !!platform_isatty(STDOUT_FILENO); + if (file == (fs_file_t*)stderr) return !!platform_isatty(STDERR_FILENO); + return false; +} + void util_seed(uint32_t value) { srand((int)value); }