77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.124 1998/01/05 13:56:05 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.125 1998/01/09 19:34:38 momjian Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -472,9 +472,24 @@ rightsList(PsqlSettings *pset)
472472char listbuf [256 ];
473473int nColumns ;
474474int i ;
475-
475+ int usePipe = 0 ;
476+ char * pagerenv ;
477+ FILE * fout ;
476478PGresult * res ;
477479
480+ #ifdef TIOCGWINSZ
481+ if (pset -> notty == 0 &&
482+ (ioctl (fileno (stdout ),TIOCGWINSZ ,& screen_size )== -1 ||
483+ screen_size .ws_col == 0 ||
484+ screen_size .ws_row == 0 ))
485+ {
486+ #endif
487+ screen_size .ws_row = 24 ;
488+ screen_size .ws_col = 80 ;
489+ #ifdef TIOCGWINSZ
490+ }
491+ #endif
492+
478493listbuf [0 ]= '\0' ;
479494strcat (listbuf ,"SELECT relname, relacl " );
480495strcat (listbuf ,"FROM pg_class, pg_user " );
@@ -485,26 +500,43 @@ rightsList(PsqlSettings *pset)
485500strcat (listbuf ," ORDER BY relname " );
486501if (!(res = PSQLexec (pset ,listbuf )))
487502return -1 ;
488-
503+ /* first, print out the attribute names */
489504nColumns = PQntuples (res );
490505if (nColumns > 0 )
491506{
507+ if (pset -> notty == 0 &&
508+ (pagerenv = getenv ("PAGER" ))&&
509+ pagerenv [0 ]!= '\0' &&
510+ screen_size .ws_row <=nColumns + 7 &&
511+ (fout = popen (pagerenv ,"w" )))
512+ {
513+ usePipe = 1 ;
514+ pqsignal (SIGPIPE ,SIG_IGN );
515+ }
516+ else
517+ fout = stdout ;
518+
492519/* Display the information */
493520
494- printf ( "\nDatabase = %s\n" ,PQdb (pset -> db ));
495- printf ( " +------------------+----------------------------------------------------+\n" );
496- printf ( " | Relation | Grant/Revoke Permissions |\n" );
497- printf ( " +------------------+----------------------------------------------------+\n" );
521+ fprintf ( fout , "\nDatabase = %s\n" ,PQdb (pset -> db ));
522+ fprintf ( fout , " +------------------+----------------------------------------------------+\n" );
523+ fprintf ( fout , " | Relation | Grant/Revoke Permissions |\n" );
524+ fprintf ( fout , " +------------------+----------------------------------------------------+\n" );
498525
499526/* next, print out the instances */
500527for (i = 0 ;i < PQntuples (res );i ++ )
501528{
502- printf ( " | %-16.16s" ,PQgetvalue (res ,i ,0 ));
503- printf ( " | %-50.50s | " ,PQgetvalue (res ,i ,1 ));
504- printf ( "\n" );
529+ fprintf ( fout , " | %-16.16s" ,PQgetvalue (res ,i ,0 ));
530+ fprintf ( fout , " | %-50.50s | " ,PQgetvalue (res ,i ,1 ));
531+ fprintf ( fout , "\n" );
505532}
506- printf ( " +------------------+----------------------------------------------------+\n" );
533+ fprintf ( fout , " +------------------+----------------------------------------------------+\n" );
507534PQclear (res );
535+ if (usePipe )
536+ {
537+ pclose (fout );
538+ pqsignal (SIGPIPE ,SIG_DFL );
539+ }
508540return (0 );
509541}
510542else