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

📄 intprint.c

📁 A Programmer s Reference to BIOS, DOS, and Third-Party Calls
💻 C
📖 第 1 页 / 共 5 页
字号:
char num[8] ;
int need_summary ;
char summary_line[2*MAXLINE] ;
int summary_line_len ;

int pages_printed = 0 ;
int page_width = 0 ;		/* page width in characters, 0 = use prtdef */
int indent = 0 ;	        /* number of columns to indent lines */
char *indent_string = NULL ;	/* what to add at start of line to indent */
int indent_len = 0 ;	        /* length of indent_string */
int widow_length = 8 ;		/* number of lines to scan for good place to break */
int page_numbers = FALSE ;	/* add page numbers to bottom of page? */
int multi_file = FALSE ;	/* printing multipart interrupt list? */
int out_of_files = FALSE ;	/* hit end of last file for multipart printing? */
int do_summary = FALSE ;	/* create a one-line-per-call summary? */
int do_tables = FALSE ;		/* create a one-line-per-table index? */
int do_formats = FALSE ;	/* create a separate file with data structures? */
int do_filter = FALSE ;		/* using a filtering file? */
int do_headers = FALSE ;	/* add page headings? */
int include_index_lines = FALSE ;
int IBM_chars = FALSE ;		/* printer can handle IBM graphics characters */
int boldface = FALSE ;		/* boldface titles and Return:/Notes: ? */
int printer_bold = FALSE ;	/* boldface using printer control sequences? */
int echo_format = FALSE ;
int duplex = FALSE ;
int HPPCL_mode = FALSE ;
int show_offsets = FALSE ;
int keep_divider_lines = FALSE ;
int exclude_only = TRUE ;
IP_FILE *summary ;
IP_FILE *tables ;
IP_FILE *formats ;
PRINTER_DEF *printer = NULL ;

unsigned long current_line_offset = 0 ;
unsigned long offset_adjust = 0 ;

unsigned int first_page = 0 ;
unsigned int last_page = ~0 ;

int prev_table = 0 ;

FILT_LIST *includes = NULL ;
FILT_LIST *excludes = NULL ;

HEADER header_first = { 0, FALSE, "" } ;
HEADER header_last = { 0, FALSE, "" } ;

/***********************************************/

PRINTER_DEF printers[] =
   {
     { "default",
       CSTR(""), CSTR(""),
       CSTR(""), CSTR(""), CSTR(""),
       CSTR(""),
       CSTR(""), CSTR(""),
       CSTR(""), CSTR(""),
       -1,
       60,
       0,
       79,
       put_line,
       NULL,
       NULL,
     },
     { "Epson FX80, 12 cpi",
       CSTR("\033M"), CSTR(""),
       CSTR("\033l\004"), CSTR("\033l\007"), CSTR("\033l\014"),
       CSTR(""),
       CSTR("\033P"), CSTR("\033l\000"),
       CSTR("\033E"), CSTR("\033F"),
       0,
       60,
       0,
       87,	/* 96 - left margin - 1 right margin */
       put_line,
       NULL,
       NULL,
     },
     { "Panasonic KX-P1124i / 10 cpi Epson",
       CSTR(""), CSTR(""),
       CSTR(""), CSTR(""), CSTR(""),
       CSTR(""),
       CSTR(""), CSTR(""),
       CSTR("\033E"), CSTR("\033F"),
       -1,
       60,
       0,
       79,
       put_line,
       NULL,
       NULL,
     },
     { "HP PCL",
       CSTR("\033(8U"), CSTR(""),
       CSTR("\033&a4c4L"), CSTR("\033&a8c8L"), CSTR("\033&a12c12L"),
       CSTR("\033&l1S"),
       CSTR("\033E"), CSTR(""),
       CSTR("\033(s3B"), CSTR("\033(s0B"),
       0,
       69,
       0,
       87,	/* 96 - left margin - 1 right margin */
       HPPCL_put_line,
       HPPCL_set_typeface,
       &HPPCL_mode,
     },
#define HPPCL_FONT_ON_A "\033(s0p12h10v0s0b"
/* HP PCL4/5 Font select: Roman-8;Upright12Pitch10PointMediumWeight */
#define HPPCL_FONT_ON_B "T\033&l6.8571C"
/* HP PCL4/5 Font select: End typeface select;VMI=7LPI: (48/7)-48th's inches*/
#define HPPCL_IBM_LN_A	"\033&f0S\033*p-15Y\033*c"
/* HP PCL4/5 IBM Line:	Push Pos;Up 15/720";Hor.Rule ???/300ths" long */
#define HPPCL_IBM_LN_B	"a3b0P\033&f1S"
/* HP PCL4/5 IBM Line:	 3/300ths" high,Print rule;Pop Position */
     { "LaserJet II",
       CSTR("\033(10U"),CSTR(""),
       CSTR("\033&a4c4L"), CSTR("\033&a8c8L"), CSTR("\033&a12c12L"),
       CSTR(""),
       CSTR("\033E"),CSTR(""),
       CSTR("\033(s3B"),CSTR("\033(s0B"),
       0,
       54,
       60,
       79,
       put_line,
       NULL,
       &IBM_chars,
     },
   } ;
#define NUM_PRINTERS lengthof(printers)

/***********************************************/

#define KEYWORD_ENTRY(s) { s, sizeof(s)-1 }

KEYWORDS section_start_keys[] =
   {
    KEYWORD_ENTRY("BUG:"),
    KEYWORD_ENTRY("BUGS:"),
    KEYWORD_ENTRY("Desc:"),
    KEYWORD_ENTRY("Index:"),
    KEYWORD_ENTRY("Note:"),
    KEYWORD_ENTRY("Notes:"),
    KEYWORD_ENTRY("Program:"),
    KEYWORD_ENTRY("Range:"),
    KEYWORD_ENTRY("Return:"),
    KEYWORD_ENTRY("SeeAlso:"),
   } ;

KEYWORDS table_start_keys[] =
   {
    KEYWORD_ENTRY("Bitfields "),
    KEYWORD_ENTRY("Call "),
    KEYWORD_ENTRY("Format "),
    KEYWORD_ENTRY("Values "),
   } ;

/***********************************************/

#ifdef isxdigit
#undef NEED_ISXDIGIT
#endif

#ifdef NEED_STRNICMP
#ifdef PROTOTYPES
int strnicmp(char *s1,char *s2,unsigned int len) ;
#endif
int strnicmp(s1,s2,len)
char *s1,*s2 ;
unsigned int len ;
{
   char c1, c2 ;

   while (*s1 && *s2 && len > 0)
      {
      len-- ;
      c1 = (islower(*s1) ? toupper(*s1) : *s1) ;
      c2 = (islower(*s2) ? toupper(*s2) : *s2) ;
      if (c1 != c2 || len == 0)	 /* mismatch or substrings exhausted? */
	 return (c1 - c2) ;
      s1++ ;
      s2++ ;
      }
   return 0 ;  /* strings match exactly on first 'len' characters */
}
#endif /* NEED_STRNICMP */

#ifdef NEED_STRUPR
#ifdef PROTOTYPES
char *strupr(char *s) ;
#endif
char *strupr(s)
char *s ;
{
   char *orig_s = s ;
   char c ;
   
   if (s)
      while (*s)
	 {
	 c = *s ;      
	 *s++ = (islower(c) ? toupper(c) : c) ;
	 }
   return orig_s ;
}
#endif /* NEED_STRUPR */

#ifdef NEED_ISXDIGIT
#ifdef PROTOTYPES
int isxdigit(int c) ;
#endif
int isxdigit(c)
int c ;
{
   return isdigit(c) || (memchr("ABCDEFabcdef",c,12) != NULL) ;
}
#endif /* NEED_ISXDIGIT */

