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

📄 ipfe.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
					    break;					case ('p'):					    val = val * 254;					    d = ((d * 720000) & 0x7fffffff);					    break;					case ('P'):					    val = val * 254;					    d = ((d * 60000) & 0x7fffffff);					    break;					default:					    d = d * 100;  /* def=cm */					    break;				    }/*				    end switch (ch) */				    if  (d != 0)  /* last chk for div						     by 0 just in case						     of ovflw */				    {					yoff_num = val;					yoff_den = d;					proc_flag[Y_OFFSET] = FLAG_ON;				    }				}				else				{				    (void)sprintf(msg,			"--ipfe:  No yOffset value specified in (%s)\n",						  argv[arg]);				    pip_error(msg);				    err_flag = FLAG_ON;				}				--opt;	/* to parse cur ch at cmd line */				break;			    default:				(void)sprintf(msg,				    "--ipfe:  Invalid option in %s (%s)\n",					argv[arg], &(argv[arg][opt]));				pip_error(msg);				err_flag = FLAG_ON;				break;			}		    }		    break;		case ('['):		    break;		case ('>'):		    break;		default:/* *  the current arg is an input file; try to open it */		    if  (input_indx < MX_NO_INFILES)		    {			_fmode = BINARY_FILE;			workfile = fopen(argv[arg], "r");			if  (workfile == NULL)			{			    (void)sprintf(msg, 				    "--ipfe:  Error opening input file: %s\n",				    argv[arg]);			    pip_error(msg);			    err_flag = FLAG_ON;			}			else			{/* *  check for valid hdr */			    retcd = get_ip_hdr(workfile, argv[arg]);			    if  (retcd == OK)			    {				(void)strcpy(input_name[input_indx],					     argv[arg]);/* *  check for page range */				if  (((arg + 1) < argc) &&				     ((argv[arg+1][0] == '[') ||				      (argv[arg+1][0] == '+') ||				      (argv[arg+1][0] == '#')))				{				    ++arg;				    get_pagerange(arg, argv);				}				else				    merge_pg[input_indx][0] = (-1);				infile_flag[input_indx] = FLAG_ON;				++input_indx;				++num_infiles;			    }			    else				err_flag = FLAG_ON;			    (void)fclose(workfile);			}		    }		    else		    {			(void)sprintf(msg,	"--ipfe:  Maximum # of input files = %d; File:  %s not processed\n",				MX_NO_INFILES, argv[arg]);			pip_error(msg);			err_flag = FLAG_ON;		    }		    break;	    }/*	    end switch (argv[arg][0]) */	}/*	end for (arg=1; arg < argc; arg++) */	if  (err_flag == FLAG_ON)	    pip_error("\n");}/**************************************************************** * *	int get_ip_hdr(file, filename): *	int get_ip_hdr:	get the ip_hdr from the specified *				file into a work_buf & return a *				ptr to the buf * ****************************************************************/int get_ip_hdr(file, filename)	FILE	*file;	char	*filename;{	int	i, retcd, hdr_flag;	int	c;		/* must be int for stdio EOF compare */	char	*ptr, msg[128];	retcd = OK;/* *  get the header */	ptr = hdr_workbuf;	hdr_flag = FLAG_OFF;	for (i=0; i < MX_HDR_BUFLEN; i++)	{	    c = getc_testeof(file, filename);  /* get a char,          */	    *ptr++ = c;			/*   & stick it in the buffer  */	    if  (c == ' ')		/* if c=ip_hdr_terminate_char, */	    {		hdr_flag = FLAG_ON;	/*   set hdr_ok flag,          */		break;			/*   & exit the loop           */	    }	}	*ptr = '\0';/* *  ... & check its validity */	if  (hdr_flag == FLAG_OFF)	{	    (void)sprintf(msg, "--ipfe:  Hdr length > %d chars in file: %s\n",		    MX_HDR_BUFLEN, filename);	    pip_error(msg);	    retcd = ERROR;	}	if  (mstrncmp(hdr_workbuf, IP_Header, IP_HDR_CHKLEN) != 0)	{	    (void)sprintf(msg, "--ipfe:  INVALID HEADER! in file: %s\n",			  filename);	    pip_error(msg);	    retcd = ERROR;	}return(retcd);}/**************************************************************** * *	get_pagerange(arg, argv): *	get_pagerange:	get cmd_line page range argument *				for current input_indx from *				specified argument * ****************************************************************/get_pagerange(arg, argv)	int	arg;	char	*argv[];{	int	i, opt, opt_len, d, val, val1, lp_ctr, ch_ctr,		prv_mpg_num, err_flag, neg_flag;	char	ch, nc;	char	msg[128], name_buf[128];	merge_indx = val = 0;	prv_mpg_num = 0;	opt_len = strlen(argv[arg]);	err_flag = FLAG_OFF;	for (opt=1; ((opt < opt_len) && (err_flag == FLAG_OFF)); opt++)	{	    switch		(argv[arg][opt])	    {		case ('-'):		    merge_pg[input_indx][merge_indx] = (-1);		    ++merge_indx;		    break;/* *  all of the following can just be ignored at this level */		case (','):		case (']'):		case (')'):		case (SPC):		case ('\n'):		    break;		case ('['):		case ('+'):/* *  overlay filename */		    if  (strlen(&(argv[arg][opt])) > 1)		    {			ch = '\0';			i = 0;			++opt;			while			    (opt < opt_len)			{			    ch = argv[arg][opt];			    if  ((ch == ':') || (ch == '(') || (ch == '@') ||				 (ch == '+'))			    {				--opt;	    /* reparse opt at switch level */				break;			    }			    else			    if  ((ch == ']') || (ch == ','))				break;	    /* don't bother reparsing */			    else			    {				name_buf[i++] = ch;				++opt;			    }			}			name_buf[i] = '\0';			if  (i > 0)			{			    if  (merge_indx == 0)			    {				merge_pg[input_indx][0] = 1;				++merge_indx;			    }			    if  (merge_pg[input_indx][(merge_indx-1)] > 0)			    {				if  (ovly_pg[input_indx][(merge_indx-1)] !=					(-1))				{				    merge_pg[input_indx][merge_indx] =					merge_pg[input_indx][(merge_indx-1)];				    ++merge_indx;				}				ovly_pg[input_indx][(merge_indx-1)] =				    ovly_indx;				(void)strcpy(ovly_fname[ovly_indx], name_buf);				++ovly_indx;			    }			    else				err_flag = FLAG_ON;			}			else			    err_flag = FLAG_ON;		    }		    else			err_flag = FLAG_ON;		    break;		case (':'):/* *  overlay pagenum */		    if  ((ovly_indx == 0) ||		    	 (ovly_pg[input_indx][merge_indx-1] == (-1)) ||			 (ovly_pgnum[ovly_indx-1] != 0))			err_flag = FLAG_ON;		    else		    if  (strlen(&(argv[arg][opt])) > 1)		    {			val = 0;			++opt;			while			    (opt < opt_len)			{			    ch = argv[arg][opt];			    if  ((ch >= '0') && (ch <= '9'))			    {				ch = ch - '0';				val = (val * 10) + ch;				++opt;			    }			    else			    {				--opt;	/* reparse everything else at the					   switch level */				break;			    }			}/* *  if the pagenum is good, process it */			if  (val > 0)			    ovly_pgnum[ovly_indx-1] = val;		    }		    else			err_flag = FLAG_ON;		    break;		case ('('):		case ('@'):/* *  overlay page offset */		    if  ((ovly_indx == 0) ||		    	 (ovly_pg[input_indx][merge_indx-1] == (-1)))			err_flag = FLAG_ON;		    else		    if  (strlen(&(argv[arg][opt])) > 1)		    {			val = val1 = d = lp_ctr = ch_ctr = 0;			neg_flag = FLAG_OFF;			++opt;			while			    ((opt < opt_len) && (lp_ctr < 2))			{			    ch = argv[arg][opt++];			    if  ((ch == '-') && (ch_ctr == 0))				neg_flag = FLAG_ON;			    else			    if ((ch >= '0') && (ch <= '9'))			    {				ch = ch - '0';				if  (d == 0)				    val = (val * 10) + ch;				else				if  (d <= 1000)  /* precision = 10**(-3)						    truncated */				{				    val1 = (val1 * 10) + ch;				    d = d * 10;				}			    }			    else			    if (ch == '.')			    {				d = 1;				val1 = 0;			    }			    else			    {				if  (d != 0)				    val = (val * d) + val1;				else				    d = 1;				if  (val != 0)				{				    if  (neg_flag == FLAG_ON)					val = -(val);				    switch					(ch)				    {					case ('c'):					    d = d * 100;					    break;					case ('i'):					    val = val * 254;					    d = d * 10000;					    break;					case ('p'):					    val = val * 254;					    d = ((d * 720000) & 0x7fffffff);					    break;					case ('P'):					    val = val * 254;					    d = ((d * 60000) & 0x7fffffff);					    break;					default:					    d = d * 100;  /* assume cm */					    break;				    }				    if  (d != 0)  /* last chk for div by 0						     just in case of ovflw */				    {					ovly_num[lp_ctr][ovly_indx-1] = val;					ovly_den[lp_ctr][ovly_indx-1] = d;				    }				    if  (lp_ctr == 0)				    {					nc = argv[arg][opt];					if  (((nc < '0') && (nc != '-')) ||					     (nc > '9'))					    ++opt; /* assume only 1 separator						      after scale char */				    }				}				val = d = 0;				neg_flag = FLAG_OFF;				++lp_ctr;				ch_ctr = (-1);				if  ((lp_ctr == 2) &&				     ((ch == '+') || (ch == '[') ||				      (ch == '-')))				    --opt;	/* reparse at switch level */			    }			    ++ch_ctr;			}			--opt;	    /* to undo the automatic incr above */		    }		    else			err_flag = FLAG_ON;		    break;		default:/* *  current opt should be a pageNum */		    val = 0;		    while			(opt < opt_len)		    {			ch = argv[arg][opt];			if  ((ch >= '0') && (ch <= '9'))			{			    ch = ch - '0';			    val = (val * 10) + ch;			    ++opt;			}			else			if  ((ch == '-') || (ch == ',') || (ch == '[') ||			     (ch == ']') || (ch == '+'))			{			    --opt;	/* reparse opt at switch level */			    break;			}			else			if  ((ch == SPC) || (ch == '\n'))			    break;	/* don't bother to reparse */			else			{			    err_flag = FLAG_ON;			    break;			}		    }/* *  if the val is good, process it */		    if  (val > prv_mpg_num)		    {			merge_pg[input_indx][merge_indx] = val;			prv_mpg_num = val;			++merge_indx;		    }		    else			err_flag = FLAG_ON;		    break;	    }/*	    end of switch (argv[arg][opt]) */	    if  (err_flag == FLAG_ON)	    {		(void)sprintf(msg,		    "--ipfe:  Invalid pagerange specification in %s (%s)\n",				argv[arg], &(argv[arg][opt]));		pip_error(msg);		exit_status = 5;	    }	}/*	end of for (opt=1; ((opt < opt_len) && (err_flag == FLAG_OFF));		    ++ opt) */}/**************************************************************** * *	int getc_testeof(file, filename): *	int getc_testeof:	get a char from input file; *				if we get an EOF here, *				    it's an error; *				else, *				    return the char as an int * ****************************************************************/int getc_testeof(file, filename)	FILE	*file;	char	*filename;{	int	val;	char	msg[128];	val = mgetc(file);	if  (feof(file))	{	    (void)sprintf(msg, "\nUnexpected EOF! in file:  %s\n", filename);	    pip_error(msg);	    longjmp(next_file, 1);	}return(val);}/**************************************************************** * *	indent(cnt, file): *	indent:		put <cnt> spcs to specified file * ****************************************************************/indent(cnt, file)	FILE	*file;	int	cnt;{	if  (file != NULL)	{	    if  ((file == propfile) && (cnt > 0))		cur_col = cur_col + cnt;	    while		(cnt-- > 0)	    {		putc(' ', file);	    }	}}/**************************************************************** * *	init: *	init_ipfe:		initialization * ****************************************************************/init_ipfe(){	int	i, j;	abort_flag = debug_flag = FLAG_OFF;	exit_status = 0;	ovly_flag = FLAG_OFF;	frstpg_flag = FLAG_OFF;	num_infiles = out_filnum = 0;	input_indx = output_indx = sif_indx = 0;	num_aliases = 0;	alias_indx = 0;	prop_level = 0;	hdr_len = 0;	pos = in_offset = 0;	block_indx = 0;	block_flag = FLAG_OFF;	out_beg_offset[block_indx] = 0;	tnum_blocks = tnum_pages = tnum_sifs = 0;	for (i=0; i < NUM_FNS; i++)	    proc_flag[i] = FLAG_OFF;	chap_type = chap_val = 0;	ipwrite_flag = FLAG_ON;	merge_indx = ovly_indx = 0;	for (i=0; i < MX_NO_INFILES; i++)	{	    merge_pg[i][0] = (-1);	/* init to all pages */	    ovly_pg[i][0] = (-1);	/* init to no overlay */	    for (j=1; j < MX_NO_MPG_ENTRIES; j++)	    {		merge_pg[i][j] = 0;

⌨️ 快捷键说明

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