]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Some more cleanup
authorDale Weiler <killfieldengine@gmail.com>
Fri, 11 Oct 2013 10:36:05 +0000 (06:36 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Fri, 11 Oct 2013 10:36:05 +0000 (06:36 -0400)
conout.c
gmqcc.h
platform.h
test.c
util.c

index 1176e9bda81fc5a655c3508d6b3f0c80045505c9..c22758be9c178a43a7ac61617405a7124fcd7b4f 100644 (file)
--- 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 <stdio.h>
 #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 ad8948c32cc2cf8bb2d6542b4c6a77f4e1752633..9d00687c8daf7c57c9048af9f62c2059863a8cf0 100644 (file)
--- 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 *);
index bde63d7023e2a9047435f52eb1cad3653ddc60c6..5360572bd592b593911ac131786022b9a158691b 100644 (file)
 #   include <dirent.h>
 #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 75f7b3b3470783b63ec53b5e628d9d5e52fa28fb..2672cb6a93fa955cf6f772d49ec41348aa1789a6 100644 (file)
--- 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 <stdlib.h>
 #include <string.h>
 
diff --git a/util.c b/util.c
index 32051a3f0d70997e24c36cb30fc284728cfc7bf6..baff4a435c0c2268624a6982c4d5cbe0371644a6 100644 (file)
--- 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);
 }