コード例 #1
0
ファイル: console.c プロジェクト: takuto-h/ruby
/*
 * call-seq:
 *   io.getch(min: nil, time: nil)       -> char
 *
 * Reads and returns a character in raw mode.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_getch(int argc, VALUE *argv, VALUE io)
{
    rawmode_arg_t opts, *optp = rawmode_opt(argc, argv, &opts);
    return ttymode(io, getc_call, set_rawmode, optp);
}
コード例 #2
0
ファイル: console.c プロジェクト: takuto-h/ruby
/*
 * call-seq:
 *   io.noecho {|io| }
 *
 * Yields +self+ with disabling echo back.
 *
 *   STDIN.noecho(&:gets)
 *
 * will read and return a line without echo back.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_noecho(VALUE io)
{
    return ttymode(io, rb_yield, set_noecho, NULL);
}
コード例 #3
0
ファイル: console.c プロジェクト: takuto-h/ruby
/*
 * call-seq:
 *   io.raw(min: nil, time: nil) {|io| }
 *
 * Yields +self+ within raw mode.
 *
 *   STDIN.raw(&:gets)
 *
 * will read and return a line without echo back and line editing.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_raw(int argc, VALUE *argv, VALUE io)
{
    rawmode_arg_t opts, *optp = rawmode_opt(argc, argv, &opts);
    return ttymode(io, rb_yield, set_rawmode, optp);
}
コード例 #4
0
ファイル: console.c プロジェクト: takuto-h/ruby
/*
 * call-seq:
 *   io.cooked {|io| }
 *
 * Yields +self+ within cooked mode.
 *
 *   STDIN.cooked(&:gets)
 *
 * will read and return a line with echo back and line editing.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_cooked(VALUE io)
{
    return ttymode(io, rb_yield, set_cookedmode, NULL);
}
コード例 #5
0
ファイル: console.c プロジェクト: Artoria/ruby-1.9.3-p0
/*
 * call-seq:
 *   io.getch       -> char
 *
 * Reads and returns a character in raw mode.
 */
static VALUE
console_getch(VALUE io)
{
    return ttymode(io, getc_call, set_rawmode);
}
コード例 #6
0
ファイル: console.c プロジェクト: Artoria/ruby-1.9.3-p0
/*
 * call-seq:
 *   io.raw {|io| }
 *
 * Yields +self+ within raw mode.
 *
 *   STDIN.raw(&:gets)
 *
 * will read and return a line with echo back and line editing.
 */
static VALUE
console_raw(VALUE io)
{
    return ttymode(io, rb_yield, set_rawmode);
}
コード例 #7
0
int
main(int argc, char **argv)
{
	int ch, ret;
	int fileflag, ttyflag, vnodeflag;
	char buf[_POSIX2_LINE_MAX];
	const char *opts;

	fileflag = swapflag = ttyflag = vnodeflag = 0;

	/* We will behave like good old swapinfo if thus invoked */
	opts = strrchr(argv[0],'/');
	if (opts)
		opts++;
	else
		opts = argv[0];
	if (!strcmp(opts,"swapinfo")) {
		swapflag = 1;
		opts = "ghkmM:N:";
		usagestr = "swapinfo [-ghkm] [-M core] [-N system]";
	} else {
		opts = "TM:N:fhiknstv";
		usagestr = "pstat [-Tfhknst] [-M core] [-N system]";
	}

	while ((ch = getopt(argc, argv, opts)) != -1) {
		switch (ch) {
		case 'f':
			fileflag = 1;
			break;
		case 'g':
			if (setenv("BLOCKSIZE", "1G", 1) == -1)
				warn("setenv: cannot set BLOCKSIZE=1K");
			break;
		case 'k':
			if (setenv("BLOCKSIZE", "1K", 1) == -1)
				warn("setenv: cannot set BLOCKSIZE=1K");
			break;
		case 'm':
			if (setenv("BLOCKSIZE", "1M", 1) == -1)
				warn("setenv: cannot set BLOCKSIZE=1K");
			break;
		case 'h':
			humanflag = 1;
			break;
		case 'M':
			memf = optarg;
			break;
		case 'N':
			nlistf = optarg;
			break;
		case 'n':
			usenumflag = 1;
			break;
		case 's':
			++swapflag;
			break;
		case 'T':
			totalflag = 1;
			break;
		case 't':
			ttyflag = 1;
			break;
		case 'v':
		case 'i':		/* Backward compatibility. */
			errx(1, "vnode mode not supported");
#if 0
			vnodeflag = 1;
			break;
#endif
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	/*
	 * Discard setgid privileges if not the running kernel so that bad
	 * guys can't print interesting stuff from kernel memory.
	 */
	if (nlistf != NULL || memf != NULL)
		setgid(getgid());

	if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL)
		errx(1, "kvm_openfiles: %s", buf);
#ifdef USE_KCORE
	if (kcore_wrapper_open(nlistf, memf, buf))
		errx(1, "kcore_open: %s", buf);
#endif
	if ((ret = kvm_nlist(kd, nl)) != 0) {
		size_t i;
		int quit = 0;

		if (ret == -1)
			errx(1, "kvm_nlist: %s", kvm_geterr(kd));
		for (i = 0; i < NL_LAST_MANDATORY; i++) {
			if (!nl[i].n_value) {
				quit = 1;
				warnx("undefined symbol: %s", nl[i].n_name);
			}
		}
		if (quit)
			exit(1);
	}
	if (!(fileflag | vnodeflag | ttyflag | swapflag | totalflag))
		usage();
	if (fileflag || totalflag)
		filemode();
	if (vnodeflag)
		vnodemode();
	if (ttyflag)
		ttymode();
	if (swapflag || totalflag)
		swapmode();
	exit (0);
}
コード例 #8
0
ファイル: pstat.c プロジェクト: mulichao/freebsd
int
main(int argc, char *argv[])
{
	int ch, quit, ret;
	int fileflag, ttyflag;
	unsigned int i;
	char buf[_POSIX2_LINE_MAX];
	const char *opts;

	fileflag = swapflag = ttyflag = 0;

	/* We will behave like good old swapinfo if thus invoked */
	opts = strrchr(argv[0], '/');
	if (opts)
		opts++;
	else
		opts = argv[0];
	if (!strcmp(opts, "swapinfo")) {
		swapflag = 1;
		opts = "ghkmM:N:";
		usagestr = "swapinfo [-ghkm] [-M core [-N system]]";
	} else {
		opts = "TM:N:fghkmnst";
		usagestr = "pstat [-Tfghkmnst] [-M core [-N system]]";
	}

	while ((ch = getopt(argc, argv, opts)) != -1)
		switch (ch) {
		case 'f':
			fileflag = 1;
			break;
		case 'g':
			setenv("BLOCKSIZE", "1G", 1);
			break;
		case 'h':
			humanflag = 1;
			break;
		case 'k':
			setenv("BLOCKSIZE", "1K", 1);
			break;
		case 'm':
			setenv("BLOCKSIZE", "1M", 1);
			break;
		case 'M':
			memf = optarg;
			break;
		case 'N':
			nlistf = optarg;
			break;
		case 'n':
			usenumflag = 1;
			break;
		case 's':
			++swapflag;
			break;
		case 'T':
			totalflag = 1;
			break;
		case 't':
			ttyflag = 1;
			break;
		default:
			usage();
		}

	/*
	 * Initialize symbol names list.
	 */
	for (i = 0; i < NNAMES; i++)
		nl[namelist[i].order].n_name = strdup(namelist[i].name);

	if (memf != NULL) {
		kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf);
		if (kd == NULL)
			errx(1, "kvm_openfiles: %s", buf);
		if ((ret = kvm_nlist(kd, nl)) != 0) {
			if (ret == -1)
				errx(1, "kvm_nlist: %s", kvm_geterr(kd));
			quit = 0;
			for (i = 0; nl[i].n_name[0] != '\0'; ++i)
				if (nl[i].n_value == 0) {
					quit = 1;
					warnx("undefined symbol: %s",
					    nl[i].n_name);
				}
			if (quit)
				exit(1);
		}
	}
	if (!(fileflag | ttyflag | swapflag | totalflag))
		usage();
	if (fileflag || totalflag)
		filemode();
	if (ttyflag)
		ttymode();
	if (swapflag || totalflag)
		swapmode();
	exit (0);
}
コード例 #9
0
ファイル: console.c プロジェクト: DashYang/sim
static VALUE
getpass_call(VALUE io)
{
    return ttymode(io, rb_io_gets, set_noecho, NULL);
}