From 5a0c5630e0bcc5e06beb856c666f7eaedd1c9559 Mon Sep 17 00:00:00 2001 From: foswret Date: Thu, 11 Dec 2025 23:40:02 -0600 Subject: updated Makefile, renamed output to calp and main.c/main.o to calp.c/calp.o --- .gitignore | 2 +- 0.pdf | Bin 5505 -> 5506 bytes Makefile | 24 ++++++++++----- README.md | 16 +++++----- src/calp.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/calp.o | Bin 0 -> 13272 bytes src/main.c | 97 ---------------------------------------------------------- 7 files changed, 129 insertions(+), 112 deletions(-) create mode 100644 src/calp.c create mode 100644 src/calp.o delete mode 100644 src/main.c diff --git a/.gitignore b/.gitignore index 73283e0..50f0bac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -output +calp 0.pdf main.o draw.o diff --git a/0.pdf b/0.pdf index 0157847..8b56078 100644 Binary files a/0.pdf and b/0.pdf differ diff --git a/Makefile b/Makefile index 67861a0..5e9411d 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,25 @@ +VERSION = 0.0 +PREFIX = /usr/local CC = cc DIR = src -OBJS = $(DIR)/draw.o $(DIR)/main.o -CAIROI = `pkg-config --cflags -libs cairo cairo-pdf` -.PHONY: clean all +OBJS = $(DIR)/draw.o $(DIR)/calp.o +LIBS = -lcairo +.PHONY: clean all install CFLAGS = -O2 -g -Wall -Werror -Wextra -Winit-self -Wuninitialized -pedantic -all: output +all: calp -output: $(OBJS) - $(CC) $(CAIROI) -o output $(OBJS) +calp: $(OBJS) + $(CC) $(LIBS) -o calp $(OBJS) clean: - -rm -f $(OBJS) output + -rm -f $(OBJS) calp + +install: all + mkdir -p ${DESTDIR}${PREFIX}/bin + cp -f calp ${DESTDIR}${PREFIX}/bin + chmod 755 ${DESTDIR}${PREFIX}/bin/calp + +uninstall: + rm -f ${DESTDIR}${PREFIX}/bin/calp diff --git a/README.md b/README.md index 8e6b231..7f274a5 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,18 @@ # Calp -`calp` attempts to generate clear and attractive calendars that can be printed. +calp attempts to generate dry and attractive calendars that can be printed. It is designed to be extensible and customizable for a wide range of calendar designs. # Dependencies - `cairo` -- `pkg-config` -# Build -- `make` +# Install +- `make clean install` + +# Uninstall +- `make uninstall` # Planned Features - Arguments (`getopts`) -- Holidays -- Moon Phases -- Month Art - Custom layout file parsing (config files) +- Holidays (.csv files) +- Month Art +- Moon Phases diff --git a/src/calp.c b/src/calp.c new file mode 100644 index 0000000..278538e --- /dev/null +++ b/src/calp.c @@ -0,0 +1,102 @@ +/* Standard Libraries */ +#include +#include +#include +#include +#include +#include +#include + +/* Cairo Libraries */ +#include +#include + +/* calp Libraries */ +#include "color.h" +#include "date.h" +#include "draw.h" + +// int main (int argc, char *argv[]) { +int main (void) { + /* Dimension initialization */ + int rows = 6; /* Number of weeks in a month */ + int columns = 7; /* Number of days in a week */ + double margin = 0.5; /* 0.5" */ + int number_of_days = 28; + + double month_origin_x = margin; + double month_origin_y = 3.0; + double paper_width = 8.5; + double paper_height = 11; + double month_width = paper_width - (month_origin_x * 2); + double month_height = paper_height - month_origin_y - margin; + double day_box_width = month_width / columns; + double day_box_height = month_height / rows; + + struct dimensions dim = { + paper_width, /* pw */ + paper_height, /* ph */ + month_width, /* mw */ + month_height, /* mh */ + day_box_width, /* bw */ + day_box_height, /* bh */ + rows, /* r */ + columns, /* c */ + margin, /* m */ + }; + + /* Date Setup */ + char *months[] = { + "January", "February", "March", "April", "May", + "June", "July", "August", "September", "October", + "November", "December" + }; + + //int days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + // const char *weekday_names[] = { + // "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" + // }; + + // const char *weekdays_abbr[] = { + // "Su", "Mo", "Tue", "Wed", "Thurs", "Fri", "Sat" + // }; + + int year = 2025; + int month = 2; + + struct tm day; + day.tm_mon = month - 1; + day.tm_mday = 1; + day.tm_year = year - 1900; + + /* tm.hour, tm_min, & tm_sec are not used, but need to be zeroed. */ + day.tm_hour = 0; + day.tm_min = 0; + day.tm_sec = 0; + + mktime(&day); + + cairo_surface_t * surface = cairo_pdf_surface_create("0.pdf", dim.pw * 72, dim.ph * 72); + cairo_t *cr = cairo_create(surface); + + + cairo_scale(cr, 72, 72); + set_color(cr, "GRAY"); + cairo_set_line_width (cr, 0.03); + + + clock_t begin = clock(); + draw_calendar(cr, month_origin_x, month_origin_y, dim); + draw_numbers(cr, month_origin_x, month_origin_y, dim, day.tm_wday, number_of_days); + draw_month_name(cr, months[1], dim); + + /* Clean Up */ + cairo_destroy(cr); + cairo_surface_destroy(surface); + + clock_t end = clock(); + double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; + printf("Execution Time: %.3fs\n", time_spent); + return(0); +} diff --git a/src/calp.o b/src/calp.o new file mode 100644 index 0000000..23e90f5 Binary files /dev/null and b/src/calp.o differ diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 6d76a6d..0000000 --- a/src/main.c +++ /dev/null @@ -1,97 +0,0 @@ -/* Standard Libraries */ -#include -#include -#include -#include -#include -#include -#include - -/* Cairo Libraries */ -#include -#include - -/* calp Libraries */ -#include "color.h" -#include "date.h" -#include "draw.h" - -// int main (int argc, char *argv[]) { -int main (void) { - /* Dimension initialization */ - int rows = 6; /* Number of weeks in a month */ - int columns = 7; /* Number of days in a week */ - double margin = 0.5; /* 0.5" */ - int number_of_days = 28; - - double month_origin_x = margin; - double month_origin_y = 3.0; - double paper_width = 8.5; - double paper_height = 11; - double month_width = paper_width - (month_origin_x * 2); - double month_height = paper_height - month_origin_y - margin; - double day_box_width = month_width / columns; - double day_box_height = month_height / rows; - - struct dimensions dim = { - paper_width, /* pw */ - paper_height, /* ph */ - month_width, /* mw */ - month_height, /* mh */ - day_box_width, /* bw */ - day_box_height, /* bh */ - rows, /* r */ - columns, /* c */ - margin, /* m */ - }; - - /* Date Setup */ - char *months[] = { - "January", "February", "March", "April", "May", - "June", "July", "August", "September", "October", - "November", "December" - }; - - //int days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - - // const char *weekday_names[] = { - // "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" - // }; - - // const char *weekdays_abbr[] = { - // "Su", "Mo", "Tue", "Wed", "Thurs", "Fri", "Sat" - // }; - - int year = 2025; - int month = 2; - - struct tm day; - day.tm_mon = month - 1; - day.tm_mday = 1; - day.tm_year = year - 1900; - - /* tm.hour, tm_min, & tm_sec are not used, but need to be zeroed. */ - day.tm_hour = 0; - day.tm_min = 0; - day.tm_sec = 0; - - mktime(&day); - - cairo_surface_t * surface = cairo_pdf_surface_create("0.pdf", dim.pw * 72, dim.ph * 72); - cairo_t *cr = cairo_create(surface); - - - cairo_scale(cr, 72, 72); - set_color(cr, "GRAY"); - cairo_set_line_width (cr, 0.03); - - - draw_calendar(cr, month_origin_x, month_origin_y, dim); - draw_numbers(cr, month_origin_x, month_origin_y, dim, day.tm_wday, number_of_days); - draw_month_name(cr, months[1], dim); - - /* Clean Up */ - cairo_destroy(cr); - cairo_surface_destroy(surface); - return(0); -} -- cgit v1.2.3