[comp.lang.c] printing underlined text

cage@fmeed1.UUCP (Russ Cage) (10/31/90)

In article <43321@eerie.acsu.Buffalo.EDU> haozhou@acsu.buffalo.edu (hao zhou) writes:
>Does anybody out there know if it's possible to print out underlined
>text using printf() in C? And how? 

This really belongs in comp.lang.c, but...

printf( "Underlined text\015__________ ____\n" );

ought to work on any ASCII system with printing terminals.
To use underlining on CRTs or other fancy equipment you
have to get hardware-specific (or use termcap).

Followups to comp.lang.c.
-- 
Russ Cage	Ford Powertrain Engineering Development Department
Work:  itivax.iti.org!cfctech!fmeed1!cage   (CHATTY MAIL NOT ANSWERED HERE)
Home:  russ@m-net.ann-arbor.mi.us  (All non-business mail)
Member:  HASA, "S" division.

rickert@mp.cs.niu.edu (Neil Rickert) (11/11/90)

In article <8611@fmeed1.UUCP> russ@m-net.ann-arbor.mi.us (Russ Cage) writes:
>In article <43321@eerie.acsu.Buffalo.EDU> haozhou@acsu.buffalo.edu (hao zhou) writes:
>>Does anybody out there know if it's possible to print out underlined
>>text using printf() in C? And how? 
>
>This really belongs in comp.lang.c, but...
>
>printf( "Underlined text\015__________ ____\n" );
>
>ought to work on any ASCII system with printing terminals.
>To use underlining on CRTs or other fancy equipment you
>have to get hardware-specific (or use termcap).
>

 One improvement would be to use:

printf( "__________ ____\015Underlined text\n" );

 That way, on a CRT you would at least see the text instead of the
underscores.

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert@cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115.                                  +1-815-753-6940

weimer@ssd.kodak.com (Gary Weimer) (11/13/90)

In article <1990Nov11.153636.13643@mp.cs.niu.edu> rickert@mp.cs.niu.edu (Neil Rickert) writes:
>In article <8611@fmeed1.UUCP> russ@m-net.ann-arbor.mi.us (Russ Cage) writes:
>>In article <43321@eerie.acsu.Buffalo.EDU> haozhou@acsu.buffalo.edu (hao zhou) writes:
>>>Does anybody out there know if it's possible to print out underlined
>>>text using printf() in C? And how? 
>>
>>This really belongs in comp.lang.c, but...
>>
>>printf( "Underlined text\015__________ ____\n" );
>>
>>ought to work on any ASCII system with printing terminals.
>>To use underlining on CRTs or other fancy equipment you
>>have to get hardware-specific (or use termcap).
>>
>
> One improvement would be to use:
>
>printf( "__________ ____\015Underlined text\n" );
>
> That way, on a CRT you would at least see the text instead of the
>underscores.

Another improvement:

printf( "_^HU_^Hn_^Hd_^He_^Hr_^Hl_^Hi_^Hn_^He_^Hd _^Ht_^He_^Hx_^Ht\n" );

Although this is much less readable, most "smart" terminals, as well as
printers will know how to handle this (see nroff output).

Gary Weimer

epames@eos.ericsson.se (Michael Salmon) (11/13/90)

While I agree that the solutions given will all work I would like to make
a couple of comments. Firstly C has a lovely way to describe system
independant characters, in this case \r and \b, personally I hate having
to translate into and out of octal. Secondly, I would advise against using
backspace in any output to a dot matrix printer, it causes the buffer to be
printed and this can significantly slow down the printer.

Michael Salmon
L.M.Ericsson
Stockholm

gwyn@smoke.brl.mil (Doug Gwyn) (11/14/90)

In article <1990Nov13.074643.3107@ericsson.se> epames@eos.ericsson.se writes:
>Secondly, I would advise against using backspace in any output to a dot
>matrix printer, it causes the buffer to be printed and this can
>significantly slow down the printer.

It's a good idea to filter output through an "overstrike" filter on its
way to a line printer (or in this case dot-matrix printer).  BRL's MDQS
queueing system's line printer server invokes a copyn() function that
takes care of this.  (Based on an earlier implementation by John
Quarterman.)  MDQS is available via anonymous FTP from VGR.BRL.MIL.

pjh@mccc.uucp (Pete Holsberg) (11/15/90)

In article <1990Nov12.183213.8920@ssd.kodak.com> weimer@ssd.kodak.com (Gary Weimer) writes:
=Another improvement:
=
=printf( "_^HU_^Hn_^Hd_^He_^Hr_^Hl_^Hi_^Hn_^He_^Hd _^Ht_^He_^Hx_^Ht\n" );
=
=Although this is much less readable, most "smart" terminals, as well as
=printers will know how to handle this (see nroff output).

Only "smart" printers can handle "real-time" backspacing.  Our dot
matrix printers won't so we like the "print the underline, return the
carriage, print the text" approach.  I don't think that lasers are smart
enough, either.

