1.1 --- a/src/c2html.h Thu Nov 10 18:44:48 2016 +0100 1.2 +++ b/src/c2html.h Mon Apr 24 20:54:38 2023 +0200 1.3 @@ -31,61 +31,23 @@ 1.4 #define C2HTML_H 1.5 1.6 #include <stdio.h> 1.7 +#include <cx/list.h> 1.8 #include "highlighter.h" 1.9 1.10 #ifdef __cplusplus 1.11 extern "C" { 1.12 #endif 1.13 1.14 -#define VERSION_MAJOR 2 1.15 +#define VERSION_MAJOR 3 1.16 #define VERSION_MINOR 0 1.17 #define VERSION_DEVELOP 0 /* set this to zero for release version */ 1.18 1.19 /** 1.20 - * Reads a source file from the input buffer and writes at most 1.21 - * <code>maxlen</code> bytes of the formatted output to the output buffer. 1.22 + * Writes the formatted source data to the output buffer. 1.23 * 1.24 - * The output buffer must either be large enough to hold <code>maxlen</code> 1.25 - * bytes or the write function must trigger an automatic extension of the 1.26 - * buffer. 1.27 - * 1.28 - * The input is copied via an intermediate buffer to an internal buffer. 1.29 - * 1.30 - * @param inputbuffer the input buffer 1.31 - * @param rfnc a read function operating for the input buffer 1.32 - * @param ibuf intermediate processing buffer 1.33 - * @param ibuflen length of intermediate processing buffer 1.34 - * @param outputbuffer the output buffer 1.35 - * @param wfnc a write function for the output buffer 1.36 - * @param maxlen the maximum amount bytes which will be written to the 1.37 - * output buffer 1.38 - * @param hltr the highlighter function 1.39 - * @param showln zero, if line numbers shall be omitted, nonzero otherwise 1.40 - * 1.41 - * @return total amount of bytes written to the output buffer 1.42 - * 1.43 - * @see c2html_plain_highlighter() 1.44 - * @see c2html_c_highlighter() 1.45 - * @see c2html_java_highlighter() 1.46 - */ 1.47 -size_t c2html_formatn(void* inputbuffer, read_func rfnc, 1.48 - char* ibuf, size_t ibuflen, void* outputbuffer, write_func wfnc, 1.49 - size_t maxlen, c2html_highlighter_func hltr, int showln); 1.50 - 1.51 -/** 1.52 - * Reads a source file from the input buffer and writes the formatted output 1.53 - * to an output buffer. 1.54 - * 1.55 - * The output buffer must either be large enough to hold the formatted data 1.56 - * or the write function must trigger an automatic extension of the buffer. 1.57 - * 1.58 - * The input is copied via an intermediate buffer to an internal buffer. 1.59 - * 1.60 - * @param inputbuffer the input buffer 1.61 - * @param rfnc a read function operating for the input buffer 1.62 - * @param ibuf intermediate processing buffer 1.63 - * @param ibuflen length of intermediate processing buffer 1.64 - * @param outputbuffer the output buffer 1.65 + * @param inputbuffer the source file data as string 1.66 + * @param inputbuflen the length of the source file 1.67 + * @param outbuf the output buffer 1.68 * @param wfnc a write function for the output buffer 1.69 * @param hltr the highlighter function 1.70 * @param showln zero, if line numbers shall be omitted, nonzero otherwise 1.71 @@ -96,121 +58,32 @@ 1.72 * @see c2html_c_highlighter() 1.73 * @see c2html_java_highlighter() 1.74 */ 1.75 -size_t c2html_format(void* inputbuffer, read_func rfnc, 1.76 - char* ibuf, size_t ibuflen, void* outputbuffer, write_func wfnc, 1.77 - c2html_highlighter_func hltr, int showln); 1.78 +size_t c2html_bformat(char const* inputbuffer, size_t inputbuflen, 1.79 + void* outbuf, cx_write_func wfnc, 1.80 + c2html_highlighter_func hltr, int showln); 1.81 1.82 /** 1.83 - * Reads a source file from the specified input file stream and writes the 1.84 - * formatted output to an output buffer. 1.85 - * 1.86 - * The output buffer must either be large enough to hold the formatted data 1.87 - * or the write function must trigger an automatic extension of the buffer. 1.88 - * 1.89 - * The input is copied via an intermediate buffer to an internal buffer. 1.90 - * For files, the recommended intermediate buffer length is the file system 1.91 - * block size. 1.92 - * 1.93 - * @param inputfile the input file stream 1.94 - * @param ibuf intermediate processing buffer 1.95 - * @param ibuflen length of intermediate processing buffer 1.96 - * @param outputbuffer the output buffer 1.97 + * Writes the formatted source data to the output buffer. 1.98 + * 1.99 + * This function takes a list of \c char* that point to the beginning of each 1.100 + * line. These pointers may point directly into the source text and the strings 1.101 + * do not need to be zero-terminated, but the line-breaks must be included. 1.102 + * 1.103 + * @param lines a list of pointers to the beginning of each line 1.104 + * @param outbuf the output buffer 1.105 * @param wfnc a write function for the output buffer 1.106 * @param hltr the highlighter function 1.107 * @param showln zero, if line numbers shall be omitted, nonzero otherwise 1.108 - * 1.109 + * 1.110 * @return total amount of bytes written to the output buffer 1.111 - * 1.112 + * 1.113 * @see c2html_plain_highlighter() 1.114 * @see c2html_c_highlighter() 1.115 * @see c2html_java_highlighter() 1.116 */ 1.117 -size_t c2html_fformat(FILE* inputfile, char *ibuf, size_t ibuflen, 1.118 - void* outputbuffer, write_func wfnc, 1.119 - c2html_highlighter_func hltr, int showln); 1.120 - 1.121 -/** 1.122 - * Reads a source file from the specified input file stream and directly writes 1.123 - * the formatted output to the output file stream. 1.124 - * 1.125 - * For files, the recommended intermediate buffer length is the file system 1.126 - * block size. 1.127 - * 1.128 - * @param inputfile the input file stream 1.129 - * @param ibuf intermediate processing buffer 1.130 - * @param ibuflen length of intermediate processing buffer (recommended: 4 KB) 1.131 - * @param outputfile the output file stream 1.132 - * @param hltr the highlighter function 1.133 - * @param showln zero, if line numbers shall be omitted, nonzero otherwise 1.134 - * 1.135 - * @see c2html_plain_highlighter() 1.136 - * @see c2html_c_highlighter() 1.137 - * @see c2html_java_highlighter() 1.138 - */ 1.139 -void c2html_fformatf(FILE *inputfile, char *ibuf, size_t ibuflen, 1.140 - FILE* outputfile, c2html_highlighter_func hltr, int showln); 1.141 - 1.142 - 1.143 -/** 1.144 - * Writes at most <code>maxlen</code> bytes of formatted source data to the 1.145 - * output buffer. 1.146 - * 1.147 - * @param inputbuffer the source file data as string 1.148 - * @param inputbuflen the length of the source file 1.149 - * @param outputbuffer the output buffer 1.150 - * @param wfnc a write function for the output buffer 1.151 - * @param maxlen the maximum amount bytes which will be written to the 1.152 - * output buffer 1.153 - * @param hltr the highlighter function 1.154 - * @param showln zero, if line numbers shall be omitted, nonzero otherwise 1.155 - * 1.156 - * @return total amount of bytes written to the output buffer 1.157 - * 1.158 - * @see c2html_plain_highlighter() 1.159 - * @see c2html_c_highlighter() 1.160 - * @see c2html_java_highlighter() 1.161 - */ 1.162 -size_t c2html_bformatn(const char* inputbuffer, size_t inputbuflen, 1.163 - void* outputbuffer, write_func wfnc, 1.164 - size_t maxlen, c2html_highlighter_func hltr, int showln); 1.165 - 1.166 - 1.167 -/** 1.168 - * Writes the formatted source data to the output buffer. 1.169 - * 1.170 - * @param inputbuffer the source file data as string 1.171 - * @param inputbuflen the length of the source file 1.172 - * @param outputbuffer the output buffer 1.173 - * @param wfnc a write function for the output buffer 1.174 - * @param hltr the highlighter function 1.175 - * @param showln zero, if line numbers shall be omitted, nonzero otherwise 1.176 - * 1.177 - * @return total amount of bytes written to the output buffer 1.178 - * 1.179 - * @see c2html_plain_highlighter() 1.180 - * @see c2html_c_highlighter() 1.181 - * @see c2html_java_highlighter() 1.182 - */ 1.183 -size_t c2html_bformat(const char* inputbuffer, size_t inputbuflen, 1.184 - void* outputbuffer, write_func wfnc, 1.185 - c2html_highlighter_func hltr, int showln); 1.186 - 1.187 - 1.188 -/** 1.189 - * Writes the formatted source data directly to the specified file stream. 1.190 - * 1.191 - * @param inputbuffer the source file data as string 1.192 - * @param inputbuflen the length of the source file 1.193 - * @param outputfile the output file stream 1.194 - * @param hltr the highlighter function 1.195 - * @param showln zero, if line numbers shall be omitted, nonzero otherwise 1.196 - * 1.197 - * @see c2html_plain_highlighter() 1.198 - * @see c2html_c_highlighter() 1.199 - * @see c2html_java_highlighter() 1.200 - */ 1.201 -void c2html_bformatf(const char* inputbuffer, size_t inputbuflen, 1.202 - FILE* outputfile, c2html_highlighter_func hltr, int showln); 1.203 +size_t c2html_format(CxList const* lines, 1.204 + void* outbuf, cx_write_func wfnc, 1.205 + c2html_highlighter_func hltr, int showln); 1.206 1.207 #ifdef __cplusplus 1.208 }