home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast.iso
/
printer
/
nobs.c
< prev
next >
Wrap
Internet Message Format
|
1994-03-05
|
4KB
From: att!mtunb!dmt@ucbvax.berkeley.edu (Dave Tutelman)
Newsgroups: comp.sys.ibm.pc
Subject: Re: Printer can't backspace (was Help with IBM Graphics Printer)
Date: 13 Sep 88 13:40:47 GMT
Summary: Here's a filter to solve the problem.
randy@umn-cs.cs.umn.edu (Randy Orrison) writes:
>Could someone tell me how to set up my IBM Personal Computer Graphics
>Printer so that it understands what a backspace is, instead of just
>ignoring it? ... I have a big document with
>lots of _^Hs_^Ht_^Hu_^Hf_^Hf in it that I would really like to be able
>to print. It also has IBM printer specific escape codes in it, so I can't
>just use a different printer.
Gee, that's the second such request I've seen this morning. I had the
same problem last week with my AT&T 473 printer (a "clone"), and wrote a
little filter that fixes the problem. It scans through a line at a
time, and converts overstrikes to full-line overstrikes; backspace may
not work on my printer, but carriage return does.
I've attached the C source. I compiled it using Turbo 1.0, but it's
vanilla C and even compiles on UNIX systems. I call it NOBS (for NO
BackSpace).
+---------------------------------------------------------------+
| Dave Tutelman |
| Physical - AT&T Bell Labs - Lincroft, NJ |
| Logical - ...att!mtunb!dmt |
| Audible - (201) 576 2442 |
+---------------------------------------------------------------+
/**********************************************************************
*
* This program is a filter to fix up text for a printer that
* doesn't support BackSpace (NO BackSpace = NOBS).
* It replaces backspace sequences with carriage return sequences.
*
* Dave Tutelman - September 1988
*/
/* #define DEBUG */
#include <stdio.h>
#define LL 200 /* line length */
#define LD 8 /* line (overstrike) depth */
#define CR 13
#define LF 10
#define FF 12
#define VT 11
char line [LD] [LL];
int quit=0;
main ()
{
while ( !quit )
do_line ();
}
/*********************************************************************/
do_line ()
{
int col=0; /* current column */
int c; /* current input character */
int eol=0; /* end of line.. "quit" for do_line */
clear_line (); /* zero out the array */
while (!eol) { /* get characters till end of line */
c = getchar ();
switch (c) {
case EOF:
col=0;
eol=1;
quit=1;
break;
case FF: /* Form Feed - done with page */
case LF: /* Line Feed - done with line */
col=0;
eol=1;
break;
case VT: /* Vertical Tab - no more line */
eol = 1;
break;
case CR: /* Carriage Return - back to col 0 */
col = 0;
break;
case '\t': /* Tab - move to good col */
col = (col / 8)*8 + 8;
break;
case '\b': /* BackSpace - back off a column */
if (col>0) col--;
break;
default: /* put c into lines [..] array */
insert_c (c, col);
col ++;
break;
}
}
print_line (col);
putchar (c); /* use same line-ender that we got */
}
/**********************************************************************
* clear the line[][] array to nulls
*/
clear_line ()
{
int i,j;
for (i=0; i<LD; i++)
for (j=0; j<LL; j++)
line [i][j] = '\0';
}
/**********************************************************************
* Put c into the line[..] array at column n.
*/
insert_c (c, n)
char c;
int n;
{
int d;
if (n >= LL) /* past end of line */
return;
for (d=0; d<LD-1; d++) /* how deep? */
if (line [d][n] == '\0')
break;
line [d][n] = c;
}
/**********************************************************************
* The line is done. Put to stdout from line[..] array.
*/
print_line (col)
int col;
{
int i,j;
int jmax;
char c;
for (i=0; i<LD; i++) {
if (i>0) {
putchar (CR);
#ifdef DEBUG
putchar (LF);
#endif
col = 0;
}
for (jmax=LL-1; jmax>=0; jmax--)
if (line [i][jmax]) break;
if (jmax < 0) break;
for (j=col; j<=jmax; j++) {
c = line [i] [j];
if (c == '\0')
c = ' ';
putchar (c);
}
}
}