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

Annotation of mandoc/mandoc.c, Revision 1.2

1.2     ! kristaps    1: /*     $Id: mandoc.c,v 1.1 2009/07/04 09:01:55 kristaps Exp $ */
1.1       kristaps    2: /*
                      3:  * Copyright (c) 2008, 2009 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 above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
1.2     ! kristaps   17: #include <sys/types.h>
        !            18:
1.1       kristaps   19: #include <assert.h>
                     20: #include <ctype.h>
                     21: #include <stdlib.h>
                     22:
                     23: #include "libmandoc.h"
                     24:
                     25: int
                     26: mandoc_special(const char *p)
                     27: {
                     28:        int              c;
                     29:
                     30:        if ('\\' != *p++)
                     31:                return(0);
                     32:
                     33:        switch (*p) {
                     34:        case ('\\'):
                     35:                /* FALLTHROUGH */
                     36:        case ('\''):
                     37:                /* FALLTHROUGH */
                     38:        case ('`'):
                     39:                /* FALLTHROUGH */
                     40:        case ('q'):
                     41:                /* FALLTHROUGH */
                     42:        case ('-'):
                     43:                /* FALLTHROUGH */
                     44:        case ('~'):
                     45:                /* FALLTHROUGH */
                     46:        case ('^'):
                     47:                /* FALLTHROUGH */
                     48:        case ('%'):
                     49:                /* FALLTHROUGH */
                     50:        case ('0'):
                     51:                /* FALLTHROUGH */
                     52:        case (' '):
                     53:                /* FALLTHROUGH */
                     54:        case ('|'):
                     55:                /* FALLTHROUGH */
                     56:        case ('&'):
                     57:                /* FALLTHROUGH */
                     58:        case ('.'):
                     59:                /* FALLTHROUGH */
                     60:        case (':'):
                     61:                /* FALLTHROUGH */
                     62:        case ('e'):
                     63:                return(2);
                     64:        case ('f'):
                     65:                if (0 == *++p || ! isgraph((u_char)*p))
                     66:                        return(0);
                     67:                return(3);
                     68:        case ('*'):
                     69:                if (0 == *++p || ! isgraph((u_char)*p))
                     70:                        return(0);
                     71:                switch (*p) {
                     72:                case ('('):
                     73:                        if (0 == *++p || ! isgraph((u_char)*p))
                     74:                                return(0);
                     75:                        return(4);
                     76:                case ('['):
                     77:                        for (c = 3, p++; *p && ']' != *p; p++, c++)
                     78:                                if ( ! isgraph((u_char)*p))
                     79:                                        break;
                     80:                        return(*p == ']' ? c : 0);
                     81:                default:
                     82:                        break;
                     83:                }
                     84:                return(3);
                     85:        case ('('):
                     86:                if (0 == *++p || ! isgraph((u_char)*p))
                     87:                        return(0);
                     88:                if (0 == *++p || ! isgraph((u_char)*p))
                     89:                        return(0);
                     90:                return(4);
                     91:        case ('['):
                     92:                break;
                     93:        default:
                     94:                return(0);
                     95:        }
                     96:
                     97:        for (c = 3, p++; *p && ']' != *p; p++, c++)
                     98:                if ( ! isgraph((u_char)*p))
                     99:                        break;
                    100:
                    101:        return(*p == ']' ? c : 0);
                    102: }
                    103:

CVSweb