]> Pileus Git - lackey/commitdiff
Some organization
authorAndy Spencer <andy753421@gmail.com>
Fri, 12 Oct 2012 04:43:10 +0000 (04:43 +0000)
committerAndy Spencer <andy753421@gmail.com>
Fri, 12 Oct 2012 04:52:06 +0000 (04:52 +0000)
18 files changed:
cal/dummy.c
config.mk.example
makefile
src/date.c [new file with mode: 0644]
src/date.h [new file with mode: 0644]
src/event.c
src/event.h
src/main.c
src/main.h [deleted file]
src/screen.c
src/screen.h
src/test.c
src/util.c
src/util.h
view/day.c
view/month.c
view/week.c
view/year.c

index da4b8ee6e5abefdf6832063a1f1e0ec69992825c..1e40fec5c5c6dc3be96b36e5ddc6f7a19f40560e 100644 (file)
@@ -17,7 +17,8 @@
 
 #include <stdlib.h>
 
-#include "main.h"
+#include "util.h"
+#include "date.h"
 #include "event.h"
 
 /* Test data */
index 1942a0ccd23c81be90abb0aab3e1b39ed71734c1..d3ce06a01499b24fa76b6f4557863bd2795353e0 100644 (file)
@@ -1 +1,2 @@
-default: run-lackey
+CFLAGS = -g -Wall -Werror --std=c99
+default: all run-lackey
index 08012b62af8ce77ec0b9d175d79b2593aee50cd2..e8bd692a458ac43933e03c9b346b56ece658dff1 100644 (file)
--- a/makefile
+++ b/makefile
@@ -8,9 +8,9 @@ LDFLAGS  ?= -lncursesw
 
 # Sources
 PROG      = lackey
+PROG_SRC  = main screen date event util 
 TEST      = test
-SOURCES   = main screen event util
-TESTS     = test util
+TEST_SRC  = test date
 VIEWS     = day week month year todo notes settings help
 CALS      = dummy
 
@@ -25,14 +25,14 @@ run-$(TEST): $(TEST)
        ./$<
 
 clean:
