Browse Source

init

master
Emil 7 months ago
commit
86bf168eea
No known key found for this signature in database GPG Key ID: 5432DB986FDBCF8A
4 changed files with 94 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +18
    -0
      Makefile
  3. +25
    -0
      README
  4. +49
    -0
      clock.c

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
clock
clock~

+ 18
- 0
Makefile View File

@@ -0,0 +1,18 @@
#!/bin/make -f

CFLAGS := -std=c99 -Os -s -Wall -Wextra -Wpedantic
CPPFLAGS :=
INSTALL := /usr/local
PROGN := clock

$(PROGN): clock.c
$(CC) $(CFLAGS) -pipe -o $@ $<
gzexe $@

clean:
-rm $(PROGN) $(PROGN)~

install: $(PROGN)
install -m 755 $< $(INSTALL)/bin/

.PHONY: clean install all

+ 25
- 0
README View File

@@ -0,0 +1,25 @@
/-------------------------------\
| Clock |
\-------------------------------/

It's just a clock.

The executable is compressed, if you compile it and it fails to run, run `mv clock~ clock` and try again.

Building: make or baked

CPPFLAGS='...
PERIOD - Inteval which the clock will update by.
CLEAR - The control code for clearing the terminal.
CLEAR_DUMB - How it clears on a dumb terminal, 127 newlines is enough.
'

These definitions may be omitted without issue.

Installing: make install INSTALL=/usr/local PROGN=clock
INSTALL - Installation location, should be somewhere within the PATH.
PROGN - A overridable program name, change it if you want to.

Licensed under the public domain.

This line makes the README as exactly as long as the code.

+ 49
- 0
clock.c View File

@@ -0,0 +1,49 @@
/* clock.c - Public Domain - It's a digital clock
EXEC:
cc -O1 -s -pipe -Wall -Wextra -Wpedantic $CPPFLAGS -o clock clock.c && gzexe clock
:STOP */
#include <time.h>
#include <stdio.h>
#include <unistd.h>

#ifndef CLEAR
# define CLEAR "\033[2J"
#endif

#ifndef CLEAR_DUMB
# define CLEAR_DUMB "\n"
#endif

#ifndef PERIOD
# define PERIOD 5
#endif

char * hmstime(struct tm * tm)
{
static char time[9];
sprintf(time, "%.2d:%.2d:%.2d",
tm->tm_hour, tm->tm_min, tm->tm_sec);
return time;
}

int
main(void)
{
struct tm * tm;
time_t now;
int sec;

puts("Type C-c to exit.\n");

for (;;)
{
time(&now);
tm = gmtime(&now);
/* Junk character may be printed, this is the time to get a new terminal. */
printf(CLEAR " %s\n" CLEAR_DUMB, hmstime(tm));
sec = tm->tm_sec % PERIOD;
sleep(!sec ? PERIOD : PERIOD - sec);
}

return 0;
}