mpstrings.h /size: 2245 b    last modification: 2025-02-21 11:03
1/* 
2    This file was generated by "mtxrun --script "mtx-wtoc.lua" from the metapost cweb 
3    files but now maintained as C file.
4*/
5
6# ifndef MPSTRINGS_H
7# define MPSTRINGS_H 1
8
9# include "mp.h"
10
11extern void      *mp_aux_copy_strings_entry (const void *p);
12extern char      *mp_strdup                 (const char *s);
13extern char      *mp_strndup                (const char *s, size_t l);
14/*     int        mp_strcmp                 (const char *a, const char *b); */
15extern void       mp_initialize_strings     (MP mp);
16extern void       mp_dealloc_strings        (MP mp);
17/*     char      *mp_str                    (MP mp, mp_string s); */
18extern mp_string  mp_rtsl                   (MP mp, const char *s, size_t l);
19extern mp_string  mp_rts                    (MP mp, const char *s);
20extern mp_string  mp_make_string            (MP mp);
21extern void       mp_append_char            (MP mp, unsigned char c);
22extern void       mp_append_str             (MP mp, const char *s);
23extern void       mp_str_room               (MP mp, int wsize);
24extern void       mp_reset_cur_string       (MP mp);
25extern void       mp_flush_string           (MP mp, mp_string s);
26extern mp_string  mp_intern                 (MP mp, const char *s);
27extern mp_string  mp_make_string            (MP mp);
28extern int        mp_str_vs_str             (MP mp, mp_string s, mp_string t);
29extern mp_string  mp_cat                    (MP mp, mp_string a, mp_string b);
30extern mp_string  mp_chop_string            (MP mp, mp_string s, int a, int b);
31
32static inline char *mp_str (MP mp, mp_string ss) { 
33    (void) mp; 
34    return (char *) ss->str; 
35}
36
37static inline int mp_strcmp (const char *a, const char *b) 
38{ 
39    return a == NULL ? (b == NULL ? 0 : -1) : (b == NULL ? 1 : strcmp(a, b));
40}
41
42/*tex 
43    As soon as we have more than |MAX_STR_REF| references we assume that the string is persistent
44    and that there is no need to ever free it.
45*/
46
47# define MAX_STR_REF 127 
48
49# define add_str_ref(A) { if ( (A)->refs < MAX_STR_REF ) ((A)->refs)++; }
50
51# define delete_str_ref(A) do {  \
52    if ((A)->refs < MAX_STR_REF) { \
53        if ((A)->refs > 1) \
54            ((A)->refs)--; \
55        else \
56            mp_flush_string(mp, (A)); \
57    } \
58  } while (0)
59
60# endif
61
62