]>
git.cameronkatri.com Git - mandoc.git/blob - tokens.c
1 /* $Id: tokens.c,v 1.3 2008/12/04 19:31:57 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
23 #include "libmdocml.h"
27 static int rofftok_dashes(const char *, int *);
28 static int rofftok_special(const char *, int *);
29 static int rofftok_predef(const char *, int *);
30 static int rofftok_defined(const char *, int *);
34 rofftok_defined(const char *buf
, int *i
)
46 if (0 == memcmp(p
, ">=", 2))
48 else if (0 == memcmp(p
, "<=", 2))
50 else if (0 == memcmp(p
, "Rq", 2))
51 return(ROFFTok_Rquote
);
52 else if (0 == memcmp(p
, "Lq", 2))
53 return(ROFFTok_Lquote
);
54 else if (0 == memcmp(p
, "ua", 2))
55 return(ROFFTok_Uparrow
);
56 else if (0 == memcmp(p
, "aa", 2))
57 return(ROFFTok_Acute
);
58 else if (0 == memcmp(p
, "ga", 2))
59 return(ROFFTok_Grave
);
60 else if (0 == memcmp(p
, "Pi", 2))
62 else if (0 == memcmp(p
, "Ne", 2))
64 else if (0 == memcmp(p
, "Le", 2))
66 else if (0 == memcmp(p
, "Ge", 2))
68 else if (0 == memcmp(p
, "Lt", 2))
70 else if (0 == memcmp(p
, "Gt", 2))
72 else if (0 == memcmp(p
, "Pm", 2))
73 return(ROFFTok_Plusmin
);
74 else if (0 == memcmp(p
, "If", 2))
75 return(ROFFTok_Infty
);
76 else if (0 == memcmp(p
, "Na", 2))
78 else if (0 == memcmp(p
, "Ba", 2))
86 rofftok_predef(const char *buf
, int *i
)
91 return(rofftok_defined(buf
, i
));
95 return(ROFFTok_Quote
);
105 rofftok_dashes(const char *buf
, int *i
)
110 else if (buf
[(*i
)++] != 'e')
128 rofftok_special(const char *buf
, int *i
)
132 return(ROFFTok_Slash
);
136 return(ROFFTok_Sp_A
);
138 return(ROFFTok_Sp_B
);
140 return(ROFFTok_Sp_F
);
142 return(ROFFTok_Sp_N
);
144 return(ROFFTok_Sp_R
);
146 return(ROFFTok_Sp_T
);
148 return(ROFFTok_Sp_V
);
150 return(ROFFTok_Sp_0
);
159 rofftok_scan(const char *buf
, int *i
)
163 assert(buf
[*i
] == '\\');
167 for ( ; buf
[*i
]; (*i
)++) {
171 return(rofftok_special(buf
, i
));
174 return(rofftok_dashes(buf
, i
));
176 return(ROFFTok_Space
);
178 return(ROFFTok_Null
);
180 return(ROFFTok_Hyphen
);
183 return(rofftok_predef(buf
, i
));
185 return(ROFFTok_Slash
);