[BACK]Return to tokens.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/tokens.c, Revision 1.2

1.2     ! kristaps    1: /* $Id: tokens.c,v 1.1 2008/12/04 16:19:52 kristaps Exp $ */
1.1       kristaps    2: /*
                      3:  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
                      4:  *
                      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
                      8:  * copies.
                      9:  *
                     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.
                     18:  */
                     19: #include <assert.h>
                     20: #include <stdlib.h>
                     21: #include <string.h>
                     22:
                     23: #include "libmdocml.h"
                     24: #include "private.h"
                     25:
                     26:
                     27: static int              rofftok_dashes(const char *);
                     28: static int              rofftok_special(const char *);
                     29: static int              rofftok_predef(const char *);
                     30: static int              rofftok_defined(const char *);
                     31:
                     32:
                     33: static int
                     34: rofftok_defined(const char *buf)
                     35: {
                     36:        if (0 == *buf)
                     37:                return(-1);
                     38:        if (0 == *(buf + 1))
                     39:                return(-1);
                     40:        if (0 != *(buf + 2))
                     41:                return(-1);
                     42:
                     43:        if (0 == strcmp(buf, ">="))
                     44:                return(ROFFTok_Ge);
                     45:        else if (0 == strcmp(buf, "<="))
                     46:                return(ROFFTok_Le);
                     47:        else if (0 == strcmp(buf, "Rq"))
                     48:                return(ROFFTok_Rquote);
                     49:        else if (0 == strcmp(buf, "Lq"))
                     50:                return(ROFFTok_Lquote);
                     51:        else if (0 == strcmp(buf, "ua"))
                     52:                return(ROFFTok_Uparrow);
                     53:        else if (0 == strcmp(buf, "aa"))
                     54:                return(ROFFTok_Acute);
                     55:        else if (0 == strcmp(buf, "ga"))
                     56:                return(ROFFTok_Grave);
                     57:        else if (0 == strcmp(buf, "Pi"))
                     58:                return(ROFFTok_Pi);
                     59:        else if (0 == strcmp(buf, "Ne"))
                     60:                return(ROFFTok_Ne);
                     61:        else if (0 == strcmp(buf, "Le"))
                     62:                return(ROFFTok_Le);
                     63:        else if (0 == strcmp(buf, "Ge"))
                     64:                return(ROFFTok_Ge);
                     65:        else if (0 == strcmp(buf, "Lt"))
                     66:                return(ROFFTok_Lt);
                     67:        else if (0 == strcmp(buf, "Gt"))
                     68:                return(ROFFTok_Gt);
                     69:        else if (0 == strcmp(buf, "Pm"))
                     70:                return(ROFFTok_Plusmin);
                     71:        else if (0 == strcmp(buf, "If"))
                     72:                return(ROFFTok_Infty);
                     73:        else if (0 == strcmp(buf, "Na"))
                     74:                return(ROFFTok_Nan);
                     75:        else if (0 == strcmp(buf, "Ba"))
                     76:                return(ROFFTok_Bar);
                     77:
                     78:        return(-1);
                     79: }
                     80:
                     81:
                     82: static int
                     83: rofftok_predef(const char *buf)
                     84: {
                     85:        if (0 == *buf)
                     86:                return(-1);
                     87:
                     88:        if ('(' == *buf)
                     89:                return(rofftok_defined(++buf));
                     90:
1.2     ! kristaps   91:        switch (*buf) {
        !            92:        case ('q'):
        !            93:                return(ROFFTok_Quote);
        !            94:        default:
        !            95:                break;
        !            96:        }
1.1       kristaps   97:
                     98:        return(-1);
                     99: }
                    100:
                    101:
                    102: static int
                    103: rofftok_dashes(const char *buf)
                    104: {
                    105:
                    106:        if (0 == *buf)
                    107:                return(-1);
                    108:        else if (*buf++ != 'e')
                    109:                return(-1);
                    110:
                    111:        if (0 == *buf)
                    112:                return(-1);
                    113:        else if (0 != *(buf + 1))
                    114:                return(-1);
                    115:
                    116:        switch (*buf) {
                    117:        case ('m'):
                    118:                return(ROFFTok_Em);
                    119:        case ('n'):
                    120:                return(ROFFTok_En);
                    121:        default:
                    122:                break;
                    123:        }
                    124:        return(-1);
                    125: }
                    126:
                    127:
                    128: static int
                    129: rofftok_special(const char *buf)
                    130: {
                    131:
                    132:        if (0 == *buf)
                    133:                return(-1);
                    134:        else if (0 != *(buf + 1))
                    135:                return(-1);
                    136:
                    137:        switch (*buf) {
                    138:        case ('a'):
                    139:                return(ROFFTok_Sp_A);
                    140:        case ('b'):
                    141:                return(ROFFTok_Sp_B);
                    142:        case ('f'):
                    143:                return(ROFFTok_Sp_F);
                    144:        case ('n'):
                    145:                return(ROFFTok_Sp_N);
                    146:        case ('r'):
                    147:                return(ROFFTok_Sp_R);
                    148:        case ('t'):
                    149:                return(ROFFTok_Sp_T);
                    150:        case ('v'):
                    151:                return(ROFFTok_Sp_V);
                    152:        default:
                    153:                break;
                    154:        }
                    155:        return(-1);
                    156: }
                    157:
                    158:
                    159: int
                    160: rofftok_scan(const char *buf)
                    161: {
                    162:
                    163:        assert(*buf);
                    164:        if ('\\' != *buf++)
                    165:                return(ROFFTok_MAX);
                    166:
                    167:        for ( ; *buf; buf++) {
                    168:                switch (*buf) {
                    169:                case ('e'):
                    170:                        return(rofftok_special(++buf));
                    171:                case ('('):
                    172:                        return(rofftok_dashes(++buf));
                    173:                case (' '):
                    174:                        return(ROFFTok_Space);
                    175:                case ('&'):
                    176:                        return(ROFFTok_Null);
                    177:                case ('-'):
                    178:                        return(ROFFTok_Hyphen);
                    179:                case ('*'):
                    180:                        return(rofftok_predef(++buf));
1.2     ! kristaps  181:                case ('\\'):
        !           182:                        return(ROFFTok_MAX);
1.1       kristaps  183:                default:
                    184:                        break;
                    185:                }
                    186:        }
                    187:
                    188:        return(-1);
                    189: }
                    190:
                    191:

CVSweb