📄 ipfe.c
字号:
fprintf(STDERR, "--ipfe: Log file: %s is open\n", logfilename); fprintf(logfile, "\n"); for (i=0; i < argc; i++) fprintf(logfile, "%s ", argv[i]); fprintf(logfile, "\n\n"); }}/**************************************************************** * * open_output: open the output for processing * ****************************************************************/open_output(){ char msg[128]; _fmode = BINARY_FILE; output = fopen(outputname, "w"); if (output == NULL) { terrno = errno; /* save errno */ (void)sprintf(msg, "--ipfe: Error opening output file: %s, retcd=%d\n", outputname, errno); pip_error(msg); errno = terrno; exit(2); }}/**************************************************************** * * open_propfile: open the properties file for processing * ****************************************************************/open_propfile(){ char msg[128]; _fmode = TEXT_FILE; if (propfname == 0) { (void)strcpy(prop_fname, input_fnm); (void)strcat(prop_fname, ".prop"); propfname = prop_fname; (void)sprintf(msg, "--ipfe: No properties filename specified. Using: %s\n", propfname); pip_error(msg); } propfile = fopen(propfname, "w"); if (propfile == NULL) { (void)sprintf(msg, "--ipfe: Can't open properties file: %s\n", propfname); pip_error(msg); *propfname = '\0'; } else { (void)sprintf(msg, "--ipfe: Properties file: %s is open\n", propfname); pip_error(msg); }}/**************************************************************** * * char *op_name(op): * char *op_name: check op_names[] table of op_code * name strings for non-null entry; * if non_null, * return ptr to the string, * else, * return ptr to string * "--Unknown op: <op>" * ****************************************************************/ char *op_name(op) int op;{ char buf[20]; if (op_names[op] == NULL) { (void)sprintf(buf, "--Unknown op: %d --", op); return(buf); } else return(op_names[op]);}/**************************************************************** * * pip_error(msg): * pip_error: put error msg to stdout & logfile * ****************************************************************/ pip_error(msg) char *msg;{ if (proc_flag[QUIET] != FLAG_ON) fprintf(STDERR, msg); if (logfile != NULL) fprintf(logfile, msg);}/**************************************************************** * * pip_prop(msg): * pip_prop: put msg to propfile * ****************************************************************/ pip_prop(msg) char *msg;{ if ((propfile != NULL) && (ovly_flag == FLAG_OFF)) { fprintf(propfile, msg); if (*(msg + strlen(msg) - 1) == '\n') cur_col = 0; else cur_col = cur_col + strlen(msg); }}/**************************************************************** * * preserve_SIF_copy(type_byte, length, file, filename): * preserve_SIF_copy: preserve SIF reference by copying * from specified input file to output * ****************************************************************/ copy_preserve_SIF(type_byte, length, file, filename) FILE *file; long length; int type_byte; char *filename;{ put_seq_type_len(type_byte, length); iocopyn(length, file, filename);}/**************************************************************** * * preserve_SIF_put(type_byte, length, buf): * preserve_SIF_put: preserve SIF reference by copying * from specified buffer to output * ****************************************************************/ put_preserve_SIF(type_byte, length, buf) long length; int type_byte; char *buf;{ put_seq_type_len(type_byte, length); ioputn(length, buf);}/**************************************************************** * * proc_alias(alias_string): * proc_alias: process alias argument * ****************************************************************/proc_alias(alias_string) char *alias_string;{ int indx, len; char msg[128]; len = strlen(alias_string); indx = mrstrichr(alias_string, ':'); if ((indx > 0) && (indx < (len - 1))) /* past beg & before end */ { (void)mstrncpy(alias_ref[alias_indx], alias_string, indx); ++indx; (void)mstrncpy(alias_act[alias_indx], (alias_string + indx), (len - indx)); ++alias_indx; ++num_aliases; } else { (void)sprintf(msg, "--ipfe: *** warning -- invalid alias specification (%s)\n", alias_string); pip_error(msg); exit_status = 4; }}/**************************************************************** * * proc_chapterize: test for & process chapterizing * ****************************************************************/ proc_chapterize(){ long len, temp_end_offset; int i, op, terrno, tblock_indx, proc_op_flag, eof_flag, proc_type; int type_byte; /* must be int for stdio EOF */ char msg[128]; if ((proc_flag[CHAPTERIZE] == FLAG_ON) && (((chap_type == CH_PAGES) && (out_numpages == chap_val)) || (((chap_type == CH_KBYTES) || (chap_type == CH_MBYTES)) && (out_offset >= chap_val)))) { /* * Eventually, the next two lines should be rewritten to check to see * if we might somehow be nested in a body before putting the * OP_endblock(s) */ for (i=0; i < block_indx; i++) put_op(OP_endBlock); (void)fclose(output);/* * Now, check for OP_endBlock(s) appearing immediately in the input * file. If so, skip them: they were already put out above. In looking, * if we get an EOF and there are no more input files, don't open a * new output file. */ proc_op_flag = eof_flag = FLAG_OFF; tblock_indx = block_indx; /* because the actual block_indx can be dcr'd in the loop */ for (i=0; i <= tblock_indx; i++) { type_byte = mgetc(input); if (feof(input)) {/* * set eof_flag only if there are no more input files */ if (input_indx >= (num_infiles - 1)) eof_flag = FLAG_ON; break; } else if ((type_byte & OP_Mask) == (LONG_OP & OP_Mask)) { op = ((type_byte & 0x1f) << 8) + getc_testeof(input, inputname); if ((op == OP_endBlock) && (i < block_indx)) --block_indx; else { proc_op_flag = FLAG_ON; /* set flag for use below */ proc_type = LONG_OP; break; } } else { proc_op_flag = FLAG_ON; /* set flag for use below */ proc_type = ~(LONG_OP); break; } } if (eof_flag == FLAG_OFF) { (void)strcpy(work_fname, outputname); workfile = fopen(work_fname, "r"); if (workfile == NULL) { terrno = errno; /* save errno */ pip_error( "Chapterize error opening previous output file as input\n"); (void)sprintf(msg, " file=%s, retcd=%d\n", outputname, errno); pip_error(msg); pip_error(" Can't complete chapterization --\n\n"); pip_error(" *** ABORTING ***\n"); errno = terrno; exit(3); } else { ++out_filnum; (void)strcpy(output_name, output_fnm); (void)strcat(output_name, itostr(out_filnum)); (void)strcat(output_name, output_ext); (void)sprintf(msg, "--ipfe: Processing output file: %s\n", outputname); pip_error(msg); _fmode = BINARY_FILE; output = fopen(outputname, "w"); if (output == NULL) { terrno = errno; /* save errno */ (void)sprintf(msg, "--ipfe: Error opening output file=%s, retcd=%d\n", outputname, errno); pip_error(msg); errno = terrno; exit(4); } else {/* * Then, copy Hdr & BEGIN/Preamble(s) to new output */ out_numpages = 0; out_offset = 0; for (i=0; i <= block_indx; i++) { len = out_end_offset[i] - out_beg_offset[i] + 1; out_beg_offset[i] = out_offset; iocopyn(len, workfile, work_fname); temp_end_offset = out_end_offset[i]; out_end_offset[i] = out_offset - 1; if (i < block_indx) /* if there is more to do */ { len = out_beg_offset[i+1] - temp_end_offset - 1; ioreadn(len, workfile, work_fname); } } } (void)fclose(workfile);/* * Finally, if a token other than OP_endBlock token was read above, * process it */ if (proc_op_flag == FLAG_ON) { if (proc_type == LONG_OP) proc_long_op(op); else proc_ip_token(type_byte, input, inputname); } } } }}/**************************************************************** * * proc_file: process the input file * ****************************************************************/ proc_file() { long offset; int i, op, retcd, exit_flag; int type_byte; /* must be int for stdio EOF */ char msg[128]; if (setjmp(next_file) != 0) /* for error recovery of */ { /* unexpected EOF */ return; } offset = in_offset; retcd = get_ip_hdr(input, inputname); /* get the hdr */ if (retcd == OK) { (void)sprintf(msg, "-- Hdr : %s--\n", hdr_workbuf); pip_error(msg); mputc_prop('\n'); put_offset_msg_to_prop(offset, hdr_workbuf); pip_prop("--\n"); if (input_indx == 0) /* if 1st file, */ { if (proc_flag[CONCAT] == FLAG_ON) (void)strcpy((hdr_workbuf+IP_VERS_OFFSET), "2.1 "); (void)strcpy(hdr_buf, hdr_workbuf); /* save hdr */ if (output != NULL) { (void)sprintf(msg, "\nProcessing output file: %s\n", outputname); pip_error(msg); (void)sprintf(msg, "-- Output Hdr: %s--\n", hdr_workbuf); pip_error(msg); ip_puts(hdr_workbuf); /* copy hdr & add len to out_offset */ }/* * copy everything up to, but NOT including (will include later), * OP_beginBlock */ exit_flag = FLAG_OFF; while (exit_flag == FLAG_OFF) { type_byte = getc_testeof(input, inputname); if ((type_byte & OP_Mask) == (LONG_OP & OP_Mask)) { op = ((type_byte & 0x1f) << 8) + getc_testeof(input, inputname); if (op == OP_beginBlock) exit_flag = FLAG_ON; else { ip_putc(type_byte); ip_putc(op); } } else proc_ip_token(type_byte, input, inputname); } out_end_offset[0] = out_offset - 1;/* * if concatenating, wrap a BEGIN empty_preamble END after the hdr & * instructionsBody and around the rest of the output */ if (proc_flag[CONCAT] == FLAG_ON) { ++block_indx; out_beg_offset[block_indx] = out_offset; put_op(OP_beginBlock); put_op(OP_beginBody); put_op(OP_endBody); out_end_offset[block_indx] = out_offset - 1; }/* * NOW include the OP_beginBlock, & process the rest of the master */ proc_long_op(OP_beginBlock); } prc_ip_tokens(input, inputname); mputc_prop('\n'); indent(off_indent, propfile); (void)sprintf(msg, "--Number of Blocks:%4d\n", num_blocks); pip_prop(msg); indent(off_indent, propfile); (void)sprintf(msg, "--Number of Pages :%4d\n", num_pages); pip_prop(msg); indent(off_indent, propfile); (void)sprintf(msg, "--Number of SIFs :%4d\n", num_sifs); pip_prop(msg); for (i=0; merge_pg[input_indx][i] != 0; i++) { if (merge_pg[input_indx][i] > num_pages) { (void)sprintf(msg, "\n--ipfe: *** Page %d selected > # of pages in %s (%d)\n", merge_pg[input_indx][i], inputname, num_pages); pip_error(msg); break; } } }/*** else { (void)sprintf(msg, "(*** PROCESSING ABORTED ***)\n"); pip_error(msg); input_indx = num_infiles; abort_flag = FLAG_ON; }***/}/**************************************************************** * * prc_IF_bof(ifile, ifilename): * prc_IF_bof: read specified Interpress file & * discard everything up to, and * including, first OP_beginBlock * ****************************************************************/prc_IF_bof(ifile, ifilename) FILE *ifile; char *ifilename;{ int op, exit_flag; int type_byte; /* must be int for stdio EOF */ exit_flag = FLAG_OFF; while (exit_flag == FLAG_OFF) { type_byte = getc_testeof(ifile, ifilename); if ((type_byte & OP_Mask) == (LONG_OP & OP_Mask)) { op = ((type_byte & 0x1f) << 8) + getc_testeof(ifile, ifilename); if (op == OP_beginBlock) exit_flag = FLAG_ON; } }}/**************************************************************** * * prc_IF_fragment(ifile, ifilename): * prc_IF_fragment: process specified Interpress fragment * (i.e., skip everything up to, and * including the first OP_beginBlock; * then include everything up to, but * not including, the next OP_endBlock) * ****************************************************************/prc_IF_fragment(ifile, ifilename) FILE *ifile; char *ifilename;{ int op, exit_flag; int type_byte; /* must be int for stdio EOF *//* * read & discard everything up to, and including, OP_beginBlock */ prc_IF_bof(ifile, ifilename);/* * read & copy everything up to, but NOT including OP_endBlock */ exit_flag = FLAG_OFF; while (exit_flag == FLAG_OFF) { typ
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -