| 1 |
// SPDX-License-Identifier: MIT |
| 2 |
|
| 3 |
#ifndef _LO_UTIL_H_ |
| 4 |
#define _LO_UTIL_H_ |
| 5 |
#include <limits.h> |
| 6 |
#include "stdint.h" |
| 7 |
|
| 8 |
#define MIN(x, y) ((x) > (y) ? (y) : (x)) |
| 9 |
#define MAX(x, y) ((x) > (y) ? (x) : (y)) |
| 10 |
|
| 11 |
#define with_port(port, block) \ |
| 12 |
{ \ |
| 13 |
GrafPtr oldPort; \ |
| 14 |
GetPort(&oldPort); \ |
| 15 |
SetPort(port); \ |
| 16 |
block \ |
| 17 |
SetPort(oldPort); \ |
| 18 |
} |
| 19 |
|
| 20 |
typedef struct |
| 21 |
{ |
| 22 |
short push[2], rts; |
| 23 |
void *addr; |
| 24 |
} def_jmp_t; |
| 25 |
|
| 26 |
inline bool win_is_dialog(WindowPtr win) |
| 27 |
{ |
| 28 |
WindowPeek wPeek = (WindowPeek)win; |
| 29 |
return (wPeek->windowKind == dialogKind); |
| 30 |
} |
| 31 |
|
| 32 |
void win_center(WindowPtr win); |
| 33 |
|
| 34 |
// expand a Rect by npixels on each side |
| 35 |
inline void rect_expand(Rect *r, short npixels) |
| 36 |
{ |
| 37 |
r->top -= npixels; |
| 38 |
r->bottom += npixels; |
| 39 |
r->left -= npixels; |
| 40 |
r->right += npixels; |
| 41 |
} |
| 42 |
|
| 43 |
short inline rect_width(const Rect* r) |
| 44 |
{ |
| 45 |
return r->right - r->left; |
| 46 |
} |
| 47 |
|
| 48 |
short inline rect_height(const Rect* r) |
| 49 |
{ |
| 50 |
return r->bottom - r->top; |
| 51 |
} |
| 52 |
|
| 53 |
void* xmalloc(size_t sz); |
| 54 |
void* xrealloc(void* ptr, size_t newsz); |
| 55 |
|
| 56 |
void die(const char*, ...); |
| 57 |
void warn(const char*, ...); |
| 58 |
void info(const char*, ...); |
| 59 |
|
| 60 |
size_t lo_strlcpy(char* dest, const char* src, size_t len); |
| 61 |
|
| 62 |
char* lo_strdup(const char* s); |
| 63 |
|
| 64 |
short lo_snprintf(char* s, size_t size, |
| 65 |
const char *fmt, ...); |
| 66 |
|
| 67 |
short lo_vsnprintf(char* s, size_t size, |
| 68 |
const char* fmt, void* p); |
| 69 |
|
| 70 |
#ifndef _UTIL_IMPL_ |
| 71 |
|
| 72 |
#define strlcpy lo_strlcpy |
| 73 |
#define vsnprintf lo_vsnprintf |
| 74 |
#define snprintf lo_snprintf |
| 75 |
#define strdup lo_strdup |
| 76 |
|
| 77 |
#endif |
| 78 |
|
| 79 |
void toolbox_init(void); |
| 80 |
void memory_init(void); |
| 81 |
|
| 82 |
bool have_thread_manager(); |
| 83 |
|
| 84 |
#endif // _LO_UTIL_H_ |