pax_global_header00006660000000000000000000000064130365652640014524gustar00rootroot0000000000000052 comment=8868f3ed2312f7cd887613864cd14c0d12260aa9 tty-clock-2.3/000077500000000000000000000000001303656526400133015ustar00rootroot00000000000000tty-clock-2.3/.gitignore000066400000000000000000000000321303656526400152640ustar00rootroot00000000000000tty-clock tty-clock.dSYM/ tty-clock-2.3/Makefile000066400000000000000000000025101303656526400147370ustar00rootroot00000000000000#TTY-Clock MakeFile #Under BSD License #See clock.c for the license detail. SRC = ttyclock.c CC ?= gcc BIN = tty-clock PREFIX ?= /usr/local INSTALLPATH = ${DESTDIR}${PREFIX}/bin MANPATH = ${DESTDIR}${PREFIX}/share/man/man1 ifeq ($(shell sh -c 'which ncurses5-config>/dev/null 2>/dev/null && echo y'), y) CFLAGS += -Wall -g $$(ncurses5-config --cflags) LDFLAGS += $$(ncurses5-config --libs) else ifeq ($(shell sh -c 'which ncursesw5-config>/dev/null 2>/dev/null && echo y'), y) CFLAGS += -Wall -g $$(ncursesw5-config --cflags) LDFLAGS += $$(ncursesw5-config --libs) else CFLAGS += -Wall -g $$(pkg-config --cflags ncurses) LDFLAGS += $$(pkg-config --libs ncurses) endif tty-clock : ${SRC} @echo "building ${SRC}" ${CC} ${CFLAGS} ${SRC} -o ${BIN} ${LDFLAGS} install : ${BIN} @echo "installing binary file to ${INSTALLPATH}/${BIN}" @mkdir -p ${INSTALLPATH} @cp ${BIN} ${INSTALLPATH} @chmod 0755 ${INSTALLPATH}/${BIN} @echo "installing manpage to ${MANPATH}/${BIN}.1" @mkdir -p ${MANPATH} @cp ${BIN}.1 ${MANPATH} @chmod 0644 ${MANPATH}/${BIN}.1 @echo "installed" uninstall : @echo "uninstalling binary file (${INSTALLPATH})" @rm -f ${INSTALLPATH}/${BIN} @echo "uninstalling manpage (${MANPATH})" @rm -f ${MANPATH}/${BIN}.1 @echo "${BIN} uninstalled" clean : @echo "cleaning ${BIN}" @rm -f ${BIN} @echo "${BIN} cleaned" tty-clock-2.3/README000066400000000000000000000025431303656526400141650ustar00rootroot00000000000000usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] -s Show seconds -S Screensaver mode -x Show box -c Set the clock at the center of the terminal -C [0-7] Set the clock color -b Use bold colors -t Set the hour in 12h format -u Use UTC time -T tty Display the clock on the specified terminal -r Do rebound the clock -f format Set the date format -n Don't quit on keypress -v Show tty-clock version -i Show some info about tty-clock -h Show this page -D Hide date -B Enable blinking colon -d delay Set the delay between two redraws of the clock. Default 1s. -a nsdelay Additional delay between two redraws in nanoseconds. Default 0ns. tty-clock-2.3/tty-clock.1000066400000000000000000000062401303656526400152760ustar00rootroot00000000000000.\" This manpage was written by Carla Valenti .\" and Christian Giessen for tty-clock. .\" In details the command line options displayed by tty-clock -h as .\" well as the keyboard commands. .TH "TTY-CLOCK" "1" "October 2013" "" "User Commands" .SH "NAME" .LP tty\-clock \- a terminal digital clock .SH "SYNOPSIS" .LP \fBtty\-clock [\-iuvsScbtrahDBxn] [\-C [\fI0\-7\fB]] [\-f \fIformat\fB] [\-d \fIdelay\fB] [\-a \fInsdelay\fB] \fB[\-T \fItty\fB]\fR .SH "DESCRIPTION" .LP \fItty\-clock\fR displays a simple digital clock on the terminal. Invoked without options it will display the clock on the upper left corner of the screen on the terminal it was executed from. .SH "COMMANDS" .LP \fItty\-clock\fR accepts a number of runtime keyboard commands, upper and lower case characters are treated identically. .TP K,J,H,L vi\-style movement commands to set the position of the displayed clock. These commands have no effect when the \fBcentered\fR option is set. .TP [0\-7] Select a different color for displaying the clock. .TP B Toggles bewteen bold and normal colors. .TP X Toggles displaying a box around the clock. This option is disabled by default. .TP C Toggle the clock's position to \fBcentered\fR. When set the movement commands are disabled. .TP R Set the clock to \fBrebound\fR along the edges of the terminal. .TP S Display seconds. .TP T Switch time output to the 12\-hour format. .TP Q Quit. .SH "OPTIONS" .LP .TP \fB\-s\fR Show seconds. .TP \fB\-S\fR Screensaver mode. tty\-clock terminates when any key is pressed. .TP \fB\-x\fR Show box. .TP \fB\-c\fR Set the clock at the center of the terminal. .TP \fB\-C\fR \fI[0\-7]\fR Set the clock color. .TP \fB\-b\fR Use bold colors. .TP \fB\-t\fR Set the hour in 12h format. .TP \fB\-u\fR Use UTC time. .TP \fB\-T\fR \fItty\fR Display the clock on the given \fItty\fR. \fItty\fR must be a valid character device to which the user has rw access permissions. (See \fBEXAMPLES\fR) .TP \fB\-r\fR Do rebound the clock. .TP \fB\-f\fR \fIformat\fR Set the date format as described in \fBstrftime(3)\fR. .TP \fB\-n\fR Do not quit the program when the Q key is pressed (or when any key is pressed while in \fBScreensaver\fR mode). A signal must be sent to \fItty\-clock\fR in order to terminate its execution. (See \fBEXAMPLES\fR) .TP \fB\-v\fR Show tty\-clock version. .TP \fB\-i\fR Show some info about tty\-clock. .TP \fB\-h\fR Show usage information. .TP \fB\-D\fR Hide the date. .TP \fB\-B\fR Enable blinking colon. .TP \fB\-d\fR \fIdelay\fR Set the delay (in seconds) between two redraws of the clock. Default 1s. .TP \fB\-a\fR \fInsdelay\fR Additional delay (in nanoseconds) between two redraws of the clock. Default 0ns. .SH "EXAMPLES" .LP To invoke .I tty\-clock in screensaver mode with the clock display set to rebound and the update delay set to 1/10th of a second (10 FPS): .IP $ tty\-clock \-Sra 100000000 \-d 0 .LP The following example arranges for \fItty\-clock\fR to be displayed indefinitely on one of the Virtual Terminals on a Linux system at boot time using an .B inittab(5) entry: .IP # /etc/inittab: .br 9:2345:respawn:/usr/bin/tty\-clock \-c \-n \-T /dev/tty9 .LP tty-clock-2.3/ttyclock.c000066400000000000000000000477671303656526400153260ustar00rootroot00000000000000/* * TTY-CLOCK Main file. * Copyright © 2008 Martin Duquesnoy * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * Neither the name of the nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "ttyclock.h" void init(void) { struct sigaction sig; ttyclock->bg = COLOR_BLACK; /* Init ncurses */ if (ttyclock->tty) { FILE *ftty = fopen(ttyclock->tty, "r+"); if (!ftty) { fprintf(stderr, "tty-clock: error: '%s' couldn't be opened: %s.\n", ttyclock->tty, strerror(errno)); exit(EXIT_FAILURE); } ttyclock->ttyscr = newterm(NULL, ftty, ftty); assert(ttyclock->ttyscr != NULL); set_term(ttyclock->ttyscr); } else initscr(); cbreak(); noecho(); keypad(stdscr, True); start_color(); curs_set(False); clear(); /* Init default terminal color */ if(use_default_colors() == OK) ttyclock->bg = -1; /* Init color pair */ init_pair(0, ttyclock->bg, ttyclock->bg); init_pair(1, ttyclock->bg, ttyclock->option.color); init_pair(2, ttyclock->option.color, ttyclock->bg); // init_pair(0, ttyclock->bg, ttyclock->bg); // init_pair(1, ttyclock->bg, ttyclock->option.color); // init_pair(2, ttyclock->option.color, ttyclock->bg); refresh(); /* Init signal handler */ sig.sa_handler = signal_handler; sig.sa_flags = 0; sigaction(SIGWINCH, &sig, NULL); sigaction(SIGTERM, &sig, NULL); sigaction(SIGINT, &sig, NULL); sigaction(SIGSEGV, &sig, NULL); /* Init global struct */ ttyclock->running = True; if(!ttyclock->geo.x) ttyclock->geo.x = 0; if(!ttyclock->geo.y) ttyclock->geo.y = 0; if(!ttyclock->geo.a) ttyclock->geo.a = 1; if(!ttyclock->geo.b) ttyclock->geo.b = 1; ttyclock->geo.w = (ttyclock->option.second) ? SECFRAMEW : NORMFRAMEW; ttyclock->geo.h = 7; ttyclock->tm = localtime(&(ttyclock->lt)); if(ttyclock->option.utc) { ttyclock->tm = gmtime(&(ttyclock->lt)); } ttyclock->lt = time(NULL); update_hour(); /* Create clock win */ ttyclock->framewin = newwin(ttyclock->geo.h, ttyclock->geo.w, ttyclock->geo.x, ttyclock->geo.y); if(ttyclock->option.box) { box(ttyclock->framewin, 0, 0); } if (ttyclock->option.bold) { wattron(ttyclock->framewin, A_BLINK); } /* Create the date win */ ttyclock->datewin = newwin(DATEWINH, strlen(ttyclock->date.datestr) + 2, ttyclock->geo.x + ttyclock->geo.h - 1, ttyclock->geo.y + (ttyclock->geo.w / 2) - (strlen(ttyclock->date.datestr) / 2) - 1); if(ttyclock->option.box) { box(ttyclock->datewin, 0, 0); } clearok(ttyclock->datewin, True); set_center(ttyclock->option.center); nodelay(stdscr, True); if (ttyclock->option.date) { wrefresh(ttyclock->datewin); } wrefresh(ttyclock->framewin); return; } void signal_handler(int signal) { switch(signal) { case SIGWINCH: endwin(); init(); break; /* Interruption signal */ case SIGINT: case SIGTERM: ttyclock->running = False; /* Segmentation fault signal */ break; case SIGSEGV: endwin(); fprintf(stderr, "Segmentation fault.\n"); exit(EXIT_FAILURE); break; } return; } void cleanup(void) { if (ttyclock->ttyscr) delscreen(ttyclock->ttyscr); if (ttyclock && ttyclock->tty) free(ttyclock->tty); if (ttyclock && ttyclock->option.format) free(ttyclock->option.format); if (ttyclock) free(ttyclock); } void update_hour(void) { int ihour; char tmpstr[128]; ttyclock->lt = time(NULL); ttyclock->tm = localtime(&(ttyclock->lt)); if(ttyclock->option.utc) { ttyclock->tm = gmtime(&(ttyclock->lt)); } ihour = ttyclock->tm->tm_hour; if(ttyclock->option.twelve) ttyclock->meridiem = ((ihour > 12) ? PMSIGN : AMSIGN); else ttyclock->meridiem = "\0"; /* Manage hour for twelve mode */ ihour = ((ttyclock->option.twelve && ihour > 12) ? (ihour - 12) : ihour); ihour = ((ttyclock->option.twelve && !ihour) ? 12 : ihour); /* Set hour */ ttyclock->date.hour[0] = ihour / 10; ttyclock->date.hour[1] = ihour % 10; /* Set minutes */ ttyclock->date.minute[0] = ttyclock->tm->tm_min / 10; ttyclock->date.minute[1] = ttyclock->tm->tm_min % 10; /* Set date string */ strftime(tmpstr, sizeof(tmpstr), ttyclock->option.format, ttyclock->tm); sprintf(ttyclock->date.datestr, "%s%s", tmpstr, ttyclock->meridiem); /* Set seconds */ ttyclock->date.second[0] = ttyclock->tm->tm_sec / 10; ttyclock->date.second[1] = ttyclock->tm->tm_sec % 10; return; } void draw_number(int n, int x, int y) { int i, sy = y; for(i = 0; i < 30; ++i, ++sy) { if(sy == y + 6) { sy = y; ++x; } if (ttyclock->option.bold) wattron(ttyclock->framewin, A_BLINK); else wattroff(ttyclock->framewin, A_BLINK); wbkgdset(ttyclock->framewin, COLOR_PAIR(number[n][i/2])); mvwaddch(ttyclock->framewin, x, sy, ' '); } wrefresh(ttyclock->framewin); return; } void draw_clock(void) { /* Draw hour numbers */ draw_number(ttyclock->date.hour[0], 1, 1); draw_number(ttyclock->date.hour[1], 1, 8); chtype dotcolor = COLOR_PAIR(1); if (ttyclock->option.blink && time(NULL) % 2 == 0) dotcolor = COLOR_PAIR(2); /* 2 dot for number separation */ wbkgdset(ttyclock->framewin, dotcolor); mvwaddstr(ttyclock->framewin, 2, 16, " "); mvwaddstr(ttyclock->framewin, 4, 16, " "); /* Draw minute numbers */ draw_number(ttyclock->date.minute[0], 1, 20); draw_number(ttyclock->date.minute[1], 1, 27); /* Draw the date */ if (ttyclock->option.bold) wattron(ttyclock->datewin, A_BOLD); else wattroff(ttyclock->datewin, A_BOLD); if (ttyclock->option.date) { wbkgdset(ttyclock->datewin, (COLOR_PAIR(2))); mvwprintw(ttyclock->datewin, (DATEWINH / 2), 1, ttyclock->date.datestr); wrefresh(ttyclock->datewin); } /* Draw second if the option is enable */ if(ttyclock->option.second) { /* Again 2 dot for number separation */ wbkgdset(ttyclock->framewin, dotcolor); mvwaddstr(ttyclock->framewin, 2, NORMFRAMEW, " "); mvwaddstr(ttyclock->framewin, 4, NORMFRAMEW, " "); /* Draw second numbers */ draw_number(ttyclock->date.second[0], 1, 39); draw_number(ttyclock->date.second[1], 1, 46); } return; } void clock_move(int x, int y, int w, int h) { /* Erase border for a clean move */ wbkgdset(ttyclock->framewin, COLOR_PAIR(0)); wborder(ttyclock->framewin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); werase(ttyclock->framewin); wrefresh(ttyclock->framewin); if (ttyclock->option.date) { wbkgdset(ttyclock->datewin, COLOR_PAIR(0)); wborder(ttyclock->datewin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); werase(ttyclock->datewin); wrefresh(ttyclock->datewin); } /* Frame win move */ mvwin(ttyclock->framewin, (ttyclock->geo.x = x), (ttyclock->geo.y = y)); wresize(ttyclock->framewin, (ttyclock->geo.h = h), (ttyclock->geo.w = w)); /* Date win move */ if (ttyclock->option.date) { mvwin(ttyclock->datewin, ttyclock->geo.x + ttyclock->geo.h - 1, ttyclock->geo.y + (ttyclock->geo.w / 2) - (strlen(ttyclock->date.datestr) / 2) - 1); wresize(ttyclock->datewin, DATEWINH, strlen(ttyclock->date.datestr) + 2); if (ttyclock->option.box) { box(ttyclock->datewin, 0, 0); } } if (ttyclock->option.box) { box(ttyclock->framewin, 0, 0); } wrefresh(ttyclock->framewin); wrefresh(ttyclock->datewin); return; } /* Useless but fun :) */ void clock_rebound(void) { if(!ttyclock->option.rebound) return; if(ttyclock->geo.x < 1) ttyclock->geo.a = 1; if(ttyclock->geo.x > (LINES - ttyclock->geo.h - DATEWINH)) ttyclock->geo.a = -1; if(ttyclock->geo.y < 1) ttyclock->geo.b = 1; if(ttyclock->geo.y > (COLS - ttyclock->geo.w - 1)) ttyclock->geo.b = -1; clock_move(ttyclock->geo.x + ttyclock->geo.a, ttyclock->geo.y + ttyclock->geo.b, ttyclock->geo.w, ttyclock->geo.h); return; } void set_second(void) { int new_w = (((ttyclock->option.second = !ttyclock->option.second)) ? SECFRAMEW : NORMFRAMEW); int y_adj; for(y_adj = 0; (ttyclock->geo.y - y_adj) > (COLS - new_w - 1); ++y_adj); clock_move(ttyclock->geo.x, (ttyclock->geo.y - y_adj), new_w, ttyclock->geo.h); set_center(ttyclock->option.center); return; } void set_center(Bool b) { if((ttyclock->option.center = b)) { ttyclock->option.rebound = False; clock_move((LINES / 2 - (ttyclock->geo.h / 2)), (COLS / 2 - (ttyclock->geo.w / 2)), ttyclock->geo.w, ttyclock->geo.h); } return; } void set_box(Bool b) { ttyclock->option.box = b; wbkgdset(ttyclock->framewin, COLOR_PAIR(0)); wbkgdset(ttyclock->datewin, COLOR_PAIR(0)); if(ttyclock->option.box) { wbkgdset(ttyclock->framewin, COLOR_PAIR(0)); wbkgdset(ttyclock->datewin, COLOR_PAIR(0)); box(ttyclock->framewin, 0, 0); box(ttyclock->datewin, 0, 0); } else { wborder(ttyclock->framewin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); wborder(ttyclock->datewin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); } wrefresh(ttyclock->datewin); wrefresh(ttyclock->framewin); } void key_event(void) { int i, c; struct timespec length = { ttyclock->option.delay, ttyclock->option.nsdelay }; if (ttyclock->option.screensaver) { c = wgetch(stdscr); if(c != ERR && ttyclock->option.noquit == False) { ttyclock->running = False; } else { nanosleep(&length, NULL); for(i = 0; i < 8; ++i) if(c == (i + '0')) { ttyclock->option.color = i; init_pair(1, ttyclock->bg, i); init_pair(2, i, ttyclock->bg); } } return; } switch(c = wgetch(stdscr)) { case KEY_UP: case 'k': case 'K': if(ttyclock->geo.x >= 1 && !ttyclock->option.center) clock_move(ttyclock->geo.x - 1, ttyclock->geo.y, ttyclock->geo.w, ttyclock->geo.h); break; case KEY_DOWN: case 'j': case 'J': if(ttyclock->geo.x <= (LINES - ttyclock->geo.h - DATEWINH) && !ttyclock->option.center) clock_move(ttyclock->geo.x + 1, ttyclock->geo.y, ttyclock->geo.w, ttyclock->geo.h); break; case KEY_LEFT: case 'h': case 'H': if(ttyclock->geo.y >= 1 && !ttyclock->option.center) clock_move(ttyclock->geo.x, ttyclock->geo.y - 1, ttyclock->geo.w, ttyclock->geo.h); break; case KEY_RIGHT: case 'l': case 'L': if(ttyclock->geo.y <= (COLS - ttyclock->geo.w - 1) && !ttyclock->option.center) clock_move(ttyclock->geo.x, ttyclock->geo.y + 1, ttyclock->geo.w, ttyclock->geo.h); break; case 'q': case 'Q': if (ttyclock->option.noquit == False) ttyclock->running = False; break; case 's': case 'S': set_second(); break; case 't': case 'T': ttyclock->option.twelve = !ttyclock->option.twelve; /* Set the new ttyclock->date.datestr to resize date window */ update_hour(); clock_move(ttyclock->geo.x, ttyclock->geo.y, ttyclock->geo.w, ttyclock->geo.h); break; case 'c': case 'C': set_center(!ttyclock->option.center); break; case 'b': case 'B': ttyclock->option.bold = !ttyclock->option.bold; break; case 'r': case 'R': ttyclock->option.rebound = !ttyclock->option.rebound; if(ttyclock->option.rebound && ttyclock->option.center) ttyclock->option.center = False; break; case 'x': case 'X': set_box(!ttyclock->option.box); break; default: nanosleep(&length, NULL); for(i = 0; i < 8; ++i) if(c == (i + '0')) { ttyclock->option.color = i; init_pair(1, ttyclock->bg, i); init_pair(2, i, ttyclock->bg); } break; } return; } 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_GREEN; /* COLOR_GREEN = 2 */ /* Default delay */ ttyclock->option.delay = 1; /* 1FPS */ ttyclock->option.nsdelay = 0; /* -0FPS */ ttyclock->option.blink = False; atexit(cleanup); while ((c = getopt(argc, argv, "iuvsScbtrhBxnDC:f:d:T:a:")) != -1) { switch(c) { case 'h': default: printf("usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] \n" " -s Show seconds \n" " -S Screensaver mode \n" " -x Show box \n" " -c Set the clock at the center of the terminal \n" " -C [0-7] Set the clock color \n" " -b Use bold colors \n" " -t Set the hour in 12h format \n" " -u Use UTC time \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 Hide date \n" " -B Enable blinking colon \n" " -d delay Set the delay between two redraws of the clock. Default 1s. \n" " -a nsdelay Additional delay between two redraws in nanoseconds. Default 0ns.\n"); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy (xorg62@gmail.com), Grey (grey@greytheory.net)"); exit(EXIT_SUCCESS); break; case 'u': ttyclock->option.utc = True; 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 'b': ttyclock->option.bold = 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) < 100) ttyclock->option.delay = atol(optarg); break; case 'D': ttyclock->option.date = False; 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; } } init(); attron(A_BLINK); while(ttyclock->running) { clock_rebound(); update_hour(); draw_clock(); key_event(); } endwin(); return 0; } tty-clock-2.3/ttyclock.h000066400000000000000000000101271303656526400153070ustar00rootroot00000000000000/* * TTY-CLOCK headers file. * Copyright © 2008 Martin Duquesnoy * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * Neither the name of the nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef TTYCLOCK_H_INCLUDED #define TTYCLOCK_H_INCLUDED #include #include #include #include #include #include #include #include #include #include #include /* Macro */ #define NORMFRAMEW 35 #define SECFRAMEW 54 #define DATEWINH 3 #define AMSIGN " [AM]" #define PMSIGN " [PM]" typedef enum { False, True } Bool; /* Global ttyclock struct */ typedef struct { /* while() boolean */ Bool running; /* terminal variables */ SCREEN *ttyscr; char *tty; int bg; /* Running option */ struct { Bool second; Bool screensaver; Bool twelve; Bool center; Bool rebound; Bool date; Bool utc; Bool box; Bool noquit; char *format; int color; Bool bold; long delay; Bool blink; long nsdelay; } option; /* Clock geometry */ struct { int x, y, w, h; /* For rebound use (see clock_rebound())*/ int a, b; } geo; /* Date content ([2] = number by number) */ struct { unsigned int hour[2]; unsigned int minute[2]; unsigned int second[2]; char datestr[256]; } date; /* time.h utils */ struct tm *tm; time_t lt; /* Clock member */ char *meridiem; WINDOW *framewin; WINDOW *datewin; } ttyclock_t; /* Prototypes */ void init(void); void signal_handler(int signal); void update_hour(void); void draw_number(int n, int x, int y); void draw_clock(void); void clock_move(int x, int y, int w, int h); void set_second(void); void set_center(Bool b); void set_box(Bool b); void key_event(void); /* Global variable */ ttyclock_t *ttyclock; /* Number matrix */ const Bool number[][15] = { {1,1,1,1,0,1,1,0,1,1,0,1,1,1,1}, /* 0 */ {0,0,1,0,0,1,0,0,1,0,0,1,0,0,1}, /* 1 */ {1,1,1,0,0,1,1,1,1,1,0,0,1,1,1}, /* 2 */ {1,1,1,0,0,1,1,1,1,0,0,1,1,1,1}, /* 3 */ {1,0,1,1,0,1,1,1,1,0,0,1,0,0,1}, /* 4 */ {1,1,1,1,0,0,1,1,1,0,0,1,1,1,1}, /* 5 */ {1,1,1,1,0,0,1,1,1,1,0,1,1,1,1}, /* 6 */ {1,1,1,0,0,1,0,0,1,0,0,1,0,0,1}, /* 7 */ {1,1,1,1,0,1,1,1,1,1,0,1,1,1,1}, /* 8 */ {1,1,1,1,0,1,1,1,1,0,0,1,1,1,1}, /* 9 */ }; #endif /* TTYCLOCK_H_INCLUDED */