#ifdef NEED_ITOA
#ifdef PROTOTYPES
char *itoa(int num,char *buf,int radix) ;
#endif
char *itoa(num,buf,radix)   /* not everybody has the same itoa() as TurboC */
int num ;		    /* minimal implementation */
char *buf ;
int radix ;
{
   int count = 0 ;
   int i ;
   char tmp ;

   do {
      buf[count++] = "0123456789ABCDEF"[num % radix] ;
      num /= radix ;
   } while (num) ;
   buf[count] = '\0' ;
   if (count > 1)
      for (i = 0 ; i < count / 2 ; i++)
	 {
	 tmp = buf[i] ;
	 buf[i] = buf[count-i-1] ;
	 buf[count-i-1] = tmp ;
	 }
   return buf ;
}
#endif /* NEED_ITOA */

#ifdef NEED_ULTOA
#ifdef PROTOTYPES
char *ultoa(unsigned long num,char *buf,int radix) ;
#endif
char *ultoa(num,buf,radix)   /* not everybody has the same ultoa() as TurboC */
unsigned long num ;	     /* minimal implementation */
char *buf ;
int radix ;
{
   int count = 0 ;
   int i ; 
   char tmp ;

   do {
      buf[count++] = "0123456789ABCDEF"[num % radix] ;
      num /= radix ;
   } while (num) ;
   buf[count] = '\0' ;
   if (count > 1)
      for (i = 0 ; i < count / 2 ; i++)
	 {
	 tmp = buf[i] ;
	 buf[i] = buf[count-i-1] ;
	 buf[count-i-1] = tmp ;
	 }
   return buf ;
}
#endif /* NEED_ULTOA */

/***********************************************/

void usage()
{
   ip_putlit("\
Usage: intprint [options] intlist [>|>>]output\r\n\
Options:\r\n\
Filtering:\t-Ffile\tprint only entries matching filtering info in 'file'\r\n\
\t\t-k\tkeep original divider lines\r\n\
\t\t-rN:M\tprint only pages N through M\r\n\
\t\t-x\tinclude Index: lines in formatted output\r\n\
Formatting:\t-b\tboldface headings\t-B\tbold with control codes\r\n\
\t\t-d\t(duplex) print even/odd pages with different indents\r\n\
\t\t-e\t(elite) 96 chars/line\t-tN\tselect typeface N\r\n\
Pagination:\t-H\tadd page headers\t-iN\tindent N spaces\r\n\
\t\t-p\tnumber pages\t\t-nN\tN pages already printed\r\n\
\t\t-wN\twidow lines control\r\n\
\t\t-lN\tprint length\t\t-LN\ttotal page length\r\n\
\t\t\t(0 = infinite)\t(use linefeeds if > #lines printed)\r\n\
Printer:\t-I\tIBM graphics characters\r\n\
\t\t-Pname\tassume printer 'name'\t-P?\tlist printers\r\n\
Summaries:\t-ffile\tdata structure formats\t-sfile\tINT calls\r\n\
\t\t-Tfile\tlist tables\r\n\
Misc:\t\t-m\tprocess multiple parts\t-V\tmake INTERVUE summary\r\n\
"
	,err) ;
   ip_flush(err) ;
   exit(1) ;
}

/***********************************************/

void fatal(msg)
char *msg ;
{
   ip_putlit("UNRECOVERABLE ERROR:",err) ;
   newline(err) ;
   ip_puts(msg,err) ;
   newline(err) ;
   ip_flush(err) ;
   exit(1) ;
}

/***********************************************/

void warning(msg)
char *msg ;
{
   ip_putlit("Warning: ",err) ;
   ip_puts(msg,err) ;
   newline(err) ;
}

/***********************************************/

