/src/z-util.h
C Header | 89 lines | 24 code | 23 blank | 42 comment | 0 complexity | 9cb1c123cef52eae6518a4ef76ac3748 MD5 | raw file
1#ifndef INCLUDED_Z_UTIL_H 2#define INCLUDED_Z_UTIL_H 3 4#include "h-basic.h" 5 6 7/**** Available variables ****/ 8 9/** 10 * The name of the program. 11 */ 12extern char *argv0; 13 14 15/* Aux functions */ 16extern void (*plog_aux)(cptr); 17extern void (*quit_aux)(cptr); 18 19 20/**** Available Functions ****/ 21 22/** 23 * Case insensitive comparison between two strings 24 */ 25extern int my_stricmp(const char *s1, const char *s2); 26 27/** 28 * Case insensitive comparison between two strings, up to n characters long. 29 */ 30extern int my_strnicmp(cptr a, cptr b, int n); 31 32/** 33 * Case-insensitive strstr 34 */ 35extern char *my_stristr(const char *string, const char *pattern); 36 37/** 38 * Copy up to 'bufsize'-1 characters from 'src' to 'buf' and NULL-terminate 39 * the result. The 'buf' and 'src' strings may not overlap. 40 * 41 * Returns: strlen(src). This makes checking for truncation 42 * easy. Example: 43 * if (my_strcpy(buf, src, sizeof(buf)) >= sizeof(buf)) ...; 44 * 45 * This function should be equivalent to the strlcpy() function in BSD. 46 */ 47extern size_t my_strcpy(char *buf, const char *src, size_t bufsize); 48 49/** 50 * Try to append a string to an existing NULL-terminated string, never writing 51 * more characters into the buffer than indicated by 'bufsize', and 52 * NULL-terminating the buffer. The 'buf' and 'src' strings may not overlap. 53 * 54 * my_strcat() returns strlen(buf) + strlen(src). This makes checking for 55 * truncation easy. Example: 56 * if (my_strcat(buf, src, sizeof(buf)) >= sizeof(buf)) ...; 57 * 58 * This function should be equivalent to the strlcat() function in BSD. 59 */ 60extern size_t my_strcat(char *buf, const char *src, size_t bufsize); 61 62/* Test equality, prefix, suffix */ 63extern bool streq(cptr s, cptr t); 64extern bool prefix(cptr s, cptr t); 65extern bool suffix(cptr s, cptr t); 66 67#define streq(s, t) (!strcmp(s, t)) 68 69 70/* Print an error message */ 71extern void plog(cptr str); 72 73/* Exit, with optional message */ 74extern void quit(cptr str); 75 76 77/* Sorting functions */ 78/* TODO: make ang_sort() take comp and swap hooks rather than use globals */ 79void ang_sort(void *u, void *v, int n); 80void ang_sort_aux(void *u, void *v, int p, int q); 81 82extern bool (*ang_sort_comp)(const void *u, const void *v, int a, int b); 83extern void (*ang_sort_swap)(void *u, void *v, int a, int b); 84 85/* Mathematical functions */ 86int mean(int *nums, int size); 87int variance(int *nums, int size); 88 89#endif /* INCLUDED_Z_UTIL_H */