int main(int argc, char **argv){ int c; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); assert(ttyclock != NULL); memset(ttyclock, 0, sizeof(ttyclock_t)); ttyclock->option.date = True; /* Date format */ ttyclock->option.format = malloc(sizeof(char) * 100); /* Default date format */ strncpy(ttyclock->option.format, "%F", 100); /* Default color */ ttyclock->option.color = COLOR_RED; /* Default delay */ ttyclock->option.delay = 1; /* 1FPS */ ttyclock->option.nsdelay = 0; /* -0FPS */ ttyclock->option.blink = False; /* Never show seconds */ ttyclock->option.second = False; /* Hide the date */ ttyclock->option.date = False; atexit(cleanup); while ((c = getopt(argc, argv, "ivcbrhBxnC:d:T:a:")) != -1){ switch(c) { case 'h': default: print_usage(); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy ([email protected]), Grey ([email protected])"); exit(EXIT_SUCCESS); break; case 'v': puts("TTY-Clock 2 © devel version"); exit(EXIT_SUCCESS); break; case 'c': ttyclock->option.center = True; break; case 'b': ttyclock->option.bold = True; break; case 'C': if(atoi(optarg) >= 0 && atoi(optarg) < 8) ttyclock->option.color = atoi(optarg); break; case 'r': ttyclock->option.rebound = True; break; case 'd': if(atol(optarg) >= 0 && atol(optarg) < 100) ttyclock->option.delay = atol(optarg); break; case 'B': ttyclock->option.blink = True; break; case 'a': if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.nsdelay = atol(optarg); break; case 'x': ttyclock->option.box = True; break; case 'T': { struct stat sbuf; if (stat(optarg, &sbuf) == -1) { fprintf(stderr, "tty-clock: error: couldn't stat '%s': %s.\n", optarg, strerror(errno)); exit(EXIT_FAILURE); } else if (!S_ISCHR(sbuf.st_mode)) { fprintf(stderr, "tty-clock: error: '%s' doesn't appear to be a character device.\n", optarg); exit(EXIT_FAILURE); } else { if (ttyclock->tty) free(ttyclock->tty); ttyclock->tty = strdup(optarg); }} break; case 'n': ttyclock->option.noquit = True; break; } } /* Set the default minutes to 25 */ start_minutes = DEFAULT_TIME; /* Check if short or long break */ if (optind < argc){ char *argument = argv[optind]; if (!strcmp(argument, "short")){ start_minutes = SHORT_BREAK; }else if (!strcmp(argument, "long")){ start_minutes = LONG_BREAK; }else{ printf("Command not recognized\n"); print_usage(); exit(EXIT_FAILURE); } } init(); attron(A_BLINK); while(ttyclock->running){ clock_rebound(); update_hour(); draw_clock(); key_event(); } endwin(); return 0; }
int main(int argc, char **argv) { int c; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); ttyclock->option.date = True; /* Date format */ ttyclock->option.format = malloc(sizeof(char) * 100); /* Default date format */ strncpy(ttyclock->option.format, "%a %d %b %Y", 100); /* Default color */ ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */ /* Default bottom pos */ ttyclock->option.bottom = False; /* Default delay */ ttyclock->option.delay = 40000000; /* 25FPS */ /* Default blink */ ttyclock->option.blink = False; while ((c = getopt(argc, argv, "tvsrcbihf:DBd:C:")) != -1) { switch(c) { case 'h': default: printf("usage : tty-clock [-scbtrvihDB] [-C [0-7]] [-f format] \n" " -s Show seconds \n" " -c Set the clock at the center of the terminal \n" " -b Set the clock at the bottom of the terminal \n" " -C [0-7] Set the clock color \n" " -t Set the hour in 12h format \n" " -r Do rebound the clock \n" " -f format Set the date format \n" " -v Show tty-clock version \n" " -i Show some info about tty-clock \n" " -h Show this page \n" " -d delay Set the delay between two redraws of the clock \n" " -D Hide date \n" " -B Enable blinking colon \n"); free(ttyclock); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy ([email protected])"); free(ttyclock); free(ttyclock->option.format); exit(EXIT_SUCCESS); break; case 'v': puts("TTY-Clock 2 © devel version"); free(ttyclock); free(ttyclock->option.format); exit(EXIT_SUCCESS); break; case 's': ttyclock->option.second = True; break; case 'c': ttyclock->option.center = True; break; case 'b': ttyclock->option.bottom = True; break; case 'C': if(atoi(optarg) >= 0 && atoi(optarg) < 8) ttyclock->option.color = atoi(optarg); break; case 't': ttyclock->option.twelve = True; break; case 'r': ttyclock->option.rebound = True; break; case 'f': strncpy(ttyclock->option.format, optarg, 100); break; case 'd': if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.delay = atol(optarg); break; case 'D': ttyclock->option.date = False; break; case 'B': ttyclock->option.blink = True; break; } } init(); while(ttyclock->running) { clock_rebound(); update_hour(); draw_clock(); key_event(); } free(ttyclock); free(ttyclock->option.format); endwin(); return 0; }
int main(int argc, char **argv) { int c; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); assert(ttyclock != NULL); memset(ttyclock, 0, sizeof(ttyclock_t)); /* Date format */ ttyclock->option.format = malloc(sizeof(char) * 100); /* Default date format */ strncpy(ttyclock->option.format, "%F", 100); /* Default color */ ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */ /* Default delay */ ttyclock->option.delay = 40000000; /* 25FPS */ atexit(cleanup); while ((c = getopt(argc, argv, "tT:nvsSrcihbf:d:C:")) != -1) { switch(c) { case 'h': default: printf("usage : tty-clock [-sSbctrnvih] [-C [0-7]] [-f format] [-d delay] [-T tty] \n" " -s Show seconds \n" " -S Screensaver mode \n" " -b Show box \n" " -c Set the clock at the center of the terminal \n" " -C [0-7] Set the clock color \n" " -t Set the hour in 12h format \n" " -T tty Display the clock on the specified terminal \n" " -r Do rebound the clock \n" " -f format Set the date format \n" " -n Don't quit on keypress \n" " -v Show tty-clock version \n" " -i Show some info about tty-clock \n" " -h Show this page \n" " -d delay Set the delay between two redraws of the clock \n"); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy ([email protected])"); exit(EXIT_SUCCESS); break; case 'v': puts("TTY-Clock 2 © devel version"); exit(EXIT_SUCCESS); break; case 's': ttyclock->option.second = True; break; case 'S': ttyclock->option.screensaver = True; break; case 'c': ttyclock->option.center = True; break; case 'C': if(atoi(optarg) >= 0 && atoi(optarg) < 8) ttyclock->option.color = atoi(optarg); break; case 't': ttyclock->option.twelve = True; break; case 'r': ttyclock->option.rebound = True; break; case 'f': strncpy(ttyclock->option.format, optarg, 100); break; case 'd': if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.delay = atol(optarg); break; case 'b': ttyclock->option.box = True; break; case 'T': { struct stat sbuf; if (stat(optarg, &sbuf) == -1) { fprintf(stderr, "tty-clock: error: couldn't stat '%s': %s.\n", optarg, strerror(errno)); exit(EXIT_FAILURE); } else if (!S_ISCHR(sbuf.st_mode)) { fprintf(stderr, "tty-clock: error: '%s' doesn't appear to be a character device.\n", optarg); exit(EXIT_FAILURE); } else { if (ttyclock->tty) free(ttyclock->tty); ttyclock->tty = strdup(optarg); } } break; case 'n': ttyclock->option.noquit = True; break; } } init(); while(ttyclock->running) { clock_rebound(); update_hour(); draw_clock(); key_event(); } endwin(); return 0; }