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

Annotation of mandoc/tbl_data.c, Revision 1.2

1.2     ! kristaps    1: /*     $Id: tbl_data.c,v 1.1 2010/12/29 16:44:23 kristaps Exp $ */
1.1       kristaps    2: /*
                      3:  * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
                      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:  */
                     17: #include <assert.h>
                     18: #include <ctype.h>
                     19: #include <stdlib.h>
                     20: #include <string.h>
                     21:
                     22: #include "mandoc.h"
                     23: #include "libmandoc.h"
                     24: #include "libroff.h"
                     25:
                     26: static void    data(struct tbl *, struct tbl_span *,
                     27:                        int, const char *, int *);
                     28:
                     29: void
                     30: data(struct tbl *tbl, struct tbl_span *dp,
                     31:                int ln, const char *p, int *pos)
                     32: {
                     33:        struct tbl_dat  *dat;
                     34:        int              sv;
                     35:
                     36:        /* FIXME: warn about losing data contents if cell is HORIZ. */
                     37:
                     38:        dat = mandoc_calloc(1, sizeof(struct tbl_dat));
                     39:
                     40:        if (dp->last) {
                     41:                dp->last->next = dat;
                     42:                dp->last = dat;
                     43:        } else
                     44:                dp->last = dp->first = dat;
                     45:
                     46:        sv = *pos;
                     47:        while (p[*pos] && p[*pos] != tbl->tab)
                     48:                (*pos)++;
                     49:
                     50:        dat->string = mandoc_malloc(*pos - sv + 1);
                     51:        memcpy(dat->string, &p[sv], *pos - sv);
                     52:        dat->string[*pos - sv] = '\0';
                     53:
                     54:        if (p[*pos])
                     55:                (*pos)++;
                     56:
                     57:        /* XXX: do the strcmps, then malloc(). */
                     58:
                     59:        if ( ! strcmp(dat->string, "_"))
                     60:                dat->flags |= TBL_DATA_HORIZ;
                     61:        else if ( ! strcmp(dat->string, "="))
                     62:                dat->flags |= TBL_DATA_DHORIZ;
                     63:        else if ( ! strcmp(dat->string, "\\_"))
                     64:                dat->flags |= TBL_DATA_NHORIZ;
                     65:        else if ( ! strcmp(dat->string, "\\="))
                     66:                dat->flags |= TBL_DATA_NDHORIZ;
                     67: }
                     68:
1.2     ! kristaps   69: int
1.1       kristaps   70: tbl_data(struct tbl *tbl, int ln, const char *p)
                     71: {
                     72:        struct tbl_span *dp;
                     73:        int              pos;
                     74:
                     75:        pos = 0;
                     76:
                     77:        if ('\0' == p[pos]) {
                     78:                TBL_MSG(tbl, MANDOCERR_TBL, ln, pos);
1.2     ! kristaps   79:                return(1);
1.1       kristaps   80:        }
                     81:
                     82:        dp = mandoc_calloc(1, sizeof(struct tbl_span));
                     83:
1.2     ! kristaps   84:        if (tbl->last_span) {
        !            85:                tbl->last_span->next = dp;
        !            86:                tbl->last_span = dp;
        !            87:        } else
        !            88:                tbl->last_span = tbl->first_span = dp;
        !            89:
1.1       kristaps   90:        if ( ! strcmp(p, "_")) {
                     91:                dp->flags |= TBL_SPAN_HORIZ;
1.2     ! kristaps   92:                return(1);
1.1       kristaps   93:        } else if ( ! strcmp(p, "=")) {
                     94:                dp->flags |= TBL_SPAN_DHORIZ;
1.2     ! kristaps   95:                return(1);
1.1       kristaps   96:        }
                     97:
                     98:        while ('\0' != p[pos])
                     99:                data(tbl, dp, ln, p, &pos);
                    100:
1.2     ! kristaps  101:        return(1);
1.1       kristaps  102: }

CVSweb