📄 intprint.c
字号:
if (bufpos >= fp->bufsize)
{
if (fp->bufsize < fp->buf_maxsize)
{
fp->bufsize = bufpos = 0 ;
fpbuf[0] = '\0' ; /* dummy value to ensure empty string */
}
else
{
fp->bufoffset += fp->buf_maxsize ;
fp->bufsize = read(fp->fd,fpbuf,fp->buf_maxsize) ;
bufpos = 0 ;
}
if (fp->bufsize <= 0)
{
line_offset = (unsigned long)-1 ; /* signal end of file */
if (*buf != LINE_TERMINATOR)
*buf++ = LINE_TERMINATOR;
break ;
}
}
if (*buf == LINE_TERMINATOR)
break ;
else
buf++ ;
}
if (len > max) /* did we overflow before hitting EOL? */
*buf = '\0' ; /* if yes, plug in the terminator */
else
/* eradicate rest of multi-character line terminator */
while (len-- > 0 && *buf <= ' ')
*buf-- = '\0' ;
}
fp->bufpos = bufpos ;
return line_offset ;
}
/***********************************************/
int ip_write(buf, count, fp)
char *buf ;
int count ;
IP_FILE *fp ;
{
if (fp->bufpos + count < fp->buf_maxsize)
{
memcpy(fp->buf+fp->bufpos,buf,count) ;
fp->bufpos += count ;
}
else
while (count > 0)
{
int partial = fp->buf_maxsize - fp->bufpos ;
if (count < partial)
partial = count ;
memcpy(fp->buf+fp->bufpos,buf,partial) ;
buf += partial ;
fp->bufpos += partial ;
count -= partial ;
if (fp->bufpos >= fp->buf_maxsize && ip_flush(fp) == -1)
return -1 ;
}
return 0 ;
}
/***********************************************/
#define indent_line(fp) if(indent_string)ip_write(indent_string,indent_len,fp)
/***********************************************/
void indent_to(where,fp)
int where ;
IP_FILE *fp ;
{
where += indent ;
while (where >= 8)
{
ip_putc('\t',fp) ;
where -= 8 ;
}
if (where)
ip_write(" ",where,fp) ;
}
/***********************************************/
void put_line(fp,len)
IP_FILE *fp ;
int len ;
{
static char line[8] = { 196, 196, 196, 196, 196, 196, 196, 196 } ;
if (IBM_chars)
{
while (len >= 8)
{
ip_write(line,8,fp) ;
len -= 8 ;
}
if (len)
ip_write(line,len,fp) ;
}
else
{
while (len >= 8)
{
ip_write("--------",8,fp) ;
len -= 8 ;
}
if (len)
ip_write("--------",len,fp) ;
}
}
/***********************************************/
void HPPCL_put_line(fp,len)
IP_FILE *fp ;
int len ;
{
ip_putlit(HPPCL_IBM_LN_A,fp) ;
ip_puts(itoa((len * 25), num, 10),fp) ;
ip_putlit(HPPCL_IBM_LN_B,fp) ;
}
/***********************************************/
void HPPCL_set_typeface(fp,typeface)
IP_FILE *fp ;
char *typeface ;
{
ip_putlit(HPPCL_FONT_ON_A,fp) ;
if (typeface)
ip_puts(typeface,fp) ;
else
ip_putlit("8",fp) ;
ip_putlit(HPPCL_FONT_ON_B,fp) ;
}
/***********************************************/
int start_of_entry(s)
char *s ;
{
if (!*s || !isupper(*s))
return 0 ;
return memcmp(s,"INT ",4) == 0 ||
memcmp(s,"PORT ",5) == 0 ||
memcmp(s,"CMOS ",5) == 0 ||
memcmp(s,"MEM ",4) == 0 ||
memcmp(s,"I2C ",4) == 0 ||
memcmp(s,"CALL ",5) == 0 ||
memcmp(s,"OPCODE ",7) == 0 ||
memcmp(s,"MSR ",4) == 0 ;
}
/***********************************************/
int is_keyword(s,keys,numkeys)
char *s ;
KEYWORDS *keys ;
unsigned int numkeys ;
{
register int cmp ;
register unsigned int i ;
KEYWORDS *currkey ;
int firstchar = *s ;
do {
i = numkeys / 2 ;
currkey = &keys[i] ;
cmp = (firstchar - currkey->name[0]) ;
if (cmp == 0)
cmp = memcmp(s,currkey->name,currkey->length) ;
if (cmp < 0)
numkeys = i ;
else if (cmp > 0)
{
keys = currkey+1 ;
numkeys -= i+1 ;
}
else
return TRUE ;
} while (numkeys) ;
return FALSE ;
}
/***********************************************/
void output_line(line,fp)
char *line ;
IP_FILE *fp ;
{
if (*line)
{
int pos = 0 ;
int len = strlen(line) ;
indent_line(fp) ;
if (boldface)
{
if (start_of_entry(line) || start_of_table(line))
{
if (printer_bold)
{
ip_putcstr(&printer->bold_on,fp) ;
ip_write(line,len,fp) ;
ip_putcstr(&printer->bold_off,fp) ;
newline(fp) ;
return ;
}
else
{
ip_write(line,len,fp) ;
ip_putc('\r',fp) ;
indent_line(fp) ;
}
}
else if (section_start(line))
{
pos = (char *)memchr(line,':',len) - line ;
if (printer_bold)
{
ip_putcstr(&printer->bold_on,fp) ;
ip_write(line,pos,fp) ;
ip_putcstr(&printer->bold_off,fp) ;
line += pos ; /* adjust because no longer at left edge */
len -= pos ;
}
else
{
ip_write(line,pos,fp) ;
ip_putc('\r',fp) ;
indent_line(fp) ;
}
}
} /* boldface */
if (indent & 7) /* indenting by other than a multiple of 8 ? */
{
while (*line)
{
if (*line == '\t')
{
ip_write(" ",8-(pos&7),fp) ;
pos = 0 ; /* absolute column doesn't matter, only mod 8 */
}
else
{
ip_putc(*line,fp) ;
pos++ ;
}
line++ ;
}
}
else
ip_write(line,len,fp) ;
}
newline(fp) ;
}
/***********************************************/
void get_raw_line(buf)
char *buf ;
{
static char progress_indicator[] = "ii\r";
IP_FILE *in ;
buf[0] = '\0' ;
if (out_of_files)
return ;
current_line_offset = ip_fgets(buf,MAXLINE,infile) ;
if (current_line_offset == (unsigned long)-1)
if (multi_file)
{
offset_adjust += lseek(infile->fd,0L,SEEK_END) ;
input_file[input_file_namelen-1]++ ;
ip_close(infile) ;
if ((in = ip_open_read(input_file,infile_buf,sizeof(infile_buf)))
!= NULL)
{
infile = in ;
current_line_offset = ip_fgets(buf,MAXLINE,infile) ;
}
else
{
out_of_files = TRUE ;
return ;
}
}
else
out_of_files = TRUE ;
if (start_of_entry(buf) && ((short*)buf)[2] != ((short*)progress_indicator)[0])
{
((short*)progress_indicator)[0] = ((short*)buf)[2] ;
ip_putlit(progress_indicator, err) ;
}
}
/***********************************************/
int unwanted_section(buf)
char *buf ;
{
char str[MAXLINE] ;
FILT_LIST *p ;
strcpy(str,buf) ;
(void) strupr(str) ;
if (strchr(cf_buffers[CF_EXCLUDE], cf_current_category))
return TRUE ; /* section is not wanted */
if (exclude_only)
goto test_exclude ;
/* include the section unless it is header-excluded */
if (strchr(cf_buffers[CF_UNCONDITIONAL], cf_current_category))
return FALSE ; /* section is unconditionally wanted */
if (strchr(cf_buffers[CF_INCLUDE], cf_current_category))
goto test_exclude ; /* section is wanted if not header-excluded */
/* section may be wanted if an include string matches */
for (p = includes ; p ; p = p->next)
if (p->str && strstr(str, p->str) != NULL)
goto test_exclude ;
return TRUE ; /* no include match, the entry is not wanted */
test_exclude:
if (strchr(cf_buffers[CF_OVERRIDE], cf_current_category))
return FALSE ; /* overriding header exclutions, section wanted */
/* if wanted here, set to TRUE if *any* exclude string matches */
for (p = excludes ; p ; p = p->next)
if (p->str && strstr(str, p->str) != NULL)
return TRUE ;
return FALSE ; /* not excluded, the section is wanted */
}
/***********************************************/
void get_line(buf)
char *buf ;
{
static char next_line[MAXLINE] ;
static int readahead = FALSE ;
/* get the next line from the file, skipping unwanted entries */
if (readahead)
{
strcpy(buf,next_line) ;
readahead = FALSE ;
}
else
{
do {
get_raw_line(buf) ;
} while (!include_index_lines && index_line(buf)) ;
if (section_file_start(buf))
do {
get_raw_line(buf) ;
} while (!divider_line(buf)) ;
if (do_filter && divider_line(buf))
{
/* if we read a divider line while filtering, we have to look ahead */
strcpy(next_line,buf);
while (divider_line(next_line))
{
strcpy(buf,next_line) ; /* we may be returning the divider */
get_raw_line(next_line) ;
if (start_of_entry(next_line)) /* is it an interrupt entry? */
{
cf_current_category = buf[8]; /* save the category character */
if (unwanted_section(next_line))
{
while (!divider_line(next_line))
get_raw_line(next_line) ;
}
else /* section is wanted, so return divider and then next line */
readahead = TRUE ;
}
else
readahead = TRUE ;
}
}
}
}
/***********************************************/
void fill_buffer(lines,lines_per_page)
int lines, lines_per_page ;
{
int i ;
/* copy remainder, if any, from last page to top of current page */
if (lines)
for (i = lines ; i < lines_per_page ; i++)
{
strcpy(buffer[i-lines], buffer[i]) ;
line_offsets[i-lines] = line_offsets[i] ;
}
else
lines = lines_per_page ;
for (i = lines_per_page - lines ; i < lines_per_page ; i++)
{
get_line(buffer[i]) ;
line_offsets[i] = current_line_offset + offset_adjust ;
}
}
/***********************************************/
int find_page_break(lines)
int lines ;
{
int i ;
char *buf ;
for (i = 0 ; i < widow_length ; i++)
{
buf = buffer[lines-i-1] ;
if (buf[0] == '\0' || divider_line(buf))
return lines - i ;
else if (section_start(buf))
return lines - i - 1 ;
}
return lines ;
}
/***********************************************/
int summarize(line, pages_printed)
int line, pages_printed ;
{
char *s, reg ;
int i ;
int max_descrip ;
int len, numlen ;
int is_INT_entry = 0 ;
s = buffer[line] ;
if (start_of_entry(s))
{
memcpy(summary_line," -- -- -- ",10) ;
if (s[0] == 'I' && s[1] == 'N')
is_INT_entry = 1 ;
if (is_INT_entry)
{
summary_line[1] = s[4] ; /* output interrupt number */
summary_line[2] = s[5] ;
len = 4 ;
s = buffer[line+1] ;
while (*s && isspace(*s))
s++ ;
if (*s == 'A')
{
reg = s[1] ;
while (*s && *s != '=')
s++ ;
s++ ; /* skip the equal sign */
while (*s && isspace(*s))
s++ ; /* skip the space between equal sign and number */
if (isxdigit(*s) && isxdigit(s[1]))
{
if (reg == 'L')
len += 3 ;
summary_line[len++] = *s++ ;
summary_line[len++] = *s++ ;
if (reg == 'X')
{
len++ ;
summary_line[len++] = *s++ ;
summary_line[len] = *s ;
}
}
}
}
else if (s[0] == 'C' && s[1] == 'M')
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -