⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipfe.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
/***  file = ipfe.c  ********************************************//*** start of specifications ************************************ * * name = ipfe * descriptive name = interpress file editor * filename = ipfe.c * module type = main * subsystem name = interpress toolkit * copyright = (c) 1985, 1986, xerox corporation * author = mark l. rollins * date written = 10/oct/85 * * change activity = *   07/18/86 r1.05 mlr wrc:	changed so Scale follows, rather than *				  precedes, Rotate, BindingOffset, XOffset, *				  and YOffset in output processing *   06/16/86 r1.04 mlr wrc:	add Scale processing *   05/19/86 r1.03 mlr wrc:	fixed bug in dsply of Y-offset values *   04/22/86 r1.02 mlr wrc:	fixed bug in pagerange parsing that gave *				  error on terminating "]"; *				add vers display *   03/14/86 r1.01 mlr wrc:	major enhancements *   10/10/85 r1.00 mlr wrc:	original date * *   release = r1.05 *   date = 18/jul/86 * * function = provide the following skeleton- and page-level functions *		for editing interpress masters: *		.  concatenate masters *		.  merge pages from multiple masters into one master *		.  overlay selected pages as a single page (may be *			combined with merge function) *		.  chapterize a master into multiple masters *		.  satisfy sequenceInsertFile & sequenceInsertMaster *			references *		.  resolve alias and binding offset printing instructions *		.  return information about the properties of a set of *			masters * * function description = * *	Usage:  ipfe [ options ] file [ pagerange] ... [ file [pagerange] ...] *	Options: [-l logfile] [-dDiLqrRsS] [-a alias:actual [-a alias:actual] *		 ...] [-b offset:unit] [-c count:unit] [-o outfile] *		 [-p level:propfile] [-S factor] [-X offset:unit] *		 [-Y offset:unit] * *		 -a alias:actual *				(alias). If the -s option is specified, *				replace any SIF matching the string "alias" *				with the string "actual" before attempting *				to satisfy the SIF. If "actual" cannot be *				opened or there is some error, the SIF *				"alias" is preserved, unless the -r option *				is also specified. *		 -b offset:unit	(binding offset). Shift the image offset units *				in the x-direction, where unit may be: none *				(default centimeters), c (centimeters), i *				(inches), p (points), P (Picas). If the -L *				(Landscape) switch is set, the image offset *				is in the y-direction. *		 -c count:unit	(chapterize) every count units, where unit may *				be p (pages), k (kilobytes), or m (megabytes). *		 -d		(duplex). For resolving binding offset. *		 -D		(Debug). If the -p option is specified, also *				write to the properties file the offsets of *				each skeleton-level token encountered. *		 -i		(insert SIF for overlay). Insert (create) a *				SIF for any unresolvable overlays. *		 -l logfile	(log). Keep a running log. *		 -L		(Landscape). Rotate every page 90 degrees *				counterclockwise and preserve the upper left *				corner. Intended for printing text in *				landscape orientation. *		 -o outfile	(output). Where the output goes. If there is *				no -o and there is a -p, only the properties *				are written, else if there is no -o *				"infile.ip" is used if it doesn't already *				exist, else "infileN.ip" is used, where N *				is the lowest ordinal number such that *				"infileN.ip" does not already exist. *		 -p level:propfile *				(properties). Where the properties are *				written. Increasing levels provide increasing *				information details. *		 -q		(quiet). Don't write info & error msgs (to *				STDERR). *		 -r		(remove SIFS). If -s is also specified, it *				takes precedence and a SIF reference is *				removed only if it is unresolved or there is *				some other error. *		 -R		(Rotate). Rotate every page 90 degrees *				clockwise and preserve the center point. *				Intended for rotating an image created for *				a "landscape printer" to print in portrait *				orientation. *		 -s		(satisfy SIFS). Replace any SIF references *				tokens found in the referenced file. If the *				referenced file cannot be opened, the SIF *				reference is preserved unless -r is also *				specified. *		 -S factor	(scale). Scale the image by factor. *		 -X offset:unit	(X-imageShift). Shift the image offset units *				in the x-direction, where unit may be: none *				(default centimeters), c (centimeters), i *				(inches), p (points), P (Picas). The shift *				is independent of the -L and -R switches *				(i.e., the x-direction is the same as the *				unrotated image). *		 -Y offset:unit	(Y-imageShift). Shift the image offset units *				in the y-direction, where unit may be: none *				(default centimeters), c (centimeters), i *				(inches), p (points), P (Picas). The shift *				is independent of the -L and -R switches *				(i.e., the y-direction is the same as the *				unrotated image). *		 infile [pagerange] *				See the manual page for syntax details. *		  Example: *		   [1,4-6,9[pic1],10-11,12[pic2:2(2P,4P)][pic3(-4P,-2P)],15-] *				include page 1. *				skip pages 2-3. *				include pages 4-6. *				skip pages 7-8. *				include page 9, overlaying it with pic1. *				include pages 10-11. *				include pages 12, overlaying it with page 2 of *				  pic2 at an offset of 2 Picas to the right *				  and 4 Picas up, and pic3 at an offset of *				  4 Picas to the left and 2 Picas down. *				skip pages 13-14. *				include pages 15 thru the end of the master. * * linkage = *   entry = exec ipfe *   input = see cmd line options above *   output = interpress master(s), STDERR, log file, property file *   exit = exit(exit_status) * * publics = * * dependencies = *   src = iptokens.h, ipnames.h *   obj = *   lnk = * * environment = *   runtime = vax/masscomp unix/4.23bsd *   development = vax unix/4.23bsd *   processor = cc *   code = unix c mnemonics & linkages * *** end of specifications **************************************/#ifdef vax11c# include stdio# include setjmp# include ctype#else# include <stdio.h>/***# include <sys/time.h># include <sys/resource.h>***/# include <setjmp.h># include <ctype.h>#endif#include "iptokens.h"#include "ipnames.h"#define	IPFE_VERS	"1.05"#define	IPFE_DATE	"18 JUL 86"#define	FALSE		0#define	TRUE		1#define	FLAG_OFF	0#define	FLAG_ON		1#define	CR		13#define	BEL		07#define	BS		08#define	TAB		09#define	LF		10#define	FF		12#define	TOF		12#define	SPC		32#define	ESC		27#define	DEL		127#define	STDIN		stdin#define	STDOUT		stdout#define	STDERR		stderr#define	STDIN_DEV	0#define	STDOUT_DEV	1#define	STDERR_DEV	2#define	DEF_LOGFILENAME	"ipfe.log"#define	DEF_OUTFILENAME	"ipfe.ip"#define	DEF_PROPFILENAME "ipfe.prop"#define	DEF_WORKFILENAME "ipfe.wrk"#define	BUFSIZE		2048#define	OP_Mask		0xe0#define	OK		0#define	ERROR		(-1)#define	DONT_FORMAT	0#define	FORMAT		1#define	MX_NO_INFILES	64#define	MX_NO_OUTFILES	64#define	MX_NO_OVLY_FILES  64#define	IP_HDR_CHKLEN	17#define	IP_VERS_OFFSET	17#define	IP_HDR_MASTERLEN 21#define	MX_HDR_BUFLEN	255#define	MX_NO_ALIASES	128#define	MX_NO_MPG_ENTRIES 128#define	MX_BLOCK_DEPTH	8#define	MX_BODY_DEPTH	8#define	MX_BOP_DEPTH	16	/* max # of nested body_operators */#define	MX_SIF_DEPTH	8	/* max sif nesting depth */#define	INDENT_INCR	3	/* # cols to incr indent each nesting depth *//* *  defines for ipfe fn types */#define	CONCAT		0#define	CHAPTERIZE	1#define	SATISFY_SIFS	2#define	REMOVE_SIFS	3#define	PROPERTIES	4#define	INSERT_OVLY	5#define	DEBUG		6#define	PROC_LOG	7#define	FORCE_STDOUT	8#define	BINDING_OFFSET	9#define	DUPLEX		10#define	QUIET		11#define	LANDSCAPE	12#define	ROTATE		13#define	SCALE		14#define	X_OFFSET	15#define	Y_OFFSET	16#define	NUM_FNS		17/* *  defines for chapterization type */#define	CH_PAGES	1#define	CH_KBYTES	2#define	CH_MBYTES	3#ifdef lcv2			/* if Lattice C vers 2.15 or earlier */#define	void	int#endif/* *  lattice C defines for fopen file types (binary & text) */#define	BINARY_FILE	0x8000#define	TEXT_FILE	0FILE	*input;FILE	*output;FILE	*workfile;	/* work file for testing input file opens & storing			   hdr/preamble for chapterizing */FILE	*ovly_file;FILE	*sif_file[MX_SIF_DEPTH];FILE	*siffile;FILE	*logfile;FILE	*propfile;jmp_buf	next_file;extern int errno;int	_fmode = TEXT_FILE;	/* lattice C file_mode */int	abort_flag, debug_flag;int	terrno;int	exit_status;long	pos, in_offset, out_offset;long	out_beg_offset[MX_BLOCK_DEPTH],	out_end_offset[MX_BLOCK_DEPTH];long	chap_val;long	boff_num, boff_den;	/* binding offset numerator, denominator */long	xoff_num, xoff_den;	/* xOffset numerator, denominator */long	yoff_num, yoff_den;	/* yOffset numerator, denominator */long	rxoff_num, rxoff_den,	/* rotation xOffset numerator, denominator */	ryoff_num, ryoff_den;	/*          yOffset numerator, denominator */long	scale_num, scale_den;	/* scale factor numerator, denominator */long	blk_num_bytes[MX_BLOCK_DEPTH];long	pg_num_bytes;int	num_infiles, out_filnum;int	input_indx, output_indx, sif_indx;int	prop_level;int	cur_indent, off_indent, cur_col;int	ovly_flag;int	proc_flag[NUM_FNS];int	chap_type;int	ipwrite_flag;int	rot_deg;		/* rotation degrees */int	num_aliases;int	alias_indx;int	begBody_flag;int	preamble_expected, endpreamble_expected, frstpg_flag,	bop_preamble_expected[MX_BOP_DEPTH];/* *  MERGE & OVERLAY ARRAYS *    There are 2 second order arrays, one for merge pages and one for *    overlay files. The 1st order of both is indexed by input_indx, and *    the 2nd order by merge_indx. For overlay files, there are 3 *    additional arrays, one for an overlay pagenum, one for page offset *    numerators, and one for page offset denominators. These 3 arrays *    are indexed by ovly_indx (the 1st order indexing for the numerator *    and denominator arrays is 0 for the x-offset and 1 for the y-offset). * *    Each 2nd order vector of the merge_pg[][] array is initialized to *    (-1),0,0,... which indicates to include all pages, and each vector *    of the ovly_pg[][] array is initialized to (-1),(-1),(-1),... which *    indicates no overlay files. *    As IPFE scans the command line, an entry is put into the merge_pg[][] *    array for each pageNum specified in a pagerange for an infile (the *    value put into the entry is pageNum). If there is an overlay file *    specified for pageNum, the (-1) in the ovly_pg[][merge_indx] entry *    is replaced with the current value of ovly_indx and ovly_indx is *    incremented. If there is another overlay file specified for pageNum, *    the value pageNum is repeated in the next merge_pg[][] entry and the *    incremented ovly_indx is placed in the next ovly_pg[][] entry. *      Example: *        ipfe infile "[2,4-6,9[ovly1],12[ovly2][ovly3],15-]" *      will yield the following merge_pg[input_indx][] &  *      ovly_pg[input_indx][] vectors: *                    0    1    2    3    4    5    6    7    8    9   10 *                  ----|----|----|----|----|----|----|----|----|----|---- *        merge_pg:   2 ,  4 ,(-1),  6 ,  9 , 12 , 12 , 15 ,(-1),  0 ,  0 ,... *        ovly_pg:  (-1),(-1),(-1),(-1),  0 ,  1 ,  2 ,(-1),(-1),(-1),(-1),... * *    The algorithm used to decode the merge_pg vector for each infile is *    as follows: *      Initialize merge_indx to 0; *      Loop: *      Current_entry = merge_pg[input_indx][merge_indx]; *        If Current_entry = 0, we're all done with this infile; *	  Else if Current_entry = (-1), look at next merge_indx entry; *          Next_entry = merge_pg[input_indx][merge_indx+1]; *            If Next_entry = 0, include all pages to the end of infile; *	      Else include all pages until the value of Next_entry is *              reached in infile; when it is, increment merge_indx (making *              Current_entry = Next_entry, and goto Loop; *        Else exclude all pages until Current_entry is reached in infile *          (it may already be reached); when it is, include that page and *	      check the ovly_pg[][] entry; *          Ovly_entry = ovly_pg[input_indx][merge_indx]; *            If Ovly_entry != (-1) do overlay processing; *          Increment merge_indx, and goto Loop; */int	merge_indx, merge_pg[MX_NO_INFILES][MX_NO_MPG_ENTRIES];int	ovly_indx, ovly_pg[MX_NO_INFILES][MX_NO_MPG_ENTRIES];int	ovly_pgnum[MX_NO_OVLY_FILES];long	ovly_num[2][MX_NO_OVLY_FILES],	ovly_den[2][MX_NO_OVLY_FILES];int	block_indx;int	block_flag;int	bproc_indx, bop_indx, bop_iindx[MX_BOP_DEPTH];int	bproc_flag, bop_flag;int	num_blocks, num_pages, num_sifs,	tnum_blocks, tnum_pages, tnum_sifs;int	out_numpages;int	infile_flag[MX_NO_INFILES];int	hdr_len;char	hdr_buf[MX_HDR_BUFLEN+1], hdr_workbuf[MX_HDR_BUFLEN+1];char	input_name[MX_NO_INFILES][128], input_fnm[128], input_ext[128],	output_name[128], output_fnm[128], output_ext[128],	work_fname[128], sif_name[MX_SIF_DEPTH][128], prop_fname[128];char	ovly_fname[MX_NO_OVLY_FILES][128];char	alias_ref[MX_NO_ALIASES][128], alias_act[MX_NO_ALIASES][128];char	*inputname, *outputname, *sifname, *propfname;char	*logfilename = "ipfe.log";char	*itostr(), lcase(), *op_name(), *strcat(), *strcpy();/**************************************************************** * *	main(argc, argv):	ipfe mainline: *	main:			  interpress file editor * ****************************************************************/main(argc, argv)	int	argc;	char	*argv[];{	char	msg[128];	(void)sprintf(msg,		      "\nIPFE Version %s, %s -- Interpress File Editor\n",		      IPFE_VERS, IPFE_DATE);	pip_error(msg);	pip_error("Copyright (c) 1985,1986 Xerox Corporation\n\n");	init_ipfe();	get_cmd_args(argc, argv);	init1_ipfe();		/* initialization after getting cmd args */	for (input_indx=0; input_indx < num_infiles; input_indx++)	{	    init_proc_file();	    inputname = input_name[input_indx];	    (void)sprintf(msg, "-- File:  %s--\n", inputname);	    pip_error(msg);	    pip_prop(msg);	    _fmode = BINARY_FILE;	    input = fopen(inputname, "r");	    if  (input == NULL)	    {		(void)sprintf(msg, "\nError opening input file: %s\n",				   inputname);		pip_error(msg);		pip_prop(msg);	    }	    else	    {		proc_file();		/* do the real work */		(void)fclose(input);	    }	}	if  ((abort_flag == FLAG_OFF) &&	     (proc_flag[CONCAT] == FLAG_ON))	{	    ipwrite_flag = FLAG_ON;	/* in case it was turned off by					   last file processed */	    put_op(OP_endBlock);	}	cleanup();	exit(exit_status);}/**************************************************************** * *	cleanup:		housecleaning * ****************************************************************/cleanup(){	char	msg[128];	if  (proc_flag[CONCAT] == FLAG_ON)	{	    (void)sprintf(msg, "\n--Total Number of Blocks:%4d\n", tnum_blocks);	    pip_prop(msg);	    (void)sprintf(msg,   "--Total Number of Pages :%4d\n", tnum_pages);	    pip_prop(msg);	    (void)sprintf(msg,   "--Total Number of SIFs  :%4d\n", tnum_sifs);	    pip_prop(msg);	}	mputc_prop('\n');	(void)sprintf(msg, "\n-- Total Number of Input Pages :%4d\n",			tnum_pages);	pip_error(msg);	if  ((output != NULL) || (out_numpages > 0))	{	    (void)sprintf(msg, "-- Total Number of Output Pages:%4d\n",			    out_numpages);	    pip_error(msg);	}	pip_error("\n");	if  (logfile != NULL)	    (void)fclose(logfile);	if  (propfile != NULL)	    (void)fclose(propfile);	if  (output != NULL)	    (void)fclose(output);}/**************************************************************** * *	int count_int_bytes(val): *	int count_int_bytes:	return the number of bytes in the *				specified int val * ****************************************************************/int count_int_bytes(val)	long	val;{	long	mask;	int	i;	if  ((val == 0) || (val == (-1)))	    i = 1;		/* avoid infinite looping */	else	{	    if  (val < 0)		val = ~(val);	/* same # of bytes as one's complement */	    mask = 0xff800000;	    for (i=4; ((val & mask) == 0); i--)		mask = mask >> 8;	}return(i);}/**************************************************************** * *	create_SIF(fname): *	create_SIF:		create a new SIF (for ovly handling) * ****************************************************************/create_SIF(fname)	char	*fname;{	int	not_created_flag;	char	msg[128];	not_created_flag = FLAG_OFF;	if  (proc_flag[INSERT_OVLY] == FLAG_ON)	{	    if  (ovly_pgnum[ovly_indx] < 2)	    {		(void)sprintf(msg,			"                  --Creating SIF:  %s\n", fname);		pip_error(msg);		put_seq_type_len(sequenceInsertFile, (long)strlen(fname));		ip_puts(fname);	    }	    else	    {		pip_error(    "                  --Cannot create SIF for overlay with pageNum > 1\n");		not_created_flag = FLAG_ON;	    }	}	else	{	    pip_error(    "                    -i switch (Insert SIF for overlay) not specified\n");	    not_created_flag = FLAG_ON;	}	if  (not_created_flag == FLAG_ON)	{	    (void)sprintf(msg,			  "                  --SIF Not Created for:  %s\n",			  fname);	    pip_error(msg);	}}/**************************************************************** * *	get_cmd_args(argc, argv):

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -