-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4694b37
commit e32b8ac
Showing
7 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
VERSION := v0.1.0 | ||
BINDIR := bin | ||
BINARY := standup | ||
override LDFLAGS += | ||
override CFLAGS += -static -Dbin_name=$(BINARY) -Dstandup_version=$(VERSION) -Dgit_sha=$(shell git rev-parse HEAD) -O3 | ||
|
||
PREFIX = /usr/local | ||
|
||
UNAME_S = $(shell uname -s) | ||
|
||
MACOS_MANPAGE_LOC = /usr/share/man | ||
LINUX_MAPPAGE_LOC = $(PREFIX)/man/man8 | ||
|
||
$(BINDIR)/$(BINARY): $(BINDIR) clean | ||
ifeq ($(UNAME_S),FreeBSD) | ||
$(CC) main.c $(CFLAGS) -o $@ $(LDFLAGS) -I$(PREFIX)/include -L$(PREFIX)/lib | ||
else | ||
$(CC) main.c $(CFLAGS) -o $@ $(LDFLAGS) | ||
endif | ||
|
||
$(BINDIR): | ||
mkdir -p $@ | ||
|
||
$(DEPDIR): | ||
mkdir -p $@ | ||
|
||
.PHONY: install | ||
install: $(BINDIR)/$(BINARY) | ||
mkdir -p $(PREFIX)/bin | ||
cp $(BINDIR)/$(BINARY) $(PREFIX)/bin | ||
|
||
.PHONY: uninstall | ||
uninstall: | ||
rm -f $(PREFIX)/$(BINDIR)/$(BINARY) | ||
|
||
.PHONY: deps | ||
deps: $(DEPDIR) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(BINDIR)/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <time.h> | ||
#include <unistd.h> | ||
|
||
#define STR1(x) #x | ||
#define STR(x) STR1(x) | ||
|
||
// USAGE contains the application usage. | ||
#define USAGE \ | ||
"usage: %s [-vh] [-f]\n\ | ||
-v version\n\ | ||
-h help\n\ | ||
-f create a new file. default name: yyyy-mm-dd\n" | ||
|
||
// STANDUP_TEMPLATE contains the base information to be filled out with | ||
// today's and tomorrow's dates. This is then ready to be used to be | ||
// further fleshed out. | ||
#define STANDUP_TEMPLATE \ | ||
"Yesterday:\n\ | ||
* \n\n\ | ||
Today:\n\ | ||
* \n\n\ | ||
PRs:\n\ | ||
* \n\n" | ||
|
||
#define DATE_BUF_SZ 11 | ||
|
||
// date_format for getting the year, month, and day in yyyy-mm-dd format. | ||
static const char* date_format = "%lu-%02lu-%02lu"; | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
int file_output = 0; | ||
FILE *out; | ||
|
||
int c; | ||
if (argc > 1) { | ||
while ((c = getopt(argc, argv, "hvf")) != -1) { | ||
switch (c) { | ||
case 'h': | ||
printf(USAGE, STR(bin_name)); | ||
return 0; | ||
case 'v': | ||
printf("%s %s - git: %s\n", | ||
STR(bin_name), | ||
STR(standup_version), | ||
STR(git_sha)); | ||
return 0; | ||
case 'f': | ||
file_output = 1; | ||
break; | ||
default: | ||
printf(USAGE, STR(bin_name)); | ||
return 1; | ||
} | ||
} | ||
} | ||
|
||
time_t s = time(NULL); | ||
struct tm *now = localtime(&s); | ||
|
||
int year = now->tm_year + 1900; | ||
int month = now->tm_mon + 1; | ||
|
||
char today[DATE_BUF_SZ]; | ||
sprintf(today, date_format, year, month, now->tm_mday); | ||
|
||
// check if the output needs to be written to a file. If so, set the output | ||
// to the file descriptor derived from "today's" date, otherwise set it to | ||
// STDOUT. | ||
if (file_output) { | ||
out = fopen(today, "w"); | ||
} else { | ||
out = stdout; | ||
} | ||
|
||
fprintf(out, STANDUP_TEMPLATE); | ||
fclose(out); | ||
|
||
return 0; | ||
} |