diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit acf7e34483a6a0dc37952b62885882a5df0583a0
parent 33642883543c509b050c969c684d1f4023143a05
Author: Johnathan Jenkins <john@nixheads.co.uk>
Date:   Tue, 20 Dec 2016 12:02:11 -0800

travis gitignore mac freebsd

Diffstat:
A.gitignore | 3+++
A.travis.yml | 12++++++++++++
MMakefile | 6+++++-
MREADME.md | 1+
Mdiary.c | 18++++++++++++++++--
Mdiary.h | 5+++++
6 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,3 @@ +diary +*.o +*.gch diff --git a/.travis.yml b/.travis.yml @@ -0,0 +1,12 @@ +language: c + +os: + - linux + - osx + +compiler: + - gcc + - clang + +script: + - make diff --git a/Makefile b/Makefile @@ -7,12 +7,16 @@ CC = gcc CFLAGS = -Wall UNAME = ${shell uname} +ifeq ($(UNAME),FreeBSD) + LIBS = -lncurses +endif + ifeq ($(UNAME),Linux) LIBS = -lncursesw endif ifeq ($(UNAME),Darwin) - LIBS = -lncurses + LIBS = -lncurses -framework CoreFoundation endif diff --git a/README.md b/README.md @@ -14,6 +14,7 @@ This is a text based diary, inspired by [khal](https://github.com/pimutils/khal) ``` make ``` +Note: for *BSD users run gmake. 3. Install the binary (optional): ``` diff --git a/diary.c b/diary.c @@ -303,7 +303,13 @@ int main(int argc, char** argv) { { // references: locale(5) and util-linux's cal.c // get the base date, 8-digit integer (YYYYMMDD) returned as char * - unsigned long d = (uintptr_t) nl_langinfo(_NL_TIME_WEEK_1STDAY); + #ifdef _NL_TIME_WEEK_1STDAY + unsigned long d = (uintptr_t) nl_langinfo(_NL_TIME_WEEK_1STDAY); + // reference: https://sourceware.org/glibc/wiki/Locales + // assign a static date value 19971130 (a Sunday) + #else + unsigned long d = 19971130; + #endif struct tm base = { .tm_sec = 0, .tm_min = 0, @@ -314,7 +320,15 @@ int main(int argc, char** argv) { }; mktime(&base); // first_weekday is base date's day of the week offset by (_NL_TIME_FIRST_WEEKDAY - 1) - first_weekday = (base.tm_wday + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % 7; + #ifdef __linux__ + first_weekday = (base.tm_wday + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % 7; + #elif defined __MACH__ + CFIndex first_day_of_week; + CFCalendarRef currentCalendar = CFCalendarCopyCurrent(); + first_day_of_week = CFCalendarGetFirstWeekday(currentCalendar); + CFRelease(currentCalendar); + first_weekday = (base.tm_wday + first_day_of_week - 1) % 7; + #endif } setup_cal_timeframe(); diff --git a/diary.h b/diary.h @@ -1,6 +1,11 @@ #ifndef DIARY #define DIARY + +#ifdef __MACH__ + #include <CoreFoundation/CoreFoundation.h> +#endif +#include <stdint.h> #include <stdlib.h> #include <unistd.h> #include <string.h>