summaryrefslogtreecommitdiff
path: root/pith/string.h
blob: 3dcbaf60d6292e9669a57dee0ab4ce7f3cb4192a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * $Id: string.h 769 2007-10-24 00:15:40Z hubert@u.washington.edu $
 *
 * ========================================================================
 * Copyright 2006-2007 University of Washington
 * Copyright 2013-2014 Eduardo Chappa
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * ========================================================================
 */

#ifndef PITH_STRING_INCLUDED
#define PITH_STRING_INCLUDED


/*
 * Hex conversion aids
 */
#define HEX_ARRAY	"0123456789ABCDEF"
#define	HEX_CHAR1(C)	HEX_ARRAY[((C) & 0xf0) >> 4]
#define	HEX_CHAR2(C)	HEX_ARRAY[(C) & 0xf]

#define	XDIGIT2C(C)	((C) - (isdigit((unsigned char) (C)) \
			  ? '0' : (isupper((unsigned char)(C))? '7' : 'W')))

#define	X2C(S)		((XDIGIT2C(*(S)) << 4) | XDIGIT2C(*((S)+1)))

#define	C2XPAIR(C, S)	{ \
			    *(S)++ = HEX_CHAR1(C); \
			    *(S)++ = HEX_CHAR2(C); \
			}


/* for flags to fold() routine */
#define FLD_NONE	0x00
#define FLD_CRLF	0x01	/* use CRLF end of line instead of LF */
#define FLD_PWS		0x02	/* preserve whitespace when folding   */


typedef enum {FrontDots, MidDots, EndDots} WhereDots;


/*
 * Macro to help determine when we need to filter out chars
 * from message index or headers...
 */
#define	FILTER_THIS(c)	(((((unsigned char) (c) < 0x20                  \
                            || (unsigned char) (c) == 0x7f)             \
                            && !ps_global->pass_ctrl_chars)             \
                           || (((unsigned char) (c) >= 0x80             \
                                && (unsigned char) (c) < 0xA0)          \
                            && !ps_global->pass_ctrl_chars              \
			    && !ps_global->pass_c1_ctrl_chars))         \
			 && !((c) == SPACE				\
			      || (c) == TAB				\
			      || (c) == '\016'				\
			      || (c) == '\017'))


/*
 * Keeps track of selected folders between instances of
 * the folder list screen.
 */
typedef	struct name_list {
    char		*name;
    struct name_list	*next;
} STRLIST_S;


struct date {
    int	 sec, minute, hour, day, month, 
	 year, hours_off_gmt, min_off_gmt, wkday;
};


/* just a convenient place to put these so everything can access */
#define BUILDER_SCREEN_MANGLED		0x1
#define BUILDER_MESSAGE_DISPLAYED	0x2
#define BUILDER_FOOTER_MANGLED		0x4


/* exported protoypes */
char	   *rplstr(char *, size_t, int, char *);
void	    sqzspaces(char *);
void	    sqznewlines(char *);
void	    removing_leading_white_space(char *);
void	    removing_trailing_white_space(char *);
void	    replace_tabs_by_space(char *);
void	    removing_leading_and_trailing_white_space(char *);
int 	    removing_double_quotes(char *);
char	   *skip_white_space(char *);
char	   *skip_to_white_space(char *);
char	   *removing_quotes(char *);
char	   *strclean(char *);
char	   *short_str(char *, char *, size_t, int, WhereDots);
char	   *srchstr(char *, char *);
char	   *srchrstr(char *, char *);
char	   *strindex(char *, int);
char	   *strrindex(char *, int);
char	   *iutf8ncpy(char *, char *, int);
char	   *istrncpy(char *, char *, int);
char	   *month_abbrev(int);
char	   *month_abbrev_locale(int);
char	   *month_name(int);
char	   *month_name_locale(int);
char	   *day_abbrev(int);
char	   *day_abbrev_locale(int);
char	   *day_name(int);
char	   *day_name_locale(int);
size_t      our_strftime(char *, size_t, char *, struct tm *);
int	    month_num(char *);
void	    parse_date(char *, struct date *);
char       *convert_date_to_local(char *);
char	   *repeat_char(int, int);
char	   *byte_string(long);
char	   *enth_string(int);
char       *fold(char *, int, int, char *, char *, unsigned);
char	   *strsquish(char *, size_t, char *, int);
char	   *long2string(long);
char	   *ulong2string(unsigned long);
char	   *int2string(int);
char	   *strtoval(char *, int *, int, int, int, char *, size_t, char *);
char	   *strtolval(char *, long *, long, long, long, char *, size_t, char *);
void	    get_pair(char *, char **, char **, int, int);
char	   *put_pair(char *, char *);
char       *quote_if_needed(char *);
int	    read_hex(char *);
char	   *string_to_cstring(char *);
char	   *cstring_to_hexstring(char *);
void	    cstring_to_string(char *, char *);
char	   *add_backslash_escapes(char *);
char	   *remove_backslash_escapes(char *);
char	   *add_viewerhdr_escapes(char *);
char	   *vcard_escape(char *);
char	   *vcard_unescape(char *);
void	    vcard_unfold(char *);
char       *add_escapes(char *, char *, int, char *, char *);
char       *copy_quoted_string_asis(char *);
int	    isxpair(char *);
STRLIST_S  *new_strlist(char *);
STRLIST_S  *copy_strlist(STRLIST_S *);
void	    combine_strlists(STRLIST_S **, STRLIST_S *);
void	    free_strlist(STRLIST_S **);
int         read_octal(char **);
time_t      date_to_local_time_t(char *);

#endif /* PITH_STRING_INCLUDED */