/*
***************************************************************************
* Get number of rows for current window.
+ * If stdout is not a terminal then use the value given by environment
+ * variable S_REPEAT_HEADER if existent.
*
* RETURNS:
* Number of rows.
int get_win_height(void)
{
struct winsize win;
+ char *e;
/*
* This default value will be used whenever STDOUT
- * is redirected to a pipe or a file
+ * is redirected to a pipe or a file and S_REPEAT_HEADER variable is not set
*/
int rows = 3600 * 24;
+ /* Get number of lines of current terminal */
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) != -1) {
if (win.ws_row > 2) {
rows = win.ws_row - 2;
}
}
+ /* STDOUT is not a terminal. Look for S_REPEAT_HEADER variable's value instead */
+ else if ((e = __getenv(ENV_REPEAT_HEADER)) != NULL) {
+ if (strspn(e, DIGITS) == strlen(e)) {
+ int v = atol(e);
+ if (v > 0) {
+ rows = v;
+ }
+ }
+ }
return rows;
}
#define ENV_TIME_DEFTM "S_TIME_DEF_TIME"
#define ENV_COLORS "S_COLORS"
#define ENV_COLORS_SGR "S_COLORS_SGR"
+#define ENV_REPEAT_HEADER "S_REPEAT_HEADER"
#define C_NEVER "never"
#define C_ALWAYS "always"