2020-09-07 23:22:43 -07:00
|
|
|
/*
|
2020-09-11 01:28:06 -07:00
|
|
|
* utils.h - Some utility and printing functions.
|
2020-09-07 23:22:43 -07:00
|
|
|
*/
|
2020-09-11 01:28:06 -07:00
|
|
|
#ifndef UTILS__H
|
|
|
|
#define UTILS__H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "vm.h"
|
2020-09-07 23:22:43 -07:00
|
|
|
|
2020-09-09 22:29:09 -07:00
|
|
|
#define streq(a, b) (strcmp(a, b) == 0)
|
2020-09-07 23:22:43 -07:00
|
|
|
// TODO: better error reporting
|
|
|
|
#define check(cond, ...) do { if (!(cond)) { fprintf(stderr, __VA_ARGS__); fwrite("\n", 1, 1, stderr); _exit(1); } } while(0)
|
|
|
|
#define debug(...) do { if (verbose) fprintf(stderr, __VA_ARGS__); } while(0)
|
2020-12-17 16:27:23 -08:00
|
|
|
#define new(t) memcheck(calloc(sizeof(t), 1))
|
|
|
|
#define xcalloc(a,b) memcheck(calloc(a,b))
|
|
|
|
#define xrealloc(a,b) memcheck(realloc(a,b))
|
2020-09-08 19:45:00 -07:00
|
|
|
|
2020-09-23 22:37:28 -07:00
|
|
|
__attribute__((nonnull))
|
2020-09-28 21:30:43 -07:00
|
|
|
unsigned char unescapechar(const char *escaped, const char **end);
|
2020-09-23 22:37:28 -07:00
|
|
|
__attribute__((pure, nonnull, returns_nonnull))
|
2020-09-11 01:28:06 -07:00
|
|
|
const char *after_name(const char *str);
|
2020-09-23 22:37:28 -07:00
|
|
|
__attribute__((pure, nonnull, returns_nonnull))
|
2020-09-11 01:28:06 -07:00
|
|
|
const char *after_spaces(const char *str);
|
2020-09-23 22:37:28 -07:00
|
|
|
__attribute__((nonnull))
|
2020-09-11 01:28:06 -07:00
|
|
|
int matchchar(const char **str, char c);
|
2020-09-23 22:37:28 -07:00
|
|
|
__attribute__((nonnull))
|
2020-12-30 15:30:19 -08:00
|
|
|
int matchstr(const char **str, const char *target);
|
|
|
|
__attribute__((nonnull))
|
2020-09-11 01:28:06 -07:00
|
|
|
size_t unescape_string(char *dest, const char *src, size_t bufsize);
|
2020-12-17 16:27:23 -08:00
|
|
|
void *memcheck(void *p);
|
2020-12-17 19:49:56 -08:00
|
|
|
int memicmp(const void *s1, const void *s2, size_t n);
|
2020-09-10 03:41:03 -07:00
|
|
|
|
2020-09-11 01:28:06 -07:00
|
|
|
#endif
|
2020-09-11 01:38:44 -07:00
|
|
|
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1
|