| 21 | #define MIN_TOTAL_WIDTH 50 |
| 22 | |
| 23 | static unsigned int get_columns(void) |
| 24 | { |
| 25 | int ws_col = 0; |
| 26 | const char *env = getenv("COLUMNS"); |
| 27 | |
| 28 | if (env) |
| 29 | ws_col = atoi(env); |
| 30 | |
| 31 | #ifdef TIOCGWINSZ |
| 32 | if (!ws_col) |
| 33 | { |
| 34 | struct winsize w; |
| 35 | if (ioctl(0, TIOCGWINSZ, &w) != -1) |
| 36 | ws_col = w.ws_col; |
| 37 | } |
| 38 | #endif |
| 39 | if (!ws_col) |
| 40 | ws_col = 80; |
| 41 | |
| 42 | return ws_col; |
| 43 | } |
| 44 | |
| 45 | /* Return number of chars of words to put on this line. |
| 46 | * Prefix is set to number to skip at start, maxlen is max width, returns |