1 /* Monolith text processing functions.
2 * - by Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: text.c,v 1.1 2002/12/08 17:29:17 rich Exp $
31 #include <pthr_iolib.h>
34 #include "ml_smarttext.h"
37 ml_plaintext_print (io_handle io, const char *text)
43 default: io_fputc (*text, io); break;
44 case '<': io_fputs ("<", io); break;
45 case '>': io_fputs (">", io); break;
46 case '\n': io_fputs ("<br>", io); break;
47 case '&': io_fputs ("&", io); break;
48 case '"': io_fputs (""", io); break;
55 ml_plaintext_to_html (pool pool, const char *text)
58 int len = strlen (text);
62 /* Work out how long the escaped string will be. Escaped strings get
65 for (i = 0; i < len; ++i)
66 if (text[i] == '<' || text[i] == '>' || text[i] == '\n')
68 else if (text[i] == '&')
70 else if (text[i] == '"')
75 new_text = pmalloc (pool, sizeof (char) * (new_len+1));
77 /* Now copy and escape the string. */
78 for (i = j = 0; i < len; ++i)
82 new_text[j++] = text[i];
119 new_text[j++] = '\0';
125 ml_smarttext_print (io_handle io, const char *text)
127 pool tmp = new_subpool (global_pool);
130 s = ml_smarttext_to_html (tmp, text);
136 ml_filterhtml_print (io_handle io, const char *text)
138 /* XXX NOT IMPLEMENTED XXX */
143 ml_filterhtml_to_html (pool pool, const char *text)
145 /* XXX NOT IMPLEMENTED XXX */
150 ml_anytext_print (io_handle io, const char *text, char type)
155 ml_plaintext_print (io, text);
158 ml_smarttext_print (io, text);
161 ml_filterhtml_print (io, text);
167 ml_anytext_to_html (pool pool, const char *text, char type)
172 text = ml_plaintext_to_html (pool, text);
175 text = ml_smarttext_to_html (pool, text);
178 text = ml_filterhtml_to_html (pool, text);