Pete
-- 
Prof. Peter J. Holsberg      Mercer County Community College
Voice: 609-586-4800          Engineering Technology, Computers and Math
UUCP:...!princeton!mccc!pjh  1200 Old Trenton Road, Trenton, NJ 08690
Internet: pjh@mccc.edu	     Trenton Computer Festival -- 4/20-21/91

garlange@mentor.cc.purdue.edu (Mark Garlanger) (11/15/90)

In article <8611@fmeed1.UUCP> russ@m-net.ann-arbor.mi.us (Russ Cage) writes:
>In article <43321@eerie.acsu.Buffalo.EDU> haozhou@acsu.buffalo.edu (hao zhou) writes:
>>Does anybody out there know if it's possible to print out underlined
>>text using printf() in C? And how? 
>
>printf( "Underlined text\015__________ ____\n" );
>
A slightly better way would be to put it:

printf("__________ ____\015Underlined text\n");

This way when someone tries to view it on a regular terminal the text will
still be readable. 

			 	Mark

userAKDU@mts.ucs.UAlberta.CA (Al Dunbar) (11/16/90)

In article <1990Nov11.153636.13643@mp.cs.niu.edu>, rickert@mp.cs.niu.edu (Neil Rickert) writes:
>In article <8611@fmeed1.UUCP> russ@m-net.ann-arbor.mi.us (Russ Cage) writes:
>>In article <43321@eerie.acsu.Buffalo.EDU> haozhou@acsu.buffalo.edu (hao zhou) writes:
>>>Does anybody out there know if it's possible to print out underlined
>>>text using printf() in C? And how?
<<< deletions >>>
> One improvement would be to use:
>
>printf( "__________ ____\015Underlined text\n" );
>
> That way, on a CRT you would at least see the text instead of the
>underscores.
>
A further change will possibly save a few edit/compile cycles,
or at least some drudgery:
 
printf( "__________ ____?015"?
"Underlined text?n" );
 
I steadfastly refuse to count characters in strings since last
using hollerith fields in Fortran.
 
-------------------+-------------------------------------------
Al Dunbar          |
Edmonton, Alberta  |   this space for rent
CANADA             |
-------------------+-------------------------------------------

userAKDU@mts.ucs.UAlberta.CA (Al Dunbar) (11/19/90)

In article <1925@mts.ucs.UAlberta.CA>, userAKDU@mts.ucs.UAlberta.CA (Al Dunbar) writes:
>In article <1990Nov11.153636.13643@mp.cs.niu.edu>, rickert@mp.cs.niu.edu (Neil Rickert) writes:
>>In article <8611@fmeed1.UUCP> russ@m-net.ann-arbor.mi.us (Russ Cage) writes:
>>>In article <43321@eerie.acsu.Buffalo.EDU> haozhou@acsu.buffalo.edu (hao zhou) writes:
>>>>Does anybody out there know if it's possible to print out underlined
<<<deletions>>>
>
>printf( "__________ ____?015"?
>"Underlined text?n" );
>
Oooops, forgot that our usenet interface eats leading blanks.
The second line should be right shifted by 8.
 
-------------------+-------------------------------------------
Al Dunbar          |
Edmonton, Alberta  |  "this mind left intentionally blank"
CANADA             |          - Manuel Writer
-------------------+-------------------------------------------
#! r

hp@vmars.tuwien.ac.at (Peter Holzer) (11/21/90)

pjh@mccc.uucp (Pete Holsberg) writes:

>In article <1990Nov12.183213.8920@ssd.kodak.com> weimer@ssd.kodak.com (Gary Weimer) writes:
>=Another improvement:
>=
>=printf( "_^HU_^Hn_^Hd_^He_^Hr_^Hl_^Hi_^Hn_^He_^Hd _^Ht_^He_^Hx_^Ht\n" );
>=
>=Although this is much less readable, most "smart" terminals, as well as
>=printers will know how to handle this (see nroff output).

>Only "smart" printers can handle "real-time" backspacing.  Our dot
>matrix printers won't so we like the "print the underline, return the
>carriage, print the text" approach.  I don't think that lasers are smart
>enough, either.

Huh? What does the printf above print on your printer?
It works on any matrix printer I have seen and in the worst case it
should print ``Underlinedtext'' non-underlined as many terminals do.
Many Matrix-Printers will slow down very much on such output because
they have to
start, print underscore, stop,
start backwards, stop,
start, print character, stop
for each character. Underline\rText is certainly faster on such 
printers.

I certainly see no reason why it should not work on a laser printer.
Laser printers are usually quite ``smart''.

Note however that there are two backspace characters in the ASCII.
BS (0x08, ^H) just moves the cursor to the left, while DEL (0x7F, ^?)
deletes the previous character from the print queue (if it exists).

The REAL SOLUTION(TM) however is to have a database of means how to 
get underlining, bold, etc from all your printers, terminals etc.
(If you have a UNIX-system, use termcap or termlib) and use this.
--
|    _  | Peter J. Holzer                       | Think of it   |
| |_|_) | Technical University Vienna           | as evolution  |
| | |   | Dept. for Real-Time Systems           | in action!    |
| __/   | hp@vmars.tuwien.ac.at                 |     Tony Rand |