]>
git.cameronkatri.com Git - mandoc.git/blob - tokens.c
1 /* $Id: tokens.c,v 1.4 2008/12/09 17:09:12 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.
26 static int rofftok_dashes(const char *, int *);
27 static int rofftok_special(const char *, int *);
28 static int rofftok_predef(const char *, int *);
29 static int rofftok_defined(const char *, int *);
33 rofftok_defined(const char *buf
, int *i
)
45 if (0 == memcmp(p
, ">=", 2))
47 else if (0 == memcmp(p
, "<=", 2))
49 else if (0 == memcmp(p
, "Rq", 2))
50 return(ROFFTok_Rquote
);
51 else if (0 == memcmp(p
, "Lq", 2))
52 return(ROFFTok_Lquote
);
53 else if (0 == memcmp(p
, "ua", 2))
54 return(ROFFTok_Uparrow
);
55 else if (0 == memcmp(p
, "aa", 2))
56 return(ROFFTok_Acute
);
57 else if (0 == memcmp(p
, "ga", 2))
58 return(ROFFTok_Grave
);
59 else if (0 == memcmp(p
, "Pi", 2))
61 else if (0 == memcmp(p
, "Ne", 2))
63 else if (0 == memcmp(p
, "Le", 2))
65 else if (0 == memcmp(p
, "Ge", 2))
67 else if (0 == memcmp(p
, "Lt", 2))
69 else if (0 == memcmp(p
, "Gt", 2))
71 else if (0 == memcmp(p
, "Pm", 2))
72 return(ROFFTok_Plusmin
);
73 else if (0 == memcmp(p
, "If", 2))
74 return(ROFFTok_Infty
);
75 else if (0 == memcmp(p
, "Na", 2))
77 else if (0 == memcmp(p
, "Ba", 2))
85 rofftok_predef(const char *buf
, int *i
)
90 return(rofftok_defined(buf
, i
));
94 return(ROFFTok_Quote
);
104 rofftok_dashes(const char *buf
, int *i
)
109 else if (buf
[(*i
)++] != 'e')
127 rofftok_special(const char *buf
, int *i
)
131 return(ROFFTok_Slash
);
135 return(ROFFTok_Sp_A
);
137 return(ROFFTok_Sp_B
);
139 return(ROFFTok_Sp_F
);
141 return(ROFFTok_Sp_N
);
143 return(ROFFTok_Sp_R
);
145 return(ROFFTok_Sp_T
);
147 return(ROFFTok_Sp_V
);
149 return(ROFFTok_Sp_0
);
158 rofftok_scan(const char *buf
, int *i
)
162 assert(buf
[*i
] == '\\');
166 for ( ; buf
[*i
]; (*i
)++) {
170 return(rofftok_special(buf
, i
));
173 return(rofftok_dashes(buf
, i
));
175 return(ROFFTok_Space
);
177 return(ROFFTok_Null
);
179 return(ROFFTok_Hyphen
);
182 return(rofftok_predef(buf
, i
));
184 return(ROFFTok_Slash
);