File: Size.xs

package info (click to toggle)
libterm-size-perl 0.209-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 100 kB
  • sloc: perl: 10; makefile: 3
file content (51 lines) | stat: -rw-r--r-- 821 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifdef __cplusplus
extern "C" {
#endif

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#ifndef _AIX
#include <sys/termios.h>
#else
#include <termios.h>
#endif

#ifdef __cplusplus
}
#endif

MODULE = Term::Size		PACKAGE = Term::Size

PROTOTYPES: DISABLE

void
chars( f = PerlIO_stdin() )
	PerlIO *f;

	PREINIT:
	struct winsize w = { 0, 0, 0, 0 };

	PPCODE:
	if (ioctl(PerlIO_fileno(f), TIOCGWINSZ, &w) == -1)
		XSRETURN(0);

	XPUSHs(sv_2mortal(newSViv(w.ws_col)));
	if (GIMME != G_SCALAR)
		XPUSHs(sv_2mortal(newSViv(w.ws_row)));

void
pixels( f = PerlIO_stdin() )
	PerlIO *f;

	PREINIT:
	struct winsize w = { 0, 0, 0, 0 };

	PPCODE:
	if (ioctl(PerlIO_fileno(f), TIOCGWINSZ, &w) == -1)
		XSRETURN(0);

	XPUSHs(sv_2mortal(newSViv(w.ws_xpixel)));
	if (GIMME != G_SCALAR)
		XPUSHs(sv_2mortal(newSViv(w.ws_ypixel)));