version 0.32
[irssistats] / irssistats.c
1 /* Usage: cat /path/to/file.log | ./irssistats channel maintainer language theme > /path/to/file.html */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <time.h>
6 #include <string.h>
7
8 /* Config */
9 #define MAXUSERS 5000
10 #define MAXNICKLENGTH 50
11 #define MAXLINELENGTH 2000
12 #define MAXQUOTELENGTH 100
13 #define NBUSERS 50
14 #define NBUSERSTIME 10
15 #define NBURLS 5
16 #define NBTOPICS 5
17 #define NBWORDS 20
18 #define MINWORDLENGTH 5
19
20 /* irssistats */
21 #define VERSION "0.32"
22 #define URL "http://royale.zerezo.com/programmation/irssistats/"
23
24 /* Counters */
25 #define D_SMILE     0
26 #define D_FROWN     1
27 #define D_EXCLAM    2
28 #define D_QUESTION  3
29 #define D_ME        4
30 #define D_TOPIC     5
31 #define D_MODE      6
32 #define D_KICK      7
33 #define D_KICKED    8
34 #define D_URL       9
35 #define D_JOIN      10
36 #define D_NICK      11
37 #define D_MONOLOGUE 12
38 #define NBCOUNTERS  13
39 char *counters[NBCOUNTERS]={"C_SMILE","C_FROWN","C_EXCLAM","C_QUESTION","C_ME","C_TOPIC","C_MODE","C_KICK","C_KICKED","C_URL","C_JOIN","C_NICK","C_MONOLOGUE"};
40
41 /* Languages */
42 #define NBLANGUAGES 4
43 #define NBKEYS 38
44 char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and abbreviation */
45 {
46   { /* English language */
47     { "English",      "en" },
48     { "HEADER",       "Statistics for #%s by %s" },
49     { "LEGEND",       "Legend" },
50     { "LASTDAYS",     "Lastdays statistics" },
51     { "TOPHOURS",     "Hourly statistics" },
52     { "TOPUSERS",     "Most active people" },
53     { "OTHERS",       "There are %d left not ranked..." },
54     { "NBLINES",      "lines" },
55     { "NICK",         "nick" },
56     { "AVGLETTERS",   "letters/lines" },
57     { "HOURS",        "hours" },
58     { "QUOTE",        "random message" },
59     { "TOPUSERSTIME", "Most active people by time of day" },
60     { "RANDTOPICS",   "Some topics" },
61     { "CHANGEDBY",    "changed by" },
62     { "NEWTOPIC",     "new topic" },
63     { "RANDURLS",     "Some URLs" },
64     { "POSTEDBY",     "posted by" },
65     { "POSTEDURL",    "URL" },
66     { "TOPWORDS",     "Most used words" },
67     { "WORD",         "word" },
68     { "OCCURRENCES",  "occurrences" },
69     { "BIGNUMBERS",   "Some big numbers..." },
70     { "NUMBERS",      "numbers" },
71     { "TIME",         "%d lines parsed in %d seconds" },
72     { "FOOTER",       "Statistics generated by" },
73     { "C_SMILE",      "is often happy :)" },
74     { "C_FROWN",      "is often sad :(" },
75     { "C_EXCLAM",     "yells a lot !" },
76     { "C_QUESTION",   "asks a lot of questions ?" },
77     { "C_ME",         "likes /me command" },
78     { "C_TOPIC",      "often changes the topic" },
79     { "C_MODE",       "often changes the modes" },
80     { "C_KICK",       "likes to /kick" },
81     { "C_KICKED",     "is often kicked" },
82     { "C_URL",        "posts many URLs" },
83     { "C_JOIN",       "doesn't know wether to stay or quit" },
84     { "C_NICK",       "often changes his nick" },
85     { "C_MONOLOGUE",  "speaks a lot of monologues" }
86   },
87   { /* French language */
88     { "Français",     "fr" },
89     { "HEADER",       "Statistiques de #%s par %s" },
90     { "LEGEND",       "L&eacute;gende" },
91     { "LASTDAYS",     "Statistiques des derniers jours" },
92     { "TOPHOURS",     "Statistiques horaires" },
93     { "TOPUSERS",     "Personnes les plus actives" },
94     { "OTHERS",       "Il reste %d personnes non class&eacute;es..." },
95     { "NBLINES",      "lignes" },
96     { "NICK",         "nick" },
97     { "AVGLETTERS",   "lettres/lignes" },
98     { "HOURS",        "heures" },
99     { "QUOTE",        "message al&eacute;atoire" },
100     { "TOPUSERSTIME", "Personnes les plus actives par p&eacute;riode de la journ&eacutee" },
101     { "RANDTOPICS",   "Quelques topics" },
102     { "CHANGEDBY",    "chang&eacute; par" },
103     { "NEWTOPIC",     "nouveau topic" },
104     { "RANDURLS",     "Quelques URLs" },
105     { "POSTEDBY",     "post&eacute;e par" },
106     { "POSTEDURL",    "URL" },
107     { "TOPWORDS",     "Mots les plus utilis&eacute;s" },
108     { "WORD",         "mot" },
109     { "OCCURRENCES",  "occurrences" },
110     { "BIGNUMBERS",   "Quelques grands nombres..." },
111     { "NUMBERS",      "nombres" },
112     { "TIME",         "%d lignes trait&eacute;es en %d secondes" },
113     { "FOOTER",       "Statistiques g&eacute;n&eacute;r&eacute;es par" },
114     { "C_SMILE",      "est souvent heureux :)" },
115     { "C_FROWN",      "est souvent triste :(" },
116     { "C_EXCLAM",     "hurle beaucoup !" },
117     { "C_QUESTION",   "pose beaucoup de questions ?" },
118     { "C_ME",         "aime la commande /me" },
119     { "C_TOPIC",      "change souvent le topic" },
120     { "C_MODE",       "change souvent les modes" },
121     { "C_KICK",       "aime la commande /kick" },
122     { "C_KICKED",     "est souvent kick&eacute;" },
123     { "C_URL",        "poste beaucoup d'URLs" },
124     { "C_JOIN",       "ne sait pas s'il doit rester ou partir" },
125     { "C_NICK",       "change souvent de nick" },
126     { "C_MONOLOGUE",  "parle beaucoup de monologues" }
127   },
128   { /* German language */
129     /* contributed by Valentin Gelhorn <valentin.gelhorn@web.de> */
130     { "German",       "de" },
131     { "HEADER",       "Statistiken f&uuml;r #%s von %s" },
132     { "LEGEND",       "Legende" },
133     { "LASTDAYS",     "Statistik der letzten Tage" },
134     { "TOPHOURS",     "St&uuml;ndliche Statistik" },
135     { "TOPUSERS",     "Die aktivsten Personen" },
136     { "OTHERS",       "Es bleiben noch %d uneingetragene" },
137     { "NBLINES",      "Zeilen" },
138     { "NICK",         "Nick" },
139     { "AVGLETTERS",   "Buchstaben/Zeile" },
140     { "HOURS",        "Stunden" },
141     { "QUOTE",        "Zuf&auml;llig ausgewaehlte Zitate" },
142     { "TOPUSERSTIME", "Die aktivsten Personen zur bestimmten Tageszeit" },
143     { "RANDTOPICS",   "Ein paar Topics" },
144     { "CHANGEDBY",    "Gesetzt von" },
145     { "NEWTOPIC",     "Neues topic" },
146     { "RANDURLS",     "Ein paar URLs" },
147     { "POSTEDBY",     "Geschrieben von" },
148     { "POSTEDURL",    "URL" },
149     { "TOPWORDS",     "Am h&auml;ufigsten benutze W&ouml;rter" },
150     { "WORD",         "Wort" },
151     { "OCCURRENCES",  "Vorkommen" },
152     { "BIGNUMBERS",   "Ein paar grosse Zahlen" },
153     { "NUMBERS",      "Zahlen" },
154     { "TIME",         "%d Zeilen analysiert in %d Sekunden" },
155     { "FOOTER",       "Statistiken wurden erstellt von" },
156     { "C_SMILE",      "ist oft gl&uuml;klich :)" },
157     { "C_FROWN",      "ist oft traurig :(" },
158     { "C_EXCLAM",     "schreit oft !" },
159     { "C_QUESTION",   "stellt viele Fragen ?" },
160     { "C_ME",         "mag /me'en" },
161     { "C_TOPIC",      "aendert oft das Topico" },
162     { "C_MODE",       "aendert oft die Modes" },
163     { "C_KICK",       "mag /kick'en" },
164     { "C_KICKED",     "wird oft gekickt"},
165     { "C_URL",        "schreibt viele URLs"},
166     { "C_JOIN",       "kann sich nicht entscheiden ob er bleiben oder gehen soll" },
167     { "C_NICK",       "&auml;ndert oft seinen Nick" },
168     { "C_MONOLOGUE",  "spricht oft Monologe" }
169   },
170   { /* Spanish language */
171     /* contributed by Alex <ainaker@gmx.net> */
172     { "Spanish",      "es" },
173     { "HEADER",       "Estad&iacute;sticas de #%s por %s" },
174     { "LEGEND",       "Leyenda" },
175     { "LASTDAYS",     "Estad&iacute;sticas de los &uacute;ltimos d&iacute;as" },
176     { "TOPHOURS",     "Estad&iacute;sticas por horas" },
177     { "TOPUSERS",     "Los que m&aacute;s escriben" },
178     { "OTHERS",       "Hay %d m&aacute;s que no llegaron..." },
179     { "NBLINES",      "l&iacute;neas" },
180     { "NICK",         "nick" },
181     { "AVGLETTERS",   "letras por l&iacute;nea" },
182     { "HOURS",        "horas" },
183     { "QUOTE",        "Frase aleatoria" },
184     { "TOPUSERSTIME", "Los que m&aacute;s escriben seg&uacute;n la hora" },
185     { "RANDTOPICS",   "Algunos topics" },
186     { "CHANGEDBY",    "Puestos por" },
187     { "NEWTOPIC",     "topic" },
188     { "RANDURLS",     "Algunas URLs" },
189     { "POSTEDBY",     "puestas por" },
190     { "POSTEDURL",    "URL" },
191     { "TOPWORDS",     "Palabras m&aacute;s usadas" },
192     { "WORD",         "Palabra" },
193     { "OCCURRENCES",  "Frecuencia" },
194     { "BIGNUMBERS",   "Algunos datos..." },
195     { "NUMBERS",      "N&uacute;mero de veces" },
196     { "TIME",         "%d lineas procesadas en %d segundos" },
197     { "FOOTER",       "Estad&iacute;sticas generadas por" },
198     { "C_SMILE",      "Suele estar fel&iacute;z :)" },
199     { "C_FROWN",      "Suele estar triste :(" },
200     { "C_EXCLAM",     "Grita mucho !" },
201     { "C_QUESTION",   "Hace muchas preguntas ?" },
202     { "C_ME",         "Abusa del comando /me" },
203     { "C_TOPIC",      "Suele cambiar el topic" },
204     { "C_MODE",       "Cambia a veces los modos del canal" },
205     { "C_KICK",       "Le gusta patear" },
206     { "C_KICKED",     "Es pateado con frecuencia" },
207     { "C_URL",        "Pone muchas URLs" },
208     { "C_JOIN",       "No sabe si irse o quedarse" },
209     { "C_NICK",       "Cambia mucho de nick" },
210     { "C_MONOLOGUE",  "Habla solo" }
211   }
212 };
213
214 int language;
215
216 char *L(char *key)
217 {
218   int i;
219   for (i=1;i<=NBKEYS;i++) if (strcmp(key,keys[language][i][0])==0) return(keys[language][i][1]);
220   fprintf(stderr,"unknown language key: %s\n",key);
221   return("");
222 }
223
224 /* Themes */
225 #define NBTHEMES 5
226 #define NBCOLORS 9
227 char *colors[NBTHEMES][NBCOLORS+1][2]= /* first key used for theme name/description and abbreviation */
228 {
229   { /* Default theme */
230     { "White background", "default" },
231     { "BGCOLOR", "#FFFFFF" },
232     { "TEXT",    "#000000" },
233     { "LINK",    "#0000EE" },
234     { "VLINK",   "#551A8B" },
235     { "ALINK",   "#FF0000" },
236     { "TITLE1",  "#000000" },
237     { "TITLE2",  "#000000" },
238     { "BGTABLE", "#EEEEEE" },
239     { "BGTITLE", "#FFEEEE" }
240   },
241   { /* Dark theme */
242     { "Black background", "dark" },
243     { "BGCOLOR", "#000000" },
244     { "TEXT",    "#FFFFFF" },
245     { "LINK",    "#AAAAFF" },
246     { "VLINK",   "#CCCCDD" },
247     { "ALINK",   "#FFAAAA" },
248     { "TITLE1",  "#AAAAFF" },
249     { "TITLE2",  "#FFAAAA" },
250     { "BGTABLE", "#225522" },
251     { "BGTITLE", "#552222" }
252   },
253   { /* zeRezo theme */
254     { "Green theme...", "zerezo" },
255     { "BGCOLOR", "#000000" },
256     { "TEXT",    "#FFFFFF" },
257     { "LINK",    "#14F024" },
258     { "VLINK",   "#0CBA18" },
259     { "ALINK",   "#FFFFFF" },
260     { "TITLE1",  "#0CBA18" },
261     { "TITLE2",  "#84DB8C" },
262     { "BGTABLE", "#085D10" },
263     { "BGTITLE", "#0B810B" }
264   },
265   { /* tit-namour theme */
266     { "Purple and Pink", "namour" },
267     { "BGCOLOR", "#9933CC" },
268     { "TEXT",    "#DDAAFF" },
269     { "LINK",    "#CC99FF" },
270     { "VLINK",   "#999999" },
271     { "ALINK",   "#FFC8C8" },
272     { "TITLE1",  "#FFC8C8" },
273     { "TITLE2",  "#FFC8C8" },
274     { "BGTABLE", "#7711AA" },
275     { "BGTITLE", "#550088" }
276   },
277   { /* zeDuel theme */
278     { "Orange theme...", "zeduel" },
279     { "BGCOLOR", "#FFFFFF" },
280     { "TEXT",    "#000000" },
281     { "LINK",    "#FF7700" },
282     { "VLINK",   "#C05A00" },
283     { "ALINK",   "#FF9A41" },
284     { "TITLE1",  "#C05A00" },
285     { "TITLE2",  "#FF7700" },
286     { "BGTABLE", "#FFEEEE" },
287     { "BGTITLE", "#FF7700" }
288   }
289 };
290
291 int theme;
292
293 char *T(char *color)
294 {
295   int i;
296   for (i=1;i<=NBCOLORS;i++) if (strcmp(color,colors[theme][i][0])==0) return(colors[theme][i][1]);
297   fprintf(stderr,"unknown theme color: %s\n",color);
298   return("");
299 }
300
301 /* Variables */
302
303 char *channel;
304 char *maintainer;
305
306 struct
307 {
308   char nick[MAXNICKLENGTH];
309   int lines;
310   int letters;
311   int hours[4];
312   char quote[MAXQUOTELENGTH+1];
313   int counters[NBCOUNTERS];
314 } users[MAXUSERS];
315 int nbusers=0;
316
317 struct
318 {
319   char nick[MAXNICKLENGTH];
320   char url[MAXLINELENGTH];
321   char shorturl[MAXQUOTELENGTH+1];
322 } urls[5];
323 int nburls=0;
324
325 struct
326
327   char nick[MAXNICKLENGTH];
328   char topic[MAXQUOTELENGTH+1];
329 } topics[5];
330 int nbtopics=0;
331
332 struct
333 {
334   int lines;
335   int hours[4];
336 } lastdays[31];
337 int days=0;
338
339 int hours[24];
340 int lines=0;
341
342 struct letter
343 {
344   int nb;
345   struct letter *next[26];
346 } words;
347
348 struct
349 {
350   int nb;
351   char word[MAXLINELENGTH];
352 } topwords[NBWORDS];
353
354 #define isletter(c) (((c>='a')&&(c<='z'))||((c>='A')&&(c<='Z')))
355 #define lowercase(c) (((c>='A')&&(c<='Z'))?c-'A'+'a':c)
356 void findwords(char *message)
357 {
358   int i,c;
359   struct letter *pos,*tmp;
360   for (;;)
361   {
362     while (!isletter(*message)) if (*message=='\0') return; else message++;
363     pos=&words;
364     while (isletter(*message))
365     {
366       c=lowercase(*message)-'a';
367       if (pos->next[(int)c]==NULL)
368       {
369         tmp=malloc(sizeof(struct letter));
370         tmp->nb=0;
371         for (i=0;i<26;i++) tmp->next[i]=NULL;
372         pos->next[(int)c]=tmp;
373       }
374       pos=pos->next[(int)c];
375       message++; 
376     }
377     pos->nb++;
378   }
379   return;
380 }
381
382 char tempword[MAXLINELENGTH];
383 void bestwords(struct letter pos,int cur)
384 {
385   int i,j;
386   if ((cur>=MINWORDLENGTH)&&(pos.nb>topwords[NBWORDS-1].nb))
387   {
388     for (i=0;pos.nb<topwords[i].nb;i++);
389     for (j=NBWORDS-1;j>i;j--)
390     {
391       topwords[j].nb=topwords[j-1].nb;
392       strcpy(topwords[j].word,topwords[j-1].word);
393     }
394     topwords[i].nb=pos.nb;
395     strcpy(topwords[i].word,tempword);
396   }
397   for (i=0;i<26;i++) if (pos.next[i]!=NULL)
398   {
399     tempword[cur]='a'+i;
400     bestwords(*(pos.next[i]),cur+1);
401   }
402   tempword[cur]='\0';
403 }
404
405 void printhtml(char *string) /* replace < and > by &lt; and &gt; */
406 {
407   while (*string!='\0')
408   {
409     switch (*string)
410     {
411       case '<':printf("&lt;"); break;
412       case '>':printf("&gt;"); break;
413       case '&':printf("&amp;"); break;
414       default:printf("%c",*string); break;
415     }
416     string++;
417   }
418   return;
419 }
420
421 int dichotomic(char *nick)
422 {
423   int i,j,start=0,end=nbusers-1,middle;
424   while (start<=end)
425   {
426     middle=(start+end)/2;
427     if (strcmp(nick,users[middle].nick)>0) start=middle+1; else end=middle-1;
428   }
429   if (strcmp(nick,users[start].nick)!=0)
430   {
431     nbusers++;
432     if (nbusers>=MAXUSERS) { fprintf(stderr,"too many users\n"); exit(1); }
433     for (i=nbusers-1;i>start;i--)
434     {
435       strcpy(users[i].nick,users[i-1].nick);
436       users[i].lines=users[i-1].lines;
437       users[i].letters=users[i-1].letters;
438       for (j=0;j<4;j++) users[i].hours[j]=users[i-1].hours[j];
439       strcpy(users[i].quote,users[i-1].quote);
440       for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=users[i-1].counters[j];
441     }
442     strcpy(users[start].nick,nick);
443     users[start].lines=0;
444     users[start].letters=0;
445     for (j=0;j<4;j++) users[start].hours[j]=0;
446     users[start].quote[0]='\0';
447     for (j=0;j<NBCOUNTERS;j++) users[start].counters[j]=0;
448   }
449   return(start);
450 }
451
452 int main(int argc,char *argv[])
453 {
454   int i,j,k;
455   int max,user,temp,hour;
456   int mononick,monolines;
457   time_t debut;
458   int totallines=0;
459   int pos=0;
460   char c;
461   char *nick,*message;
462   char line[MAXLINELENGTH];
463   
464   /*** INIT ***/
465   
466   if (argc!=5)
467   {
468     fprintf(stderr,"Usage: cat /path/to/file.log | ./irssistats channel maintainer language theme > /path/to/file.html\n\n");
469     fprintf(stderr,"Version :\nirssistats %s\n\n",VERSION);
470     fprintf(stderr,"Supported languages :\n");
471     for (i=0;i<NBLANGUAGES;i++) fprintf(stderr,"%s = %s\n",keys[i][0][1],keys[i][0][0]);
472     fprintf(stderr,"\nSupported themes :\n");
473     for (i=0;i<NBTHEMES;i++) fprintf(stderr,"%s = %s\n",colors[i][0][1],colors[i][0][0]);
474     return(1);
475   }
476   channel=argv[1];
477   maintainer=argv[2];
478   for (i=0;i<NBLANGUAGES;i++) if (strcmp(argv[3],keys[i][0][1])==0) { language=i; break; }
479   if (i==NBLANGUAGES)
480   {
481     fprintf(stderr,"Invalid language : %s\n",argv[3]);
482     return(1);
483   }
484   for (i=0;i<NBTHEMES;i++) if (strcmp(argv[4],colors[i][0][1])==0) { theme=i; break; }
485   if (i==NBTHEMES)
486   {
487     fprintf(stderr,"Invalid theme : %s\n",argv[4]);
488     return(1);
489   }
490
491   /*** LOG ***/
492   
493   srand(debut=time(NULL));
494   fprintf(stderr,"working:");
495   while (!feof(stdin))
496   {
497     c=getchar();
498     line[pos++]=c;
499     if (pos>=MAXLINELENGTH) { fprintf(stderr,"line too long\n"); exit(1); }
500     if (c=='\n')
501     {
502       line[pos-1]='\0';
503       totallines++;
504       if (totallines%10000==0) { fprintf(stderr,"."); fflush(stdout); }
505       if (strncmp("--- Day changed",line,15)==0) /* --- Day changed Wed May 01 2002 */
506       {
507         for (i=30;i>0;i--)
508         {
509           lastdays[i].lines=lastdays[i-1].lines;
510           for (j=0;j<4;j++) lastdays[i].hours[j]=lastdays[i-1].hours[j];
511         }
512         lastdays[0].lines=0;
513         for (j=0;j<4;j++) lastdays[0].hours[j]=0;
514         days++;
515       }
516       else if (strncmp("-!- mode/",&line[6],9)==0) /* 00:00 -!- mode/#channel [...] by Nick(, Nick2, Nick3...) */
517       {
518         for (i=15;(line[i]!=']')||(line[i+1]!=' ');i++);
519         nick=&line[i+5];
520         for (i=0;(nick[i]!='\0')&&(nick[i]!=',');i++);
521         nick[i]='\0';
522         users[dichotomic(nick)].counters[D_MODE]++;
523       }
524       else if (strncmp("-!-",&line[6],3)==0) /* 00:00 -!- Nick something... */
525       {
526         for (i=10;line[i]!=' ';i++);
527         line[i]='\0';
528         nick=&line[10];
529         message=&line[i+1];
530         if (strncmp("changed the topic of",message,20)==0) /* 00:00 -!- Nick changed the topic of #channel to: new topic */
531         {
532           users[dichotomic(nick)].counters[D_TOPIC]++;
533           for (i=21;message[i]!=':';i++);
534           message=&message[i+2];
535           nbtopics++;
536           if ((nbtopics<=NBTOPICS) || (rand()%(nbtopics/NBTOPICS)==0))
537           {
538             temp=nbtopics<=NBTOPICS?nbtopics-1:rand()%NBTOPICS;
539             strcpy(topics[temp].nick,nick);
540             strncpy(topics[temp].topic,message,MAXQUOTELENGTH);
541           }
542         }
543         else if (strncmp("was kicked from",message,15)==0) /* 00:00 -!- Nick was kicked from #channel by Nick [Reason] */
544         {
545           users[dichotomic(nick)].counters[D_KICKED]++;
546           for (i=16;message[i]!=' ';i++);
547           message=&message[i+4];
548           for (i=0;message[i]!=' ';i++);
549           message[i]='\0';
550           users[dichotomic(message)].counters[D_KICK]++;
551         }
552         else if (strncmp("is now known as",message,15)==0) /* 00:00 -!- Nick is now known as Nick */
553           users[dichotomic(nick)].counters[D_NICK]++;
554         else if (message[0]=='[') /* 00:00 -!- Nick [user@host] something... */
555         {
556           for (i=0;message[i]!=']';i++);
557           message=&message[i+2];
558           if (strncmp("has joined",message,10)==0) /* 00:00 -!- Nick [user@host] has joined #channel */
559             users[dichotomic(nick)].counters[D_JOIN]++;
560           else if (strncmp("has quit",message,8)==0); /* 00:00 -!- Nick [user@host] has quit [Reason] */
561           else if (strncmp("has left",message,8)==0); /* 00:00 -!- Nick [user@host] has left #channel [Reason] */
562           else;
563         }
564       }
565       else if ((line[6]=='<') || (line[7]=='*'))
566       {
567         line[2]='\0';
568         hour=atoi(line);
569         if (line[7]=='*') /* 00:00  * Nick the message */
570         {
571           for (i=9;line[i]!=' ';i++);
572           nick=&line[9];
573           message=&line[i+1];
574         }
575         else if (line[7]=='>') /* 00:00 <>>>?Nick<<<> the personal message */
576         {
577           for (i=11;line[i]!='<';i++);
578           nick=&line[11];
579           message=&line[i+5];
580         }
581         else /* 00:00 <?Nick> the message */
582         {
583           for (i=8;line[i]!='>';i++);
584           nick=&line[8];
585           message=&line[i+2];
586         }
587         line[i]='\0';
588         i=dichotomic(nick);
589         if (line[7]=='*') users[i].counters[D_ME]++;
590         if (i==mononick)
591         {
592           monolines++;
593           if (monolines==5) users[i].counters[D_MONOLOGUE]++;
594         }
595         else
596         {
597           mononick=i;
598           monolines=1;
599         }
600         j=strlen(message);
601         users[i].lines++;
602         users[i].letters+=j;
603         users[i].hours[hour/6]++;
604         lastdays[0].lines++;
605         lastdays[0].hours[hour/6]++;
606         lines++;
607         hours[hour]++;
608         if (message[j-1]=='?') users[i].counters[D_QUESTION]++;
609         else if (message[j-1]=='!') users[i].counters[D_EXCLAM]++;
610         else if ((message[j-3]==' ')&&(message[j-2]==':'))
611         {
612           if (message[j-1]==')') users[i].counters[D_SMILE]++;
613           else if (message[j-1]=='(') users[i].counters[D_FROWN]++;
614         }
615         if (rand()%users[i].lines==0) strncpy(users[i].quote,message,MAXQUOTELENGTH);
616         if (strncmp("http://",message,7)==0)
617         {
618           users[i].counters[D_URL]++;
619           for (i=0;(message[i]!=' ') && (i<strlen(message));i++);
620           message[i]='\0';
621           nburls++;
622           if ((nburls<=NBURLS) || (rand()%(nburls/NBURLS)==0))
623           {
624             temp=nburls<=NBURLS?nburls-1:rand()%NBURLS;
625             strcpy(urls[temp].nick,nick);
626             strcpy(urls[temp].url,message);
627             strncpy(urls[temp].shorturl,message,MAXQUOTELENGTH);
628           }
629         }
630         findwords(message);
631       }
632       pos=0;
633     }
634   }
635   fprintf(stderr,"done\n");
636
637   bestwords(words,0);
638
639   /*** HTML ***/
640
641   /* header */
642   printf("<!-- Generated by irssistats %s : %s -->\n\n",VERSION,URL);
643   printf("<html>\n\n<head>\n<base target=\"_blank\">\n<title>");
644   printf(L("HEADER"),channel,maintainer);
645   printf("</title>\n</head>\n\n");
646   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"));
647   printf(L("HEADER"),channel,maintainer);
648   printf("</h1></font>\n%s<br>\n<br><br>\n\n",ctime(&debut));
649
650   /* legend */
651   printf("<font color=\"%s\"><h3>%s</h3></font>\n<table bgcolor=%s>\n<tr>\n",T("TITLE2"),L("LEGEND"),T("BGTABLE"));
652   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);
653   printf("</tr>\n</table>\n<br><br>\n\n");
654   
655   /* last days */
656   printf("<font color=\"%s\"><h3>%s</h3></font>\n<table>\n<tr>\n",T("TITLE2"),L("LASTDAYS"));
657   max=-1;
658   for (i=30;i>=0;i--) if (lastdays[i].lines>max) max=lastdays[i].lines;
659   for (i=30;i>=0;i--)
660   {
661     printf("<td width=\"15\" align=\"center\" valign=\"bottom\"><font size=\"-2\">%d</font><br>",lastdays[i].lines);
662     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);
663     printf("</td>\n");
664   }
665   printf("</tr>\n<tr>\n");
666   for (i=30;i>=0;i--)
667     printf("<td align=\"center\" valign=\"center\" bgcolor=\"%s\">%d</td>\n",T("BGTABLE"),i);
668   printf("</tr>\n</table>\n<br><br>\n\n");
669   
670   /* top hours */
671   printf("<font color=\"%s\"><h3>%s</h3></font>\n<table>\n<tr>\n",T("TITLE2"),L("TOPHOURS"));
672   max=-1;
673   for (i=0;i<24;i++) if (hours[i]>max) max=hours[i];
674   for (i=0;i<24;i++)
675   {
676     printf("<td width=\"15\" align=\"center\" valign=\"bottom\"><font size=\"-2\">%.1f%%</font><br>",lines!=0?(float)100*hours[i]/lines:0);
677     if (hours[i]!=0) printf("<img src=\"v%d.png\" width=\"15\" height=\"%d\"><br>",i/6+1,150*hours[i]/max);
678     printf("</td>\n");
679   }
680   printf("</tr>\n<tr>\n");
681   for (i=0;i<24;i++)
682     printf("<td align=\"center\" valign=\"center\" bgcolor=\"%s\">%d</td>\n",T("BGTABLE"),i);
683   printf("</tr>\n</table>\n<br><br>\n\n");
684   
685   /* top users */
686   printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("TOPUSERS"));
687   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"));
688   for (i=1;i<=NBUSERS;i++)
689   {
690     user=-1;
691     max=-1;
692     for (j=0;j<nbusers;j++) if (users[j].lines>max) max=users[user=j].lines;
693     if (user!=-1)
694     {
695       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"));
696       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);
697       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"));
698       printhtml(users[user].quote);
699       printf("\"</td></tr>\n");
700       users[user].lines=-1;
701     }    
702   }
703   printf("</table>\n");
704   if (nbusers>NBUSERS)
705   {
706     printf("<br>");
707     printf(L("OTHERS"),nbusers-50);
708     printf("<br>\n");
709   }
710   printf("<br><br>\n\n");
711   
712   /* top users by time */
713   printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("TOPUSERSTIME"));
714   printf("<table>\n<tr><td></td>");
715   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);
716   printf("</tr>\n");
717   for (i=1;i<=NBUSERSTIME;i++)
718   {
719     printf("<tr><td bgcolor=\"%s\" align=\"right\">%d</td>",T("BGTABLE"),i);
720     for (j=0;j<4;j++)
721     {
722       user=-1;
723       max=-1;
724       for (k=0;k<nbusers;k++) if (users[k].hours[j]>max) max=users[user=k].hours[j];
725       if (user!=-1)
726       {
727         printf("<td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%d</td>",T("BGTABLE"),users[user].nick,T("BGTABLE"),users[user].hours[j]);
728         users[user].hours[j]=-1;
729       }
730       else printf("<td></td><td></td>");
731     }
732     printf("</tr>\n");
733   }
734   printf("</table>\n<br><br>\n\n");
735
736   /* random topics */
737   printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("RANDTOPICS"));
738   printf("<table>\n<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td></tr>\n",T("BGTITLE"),L("CHANGEDBY"),T("BGTITLE"),L("NEWTOPIC"));
739   for (i=nbtopics<NBTOPICS?nbtopics-1:NBTOPICS-1;i>=0;i--)
740   {
741     printf("<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">\"",T("BGTABLE"),topics[i].nick,T("BGTABLE"));
742     printhtml(topics[i].topic);
743     printf("\"</td></tr>\n");
744   }
745   printf("</table>\n<br><br>\n\n");
746   
747   /* random urls */
748   printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("RANDURLS"));
749   printf("<table>\n<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td></tr>\n",T("BGTITLE"),L("POSTEDBY"),T("BGTITLE"),L("POSTEDURL"));
750   for (i=nburls<NBURLS?nburls-1:NBURLS-1;i>=0;i--)
751   {
752     printf("<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">\"<a href=\"%s\">",T("BGTABLE"),urls[i].nick,T("BGTABLE"),urls[i].url);
753     printhtml(urls[i].shorturl);
754     printf("</a>\"</td></tr>\n");
755   }
756   printf("</table>\n<br><br>\n\n");
757   
758   /* top words */
759   printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("TOPWORDS"));
760   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"));
761   for (i=0;i<NBWORDS;i++)
762     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);
763   printf("</table>\n<br><br>\n\n");
764
765   /* big numbers */
766   printf("<font color=\"%s\"><h3>%s</h3></font>\n",T("TITLE2"),L("BIGNUMBERS"));
767   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"));
768   for (i=0;i<NBCOUNTERS;i++)
769   {
770     user=-1;
771     max=0;
772     for (j=0;j<nbusers;j++) if (users[j].counters[i]>max) max=users[user=j].counters[i];
773     if (user!=-1) printf("<tr><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%s</td><td bgcolor=\"%s\">%d</td></tr>",T("BGTABLE"),users[user].nick,T("BGTABLE"),L(counters[i]),T("BGTABLE"),users[user].counters[i]);
774   }
775   printf("</table>\n<br><br>\n\n");
776   
777   /* footer */
778   printf(L("TIME"),totallines,(int)(time(NULL)-debut));
779   printf("<br>\n%s <a href=\"%s\">irssistats %s</a>",L("FOOTER"),URL,VERSION);
780   printf("\n\n</center>\n\n</body>\n\n</html>\n");
781   
782   return(0);
783 }