1 /* File z-util.h */
2 
3 #ifndef INCLUDED_Z_UTIL_H
4 #define INCLUDED_Z_UTIL_H
5 
6 #include "h-basic.h"
7 
8 
9 /*
10  * Extremely basic stuff, like global temp and constant variables.
11  * Also, some very useful low level functions, such as "streq()".
12  * All variables and functions in this file are "addressable".
13  */
14 
15 
16 /**** Available variables ****/
17 
18 /* Temporary Vars */
19 extern char char_tmp;
20 extern byte byte_tmp;
21 extern sint sint_tmp;
22 extern uint uint_tmp;
23 extern long long_tmp;
24 extern huge huge_tmp;
25 extern errr errr_tmp;
26 
27 /* Temporary Pointers */
28 extern cptr cptr_tmp;
29 extern vptr vptr_tmp;
30 
31 
32 /* Constant pointers (NULL) */
33 extern cptr cptr_null;
34 extern vptr vptr_null;
35 
36 
37 /* A bizarre vptr that always points at itself */
38 extern vptr vptr_self;
39 
40 
41 /* A cptr to the name of the program */
42 extern cptr argv0;
43 
44 /* mbcs hook and function */
45 extern size_t (*mbcs_hook)(wchar_t *dest, const char *src, int n);
46 extern size_t z_mbstowcs(wchar_t *dest, const char *src, int n);
47 
48 /* Aux functions */
49 
50 extern void (*plog_aux)(cptr);
51 extern void (*quit_aux)(cptr);
52 extern void (*core_aux)(cptr);
53 
54 
55 /**** Available Functions ****/
56 
57 /* Function that does nothing */
58 extern void func_nothing(void);
59 
60 /* Functions that return basic "errr" codes */
61 extern errr func_success(void);
62 extern errr func_problem(void);
63 extern errr func_failure(void);
64 
65 /* Functions that return bools */
66 extern bool func_true(void);
67 extern bool func_false(void);
68 
69 /* Function that work with hturn */
70 extern int ht_passed(hturn *new_ht, hturn *old_ht, huge passed);
71 extern char* ht_show(hturn *ht_ptr, int mode);
72 
73 /* Case insensitive comparison between two strings */
74 extern int my_stricmp(const char *s1, const char *s2);
75 extern int my_strnicmp(cptr a, cptr b, int n);
76 extern const char *my_stristr(const char *haystack, const char *needle);
77 
78 /* Copy a string */
79 extern size_t my_strcpy(char *buf, const char *src, size_t bufsize);
80 
81 /* Concatenate two strings */
82 extern size_t my_strcat(char *buf, const char *src, size_t bufsize);
83 
84 /* Test equality, prefix, suffix */
85 extern bool streq(cptr s, cptr t);
86 extern bool prefix(cptr s, cptr t);
87 extern bool suffix(cptr s, cptr t);
88 /* Test for case-insensitive suffix */
89 extern bool isuffix(cptr s, cptr t);
90 
91 /* Hack -- conditional (or "bizarre") externs */
92 
93 #ifndef HAVE_MEMSET
94 extern void *memset(void*, int, size_t);
95 #endif
96 
97 #ifndef HAVE_STRICMP
98 extern int stricmp(cptr a, cptr b);
99 #endif
100 
101 #ifndef HAVE_STRDUP
102 extern char *strdup(cptr s);
103 #endif
104 
105 #ifndef HAVE_STRNLEN
106 extern size_t strnlen(char *s, size_t maxlen);
107 #endif
108 
109 #ifndef HAVE_USLEEP
110 extern int usleep(huge microSeconds);
111 #endif
112 
113 
114 /* Print an error message */
115 extern void plog(cptr str);
116 
117 /* Exit, with optional message */
118 extern void quit(cptr str);
119 
120 /* Dump core, with optional message */
121 extern void core(cptr str);
122 
123 
124 /* (integer) square root and hypot */
125 extern u32b isqrt(u32b x);
126 extern u32b ihypot(u32b x, u32b y);
127 #define IHYPOT(X, Y) isqrt((X) * (X) + (Y) * (Y))
128 
129 
130 /* Sorting functions */
131 /* TODO: make ang_sort() take comp and swap hooks rather than use globals */
132 extern void ang_sort(void *player_context, vptr u, vptr v, int n);
133 extern void ang_sort_aux(void *player_context, vptr u, vptr v, int p, int q);
134 
135 extern bool (*ang_sort_comp)(void *player_context, vptr u, vptr v, int a, int b);
136 extern void (*ang_sort_swap)(void *player_context, vptr u, vptr v, int a, int b);
137 
138 #endif
139