IP_FILE *ip_fdopen(fd,buf,bufsiz,maxsiz,write)
int fd ;
char *buf ;
int bufsiz, maxsiz, write ;
{
   IP_FILE *fp = (IP_FILE *)malloc(sizeof(IP_FILE)) ;
   
   if (fp)
      {
      fp->fd = fd ;
      fp->buf = buf ;
      fp->bufsize = bufsiz ;
      fp->buf_maxsize = maxsiz ;
      fp->bufpos = 0 ;
      fp->bufoffset = 0 ;
      fp->write = write ;
      }
   return fp ;
}

/***********************************************/

IP_FILE *ip_open_write(name,trunc,buf,bufsiz)
char *name ;
char *buf ;
int trunc ;
int bufsiz ;
{
   int fd ;
   
   if (name && *name == '\0')
      fd = 1 ;	/* open stdout */
   else
      {
#ifdef __TURBOC__
      if (trunc)
	 fd = _creat(name,0) ;	 /* create with no attribute bits sets */
      else
	 fd = _open(name,O_WRONLY) ;
#else
      if (trunc) trunc = O_TRUNC ;
      fd = open(name,O_WRONLY|O_BINARY|O_CREAT|trunc,S_IREAD|S_IWRITE) ;
#endif
      if (fd == -1)
	 return 0 ;
      if (!trunc)
	 lseek(fd,0L,SEEK_END) ;
      }
   return ip_fdopen(fd,buf,bufsiz,bufsiz,1) ;
}

/***********************************************/

IP_FILE *ip_open_read(name,buf,bufsiz)
char *name ;
char *buf ;
int bufsiz ;
{
   int fd, siz ;

#ifdef __TURBOC__
   if ((fd = _open(name,O_RDONLY)) != -1)
#else
   if ((fd = open(name,O_RDONLY | O_BINARY,0)) != -1)
#endif
      {
      siz = read(fd,buf,bufsiz) ;
      if (siz == -1)
	 return 0 ;
      return ip_fdopen(fd,buf,siz,bufsiz,0) ;
      }
   else
      return 0 ;
}

/***********************************************/

int ip_flush(fp)
IP_FILE *fp ;
{
   if (fp->write && fp->bufpos)
      {
      if (fp->bufpos > fp->buf_maxsize)
	 fp->bufpos = fp->buf_maxsize ;
      if (write(fp->fd,fp->buf,fp->bufpos) == -1)
	 return -1 ;
      fp->bufpos = 0 ;
      }
   return 0 ;
}

/***********************************************/

int ip_close(fp)
IP_FILE *fp ;
{
   if (ip_flush(fp) == -1 || close(fp->fd) == -1)
      return -1 ;
   free(fp) ;
   return 0 ;
}

/***********************************************/

unsigned long ip_fgets(buf, max, fp)
char *buf ;
int max ;
IP_FILE *fp ;
{
   unsigned long line_offset = fp->bufoffset + fp->bufpos ;
   char *end ;
   int len ;
   int new_bufpos ;
   char *fpbuf = fp->buf ;
   int bufpos = fp->bufpos ;
   
   --max ;
   if (bufpos + max < fp->bufsize)
      {
      end = (char *)memchr(fpbuf+bufpos,LINE_TERMINATOR,max) ;
      if (end)
	 {
	 new_bufpos = (end-fpbuf) ;
	 len = new_bufpos++ - bufpos ;
	 /* eradicate rest of multi-character line terminator */
	 while (len > 0 && fpbuf[bufpos+len-1] <= ' ')
	    len-- ;
	 }
      else
	 {
	 len = max ;
	 new_bufpos = bufpos + len ;
	 }
      if (len)
	 memcpy(buf,fpbuf+bufpos,len) ;
      buf[len] = '\0' ;
      bufpos = new_bufpos ;
      }
   else
      {
      for (len = 1 ; len <= max ; len++)
	 {
	 *buf = fpbuf[bufpos++] ;

⌨️ 快捷键说明

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