Annotation of mandoc/tbl_data.c, Revision 1.1
1.1 ! kristaps 1: /* $Id: data.c,v 1.11 2009/09/12 16:05:34 kristaps Exp $ */
! 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:
! 69: struct tbl_span *
! 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);
! 79: return(NULL);
! 80: }
! 81:
! 82: dp = mandoc_calloc(1, sizeof(struct tbl_span));
! 83:
! 84: if ( ! strcmp(p, "_")) {
! 85: dp->flags |= TBL_SPAN_HORIZ;
! 86: return(dp);
! 87: } else if ( ! strcmp(p, "=")) {
! 88: dp->flags |= TBL_SPAN_DHORIZ;
! 89: return(dp);
! 90: }
! 91:
! 92: while ('\0' != p[pos])
! 93: data(tbl, dp, ln, p, &pos);
! 94:
! 95: return(dp);
! 96: }
CVSweb