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

Annotation of mandoc/man_action.c, Revision 1.35

1.35    ! joerg       1: /*     $Id: man_action.c,v 1.34 2010/05/15 22:44:04 kristaps Exp $ */
1.1       kristaps    2: /*
1.32      kristaps    3:  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
1.1       kristaps    4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
1.10      kristaps    6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
1.1       kristaps    8:  *
1.10      kristaps    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.
1.1       kristaps   16:  */
1.25      kristaps   17: #ifdef HAVE_CONFIG_H
                     18: #include "config.h"
                     19: #endif
1.1       kristaps   20:
                     21: #include <assert.h>
                     22: #include <stdlib.h>
                     23: #include <string.h>
                     24:
                     25: #include "libman.h"
1.22      kristaps   26: #include "libmandoc.h"
1.1       kristaps   27:
                     28: struct actions {
                     29:        int     (*post)(struct man *);
                     30: };
                     31:
1.2       kristaps   32: static int       post_TH(struct man *);
1.18      kristaps   33: static int       post_fi(struct man *);
                     34: static int       post_nf(struct man *);
1.35    ! joerg      35: static int       post_AT(struct man *);
        !            36: static int       post_UC(struct man *);
1.2       kristaps   37:
1.1       kristaps   38: const  struct actions man_actions[MAN_MAX] = {
1.12      kristaps   39:        { NULL }, /* br */
1.2       kristaps   40:        { post_TH }, /* TH */
1.1       kristaps   41:        { NULL }, /* SH */
                     42:        { NULL }, /* SS */
                     43:        { NULL }, /* TP */
                     44:        { NULL }, /* LP */
                     45:        { NULL }, /* PP */
                     46:        { NULL }, /* P */
                     47:        { NULL }, /* IP */
                     48:        { NULL }, /* HP */
                     49:        { NULL }, /* SM */
                     50:        { NULL }, /* SB */
                     51:        { NULL }, /* BI */
                     52:        { NULL }, /* IB */
                     53:        { NULL }, /* BR */
                     54:        { NULL }, /* RB */
                     55:        { NULL }, /* R */
                     56:        { NULL }, /* B */
                     57:        { NULL }, /* I */
                     58:        { NULL }, /* IR */
1.5       kristaps   59:        { NULL }, /* RI */
1.8       kristaps   60:        { NULL }, /* na */
1.9       kristaps   61:        { NULL }, /* i */
1.14      kristaps   62:        { NULL }, /* sp */
1.18      kristaps   63:        { post_nf }, /* nf */
                     64:        { post_fi }, /* fi */
1.16      kristaps   65:        { NULL }, /* r */
                     66:        { NULL }, /* RE */
                     67:        { NULL }, /* RS */
1.17      kristaps   68:        { NULL }, /* DT */
1.35    ! joerg      69:        { post_UC }, /* UC */
1.20      kristaps   70:        { NULL }, /* PD */
1.27      kristaps   71:        { NULL }, /* Sp */
                     72:        { post_nf }, /* Vb */
                     73:        { post_fi }, /* Ve */
1.35    ! joerg      74:        { post_AT }, /* AT */
1.1       kristaps   75: };
                     76:
                     77:
                     78: int
                     79: man_action_post(struct man *m)
                     80: {
                     81:
                     82:        if (MAN_ACTED & m->last->flags)
                     83:                return(1);
                     84:        m->last->flags |= MAN_ACTED;
                     85:
                     86:        switch (m->last->type) {
                     87:        case (MAN_TEXT):
1.18      kristaps   88:                /* FALLTHROUGH */
1.1       kristaps   89:        case (MAN_ROOT):
1.18      kristaps   90:                return(1);
                     91:        default:
1.1       kristaps   92:                break;
                     93:        }
1.18      kristaps   94:
                     95:        if (NULL == man_actions[m->last->tok].post)
                     96:                return(1);
                     97:        return((*man_actions[m->last->tok].post)(m));
                     98: }
                     99:
                    100:
                    101: static int
                    102: post_fi(struct man *m)
                    103: {
                    104:
                    105:        if ( ! (MAN_LITERAL & m->flags))
                    106:                if ( ! man_nwarn(m, m->last, WNLITERAL))
                    107:                        return(0);
                    108:        m->flags &= ~MAN_LITERAL;
1.29      kristaps  109:        return(1);
                    110: }
                    111:
                    112:
                    113: static int
1.18      kristaps  114: post_nf(struct man *m)
                    115: {
                    116:
                    117:        if (MAN_LITERAL & m->flags)
                    118:                if ( ! man_nwarn(m, m->last, WOLITERAL))
                    119:                        return(0);
                    120:        m->flags |= MAN_LITERAL;
1.1       kristaps  121:        return(1);
                    122: }
                    123:
