libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008-2011, 2013 Peter Miller 00004 * Written by Peter Miller <pmiller@opensource.org.au> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 3 of the License, or (at 00009 * your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #ifndef LIBEXPLAIN_STRING_BUFFER_H 00021 #define LIBEXPLAIN_STRING_BUFFER_H 00022 00023 #include <libexplain/ac/stdarg.h> 00024 #include <libexplain/ac/stddef.h> 00025 00026 #include <libexplain/gcc_attributes.h> 00027 00028 #ifndef i18n 00029 #define i18n(x) x 00030 #endif 00031 00037 typedef struct explain_string_buffer_t explain_string_buffer_t; 00038 struct explain_string_buffer_t 00039 { 00040 char *message; 00041 size_t position; 00042 size_t maximum; 00043 explain_string_buffer_t *footnotes; 00044 }; 00045 00059 void explain_string_buffer_init(explain_string_buffer_t *sb, 00060 char *message, int message_size); 00061 00062 void explain_string_buffer_putc(explain_string_buffer_t *sb, int c); 00063 00074 void explain_string_buffer_putc_quoted(explain_string_buffer_t *sb, 00075 int c); 00076 00090 void explain_string_buffer_putc_escaped(explain_string_buffer_t *sb, 00091 int c, int delimiter); 00092 00093 /* 00094 * The explain_string_buffer_puts function is used to print a string 00095 * into the string buffer. 00096 * 00097 * @param sb 00098 * The string buffer to print into. 00099 * @param s 00100 * The string to print into the string buffer. 00101 */ 00102 void explain_string_buffer_puts(explain_string_buffer_t *sb, 00103 const char *s); 00104 00105 /* 00106 * The explain_string_buffer_putsu function is used to print a string 00107 * into the string buffer. 00108 * 00109 * @param sb 00110 * The string buffer to print into. 00111 * @param s 00112 * The string to print into the string buffer. 00113 */ 00114 void explain_string_buffer_putsu(explain_string_buffer_t *sb, 00115 const unsigned char *s); 00116 00117 /* 00118 * The explain_string_buffer_puts_quoted function is used to print 00119 * a C string into the string buffer, complete with double quotes and 00120 * escape sequences if necessary. 00121 * 00122 * @param sb 00123 * The string buffer to print into. 00124 * @param s 00125 * The string to print into the string buffer. 00126 */ 00127 void explain_string_buffer_puts_quoted(explain_string_buffer_t *sb, 00128 const char *s); 00129 00130 /* 00131 * The explain_string_buffer_puts_shell_quoted function is used to print 00132 * a shell string into the string buffer, complete with double quotes and 00133 * sdingle quotes, and escape sequences if necessary. 00134 * 00135 * @param sb 00136 * The string buffer to print into. 00137 * @param s 00138 * The string to print into the string buffer. 00139 */ 00140 void explain_string_buffer_puts_shell_quoted(explain_string_buffer_t *sb, 00141 const char *s); 00142 00143 /* 00144 * The explain_string_buffer_putsu_quoted function is used to print 00145 * a C string into the string buffer, complete with double quotes and 00146 * escape sequences if necessary. 00147 * 00148 * @param sb 00149 * The string buffer to print into. 00150 * @param s 00151 * The string to print into the string buffer. 00152 */ 00153 void explain_string_buffer_putsu_quoted(explain_string_buffer_t *sb, 00154 const unsigned char *s); 00155 00156 /* 00157 * The explain_string_buffer_puts_quoted_n function is used to print 00158 * a C string into the string buffer, complete with double quotes and 00159 * escape sequences if necessary. The length is limited to that given, 00160 * unless a NUL is seen earlier. 00161 * 00162 * @param sb 00163 * The string buffer to print into. 00164 * @param s 00165 * The string to print into the string buffer. 00166 * @param n 00167 * The maximum length of the string. 00168 */ 00169 void explain_string_buffer_puts_quoted_n(explain_string_buffer_t *sb, 00170 const char *s, size_t n); 00171 00172 /* 00173 * The explain_string_buffer_putsu_quoted_n function is used to print 00174 * a C string into the string buffer, complete with double quotes and 00175 * escape sequences if necessary. The length is limited to that given, 00176 * unless a NUL is seen earlier. 00177 * 00178 * @param sb 00179 * The string buffer to print into. 00180 * @param s 00181 * The string to print into the string buffer. 00182 * @param n 00183 * The maximum length of the string. 00184 */ 00185 void explain_string_buffer_putsu_quoted_n(explain_string_buffer_t *sb, 00186 const unsigned char *s, size_t n); 00187 00198 void explain_string_buffer_printf(explain_string_buffer_t *sb, 00199 const char *fmt, ...) 00200 LIBEXPLAIN_FORMAT_PRINTF(2, 3); 00201 00214 void explain_string_buffer_printf_gettext(explain_string_buffer_t *sb, 00215 const char *fmt, ...) 00216 LIBEXPLAIN_FORMAT_PRINTF(2, 3); 00217 00218 void explain_string_buffer_vprintf(explain_string_buffer_t *sb, 00219 const char *fmt, va_list ap); 00220 00221 void explain_string_buffer_copy(explain_string_buffer_t *dst, 00222 const explain_string_buffer_t *src); 00223 00224 void explain_string_buffer_path_join(explain_string_buffer_t *sb, 00225 const char *s); 00226 00235 int explain_string_buffer_full(const explain_string_buffer_t *sb); 00236 00253 void explain_string_buffer_write(explain_string_buffer_t *sb, 00254 const char *data, size_t data_size); 00255 00265 void explain_string_buffer_truncate(explain_string_buffer_t *sb, 00266 long new_position); 00267 00275 void explain_string_buffer_rewind(explain_string_buffer_t *sb); 00276 00277 #endif /* LIBEXPLAIN_STRING_BUFFER_H */ 00278 /* vim: set ts=8 sw=4 et : */