Last change
on this file since 3298 was 3232, checked in by Bruno Cornec, 11 years ago |
- Update mindi-busybox to 1.21.1
|
-
Property svn:eol-style
set to
native
|
File size:
1.1 KB
|
Rev | Line | |
---|
[1765] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * Replacement for "stty size", which is awkward for shell script use.
|
---|
| 4 | * - Allows to request width, height, or both, in any order.
|
---|
| 5 | * - Does not complain on error, but returns width 80, height 24.
|
---|
| 6 | * - Size: less than 200 bytes
|
---|
| 7 | *
|
---|
| 8 | * Copyright (C) 2007 by Denys Vlasenko <vda.linux@googlemail.com>
|
---|
| 9 | *
|
---|
[2725] | 10 | * Licensed under GPLv2, see file LICENSE in this source tree.
|
---|
[1765] | 11 | */
|
---|
[3232] | 12 |
|
---|
| 13 | //usage:#define ttysize_trivial_usage
|
---|
| 14 | //usage: "[w] [h]"
|
---|
| 15 | //usage:#define ttysize_full_usage "\n\n"
|
---|
| 16 | //usage: "Print dimension(s) of stdin's terminal, on error return 80x25"
|
---|
| 17 |
|
---|
[1765] | 18 | #include "libbb.h"
|
---|
| 19 |
|
---|
[2725] | 20 | int ttysize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
| 21 | int ttysize_main(int argc UNUSED_PARAM, char **argv)
|
---|
[1765] | 22 | {
|
---|
[2725] | 23 | unsigned w, h;
|
---|
[1765] | 24 | struct winsize wsz;
|
---|
| 25 |
|
---|
| 26 | w = 80;
|
---|
| 27 | h = 24;
|
---|
| 28 | if (!ioctl(0, TIOCGWINSZ, &wsz)) {
|
---|
| 29 | w = wsz.ws_col;
|
---|
| 30 | h = wsz.ws_row;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[2725] | 33 | if (!argv[1]) {
|
---|
[1765] | 34 | printf("%u %u", w, h);
|
---|
| 35 | } else {
|
---|
| 36 | const char *fmt, *arg;
|
---|
| 37 |
|
---|
| 38 | fmt = "%u %u" + 3; /* "%u" */
|
---|
| 39 | while ((arg = *++argv) != NULL) {
|
---|
| 40 | char c = arg[0];
|
---|
| 41 | if (c == 'w')
|
---|
| 42 | printf(fmt, w);
|
---|
| 43 | if (c == 'h')
|
---|
| 44 | printf(fmt, h);
|
---|
| 45 | fmt = "%u %u" + 2; /* " %u" */
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
[2725] | 48 | bb_putchar('\n');
|
---|
[1765] | 49 | return 0;
|
---|
| 50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.