#include <string.h>
#include <regex.h>
+/* Options */
+#define REFRESH_TIME 3600
+#define W3C_LINK
+
/* Config */
#define MAXUSERS 5000
#define MAXNICKLENGTH 50
#define MINWORDLENGTH 5
/* irssistats */
-#define VERSION "0.41"
+#define VERSION "0.42"
#define URL "http://royale.zerezo.com/programmation/irssistats/"
/* Counters */
{ "AVGLETTERS", "lettres/lignes" },
{ "HOURS", "heures" },
{ "QUOTE", "message aléatoire" },
- { "TOPUSERSTIME", "Personnes les plus actives par période de la journée" },
+ { "TOPUSERSTIME", "Personnes les plus actives par période de la journée" },
{ "RANDTOPICS", "Quelques topics" },
{ "CHANGEDBY", "changé par" },
{ "NEWTOPIC", "nouveau topic" },
int hours[4];
char quote[MAXQUOTELENGTH+1];
int counters[NBCOUNTERS];
+ int temp;
} users[MAXUSERS];
int nbusers=0;
for (j=0;j<4;j++) users[i].hours[j]=users[i-1].hours[j];
strcpy(users[i].quote,users[i-1].quote);
for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=users[i-1].counters[j];
+ users[i].temp=users[i-1].temp;
}
strcpy(users[start].nick,nick);
users[start].lines=0;
for (j=0;j<4;j++) users[start].hours[j]=0;
users[start].quote[0]='\0';
for (j=0;j<NBCOUNTERS;j++) users[start].counters[j]=0;
+ users[start].temp=0;
}
return(start);
}
if (argc==6)
{
+ for (i=0;i<nbusers;i++) users[i].temp=users[i].lines;
if ((fic=fopen(argv[5],"rt"))==NULL) { fprintf(stderr,"can't open nick file\n"); exit(1); }
while (fscanf(fic,"%s",line)==1)
{
user=dichotomic(line);
fscanf(fic,"%s",line);
if (regcomp(&preg,line,0)!=0) { fprintf(stderr,"error in nick file"); exit(1); }
- temp=users[user].lines;
for (i=0;i<nbusers;i++) if ((i!=user) && (regexec(&preg,users[i].nick,0,0,0)==0) && (users[i].lines>=0))
{
- if (users[i].lines>temp) /* for nick alias, keep the random quote of the most used nick */
+ if (users[i].temp>users[user].temp) /* for nick alias, keep the random quote of the most used nick */
{
strcpy(users[user].quote,users[i].quote);
- temp=users[i].lines;
+ users[user].temp=users[i].temp;
}
users[user].lines+=users[i].lines;
users[user].letters+=users[i].letters;
/*** HTML ***/
/* header */
+ printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n\n");
printf("<!-- Generated by irssistats %s : %s -->\n\n",VERSION,URL);
- printf("<html>\n\n<head>\n<base target=\"_blank\">\n<title>");
+ printf("<html>\n\n<head>\n<title>");
printf(L("HEADER"),channel,maintainer);
- printf("</title>\n</head>\n\n");
- printf("<body bgcolor=\"%s\" text=\"%s\" link=\"%s\" vlink=\"%s\" alink=\"%s\">\n\n<center>\n\n<font color=\"%s\"><h1>",T("BGCOLOR"),T("TEXT"),T("LINK"),T("VLINK"),T("ALINK"),T("TITLE1"));
+ printf("</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
+#ifdef REFRESH_TIME
+ printf("<meta http-equiv=\"Refresh\" content=\"%d\">\n",REFRESH_TIME);
+#endif
+ printf("<base target=\"_blank\">\n</head>\n\n");
+ printf("<body bgcolor=\"%s\" text=\"%s\" link=\"%s\" vlink=\"%s\" alink=\"%s\">\n\n<center>\n\n<font color=\"%s\" size=\"+3\"><b>",T("BGCOLOR"),T("TEXT"),T("LINK"),T("VLINK"),T("ALINK"),T("TITLE1"));
printf(L("HEADER"),channel,maintainer);
- printf("</h1></font>\n%s<br>\n<br><br>\n\n",ctime(&debut));
+ printf("</b></font><br><br>\n%s<br>\n<br><br>\n\n",ctime(&debut));
/* legend */
- printf("<font color=\"%s\"><h3>%s</h3></font>\n<table bgcolor=%s>\n<tr>\n",T("TITLE2"),L("LEGEND"),T("BGTABLE"));
- for (i=0;i<4;i++) printf("<td><img src=\"h%d.png\" width=\"40\" height=\"15\"></td><td> : %s %d-%d</td><td width=\"10\"></td>\n",i+1,L("HOURS"),i*6,i*6+5);
+ printf("<font color=\"%s\" size=\"+1\"><b>%s</b></font><br><br>\n<table bgcolor=\"%s\">\n<tr>\n",T("TITLE2"),L("LEGEND"),T("BGTABLE"));
+ for (i=0;i<4;i++) printf("<td><img src=\"h%d.png\" width=\"40\" height=\"15\" alt=\"\"></td><td> : %s %d-%d</td><td width=\"10\"></td>\n",i+1,L("HOURS"),i*6,i*6+5);
printf("</tr>\n</table>\n<br><br>\n\n");
/* last days */
- printf("<font color=\"%s\"><h3>%s</h3></font>\n<table>\n<tr>\n",T("TITLE2"),L("LASTDAYS"));
+ printf("<font color=\"%s\" size=\"+1\"><b>%s</b></font><br><br>\n<table>\n<tr>\n",T("TITLE2"),L("LASTDAYS"));
max=-1;
for (i=30;i>=0;i--) if (lastdays[i].lines>max) max=lastdays[i].lines;
for (i=30;i>=0;i--)
{
printf("<td width=\"15\" align=\"center\" valign=\"bottom\"><font size=\"-2\">%d</font><br>",lastdays[i].lines);
- for (j=0;j<4;j++) if (lastdays[i].hours[j]!=0) printf("<img src=\"v%d.png\" width=\"15\" height=\"%d\"><br>",j+1,150*lastdays[i].hours[j]/max);
+ for (j=0;j<4;j++) if (lastdays[i].hours[j]!=0) printf("<img src=\"v%d.png\" width=\"15\" height=\"%d\" alt=\"\"><br>",j+1,150*lastdays[i].hours[j]/max);
printf("</td>\n");
}
printf("</tr>\n<tr>\n");
for (i=30;i>=0;i--)
- printf("<td align=\"center\" valign=\"center\" bgcolor=\"%s\">%d</td>\n",T("BGTABLE"),i);
+ printf("<td align=\"center\" valign=\"middle\" bgcolor=\"%s\">%d</td>\n",T("BGTABLE"),i);
printf("</tr>\n</table>\n<br><br>\n\n");
/* top hours */
- printf("<font color=\"%s\"><h3>%s</h3></font>\n<table>\n<tr>\n",T("TITLE2"),L("TOPHOURS"));
+ printf("<font color=\"%s\" size=\"+1\"><b>%s</b></font><br><br>\n<table>\n<tr>\n",T("TITLE2"),L("TOPHOURS"));
max=-1;
for (i=0;i<24;i++) if (hours[i]>max) max=hours[i];
for (i=0;i<24;i++)
{
printf("<td width=\"15\" align=\"center\" valign=\"bottom\"><font size=\"-2\">%.1f%%</font><br>",lines!=0?(float)100*hours[i]/lines:0);
- if (hours[i]!=0) printf("<img src=\"v%d.png\" width=\"15\" height=\"%d\"><br>",i/6+1,150*hours[i]/max);
+ if (hours[i]!=0) printf("<img src=\"v%d.png\" width=\"15\" height=\"%d\" alt=\"\"><br>",i/6+1,150*hours[i]/max);
printf("</td>\n");
}
printf("</tr>\n<tr>\n");
for (i=0;i<24;i++)
- printf("<td align=\"center\" valign=\"center\" bgcolor=\"%s\">%d</td>\n",T("BGTABLE"),i);
+ printf("<td align=\"center\" valign=\"middle\" bgcolor=\"%s\">%d</td>\n",T("BGTABLE"),i);
printf("</tr>\n</table>\n<br><br>\n\n");
/* top users */
- printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("TOPUSERS"));
+ printf("<font color=\"%s\" size=\"+1\"><b>%s</b></font><br><br>\n",T("TITLE2"),L("TOPUSERS"));
printf("<table>\n<tr><td></td><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\" colspan=\"2\">%s</td><td bgcolor=\"%s\">%s</td>\n",T("BGTITLE"),L("NICK"),T("BGTITLE"),L("NBLINES"),T("BGTITLE"),L("HOURS"),T("BGTITLE"),L("AVGLETTERS"),T("BGTITLE"),L("QUOTE"));
for (i=1;i<=NBUSERS;i++)
{
if (user!=-1)
{
printf("<tr><td bgcolor=\"%s\" align=\"right\">%d</td><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%d</td><td bgcolor=\"%s\">",T("BGTABLE"),i,T("BGTABLE"),users[user].nick,T("BGTABLE"),users[user].lines,T("BGTABLE"));
- for (j=0;j<4;j++) if (users[user].hours[j]!=0) printf("<img src=\"h%d.png\" width=\"%d\" height=\"15\">",j+1,100*users[user].hours[j]/users[user].lines);
- printf("</td><td bgcolor=\"%s\">%d</td><td bgcolor=\"%s\"><img src=\"hm.png\" width=\"%d\" height=\"15\"></td><td bgcolor=\"%s\">\"",T("BGTABLE"),users[user].lines!=0?users[user].letters/users[user].lines:0,T("BGTABLE"),users[user].lines!=0?users[user].letters/users[user].lines:0,T("BGTABLE"));
+ for (j=0;j<4;j++) if (users[user].hours[j]!=0) printf("<img src=\"h%d.png\" width=\"%d\" height=\"15\" alt=\"\">",j+1,100*users[user].hours[j]/users[user].lines);
+ printf("</td><td bgcolor=\"%s\">%d</td><td bgcolor=\"%s\"><img src=\"hm.png\" width=\"%d\" height=\"15\" alt=\"\"></td><td bgcolor=\"%s\">\"",T("BGTABLE"),users[user].lines!=0?users[user].letters/users[user].lines:0,T("BGTABLE"),users[user].lines!=0?users[user].letters/users[user].lines:0,T("BGTABLE"));
printhtml(users[user].quote);
printf("\"</td></tr>\n");
users[user].lines=-1;
printf("<br><br>\n\n");
/* top users by time */
- printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("TOPUSERSTIME"));
+ printf("<font color=\"%s\" size=\"+1\"><b>%s</b></font><br><br>\n",T("TITLE2"),L("TOPUSERSTIME"));
printf("<table>\n<tr><td></td>");
for (i=0;i<4;i++) printf("<td bgcolor=\"%s\" colspan=\"2\">%s %d-%d</td>",T("BGTITLE"),L("HOURS"),i*6,i*6+5);
printf("</tr>\n");
printf("</table>\n<br><br>\n\n");
/* random topics */
- printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("RANDTOPICS"));
+ printf("<font color=\"%s\" size=\"+1\"><b>%s</b></font><br><br>\n",T("TITLE2"),L("RANDTOPICS"));
printf("<table>\n<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td></tr>\n",T("BGTITLE"),L("CHANGEDBY"),T("BGTITLE"),L("NEWTOPIC"));
for (i=nbtopics<NBTOPICS?nbtopics-1:NBTOPICS-1;i>=0;i--)
{
printf("</table>\n<br><br>\n\n");
/* random urls */
- printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("RANDURLS"));
+ printf("<font color=\"%s\" size=\"+1\"><b>%s</b></font><br><br>\n",T("TITLE2"),L("RANDURLS"));
printf("<table>\n<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td></tr>\n",T("BGTITLE"),L("POSTEDBY"),T("BGTITLE"),L("POSTEDURL"));
for (i=nburls<NBURLS?nburls-1:NBURLS-1;i>=0;i--)
{
- printf("<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">\"<a href=\"%s\">",T("BGTABLE"),urls[i].nick,T("BGTABLE"),urls[i].url);
+ printf("<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">\"<a href=\"",T("BGTABLE"),urls[i].nick,T("BGTABLE"));
+ printhtml(urls[i].url);
+ printf("\">");
printhtml(urls[i].shorturl);
printf("</a>\"</td></tr>\n");
}
printf("</table>\n<br><br>\n\n");
/* top words */
- printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("TOPWORDS"));
+ printf("<font color=\"%s\" size=\"+1\"><b>%s</b></font><br><br>\n",T("TITLE2"),L("TOPWORDS"));
printf("<table>\n<tr><td></td><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td></tr>\n",T("BGTITLE"),L("WORD"),T("BGTITLE"),L("OCCURRENCES"));
for (i=0;i<NBWORDS;i++)
if (topwords[i].nb!=0) printf("<tr><td bgcolor=\"%s\" align=\"right\">%d</td><td bgcolor=\"%s\">\"%s\"</td><td bgcolor=\"%s\">%d</td></tr>\n",T("BGTABLE"),i+1,T("BGTABLE"),topwords[i].word,T("BGTABLE"),topwords[i].nb);
printf("</table>\n<br><br>\n\n");
/* big numbers */
- printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("BIGNUMBERS"));
+ printf("<font color=\"%s\" size=\"+1\"><b>%s</b></font><br><br>\n",T("TITLE2"),L("BIGNUMBERS"));
printf("<table>\n<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td></tr>\n",T("BGTITLE"),L("NICK"),T("BGTITLE"),L("NUMBERS"),T("BGTITLE"),L("NBLINES"));
for (i=0;i<NBCOUNTERS;i++)
{
/* footer */
printf(L("TIME"),totallines,days,(int)(time(NULL)-debut));
printf("<br>\n%s <a href=\"%s\">irssistats %s</a>",L("FOOTER"),URL,VERSION);
+#ifdef W3C_LINK
+ printf("<br><br>\n\n<a href=\"http://validator.w3.org/check/referer\"><img src=\"valid-html401.gif\" border=\"0\" height=\"31\" width=\"88\"alt=\"Valid HTML 4.01!\"></a>");
+#endif
printf("\n\n</center>\n\n</body>\n\n</html>\n");
return(0);