📄 intprint.c
字号:
/***********************************************/
void add_category_filter_info(filter, str)
CF_ENUM filter ;
char *str ;
/* insert category filter characters into proper buffer, provided they do
not appear in other filter buffers
*/
{
static char err_msg[] =
"Character \"x\" appears in more than one category filter string";
#define err_char_pos 11 /* position of x in err_msg */
CF_ENUM f ;
int i = 0, len = strlen(cf_buffers[filter]) ;
char c, errmsg[80] ;
while ((c = str[i++]) > ' ' && len < CF_BUFFER_SIZE)
{
for (f = filter; ; )
{
if ((f = (f + 1) % CF_ENUM_SIZE) == filter)
break; /* all other filters checked */
if (strchr(cf_buffers[f], c))
{
err_msg[err_char_pos] = c ;
fatal(err_msg) ;
}
}
cf_buffers[filter][len++] = c;
}
#undef err_char_pos
}
/***********************************************/
FILT_LIST *add_filter_info(list,str)
FILT_LIST *list ;
char *str ;
{
FILT_LIST *newfilt ;
int len = strlen(str)+1 ;
if ((newfilt = (FILT_LIST *)malloc(sizeof(struct filter_list)+len))
!= NULL)
{
newfilt->next = list ;
memcpy(newfilt->str,str,len) ;
strupr(newfilt->str) ;
}
else
fatal("out of memory") ;
return newfilt ;
}
/***********************************************/
void build_filter_lists(file)
char *file ;
{
static char err_msg[] = "Unknown command \"x\" in filter file";
#define err_char_pos 17 /* position of x in err_msg */
IP_FILE *fp ;
char buf[MAXLINE] ;
int len ;
long result ;
if ((fp = ip_open_read(file,filter_buf,sizeof(filter_buf))) == NULL)
{
warning("unable to open filtering file, will print entire list.") ;
do_filter = FALSE ;
}
else /* OK, file is open, so start reading */
{
do {
buf[0] = '\0' ;
result = ip_fgets(buf, sizeof(buf), fp) ;
len = strlen(buf) ;
if (len > 1)
{
switch (buf[0])
{
case '+':
includes = add_filter_info(includes,buf+1) ;
goto include_too ;
case '-':
excludes = add_filter_info(excludes,buf+1) ;
break ;
case CF_EXCLUDE_CHAR:
add_category_filter_info(CF_EXCLUDE, buf+1) ;
break ;
case CF_UNCONDITIONAL_CHAR:
add_category_filter_info(CF_UNCONDITIONAL, buf+1) ;
goto include_too ;
case CF_INCLUDE_CHAR:
add_category_filter_info(CF_INCLUDE, buf+1) ;
goto include_too ;
case CF_OVERRIDE_CHAR:
add_category_filter_info(CF_OVERRIDE, buf+1) ;
break ;
case '#': /* comment lines */
break ;
default:
err_msg[err_char_pos] = buf[0] ;
fatal(err_msg) ;
include_too:
exclude_only = FALSE;
}
}
} while (result != -1) ;
ip_close(fp) ;
do_filter = TRUE ;
}
#undef err_char_pos
}
/***********************************************/
void write_summary_header(fp,title,show_offsets,show_table)
IP_FILE *fp ;
char *title ;
int show_offsets, show_table ;
{
/* set up the printer */
ip_putcstr(&printer->init1,fp) ;
ip_putcstr(&printer->init2,fp) ;
ip_putcstr(&printer->marginc,fp) ;
/* now start writing the actual header */
indent_to(show_offsets?8:0,fp) ;
ip_putlit("\t\t\t\t",fp) ;
ip_puts(title,fp) ;
newline(fp) ;
indent_to(show_offsets?8:0,fp) ;
ip_putlit("\t\t\t\t",fp) ;
(*printer->put_line)(fp,strlen(title)) ;
newline(fp) ;
newline(fp) ;
indent_line(fp) ;
if (show_offsets)
ip_putlit("Offset ", fp) ;
if (show_table)
ip_putlit("Table ",fp) ;
ip_putlit("INT AH AL", fp) ;
if (page_numbers)
ip_putlit(" Page", fp) ;
ip_putlit("\t\t\tDescription", fp) ;
newline(fp) ;
indent_line(fp) ;
(*printer->put_line)(fp,page_width+(show_offsets?8:0)) ;
newline(fp) ;
}
/***********************************************/
static void reset_printer_and_close(fp)
IP_FILE *fp ;
{
ip_putcstr(&printer->term1,fp) ;
ip_putcstr(&printer->term2,fp) ;
ip_close(fp) ;
}
/***********************************************/
int _Cdecl main(argc,argv)
int argc ;
char *argv[] ;
{
int lines_per_page = -1 ;
int total_lines = -1 ;
int use_FF = TRUE ;
int last_line ;
int body_lines ;
char *typeface = NULL ;
char *summary_file = NULL ;
char *table_file = NULL ;
char *formats_file = NULL ;
char *filter_file = NULL ;
char *last_page_num ;
err = ip_fdopen(2,stderr_buf,sizeof(stderr_buf),sizeof(stderr_buf),1) ;
ip_putlit("INTPRINT v", err) ;
ip_putlit(VERSION, err) ;
ip_putlit(" by Ralf Brown and others. Donated to the Public Domain.",err) ;
newline(err) ;
ip_flush(err) ;
if (argc == 1 && isatty(0))
usage() ; /* give help if invoked with no args and keybd input */
while (argc >= 2 && argv[1][0] == '-')
{
switch (argv[1][1])
{
case 'B':
printer_bold = TRUE ;
/* fall through to -b */
case 'b':
boldface = TRUE ;
break ;
case 'd':
duplex = TRUE ;
break ;
case 'e':
indent = 8 ;
page_width = 87 ; /* 96 - indent - 1 right margin */
break ;
case 'f':
formats_file = argv[1]+2 ;
break ;
case 'F':
filter_file = argv[1]+2 ;
break ;
case 'H': /* page headers */
do_headers = TRUE ;
break ;
case 'i':
indent = atoi(argv[1]+2) ;
break ;
case 'I':
IBM_chars = TRUE ;
break ;
case 'k':
keep_divider_lines = TRUE ;
break ;
case 'l':
lines_per_page = atoi(argv[1]+2) ;
break ;
case 'L':
total_lines = atoi(argv[1]+2) ;
break ;
case 'm':
multi_file = TRUE ;
break ;
case 'n':
pages_printed = atoi(argv[1]+2) ;
break ;
case 'P':
if (argv[1][2] == '?')
display_printers() ;
else
select_printer(argv[1]+2) ;
break ;
case 'p':
page_numbers = TRUE ;
break ;
case 'r':
first_page = atoi(argv[1]+2) ;
last_page_num = strchr(argv[1]+2, ':') ;
last_page = last_page_num ? atoi(last_page_num+1) : 0 ;
if (last_page == 0)
last_page = ~0 ;
break ;
case 's':
summary_file = argv[1]+2 ;
break ;
case 't':
typeface = argv[1]+2 ;
break ;
case 'T':
table_file = argv[1]+2 ;
break ;
case 'V':
show_offsets = IBM_chars = TRUE ;
break ;
case 'w':
widow_length = atoi(argv[1]+2) ;
break ;
case 'x':
include_index_lines = TRUE ;
break ;
default:
usage() ;
}
argv++ ;
argc-- ;
}
if (printer == NULL)
select_printer("default") ;
/* apply any necessary overrides to parameters */
if (printer->indent != -1)
indent = printer->indent ;
if (lines_per_page < 0)
lines_per_page = printer->lines_per_page ;
if (total_lines <= 0)
total_lines = printer->page_length ;
if (page_width <= 0)
page_width = printer->page_width ;
if (show_offsets && page_width < 80)
page_width = 80 ;
if (printer->flag)
*(printer->flag) = TRUE ;
if (cstrlen(&printer->bold_on) == 0) /* control sequences for bold? */
printer_bold = FALSE ; /* if not, don't try to use them */
/* build the indent string */
if (indent)
{
char *t ;
int ind = indent ;
indent_len = indent/8 + indent%8 ;
t = indent_string = (char *)malloc(indent_len+1) ;
while (ind >= 8)
{
*t++ = '\t' ;
ind -= 8 ;
}
while (ind > 0)
{
*t++ = ' ' ;
ind-- ;
}
}
/* open the summary file, if any */
if (summary_file && *summary_file)
if ((summary = ip_open_write(summary_file,!pages_printed,summary_buf,
sizeof(summary_buf)))
!= NULL)
do_summary = TRUE ;
else
warning("unable to open summary file") ;
/* open the table index file, if any */
if (table_file && *table_file)
if ((tables = ip_open_write(table_file,!pages_printed,tables_buf,
sizeof(tables_buf)))
!= NULL)
do_tables = TRUE ;
else
warning("unable to open table index file") ;
/* open the data formats file, if any */
if (formats_file && *formats_file)
if ((formats = ip_open_write(formats_file,!pages_printed,formats_buf,
sizeof(formats_buf)))
!= NULL)
do_formats = TRUE ;
else
warning("unable to open formats file") ;
need_summary = (do_summary || do_formats || do_tables) ;
/* initialize filtering data, if specified */
if (filter_file && *filter_file)
build_filter_lists(filter_file) ;
if (total_lines <= lines_per_page)
{
total_lines = lines_per_page ;
use_FF = TRUE ;
}
else
use_FF = FALSE ;
if (argc == 2 || argc == 3)
{
input_file = argv[1] ;
input_file_namelen = strlen(input_file) ;
if ((infile = ip_open_read(input_file,infile_buf,sizeof(infile_buf))) == NULL)
fatal("unable to open input file") ;
if (argc == 3)
{
outfile = ip_open_write(argv[2],!pages_printed,outfile_buf,
sizeof(outfile_buf)) ;
if (outfile == NULL)
fatal("unable to open output file") ;
}
else
outfile = ip_open_write("",0,outfile_buf,sizeof(outfile_buf)) ;
}
else
usage() ;
if (lines_per_page > MAXPAGE)
{
ip_putlit("Surely you jest! I can't handle pages that long.",err) ;
newline(err) ;
newline(err) ;
usage() ;
}
else if (lines_per_page == 0) /* infinite page? */
{
widow_length = 0 ;
if (total_lines <= 0)
total_lines = MAXPAGE ;
lines_per_page = total_lines ;
use_FF = do_headers = page_numbers = FALSE ;
}
else
{
if (lines_per_page < 20)
{
ip_putlit("Surely your printer can handle at least 20 lines per page!",
err) ;
newline(err) ;
ip_putlit("Adjusting page length....",err) ;
newline(err) ;
lines_per_page = 20 ;
}
if (widow_length < 3 || widow_length > lines_per_page / 2)
{
ip_putlit("Widow lines (-w) must be set to at least 3 and at most one-half of the",err) ;
newline(err) ;
ip_putlit("page length. Using default of 8 lines.",err) ;
newline(err) ;
widow_length = 8 ;
}
}
/* set up the printer */
ip_putcstr(&printer->init1,outfile) ;
ip_putcstr(&printer->init2,outfile) ;
if (printer->set_typeface)
(*printer->set_typeface)(outfile,typeface) ;
if (duplex)
{
ip_putcstr(&printer->duplex_on,outfile) ;
if (pages_printed & 1) /* next page odd or even? */
ip_putcstr(&printer->marginl,outfile) ; /* even */
else
ip_putcstr(&printer->marginr,outfile) ; /* odd */
}
else
ip_putcstr(&printer->marginc,outfile) ; /* non-duplex, so center */
/* start the auxiliary files if this is the first part processed */
if (pages_printed == 0)
{
/* start the summary file */
if (do_summary)
write_summary_header(summary,"Interrupt Summary",show_offsets,FALSE) ;
/* start the table index file */
if (do_tables)
write_summary_header(tables,"Table Summary",show_offsets,TRUE) ;
/* start the data formats file */
if (do_formats)
write_summary_header(formats,"Data Structure Formats",FALSE,FALSE) ;
}
if (page_numbers)
body_lines = lines_per_page - 2 ;
else
body_lines = lines_per_page ;
if (do_headers)
body_lines -= 2 ;
last_line = 0 ;
while (!out_of_files)
{
fill_buffer(last_line,body_lines) ;
last_line = find_page_break(body_lines) ;
print_buffer(last_line,body_lines,lines_per_page,total_lines,use_FF) ;
}
if (last_line < body_lines)
{
int i ;
for (i = last_line ; i < body_lines ; i++)
{
strcpy(buffer[i-last_line], buffer[i]) ;
line_offsets[i-last_line] = line_offsets[i] ;
}
print_buffer(body_lines-last_line,body_lines,lines_per_page,total_lines,
use_FF) ;
}
ip_close(infile) ;
/* reset the printer */
reset_printer_and_close(outfile) ;
ip_puts(itoa(pages_printed, num, 10), err) ;
ip_putlit(" pages", err) ;
if (do_summary)
reset_printer_and_close(summary) ;
if (do_tables)
{
ip_putlit(", ", err) ;
ip_puts(itoa(prev_table, num, 10), err) ;
ip_putlit(" tables", err) ;
reset_printer_and_close(tables) ;
}
if (do_formats)
reset_printer_and_close(formats) ;
newline(err) ;
ip_close(err) ;
return 0 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -