Exemplo n.º 1
0
/* if the added stuff does not fit on current page, write it out
   after page break and change buffer handling mode to pass though */
void buffer_eob(int eot)
{
	block_put();
	if (epsf) {
		if (epsf == 3)
			write_eps();		/* close the image */
		return;
	}
	if (remy + bposy >= 0
	 || multicol_start != 0)
		return;

	// page full
	if (!in_page) {
		if ((cfmt.splittune == 2 && !(nbpages & 1))
		 || (cfmt.splittune == 3 && (nbpages & 1))) { // wrong odd/even page
			if (remy + maxy + bposy < 0) {	// 2nd overflow
				init_page();
				close_page();
				write_buffer();
				return;
			}
			if (eot)
				write_buffer();
			return;
		}
	} else {
		close_page();
	}
	if ((cfmt.splittune == 2 && !(nbpages & 1))
	 || (cfmt.splittune == 3 && (nbpages & 1)))
		use_buffer = 1;			// if wrong odd/even page
	else
		write_buffer();
#if 0
--- old
		if (use_buffer
		 && !eot
		 && ((cfmt.splittune == 2 && !(nbpages & 1))
		   || (cfmt.splittune == 3 && (nbpages & 1)))) {
			init_page();
// 8.7.4
			use_buffer = 1;
		} else {
// 8.7.5 - required to avoid buffer overflow
			write_buffer();
		}
//8.7.0
//		write_buffer();
//8.6.2
//		use_buffer = 0;
#endif
}
Exemplo n.º 2
0
int do_command(void)
{
	const char *cmd;
	int i;
	char lbuf[10];

	cmd = word + 1;

	/* Comments don't need the space */
	if (strncmp(cmd, "\\\"", 2) == 0)
		cmd = "\\\"";

	for (i = 0; cmd_list[i].cmd[0]; i++) {
		if (strcmp(cmd_list[i].cmd, cmd) == 0)
			break;
	}

	if (cmd_list[i].cmd[0] == 0) {
		if (verbose) {
			strncpy(lbuf, cmd, 3);
			lbuf[3] = 0;
			line_break();
			i = left_indent;
			left_indent = 0;
			strcpy(word, "**** Unknown formatter command: .");
			strcat(word, lbuf);
			print_word(word);
			line_break();
			left_indent = i;
		}

		i = 0;		/* Treat as comment */
	}

	switch (cmd_list[i].class) {
	case 1:		/* Parametered commands */
		return do_argvcmd(cmd_list[i].id);

	case 2:		/* Font changers */
		return do_fontwords(cmd_list[i].id / 10,
				    cmd_list[i].id % 10, 0);

	case 3:		/* .so */
		fetch_word();
		strcat(man_file, word);
		close_page();
		if (find_page(man_file, (char *) 0) < 0) {
			fprintf(stderr, "Cannot open .so file %s\n", word);
			return -1;
		}
		ungetc('\r', ifd);
		break;

	default:
		do_skipeol();
		if (cmd_list[i].id)
			return do_noargs(cmd_list[i].id);
	}
	return 0;
}
Exemplo n.º 3
0
/* epsf is always null */
void close_output_file(void)
{
	if (!fout)
		return;
	if (multicol_start != 0) {	/* if no '%%multicol end' */
		error(1, NULL, "No \"%%%%multicol end\"");
		multicol_start = 0;
		write_buffer();
	}
	if (tunenum == 0)
		error(0, NULL, "No tunes written to output file");
	close_page();
	switch (svg) {
	case 0:				/* PS */
		if (epsf == 0)
			fprintf(fout, "%%%%Trailer\n"
				"%%%%Pages: %d\n"
				"%%EOF\n", nbpages);
		close_fout();
		break;
	case 2:				/* -X */
		fputs("</body>\n"
			"</html>\n", fout);
	case 3:				/* -z */
		close_fout();
		break;
//	default:
//	case 1:				/* -v */
//		'fout' is closed in close_page
	}

	nbpages = tunenum = 0;
	defl = 0;
}
Exemplo n.º 4
0
/* ----- write_pagebreak ----- */
void write_pagebreak (FILE *fp)
{

  close_page (fp);
  init_page  (fp);
  if (strlen(page_init)>0) fprintf(fp,"%s\n", page_init);
  posy=cfmt.pageheight-cfmt.topmargin;

}
Exemplo n.º 5
0
static void document_manager_close_document_cb (DocumentManager *docmg, Documentable *doc, gpointer user_data)
{
  MainWindow *main_window = (MainWindow *) user_data;
  close_page(main_window, DOCUMENT(doc));
  update_app_title(main_window, document_manager_get_current_documentable(docmg));
  gchar *filename = documentable_get_filename (doc);
  gint ftype;
  g_object_get(doc, "type", &ftype, NULL);
  symbol_manager_purge_file (main_window->symbolmg, filename, ftype);
  g_free(filename);
}
Exemplo n.º 6
0
/****************************************************************************
 * Main routine, hunt down the manpage.
 */
