1 /* 2 * $Id: string.h 769 2007-10-24 00:15:40Z hubert@u.washington.edu $ 3 * 4 * ======================================================================== 5 * Copyright 2013-2021 Eduardo Chappa 6 * Copyright 2006-2007 University of Washington 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * ======================================================================== 15 */ 16 17 #ifndef PITH_STRING_INCLUDED 18 #define PITH_STRING_INCLUDED 19 20 21 /* 22 * Hex conversion aids 23 */ 24 #define HEX_ARRAY "0123456789ABCDEF" 25 #define HEX_CHAR1(C) HEX_ARRAY[((C) & 0xf0) >> 4] 26 #define HEX_CHAR2(C) HEX_ARRAY[(C) & 0xf] 27 28 #define XDIGIT2C(C) ((C) - (isdigit((unsigned char) (C)) \ 29 ? '0' : (isupper((unsigned char)(C))? '7' : 'W'))) 30 31 #define X2C(S) ((XDIGIT2C(*(S)) << 4) | XDIGIT2C(*((S)+1))) 32 33 #define C2XPAIR(C, S) { \ 34 *(S)++ = HEX_CHAR1(C); \ 35 *(S)++ = HEX_CHAR2(C); \ 36 } 37 38 39 /* for flags to fold() routine */ 40 #define FLD_NONE 0x00 41 #define FLD_CRLF 0x01 /* use CRLF end of line instead of LF */ 42 #define FLD_PWS 0x02 /* preserve whitespace when folding */ 43 #define FLD_NEXTSPC 0x04 /* fold at next available space after given length */ 44 45 46 typedef enum {FrontDots, MidDots, EndDots} WhereDots; 47 48 49 /* 50 * Macro to help determine when we need to filter out chars 51 * from message index or headers... 52 */ 53 #define FILTER_THIS(c) (((((unsigned char) (c) < 0x20 \ 54 || (unsigned char) (c) == 0x7f) \ 55 && !ps_global->pass_ctrl_chars) \ 56 || (((unsigned char) (c) >= 0x80 \ 57 && (unsigned char) (c) < 0xA0) \ 58 && !ps_global->pass_ctrl_chars \ 59 && !ps_global->pass_c1_ctrl_chars)) \ 60 && !((c) == SPACE \ 61 || (c) == TAB \ 62 || (c) == '\016' \ 63 || (c) == '\017')) 64 65 66 /* 67 * Keeps track of selected folders between instances of 68 * the folder list screen. 69 */ 70 typedef struct name_list { 71 char *name; 72 struct name_list *next; 73 } STRLIST_S; 74 75 76 struct date { 77 int sec, minute, hour, day, month, 78 year, hours_off_gmt, min_off_gmt, wkday; 79 }; 80 81 82 /* just a convenient place to put these so everything can access */ 83 #define BUILDER_SCREEN_MANGLED 0x1 84 #define BUILDER_MESSAGE_DISPLAYED 0x2 85 #define BUILDER_FOOTER_MANGLED 0x4 86 87 88 /* exported prototypes */ 89 char *rplstr(char *, size_t, int, char *); 90 void sqzspaces(char *); 91 void sqznewlines(char *); 92 void removing_leading_white_space(char *); 93 void removing_trailing_white_space(char *); 94 void replace_tabs_by_space(char *); 95 void removing_leading_and_trailing_white_space(char *); 96 int removing_double_quotes(char *); 97 char *skip_white_space(char *); 98 char *skip_to_white_space(char *); 99 char *removing_quotes(char *); 100 char *strclean(char *); 101 char *short_str(char *, char *, size_t, int, WhereDots); 102 char *srchstr(char *, char *); 103 char *srchrstr(char *, char *); 104 char *strindex(char *, int); 105 char *strrindex(char *, int); 106 char *iutf8ncpy(char *, char *, int); 107 char *istrncpy(char *, char *, int); 108 char *month_abbrev(int); 109 char *month_abbrev_locale(int); 110 char *month_name(int); 111 char *month_name_locale(int); 112 char *day_abbrev(int); 113 char *day_abbrev_locale(int); 114 char *day_name(int); 115 char *day_name_locale(int); 116 size_t our_strftime(char *, size_t, char *, struct tm *); 117 int month_num(char *); 118 void parse_date(char *, struct date *); 119 char *convert_date_to_local(char *); 120 char *repeat_char(int, int); 121 char *byte_string(long); 122 char *enth_string(int); 123 char *fold(char *, int, int, char *, char *, unsigned); 124 char *strsquish(char *, size_t, char *, int); 125 char *long2string(long); 126 char *ulong2string(unsigned long); 127 char *int2string(int); 128 char *strtoval(char *, int *, int, int, int, char *, size_t, char *); 129 char *strtolval(char *, long *, long, long, long, char *, size_t, char *); 130 void get_pair(char *, char **, char **, int, int); 131 char *put_pair(char *, char *); 132 char *quote_if_needed(char *); 133 int read_hex(char *); 134 char *string_to_cstring(char *); 135 char *cstring_to_hexstring(char *); 136 void cstring_to_string(char *, char *); 137 char *add_backslash_escapes(char *); 138 char *remove_backslash_escapes(char *); 139 char *add_viewerhdr_escapes(char *); 140 char *vcard_escape(char *); 141 char *vcard_unescape(char *); 142 void vcard_unfold(char *); 143 char *add_escapes(char *, char *, int, char *, char *); 144 char *copy_quoted_string_asis(char *); 145 int isxpair(char *); 146 STRLIST_S *new_strlist(char *); 147 STRLIST_S *new_strlist_auth(char *, char *, char); 148 STRLIST_S *copy_strlist(STRLIST_S *); 149 void combine_strlists(STRLIST_S **, STRLIST_S *); 150 void free_strlist(STRLIST_S **); 151 int read_octal(char **); 152 time_t date_to_local_time_t(char *); 153 void convert_decimal_to_roman (char *, size_t, long, char); 154 void convert_decimal_to_alpha (char *, size_t, long, char); 155 156 #endif /* PITH_STRING_INCLUDED */ 157