Use standard bool type

master
Jakub Wilk 6 years ago
parent e7eaef18ca
commit 2b79d36ff0
  1. 54
      ttyclock.c
  2. 33
      ttyclock.h

@ -55,9 +55,9 @@ init(void)
cbreak(); cbreak();
noecho(); noecho();
keypad(stdscr, True); keypad(stdscr, true);
start_color(); start_color();
curs_set(False); curs_set(false);
clear(); clear();
/* Init default terminal color */ /* Init default terminal color */
@ -81,7 +81,7 @@ init(void)
sigaction(SIGSEGV, &sig, NULL); sigaction(SIGSEGV, &sig, NULL);
/* Init global struct */ /* Init global struct */
ttyclock.running = True; ttyclock.running = true;
if(!ttyclock.geo.x) if(!ttyclock.geo.x)
ttyclock.geo.x = 0; ttyclock.geo.x = 0;
if(!ttyclock.geo.y) if(!ttyclock.geo.y)
@ -121,11 +121,11 @@ init(void)
if(ttyclock.option.box && ttyclock.option.date) { if(ttyclock.option.box && ttyclock.option.date) {
box(ttyclock.datewin, 0, 0); box(ttyclock.datewin, 0, 0);
} }
clearok(ttyclock.datewin, True); clearok(ttyclock.datewin, true);
set_center(ttyclock.option.center); set_center(ttyclock.option.center);
nodelay(stdscr, True); nodelay(stdscr, true);
if (ttyclock.option.date) if (ttyclock.option.date)
{ {
@ -144,7 +144,7 @@ signal_handler(int signal)
{ {
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
ttyclock.running = False; ttyclock.running = false;
break; break;
/* Segmentation fault signal */ /* Segmentation fault signal */
case SIGSEGV: case SIGSEGV:
@ -370,11 +370,11 @@ set_second(void)
} }
void void
set_center(Bool b) set_center(bool b)
{ {
if((ttyclock.option.center = b)) if((ttyclock.option.center = b))
{ {
ttyclock.option.rebound = False; ttyclock.option.rebound = false;
clock_move((LINES / 2 - (ttyclock.geo.h / 2)), clock_move((LINES / 2 - (ttyclock.geo.h / 2)),
(COLS / 2 - (ttyclock.geo.w / 2)), (COLS / 2 - (ttyclock.geo.w / 2)),
@ -386,7 +386,7 @@ set_center(Bool b)
} }
void void
set_box(Bool b) set_box(bool b)
{ {
ttyclock.option.box = b; ttyclock.option.box = b;
@ -422,9 +422,9 @@ key_event(void)
if (ttyclock.option.screensaver) if (ttyclock.option.screensaver)
{ {
c = wgetch(stdscr); c = wgetch(stdscr);
if(c != ERR && ttyclock.option.noquit == False) if(c != ERR && ttyclock.option.noquit == false)
{ {
ttyclock.running = False; ttyclock.running = false;
} }
else else
{ {
@ -482,8 +482,8 @@ key_event(void)
case 'q': case 'q':
case 'Q': case 'Q':
if (ttyclock.option.noquit == False) if (ttyclock.option.noquit == false)
ttyclock.running = False; ttyclock.running = false;
break; break;
case 's': case 's':
@ -513,7 +513,7 @@ key_event(void)
case 'R': case 'R':
ttyclock.option.rebound = !ttyclock.option.rebound; ttyclock.option.rebound = !ttyclock.option.rebound;
if(ttyclock.option.rebound && ttyclock.option.center) if(ttyclock.option.rebound && ttyclock.option.center)
ttyclock.option.center = False; ttyclock.option.center = false;
break; break;
case 'x': case 'x':
@ -544,7 +544,7 @@ main(int argc, char **argv)
/* Alloc ttyclock */ /* Alloc ttyclock */
memset(&ttyclock, 0, sizeof(ttyclock_t)); memset(&ttyclock, 0, sizeof(ttyclock_t));
ttyclock.option.date = True; ttyclock.option.date = true;
/* Default date format */ /* Default date format */
strncpy(ttyclock.option.format, "%F", sizeof (ttyclock.option.format)); strncpy(ttyclock.option.format, "%F", sizeof (ttyclock.option.format));
@ -553,7 +553,7 @@ main(int argc, char **argv)
/* Default delay */ /* Default delay */
ttyclock.option.delay = 1; /* 1FPS */ ttyclock.option.delay = 1; /* 1FPS */
ttyclock.option.nsdelay = 0; /* -0FPS */ ttyclock.option.nsdelay = 0; /* -0FPS */
ttyclock.option.blink = False; ttyclock.option.blink = false;
atexit(cleanup); atexit(cleanup);
@ -590,33 +590,33 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'u': case 'u':
ttyclock.option.utc = True; ttyclock.option.utc = true;
break; break;
case 'v': case 'v':
puts("TTY-Clock 2 © devel version"); puts("TTY-Clock 2 © devel version");
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 's': case 's':
ttyclock.option.second = True; ttyclock.option.second = true;
break; break;
case 'S': case 'S':
ttyclock.option.screensaver = True; ttyclock.option.screensaver = true;
break; break;
case 'c': case 'c':
ttyclock.option.center = True; ttyclock.option.center = true;
break; break;
case 'b': case 'b':
ttyclock.option.bold = True; ttyclock.option.bold = true;
break; break;
case 'C': case 'C':
if(atoi(optarg) >= 0 && atoi(optarg) < 8) if(atoi(optarg) >= 0 && atoi(optarg) < 8)
ttyclock.option.color = atoi(optarg); ttyclock.option.color = atoi(optarg);
break; break;
case 't': case 't':
ttyclock.option.twelve = True; ttyclock.option.twelve = true;
break; break;
case 'r': case 'r':
ttyclock.option.rebound = True; ttyclock.option.rebound = true;
break; break;
case 'f': case 'f':
strncpy(ttyclock.option.format, optarg, 100); strncpy(ttyclock.option.format, optarg, 100);
@ -626,17 +626,17 @@ main(int argc, char **argv)
ttyclock.option.delay = atol(optarg); ttyclock.option.delay = atol(optarg);
break; break;
case 'D': case 'D':
ttyclock.option.date = False; ttyclock.option.date = false;
break; break;
case 'B': case 'B':
ttyclock.option.blink = True; ttyclock.option.blink = true;
break; break;
case 'a': case 'a':
if(atol(optarg) >= 0 && atol(optarg) < 1000000000) if(atol(optarg) >= 0 && atol(optarg) < 1000000000)
ttyclock.option.nsdelay = atol(optarg); ttyclock.option.nsdelay = atol(optarg);
break; break;
case 'x': case 'x':
ttyclock.option.box = True; ttyclock.option.box = true;
break; break;
case 'T': { case 'T': {
struct stat sbuf; struct stat sbuf;
@ -654,7 +654,7 @@ main(int argc, char **argv)
}} }}
break; break;
case 'n': case 'n':
ttyclock.option.noquit = True; ttyclock.option.noquit = true;
break; break;
} }
} }

@ -38,6 +38,7 @@
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/select.h> #include <sys/select.h>
@ -55,13 +56,11 @@
#define AMSIGN " [AM]" #define AMSIGN " [AM]"
#define PMSIGN " [PM]" #define PMSIGN " [PM]"
typedef enum { False, True } Bool;
/* Global ttyclock struct */ /* Global ttyclock struct */
typedef struct typedef struct
{ {
/* while() boolean */ /* while() boolean */
Bool running; bool running;
/* terminal variables */ /* terminal variables */
SCREEN *ttyscr; SCREEN *ttyscr;
@ -71,20 +70,20 @@ typedef struct
/* Running option */ /* Running option */
struct struct
{ {
Bool second; bool second;
Bool screensaver; bool screensaver;
Bool twelve; bool twelve;
Bool center; bool center;
Bool rebound; bool rebound;
Bool date; bool date;
Bool utc; bool utc;
Bool box; bool box;
Bool noquit; bool noquit;
char format[100]; char format[100];
int color; int color;
Bool bold; bool bold;
long delay; long delay;
Bool blink; bool blink;
long nsdelay; long nsdelay;
} option; } option;
@ -124,15 +123,15 @@ void draw_number(int n, int x, int y);
void draw_clock(void); void draw_clock(void);
void clock_move(int x, int y, int w, int h); void clock_move(int x, int y, int w, int h);
void set_second(void); void set_second(void);
void set_center(Bool b); void set_center(bool b);
void set_box(Bool b); void set_box(bool b);
void key_event(void); void key_event(void);
/* Global variable */ /* Global variable */
ttyclock_t ttyclock; ttyclock_t ttyclock;
/* Number matrix */ /* Number matrix */
const Bool number[][15] = const bool number[][15] =
{ {
{1,1,1,1,0,1,1,0,1,1,0,1,1,1,1}, /* 0 */ {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 */ {0,0,1,0,0,1,0,0,1,0,0,1,0,0,1}, /* 1 */

Loading…
Cancel
Save