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

Annotation of mandoc/man_action.c, Revision 1.1

1.1     ! kristaps    1: /* $Id: action.c,v 1.51 2009/03/23 14:31:58 kristaps Exp $ */
        !             2: /*
        !             3:  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
        !             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 <sys/utsname.h>
        !            20:
        !            21: #include <assert.h>
        !            22: #include <err.h>
        !            23: #include <errno.h>
        !            24: #include <stdio.h>
        !            25: #include <stdlib.h>
        !            26: #include <string.h>
        !            27:
        !            28: #include "libman.h"
        !            29:
        !            30:
        !            31: struct actions {
        !            32:        int     (*post)(struct man *);
        !            33: };
        !            34:
        !            35:
        !            36: const  struct actions man_actions[MAN_MAX] = {
        !            37:        { NULL }, /* __ */
        !            38:        { NULL }, /* TH */
        !            39:        { NULL }, /* SH */
        !            40:        { NULL }, /* SS */
        !            41:        { NULL }, /* TP */
        !            42:        { NULL }, /* LP */
        !            43:        { NULL }, /* PP */
        !            44:        { NULL }, /* P */
        !            45:        { NULL }, /* IP */
        !            46:        { NULL }, /* HP */
        !            47:        { NULL }, /* SM */
        !            48:        { NULL }, /* SB */
        !            49:        { NULL }, /* BI */
        !            50:        { NULL }, /* IB */
        !            51:        { NULL }, /* BR */
        !            52:        { NULL }, /* RB */
        !            53:        { NULL }, /* R */
        !            54:        { NULL }, /* B */
        !            55:        { NULL }, /* I */
        !            56:        { NULL }, /* IR */
        !            57: };
        !            58:
        !            59:
        !            60: int
        !            61: man_action_post(struct man *m)
        !            62: {
        !            63:
        !            64:        if (MAN_ACTED & m->last->flags)
        !            65:                return(1);
        !            66:        m->last->flags |= MAN_ACTED;
        !            67:
        !            68:        switch (m->last->type) {
        !            69:        case (MAN_TEXT):
        !            70:                break;
        !            71:        case (MAN_ROOT):
        !            72:                break;
        !            73:        default:
        !            74:                if (NULL == man_actions[m->last->tok].post)
        !            75:                        break;
        !            76:                return((*man_actions[m->last->tok].post)(m));
        !            77:        }
        !            78:        return(1);
        !            79: }
        !            80:
        !            81: #if 0
        !            82: static int
        !            83: post_dt(POST_ARGS)
        !            84: {
        !            85:        struct mdoc_node *n;
        !            86:        const char       *cp;
        !            87:        char             *ep;
        !            88:        long              lval;
        !            89:
        !            90:        if (m->meta.title)
        !            91:                free(m->meta.title);
        !            92:        if (m->meta.vol)
        !            93:                free(m->meta.vol);
        !            94:        if (m->meta.arch)
        !            95:                free(m->meta.arch);
        !            96:
        !            97:        m->meta.title = m->meta.vol = m->meta.arch = NULL;
        !            98:        m->meta.msec = 0;
        !            99:
        !           100:        /* Handles: `.Dt'
        !           101:         *   --> title = unknown, volume = local, msec = 0, arch = NULL
        !           102:         */
        !           103:
        !           104:        if (NULL == (n = m->last->child)) {
        !           105:                m->meta.title = xstrdup("unknown");
        !           106:                m->meta.vol = xstrdup("local");
        !           107:                return(post_prol(m));
        !           108:        }
        !           109:
        !           110:        /* Handles: `.Dt TITLE'
        !           111:         *   --> title = TITLE, volume = local, msec = 0, arch = NULL
        !           112:         */
        !           113:
        !           114:        m->meta.title = xstrdup(n->string);
        !           115:
        !           116:        if (NULL == (n = n->next)) {
        !           117:                m->meta.vol = xstrdup("local");
        !           118:                return(post_prol(m));
        !           119:        }
        !           120:
        !           121:        /* Handles: `.Dt TITLE SEC'
        !           122:         *   --> title = TITLE, volume = SEC is msec ?
        !           123:         *           format(msec) : SEC,
        !           124:         *       msec = SEC is msec ? atoi(msec) : 0,
        !           125:         *       arch = NULL
        !           126:         */
        !           127:
        !           128:        cp = mdoc_a2msec(n->string);
        !           129:        if (cp) {
        !           130:                m->meta.vol = xstrdup(cp);
        !           131:                errno = 0;
        !           132:                lval = strtol(n->string, &ep, 10);
        !           133:                if (n->string[0] != '\0' && *ep == '\0')
        !           134:                        m->meta.msec = (int)lval;
        !           135:        } else
        !           136:                m->meta.vol = xstrdup(n->string);
        !           137:
        !           138:        if (NULL == (n = n->next))
        !           139:                return(post_prol(m));
        !           140:
        !           141:        /* Handles: `.Dt TITLE SEC VOL'
        !           142:         *   --> title = TITLE, volume = VOL is vol ?
        !           143:         *       format(VOL) :
        !           144:         *           VOL is arch ? format(arch) :
        !           145:         *               VOL
        !           146:         */
        !           147:
        !           148:        cp = mdoc_a2vol(n->string);
        !           149:        if (cp) {
        !           150:                free(m->meta.vol);
        !           151:                m->meta.vol = xstrdup(cp);
        !           152:                n = n->next;
        !           153:        } else {
        !           154:                cp = mdoc_a2arch(n->string);
        !           155:                if (NULL == cp) {
        !           156:                        free(m->meta.vol);
        !           157:                        m->meta.vol = xstrdup(n->string);
        !           158:                } else
        !           159:                        m->meta.arch = xstrdup(cp);
        !           160:        }
        !           161:
        !           162:        /* Ignore any subsequent parameters... */
        !           163:
        !           164:        return(post_prol(m));
        !           165: }
        !           166:
        !           167: static int
        !           168: post_prol(POST_ARGS)
        !           169: {
        !           170:        struct mdoc_node *n;
        !           171:
        !           172:        /*
        !           173:         * The end document shouldn't have the prologue macros as part
        !           174:         * of the syntax tree (they encompass only meta-data).
        !           175:         */
        !           176:
        !           177:        if (m->last->parent->child == m->last)
        !           178:                m->last->parent->child = m->last->prev;
        !           179:        if (m->last->prev)
        !           180:                m->last->prev->next = NULL;
        !           181:
        !           182:        n = m->last;
        !           183:        assert(NULL == m->last->next);
        !           184:
        !           185:        if (m->last->prev) {
        !           186:                m->last = m->last->prev;
        !           187:                m->next = MDOC_NEXT_SIBLING;
        !           188:        } else {
        !           189:                m->last = m->last->parent;
        !           190:                m->next = MDOC_NEXT_CHILD;
        !           191:        }
        !           192:
        !           193:        mdoc_node_freelist(n);
        !           194:        return(1);
        !           195: }
        !           196: #endif

CVSweb