Thread: Re: [HACKERS] use of pager on Windows psql

Re: [HACKERS] use of pager on Windows psql

From
Bruce Momjian
Date:
Andrew Dunstan wrote:
> > Not sure why ware are not.  Should we enabled that code on Win32 and see
> > how it works?  Can you test it? Was it some MinGW limitation?  I do see
> > isatty() being used on lots of platforms.
> >
> > This is kind of odd.  Ah, I bet it came from libpq's PQprint(), which I
> > think we had working on Win32 long before we had psql working and
> > perhaps I copied it from there.  I don't see the Win32 checks around
> > isatty() anywhere else.
> >
> >
> >> In fact, it looks to me like it would be much more sensible to #include
> >> "settings.h" and then simply test pset.notty for all platforms.
> >>
> >
> > Yes, we could do that but does the isatty() value ever change while psql
> > is running?  When you do '\g filename' does stdout then have isatty as
> > false?
> >
>
>
> Good point. I think the best thing would just be to remove the #ifndef
> WIN32 / #endif lines

OK, patch applied to remove the Win32 test in both places.

I was wrong about \g filename changing stdout, I think.  It keeps stdout
but uses a different output stream.  I am just unsure, given all the
features of psql, wether it could change stdin/stdout while running in
some way.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/bin/psql/print.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/print.c,v
retrieving revision 1.105
diff -c -c -r1.105 print.c
*** src/bin/psql/print.c    17 May 2008 21:40:44 -0000    1.105
--- src/bin/psql/print.c    17 May 2008 23:32:36 -0000
***************
*** 1912,1924 ****
  PageOutput(int lines, unsigned short int pager)
  {
      /* check whether we need / can / are supposed to use pager */
!     if (pager
! #ifndef WIN32
!         &&
!         isatty(fileno(stdin)) &&
!         isatty(fileno(stdout))
! #endif
!         )
      {
          const char *pagerprog;
          FILE       *pagerpipe;
--- 1912,1918 ----
  PageOutput(int lines, unsigned short int pager)
  {
      /* check whether we need / can / are supposed to use pager */
!     if (pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
      {
          const char *pagerprog;
          FILE       *pagerpipe;
Index: src/interfaces/libpq/fe-print.c
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v
retrieving revision 1.75
diff -c -c -r1.75 fe-print.c
*** src/interfaces/libpq/fe-print.c    1 Jan 2008 19:46:00 -0000    1.75
--- src/interfaces/libpq/fe-print.c    17 May 2008 23:32:36 -0000
***************
*** 147,159 ****

          if (fout == NULL)
              fout = stdout;
!         if (po->pager && fout == stdout
! #ifndef WIN32
!             &&
!             isatty(fileno(stdin)) &&
!             isatty(fileno(stdout))
! #endif
!             )
          {
              /*
               * If we think there'll be more than one screen of output, try to
--- 147,154 ----

          if (fout == NULL)
              fout = stdout;
!         if (po->pager && fout == stdout && isatty(fileno(stdin)) &&
!             isatty(fileno(stdout)))
          {
              /*
               * If we think there'll be more than one screen of output, try to

Re: [HACKERS] use of pager on Windows psql

From
Andrew Dunstan
Date:

Bruce Momjian wrote:
> Andrew Dunstan wrote:
>
>>> Not sure why ware are not.  Should we enabled that code on Win32 and see
>>> how it works?  Can you test it? Was it some MinGW limitation?  I do see
>>> isatty() being used on lots of platforms.
>>>
>>> This is kind of odd.  Ah, I bet it came from libpq's PQprint(), which I
>>> think we had working on Win32 long before we had psql working and
>>> perhaps I copied it from there.  I don't see the Win32 checks around
>>> isatty() anywhere else.
>>>
>>>
>>>
>>>> In fact, it looks to me like it would be much more sensible to #include
>>>> "settings.h" and then simply test pset.notty for all platforms.
>>>>
>>>>
>>> Yes, we could do that but does the isatty() value ever change while psql
>>> is running?  When you do '\g filename' does stdout then have isatty as
>>> false?
>>>
>>>
>> Good point. I think the best thing would just be to remove the #ifndef
>> WIN32 / #endif lines
>>
>
> OK, patch applied to remove the Win32 test in both places.
>
>
>

This broke the buildfarm and finally explains the following kluge which
has been puzzling me for four years:

        /*
         * for some reason MinGW (and MSVC) outputs an extra newline, so
this
         * suppresses it
         */
#ifndef WIN32
        fputc('\n', fout);
#endif

I have removed the kluge (and yes, I tested it).

cheers

andrew


Re: [HACKERS] use of pager on Windows psql

From
Bruce Momjian
Date:
Andrew Dunstan wrote:
> >>>> In fact, it looks to me like it would be much more sensible to #include
> >>>> "settings.h" and then simply test pset.notty for all platforms.
> >>>>
> >>>>
> >>> Yes, we could do that but does the isatty() value ever change while psql
> >>> is running?  When you do '\g filename' does stdout then have isatty as
> >>> false?
> >>>
> >>>
> >> Good point. I think the best thing would just be to remove the #ifndef
> >> WIN32 / #endif lines
> >>
> >
> > OK, patch applied to remove the Win32 test in both places.
> >
> >
> >
>
> This broke the buildfarm and finally explains the following kluge which
> has been puzzling me for four years:
>
>         /*
>          * for some reason MinGW (and MSVC) outputs an extra newline, so
> this
>          * suppresses it
>          */
> #ifndef WIN32
>         fputc('\n', fout);
> #endif
>
> I have removed the kluge (and yes, I tested it).

Oh, that kluge.  Why did the isatty() addition fix this?  Was the pager
being used on Win32 for the regression tests and somehow eating a line
or something?

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Re: [HACKERS] use of pager on Windows psql

From
Andrew Dunstan
Date:

Bruce Momjian wrote:
>
>
>> This broke the buildfarm and finally explains the following kluge which
>> has been puzzling me for four years:
>>
>>         /*
>>          * for some reason MinGW (and MSVC) outputs an extra newline, so
>> this
>>          * suppresses it
>>          */
>> #ifndef WIN32
>>         fputc('\n', fout);
>> #endif
>>
>> I have removed the kluge (and yes, I tested it).
>>
>
> Oh, that kluge.  Why did the isatty() addition fix this?  Was the pager
> being used on Win32 for the regression tests and somehow eating a line
> or something?
>

It apparently produced an extra line which we had compensated for with
the kluge (without really understanding why we had to).

Anyway, all is good now, as the buildfarm shows.

cheers

andrew