Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.99k stars 557 forks source link

perldoc using \n rather than \r\n #6194

Closed p5pRT closed 21 years ago

p5pRT commented 21 years ago

Migrated from rt.perl.org#19682 (status was 'resolved')

Searchable as RT19682$

p5pRT commented 21 years ago

From Philip.Newton@gmx.net

Created by Philip.Newton@gmx.net

When using ActivePerl build 804 (based on v5.8.0) on a Windows machine\, perldoc is unusable. It outputs the information separated with \n rather than with \r\n\, causing output

  with   lines   like   these

The ActivePerl I used previously (based on 5.6.1\, IIRC) did not have this problem.

I have a workaround​: starting a DJGPP sh.exe and then using\, for example\, perldoc -f sysopen | cat | more (with the cat in the middle doing LF-to-CRLF translation for me)\, but that's a bit ridiculous.

I believe the problem may stem from this sequence of events​:

- perldoc creates a temporary file to write output data into (to pass   this file to a pager). - it allocates this file with File​::Temp​::tempfile - File​::Temp​::tempfile calls _gettemp - _gettemp opens the file with sysopen() not with normal open() - It uses $OPENFLAGS or $OPENTEMPFLAGS for the sysopen flags - $OPENFLAGS is initialised with a binary or of bits including O_BINARY\,   if found (lines 202ff. in File/Temp.pm) ($OPENTEMPFLAGS simply adds   O_TEMPORARY if available) - Therefore\, the temporary files created with File​::Temp​::tempfile are   always opened in binary mode if the system supports such a mode - So the \n stays \n - Problem.

(At first I was confused becausing I thought there might be a stray binmode() but didn't find one; I'm now convinced the evildoer was the O_BINARY flag.)

I'm not sure what a good solution is -- maybe add a flag to File​::Temp​::tempfile enabling the user to request a text-mode file\, and then passing that flag from withing perldoc? At any rate\, it's rather tortuous using perldoc like this now (and I think it's not an ActivePerl problem\, but rather perl _per se_\, which is why I'm perlbugging a report)\, and I usually read the text-mode version rather than the HTML docs\, which are undoubtedly fine (and most browsers can handle both \n and \r\n anyway -- but Windows's more.exe can't).

Perl Info ``` Flags: category=utilities severity=high Site configuration information for perl v5.8.0: Configured by ActiveState at Sun Dec 1 23:15:01 2002. Summary of my perl5 (revision 5 version 8 subversion 0) configuration: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cl', ccflags ='-nologo -Gf -W3 -MD -DNDEBUG -O1 -DWIN32 - D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT - DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX', optimize='-MD -DNDEBUG -O1', cppflags='-DWIN32' ccversion='', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='link', ldflags ='-nologo -nodefaultlib -release - libpath:"D:\Programme\Perl\lib\CORE" -machine:x86' libpth="D:\Programme\Perl\lib\CORE" libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib gnulibc_version='undef' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release - libpath:"D:\Programme\Perl\lib\CORE" -machine:x86' Locally applied patches: ACTIVEPERL_LOCAL_PATCHES_ENTRY @INC for perl v5.8.0: D:/Programme/Perl/lib D:/Programme/Perl/site/lib . Environment for perl v5.8.0: HOME=E:\HOME LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=D:\PROGRAMME\RUBY\BIN;D:\PROGRAMME\PERL\BIN\;D:\BIN;D:\PROGRAMME;D: \TEXTMF\MIKTEX\BIN;C:\WINDOWS;C:\WINDOWS\COMMAND;D:\DJGPP\BIN PERL_BADLANG (unset) SHELL (unset) -- Philip Newton ```
p5pRT commented 21 years ago

From @gsar

[Philip.Newton \<!--c--> \at\ \<!--a--> gmx.net - Thu Jan 2 21​:24​:27 2003]​:

I'm not sure what a good solution is -- maybe add a flag to File​::Temp​::tempfile enabling the user to request a text-mode file\, and then passing that flag from withing perldoc? At any rate\, it's rather tortuous using perldoc like this now (and I think it's not an ActivePerl problem\, but rather perl _per se_\, which is why I'm perlbugging a report)\, and I usually read the text-mode version rather than the HTML docs\, which are undoubtedly fine (and most browsers can handle both \n and \r\n anyway -- but Windows's more.exe can't).

I can't reproduce this problem on Windows NT (though I can see the temp file created by perldoc _is_ getting created in binmode() as you say).

The 'more' on Windows NT certainly handles UNIX-style text files just fine. The only thing I know of that can't handle these files properly is 'notepad'. Perhaps you're on Windows 9x?

And there is no 'more.exe'\, only 'more.com' on Windows\, AFAIK. Where is your 'more.exe' from?

Sarathy gsar@​ActiveState.com

p5pRT commented 21 years ago

From @gsar

On 03 Jan 2003 05​:24​:28 GMT\, Philip Newton wrote​:

# New Ticket Created by Philip Newton # Please include the string​: [perl #19682] # in the subject line of all future correspondence about this issue. # \<URL​: http​://rt.perl.org/rt2/Ticket/Display.html?id=19682 >

Not sure if the RT system forwards followups to p5p\, but I added a reply in RT to this report. Please visit above URL.

Sarathy gsar@​ActiveState.com

p5pRT commented 21 years ago

From Philip.Newton@gmx.net

