Add stopwatch

Store DEBIAN/control in src/ until build. This makes the gitignore,
clean, etc. simpler.
This commit is contained in:
Dylan Lom 2020-11-29 14:56:37 +11:00
parent c819f5107f
commit b1fc2508d3
4 changed files with 72 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
*.deb
a.out
dist/usr
dist

View File

@ -1,6 +1,7 @@
all: djl-utils.deb
dist: sign pasta suptime timestamp
dist: bin DEBIAN.control
bin: sign pasta suptime stopwatch timestamp
sign: src/sign
cp src/sign dist/usr/bin
@ -11,9 +12,16 @@ pasta: src/pasta
suptime: src/suptime.c
cc -o dist/usr/bin/suptime src/suptime.c
stopwatch: src/stopwatch.c
cc -o dist/usr/bin/stopwatch src/stopwatch.c
timestamp: src/timestamp
cp src/timestamp dist/usr/bin
DEBIAN.control: src/DEBIAN/control
rm -rf dist/DEBIAN
cp -r src/DEBIAN dist/DEBIAN
djl-utils.deb: dist
dpkg-deb -b dist
mv dist.deb dist/djl-utils.deb
@ -22,4 +30,4 @@ install: djl-utils.deb
dpkg -i dist/djl-utils.deb
clean:
rm -f dist/usr/bin/* dist/djl-utils.deb
rm -rf dist

61
src/stopwatch.c Normal file
View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Dylan Lom <djl@dylanlom.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include <poll.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
const char* argv0;
void usage() {
fprintf(stderr, "usage: %s\n", argv0);
exit(1);
}
void printtime(int t) {
printf("\rstopwatch: %d", t);
fflush(stdout);
}
#define SHIFT_ARGS() argv++; argc--;
int main(int argc, char* argv[]) {
argv0 = argv[0];
SHIFT_ARGS();
if (argc > 0) usage();
time_t t = 0;
int pollrs = 0;
/* Use non-canoncial mode on stdin */
struct termios old, new;
tcgetattr(0, &old);
tcgetattr(0, &new);
new.c_lflag &= ~(ICANON | ECHO);
new.c_cc[VMIN] = 0;
new.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &new);
struct pollfd fds[1] = {{ .fd = 0, .events = POLLIN }};
while (pollrs < 1) {
printtime(t);
t++;
pollrs = poll(fds, 1, 1000);
}
puts("\n");
tcsetattr(0, TCSANOW, &old);
return 0;
}