1.2       kristaps  124:
1.1       kristaps  125: static int
1.2       kristaps  126: post_TH(struct man *m)
1.1       kristaps  127: {
1.2       kristaps  128:        struct man_node *n;
1.1       kristaps  129:
                    130:        if (m->meta.title)
                    131:                free(m->meta.title);
                    132:        if (m->meta.vol)
                    133:                free(m->meta.vol);
1.2       kristaps  134:        if (m->meta.source)
                    135:                free(m->meta.source);
1.32      kristaps  136:        if (m->meta.msec)
                    137:                free(m->meta.msec);
1.1       kristaps  138:
1.31      kristaps  139:        m->meta.title = m->meta.vol =
                    140:                m->meta.msec = m->meta.source = NULL;
1.2       kristaps  141:        m->meta.date = 0;
                    142:
                    143:        /* ->TITLE<- MSEC DATE SOURCE VOL */
                    144:
                    145:        n = m->last->child;
                    146:        assert(n);
1.22      kristaps  147:        m->meta.title = mandoc_strdup(n->string);
1.2       kristaps  148:
                    149:        /* TITLE ->MSEC<- DATE SOURCE VOL */
1.1       kristaps  150:
1.2       kristaps  151:        n = n->next;
                    152:        assert(n);
1.31      kristaps  153:        m->meta.msec = mandoc_strdup(n->string);
1.1       kristaps  154:
1.2       kristaps  155:        /* TITLE MSEC ->DATE<- SOURCE VOL */
1.1       kristaps  156:
1.24      kristaps  157:        n = n->next;
                    158:        if (n) {
                    159:                m->meta.date = mandoc_a2time
                    160:                        (MTIME_ISO_8601, n->string);
                    161:                if (0 == m->meta.date) {
                    162:                        if ( ! man_nwarn(m, n, WDATE))
                    163:                                return(0);
                    164:                        m->meta.date = time(NULL);
                    165:                }
                    166:        } else
1.2       kristaps  167:                m->meta.date = time(NULL);
1.1       kristaps  168:
1.2       kristaps  169:        /* TITLE MSEC DATE ->SOURCE<- VOL */
1.1       kristaps  170:
1.5       kristaps  171:        if (n && (n = n->next))
1.22      kristaps  172:                m->meta.source = mandoc_strdup(n->string);
1.1       kristaps  173:
1.2       kristaps  174:        /* TITLE MSEC DATE SOURCE ->VOL<- */
1.1       kristaps  175:
1.5       kristaps  176:        if (n && (n = n->next))
1.22      kristaps  177:                m->meta.vol = mandoc_strdup(n->string);
1.1       kristaps  178:
1.29      kristaps  179:        /*
                    180:         * Remove the `TH' node after we've processed it for our
                    181:         * meta-data.
                    182:         */
                    183:        man_node_delete(m, m->last);
1.35    ! joerg     184:        return(1);
        !           185: }
        !           186:
        !           187:
        !           188: static int
        !           189: post_AT(struct man *m)
        !           190: {
        !           191:        static const char * const unix_versions[] = {
        !           192:            "7th Edition",
        !           193:            "System III",
        !           194:            "System V",
        !           195:            "System V Release 2",
        !           196:        };
        !           197:
        !           198:        const char      *p, *s;
        !           199:        struct man_node *n, *nn;
        !           200:
        !           201:        n = m->last->child;
        !           202:
        !           203:        if (NULL == n || MAN_TEXT != n->type)
        !           204:                p = unix_versions[0];
        !           205:        else {
        !           206:                s = n->string;
        !           207:                if (0 == strcmp(s, "3"))
        !           208:                        p = unix_versions[0];
        !           209:                else if (0 == strcmp(s, "4"))
        !           210:                        p = unix_versions[1];
        !           211:                else if (0 == strcmp(s, "5")) {
        !           212:                        nn = n->next;
        !           213:                        if (nn && MAN_TEXT == nn->type && nn->string[0])
        !           214:                                p = unix_versions[3];
        !           215:                        else
        !           216:                                p = unix_versions[2];
        !           217:                } else
        !           218:                        p = unix_versions[0];
        !           219:        }
        !           220:
        !           221:        m->meta.source = mandoc_strdup(p);
        !           222:
        !           223:        return(1);
        !           224: }
        !           225:
        !           226:
        !           227: static int
        !           228: post_UC(struct man *m)
        !           229: {
        !           230:        static const char * const bsd_versions[] = {
        !           231:            "3rd Berkeley Distribution",
        !           232:            "4th Berkeley Distribution",
        !           233:            "4.2 Berkeley Distribution",
        !           234:            "4.3 Berkeley Distribution",
        !           235:            "4.4 Berkeley Distribution",
        !           236:        };
        !           237:
        !           238:        const char      *p, *s;
        !           239:        struct man_node *n;
        !           240:
        !           241:        n = m->last->child;
        !           242:
        !           243:        if (NULL == n || MAN_TEXT != n->type)
        !           244:                p = bsd_versions[0];
        !           245:        else {
        !           246:                s = n->string;
        !           247:                if (0 == strcmp(s, "3"))
        !           248:                        p = bsd_versions[0];
        !           249:                else if (0 == strcmp(s, "4"))
        !           250:                        p = bsd_versions[1];
        !           251:                else if (0 == strcmp(s, "5"))
        !           252:                        p = bsd_versions[2];
        !           253:                else if (0 == strcmp(s, "6"))
        !           254:                        p = bsd_versions[3];
        !           255:                else if (0 == strcmp(s, "7"))
        !           256:                        p = bsd_versions[4];
        !           257:                else
        !           258:                        p = bsd_versions[0];
        !           259:        }
        !           260:
        !           261:        m->meta.source = mandoc_strdup(p);
        !           262:
1.2       kristaps  263:        return(1);
                    264: }

CVSweb