/***********************************************************/ /* */ /* Power Management Program for Libretto V1.0 */ /* */ /* 1996/09/05 Masakazu Iizuka */ /* 1998/04/29 use SMI by S.Nomura */ /* 1998/05/25 Small Bug Fix by T.Ishioka */ /* */ /***********************************************************/ #undef HAVE_GETOPT_LONG #ifdef __linux__ #define HAVE_GETOPT_LONG 1 #endif #include #include #include #include #include #ifdef HAVE_GETOPT_LONG #include #endif #include #include #include #include "libapm.h" #ifndef CMOS_ACCESS #include "bios.h" #endif /* CMOS_ACCESS */ #undef DEBUG typedef struct { int powerup; /* Power-up Mode */ int standby; /* Standby Time */ int off; /* System Auto Off */ int panel; /* Panal Power On/Off */ int on; /* Alarm Power On */ char hour[3]; /* Alarm Power On (Hour) */ char min[3]; /* Alarm Power On (Minute) */ int lcd; /* LCD Power */ int vol; /* Beep Volume */ int suspend; /* Suspend or Hybernation */ } PMFLAG; char version[] = "1.0beta5"; PMFLAG cmos = { -1, -1, -1, -1, -1, "", "", -1, -1, -1 }; PMFLAG exec = { -1, -1, -1, -1, -1, "", "", -1, -1, -1 }; void get_status(void); void print_status(void); void set_powerup(void); void set_standby(void); void set_off(void); void set_panel(void); void set_on(void); void set_lcd(void); void usage(void); int time_conv(char *); #ifndef CMOS_ACCESS void set_vol(void); void set_suspend(void); void init(void); #endif /* CMOS_ACCESS */ int main(int argc, char *argv[]) { int r; char c; #ifdef HAVE_GETOPT_LONG struct option longopts[] = { { "Help", 0, 0, 'h' }, { "Version", 0, 0, 'v' }, { "PowerUp", 1, 0, 'P' }, { "StandbyTime", 1, 0, 'T' }, { "AutoOff", 1, 0, 'a' }, { "PanelSwitch", 1, 0, 'S' }, { "AlarmOn", 1, 0, 'A' }, { "LcdPower", 1, 0, 'L' }, #ifndef CMOS_ACCESS { "Volume", 1, 0, 'V' }, { "Off", 1, 0, 'O' }, #endif /* CMOS_ACCESS */ {0, 0, 0, 0} }; #endif if( 0 != geteuid() ){ printf("%s: Only root can execute !!\n", argv[0]); exit(-1); } #ifdef LIBRETTO r = islibretto(); if (r != 0){ printf("Only Use \"TOSHIBA Libretto20/50\"\n"); exit(0); } #endif /* LIBRETTO */ #ifndef CMOS_ACCESS init(); #endif /* CMOS_ACCESS */ get_status(); #ifdef HAVE_GETOPT_LONG while ((c = getopt_long(argc,argv, "hvP:T:a:S:A:L:V:O:", longopts, NULL)) != -1) { #else while ((c = getopt(argc,argv, "hvP:T:a:S:A:L:V:O:")) != -1) { #endif switch (c) { case 'h': usage(); break; case 'v': printf("version : %s\n", version); exit(0); break; case 'P': if (strcmp(optarg, "boot") == 0) exec.powerup = 0; if (strcmp(optarg, "hibernation") == 0) exec.powerup = 1; if (exec.powerup == -1) usage(); break; case 'T': #ifdef CMOS_ACCESS if (strcmp(optarg, "0") == 0) exec.standby = 0; if (strcmp(optarg, "5") == 0) exec.standby = 1; if (strcmp(optarg, "10") == 0) exec.standby = 2; if (strcmp(optarg, "15") == 0) exec.standby = 3; if (strcmp(optarg, "30") == 0) exec.standby = 4; if (strcmp(optarg, "45") == 0) exec.standby = 5; if (strcmp(optarg, "60") == 0) exec.standby = 6; if (strcmp(optarg, "unlimit") == 0) exec.standby = 7; #else if (strcmp(optarg, "0") == 0) exec.standby = TIME_00; if (strcmp(optarg, "5") == 0) exec.standby = TIME_05; if (strcmp(optarg, "10") == 0) exec.standby = TIME_10; if (strcmp(optarg, "15") == 0) exec.standby = TIME_15; if (strcmp(optarg, "30") == 0) exec.standby = TIME_30; if (strcmp(optarg, "45") == 0) exec.standby = TIME_45; if (strcmp(optarg, "60") == 0) exec.standby = TIME_60; if (strcmp(optarg, "unlimit") == 0) exec.standby = TIME_UNLIMIT; #endif /* CMOS_ACCESS */ if (exec.standby == -1) usage(); break; case 'a': #ifdef CMOS_ACCESS if (strcmp(optarg, "disable") == 0) exec.off = 0; if (strcmp(optarg, "10") == 0) exec.off = 1; if (strcmp(optarg, "20") == 0) exec.off = 2; if (strcmp(optarg, "30") == 0) exec.off = 3; if (strcmp(optarg, "40") == 0) exec.off = 4; if (strcmp(optarg, "50") == 0) exec.off = 5; if (strcmp(optarg, "60") == 0) exec.off = 6; #else if (strcmp(optarg, "disable") == 0) exec.off = TIME_00; if (strcmp(optarg, "10") == 0) exec.off = TIME_10; if (strcmp(optarg, "20") == 0) exec.off = TIME_20; if (strcmp(optarg, "30") == 0) exec.off = TIME_30; if (strcmp(optarg, "40") == 0) exec.off = TIME_40; if (strcmp(optarg, "50") == 0) exec.off = TIME_50; if (strcmp(optarg, "60") == 0) exec.off = TIME_60; #endif /* CMOS_ACCESS */ if (exec.off == -1) usage(); break; case 'S': if (strcmp(optarg, "disable") == 0) exec.panel = 0; if (strcmp(optarg, "enable") == 0) exec.panel = 1; if (exec.panel == -1) usage(); break; case 'A': if (strcmp(optarg, "disable") == 0) exec.on = 0; time_conv(optarg); if (exec.on == -1) usage(); break; case 'L': if (strcmp(optarg, "0") == 0) exec.lcd = 0; if (strcmp(optarg, "1") == 0) exec.lcd = 1; if (strcmp(optarg, "2") == 0) exec.lcd = 2; if (strcmp(optarg, "3") == 0) exec.lcd = 3; if (exec.lcd == -1) usage(); break; #ifndef CMOS_ACCESS case 'V': if (strcmp(optarg, "0") == 0) exec.vol = VOL_OFF; else if (strcmp(optarg, "1") == 0) exec.vol = VOL_LOW; else if (strcmp(optarg, "2") == 0) exec.vol = VOL_MID; else if (strcmp(optarg, "3") == 0) exec.vol = VOL_HIGH; else usage(); break; case 'O': if (strcmp(optarg, "suspend") == 0) exec.suspend = 0; else if (strcmp(optarg, "hibernation") == 0) exec.suspend = 1; else usage(); break; #endif /* CMOS_ACCESS */ case '?': usage(); break; default: break; } } #ifdef DEBUG printf("POWERUP:%d STANDBY:%d OFF:%d PANEL:%d ON:%d(%s:%s) LCD:%d\n", exec.powerup, exec.standby, exec.off, exec.panel, exec.on, exec.hour, exec.min, exec.lcd); #endif if (exec.powerup != -1) set_powerup(); if (exec.standby != -1) set_standby(); if (exec.off != -1) set_off(); if (exec.panel != -1) set_panel(); if (exec.on != -1) set_on(); if (exec.lcd != -1) set_lcd(); #ifndef CMOS_ACCESS if (exec.vol != -1) set_vol(); if (exec.suspend != -1) set_suspend(); #endif /* CMOS_ACCESS */ get_status(); print_status(); exit(0); } void usage(void) { #ifdef CMOS_ACCESS # ifdef HAVE_GETOPT_LONG printf("\n\ usage: libretto-config [-v --Version]\n\ [-h --Help]\n\ [-P --PowerUp {boot,hibernation}]\n\ [-T --StandbyTime {0,5,10,15,30,45,60,unlimit}]\n\ [-a --AutoOff {disable,10,20,30,40,50,60}]\n\ [-S --PanelSwitch {disable,enable}]\n\ [-A --AlarmOn {disable,