Re: [HACKERS] use of pager on Windows psql

Lists: pgsql-hackerspgsql-patches
From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: use of pager on Windows psql
Date: 2008-05-17 20:45:20
Message-ID: 482F43E0.6000003@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


psql's print.c contains this piece of code:

/*
* PageOutput
*
* Tests if pager is needed and returns appropriate FILE pointer.
*/
FILE *
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
)
{

Why are we not doing the isatty tests on Windows? We can and do use
isatty on Windows elsewhere, so I'm a bit mystified about this.

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.

cheers

andrew


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: use of pager on Windows psql
Date: 2008-05-17 21:46:04
Message-ID: 200805172146.m4HLk4k28052@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Dunstan wrote:
>
> psql's print.c contains this piece of code:
>
> /*
> * PageOutput
> *
> * Tests if pager is needed and returns appropriate FILE pointer.
> */
> FILE *
> 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
> )
> {
>
>
>
> Why are we not doing the isatty tests on Windows? We can and do use
> isatty on Windows elsewhere, so I'm a bit mystified about this.

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?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: use of pager on Windows psql
Date: 2008-05-17 22:36:45
Message-ID: 482F5DFD.4020107@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian wrote:
> Andrew Dunstan wrote:
>
>> psql's print.c contains this piece of code:
>>
>> /*
>> * PageOutput
>> *
>> * Tests if pager is needed and returns appropriate FILE pointer.
>> */
>> FILE *
>> 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
>> )
>> {
>>
>>
>>
>> Why are we not doing the isatty tests on Windows? We can and do use
>> isatty on Windows elsewhere, so I'm a bit mystified about this.
>>
>
> 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

cheers

andrew


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] use of pager on Windows psql
Date: 2008-05-17 23:36:06
Message-ID: 200805172336.m4HNa7G22034@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

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(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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

Attachment Content-Type Size
/rtmp/diff text/x-diff 1.7 KB

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] use of pager on Windows psql
Date: 2008-05-18 06:53:33
Message-ID: 482FD26D.5030603@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

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


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] use of pager on Windows psql
Date: 2008-05-18 13:49:45
Message-ID: 200805181349.m4IDnjO00591@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

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(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] use of pager on Windows psql
Date: 2008-05-18 14:06:17
Message-ID: 483037D9.1030900@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

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