]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - util.c
Fixes to README
[xonotic/gmqcc.git] / util.c
diff --git a/util.c b/util.c
index a15590791f009719d85c23e47dc3c9ca744636ef..6e02fe76aa18225953f4173f070dee5253b52e90 100644 (file)
--- a/util.c
+++ b/util.c
@@ -20,9 +20,6 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
 #include <stdarg.h>
 #include "gmqcc.h"
  
@@ -39,7 +36,7 @@ void *util_memory_a(unsigned int byte, unsigned int line, const char *file) {
        data->byte = byte;
        data->file = file;
        
-       printf("[MEM] allocation: %08u (bytes) at %s:%u\n", byte, file, line);
+       util_debug("MEM", "allocation: %08u (bytes) at %s:%u\n", byte, file, line);
        return (void*)((uintptr_t)data+sizeof(struct memblock_t));
 }
 
@@ -48,7 +45,7 @@ void util_memory_d(void *ptrn, unsigned int line, const char *file) {
        void              *data = (void*)((uintptr_t)ptrn-sizeof(struct memblock_t));
        struct memblock_t *info = (struct memblock_t*)data;
        
-       printf("[MEM] released:   %08u (bytes) at %s:%u\n", info->byte, file, line);
+       util_debug("MEM", "released:   %08u (bytes) at %s:%u\n", info->byte, file, line);
        free(data);
 }
 
@@ -81,9 +78,35 @@ char *util_strdup(const char *s) {
        return ptr;
 }
 
-void util_debug(const char *ms, ...) {
+/*
+ * Removed quotes from a string, escapes from \ in string
+ * as well.  This function shouldn't be used to create a
+ * char array that is later freed (it uses pointer arith)
+ */
+char *util_strrq(char *s) {
+       char *dst = s;
+       char *src = s;
+       char  chr;
+       while ((chr = *src++) != '\0') {
+               if (chr == '\\') {
+                       *dst++ = chr;
+                       if ((chr = *src++) == '\0')
+                               break;
+                       *dst++ = chr;
+               } else if (chr != '"')
+                       *dst++ = chr;
+       }
+       *dst = '\0';
+       return dst;
+}
+
+void util_debug(const char *area, const char *ms, ...) {
        va_list  va;
        va_start(va, ms);
-       vprintf (ms, va);
+       fprintf (stdout, "DEBUG: ");
+       fputc   ('[',  stdout);
+       fprintf (stdout, area);
+       fputs   ("] ", stdout);
+       vfprintf(stdout, ms, va);
        va_end  (va);
 }