Commit 45e3e7bb authored by Romain Bignon's avatar Romain Bignon

parameter -n to set my nickname(s)

parent c8bac7ef
......@@ -4,7 +4,7 @@ OBJ=main.o \
image.o
%.o: %.c
gcc -ggdb -Wall -Wextra -Wno-unused-parameter `imlib2-config --cflags` -c $<
gcc -ggdb -D_GNU_SOURCE -Wall -Wextra -Wno-unused-parameter `imlib2-config --cflags` -c $<
all: $(OBJ)
gcc -o irssleep $(OBJ) `imlib2-config --libs`
......
......@@ -5,12 +5,13 @@
#include <unistd.h>
#include "data.h"
#include "file.h"
static int is_in_list(const char *elem, const char **list)
static int is_in_list(const char *elem, struct nick *list)
{
for(; *list && strcasecmp(elem, *list); ++list)
for(; list && strcasecmp(elem, list->nick); list = list->next)
;
return *list != NULL;
return list != NULL;
}
static int str2mon(const char *str)
......@@ -66,7 +67,7 @@ static int write_ts(int fd, time_t start, time_t end)
return write(fd, &ts, sizeof(ts));
}
int parse_file(int fd, const char **nicknames, const char *filename)
int parse_file(int fd, struct nick *nicknames, const char *filename)
{
char *line = NULL;
size_t len = 0;
......
#ifndef _FILE_H
#define _FILE_H
int parse_file(int fd, const char **nicknames, const char *filename);
struct nick
{
char nick[50];
struct nick* next;
};
int parse_file(int fd, struct nick *nicknames, const char *filename);
#endif /* _FILE_H */
......@@ -47,7 +47,7 @@ int create_image(struct data* data, const char *filename, int quiet)
}
const int xgraph = 50;
const int ygraph = 0;
const int ygraph = 50;
const int hgraph = 24*6;
const int wgraph = days;
Imlib_Image image = imlib_create_image(xgraph + wgraph,
......@@ -86,9 +86,9 @@ int create_image(struct data* data, const char *filename, int quiet)
}
if (lt.tm_wday == 0 || lt.tm_wday == 6)
{
imlib_context_set_color(50, 50, 50, 255);
imlib_context_set_color(30, 30, 30, 255);
imlib_context_set_image(image);
imlib_image_fill_rectangle(xgraph + i, 0, 1, hgraph);
imlib_image_fill_rectangle(xgraph + i, ygraph, 1, hgraph);
}
}
imlib_free_font();
......
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <time.h>
......@@ -10,7 +11,7 @@
#include "data.h"
#include "file.h"
static int start_job(const char *filename, const char **nicks, int* hsock, fd_set *fdset)
static int start_job(const char *filename, struct nick *nicks, int* hsock, fd_set *fdset)
{
int notify_pipe[2];
......@@ -83,6 +84,7 @@ int main(int argc, char **argv)
{ "output", 1, NULL, 'o' },
{ "help", 1, NULL, 'h' },
{ "quiet", 1, NULL, 'q' },
{ "nicknames", 1, NULL, 'n' },
{ NULL, 0, NULL, 0 }
};
int option_index = 0, i;
......@@ -92,9 +94,9 @@ int main(int argc, char **argv)
fd_set fdset;
struct data data = {0};
char imagefile[100] = "output.png";
const char *nicks[] = {"romain", "Progs", "vaginus", "pr0gs", "pr0g5", "progsme", NULL};
struct nick* nicks = NULL;
while((i = getopt_long(argc, argv, "qo:j:h", long_options, &option_index)) != -1)
while((i = getopt_long(argc, argv, "qo:j:hn:", long_options, &option_index)) != -1)
switch(i)
{
case 'q':
......@@ -106,6 +108,19 @@ int main(int argc, char **argv)
case 'j':
nprocess = atoi(optarg);
break;
case 'n':
{
char *ptr = strdupa(optarg);
char *nick;
while((nick = strsep(&ptr, ",")))
{
struct nick *n = calloc(sizeof(struct nick), 1);
strncpy(n->nick, nick, sizeof(n->nick));
n->next = nicks;
nicks = n;
}
break;
}
case 'h':
usage(argv[0], 1);
exit(EXIT_SUCCESS);
......
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