7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -472,9 +472,24 @@ rightsList(PsqlSettings *pset)
472
472
char listbuf [256 ];
473
473
int nColumns ;
474
474
int i ;
475
-
475
+ int usePipe = 0 ;
476
+ char * pagerenv ;
477
+ FILE * fout ;
476
478
PGresult * res ;
477
479
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
+
478
493
listbuf [0 ] = '\0' ;
479
494
strcat (listbuf , "SELECT relname, relacl " );
480
495
strcat (listbuf , "FROM pg_class, pg_user " );
@@ -485,26 +500,43 @@ rightsList(PsqlSettings *pset)
485
500
strcat (listbuf , " ORDER BY relname " );
486
501
if (!(res = PSQLexec (pset , listbuf )))
487
502
return -1 ;
488
-
503
+ /* first, print out the attribute names */
489
504
nColumns = PQntuples (res );
490
505
if (nColumns > 0 )
491
506
{
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
+
492
519
/* Display the information */
493
520
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" );
498
525
499
526
/* next, print out the instances */
500
527
for (i = 0 ; i < PQntuples (res ); i ++ )
501
528
{
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" );
505
532
}
506
- printf ( " +------------------+----------------------------------------------------+\n" );
533
+ fprintf ( fout , " +------------------+----------------------------------------------------+\n" );
507
534
PQclear (res );
535
+ if (usePipe )
536
+ {
537
+ pclose (fout );
538
+ pqsignal (SIGPIPE , SIG_DFL );
539
+ }
508
540
return (0 );
509
541
}
510
542
else
0 commit comments