/*
 * vtchange: Change screen size.
 *
 * Ichiya Kamiki <kamiki@geocities.com>
 *
 *  Copyright (C) 1999 Ichiya Kamiki
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 *  [usage] vtchange width height
 *
 *  $B%9%/%j!<%s$rJ8;z?t(B width, $B9T?t(B height $B$N$b$N$K@ZBX$($k!#(B
 *  
 *  kernel config option $B$N(B 'Allow ... boundary' $B$,(B 'y' $B$N(B kernel $B$N>l9g!"(B
 *  $BJ8;z?t(B 32 $B!A(B 106, $B9T?t(B 5 $B!A(B 30.
 *  ($B$?$@$7J8;z?t$,(B 80 $B$r1[$($k>l9g$O(B 20 $B9T0J2<(B)
 *
 *  kernel config option $B$N(B 'Allow ... boundary' $B$,(B 'n' $B$N(B kernel $B$N>l9g!"(B
 *  $BJ8;z?t(B 32 $B!A(B 80, $B9T?t(B 5 $B!A(B 30.
 *
 *  $B$N%3%s%=!<%k$,2DG=!#(B
 *  $B$^$?!"J8;z%5%$%:!"M>Gr$O<+F0E*$KD4@0$5$l$k!#(B
 *  $BF1$8J8;z?t!"9T?t$G$b(B 'Allow drawing fonts without 4 pixels boundary' $B$NM-L5$K(B
 *  $B$h$C$F%3%s%=!<%k$O0[$J$k!#$b$A$m$s(B 'y' $B$G$N$[$&$,8+3]$1$OH~$7$$798~$K$"$k!#(B
 *
 *  kernel-0418 $B$NCJ3,$G$N@)8B;v9`(B:
 *
 *   o  20 $B9T$r1[$($k%3%s%=!<%k$G$O!"F|K\8l$O;H$($J$$!#(B
 *   o  $BJ8;z$NOF!"2<$J$I$KM>Gr$,$G$-$k%3%s%=!<%k(B(ex. 91x20) $B$G$O(B
 *      $B@ZBX$(D>8e$OM>GrItJ,$K%4%_$,;D$k(B($BE,Ev$K%9%/%m!<%k$5$;$l$P>C$($k(B)$B!#(B
 *
 */
/*
 * $B%a%b(B:
 * ioctl(*, VT_RESIZE, *) $B$O(B PocketLinux $B8GM-$N5!G=$G$J$/!"(BLinux kernel $B$K(B
 * $B$b$H$b$HHw$o$C$F$$$?5!9=$G!"$3$l$rC!$/DL>o$N%W%m%0%i%`$,J,$+$i$J$+$C$?$?$a(B
 * (vtchange $B$,(B)$B=q$+$l$?$@$1$G$"$k!#(Bbinutil $B$H$+$=$N$?$0$$$NCf$KF1Ey0J>e$N5!G=(B
 * $B$r$b$D%W%m%0%i%`$,$-$C$H$"$k$K0c$$$J$$$H;W$&!#(B
 *
 */

#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/vt.h>

int main(int argc, char* argv[]){
    struct vt_sizes arg;
    int x, y;

    if(argc != 3){
	printf("[usage] %s width height\n", argv[0]);
	exit(0);
    }
    x = atoi(argv[1]);
    y = atoi(argv[2]);
    if( (32 <= x) && (x <= 106) &&
        ( 5 <= y) && (y <= 30)    ){
	arg.v_cols = x;
	arg.v_rows = y;
	if(ioctl(0, VT_RESIZE, &arg)){
	    perror("ioctl");
	    return 1;
	}
    }
    return 0;
}
