MCPcopy Create free account
hub / github.com/apache/cloudberry / PageOutput

Function PageOutput

src/fe_utils/print.c:2975–3019  ·  view source on GitHub ↗

* PageOutput * * Tests if pager is needed and returns appropriate FILE pointer. * * If the topt argument is NULL no pager is used. */

Source from the content-addressed store, hash-verified

2973 * If the topt argument is NULL no pager is used.
2974 */
2975FILE *
2976PageOutput(int lines, const printTableOpt *topt)
2977{
2978 /* check whether we need / can / are supposed to use pager */
2979 if (topt && topt->pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
2980 {
2981#ifdef TIOCGWINSZ
2982 unsigned short int pager = topt->pager;
2983 int min_lines = topt->pager_min_lines;
2984 int result;
2985 struct winsize screen_size;
2986
2987 result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
2988
2989 /* >= accounts for a one-line prompt */
2990 if (result == -1
2991 || (lines >= screen_size.ws_row && lines >= min_lines)
2992 || pager > 1)
2993#endif
2994 {
2995 const char *pagerprog;
2996 FILE *pagerpipe;
2997
2998 pagerprog = getenv("PSQL_PAGER");
2999 if (!pagerprog)
3000 pagerprog = getenv("PAGER");
3001 if (!pagerprog)
3002 pagerprog = DEFAULT_PAGER;
3003 else
3004 {
3005 /* if PAGER is empty or all-white-space, don't use pager */
3006 if (strspn(pagerprog, " \t\r\n") == strlen(pagerprog))
3007 return stdout;
3008 }
3009 disable_sigpipe_trap();
3010 pagerpipe = popen(pagerprog, "w");
3011 if (pagerpipe)
3012 return pagerpipe;
3013 /* if popen fails, silently proceed without pager */
3014 restore_sigpipe_trap();
3015 }
3016 }
3017
3018 return stdout;
3019}
3020
3021/*
3022 * ClosePager

Callers 9

print_aligned_textFunction · 0.85
IsPagerNeededFunction · 0.85
usageFunction · 0.85
slashUsageFunction · 0.85
helpVariablesFunction · 0.85
helpSQLFunction · 0.85
printHistoryFunction · 0.85
ExecQueryUsingCursorFunction · 0.85
exec_command_sf_svFunction · 0.85

Calls 2

disable_sigpipe_trapFunction · 0.85
restore_sigpipe_trapFunction · 0.85

Tested by

no test coverage detected