| 1 |
#ifndef STRING_UTILS_H_ |
| 2 |
#define STRING_UTILS_H_ |
| 3 |
|
| 4 |
#include <stdarg.h> |
| 5 |
#include "my-vsnprintf.h" |
| 6 |
|
| 7 |
extern Boolean str_is_prefix(const char *, const char *, Boolean case_sensitive); |
| 8 |
extern Boolean str_is_suffix(const char *, const char *, Boolean case_sensitive); |
| 9 |
extern Boolean is_spaces_only(const char *); |
| 10 |
|
| 11 |
extern char *my_stristr(const char *haystack, const char *needle); |
| 12 |
|
| 13 |
typedef enum { USE_DVI_PATH, USE_CWD_PATH } expandPathTypeT; |
| 14 |
|
| 15 |
/* remove `file:[//localhost/]' prefix from filename, and append `.dvi' |
| 16 |
extension if no extension is present */ |
| 17 |
extern char *filename_append_dvi(const char *fname); |
| 18 |
/* prepend a path of type `type' (either CWD, or directory of dvi file) |
| 19 |
to `fname' */ |
| 20 |
extern char *expand_filename(const char *fname, expandPathTypeT type); |
| 21 |
|
| 22 |
/* do both of the above */ |
| 23 |
extern char *expand_filename_append_dvi(const char *fname, expandPathTypeT type, Boolean must_exist); |
| 24 |
|
| 25 |
/* normalize `../' `./' `//' from path */ |
| 26 |
extern char *canonicalize_path(const char *path); |
| 27 |
|
| 28 |
extern char *format_arg(const char *fmt, const char *arg, int *match); |
| 29 |
extern char *escape_format_arg(const char *arg); |
| 30 |
extern char *unquote_arg(const char *fmt, const char *arg, int *match, int *len); |
| 31 |
extern char *get_dir_component(const char *path); |
| 32 |
extern char **get_separated_list(const char *source, const char *sep, Boolean do_unquote); |
| 33 |
extern const char *find_format_str(const char *input, const char *fmt); |
| 34 |
extern Boolean src_compare(const char *src, int src_len, const char *target, const char *path, size_t path_len); |
| 35 |
extern char *shell_escape_string(const char *str); |
| 36 |
extern void replace_extension(const char *fname, const char *extension, char *buf, size_t name_len); |
| 37 |
extern const char *get_extension(const char *fname); |
| 38 |
extern int length_of_int(int n); |
| 39 |
|
| 40 |
extern char *get_string_va(const char *fmt, ...); |
| 41 |
extern double my_atof(const char *str); |
| 42 |
|
| 43 |
/* |
| 44 |
* Print `fmt' to a dynamically allocated string `buf'. Uses VSNPRINTF |
| 45 |
* in a way that should work with all of glibc <= 2.0.6, >= 2.1, and |
| 46 |
* the implementation in my-vsnprintf.c. We cannot invoke va_start()/va_end() |
| 47 |
* in a wrapper function since we may need to invoke vsnprintf() several |
| 48 |
* times, and each call invalidates argp; that's why this is a macro ... |
| 49 |
*/ |
| 50 |
#define XDVI_GET_STRING_ARGP(buf, fmt) \ |
| 51 |
do { \ |
| 52 |
va_list argp; \ |
| 53 |
int CHUNK_LEN = 128; \ |
| 54 |
int curr_len = CHUNK_LEN, need_len; \ |
| 55 |
\ |
| 56 |
buf = NULL; \ |
| 57 |
\ |
| 58 |
for (;;) { \ |
| 59 |
/* see man page for vsnprintf: for glibc 2.0, <need_len> is */ \ |
| 60 |
/* -1 if <buf> had been trucated to <curr_len>; for glibc 2.1, */ \ |
| 61 |
/* it's the total length of <fmt>; so the following works */ \ |
| 62 |
/* with both versions: */ \ |
| 63 |
buf = xrealloc(buf, curr_len); \ |
| 64 |
\ |
| 65 |
va_start(argp, fmt); \ |
| 66 |
need_len = VSNPRINTF(buf, curr_len, fmt, argp); \ |
| 67 |
va_end(argp); \ |
| 68 |
\ |
| 69 |
if (need_len > -1 && need_len < curr_len) { /* <curr_len> was large enough */ \ |
| 70 |
break; \ |
| 71 |
} \ |
| 72 |
if (need_len > -1) { /* now need_len + 1 is the exact space needed */ \ |
| 73 |
curr_len = need_len + 1; \ |
| 74 |
} \ |
| 75 |
else { /* try again with larger <len> */ \ |
| 76 |
curr_len += CHUNK_LEN; \ |
| 77 |
} \ |
| 78 |
} \ |
| 79 |
} while (0) \ |
| 80 |
|
| 81 |
#endif /* STRING_UTILS_H_ */ |