2021-01-12 21:04:43 -08:00
|
|
|
//
|
|
|
|
// utils.h - Some utility and printing functions.
|
|
|
|
//
|
2020-09-11 01:28:06 -07:00
|
|
|
#ifndef UTILS__H
|
|
|
|
#define UTILS__H
|
|
|
|
|
2021-01-18 10:30:17 -08:00
|
|
|
#include <stdbool.h>
|
2020-09-11 01:28:06 -07:00
|
|
|
#include <stdio.h>
|
2021-01-18 10:30:17 -08:00
|
|
|
#include <stdlib.h>
|
2020-09-11 01:28:06 -07:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2021-01-15 19:30:21 -08:00
|
|
|
#include "match.h"
|
2020-09-07 23:22:43 -07:00
|
|
|
|
2021-07-30 14:54:28 -07:00
|
|
|
#define S1(x) #x
|
|
|
|
#define S2(x) S1(x)
|
|
|
|
#define __LOCATION__ __FILE__ ":" S2(__LINE__)
|
|
|
|
|
2020-09-09 22:29:09 -07:00
|
|
|
#define streq(a, b) (strcmp(a, b) == 0)
|
2021-07-30 14:54:28 -07:00
|
|
|
#define new(t) check_nonnull(calloc(1, sizeof(t)), __LOCATION__ ": `new(" #t ")` allocation failure")
|
|
|
|
#define checked_strdup(s) check_nonnull(strdup(s), __LOCATION__ ": `checked_strdup(" #s ")` allocation failure")
|
|
|
|
#define grow(arr,n) check_nonnull(realloc(arr,sizeof(arr[0])*(n)), __LOCATION__ ": `groaw(" #arr ", " #n ")` allocation failure")
|
2020-09-08 19:45:00 -07:00
|
|
|
|
2021-01-19 21:35:34 -08:00
|
|
|
__attribute__((nonnull(1)))
|
2021-01-17 23:06:37 -08:00
|
|
|
char unescapechar(const char *escaped, const char **end);
|
2020-12-30 21:20:54 -08:00
|
|
|
__attribute__((pure, 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))
|
2021-01-18 10:30:17 -08:00
|
|
|
bool matchchar(const char **str, char c);
|
2020-09-23 22:37:28 -07:00
|
|
|
__attribute__((nonnull))
|
2021-01-18 10:30:17 -08:00
|
|
|
bool matchstr(const char **str, const char *target);
|
2021-01-18 09:52:35 -08:00
|
|
|
__attribute__((returns_nonnull))
|
2021-07-30 14:54:28 -07:00
|
|
|
void *check_nonnull(void *p, const char *err_msg, ...);
|
2021-07-30 15:03:21 -07:00
|
|
|
int check_nonnegative(int i, const char *err_msg, ...);
|
2021-01-10 00:12:09 -08:00
|
|
|
__attribute__((nonnull))
|
2020-12-17 19:49:56 -08:00
|
|
|
int memicmp(const void *s1, const void *s2, size_t n);
|
2021-01-10 00:12:09 -08:00
|
|
|
__attribute__((nonnull))
|
2021-07-30 15:06:04 -07:00
|
|
|
void delete(void *p);
|
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
|