-       rm -f src/*.o view/*.o $(PROG) $(TEST) 
+       rm -f src/*.o view/*.o cal/*.o $(PROG) $(TEST) 
 
 # Rules
-$(PROG): $(SOURCES:%=src/%.o) $(VIEWS:%=view/%.o) $(CALS:%=cal/%.o)
+$(PROG): $(PROG_SRC:%=src/%.o) $(VIEWS:%=view/%.o) $(CALS:%=cal/%.o)
        $(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
 
-$(TEST): $(TESTS:%=src/%.o) $(VIEWS:%=view/%.o) $(CALS:%=cal/%.o)
+$(TEST): $(TEST_SRC:%=src/%.o) $(CALS:%=cal/%.o)
        $(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
 
-%.o: %.c $(SOURCES:%=src/%.h) makefile
+%.o: %.c $(wildcard src/*.h) makefile
        $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
diff --git a/src/date.c b/src/date.c
new file mode 100644 (file)
index 0000000..eebbe79
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Time Keeping Bugs Abound! */
+
+#include <stdio.h>
+#include <time.h>
+
+#include "date.h"
+
+/* Global data */
+year_t  YEAR;
+month_t MONTH;
+day_t   DAY;
+
+/* Initialize */
+void date_init(void)
+{
+       time_t     sec = time(NULL);
+       struct tm *tm  = localtime(&sec);
+
+       YEAR  = tm->tm_year+1900;
+       MONTH = tm->tm_mon;
+       DAY   = tm->tm_mday-1;
+}
+
+/* Time functions */
+int is_leap_year(year_t year)
+{
+       return (year % 400 == 0) ? 1 :
+              (year % 100 == 0) ? 0 :
+              (year % 4   == 0) ? 1 : 0;
+}
+
+int days_in_year(year_t year)
+{
+       return 365 + is_leap_year(year);
+}
+
+int days_in_month(year_t year, month_t month)
+{
+       static int mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+       int days = mdays[month];
+       if (month == FEB)
+               days += is_leap_year(year);
+       return days;
+}
+
+int weeks_in_month(year_t year, month_t month)
+{
+       int start = start_of_month(year, month);
+       int days  = days_in_month(year, month);
+       return ((start + days)-1) / 7 + 1;
+}
+
+wday_t day_of_week(year_t year, month_t month, day_t day)
+{
+       static int tmp[] = {0, 3, 2, 5, 0, 3,
+                           5, 1, 4, 6, 2, 4};
+       if (month < MAR)
+               year--;
+       int start = year + year / 4
+                        - year / 100
+                        + year / 400
+                        + tmp[month];
+       return (start + day + 1) % 7;
+}
+
+wday_t start_of_month(year_t year, month_t month)
+{
+       return day_of_week(year, month, 0);
+}
+
+void add_days(year_t *year, month_t *month, day_t *day, int days)
+{
+       time_t time = mktime(&(struct tm){
+                       .tm_year = *year-1900,
+                       .tm_mon  = *month,
+                       .tm_mday = *day+1,
+                       .tm_hour = 12});
+       time  += days*24*60*60;
+       struct tm *tm = localtime(&time);
+       *year  = tm->tm_year+1900;
+       *month = tm->tm_mon;
+       *day   = tm->tm_mday-1;
+}
+
+void add_months(year_t *year, month_t *month, int months)
+{
+       int total = *year*12 + *month + months;
+       *year  = total / 12;
+       *month = total % 12;
+}
+
+/* Debug functions */
+const char *month_to_str(month_t month)
+{
+       static const char *map[] =
+               { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+                 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", };
+       return map[month%12];
+}
+const char *month_to_string(month_t month)
+{
+       static const char *map[] =
+               { "January",   "February", "March",    "April",
+                 "May",       "June",     "July",     "August",
+                 "September", "October",  "November", "December" };
+       return map[month%12];
+}
+
+const char *day_to_st(wday_t day)
+{
+       static const char *map[] =
+               { "Su","Mo", "Tu", "We", "Th", "Fr", "Sa" };
+       return map[day%7];
+}
+const char *day_to_str(wday_t day)
+{
+       static const char *map[] =
+               { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
+       return map[day%7];
+}
+const char *day_to_string(wday_t day)
+{
+       static const char *map[] =
+               { "Sunday",   "Monday", "Tuesday", "Wednesday",
+                 "Thursday", "Friday", "Saturday" };
+       return map[day%7];
+}
+
+/* Test functions */
+void test_time(void)
+{
+       printf("Info\n");
+       printf("  Year Month     Start Weeks Days\n");
+       for (int y = 2012; y <= 2012; y++)
+       for (int m = JAN;  m <= DEC;  m++) {
+               printf("  %-5d",  y);
+               printf("  %-10s", month_to_string(m));
+               printf("  %-6s",  day_to_str(start_of_month(y,m)));
+               printf("  %-6d",  weeks_in_month(y,m));
+               printf("  %-2d",  days_in_month(y,m));
+               printf("\n");
+       }
+}
diff --git a/src/date.h b/src/date.h
new file mode 100644 (file)
index 0000000..77f7341
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Time types */
+typedef int year_t;
+typedef int day_t;
+typedef int hour_t;
+typedef int min_t;
+
+typedef enum {
+       JAN =  0,
+       FEB =  1,
+       MAR =  2,
+       APR =  3,
+       MAY =  4,
+       JUN =  5,
+       JUL =  6,
+       AUG =  7,
+       SEP =  8,
+       OCT =  9,
+       NOV = 10,
+       DEC = 11,
+} month_t;
+
+typedef enum {
+       SUN = 0,
+       MON = 1,
+       TUE = 2,
+       WED = 3,
+       THU = 4,
+       FRI = 5,
+       SAT = 6,
+} wday_t;
+
+/* Global data */
+extern year_t  YEAR;
+extern month_t MONTH;
+extern day_t   DAY;
+
+/* Initialize */
+void date_init(void);
+
+/* Time functions */
+int is_leap_year(year_t year);
+int days_in_year(year_t year);
+int days_in_month(year_t year, month_t month);
+int weeks_in_month(year_t year, month_t month);
+wday_t day_of_week(year_t year, month_t month, day_t day);
+wday_t start_of_month(year_t year, month_t month);
+day_t start_of_week(year_t year, month_t month, day_t day);
+void add_days(year_t *year, month_t *month, day_t *day, int days);
+void add_months(year_t *year, month_t *month, int months);
+
+/* Time to string functions */
+const char *month_to_str(month_t month);
+const char *month_to_string(month_t month);
+const char *day_to_st(wday_t day);
+const char *day_to_str(wday_t day);
+const char *day_to_string(wday_t day);
+
+/* Tests */
+void test_time(void);
index ed3a343fa2c78d05d93a9f3204b99683f3805260..76d33cef4f6d174a753b86a2e0f8df581edf6a3f 100644 (file)
  */
 
 #include "util.h"
+#include "date.h"
 #include "event.h"
 
+/* Global data */
+event_t *EVENTS;
+
+/* Initialize */
+void event_init(void)
+{
+       EVENTS = event_get(2012, JAN, 0, 366);
+
+       /* Debug */
+       for (event_t *e = EVENTS; e; e = e->next)
+               debug("event: %04d-%02d-%02d %02d:%02d: %s - %s\n",
+                               e->start.year, e->start.month, e->start.day,
+                               e->start.hour, e->start.min, e->name, e->desc);
+}
+
 /* Event get */
 event_t *event_get(year_t year, month_t month, day_t day, int days)
 {
index 501741da15ab6b6b74cc89d109d4437f833ff0eb..199e1dc9da9998960452ca6c51c3ebc270ed75ef 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef EVENT_H
-#define EVENT_H
-
-#include "util.h"
-
 /* Calendar types */
 typedef struct {
        char *name;
@@ -45,10 +40,12 @@ typedef struct event_t {
        struct event_t *next;
 } event_t;
 
+/* Global data */
+extern event_t *EVENTS;
+
 /* Event functions */
+void event_init(void);
 event_t *event_get(year_t year, month_t month, day_t day, int days);
 
 /* Calendar implementation functions */
 event_t *dummy_get(cal_t *cal, year_t year, month_t month, day_t day, int days);
-
-#endif
index 6daa8f8cfcfcdf9770065c6948758d397ce1ffb5..4be87502b6224040c53358dda14cfb29cd2fd69b 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdarg.h>
 #include <stdlib.h>
 #include <signal.h>
-#include <time.h>
 #include <locale.h>
 #include <ncurses.h>
 
-#include "main.h"
+#include "util.h"
+#include "date.h"
+#include "event.h"
 #include "screen.h"
 
-/* Debugging */
-year_t   YEAR   = 2012;
-month_t  MONTH  = 8;
-day_t    DAY    = 29;
-
-event_t *EVENTS = NULL;
-
-/* Static data */
-static FILE *debug_fd = NULL;
-
 /* Control-C handler, so we don't hose the therminal */
 static void on_sigint(int signum)
 {
@@ -42,47 +32,13 @@ static void on_sigint(int signum)
        exit(0);
 }
 
-/* Debugging functions */
-int debug(char *fmt, ...)
-{
-       int rval;
-       va_list ap;
-
-       /* Log to debug file */
-       va_start(ap, fmt);
-       vfprintf(debug_fd, "debug: ", ap);
-       rval = vfprintf(debug_fd, fmt, ap);
-
-       /* Log to status bar */
-       va_start(ap, fmt);
-       mvhline(LINES-2, 0, ACS_HLINE, COLS);
-       move(LINES-1, 0);
-       attron(COLOR_PAIR(COLOR_ERROR));
-       vwprintw(stdscr, fmt, ap);
-       attroff(COLOR_PAIR(COLOR_ERROR));
-       clrtoeol();
-
-       va_end(ap);
-       return rval;
-}
-
 /* Main */
 int main(int argc, char **argv)
 {
        /* Misc setup */
        signal(SIGINT, on_sigint);
-       debug_fd = fopen("/tmp/lackey.log", "w+");
-
-       /* Time setup */
-       time_t sec = time(NULL);
-       struct tm *tm = localtime(&sec);
-       YEAR   = tm->tm_year+1900;
-       MONTH  = tm->tm_mon;
-       DAY    = tm->tm_mday-1;
-
-       EVENTS = event_get(2012, JAN, 0, 366);
 
-       /* Curses setup */
+       /* Setup Curses */
        setlocale(LC_ALL, "");
        initscr();
        cbreak();
@@ -93,14 +49,15 @@ int main(int argc, char **argv)
        mousemask(ALL_MOUSE_EVENTS, NULL);
        init_pair(COLOR_TITLE, COLOR_GREEN, COLOR_BLACK);
        init_pair(COLOR_ERROR, COLOR_RED,   COLOR_BLACK);
+
+       /* Initialize */
+       util_init();
+       date_init();
+       event_init();
        screen_init();
-       screen_draw();
 
-       /* Debug */
-       for (event_t *e = EVENTS; e; e = e->next)
-               debug("event: %04d-%02d-%02d %02d:%02d: %s - %s\n",
-                               e->start.year, e->start.month, e->start.day,
-                               e->start.hour, e->start.min, e->name, e->desc);
+       /* Draw initial screen */
+       screen_draw();
 
        /* Run */
        while (1) {
@@ -128,8 +85,8 @@ int main(int argc, char **argv)
                }
                if (screen_run(chr, btn.bstate, btn.y, btn.x))
                        continue;
-               //debug("Unhandled key: Dec %3d,  Hex %02x,  Oct %03o,  Chr <%c>\n",
-               //              chr, chr, chr, chr);
+               debug("main: Unhandled key - Dec %3d,  Hex %02x,  Oct %03o,  Chr <%c>\n",
+                               chr, chr, chr, chr);
        }
 
        /* Cleanup, see also on_sigint */
diff --git a/src/main.h b/src/main.h
deleted file mode 100644 (file)
index cdc5c82..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MAIN_H
-#define MAIN_H
-
-#define COLOR_TITLE 1
-#define COLOR_ERROR 2
-
-#include "util.h"
-#include "event.h"
-
-/* Debugging */
-extern year_t   YEAR;
-extern month_t  MONTH;
-extern day_t    DAY;
-
-extern event_t *EVENTS;
-
-/* Debug functions */
-int debug(char *fmt, ...);
-
-#endif
index c1c655aa455816cbb766cfa2049afe2dd9d00b80..1618f1022451c1ea3f8a1c07524b3fdb86625333 100644 (file)
 
 #include <string.h>
 #include <ncurses.h>
-#include "main.h"
-#include "screen.h"
+
 #include "util.h"
+#include "date.h"
+#include "screen.h"
 
 /* Types */
 typedef struct {
index f5b86713e81ad7f3dc195eabbad05a1fbacd811a..bce2383b4c09347f8742d9126eeea3c5ddfcc75b 100644 (file)
@@ -15,8 +15,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SCREEN_H
-#define SCREEN_H
+/* Configuration */
+#define COLOR_TITLE 1
+#define COLOR_ERROR 2
 
 /* Screen functions */
 void screen_init(void);
@@ -53,5 +54,3 @@ int todo_run(int,mmask_t,int,int);
 int notes_run(int,mmask_t,int,int);
 int settings_run(int,mmask_t,int,int);
 int help_run(int,mmask_t,int,int);
-
-#endif
index 86eb8c50480d59dcc70f437d25ab933e27c0bf7f..9255c9417d3eff1adb5044985ca4c6289cac6087 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "util.h"
-
-int YEAR  = 2012;
-int MONTH = 8;
-int DAY   = 29;
+#include "date.h"
 
 int main(int argc, char **argv)
 {
index e40fa8e2c6c747dfb575f4ec84cc93004f96e47a..53f5cef71f691aa6b7ad3be9bd43520f9a609328 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* Time Keeping Bugs Abound! */
-
 #include <stdio.h>
-#include <time.h>
+#include <ncurses.h>
 
-#include "util.h"
+#include "screen.h"
 
-/* Time functions */
-int is_leap_year(year_t year)
-{
-       return (year % 400 == 0) ? 1 :
-              (year % 100 == 0) ? 0 :
-              (year % 4   == 0) ? 1 : 0;
-}
+/* Static data */
+static FILE *debug_fd = NULL;
 
-int days_in_year(year_t year)
+/* Initialize */
+void util_init(void)
 {
-       return 365 + is_leap_year(year);
+       debug_fd = fopen("/tmp/lackey.log", "w+");
 }
 
-int days_in_month(year_t year, month_t month)
+/* Debugging functions */
+int debug(char *fmt, ...)
 {
-       static int mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-       int days = mdays[month];
-       if (month == FEB)
-               days += is_leap_year(year);
-       return days;
-}
+       int rval;
+       va_list ap;
 
-int weeks_in_month(year_t year, month_t month)
-{
-       int start = start_of_month(year, month);
-       int days  = days_in_month(year, month);
-       return ((start + days)-1) / 7 + 1;
-}
-
-wday_t day_of_week(year_t year, month_t month, day_t day)
-{
-       static int tmp[] = {0, 3, 2, 5, 0, 3,
-                           5, 1, 4, 6, 2, 4};
-       if (month < MAR)
-               year--;
-       int start = year + year / 4
-                        - year / 100
-                        + year / 400
-                        + tmp[month];
-       return (start + day + 1) % 7;
-}
-
-wday_t start_of_month(year_t year, month_t month)
-{
-       return day_of_week(year, month, 0);
-}
-
-void add_days(year_t *year, month_t *month, day_t *day, int days)
-{
-       time_t time = mktime(&(struct tm){
-                       .tm_year = *year-1900,
-                       .tm_mon  = *month,
-                       .tm_mday = *day+1,
-                       .tm_hour = 12});
-       time  += days*24*60*60;
-       struct tm *tm = localtime(&time);
-       *year  = tm->tm_year+1900;
-       *month = tm->tm_mon;
-       *day   = tm->tm_mday-1;
-}
-
-void add_months(year_t *year, month_t *month, int months)
-{
-       int total = *year*12 + *month + months;
-       *year  = total / 12;
-       *month = total % 12;
-}
-
-/* Debug functions */
-const char *month_to_str(month_t month)
-{
-       static const char *map[] =
-               { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-                 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", };
-       return map[month%12];
-}
-const char *month_to_string(month_t month)
-{
-       static const char *map[] =
-               { "January",   "February", "March",    "April",
-                 "May",       "June",     "July",     "August",
-                 "September", "October",  "November", "December" };
-       return map[month%12];
-}
-
-const char *day_to_st(wday_t day)
-{
-       static const char *map[] =
-               { "Su","Mo", "Tu", "We", "Th", "Fr", "Sa" };
-       return map[day%7];
-}
-const char *day_to_str(wday_t day)
-{
-       static const char *map[] =
-               { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
-       return map[day%7];
-}
-const char *day_to_string(wday_t day)
-{
-       static const char *map[] =
-               { "Sunday",   "Monday", "Tuesday", "Wednesday",
-                 "Thursday", "Friday", "Saturday" };
-       return map[day%7];
-}
+       /* Log to debug file */
+       if (debug_fd) {
+               va_start(ap, fmt);
+               vfprintf(debug_fd, "debug: ", ap);
+               rval = vfprintf(debug_fd, fmt, ap);
+       }
 
-/* Test functions */
-void test_time(void)
-{
-       printf("Info\n");
-       printf("  Year Month     Start Weeks Days\n");
-       for (int y = 2012; y <= 2012; y++)
-       for (int m = JAN;  m <= DEC;  m++) {
-               printf("  %-5d",  y);
-               printf("  %-10s", month_to_string(m));
-               printf("  %-6s",  day_to_str(start_of_month(y,m)));
-               printf("  %-6d",  weeks_in_month(y,m));
-               printf("  %-2d",  days_in_month(y,m));
-               printf("\n");
+       /* Log to status bar */
+       if (stdscr) {
+               va_start(ap, fmt);
+               mvhline(LINES-2, 0, ACS_HLINE, COLS);
+               move(LINES-1, 0);
+               attron(COLOR_PAIR(COLOR_ERROR));
+               vwprintw(stdscr, fmt, ap);
+               attroff(COLOR_PAIR(COLOR_ERROR));
+               clrtoeol();
        }
+
+       va_end(ap);
+       return rval;
 }
index 9b2755162379e9e3160c5d554c6b6ba50295e039..98fb33285a8b40c242703b93843c5e3d52329c93 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef UTIL_H
-#define UTIL_H
-
 /* Macros */
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
 #define MAX(a,b) ((a) > (b) ? (a) : (b))
 #define ROUND(x) ((int)((x)+0.5))
 #define N_ELEMENTS(x) (sizeof(x)/sizeof((x)[0]))
 
-/* Time types */
-typedef int year_t;
-typedef int day_t;
-typedef int hour_t;
-typedef int min_t;
-
-typedef enum {
-       JAN =  0,
-       FEB =  1,
-       MAR =  2,
-       APR =  3,
-       MAY =  4,
-       JUN =  5,
-       JUL =  6,
-       AUG =  7,
-       SEP =  8,
-       OCT =  9,
-       NOV = 10,
-       DEC = 11,
-} month_t;
-
-typedef enum {
-       SUN = 0,
-       MON = 1,
-       TUE = 2,
-       WED = 3,
-       THU = 4,
-       FRI = 5,
-       SAT = 6,
-} wday_t;
-
-/* Time functions */
-int is_leap_year(year_t year);
-int days_in_year(year_t year);
-int days_in_month(year_t year, month_t month);
-int weeks_in_month(year_t year, month_t month);
-wday_t day_of_week(year_t year, month_t month, day_t day);
-wday_t start_of_month(year_t year, month_t month);
-day_t start_of_week(year_t year, month_t month, day_t day);
-void add_days(year_t *year, month_t *month, day_t *day, int days);
-void add_months(year_t *year, month_t *month, int months);
-
-/* Time to string functions */
-const char *month_to_str(month_t month);
-const char *month_to_string(month_t month);
-const char *day_to_st(wday_t day);
-const char *day_to_str(wday_t day);
-const char *day_to_string(wday_t day);
-
-/* Tests */
-void test_time(void);
+/* Debug functions */
+void util_init(void);
 
+/* Debug functions */
+#ifdef DEBUG
+int debug(char *fmt, ...);
+#else
+#define debug(...)
 #endif
index 5d206720d01ac6faa27af1151676e17fa3a297ea..7761c9532aa497b6b950af85489e74b1e3fd562b 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <string.h>
 #include <ncurses.h>
 
-#include "main.h"
-#include "util.h"
+#include "date.h"
 
 /* Static data */
 static WINDOW *win;
index 60f6b601c4c01347a296175e6bc65d112f0f4e5d..5642c6df00a7d244ccdbd5ab4815d672b60be598 100644 (file)
@@ -20,8 +20,8 @@
 #include <string.h>
 #include <ncurses.h>
 
-#include "main.h"
 #include "util.h"
+#include "date.h"
 
 /* Static data */
 static WINDOW *win;
index 40d5b086406620d1c1e506f5dbbc894188b90e99..230a7c58778f9eb94f51bdd93420a0c3e9d712b4 100644 (file)
 
 #define _XOPEN_SOURCE_EXTENDED
 
-#include <string.h>
 #include <ncurses.h>
 
-#include "main.h"
 #include "util.h"
+#include "date.h"
+#include "event.h"
 
 /* Static data */
 static WINDOW *win;
@@ -33,7 +33,8 @@ static void print_event(event_t *event, wday_t day, hour_t hour, min_t min, floa
        int y = 3+hour*4;
        int l = (event->end.min - event->start.min)/15;
        mvwprintw(win, y, x, "%s", event->name);
-       debug("event: %s\n", event->name);
+       debug("week: event = %s\n", event->name);
+       (void)l;
 }
 
 static int before(datetime_t *start, int year, int month, int day, int hour, int min)
@@ -43,7 +44,7 @@ static int before(datetime_t *start, int year, int month, int day, int hour, int
                   start->day   < day   ? 1 : start->day   > day  ? 0 :
                   start->hour  < hour  ? 1 : start->hour  > hour ? 0 :
                   start->min   < min   ? 1 : start->min   > min  ? 0 : 0;
-       debug("%04d-%02d-%02d %02d:%02d < %04d-%02d-%02d %02d:%02d == %d\n",
+       debug("week: %04d-%02d-%02d %02d:%02d < %04d-%02d-%02d %02d:%02d == %d\n",
                        start->year, start->month, start->day, start->hour, start->min,
                        year, month, day, hour, min, rval);
        return rval;
index 16522c836534d22e158a330c380df38f36c30b05..04beba66ca0dc9e871e18abf2b7dea32bdf8472b 100644 (file)
@@ -18,8 +18,8 @@
 #include <string.h>
 #include <ncurses.h>
 
-#include "main.h"
 #include "util.h"
+#include "date.h"
 
 /* Constants */
 #define MW (2*7+6)