On Fri\, 03 Jan 2003 10​:18​:11 -0800\, gsar@​ActiveState.com (Gurusamy Sarathy) wrote​:

On 03 Jan 2003 05​:24​:28 GMT\, Philip Newton wrote​:

# New Ticket Created by Philip Newton # Please include the string​: [perl #19682] # in the subject line of all future correspondence about this issue. # \<URL​: http​://rt.perl.org/rt2/Ticket/Display.html?id=19682 >

Not sure if the RT system forwards followups to p5p\, but I added a reply in RT to this report. Please visit above URL.

It appears not to\, but I believe the other way around will work\, so I'll comment here.

The 'more' on Windows NT certainly handles UNIX-style text files just fine. The only thing I know of that can't handle these files properly is 'notepad'. Perhaps you're on Windows 9x?

Indeed I am; sorry for not making that clear in the bug report (Win98SE\, to be more precise).

(Maybe it's also a difference between COMMAND.COM and CMD.EXE? Don't know. On the other hand\, creating a Unix-style file and then invoking 'more' on it also gives me a ladder-type display\, so it's likely a difference between NT's more.com and 9x's.)

And there is no 'more.exe'\, only 'more.com' on Windows\, AFAIK. Where is your 'more.exe' from?

Er\, you're right; it *is* 'more.com' (in C​:\WINDOWS\COMMAND). I was ass-u-ming that it was an .exe but it isn't.

Let me re-phrase the last sentence as "most browsers can handle both \n and \r\n anyway -- but Windows 98's more.com can't".

Cheers\, Philip

p5pRT commented 21 years ago

From @jhi

Do I understand correctly that this is simply a documentation issue\, as in "do not try to use the Win98 more.com as your pager"?

p5pRT commented 21 years ago

From Philip.Newton@gmx.net

On 23 Jan 2003 at 4​:12\, via RT wrote​:

Do I understand correctly that this is simply a documentation issue\, as in "do not try to use the Win98 more.com as your pager"?

*tries a few things out* Maybe. "type" can also not handle \n- terminated lines\, but when I "binmode STDOUT" and then output \n- terminated lines from Perl\, it displays correctly. (And DJGPP 'od' says that with binmode it sees '\n' and without it sees '\r\n'\, so the binmode does have an effect.) So I suppose the actual console output routines (or command.com\, or whoever is responsible) *can* handle \n as line terminator.

Still\, there isn't much choice under Win98. I don't think using WordPad as a pager (as ActiveState support suggested) is really the right solution. (And I don't even know whether it accepts input from STDIN anyway.) Hardly anyone\, I'll assume\, has DJGPP less or Vern Buerg's LIST or some other pager.

I think it would be much preferable to open the temporary file in text mode -- after all\, Perl documentation is (more or less by definition) text. That way\, we could accommodate Win98's brain-damaged more.com; after all\, in previous releases it worked all right (when perldoc opened its own temp file in the default -- text -- mode rather than relying on File​::Temp\, which opens files in binary mode).

What do you suggest? Documenting that Win98's more.com does not work as a pager? What should Win98 users use then? (Note that "no pager" is not an option\, either\, since the Win9x console window does not have scrollback the way NT consoles do -- so you only see the last max. 50 lines. At least as far as I can see. And telling them to "redirect output into a text file and open that with your favourite editor" is not very user-friendly\, either\, IMO.)

Cheers\, Philip -- Philip Newton \Philip\.Newton@&#8203;gmx\.net

p5pRT commented 21 years ago

From guest@guest.guest.xxxxxxxx

I have experienced the same problem with perldoc on both of my Win98 boxes since updating to 5.8.0. I found another user in the c.l.p.m newsgroup whose perldoc works on his WinNT box\, but not his Win95 box.
This seems to support the idea that the problem is related to Win98's more.com.

I guess I'll look into a different pager. I haven't found a silver- bullet for this anywhere.

--Rick rick_is@​bigfoot.com

p5pRT commented 21 years ago

From Philip.Newton@gmx.net

On 11 Feb 2003 at 6​:29\, via RT wrote​:

I guess I'll look into a different pager. I haven't found a silver- bullet for this anywhere.

I have\, thanks to Sean M. Burke\, who suggested installing Pod​::Perldoc. That module comes with a replacement 'perldoc' script which Does The Right Thing on Windows.

It's pure Perl\, so just fetch it from CPAN. If you have a make utility (preferably Microsoft's nmake\, since that's what ActivePerl was built with)\, then the standard "perl Makefile.PL; make; make install" should work.

Otherwise copy Pod\Perldoc.pm to a directory under @​INC and put perldoc into the Perl "bin" directory; it may need converting to a batch file by hand (with pl2bat) so that you can simply call it as "perldoc".

Cheers\, Philip -- Philip Newton \Philip\.Newton@&#8203;gmx\.net

p5pRT commented 21 years ago

From guest@guest.guest.xxxxxxxx

Thanks again.

Since I have the default Activestate binary distribution\, it was even easier.

PPM>install Pod​::Perldoc

When the install finished\, perldoc worked. (It even creates perldoc.bat).

--R Clary rick_is@​bigfoot.com

p5pRT commented 21 years ago

From @schwern

Since Pod​::Perldoc is in the core now\, we'll call this resolved.

p5pRT commented 21 years ago

@schwern - Status changed from 'new' to 'resolved'