* 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"
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));
}
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);
}
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);
}