📄 fconvert.cpp
字号:
void f_write_page(Window *w) // window to display msgs in
{
int i, j = 0, // loop counter
line, // line counter
type; // pixel type
char buf[60], // work buffer
huge *p; // ..and pointer
long start_pos, // page starting position
page_len; // ..and page length
static
long percent, // percent complete
last, // last display time
far *timer = (long far *) // BIOS timer tick counter
MK_FP(0x40, 0x6c); // ..down in low memory
lseek(f_handle, 0L, SEEK_END); // goto end of file
start_pos = tell(f_handle); // ..and get position info
memset(buf, 0, sizeof(buf)); // clear buffer to nulls
write(f_handle, buf, 4); // write page length
write(f_handle, buf, 10); // ..and some nulls
f_write_flag = 0; // clear output flag
f_write_out(1, 12); // ..and write an EOL
for (p = page, line = 0; line < LINES; // for each line in the bitmap
line++, p += LINE) // ..encode into G3 format
{
f_write_cnt = 0; // clear output byte count
if ((*timer - last) > 9) // q. has half a second past?
{
percent = (line * 100L) / LINES; // a. yes .. get percentage
sprintf(buf, write_msg, // build status message
f_pgcnt, percent); // ..into a work buffer
w->Display(buf); // ..display the message
last = *timer; // ..and pickup current time
}
if (reverse_scan((char *) p, 0, LINE)) // q. anything on line?
{ // a. yes .. process
for (i = type = 0; i < PELS; i += j)// scan across the bitmap line
{
j = f_scan_out(p, i, type); // scan bitmap for pixels
type = (type + 1) & 1; // flip-flop the type code
}
}
else
f_encode(1728, 0); // else .. put out blank line
if (f_write_flag) // q. any residual bits?
f_write_out(0, 8 - f_write_flag); // a. yes .. put out the rest
if (i < 40) // q. need to pad out line?
write(f_handle, (void *) &buf, // a. yes .. write a string
40 - i); // ..of up to 40 null bytes
f_write_out(1, 12); // then put out an EOL
}
for (i = 0; i < 5; i++) // at end of page
f_write_out(1, 12); // ..put out 5 more EOLs
buf[0] = DLE; // set up termination
buf[1] = ETX; // ..with DLE ETX
write(f_handle, buf, 2); // ..then put them out
page_len = tell(f_handle) - start_pos - 4; // compute page data length
lseek(f_handle, start_pos, SEEK_SET); // position to length field
write(f_handle, (void *) &page_len, 4); // ..and update field
}
/* ******************************************************************** *
*
* f_build_char() -- fill in bitmap position with a character
*
* ******************************************************************** */
void f_build_char(char cc, // character to use
int c, int r) // column and row
{
UINT *ce, // table entry pointer
i; // loop counter
char huge *p, // bitmap pointer
ch1, ch2; // high and low bytes
ce = &ascii_map[cc][0]; // get entry in table
p = &page[((r * 22L) * LINE) + (c * 2)]; // get starting point
for (i = 0; i < 11; i++, ce++) // for each of the chars rows
{
if (*ce) // q. anything to put in bitmap?
{ // a. yes .. process bits
ch1 = *ce >> 8; // get high order byte
ch2 = *ce & 0xff; // ..and low order byte
*p |= ch1; // "or" in each cols bits
*(p + 1) |= ch2; // ..for both bytes
p += LINE; // move to next line
*p |= ch1; // "or" in each cols bits
*(p + 1) |= ch2; // ..for both bytes
p += LINE; // move to next line
}
else
p += LINE * 2; // else .. skip two bitmap lines
}
}
/* ******************************************************************** *
*
* f_build_page() -- read an ASCII text file and build a bitmap
*
* returns: 0 = end of file reached
* n = characters encoded
*
* ******************************************************************** */
int f_build_page(FILE *f) // input file pointer
{
int i, // chars processed
lines, // lines counter
c, r, // column and row (0 based)
cc; // character buffer
char huge *p; // bitmap line pointer
for (lines = 0, p = page; // for the whole bitmap
lines < LINES; // ..run through line
lines++, p += LINE) // ..by line
memset(p, 0, LINE); // ..and clear white space
c = r = 0; // start column & row at top
for (i = 0; ; i++) // loop building bitmap
{
if ((cc = fgetc(f)) == EOF) // q. get a good character?
return(i); // a. no .. return w/count
f_build_char(cc, c, r); // bld bitmap at column & row
switch (cc) // update column & row
{
case LF: // line feed
if (++r >= ROWS) // q. reach bottom limit?
return(i); // a. yes .. then page is done
break; // else .. get next character
case CR: // carriage return
c = 0; // start at next beginning
break; // ..and get next character
case 12: // form feed
return(++i); // return w/nbr chars processed
case BACKSPACE: // backspace
if (--c < 0) // q. backup too far?
c = 0; // a. yes .. goto column 0
break; // else .. get next character
case TAB: // tab
c = (c & ~0x7) + 8; // move to next tab stop
if (c >= COLUMNS) // q. too far out?
{
c = 0; // a. yes .. just wrap around
if (++r >= ROWS) // q. reach bottom of page?
return(i); // a. yes .. stop here
}
break; // else .. get next character
default: // everything else
if (++c >= COLUMNS) // q. reach right margin?
{
c = 0; // a. yes .. just wrap around
if (++r >= ROWS) // q. reach bottom of page?
return(i); // a. yes .. stop here
}
}
}
}
/* ******************************************************************** *
*
* f_build_fax() -- build a fax file from an ASCII text file
*
* ******************************************************************** */
void f_build_fax(char *f, // file name
Window *w) // window to update
{
FILE *fi; // input file
int i; // string index
char buf[60], buf2[60], // format buffers
*p; // ..and pointer
if (f_handle != -1) // q. already open?
{
close(f_handle); // a. yes .. close file
f_handle = -1; // ..and clear flag
}
if ((fi = fopen(f, "rb")) == 0) // q. open ok?
return; // a. no .. just return
strcpy(buf, f); // copy base filename
if ((p = strrchr(buf, '.')) == 0) // q. file extension found?
p = &buf[strlen(buf)]; // a. no .. point to end
strcpy(p, ".fax"); // copy in extension
if ((f_handle = open(buf, // q. open new file ok?
O_BINARY | O_TRUNC | O_RDWR | O_CREAT)) == -1)
return; // a. no .. just return
sprintf(buf2, create_msg, buf); // build display message
w->Display(buf2); // ..and send to user window
if ((i = 34 - (strlen(f) + // q. able to center the
strlen(status_conv) - 2)) < 0) // .."Converting: XXXX" msg?
i = 0; // a. no .. flush left
memset(buf2, ' ', sizeof(buf2)); // clear area to blanks
sprintf(&buf2[i / 2], status_conv, f); // format build information
status_line(status, buf2); // update status line
f_write_hdr(); // write header information
for (f_pgcnt = 1; ; f_pgcnt++) // loop building and writing
{
if (f_build_page(fi) == 0) // q. read ASCII ok?
break; // a. no .. end of file
f_write_page(w); // encode bitmap & write file
}
fclose(fi); // close input file
close(f_handle); // ..and output file
f_handle = -1; // ..and reset global
f_locate(buf); // set up to view/print file
sprintf(buf2, status_file, // format file information
buf, f_pgcnt); // ..for status line
if (f_pgcnt > 1) // q. more than 1 page fax?
strcat(buf2, "s"); // a. yes .. pluralize page
status_line(status, buf2); // update status line
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -