version 1.5, 2000/03/22 15:38:23 |
version 1.6, 2001/07/12 05:17:27 |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <unistd.h> |
|
#include <stdlib.h> |
|
#include <curses.h> |
|
#include <term.h> |
|
|
#define IESC '\033' |
#define IESC '\033' |
#define SO '\016' |
#define SO '\016' |
|
|
int upln; |
int upln; |
int iflag; |
int iflag; |
|
|
int outchar(); |
int outchar(int); |
#define PRINT(s) if (s == NULL) /* void */; else tputs(s, 1, outchar) |
void initcap(void); |
|
void initbuf(void); |
|
void mfilter(FILE *); |
|
void reverse(void); |
|
void fwd(void); |
|
void flushln(void); |
|
void msetmode(int); |
|
void outc(int); |
|
void overstrike(void); |
|
void iattr(void); |
|
|
|
#define PRINT(s) \ |
|
do { \ |
|
if (s) \ |
|
tputs(s, 1, outchar); \ |
|
} while (0) |
|
|
|
int |
main(argc, argv) |
main(argc, argv) |
int argc; |
int argc; |
char **argv; |
char **argv; |
|
|
must_overstrike = 1; |
must_overstrike = 1; |
initbuf(); |
initbuf(); |
if (optind == argc) |
if (optind == argc) |
filter(stdin); |
mfilter(stdin); |
else for (; optind<argc; optind++) { |
else for (; optind<argc; optind++) { |
f = fopen(argv[optind],"r"); |
f = fopen(argv[optind],"r"); |
if (f == NULL) { |
if (f == NULL) { |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
filter(f); |
mfilter(f); |
fclose(f); |
fclose(f); |
} |
} |
exit(0); |
exit(0); |
} |
} |
|
|
filter(f) |
void |
|
mfilter(f) |
FILE *f; |
FILE *f; |
{ |
{ |
register c; |
int c; |
|
|
while ((c = getc(f)) != EOF && col < MAXBUF) switch(c) { |
while ((c = getc(f)) != EOF && col < MAXBUF) switch(c) { |
|
|
|
|
flushln(); |
flushln(); |
} |
} |
|
|
|
void |
flushln() |
flushln() |
{ |
{ |
register lastmode; |
int lastmode, i; |
register i; |
|
int hadmodes = 0; |
int hadmodes = 0; |
|
|
lastmode = NORMAL; |
lastmode = NORMAL; |
for (i=0; i<maxcol; i++) { |
for (i=0; i<maxcol; i++) { |
if (obuf[i].c_mode != lastmode) { |
if (obuf[i].c_mode != lastmode) { |
hadmodes++; |
hadmodes++; |
setmode(obuf[i].c_mode); |
msetmode(obuf[i].c_mode); |
lastmode = obuf[i].c_mode; |
lastmode = obuf[i].c_mode; |
} |
} |
if (obuf[i].c_char == '\0') { |
if (obuf[i].c_char == '\0') { |
|
|
outc(obuf[i].c_char); |
outc(obuf[i].c_char); |
} |
} |
if (lastmode != NORMAL) { |
if (lastmode != NORMAL) { |
setmode(0); |
msetmode(0); |
} |
} |
if (must_overstrike && hadmodes) |
if (must_overstrike && hadmodes) |
overstrike(); |
overstrike(); |
|
|
* For terminals that can overstrike, overstrike underlines and bolds. |
* For terminals that can overstrike, overstrike underlines and bolds. |
* We don't do anything with halfline ups and downs, or Greek. |
* We don't do anything with halfline ups and downs, or Greek. |
*/ |
*/ |
|
void |
overstrike() |
overstrike() |
{ |
{ |
register int i; |
register int i; |
|
|
} |
} |
} |
} |
|
|
|
void |
iattr() |
iattr() |
{ |
{ |
register int i; |
register int i; |
|
|
putchar('\n'); |
putchar('\n'); |
} |
} |
|
|
|
void |
initbuf() |
initbuf() |
{ |
{ |
|
|
|
|
mode &= ALTSET; |
mode &= ALTSET; |
} |
} |
|
|
|
void |
fwd() |
fwd() |
{ |
{ |
register oldcol, oldmax; |
int oldcol, oldmax; |
|
|
oldcol = col; |
oldcol = col; |
oldmax = maxcol; |
oldmax = maxcol; |
|
|
maxcol = oldmax; |
maxcol = oldmax; |
} |
} |
|
|
|
void |
reverse() |
reverse() |
{ |
{ |
upln++; |
upln++; |
|
|
upln++; |
upln++; |
} |
} |
|
|
|
void |
initcap() |
initcap() |
{ |
{ |
static char tcapbuf[512]; |
static char tcapbuf[512]; |
|
|
must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE); |
must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE); |
} |
} |
|
|
|
int |
outchar(c) |
outchar(c) |
int c; |
int c; |
{ |
{ |
putchar(c & 0177); |
putchar(c & 0177); |
|
return (0); |
} |
} |
|
|
static int curmode = 0; |
static int curmode = 0; |
|
|
|
void |
outc(c) |
outc(c) |
int c; |
int c; |
{ |
{ |
|
|
} |
} |
} |
} |
|
|
setmode(newmode) |
void |
|
msetmode(newmode) |
int newmode; |
int newmode; |
{ |
{ |
if (!iflag) { |
if (!iflag) { |
if (curmode != NORMAL && newmode != NORMAL) |
if (curmode != NORMAL && newmode != NORMAL) |
setmode(NORMAL); |
msetmode(NORMAL); |
switch (newmode) { |
switch (newmode) { |
case NORMAL: |
case NORMAL: |
switch(curmode) { |
switch(curmode) { |