ttyclock.h - tty-clock - port of tty-clock to OpenBSD, with pledge/unveil added as goodie
HTML git clone https://git.drkhsh.at/tty-clock.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
ttyclock.h (4359B)
---
1 /*
2 * TTY-CLOCK headers file.
3 * Copyright © 2009-2013 tty-clock contributors
4 * Copyright © 2008-2009 Martin Duquesnoy <xorg62@gmail.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following disclaimer
15 * in the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of the nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef TTYCLOCK_H_INCLUDED
35 #define TTYCLOCK_H_INCLUDED
36
37 #include <assert.h>
38 #include <errno.h>
39 #include <getopt.h>
40 #include <signal.h>
41 #include <stdbool.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <sys/select.h>
45 #include <sys/stat.h>
46 #include <sys/types.h>
47 #include <locale.h>
48 #include <time.h>
49 #include <unistd.h>
50 #include <ncurses.h>
51
52 /* Macro */
53 #define NORMFRAMEW 35
54 #define SECFRAMEW 54
55 #define DATEWINH 3
56 #define AMSIGN " [AM]"
57 #define PMSIGN " [PM]"
58
59 /* Global ttyclock struct */
60 typedef struct
61 {
62 /* while() boolean */
63 bool running;
64
65 /* terminal variables */
66 SCREEN *ttyscr;
67 char *tty;
68 int bg;
69
70 /* Running option */
71 struct
72 {
73 bool second;
74 bool screensaver;
75 bool twelve;
76 bool center;
77 bool rebound;
78 bool date;
79 bool utc;
80 bool box;
81 bool noquit;
82 char format[100];
83 int color;
84 bool bold;
85 long delay;
86 bool blink;
87 long nsdelay;
88 } option;
89
90 /* Clock geometry */
91 struct
92 {
93 int x, y, w, h;
94 /* For rebound use (see clock_rebound())*/
95 int a, b;
96 } geo;
97
98 /* Date content ([2] = number by number) */
99 struct
100 {
101 unsigned int hour[2];
102 unsigned int minute[2];
103 unsigned int second[2];
104 char datestr[256];
105 char old_datestr[256];
106 } date;
107
108 /* time.h utils */
109 struct tm *tm;
110 time_t lt;
111
112 /* Clock member */
113 char *meridiem;
114 WINDOW *framewin;
115 WINDOW *datewin;
116
117 } ttyclock_t;
118
119 /* Prototypes */
120 void init(void);
121 void signal_handler(int signal);
122 void update_hour(void);
123 void draw_number(int n, int x, int y);
124 void draw_clock(void);
125 void clock_move(int x, int y, int w, int h);
126 void set_second(void);
127 void set_center(bool b);
128 void set_box(bool b);
129 void key_event(void);
130
131 /* Global variable */
132 ttyclock_t ttyclock;
133
134 /* Number matrix */
135 const bool number[][15] =
136 {
137 {1,1,1,1,0,1,1,0,1,1,0,1,1,1,1}, /* 0 */
138 {0,0,1,0,0,1,0,0,1,0,0,1,0,0,1}, /* 1 */
139 {1,1,1,0,0,1,1,1,1,1,0,0,1,1,1}, /* 2 */
140 {1,1,1,0,0,1,1,1,1,0,0,1,1,1,1}, /* 3 */
141 {1,0,1,1,0,1,1,1,1,0,0,1,0,0,1}, /* 4 */
142 {1,1,1,1,0,0,1,1,1,0,0,1,1,1,1}, /* 5 */
143 {1,1,1,1,0,0,1,1,1,1,0,1,1,1,1}, /* 6 */
144 {1,1,1,0,0,1,0,0,1,0,0,1,0,0,1}, /* 7 */
145 {1,1,1,1,0,1,1,1,1,1,0,1,1,1,1}, /* 8 */
146 {1,1,1,1,0,1,1,1,1,0,0,1,1,1,1}, /* 9 */
147 };
148
149 #endif /* TTYCLOCK_H_INCLUDED */
150
151 // vim: expandtab tabstop=5 softtabstop=5 shiftwidth=5