📄 intprint.c
字号:
/************************************************************************/
/* INTPRINT.C by Ralf Brown. Donated to the Public Domain. */
/* Please do not remove my name from any copies or derivatives. */
/************************************************************************/
/* Program History: */
/* v1.00 4/23/89 initial public release */
/* with 4/30/89 list */
/* v1.10 5/21/89 added -I and -f */
/* v1.11 1/6/90 fixed #endif's for compilers which don't handle */
/* labels */
/* v1.20 6/8/90 added -r */
/* v1.30 7/14/90 added -b, tables now stay aligned on odd indents */
/* v1.40 10/6/90 added -B based on changes by Naoto Kimura, -w */
/* v1.40a 5/6/91 HP LaserJet II support by Russ Herman */
/* v1.41 7/9/91 HP PCL support by P.J.Farley III */
/* v2.00 9/1/91 modular printer definitions */
/* printing multipart interrupt list */
/* v2.01 2/9/92 fixed summary entry for non-numeric AX= and AH= */
/* smarter page breaks */
/* v2.02 2/18/92 bugfix & isxdigit suggested by Aaron West */
/* v2.10 3/14/92 updated to handle extra flags in headings */
/* v2.11 5/23/92 bugfix pointed out by Joe White */
/* v2.20 6/12/92 added -F based on code by Richard Brittain */
/* added -H and Panasonic printer def by Lewis Paper */
/* v2.21 10/14/92 fixed error in -H/-r interaction */
/* updated for new 'Bitmask of' section */
/* v2.22 2/15/93 exclude Index: by default, -x to force inclusion */
/* changed 'Bitmask of' to 'Bitfields for' */
/* v2.23 5/24/93 fix to allow INT/AL= to appear correctly in summary*/
/* v2.24 7/15/93 -k and infinite-length pages by Bent Lynggaard */
/* v3.00 04jun94 -T, -V, and multi-file break section skipping */
/* major speedups; checked for BC++3.1 compatibility */
/* v3.01 11jun94 bugfix: crashed with -l0 -L1 on lines >=80 chars */
/* v3.02 07jan95 bugfix by Mark Shapiro: garbage with -B -PHP_PCL */
/* v3.03 14jan95 changes for Borland C++ 4.x size minimization */
/* v3.04 25mar95 malloc/sbrk and other bugfixes */
/* v3.10 11feb96 category filters by Bent Lynggard */
/* v3.11 21dec97 support formatting/summarizing other intlist files */
/* v3.12 25jul98 support for five-char table numbers */
/************************************************************************/
/* Recompiling: */
/* Turbo C / Borland C++ */
/* tcc -mt -lt -O -a -Z -p -k- intprint */
/* bcc -mt -lt -a -d -O1agim -p intprint.c */
/* Borland C++ 4.x (as .EXE, from John <tenthumbs@bix.com>) */
/* bcc -ms -a -d -O1agim -p intprint.c noehs.lib */
/************************************************************************/
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h> /* S_IREAD, S_IWRITE */
#define VERSION "3.12"
/***********************************************/
/* portability definitions */
#define _other_ /* assume no system-specific match */
/*--------------------------------------------------*/
/* first system: MS-DOS with Turbo/Borland C */
#ifdef __TURBOC__
# define PROTOTYPES
# include <alloc.h>
# include <io.h> /* open, close, read, lseek, etc. */
int _Cdecl isatty(int handle) ;
/* definitions to reduce size of executable */
unsigned int _Cdecl _stklen = 1024 ;
#define close _close
#define read _read
#define write _write
void _Cdecl _setenvp(void) {} /* don't need environment--don't include it */
void *_Cdecl malloc(size_t size)
{ void *x = sbrk(size) ; return (x==(char*)-1) ? 0 : x ; }
void _Cdecl free(void *var) { (void)var ; }
/* since our free() doesn't do anything, macro it out of existence */
#define free(p)
#ifdef __BORLANDC__
void _Cdecl _setupio(void) {}
#pragma warn -eff
/* BC++ v3.1 sets __BORLANDC__ to 0x0410!! */
#if __BORLANDC__ >= 0x0400 && __BORLANDC__ != 0x0410
/* Changes by John Sasse to minimize executable size */
#if 1
/* the preferred way */
/* Borland claims they "might" stop supporting these functions. Right */
#define _close(a) _rtl_close(a)
#define _creat(a,b) _rtl_creat(a,b)
#define _open(a,b) _rtl_open(a,b)
#define _read(a,b,c) _rtl_read(a,b,c)
#define _write(a,b,c) _rtl_write(a,b,c)
#if __BORLANDC__ == 0x400
/* They forgot to change this in 4.00 only */
#undef _read
#endif
#else
#pragma warn -obs /* the easy way */
#endif /* 1 */
#endif /* __BORLANDC__ >= 0x400 */
#endif /* __BORLANDC__ */
#undef _other_
#endif /* __TURBOC__ */
#ifdef __MSDOS__
# define LINE_TERMINATOR '\n'
#endif
/*--------------------------------------------------*/
/* Gnu C compiler */
#ifdef __GNUC__
#define PROTOTYPES
#define NEED_ITOA
#define NEED_ULTOA
#define NEED_STRUPR
#define NEED_STRNICMP
#undef _other_
#endif /* __GNUC__ */
/*--------------------------------------------------*/
/* generic Unix definitions */
#ifdef unix
# include <sys/unistd.h> /* open, close, read, lseek, etc. */
# include <sysent.h> /* open, close, read, lseek, etc. */
extern int isatty(int) ;
# define LINE_TERMINATOR '\n'
#endif
/*--------------------------------------------------*/
/* any other system */
#ifdef _other_
/* unknown compiler/system, so set configuration #defines */
#if 0 /* set to 1 if compiler supports ANSI-style prototypes, 0 otherwise */
#define PROTOTYPES
#endif
#if 1 /* set to 0 if library contains strnicmp(), 1 otherwise */
#define NEED_STRNICMP
#endif
#if 1 /* set to 0 if library contains isxdigit(), 1 otherwise */
#define NEED_ISXDIGIT
#endif
#if 1 /* set to 0 if library contains strupr(), 1 otherwise */
#define NEED_STRUPR
#endif
#if 1 /* set to 0 if library contains three-arg itoa(), 1 otherwise */
#define NEED_ITOA
#endif
#if 1 /* set to 0 if library contains three-arg ultoa(), 1 otherwise */
#define NEED_ULTOA
#endif
#endif /* _other_ */
/*--------------------------------------------------*/
/* the last character of the line termination sequence, i.e. '\n' for CRLF */
/* and LF, '\r' if your system uses CR or LFCR */
#ifndef LINE_TERMINATOR
#define LINE_TERMINATOR '\n'
#endif /* LINE_TERMINATOR */
/*--------------------------------------------------*/
/* catchall for macros which might not be defined */
#ifndef O_BINARY
# define O_BINARY 0
#endif
#ifndef _Cdecl
# define _Cdecl
#endif
/***********************************************/
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE !FALSE
#endif
/***********************************************/
#define MAXLINE 82 /* at most 80 chars per line (plus CR and newline) */
#define MAXPAGE 200 /* at most 200 lines per page */
#define lengthof(x) (sizeof(x)/sizeof(x[0]))
#ifdef __MSDOS__
#define chars_to_long(a, b, c, d) \
(a | (((long)b)<<8) | (((long)c)<<16) | (((long)d)<<24))
#define long_div_line chars_to_long('-','-','-','-')
#define divider_line(line) (((long*)line)[0] == long_div_line && \
((long*)line)[1] == long_div_line)
#define index_line(l) \
(((long*)l)[0]==chars_to_long('I','n','d','e')&& \
((short*)l)[2]==('x'+':'*0x100))
#else
static char long_chars[] = "----INT Index:" ;
#define divider_line(line) (((long*)line)[0] == ((long*)long_chars)[0]\
&& ((long*)line)[1] == ((long*)long_chars)[0])
#define index_line(line) (((long*)line)[0] == ((long*)long_chars)[2] && \
((short*)line)[2] == (short*)long_chars)[6])
#endif
#define section_start(line) is_keyword(line,section_start_keys,lengthof(section_start_keys))
#define start_of_table(line) (is_keyword(line,table_start_keys,lengthof(table_start_keys)))
#define section_file_start(s) (s[0] == '-' && memcmp(s+1,"-------!---Section",18) == 0)
/* category filters definitions and variables */
#define CF_BUFFER_SIZE 26+26+9
typedef enum {CF_EXCLUDE, CF_UNCONDITIONAL, CF_INCLUDE, CF_OVERRIDE,
CF_ENUM_SIZE} CF_ENUM; /* leave CF_ENUM_SIZE as the last enumetator */
char cf_buffers[CF_ENUM_SIZE][CF_BUFFER_SIZE+1];
char cf_current_category;
#define CF_EXCLUDE_CHAR '<'
#define CF_UNCONDITIONAL_CHAR '>'
#define CF_INCLUDE_CHAR 'i'
#define CF_OVERRIDE_CHAR 'o'
/***********************************************/
/* stub functions to reduce executable size */
/***********************************************/
#ifdef __BORLANDC__
/* Changes by John Sasse */
/* BC++ v3.1 sets __BORLANDC__ to 0x0410!! */
#if __BORLANDC__ >= 0x0400 && __BORLANDC__ != 0x0410
/* Everything within this conditional may be placed in
* a separate source file if desired.
*/
/* stack overflow checking can never be allowed inside
the run-time library */
#pragma option -N-
#include <errno.h>
/* the next 3 include files are necessary only if this
is compiled as a separate file */
#if 0
#include <io.h>
#include <stdlib.h>
#include <string.h>
#endif
/* declarations */
void _Cdecl __ErrorMessage (const char *__message);
int pascal near __IOerror (int _doserror_);
int pascal near __DOSerror (int _doserror_);
void _Cdecl _abort (void);
/* may be referenced by a lot of things */
int _Cdecl _doserrno = 0;
/*
The _rtl_* functions all call __IOError which originally
referenced sys_nerr and sys_errlist. Unfortunately, the
source file for these also contains perror which calls
fputs. Hence you get lots of extra code.
This is a very minimal replacement.
*/
int pascal near __IOerror(int _doserror_)
{
/* if _doserror_ is < 0, it might be a System V error.
we don't care */
_doserrno = (_doserror_ < 0) ? (-1) : _doserror_;
errno = EIO; /* a default value */
return (-1);
}
/* __DOSerror and __IOerror are in the same source file.
This may not actually be called. Better safe ...
*/
#if 1
int pascal near __DOSerror(int _doserror_)
{
__IOerror(_doserror_);
return (_doserror_);
}
#endif
/*
The startup code, among others, references _setargv which
references abort. The run-time library version says "raise
(SIGABRT)", bringing in a lot of unnecessary code.
*/
void _Cdecl abort (void)
{
_abort ();
}
/* necessary to avoid referencing _streams */
#if 1
#define STDERR 2
void _Cdecl __ErrorMessage(const char *msg)
{
_rtl_write(STDERR, msg, strlen(msg));
}
#endif
/* restore command line state; note the "." */
#pragma option -N.
#endif /* __BORLANDC__ >= 0x400 */
#endif /* __BORLANDC__ */
/***********************************************/
/* replacement file I/O function macros */
/***********************************************/
typedef struct
{
int fd ;
int buf_maxsize ;
char *buf ;
unsigned long bufoffset ;
int bufsize ;
int bufpos ;
int write ; /* file is output file if nonzero */
} IP_FILE ;
#define ip_putc(c,fp) \
((fp)->buf[fp->bufpos++]=(c),\
((fp)->bufpos>=(fp)->buf_maxsize&&ip_flush(fp)==-1)?-1:0)
/* output the indicated counted string to the given file */
#define ip_putcstr(s,fp) ip_write((s)->str,(s)->len,fp)
/* output the given string literal to the indicated file */
#define ip_putlit(s,fp) ip_write((s),sizeof(s)-1,fp)
/* output the given string variable to the indicated file */
#define ip_puts(s, fp) ip_write(s,strlen(s),fp)
#ifdef __MSDOS__
#define newline(fp) ip_write("\r\n",2,fp)
#else
#define newline(fp) ip_putc('\n',fp)
#endif
/***********************************************/
typedef struct /* a counted string */
{
int len ; /* the string's length */
char *str ; /* the actual contents of the string */
} cstr ;
#define CSTR(s) { sizeof(s)-1, (s) } /* for defining a counted string literal */
#define cstrlen(s) ((s)->len) /* how long is the counted string? */
typedef struct
{
char *name ; /* for selecting the appropriate printer */
cstr init1, init2 ; /* initialization strings */
cstr marginl, marginc, marginr ; /* margins: duplex even, non-duplex, duplex odd */
cstr duplex_on ; /* turn on duplex mode */
cstr term1, term2 ; /* cleanup strings */
cstr bold_on, bold_off ; /* boldface on/off */
int indent ; /* how many extra spaces to indent */
int lines_per_page ; /* how many lines to print on each page */
int page_length ; /* how many lines on each page */
int page_width ; /* how many printable columns per line? */
#ifdef PROTOTYPES
void (*put_line)(IP_FILE *,int) ;/* function to call to print out divider line */
void (*set_typeface)(IP_FILE *,char *) ;
#else
void (*put_line)() ; /* function to call to print out divider line */
void (*set_typeface)() ;
#endif /* PROTOTYPES */
int *flag ; /* flag to set when using this printer definition */
} PRINTER_DEF ;
typedef struct filter_list
{
struct filter_list *next ;
char str[1] ; /* will allocate enough for actual string */
} FILT_LIST ;
typedef struct
{
int part ;
int first_on_page ; /* TRUE if a new entry starts at the top of the page */
char desc[32] ;
int len ;
} HEADER ;
typedef struct
{
/* char *name ;*/
char name[14] ;
int length ;
} KEYWORDS ;
/***********************************************/
#ifdef PROTOTYPES
void usage(void) ;
void fatal(char *msg) ;
void warning(char *msg) ;
int unwanted_section(char *buf) ;
IP_FILE *ip_fdopen(int fd,char *buf,int bufsiz, int maxsiz, int write) ;
IP_FILE *ip_open_write(char *name, int trunc, char *buf, int bufsiz) ;
IP_FILE *ip_open_read(char *name, char *buf, int bufsiz) ;
int ip_close(IP_FILE *fp) ;
unsigned long ip_fgets(char *buf, int max, IP_FILE *fp) ;
int ip_write(char *buf, int count, IP_FILE *fp) ;
int ip_flush(IP_FILE *fp) ;
void get_raw_line(char *buf) ;
void get_line(char *buf) ;
void indent_to(int where,IP_FILE *fp) ;
void put_line(IP_FILE *fp, int len) ;
void HPPCL_put_line(IP_FILE *fp, int len) ;
void HPPCL_set_typeface(IP_FILE *fp,char *typeface) ;
int start_of_entry(char *s) ;
int is_keyword(char *s, KEYWORDS *keys, unsigned int numkeys) ;
void output_line(char *line,IP_FILE *fp) ;
void fill_buffer(int lines, int lines_per_page) ;
int find_page_break(int lines) ;
int summarize(int line, int pages_printed) ;
void start_format(char *line) ;
void write_summary_header(IP_FILE *fp, char *title, int offsets, int tables) ;
void show_offset(int line,IP_FILE *fp) ;
void add_table(int i) ;
void add_category_filter_info(CF_ENUM filter, char *str) ;
FILT_LIST *add_filter_info(FILT_LIST *list,char *str) ;
void build_filter_lists(char *file) ;
int make_description(char *desc,char *type,int line) ;
char *determine_heading(int last) ;
void print_buffer(int last,int body_lines,int lines_per_page,int total_lines,
int use_FF) ;
void select_printer(char *name) ;
void display_printers(void) ;
static void reset_printer_and_close(IP_FILE *fp) ;
int _Cdecl main(int argc, char **argv) ;
#else
void put_line() ;
void HPPCL_put_line() ;
void HPPCL_set_typeface() ;
void show_offset() ;
#endif /* PROTOTYPES */
/***********************************************/
/* I/O buffers */
/***********************************************/
char stderr_buf[1] ;
char filter_buf[256] ;
char infile_buf[8192] ;
char outfile_buf[8192] ;
char summary_buf[4096] ;
char formats_buf[3072] ;
char tables_buf[3072] ;
/***********************************************/
IP_FILE *err ;
IP_FILE *infile ;
IP_FILE *outfile ;
char *input_file ;
int input_file_namelen ;
char buffer[MAXPAGE][MAXLINE] ;
unsigned long line_offsets[MAXPAGE] ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -