src/fmt_russian.c

00001 /* $Id: fmt_russian.c,v 1.6 2006/05/30 13:10:00 piotras Exp $
00002  *
00003  * fmt_russian: Raw formatter (used for russian encodings and UTF-8 texts)
00004  *
00005  * Copyright (C) 1999 Jukka Zitting <jukka.zitting@iki.fi>
00006  * Copyright (C) 2000 The Midgard Project ry
00007  * Copyright (C) 1999-2003 Alexander Bokovoy <ab@altlinux.org>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this library; see the file COPYING.  If not, write to
00021  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00022  * Boston, MA 02111-1307, USA.
00023  */
00024 #include <config.h>
00025 #include "midgard/parser.h"
00026 #include "fmt_russian.h"
00027 #include <assert.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <ctype.h>
00031 #include <stdio.h>
00032 
00033 static int addplain(mgd_parser * parser, const char *str, int html)
00034 {
00035         if (!str)
00036                 return 0;
00037         while (*str) {
00038                 for (; *str && (!html || (*str != '[' || *(str + 1) != '<'));
00039                      str++)
00040                         if (*str == '&')
00041                                 mgd_parser_addstr(parser, "&amp;");
00042                         else if (*str == '<')
00043                                 mgd_parser_addstr(parser, "&lt;");
00044                         else if (*str == '>')
00045                                 mgd_parser_addstr(parser, "&gt;");
00046                         else if (*str == '\"')
00047                                 mgd_parser_addstr(parser, "&quot;");
00048                         else
00049                                 mgd_parser_addchar(parser, *str);
00050                 if (*str && html && *str == '[' && *(str + 1) == '<')
00051                         for (str += 2;
00052                              *str && (*str != '>' || *(str + 1) != ']'); str++)
00053                                 mgd_parser_addchar(parser, *str);
00054                 if (*str && html && *str == '>' && *(str + 1) == ']')
00055                         str += 2;
00056         }
00057         return 1;
00058 }
00059 
00060 static int addhtml(mgd_parser * parser, const char *str)
00061 {
00062         if (!str)
00063                 return 0;
00064         for (; *str; str++)
00065                 mgd_parser_addchar(parser, *str);
00066         return 1;
00067 }
00068 
00069 static int mgd_parser_raw_p(mgd_parser * parser, void *data)
00070 {
00071         return addplain(parser, (const char *) data, 0);
00072 }
00073 
00074 static int mgd_parser_raw_P(mgd_parser * parser, void *data)
00075 {
00076         return addplain(parser, (const char *) data, 1);
00077 }
00078 
00079 static int mgd_parser_raw_h(mgd_parser * parser, void *data)
00080 {
00081         return addplain(parser, (const char *) data, 1);
00082 }
00083 
00084 static int mgd_parser_raw_H(mgd_parser * parser, void *data)
00085 {
00086         return addhtml(parser, (const char *) data);
00087 }
00088 
00089 mgd_parser *mgd_parser_init_raw(const char* name, const char* encoding)
00090 {
00091         mgd_parser *parser;
00092         parser = mgd_parser_create(name, encoding, 0);
00093         mgd_parser_setcallback(parser, 'p', MGD_STR, mgd_parser_raw_p);
00094         mgd_parser_setcallback(parser, 'P', MGD_STR, mgd_parser_raw_P);
00095         mgd_parser_setcallback(parser, 'h', MGD_STR, mgd_parser_raw_h);
00096         mgd_parser_setcallback(parser, 'H', MGD_STR, mgd_parser_raw_H);
00097         return parser;
00098 }

Generated on Thu Feb 22 06:15:14 2007 for midgard-core by  doxygen 1.4.6