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

Annotation of mandoc/macro.c, Revision 1.1

1.1     ! kristaps    1: /* $Id: roff.c,v 1.63 2008/12/10 16:03:12 kristaps Exp $ */
        !             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 <stdlib.h>
        !            20:
        !            21: #include "roff.h"
        !            22:
        !            23: static int
        !            24: macro_args_next(struct rofftree *tree, int *pos, char *buf, char **v)
        !            25: {
        !            26:        int              i;
        !            27:
        !            28:        if (0 == buf[*pos])
        !            29:                return(0);
        !            30:
        !            31:        if ('\"' == buf[*pos]) {
        !            32:                /* Syntax error: quotation marks not allowed. */
        !            33:                return(-1);
        !            34:        }
        !            35:
        !            36:        *v = &buf[*pos];
        !            37:
        !            38:        while (buf[*pos] && ! isspace(buf[*pos]))
        !            39:                (*pos)++;
        !            40:
        !            41:        if (buf[*pos + 1] && '\\' == buf[*pos]) {
        !            42:                /* Syntax error: escaped whitespace not allowed. */
        !            43:                return(-1);
        !            44:        }
        !            45:
        !            46:        buf[i] = 0;
        !            47:        return(1);
        !            48: }
        !            49:
        !            50: /*
        !            51:  * Parses the following:
        !            52:  *
        !            53:  *     .Xx foo bar baz ; foo "bar baz" ; ;
        !            54:  *         ^----------   ^----------
        !            55:  */
        !            56: static int
        !            57: macro_fl(struct rofftree *tree, int tok, int *pos, char *buf)
        !            58: {
        !            59:        int               i, j, c, first;
        !            60:        char             *args[ROFF_MAXLINEARG];
        !            61:
        !            62:        first = *pos == 0;
        !            63:
        !            64:        for (j = 0; ; ) {
        !            65:                i = *pos;
        !            66:                c = macro_args_next(tree, *i, buf, args[j]);
        !            67:                if (-1 == c)
        !            68:                        return(0);
        !            69:                if (0 == c)
        !            70:                        break;
        !            71:
        !            72:                /* Break at the next command.  */
        !            73:
        !            74:                if (ROFF_MAX != (c = rofffindcallable(args[pos]))) {
        !            75:                        if ( ! macro(tree, tok, argc, argv, i, p))
        !            76:                                return(0);
        !            77:                        if ( ! parse(tree, c, pos, args))
        !            78:                                return(0);
        !            79:                        break;
        !            80:                }
        !            81:
        !            82:                /* Continue if we're just words. */
        !            83:
        !            84:                if ( ! roffispunct(args[pos])) {
        !            85:                        i++;
        !            86:                        continue;
        !            87:                }
        !            88:
        !            89:                /* Break if there's only remaining punctuation. */
        !            90:
        !            91:                if (args[pos + 1] && roffispunct(args[pos + 1]))
        !            92:                        break;
        !            93:
        !            94:                /* If there are remaining words, start anew. */
        !            95:
        !            96:                if ( ! macro(tree, tok, argc, argv, i, p))
        !            97:                        return(0);
        !            98:
        !            99:                /* Spit out the punctuation. */
        !           100:
        !           101:                if ( ! word(tree, tok, *args++))
        !           102:                        return(0);
        !           103:                i++;
        !           104:        }
        !           105: }

CVSweb