/src/z-util.h

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