I have a customer that is having a stair-stepping output issue
to the printer. I am not new to this problem and even have a FAQ
on the topic. My question has to do with command '/usr/lib/lponlcr'
which I am not familar with. I have no 'man' pages on this command.
I am most interested in finding out how it compares to what 'xtod' does...
if they are even comparable commands.
# lp -dprinter_name ascii_file
# cat ascii_file | lp -dprinter_name
# cat ascii_file | xtod | lp -dprinter_name
# cat ascii_file | /usr/lib/lponlcr | lp -dprinter_name
Best Regards,
Jeffrey Hyman, President
.--.
___________________________ .-. | | _____________________________________
Lone Star Software Corp. | | | | .-. Home of World Famous LONE-TAR(tm)
Cactus International, Inc. | |_| | | | Backup Software for UNIX and LINUX
Sales: 800.525.8649 _ |___ |_| | 24x7 Support Available
Support: 301.829.1622 _| ~- | ___| RESCUE-RANGER(tm) and AIR-BAG(tm)
http://www.LONE-TAR.com \, _} | | Disaster Recovery Software
-------------------------- \( -- | | --------------------------------------
| |
> I have a customer that is having a stair-stepping output issue
> to the printer. I am not new to this problem and even have a FAQ
> on the topic. My question has to do with command '/usr/lib/lponlcr'
> which I am not familar with. I have no 'man' pages on this command.
> I am most interested in finding out how it compares to what 'xtod' does...
> if they are even comparable commands.
>
> # lp -dprinter_name ascii_file
> # cat ascii_file | lp -dprinter_name
> # cat ascii_file | xtod | lp -dprinter_name
> # cat ascii_file | /usr/lib/lponlcr | lp -dprinter_name
`xtod` and `lponlcr` are very similar. xtod's source is more
complicated because it responds to the name you run it under (xtod or
dtox). lponlcr is _really_ simple. Aside from a ridiculous copyright
statement about how holy and confidential this stuff is, it's just:
#include <stdio.h>
main()
{
register int c;
while ((c=getchar()) != EOF) {
if (c == '\n')
putchar('\r');
putchar(c);
}
}
xtod also: takes an optional single filename to read from instead of
stdin; and appends a control-Z (DOS EOF marker) to the end of the
output.
I believe DOS Merge comes with another set of these utilities, and VP/ix
probably did, and quite a number of utilities have an embedded ability
to do CRLF translation along with something else they're doing (e.g.
`ftp`). It's a very frequent problem for Unix users, so the wheel has
been reinvented many times.
>Bela<
xtod adds a CTRL-Z and lponlcr does not.
--
Please note new phone number: (781) 784-7547
Tony Lawrence
Unix/Linux Support Tips, How-To's, Tests and more: http://aplawrence.com
Free Unix/Linux Consultants list: http://aplawrence.com/consultants.html
/usr/lib/lponlcr adds a carriage return to every newline
xtod add a carriage return to every newline AND appends a ^Z, which
is supposed to be the ms-dos end of file character.
--
==========================================================================
Tom Parsons t...@tegan.com
==========================================================================
Uh-oh. Disclosing intellectual property :-)
You'd think (given it's intended use) that it would be smart enoufgh to
see if the file really is text before munging the output. If it did
that minor little thing, it could be safely included anywhere and
everywhere as extra \r's are harmless.
None of those 'cat' commands are needed, Jeff!
My experience is that xtod adds a ^Z at the end of the file, lponlcr does
not.
--
JP
For lponlcr cat (or something) is necessary - that's a filter only,
takes no Args.
You just got married. I'm sure you'll have (if not already)
some fantastic war/bedtime stories about cat. :-)
- Jeff
>
> My experience is that xtod adds a ^Z at the end of the file, lponlcr does
> not.
PS: Thanks to all for the informative answers. It was very helpful.
> --
> JP
Input redirection is just fine; 'cat' is not needed.
--
JP
lponlcr appears to do what the stty onlcr option does - Maps NL to
CR(/LF?) Found Jeff Liebermann posting about it here:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=ie38isgar0kiohlgg74i6aqsdnrp8odovt%404ax.com
How it differs from dtox I do not know. Maybe Jeff would like to
tackle that one ?
Scott McMillan
> >># cat ascii_file | /usr/lib/lponlcr | lp -dprinter_name
> You'd think (given it's intended use) that it would be smart enoufgh to
> see if the file really is text before munging the output. If it did
> that minor little thing, it could be safely included anywhere and
> everywhere as extra \r's are harmless.
Sounds simple, but... accurately detecting "text" isn't really all that
easy. If you define it as US-ASCII text (chars 20-7E hex + CR LF TAB
and maybe a couple of others), sure, it's easy. Throw in a couple of
diacriticals and it gets worse. Throw in full ISO8859 and it's a lot
worse. And there are even more character sets. The simple 10-line
program is suddenly 350 lines of analysis + 10 lines of work -- and the
analysis is only right 98% of the time.
Do you really want that?
>Bela<
I've needed it now and then, and have used "file" to decide whether or
not to use it. Dunno how easy it is to fool "file" but it worked ok for
whatever I needed it for at the time.
Good feedback on the topic. What actually occurs (behind the scene)
to cause one to need to use 'xtod' or any other filtering process?
It is so rare that I see it needed, that I'd be curious as to the
"source" of the problem. IOW: What low-level process is in charge of
how lines end in an ascii file? Why would it occur so infrequently
on a same Ver/Rel of an OS?
-- Jeff Hyman
Nothing occurs behind the scenes. Text file line endings in Unix have
always been 0x0a, AKA LF. You don't wnat to send that to a screen
without adding a CR (try 'stty -onlcr' and cat a file...), and you may
or may not want send just an LF to a printer. Many printers allow a
setting to add a CR to an LF, but if they don't, you want to do it in a
software filter before the bytes hit the printer.
--
JP
> Bela Lubkin wrote:
> > Tony Lawrence wrote:
> >
> >
> >>>># cat ascii_file | /usr/lib/lponlcr | lp -dprinter_name
> >
> >
> >>You'd think (given it's intended use) that it would be smart enoufgh to
> >>see if the file really is text before munging the output. If it did
> >>that minor little thing, it could be safely included anywhere and
> >>everywhere as extra \r's are harmless.
> >
> >
> > Sounds simple, but... accurately detecting "text" isn't really all that
> > easy. If you define it as US-ASCII text (chars 20-7E hex + CR LF TAB
> > and maybe a couple of others), sure, it's easy. Throw in a couple of
> > diacriticals and it gets worse. Throw in full ISO8859 and it's a lot
> > worse. And there are even more character sets. The simple 10-line
> > program is suddenly 350 lines of analysis + 10 lines of work -- and the
> > analysis is only right 98% of the time.
> >
> > Do you really want that?
>
> I've needed it now and then, and have used "file" to decide whether or
> not to use it. Dunno how easy it is to fool "file" but it worked ok for
> whatever I needed it for at the time.
A file that starts with text and continues with gibberish will be
labeled text (cat /etc/termcap > /tmp/foo; compress < /etc/termcap >>
/tmp/foo; file /tmp/foo). Files in medium-exotic localized character
sets will probably not show up as text, but would need CR's added to be
printed correctly.
So now you're looking at an override flag ("look you stupid program,
this file _really is_ text, go ahead and add CRs like I told you"). But
then what's the difference between having a program that sometimes adds
CRs, unless you override it and make it always add CRs; and a program
that always adds CRs? You're back to needing to individually decide,
for each file, how to handle it. Instead of "do I pipe through lponlcr
or not", now the question is "do I pipe through lponlcr or through
lponlcr -yesIamsure".
No gain.
No matter how sophisticated you make the decider, there will be corner
cases that break it. Meanwhile, the more sophisticated the behavior,
the more mysterious it will be when it does fail. Suppose you piped
everything through lponlcr, and it generally "worked" on binaries
(didn't trash them). Then one day something got trashed. Would you
suspect lponlcr? Suppose you did. How would you test it? Run some
various binaries through it? It would pass them cleanly, since they
weren't the corner cases. Your debugging process would be painful.
The correct solution is: don't pipe everything through a filter intended
for particular data types! For instance, use an interface script which
takes arguments like "-o raw", meaning "don't do anything weird such as
piping through lponlcr" -- and _use_ that flag when you need to.
>Bela<
Probably Jeff is still left wondering why it is sometimes needed and
sometimes not. The answer is that in many setups it doesn't matter
because the printer is already doing CR/LF translations itself, or the
data is being sent in a graphic format that doesn't need it, or an
interface script is handling it in another way (example hpnpf and -N
-N). or the script does stty onlcr. And of course you absolutely don't
want it if you are sending Windows jobs to a Visionfs/Samba printer.
> I wonder if I am subliminally attracted to cat.
>Ever since my wife Crissy has allowed cats in the house,
>I have dreams where I take a pipe '|' and clobber the cat.
>Unfortunately I cannot get away with 'rm cat'.
>I cannot relocate cat outside to '/dev/null'.
>I can't even get away with putting an arrow in the cat ... '> cat'
They are already dimensioned into an array with a size of 9.
Bill
--
Bill Vermillion - bv @ wjv . com
Try Domination Option Grepper, aka DOG, in Unix tradition, it is called just
plain dog.