charmap.c

00001 /*  $Id: charmap.c,v 1.2 2005/03/07 20:31:24 kifer Exp $
00002 
00003     Part of SWI-Prolog
00004 
00005     Author:        Jan Wielemaker
00006     E-mail:        jan@swi.psy.uva.nl
00007     WWW:           http://www.swi-prolog.org
00008     Copyright (C): 1985-2002, University of Amsterdam
00009 
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014 
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include "dtd.h"
00028 
00032 static void
00033 char_range(dtd_charclass *map, int from, int to, int msk)
00034 { unsigned char *ca;
00035   int i;
00036 
00037   for(i=from, ca=map->class+i; i++<=to; )
00038     *ca++ |= msk;
00039 }
00040 
00041 
00042 dtd_charclass *
00043 new_charclass()
00044 { dtd_charclass *map = sgml_calloc(1, sizeof(*map));
00045   unsigned char *ca = map->class;
00046 
00047   char_range(map, 'a', 'z', CH_LCLETTER);
00048   char_range(map, 'A', 'Z', CH_LCLETTER);
00049   char_range(map, '0', '9', CH_DIGIT);
00050   
00051   ca['.'] |= CH_CNM;
00052   ca['-'] |= CH_CNM;
00053   ca[183] |= CH_CNM;                    /* XML */
00054   ca[':'] |= CH_CNMSTRT;                /* HTML and XML */
00055   ca['_'] |= CH_CNMSTRT;                /* HTML and XML */
00056 
00057   char_range(map, 192, 214, CH_CNMSTRT); /* XML ISO-LATIN-1 accented chars */
00058   char_range(map, 216, 246, CH_CNMSTRT);
00059   char_range(map, 248, 255, CH_CNMSTRT);
00060 
00061   ca['\t'] |= CH_WHITE;
00062   ca[' ']  |= CH_WHITE;
00063   ca['\r'] |= CH_RE;
00064   ca['\n'] |= CH_RS;
00065 
00066   return map;
00067 }
00068 
00069 
00070 dtd_charfunc *
00071 new_charfunc()
00072 { dtd_charfunc *f = sgml_calloc(1, sizeof(*f));
00073   ichar *cf = f->func;
00074 
00075   cf[CF_STAGO]  = '<';
00076   cf[CF_STAGC]  = '>';
00077   cf[CF_ETAGO1] = '<';
00078   cf[CF_ETAGO2] = '/';
00079   cf[CF_VI]     = '=';
00080   cf[CF_NS]     = ':';
00081   cf[CF_LIT]    = '"';
00082   cf[CF_LITA]   = '\'';
00083   cf[CF_PERO]   = '%';
00084   cf[CF_ERO]    = '&';
00085   cf[CF_ERC]    = ';';
00086   cf[CF_MDO1]   = '<';
00087   cf[CF_MDO2]   = '!';
00088   cf[CF_MDC]    = '>';
00089   cf[CF_PRO1]   = '<';
00090   cf[CF_PRO2]   = '?';
00091   cf[CF_PRC]    = '>';
00092   cf[CF_GRPO]   = '(';
00093   cf[CF_GRPC]   = ')';
00094   cf[CF_SEQ]    = ',';
00095   cf[CF_AND]    = '&';
00096   cf[CF_OR]     = '|';
00097   cf[CF_OPT]    = '?';
00098   cf[CF_PLUS]   = '+';
00099   cf[CF_DSO]    = '[';
00100   cf[CF_DSC]    = ']';
00101   cf[CF_REP]    = '*';
00102   cf[CF_RS]     = '\n';
00103   cf[CF_RE]     = '\r';
00104   cf[CF_CMT]    = '-';
00105 
00106   return f;
00107 }
00108 
00109 
00110 
00111 dtd_charmap *
00112 new_charmap()
00113 { dtd_charmap *map = sgml_malloc(sizeof(*map));
00114   int i;
00115 
00116   for(i=0 ; i<INPUT_CHARSET_SIZE; i++)
00117     map->map[i] = i;
00118 
00119   return map;
00120 }

Generated on Wed Jul 26 13:30:45 2006 for XSB by  doxygen 1.4.5