Commit 522ee251 authored by Romain Bignon's avatar Romain Bignon

add cleanup and proper help

parent 02f8897c
This diff is collapsed.
/*
* Copyright(C) 2010 Romain Bignon
*
* 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, version 2 of the License.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "data.h"
static struct period* insert_period(struct data* data, struct period* prev, struct period* next, time_t start, time_t end)
......
/*
* Copyright(C) 2010 Romain Bignon
*
* 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, version 2 of the License.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _DATA_H
#define _DATA_H
#include <stdlib.h>
#define IDLE_TIME 60*60
#define IDLE_TIME 2*60*60
struct period
{
......
/*
* Copyright(C) 2010 Romain Bignon
*
* 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, version 2 of the License.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
......
/*
* Copyright(C) 2010 Romain Bignon
*
* 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, version 2 of the License.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _FILE_H
#define _FILE_H
......
/*
* Copyright(C) 2010 Romain Bignon
*
* 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, version 2 of the License.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <Imlib2.h>
#include <time.h>
#include <stdio.h>
......
/*
* Copyright(C) 2010 Romain Bignon
*
* 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, version 2 of the License.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _IMAGE_H
#define _IMAGE_H
......
/*
* Copyright(C) 2010 Romain Bignon
*
* 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, version 2 of the License.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
......@@ -35,19 +52,28 @@ static int start_job(const char *filename, struct nick *nicks, int* hsock, fd_se
return 0;
}
static void usage(const char* progname, int is_help)
static void cleanup(struct data* data, struct nick* nicks, struct event* events)
{
FILE* f;
if (is_help)
f = stderr;
else
f = stdout;
struct period* p = data->periods;
while(p)
{
struct period* next = p->next;
free(p);
p = next;
}
fprintf(f, "Usage: %s [-j <nprocess>] logsfiles ...\n", progname);
while(nicks)
{
struct nick* next = nicks->next;
free(nicks);
nicks = next;
}
if (is_help)
while(events)
{
fprintf(f, "\nThis program blabla\n");
struct event* next = events->next;
free(events);
events = next;
}
}
......@@ -76,13 +102,54 @@ static void print_progress(float x, float tot)
fflush(stdout);
}
static void usage(const char* progname, int is_help)
{
FILE* f;
if (is_help)
f = stderr;
else
f = stdout;
fprintf(f, "Usage: %s [-h] [-j <nprocess>] [-o <filename>] [-q] [-n <nickname>] [-e <event>] logsfiles ...\n", progname);
if (is_help)
{
fprintf(f, "\nThis program parses irssi logs and generate a graph to display\n");
fprintf(f, "when you are idling on IRC.\n");
fprintf(f, "You can set your nickname(s), and add events which are added on\n");
fprintf(f, "graph correlate your IRC (in)activity with your own life.\n");
fprintf(f, "\nOptions:\n");
fprintf(f, " -j, --jobs=N Number of simultaneous jobs.\n");
fprintf(f, " -o, --output=FILENAME Output filename (default=output.png).\n");
fprintf(f, " -h, --help Print this message and exit.\n");
fprintf(f, " -q, --quiet Don't print anything.\n");
fprintf(f, " -n, --nickname NICKNAME Add a nickname.\n");
fprintf(f, " -e, --event FROM[,TO][,LABEL] Add an event.\n");
fprintf(f, " In form: dd/mm/yyyy[,dd/mm/yyyy][,label]\n");
fprintf(f, "\nExample:\n");
fprintf(f, " $ irssleep -j 5 -n romain -n vaginus -e 1/6/2003,1/8/2006,School\\\n");
fprintf(f, " -e \"10/12/2006,Irssi at home\" -e 10/7/2008/,27/08/2009,INL\\\n");
fprintf(f, " -e 1/12/2009,1/1/2011,Proformatique irclogs/**/*\n");
}
}
static void version(void)
{
printf("irssleep v1.0\n");
printf("\nCopyright(C) 2010 Romain Bignon\n");
printf("This program is free software; you can redistribute it and/or modify\n");
printf("it under the terms of the GNU General Public License as published by\n");
printf("the Free Software Foundation, version 2 of the License.\n");
}
int main(int argc, char **argv)
{
static struct option long_options[] =
{
{ "forks", 1, NULL, 'j' },
{ "jobs", 1, NULL, 'j' },
{ "output", 1, NULL, 'o' },
{ "help", 1, NULL, 'h' },
{ "version", 1, NULL, 'v' },
{ "quiet", 1, NULL, 'q' },
{ "nickname", 1, NULL, 'n' },
{ "event", 1, NULL, 'e' },
......@@ -92,13 +159,14 @@ int main(int argc, char **argv)
int nprocess = 1;
int quiet = 0;
int hsock = 0;
int ret;
fd_set fdset;
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:e:", long_options, &option_index)) != -1)
while((i = getopt_long(argc, argv, "qo:j:vhn:e:", long_options, &option_index)) != -1)
switch(i)
{
case 'q':
......@@ -151,12 +219,19 @@ int main(int argc, char **argv)
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);
if (!ev->from.tm_mday)
{
fprintf(stderr, "-e: invalid syntax (-e dd/mm/yyyy[,dd/mm/yyyy][,label]])\n");
free(ev);
exit(EXIT_FAILURE);
}
ev->next = events;
events = ev;
break;
};
case 'v':
version();
exit(EXIT_SUCCESS);
case 'h':
usage(argv[0], 1);
exit(EXIT_SUCCESS);
......@@ -251,5 +326,9 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
exit(create_image(&data, imagefile, events, quiet));
ret = create_image(&data, imagefile, events, quiet);
cleanup(&data, nicks, events);
exit(ret);
}
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