/* * call-seq: * io.winsize = [rows, columns] * * Tries to set console size. The effect depends on the platform and * the running environment. * * You must require 'io/console' to use this method. */ static VALUE console_set_winsize(VALUE io, VALUE size) { rb_io_t *fptr; rb_console_size_t ws; #if defined _WIN32 HANDLE wh; int newrow, newcol; #endif VALUE row, col, xpixel, ypixel; const VALUE *sz; int fd; GetOpenFile(io, fptr); size = rb_Array(size); rb_check_arity(RARRAY_LENINT(size), 2, 4); sz = RARRAY_CONST_PTR(size); row = sz[0], col = sz[1], xpixel = sz[2], ypixel = sz[3]; fd = GetWriteFD(fptr); #if defined TIOCSWINSZ ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0; #define SET(m) ws.ws_##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m) SET(row); SET(col); SET(xpixel); SET(ypixel); #undef SET if (!setwinsize(fd, &ws)) rb_sys_fail(0); #elif defined _WIN32 wh = (HANDLE)rb_w32_get_osfhandle(fd); #define SET(m) new##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m) SET(row); SET(col); #undef SET if (!NIL_P(xpixel)) (void)NUM2UINT(xpixel); if (!NIL_P(ypixel)) (void)NUM2UINT(ypixel); if (!GetConsoleScreenBufferInfo(wh, &ws)) { rb_syserr_fail(LAST_ERROR, "GetConsoleScreenBufferInfo"); } if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) || (ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) { if (!SetConsoleScreenBufferSize(wh, ws.dwSize)) { rb_syserr_fail(LAST_ERROR, "SetConsoleScreenBufferInfo"); } } ws.srWindow.Left = 0; ws.srWindow.Top = 0; ws.srWindow.Right = newcol; ws.srWindow.Bottom = newrow; if (!SetConsoleWindowInfo(wh, FALSE, &ws.srWindow)) { rb_syserr_fail(LAST_ERROR, "SetConsoleWindowInfo"); } #endif return io; }
/* * call-seq: * io.winsize = [rows, columns] * * Tries to set console size. The effect depends on the platform and * the running environment. * * You must require 'io/console' to use this method. */ static VALUE console_set_winsize(VALUE io, VALUE size) { rb_io_t *fptr; rb_console_size_t ws; #if defined _WIN32 HANDLE wh; int newrow, newcol; #endif VALUE row, col, xpixel, ypixel; #if defined TIOCSWINSZ int fd; #endif GetOpenFile(io, fptr); size = rb_Array(size); rb_scan_args((int)RARRAY_LEN(size), RARRAY_PTR(size), "22", &row, &col, &xpixel, &ypixel); #if defined TIOCSWINSZ fd = GetWriteFD(fptr); ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0; #define SET(m) ws.ws_##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m) SET(row); SET(col); SET(xpixel); SET(ypixel); #undef SET if (!setwinsize(fd, &ws)) rb_sys_fail(0); #elif defined _WIN32 wh = (HANDLE)rb_w32_get_osfhandle(GetReadFD(fptr)); newrow = (SHORT)NUM2UINT(row); newcol = (SHORT)NUM2UINT(col); if (!getwinsize(GetReadFD(fptr), &ws)) { rb_sys_fail("GetConsoleScreenBufferInfo"); } if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) || (ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) { if (!(SetConsoleScreenBufferSize(wh, ws.dwSize) || SET_LAST_ERROR)) { rb_sys_fail("SetConsoleScreenBufferInfo"); } } ws.srWindow.Left = 0; ws.srWindow.Top = 0; ws.srWindow.Right = newcol; ws.srWindow.Bottom = newrow; if (!(SetConsoleWindowInfo(wh, FALSE, &ws.srWindow) || SET_LAST_ERROR)) { rb_sys_fail("SetConsoleWindowInfo"); } #endif return io; }
static void cols(char *arg, struct termios *m) { setwinsize(-1, estrtonum(arg, 0, USHRT_MAX)); (void) m; }
static void rows(char *arg, struct termios *m) { setwinsize(estrtonum(arg, 0, USHRT_MAX), -1); (void) m; }
int main(int argc, char *argv[]) { int top, ch, iflag = 0, cflag = 0; char rc[PATH_MAX]; if(getuid() != 0) printf("%% Functionality limited without root privilege.\n"); pid = getpid(); while ((ch = getopt(argc, argv, "c:i:v")) != -1) switch (ch) { case 'c': cflag = 1; strlcpy(rc, optarg, PATH_MAX); break; case 'i': iflag = 1; strlcpy(rc, optarg, PATH_MAX); break; case 'v': verbose = 1; break; default: usage(); } argc -= optind; argv += optind; if (cflag && iflag) usage(); if (argc > 0) usage(); if (iflag) rmtemp(SQ3DBFILE); printf("%% NSH v%s\n", vers); /* create temporal tables (if they aren't already there) */ if (db_create_table_rtables() < 0) printf("%% database rtables creation failed\n"); if (db_create_table_flag_x("ctl") < 0) printf("%% database ctl creation failed\n"); if (db_create_table_flag_x("dhcrelay") < 0) printf("%% database dhcrelay creation failed\n"); if (db_create_table_flag_x("ipv6linklocal") < 0) printf("%% database ipv6linklocal creation failed\n"); if (db_create_table_flag_x("lladdr") < 0) printf("%% database lladdr creation failed\n"); if (db_create_table_flag_x("rtadvd") < 0) printf("%% database rtadvd creation failed\n"); if (db_create_table_flag_x("authkey") < 0) printf("%% database authkey creation failed\n"); if (db_create_table_flag_x("peerkey") < 0) printf("%% database peerkey creation failed\n"); if (iflag) { /* * Interpret config file and exit */ char *argv_demote[] = { "group", "carp", "carpdemote", "128" }; char *argv_restore[] = { "no", "group", "carp", "carpdemote", "128" }; priv = 1; /* * Set carp group carpdemote to 128 during initialization */ group(nitems(argv_demote), argv_demote); cmdrc(rc); /* * Initialization over */ group(nitems(argv_restore), argv_restore); exit(0); } if (cflag) { /* * Interpret command file and exit */ priv = 1; cmdrc(rc); exit(0); } top = setjmp(toplevel) == 0; if (top) { (void)signal(SIGWINCH, setwinsize); (void)signal(SIGINT, (sig_t)intr); (void)setwinsize(0); } else putchar('\n'); for (;;) { command(); top = 1; } /* NOTREACHED */ return 0; }