diary

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

commit a0052bb9bcbfe963d6af01c7c11c7b4e15009f4c
parent aad0f553e637410356370fd87a31b9e689262289
Author: Andreas Gruhler <andreas.gruhler@uzh.ch>
Date:   Wed, 21 Dec 2016 00:03:47 +0100

Merge pull request #32 from shaggytwodope/master

travis gitignore mac freebsd fixes #31
Diffstat:
A.gitignore | 3+++
A.travis.yml | 12++++++++++++
MMakefile | 6+++++-
MREADME.md | 1+
Mdiary.c | 42++++++++++++++++++++++++++++--------------
Mdiary.h | 5+++++
6 files changed, 54 insertions(+), 15 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 @@ -301,20 +301,34 @@ int main(int argc, char** argv) { } #ifdef __GNU_LIBRARY__ - // 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); - struct tm base = { - .tm_sec = 0, - .tm_min = 0, - .tm_hour = 0, - .tm_mday = d % 100, - .tm_mon = (d / 100) % 100 - 1, - .tm_year = d / (100 * 100) - 1900 - }; - 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; + // references: locale(5) and util-linux's cal.c + // get the base date, 8-digit integer (YYYYMMDD) returned as char * + #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, + .tm_hour = 0, + .tm_mday = d % 100, + .tm_mon = (d / 100) % 100 - 1, + .tm_year = d / (100 * 100) - 1900 + }; + mktime(&base); + // first_weekday is base date's day of the week offset by (_NL_TIME_FIRST_WEEKDAY - 1) + #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 #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>