diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-09-12 03:42:24 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-09-12 03:42:24 +0200 |
commit | fee2317e973b25dc0e73603702dc686eb058b397 (patch) | |
tree | 4d9a6d50b74bc0be11a1b8a9543919c0eace3e85 | |
parent | signals will interrupt read on timer, so we do not have to wait for the timer to expire to exit (diff) | |
download | mongoclock-fee2317e973b25dc0e73603702dc686eb058b397.tar.gz mongoclock-fee2317e973b25dc0e73603702dc686eb058b397.tar.bz2 mongoclock-fee2317e973b25dc0e73603702dc686eb058b397.tar.xz |
update makefile + update gitignore + fix warnings + remove old implementation + add deps2
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | DEPENDENCIES | 22 | ||||
-rw-r--r-- | Makefile | 58 | ||||
-rwxr-xr-x | mongoclock | 12 | ||||
-rwxr-xr-x | mongoclock.py | 256 | ||||
-rw-r--r-- | src/mongoclock.c | 9 |
6 files changed, 71 insertions, 288 deletions
@@ -1,5 +1,7 @@ _/ __pycache__/ +bin/ +obj/ \#*\# .* !.git* diff --git a/DEPENDENCIES b/DEPENDENCIES new file mode 100644 index 0000000..e306b78 --- /dev/null +++ b/DEPENDENCIES @@ -0,0 +1,22 @@ +RUNTIME DEPENDENCIES: + + glibc + linux + gpp (http://www.github.com/maandree/gpp) + + +BUILD DEPENDENCIES: + + glibc + gcc + linux-api-headers + make + coreutils + texinfo (opt-out: for info manual) + + +INSTALL DEPENDENCIES: + + make + coreutils + @@ -6,50 +6,76 @@ PREFIX = /usr DATA = /share BIN = /bin -LIBEXEC = /libexec PKGNAME = mongoclock COMMAND = mongoclock LICENSES = $(PREFIX)$(DATA) -all: mongoclock.install doc +GPP = gpp + + +WARN = -Wall -Wextra -pedantic -Wdouble-promotion -Wformat=2 -Winit-self -Wmissing-include-dirs \ + -Wtrampolines -Wmissing-prototypes -Wmissing-declarations -Wnested-externs \ + -Wno-variadic-macros -Wsync-nand -Wunsafe-loop-optimizations -Wcast-align \ + -Wdeclaration-after-statement -Wundef -Wbad-function-cast -Wwrite-strings -Wlogical-op \ + -Wstrict-prototypes -Wold-style-definition -Wpacked -Wvector-operation-performance \ + -Wunsuffixed-float-constants -Wsuggest-attribute=const -Wsuggest-attribute=noreturn \ + -Wsuggest-attribute=format -Wnormalized=nfkc -Wshadow -Wredundant-decls -Winline -Wcast-qual \ + -Wsign-conversion -Wstrict-overflow=5 -Wconversion -Wsuggest-attribute=pure -Wswitch-default \ + -Wstrict-aliasing=1 -fstrict-overflow -Wfloat-equal -Wpadded -Waggregate-return \ + -Wtraditional-conversion + +FFLAGS = -fstrict-aliasing -fipa-pure-const -ftree-vrp -fstack-usage -funsafe-loop-optimizations +STD = c99 +OPTIMISE = -O2 + +FLAGS = $(OPTIMISE) -std=$(STD) $(WARN) $(FFLAGS) + + +all: mongoclock doc doc: info -info: mongoclock.info.gz +info: mongoclock.info -%.info.gz: info/%.texinfo +%.info: info/%.texinfo makeinfo "$<" - gzip -9 -f "$*.info" -mongoclock.install: mongoclock - cp "$<" "$@" - sed -i 's:$$0.py:$(PREFIX)$(LIBEXEC)/$(COMMAND).py:g' "$@" +mongoclock: bin/mongoclock + +bin/mongoclock: obj/mongoclock.o + mkdir -p bin + $(CC) $(FLAGS) -o $@ $^ $(LDFLAGS) + +obj/mongoclock.o: obj/mongoclock.c + $(CC) $(FLAGS) -c -o $@ $< $(CPPFLAGS) $(CFLAGS) + +obj/mongoclock.c: src/mongoclock.c + mkdir -p obj + $(GPP) -s '$$' -i $< -o $@ install: install-cmd install-license install-info -install-cmd: +install-cmd: bin/mongoclock install -dm755 "$(DESTDIR)$(PREFIX)$(BIN)" install -dm755 "$(DESTDIR)$(PREFIX)$(LIBEXEC)" - install -m755 mongoclock.install "$(DESTDIR)$(PREFIX)$(BIN)/$(COMMAND)" - install -m755 mongoclock.py "$(DESTDIR)$(PREFIX)$(LIBEXEC)/$(COMMAND).py" + install -m755 bin/mongoclock "$(DESTDIR)$(PREFIX)$(BIN)/$(COMMAND)" install-license: install -dm755 "$(DESTDIR)$(LICENSES)/$(PKGNAME)" install -m644 COPYING "$(DESTDIR)$(LICENSES)/$(PKGNAME)" -install-info: mongoclock.info.gz +install-info: mongoclock.info install -dm755 "$(DESTDIR)$(PREFIX)$(DATA)/info" - install -m644 mongoclock.info.gz "$(DESTDIR)$(PREFIX)$(DATA)/info/$(PKGNAME).info.gz" + install -m644 mongoclock.info "$(DESTDIR)$(PREFIX)$(DATA)/info/$(PKGNAME).info" uninstall: -rm -- "$(DESTDIR)$(PREFIX)$(BIN)/$(COMMAND)" - -rm -- "$(DESTDIR)$(PREFIX)$(LIBEXEC)/$(COMMAND).py" -rm -- "$(DESTDIR)$(LICENSES)/$(PKGNAME)/COPYING" -rmdir -- "$(DESTDIR)$(LICENSES)/$(PKGNAME)" - -rm -- "$(DESTDIR)$(PREFIX)$(DATA)/info/$(PKGNAME).info.gz" + -rm -- "$(DESTDIR)$(PREFIX)$(DATA)/info/$(PKGNAME).info" .PHONY: clean clean: - -rm -f mongoclock.info.gz mongoclock.install + -rm -f bin obj mongoclock.info diff --git a/mongoclock b/mongoclock deleted file mode 100755 index 0a6746e..0000000 --- a/mongoclock +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -# -# Copyright © 2013 Mattias Andrée (maandree@member.fsf.org) -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. [GNU All Permissive License] - -echo -en '\033[?1049h\033[?25l' -"$0.py" 2>/dev/null -echo -en '\033[?25h\033[H\033[2J\033[?1049l' diff --git a/mongoclock.py b/mongoclock.py deleted file mode 100755 index 57fe6f4..0000000 --- a/mongoclock.py +++ /dev/null @@ -1,256 +0,0 @@ -#!/usr/bin/env python -# -# Copyright © 2013 Mattias Andrée (maandree@member.fsf.org) -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. [GNU All Permissive License] - -import os -import time -import sys -from subprocess import Popen, PIPE - -def awesome(list): - return [elem.replace('X', ' ').replace('[', '\033[07m ').replace(']', ' \033[00m') for elem in list] - - -MONGO_0 = [' [XXXX] ', - ' [XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [] [XX] ', - '[XX] [] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - ' [XX] [XX] ', - ' [XXXX] '] - -MONGO_1 = [' [XX] ', - ' [XXXX] ', - ' [XXXXXX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XXXXXXXXXX] '] - -MONGO_2 = [' [XXXXXXXX] ', - '[XX] [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - '[XX] ', - '[XX] [XX] ', - '[XXXXXXXXXXXX] '] - -MONGO_3 = [' [XXXXXXXX] ', - '[XX] [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XXXXXX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - '[XX] [XX] ', - ' [XXXXXXXX] '] - -MONGO_4 = [' [XX] ', - ' [XXXX] ', - ' [XXXXXX] ', - ' [XX] [XX] ', - '[XX] [XX] ', - '[XXXXXXXXXXXX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XXXXXX] '] - -MONGO_5 = ['[XXXXXXXXXXXX] ', - '[XX] ', - '[XX] ', - '[XX] ', - '[XX] ', - '[XXXXXXXXXX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - '[XX] [XX] ', - ' [XXXXXXXX] '] - -MONGO_6 = [' [XXXX] ', - ' [XX] ', - ' [XX] ', - '[XX] ', - '[XX] ', - '[XXXXXXXXXX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - ' [XXXXXXXX] '] - -MONGO_7 = ['[XXXXXXXXXXXX] ', - '[XX] [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] '] - -MONGO_8 = [' [XXXXXXXX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - ' [XXXXXXXX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - ' [XXXXXXXX] '] - -MONGO_9 = [' [XXXXXXXX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - '[XX] [XX] ', - ' [XXXXXXXXXX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XX] ', - ' [XXXX] '] - -MONGO__ = [' ', - ' ', - ' [XX] ', - ' [XX] ', - ' ', - ' ', - ' ', - ' ', - ' [XX] ', - ' [XX] ', - ' ', - ' '] - - -DX = len(MONGO_0[0]) -DC = len(MONGO__[0]) - - -MONGO_0 = awesome(MONGO_0) -MONGO_1 = awesome(MONGO_1) -MONGO_2 = awesome(MONGO_2) -MONGO_3 = awesome(MONGO_3) -MONGO_4 = awesome(MONGO_4) -MONGO_5 = awesome(MONGO_5) -MONGO_6 = awesome(MONGO_6) -MONGO_7 = awesome(MONGO_7) -MONGO_8 = awesome(MONGO_8) -MONGO_9 = awesome(MONGO_9) -MONGO__ = awesome(MONGO__) - - -def print_digit(digit, x, y): - d = MONGO__ - if digit == 0: d = MONGO_0 - elif digit == 1: d = MONGO_1 - elif digit == 2: d = MONGO_2 - elif digit == 3: d = MONGO_3 - elif digit == 4: d = MONGO_4 - elif digit == 5: d = MONGO_5 - elif digit == 6: d = MONGO_6 - elif digit == 7: d = MONGO_7 - elif digit == 8: d = MONGO_8 - elif digit == 9: d = MONGO_9 - x += 1 - for i in range(len(d)): - y += 1 - print("\033[%i;%iH%s" % (y, x, d[i])) - -def print_number(number, x, y): - print_digit(number // 10, x, y) - print_digit(number % 10, x + DX, y) - -def print_time(h, m, s, x, y): - print_number(h, x, y) - x += DX << 1 - print_digit(-1, x, y) - x += DC - print_number(m, x, y) - if s is not None: - x += DX << 1 - print_digit(-1, x, y) - x += DC - print_number(s, x, y) - -def get_print_width(has_seconds): - return DC + 4 * DX + ((DC + 2 * DX) if has_seconds else 0) - -def get_print_height(): - return len(MONGO_0) - -def get_print_offset(has_seconds): - (h, w) = get_dimensions() - return ((w - get_print_width(has_seconds)) // 2, (h - get_print_height()) // 2) - -def fits(has_seconds): - (h, w) = get_dimensions() - return (get_print_width(has_seconds) <= w) and (get_print_height() <= h) - -def get_dimensions(): - rc = Popen(['stty', 'size'], stdout = PIPE).communicate()[0] - rc = rc.decode('utf-8') - rc = rc.replace('\n', '').split(' ') - return [int(x) for x in rc] - - -if __name__ == '__main__': - val = None - if fits(True): - val = True - elif fits(False): - val = False - else: - print('Screen is too small') - exit(1) - (x, y) = get_print_offset(val) - last = (-1, -1, -1) - while True: - (h, m, s) = [int(x) for x in time.strftime('%H %M %S', time.localtime()).split(' ')] - if not val: - s = None - if h != last[0] or m != last[1] or s != last[2]: - print('\033[H\033[2J', end='') - print_time(h, m, s, x, y) - print('\033[1;1H', end='') - sys.stdout.flush() - last = (h, m, s) - time.sleep(0.1) - diff --git a/src/mongoclock.c b/src/mongoclock.c index 8ff3676..9d822e5 100644 --- a/src/mongoclock.c +++ b/src/mongoclock.c @@ -219,7 +219,7 @@ int main(int argc, char* argv[]) const char** digits[9]; size_t x = 0, y = 0; struct winsize winsize; - int small = 0, fd; + int small = 0, fd = -1; struct itimerspec itimerspec; char _buf[8]; @@ -247,7 +247,7 @@ int main(int argc, char* argv[]) if (caught_sigwinch) { caught_sigwinch = 0; - t (TEMP_FAILURE_RETRY(ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize))); + t (TEMP_FAILURE_RETRY(ioctl(STDOUT_FILENO, (unsigned long)TIOCGWINSZ, &winsize))); y = winsize.ws_row; x = winsize.ws_col; if (y < DY) small = 2; @@ -287,7 +287,7 @@ int main(int argc, char* argv[]) print_time(digits, y, x); - if (read(fd, _buf, 8) < 0) + if (read(fd, _buf, (size_t)8) < 0) if (errno != EINTR) goto fail; } @@ -301,7 +301,8 @@ int main(int argc, char* argv[]) perror(*argv); fprintf(stdout, "\033[?25h\n\033[?1049l"); fflush(stdout); - TEMP_FAILURE_RETRY(close(fd)); + if (fd >= 0) + TEMP_FAILURE_RETRY(close(fd)); return 1; (void) argc; } |