Example #1
0
void
tbl_data(struct tbl_node *tbl, int ln, const char *p, int pos)
{
	struct tbl_span	*dp;
	struct tbl_row	*rp;

	/*
	 * Choose a layout row: take the one following the last parsed
	 * span's.  If that doesn't exist, use the last parsed span's.
	 * If there's no last parsed span, use the first row.  Lastly,
	 * if the last span was a horizontal line, use the same layout
	 * (it doesn't "consume" the layout).
	 */

	if (tbl->last_span != NULL) {
		if (tbl->last_span->pos == TBL_SPAN_DATA) {
			for (rp = tbl->last_span->layout->next;
			     rp != NULL && rp->first != NULL;
			     rp = rp->next) {
				switch (rp->first->pos) {
				case TBL_CELL_HORIZ:
					dp = newspan(tbl, ln, rp);
					dp->pos = TBL_SPAN_HORIZ;
					continue;
				case TBL_CELL_DHORIZ:
					dp = newspan(tbl, ln, rp);
					dp->pos = TBL_SPAN_DHORIZ;
					continue;
				default:
					break;
				}
				break;
			}
		} else
			rp = tbl->last_span->layout;

		if (rp == NULL)
			rp = tbl->last_span->layout;
	} else
		rp = tbl->first_row;

	assert(rp);

	dp = newspan(tbl, ln, rp);

	if ( ! strcmp(p, "_")) {
		dp->pos = TBL_SPAN_HORIZ;
		return;
	} else if ( ! strcmp(p, "=")) {
		dp->pos = TBL_SPAN_DHORIZ;
		return;
	}

	dp->pos = TBL_SPAN_DATA;

	while (p[pos] != '\0')
		getdata(tbl, dp, ln, p, &pos);
}
Example #2
0
extern void
analyze(void)			/* analyze our scene */
{
	int	h, v;
	int	left;
	float	*spanbr;

	spanbr = (float *)malloc((2*hsize+1)*sizeof(float));
	if (spanbr == NULL)
		memerr("view span brightness buffer");
	for (v = vsize; v >= -vsize; v--) {
		close_sources(v);
#ifndef DEBUG
		if (verbose) {
			fprintf(stderr, "%s: analyzing... %3ld%%\r",
				progname, 100L*(vsize-v)/(2*vsize));
			fflush(stderr);
		}
#endif
		getviewspan(v, spanbr);
		left = hsize + 1;
		for (h = -hsize; h <= hsize; h++) {
			if (spanbr[h+hsize] < 0.0) {	/* off view */
				if (left < h) {
					addsrcspan(newspan(left,h,v,spanbr));
					left = hsize + 1;
				}
				continue;
			}
			if (spanbr[h+hsize] > threshold) {	/* in source */
				if (left > h)
					left = h;
			} else {			/* out of source */
				if (left < h) {
					addsrcspan(newspan(left,h,v,spanbr));
					left = hsize + 1;
				}
				addindirect(h, v, spanbr[h+hsize]);
			}
		}
		if (left < h)
			addsrcspan(newspan(left,h,v,spanbr));
	}
	free((void *)spanbr);
	close_allsrcs();
}
Example #3
0
int
tbl_data(struct tbl_node *tbl, int ln, const char *p)
{
	struct tbl_span	*dp;
	struct tbl_row	*rp;
	int		 pos;

	pos = 0;

	if ('\0' == p[pos]) {
		mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, pos, NULL);
		return(0);
	}

	/* 
	 * Choose a layout row: take the one following the last parsed
	 * span's.  If that doesn't exist, use the last parsed span's.
	 * If there's no last parsed span, use the first row.  Lastly,
	 * if the last span was a horizontal line, use the same layout
	 * (it doesn't "consume" the layout).
	 */

	if (tbl->last_span) {
		assert(tbl->last_span->layout);
		if (tbl->last_span->pos == TBL_SPAN_DATA) {
			for (rp = tbl->last_span->layout->next;
					rp && rp->first; rp = rp->next) {
				switch (rp->first->pos) {
				case (TBL_CELL_HORIZ):
					dp = newspan(tbl, ln, rp);
					dp->pos = TBL_SPAN_HORIZ;
					continue;
				case (TBL_CELL_DHORIZ):
					dp = newspan(tbl, ln, rp);
					dp->pos = TBL_SPAN_DHORIZ;
					continue;
				default:
					break;
				}
				break;
			}
		} else
			rp = tbl->last_span->layout;

		if (NULL == rp)
			rp = tbl->last_span->layout;
	} else
		rp = tbl->first_row;

	assert(rp);

	dp = newspan(tbl, ln, rp);

	if ( ! strcmp(p, "_")) {
		dp->pos = TBL_SPAN_HORIZ;
		return(1);
	} else if ( ! strcmp(p, "=")) {
		dp->pos = TBL_SPAN_DHORIZ;
		return(1);
	}

	dp->pos = TBL_SPAN_DATA;

	/* This returns 0 when TBL_PART_CDATA is entered. */

	while ('\0' != p[pos])
		if ( ! data(tbl, dp, ln, p, &pos))
			return(0);

	return(1);
}
Example #4
0
void
tbl_data(struct tbl_node *tbl, int ln, const char *p, int pos)
{
	struct tbl_row	*rp;
	struct tbl_cell	*cp;
	struct tbl_span	*sp;

	rp = (sp = tbl->last_span) == NULL ? tbl->first_row :
	    sp->pos == TBL_SPAN_DATA && sp->layout->next != NULL ?
	    sp->layout->next : sp->layout;

	assert(rp != NULL);

	if (p[1] == '\0') {
		switch (p[0]) {
		case '.':
			/*
			 * Empty request lines must be handled here
			 * and cannot be discarded in roff_parseln()
			 * because in the layout section, they
			 * are significant and end the layout.
			 */
			return;
		case '_':
			sp = newspan(tbl, ln, rp);
			sp->pos = TBL_SPAN_HORIZ;
			return;
		case '=':
			sp = newspan(tbl, ln, rp);
			sp->pos = TBL_SPAN_DHORIZ;
			return;
		default:
			break;
		}
	}

	/*
	 * If the layout row contains nothing but horizontal lines,
	 * allocate an empty span for it and assign the current span
	 * to the next layout row accepting data.
	 */

	while (rp->next != NULL) {
		if (rp->last->col + 1 < tbl->opts.cols)
			break;
		for (cp = rp->first; cp != NULL; cp = cp->next)
			if (cp->pos != TBL_CELL_HORIZ &&
			    cp->pos != TBL_CELL_DHORIZ)
				break;
		if (cp != NULL)
			break;
		sp = newspan(tbl, ln, rp);
		sp->pos = TBL_SPAN_DATA;
		rp = rp->next;
	}

	/* Process a real data row. */

	sp = newspan(tbl, ln, rp);
	sp->pos = TBL_SPAN_DATA;
	while (p[pos] != '\0')
		getdata(tbl, sp, ln, p, &pos);
}