add keylock option

reverse-branch
martin 18 years ago
parent 2eda6156bb
commit 1e3e955979
  1. 1
      README
  2. 20
      clock.c

@ -1,5 +1,6 @@
tty-clock usage : tty-clock -[option] -[option] <arg> tty-clock usage : tty-clock -[option] -[option] <arg>
-s, --second Show seconds -s, --second Show seconds
-b, --block Lock the keyboard\n\
-t, --tw Set the hour in 12h format -t, --tw Set the hour in 12h format
-x <integer> Set the clock to X -x <integer> Set the clock to X
-y <integer> Set the clock to Y -y <integer> Set the clock to Y

@ -26,6 +26,7 @@
#define printh() printf("tty-clock usage : tty-clock -[option] -[option] <arg>\n\n\ #define printh() printf("tty-clock usage : tty-clock -[option] -[option] <arg>\n\n\
-s, --second Show seconds\n\ -s, --second Show seconds\n\
-b, --block Lock the keyboard\n\
-t, --tw Set the hour in 12h format\n\ -t, --tw Set the hour in 12h format\n\
-x <integer> Set the clock to X\n\ -x <integer> Set the clock to X\n\
-y <integer> Set the clock to Y\n\ -y <integer> Set the clock to Y\n\
@ -70,6 +71,7 @@ static struct option long_options[] ={
typedef struct { typedef struct {
bool second; bool second;
bool twelve; bool twelve;
bool keylock;
} OPTIONS; } OPTIONS;
OPTIONS option; OPTIONS option;
@ -219,7 +221,9 @@ arrange_clock(int h1, int h2,
/* ********************* */ /* ********************* */
void void
check_key(void) { check_key(int keylock) {
if (keylock) {
int c; int c;
c = getch(); c = getch();
switch(c) { switch(c) {
@ -253,7 +257,7 @@ check_key(void) {
break; break;
case 's': case 's':
case 'S': case 'S':
if(!option.second ){ if(!option.second){
SCHANGE = 0; SCHANGE = 0;
clear(); clear();
option.second = 1; option.second = 1;
@ -279,6 +283,7 @@ check_key(void) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
} }
}
} }
/* ********************* */ /* ********************* */
@ -287,6 +292,7 @@ check_key(void) {
void void
get_time(void) { get_time(void) {
int ihour; int ihour;
tm = localtime(&lt); tm = localtime(&lt);
lt = time(NULL); lt = time(NULL);
@ -344,17 +350,18 @@ run(void) {
int int
main(int argc,char **argv) { main(int argc,char **argv) {
int c; int c;
option.keylock = 1;
static struct option long_options[] ={ static struct option long_options[] ={
{"help", 0, NULL, 'h'}, {"help", 0, NULL, 'h'},
{"version", 0, NULL, 'v'}, {"version", 0, NULL, 'v'},
{"info", 0, NULL, 'i'}, {"info", 0, NULL, 'i'},
{"second", 0, NULL, 's'}, {"second", 0, NULL, 's'},
{"twelve", 0, NULL, 't'}, {"twelve", 0, NULL, 't'},
{"block", 0, NULL, 'b'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
while ((c = getopt_long(argc,argv,"tx:y:vsih", while ((c = getopt_long(argc,argv,"tx:y:vsbih",
long_options,NULL)) != -1) { long_options,NULL)) != -1) {
switch(c) { switch(c) {
case 'h': case 'h':
@ -391,6 +398,9 @@ main(int argc,char **argv) {
case 't': case 't':
option.twelve = 1; option.twelve = 1;
break; break;
case 'b':
option.keylock = 0;
break;
} }
} }
@ -404,7 +414,7 @@ main(int argc,char **argv) {
while(1) { while(1) {
usleep(10000); usleep(10000);
check_key(); check_key(option.keylock);
run(); run();
} }
endwin(); endwin();

Loading…
Cancel
Save