Commit 3855d8d4 authored by Romain Bignon's avatar Romain Bignon

-e parameter to add events on generated graph

parent 45e3e7bb
......@@ -4,6 +4,7 @@
#include <string.h>
#include "data.h"
#include "image.h"
static void print_date(const char *text, time_t t)
{
......@@ -27,7 +28,7 @@ static time_t reset_day(time_t ts)
return mktime(&lt);
}
int create_image(struct data* data, const char *filename, int quiet)
int create_image(struct data* data, const char *filename, struct event* events, int quiet)
{
const char *ext;
struct period *p;
......@@ -91,6 +92,30 @@ int create_image(struct data* data, const char *filename, int quiet)
imlib_image_fill_rectangle(xgraph + i, ygraph, 1, hgraph);
}
}
for(; events; events = events->next)
{
int from, to;
from = difftime(mktime(&events->from), first)/(3600*24);
if (from < 0)
from = 0;
if (from > days)
from = days;
imlib_context_set_color(255, 255, 255, 255);
imlib_context_set_image(image);
if (events->to.tm_mday > 0)
{
to = difftime(mktime(&events->to), first)/(3600*24);
imlib_text_draw(xgraph + from + 2, ygraph - 27, events->label);
imlib_image_fill_rectangle(xgraph + from, ygraph - 7, to - from, 1);
}
else
{
imlib_text_draw(xgraph + from + 5, ygraph - 45, events->label);
imlib_image_fill_rectangle(xgraph + from, ygraph - 40, 1, 25);
}
}
imlib_free_font();
for (p = data->periods; p; p = p->next)
......
#ifndef _IMAGE_H
#define _IMAGE_H
#include <time.h>
struct data;
extern int create_image(struct data* data, const char *filename, int quiet);
struct event
{
struct tm from;
struct tm to;
char label[50];
struct event* next;
};
extern int create_image(struct data* data, const char *filename, struct event* events, int quiet);
#endif /* _IMAGE_H */
......@@ -84,7 +84,8 @@ int main(int argc, char **argv)
{ "output", 1, NULL, 'o' },
{ "help", 1, NULL, 'h' },
{ "quiet", 1, NULL, 'q' },
{ "nicknames", 1, NULL, 'n' },
{ "nickname", 1, NULL, 'n' },
{ "event", 1, NULL, 'e' },
{ NULL, 0, NULL, 0 }
};
int option_index = 0, i;
......@@ -95,8 +96,9 @@ int main(int argc, char **argv)
struct data data = {0};
char imagefile[100] = "output.png";
struct nick* nicks = NULL;
struct event* events = NULL;
while((i = getopt_long(argc, argv, "qo:j:hn:", long_options, &option_index)) != -1)
while((i = getopt_long(argc, argv, "qo:j:hn:e:", long_options, &option_index)) != -1)
switch(i)
{
case 'q':
......@@ -121,6 +123,40 @@ int main(int argc, char **argv)
}
break;
}
case 'e':
{
char *ptr = strdupa(optarg);
struct event* ev = calloc(sizeof(struct event), 1);
char *start;
while ((start = strsep(&ptr, ",")))
{
int dd = 0, mm = 0, yy = 0;
if (sscanf(start, "%d/%d/%d", &dd, &mm, &yy) == 3)
{
if (yy > 1900)
yy -= 1900;
if (ev->from.tm_mday == 0)
{
ev->from.tm_mday = dd;
ev->from.tm_mon = mm - 1;
ev->from.tm_year = yy;
}
else
{
ev->to.tm_mday = dd;
ev->to.tm_mon = mm - 1;
ev->to.tm_year = yy;
}
}
else
strncpy(ev->label, start, sizeof(ev->label));
}
printf("%d/%d/%d -> %d/%d/%d: [%s]\n", ev->from.tm_mday, ev->from.tm_mon, ev->from.tm_year,
ev->to.tm_mday, ev->to.tm_mon, ev->to.tm_year, ev->label);
ev->next = events;
events = ev;
break;
};
case 'h':
usage(argv[0], 1);
exit(EXIT_SUCCESS);
......@@ -215,5 +251,5 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
exit(create_image(&data, imagefile, quiet));
exit(create_image(&data, imagefile, events, quiet));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment