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

📄 ipfe.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
		ovly_pg[i][j] = (-1);	    }	}	for (i=0; i < MX_BLOCK_DEPTH; i++)	    blk_num_bytes[i] = 0;	pg_num_bytes = 0;	for (i=0; i < MX_NO_INFILES; i++)	    infile_flag[i] = 0;	outputname = propfname = 0;/* *  make the beginBlock & endBlock names upper case */	op_names[OP_beginBlock] = "BEGIN";	op_names[OP_endBlock] = "END";}/**************************************************************** * *	init_proc_file:	initialize proc_file() loop * ****************************************************************/init_proc_file(){	sif_indx = 0;	cur_indent = cur_col = 0;	in_offset = 0;	num_blocks = num_pages = num_sifs = 0;	preamble_expected = FLAG_OFF;	merge_indx = 0;	bproc_indx = bop_indx = 0;	bproc_flag = bop_flag = FLAG_OFF;	ipwrite_flag = FLAG_ON;}/**************************************************************** * *	init1: *	init1_ipfe:		initialization after getting cmd args * ****************************************************************/init1_ipfe(){	int	i, tval, procflag, exit_flag;	char	msg[128];	if  (num_infiles == 0)	/* input_name req'd for now */	    Usage();	else	{/* *  split the 1st input_name into input_fnm & input_ext */		i = mrstrichr(input_name[0], '.');		if  (i != (-1))		{		    (void)mstrncpy(input_fnm, input_name[0], i);		    (void)strcpy(input_ext, (input_name[0] + i));		}		else		    (void)strcpy(input_fnm, input_name[0]);/* *  Open properties file */	    if  (proc_flag[PROPERTIES] == FLAG_ON)		open_propfile();/* *  Tell about rotate, xOffset, yOffset, binding offset, duplex, and scale */	    if  ((proc_flag[LANDSCAPE] == FLAG_ON) ||		 (proc_flag[ROTATE] == FLAG_ON))	    {		(void)sprintf(msg, "--ipfe:  Rotate %d degrees\n",				rot_deg);		pip_error(msg);	    }	    if  (proc_flag[X_OFFSET] == FLAG_ON)	    {		(void)sprintf(msg, "--ipfe:  xOffset = %ld/%ld meters\n",				xoff_num, xoff_den);		pip_error(msg);	    }	    if  (proc_flag[Y_OFFSET] == FLAG_ON)	    {		(void)sprintf(msg, "--ipfe:  yOffset = %ld/%ld meters\n",				yoff_num, yoff_den);		pip_error(msg);	    }	    if  (proc_flag[BINDING_OFFSET] == FLAG_ON)	    {		(void)sprintf(msg,			"--ipfe:  Binding offset = %ld/%ld meters\n",			boff_num, boff_den);		pip_error(msg);		if  (proc_flag[DUPLEX] == FLAG_ON)		    pip_error("--ipfe:  Duplex processing set\n");	    }	    if  (proc_flag[SCALE] == FLAG_ON)	    {		(void)sprintf(msg, "--ipfe:  Scale = %ld/%ld\n",				scale_num, scale_den);		pip_error(msg);	    }/* *  Tell about chapterizing */	    if  (proc_flag[CHAPTERIZE] == FLAG_ON)	    {		(void)sprintf(msg, "--ipfe:  Chapterize every %d ", chap_val);		pip_error(msg);		switch		    (chap_type)		{		    case (CH_PAGES):			pip_error("pages");			break;		    case (CH_KBYTES):			(void)sprintf(msg, "bytes (%d kbytes)",				(chap_val / 1024));			pip_error(msg);			break;		    case (CH_MBYTES):			(void)sprintf(msg, "bytes (%d mbytes)",				(chap_val / 1048576));			pip_error(msg);			break;		}		pip_error("\n");	    }/* *  Show any aliases */	    for (i=0; i < num_aliases; i++)	    {		if  (i == 0)		    pip_error("--ipfe:  ");		else		    pip_error("--       ");		(void)sprintf(msg, "Alias: %s=%s\n",			      alias_ref[i], alias_act[i]);		pip_error(msg);	    }	    if  (num_infiles > 1)		proc_flag[CONCAT] = FLAG_ON;	    if  (proc_flag[DEBUG] == FLAG_ON)		off_indent = 10;	    else		off_indent = 0;/* *  For now, IF the properties option flag is SET AND there is no output *  file specified, *  THEN set the environment for properties only (don't open output) */	    if  ((proc_flag[PROPERTIES] == FLAG_ON) &&		 (outputname == 0))		;	/* process properties only; no output */	    else	    {/* *  open the output file */		if  (outputname == 0)		{/* *  construct a default output filename by concatenating ".ip" to the *    fnm component of the 1st input filename, making sure the resulting *    filename doesn't already exist; if it does exist, append "1" to *    the fnm, then "2" to the fnm, etc. until the filename doesn't exist */		    tval = 0;		    exit_flag = procflag = FLAG_OFF;		    while			(exit_flag == FLAG_OFF)		    {			(void)strcpy(work_fname, input_fnm);			if  (procflag == FLAG_ON)			    (void)strcat(work_fname, itostr(tval));			(void)strcat(work_fname, ".ip");			_fmode = BINARY_FILE;			workfile = fopen(work_fname, "r");			if  (workfile == NULL)			{			    outputname = work_fname;			    exit_flag = FLAG_ON;			}			else			{			    (void)fclose(workfile);			    ++tval;			    procflag = FLAG_ON;			}		    }		}		(void)strcpy(output_name, outputname);		outputname = output_name;		i = mrstrichr(outputname, '.');		if  (i != (-1))		{		    (void)mstrncpy(output_fnm, outputname, i);		    (void)strcpy(output_ext, (outputname + i));		}		else		    (void)strcpy(output_fnm, outputname);		if  (proc_flag[CHAPTERIZE] == FLAG_ON)		{		    (void)strcpy(output_name, output_fnm);		    out_filnum = 1;		    (void)strcat(output_name, itostr(out_filnum));		    (void)strcat(output_name, output_ext);		}		open_output();	    }	}}/**************************************************************** * *	iocopyn(length, file, filename): *	iocopyn:		copy <length> bytes from specified *				file to output, checking for *				unexpected EOF * ****************************************************************/iocopyn(length, file, filename)	FILE	*file;	long	length;	char	*filename;{    	while	    (length-- > 0)	{	    ip_putc(getc_testeof(file, filename));	}}/**************************************************************** * *	iogetn(length, file, filename, buf): *	iogetn:		read <length> bytes from specified *				file into specified buf, checking *				for unexpected EOF *				-- throw the bytes away, for now * ****************************************************************/iogetn(length, file, filename, buf)	FILE	*file;	long	length;	char	*filename, *buf;{	while	    (length-- > 0)	{	    *buf++ = getc_testeof(file, filename);	}	*buf = '\0';}/**************************************************************** * *	ioputn(length, buf): *	ioputn:		put <length> bytes from specified *				buf to output * ****************************************************************/ioputn(length, buf)	long	length;	char	*buf;{	while	    (length-- > 0)	{	    ip_putc(*buf++);	}}/**************************************************************** * *	ioreadn(length, file, filename): *	ioreadn:		read <length> bytes from specified *				file, checking for unexpected EOF *				-- throw the bytes away, for now * ****************************************************************/ioreadn(length, file, filename)	FILE	*file;	long	length;	char	*filename;{    	while	    (length-- > 0)	{	    (void)getc_testeof(file, filename);	/* throw it away */	}}/**************************************************************** * *	ip_putc(ch): *	ip_putc:		put char to (interpress) output & *				bump out_offset * ****************************************************************/ip_putc(ch)	char	ch;{	if  ((output != NULL) && (ipwrite_flag == FLAG_ON))	{	    putc(ch, output);	    ++out_offset;	}}/**************************************************************** * *	ip_puts(string): *	ip_puts:		put string to (interpress) output *				& add strlen(string) to out_offset * ****************************************************************/ip_puts(string)	char	*string;{	if  ((output != NULL) && (ipwrite_flag == FLAG_ON))	{	    fprintf(output, string);	    out_offset = out_offset + strlen(string);	}}/**************************************************************** * *	char *itostr(ival): *	char *itostr:		cvt int to ascii string; return ptr * ****************************************************************/char *itostr(ival)	int	ival;{	int	i, digit, digit_flag;	char	num_buf[17], *s;	s = num_buf;	digit_flag = FLAG_OFF;	for (i=10000; i > 0; i=i/10)	{	    digit = ival / i;	    if  ((digit == 0) && (digit_flag == FLAG_OFF) && (i > 1))		;	/* do nothing */	    else	    {		*s = digit + '0';		++s;		ival = ival - (digit * i);		digit_flag = FLAG_ON;	    }	}	*s = '\0';return(num_buf);}/**************************************************************** * *	mgetc(file): *	mgetc:		get char from input & bump *				appropriate counters * ****************************************************************/int mgetc(file)	FILE	*file;{	int	val;	val = getc(file);	if  (!(feof(file)))	{	    val = val & 0xff;	    ++in_offset;	    ++blk_num_bytes[block_indx];	    ++pg_num_bytes;	}return(val);}/**************************************************************** * *	mputc_prop(ch): *	mputc_prop:		put char to propfile * ****************************************************************/mputc_prop(ch){	if  ((propfile != NULL) && (ovly_flag == FLAG_OFF))	{	    putc(ch, propfile);	    if  (ch == '\n')		cur_col = 0;	}}/**************************************************************** * *	int mrstrichr(str, ch): *	int mrstrichr:	reverse srch for char in string; *				if fnd, *				  return its pos (indexed from 0); *				else *				  return (-1) * ****************************************************************/int mrstrichr(str, ch)	char	*str, ch;{	int	i, indx, retcd;	retcd = (-1);	indx = strlen(str) - 1;	str = str + indx;	for (i=indx; i >= 0; i--, str--)	{	    if  (*str == ch)	    {		retcd = i;		break;	    }	}return(retcd);}/**************************************************************** * *	int mstrncmp(s1, s2, len): *	int mstrncmp:		cmp s1 to s2 for max of len bytes *				(byte-wise compare, left to right); *				if *s1 != *s2, *				  return (int)(*s1 - *s2) *				  (i.e., <0 if s1<s2, >0 if s1>s2) *				else *				  return 0 * ****************************************************************/int mstrncmp(s1, s2, len)	int	len;	char	*s1, *s2;{	int	i, retcd;	retcd = 0;	for (i=0; i < len; i++, s1++, s2++)	{	    if  (*s1 != *s2)	    {		retcd = (int)(*s1 - *s2);		break;	    }	}return(retcd);}/**************************************************************** * *	int mstrncpy(to, from, len): *	int mstrncpy:		copy from -> to for len; return *				actual # bytes copied (will be *				< len if <from> is null-terminated *				shorter than len); *				guarantees not overwriting allocated *				space for <to> if sizeof(to) is at *				least len + 1 (i.e., if len = *				sizeof(to) - 1; *				destination <to> is always null- *				terminated * ****************************************************************/int mstrncpy(to, from, len)	int	len;	char	*to, *from;{	int	cnt;	cnt = 0;	while	    ((len-- > 0) && (*from != '\0'))	{	    *to++ = *from++;	    ++cnt;	}	*to = '\0';return(cnt);}/**************************************************************** * *	open_logfile(argc, argv): *	open_logfile:		open the logfile for processing * ****************************************************************/open_logfile(argc, argv)	int	argc;	char	*argv[];{	int	i;	_fmode = TEXT_FILE;	logfile = fopen(logfilename, "w");	if  (logfile == NULL)	{	    fprintf(STDERR,		    "--ipfe:  Can't open log file: %s\n", logfilename);	    *logfilename = '\0';	}	else	{

⌨️ 快捷键说明

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