int main(int argc, char **argv)
{
	int do_pclose_ofd = 0;
	int ar;
	char *mansect = 0;
	char *manname = 0;
	ofd = stdout;
	ifd = stdin;

	for (ar = 1; ar < argc; ar++)
		if (argv[ar][0] == '-') {
			char *p;
			for (p = argv[ar] + 1; *p; p++)
				switch (*p) {
				case 'w':
					flg_w = 1;
					break;
				case 'v':
					verbose = 1;
					break;
				case 'q':
					verbose = 0;
					break;
				}
		} else if (isdigit(argv[ar][0]))
			mansect = argv[ar];
		else if (manname == 0)
			manname = argv[ar];
		else if (mansect == 0) {
			mansect = manname;
			manname = argv[ar];
		} else {
			fprintf(stderr, "Ignoring argument %s\n",
				argv[ar]);
			break;
		}

	if (manname == 0) {
		fprintf(stderr, "Which manpage ?\n");
		exit(1);
	}

	if (find_page(manname, mansect) < 0) {
		if (mansect)
			fprintf(stderr,
				"No entry for %s in section %s of the manual.\n",
				manname, mansect);
		else
			fprintf(stderr, "No manual entry for %s\n",
				manname);
		exit(1);
	}
	if (flg_w)
		exit(0);

	/* ifd is now the file - display it */
	if (isatty(1)) {	/* If writing to a tty try to do it to a pager */
		/* The original way that this was coded relied on popen returning
		   NULL if PAGER was undefined. However, both on Linux and on
		   the V7 sh in FUZIX, sh barfed when getenv returned NULL:
		   sh: 0: -c requires an argument
		 */
		if (getenv("PAGER")) {
			ofd = popen(getenv("PAGER"), "w");
		} else {
			ofd = popen("more", "w");
		}
		if (ofd == 0) {
			/* This is likely unreachable because the popen will croak
			   in the absence of more:
			   sh: 1: tmore: not found
			   so we don't get the chance to fall-back to stdout
			 */
			ofd = stdout;
		} else {
			do_pclose_ofd = 1;
			page_length = 0;
			right_margin = 78;
		}
	}

	do_file();

	/* Close files */
	if (do_pclose_ofd)
		pclose(ofd);
	close_page();
	exit(0);
}
Exemplo n.º 7
0
/* -- write buffer contents, break at full pages -- */
void write_buffer(void)
{
	char *p_buf;
	int l, np;
	float p1, dp;
	int outft_sav;

	if (mbf == outbuf || multicol_start != 0)
		return;
	if (!in_page && !epsf)
		init_page();
	outft_sav = outft;
	p1 = 0;
	p_buf = outbuf;
	for (l = 0; l < ln_num; l++) {
		if (ln_pos[l] > 0) {		/* if in multicol */
			int ll;
			float pos;

			for (ll = l + 1; ll < ln_num; ll++) {
				if (ln_pos[ll] <= 0) {
					pos = ln_pos[ll];
					while (--ll >= l)
						ln_pos[ll] = pos;
					break;
				}
			}
		}
		dp = ln_pos[l] - p1;
		np = remy + dp < 0 && !epsf;
		if (np) {
			close_page();
			init_page();
			if (ln_font[l] >= 0) {
				struct FONTSPEC *f;

				f = &cfmt.font_tb[ln_font[l]];
				output(fout, "%.1f F%d\n",
					f->size, f->fnum);
			}
		}
		if (ln_scale[l] != cur_scale) {
			output(fout, "%.3f dup scale\n",
				ln_scale[l] / cur_scale);
			cur_scale = ln_scale[l];
		}
		if (ln_lmarg[l] != cur_lmarg) {
			output(fout, "%.2f 0 T\n",
				(ln_lmarg[l] - cur_lmarg) / cur_scale);
			cur_lmarg = ln_lmarg[l];
		}
		if (np) {
			output(fout, "0 %.2f T\n", -cfmt.topspace);
			remy -= cfmt.topspace * cfmt.scale;
		}
		if (*p_buf != '\001') {
			if (epsf > 1 || svg)
				svg_write(p_buf, ln_buf[l] - p_buf);
			else
				fwrite(p_buf, 1, ln_buf[l] - p_buf, fout);
		} else {			/* %%EPS - see parse.c */
			FILE *f;
			char line[BSIZE], *p, *q;

			p = strchr(p_buf + 1, '\n');
			fwrite(p_buf + 1, 1, p - p_buf, fout);
			p_buf = p + 1;
			p = strchr(p_buf, '%');
			*p++ = '\0';
			q = strchr(p, '\n');
			*q = '\0';
			if ((f = fopen(p, "r")) == NULL) {
				error(1, NULL, "Cannot open EPS file '%s'", p);
			} else {
				if (epsf > 1 || svg) {
					fprintf(fout, "<!--Begin document %s-->\n",
							p);
					svg_output(fout, "gsave\n"
							"%s T\n",
							p_buf);
					while (fgets(line, sizeof line, f))	/* copy the file */
						svg_write(line, strlen(line));
					svg_output(fout, "grestore\n"
							"%s T\n",
							p_buf);
					fprintf(fout, "<!--End document %s-->\n",
							p);
				} else {
					fprintf(fout,
						"save\n"
						"/showpage{}def/setpagedevice{pop}def\n"
						"%s T\n"
						"%%%%BeginDocument: %s\n",
						p_buf, p);
					while (fgets(line, sizeof line, f))	/* copy the file */
						fwrite(line, 1, strlen(line), fout);
					fprintf(fout, "%%%%EndDocument\n"
							"restore\n");
				}
				fclose(f);
			}
		}
		p_buf = ln_buf[l];
		remy += dp;
		p1 = ln_pos[l];
	}
#if 1 //fixme:test
	if (*p_buf != '\0') {
//		fprintf(stderr, "??? bug - buffer not empty:\n%s\n", p_buf);
		memcpy(outbuf, p_buf, strlen(p_buf) + 1);
		mbf = &outbuf[strlen(outbuf)];
	} else {
		mbf = outbuf;
	}
#endif
	outft = outft_sav;
	bposy = 0;
	ln_num = 0;
	use_buffer = 0;
}