1 /* Usage: irssistats [/path/to/file.conf] */
11 #define MAXUSERS 10000
12 #define MAXNICKLENGTH 50
13 #define MAXLINELENGTH 2000
14 #define MAXQUOTELENGTH 100
16 #define NBUSERSTIME 10
20 #define MINWORDLENGTH 5
24 #define URL "http://royale.zerezo.com/irssistats/"
39 #define D_MONOLOGUE 12
41 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"};
46 char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and abbreviation */
48 { /* English language */
50 { "HEADER", "Statistics for %s by %s" },
51 { "LEGEND", "Legend" },
52 { "LASTDAYS", "Lastdays statistics" },
53 { "TOPHOURS", "Hourly statistics" },
54 { "TOPUSERS", "Most active people" },
55 { "OTHERS", "There are %d left not ranked..." },
56 { "NBLINES", "lines" },
58 { "AVGLETTERS", "letters/lines" },
60 { "QUOTE", "random message" },
61 { "TOPUSERSTIME", "Most active people by time of day" },
62 { "RANDTOPICS", "Some topics" },
63 { "CHANGEDBY", "changed by" },
64 { "NEWTOPIC", "new topic" },
65 { "RANDURLS", "Some URLs" },
66 { "POSTEDBY", "posted by" },
67 { "POSTEDURL", "URL" },
68 { "TOPWORDS", "Most used words" },
70 { "OCCURRENCES", "occurrences" },
71 { "BIGNUMBERS", "Some big numbers..." },
72 { "NUMBERS", "numbers" },
73 { "TIME", "%d lines (%d days) parsed in %d seconds" },
74 { "FOOTER", "Statistics generated by" },
75 { "C_SMILE", "is often happy :)" },
76 { "C_FROWN", "is often sad :(" },
77 { "C_EXCLAM", "yells a lot !" },
78 { "C_QUESTION", "asks a lot of questions ?" },
79 { "C_ME", "likes /me command" },
80 { "C_TOPIC", "often changes the topic" },
81 { "C_MODE", "often changes the modes" },
82 { "C_KICK", "likes to /kick" },
83 { "C_KICKED", "is often kicked" },
84 { "C_URL", "posts many URLs" },
85 { "C_JOIN", "doesn't know wether to stay or quit" },
86 { "C_NICK", "often changes his nick" },
87 { "C_MONOLOGUE", "speaks a lot of monologues" }
89 { /* French language */
91 { "HEADER", "Statistiques de %s par %s" },
92 { "LEGEND", "Légende" },
93 { "LASTDAYS", "Statistiques des derniers jours" },
94 { "TOPHOURS", "Statistiques horaires" },
95 { "TOPUSERS", "Personnes les plus actives" },
96 { "OTHERS", "Il reste %d personnes non classées..." },
97 { "NBLINES", "lignes" },
99 { "AVGLETTERS", "lettres/lignes" },
100 { "HOURS", "heures" },
101 { "QUOTE", "message aléatoire" },
102 { "TOPUSERSTIME", "Personnes les plus actives par période de la journée" },
103 { "RANDTOPICS", "Quelques topics" },
104 { "CHANGEDBY", "changé par" },
105 { "NEWTOPIC", "nouveau topic" },
106 { "RANDURLS", "Quelques URLs" },
107 { "POSTEDBY", "postée par" },
108 { "POSTEDURL", "URL" },
109 { "TOPWORDS", "Mots les plus utilisés" },
111 { "OCCURRENCES", "occurrences" },
112 { "BIGNUMBERS", "Quelques grands nombres..." },
113 { "NUMBERS", "nombres" },
114 { "TIME", "%d lignes (%d jours) traitées en %d secondes" },
115 { "FOOTER", "Statistiques générées par" },
116 { "C_SMILE", "est souvent heureux :)" },
117 { "C_FROWN", "est souvent triste :(" },
118 { "C_EXCLAM", "hurle beaucoup !" },
119 { "C_QUESTION", "pose beaucoup de questions ?" },
120 { "C_ME", "aime la commande /me" },
121 { "C_TOPIC", "change souvent le topic" },
122 { "C_MODE", "change souvent les modes" },
123 { "C_KICK", "aime la commande /kick" },
124 { "C_KICKED", "est souvent kické" },
125 { "C_URL", "poste beaucoup d'URLs" },
126 { "C_JOIN", "ne sait pas s'il doit rester ou partir" },
127 { "C_NICK", "change souvent de nick" },
128 { "C_MONOLOGUE", "parle beaucoup de monologues" }
130 { /* German language */
131 /* contributed by Valentin Gelhorn <valentin.gelhorn@web.de> */
133 { "HEADER", "Statistiken für %s von %s" },
134 { "LEGEND", "Legende" },
135 { "LASTDAYS", "Statistik der letzten Tage" },
136 { "TOPHOURS", "Stündliche Statistik" },
137 { "TOPUSERS", "Die aktivsten Personen" },
138 { "OTHERS", "Es bleiben noch %d uneingetragene" },
139 { "NBLINES", "Zeilen" },
141 { "AVGLETTERS", "Buchstaben/Zeile" },
142 { "HOURS", "Stunden" },
143 { "QUOTE", "Zufällig ausgewaehlte Zitate" },
144 { "TOPUSERSTIME", "Die aktivsten Personen zur bestimmten Tageszeit" },
145 { "RANDTOPICS", "Ein paar Topics" },
146 { "CHANGEDBY", "Gesetzt von" },
147 { "NEWTOPIC", "Neues topic" },
148 { "RANDURLS", "Ein paar URLs" },
149 { "POSTEDBY", "Geschrieben von" },
150 { "POSTEDURL", "URL" },
151 { "TOPWORDS", "Am häufigsten benutze Wörter" },
153 { "OCCURRENCES", "Vorkommen" },
154 { "BIGNUMBERS", "Ein paar grosse Zahlen" },
155 { "NUMBERS", "Zahlen" },
156 { "TIME", "%d Zeilen (%d Tage) analysiert in %d Sekunden" },
157 { "FOOTER", "Statistiken wurden erstellt von" },
158 { "C_SMILE", "ist oft glüklich :)" },
159 { "C_FROWN", "ist oft traurig :(" },
160 { "C_EXCLAM", "schreit oft !" },
161 { "C_QUESTION", "stellt viele Fragen ?" },
162 { "C_ME", "mag /me'en" },
163 { "C_TOPIC", "aendert oft das Topico" },
164 { "C_MODE", "aendert oft die Modes" },
165 { "C_KICK", "mag /kick'en" },
166 { "C_KICKED", "wird oft gekickt"},
167 { "C_URL", "schreibt viele URLs"},
168 { "C_JOIN", "kann sich nicht entscheiden ob er bleiben oder gehen soll" },
169 { "C_NICK", "ändert oft seinen Nick" },
170 { "C_MONOLOGUE", "spricht oft Monologe" }
172 { /* Spanish language */
173 /* contributed by Alex <ainaker@gmx.net> */
175 { "HEADER", "Estadísticas de %s por %s" },
176 { "LEGEND", "Leyenda" },
177 { "LASTDAYS", "Estadísticas de los últimos días" },
178 { "TOPHOURS", "Estadísticas por horas" },
179 { "TOPUSERS", "Los que más escriben" },
180 { "OTHERS", "Hay %d más que no llegaron..." },
181 { "NBLINES", "líneas" },
183 { "AVGLETTERS", "letras por línea" },
184 { "HOURS", "horas" },
185 { "QUOTE", "Frase aleatoria" },
186 { "TOPUSERSTIME", "Los que más escriben según la hora" },
187 { "RANDTOPICS", "Algunos topics" },
188 { "CHANGEDBY", "Puestos por" },
189 { "NEWTOPIC", "topic" },
190 { "RANDURLS", "Algunas URLs" },
191 { "POSTEDBY", "puestas por" },
192 { "POSTEDURL", "URL" },
193 { "TOPWORDS", "Palabras más usadas" },
194 { "WORD", "Palabra" },
195 { "OCCURRENCES", "Frecuencia" },
196 { "BIGNUMBERS", "Algunos datos..." },
197 { "NUMBERS", "Número de veces" },
198 { "TIME", "%d lineas (%d días) procesadas en %d segundos" },
199 { "FOOTER", "Estadísticas generadas por" },
200 { "C_SMILE", "Suele estar felíz :)" },
201 { "C_FROWN", "Suele estar triste :(" },
202 { "C_EXCLAM", "Grita mucho !" },
203 { "C_QUESTION", "Hace muchas preguntas ?" },
204 { "C_ME", "Abusa del comando /me" },
205 { "C_TOPIC", "Suele cambiar el topic" },
206 { "C_MODE", "Cambia a veces los modos del canal" },
207 { "C_KICK", "Le gusta patear" },
208 { "C_KICKED", "Es pateado con frecuencia" },
209 { "C_URL", "Pone muchas URLs" },
210 { "C_JOIN", "No sabe si irse o quedarse" },
211 { "C_NICK", "Cambia mucho de nick" },
212 { "C_MONOLOGUE", "Habla solo" }
214 { /* Polish language */
215 /* contributed by Piotr Jarmuz <coreupper@yahoo.com> */
217 { "HEADER", "Statystyki dla %s przez %s" },
218 { "LEGEND", "Legenda" },
219 { "LASTDAYS", "Statystyki z ostatnich dni" },
220 { "TOPHOURS", "Statystyki godzinne" },
221 { "TOPUSERS", "Najaktywniejsi ludzie" },
222 { "OTHERS", "Zostalo jeszcze %d nie sklasyfikowanych..." },
223 { "NBLINES", "linie" },
225 { "AVGLETTERS", "litery/linie" },
226 { "HOURS", "godziny" },
227 { "QUOTE", "przypadkowa wiadomosc" },
228 { "TOPUSERSTIME", "Najaktywniejsi ludzie wedlug czasu dnia" },
229 { "RANDTOPICS", "Pare tematow" },
230 { "CHANGEDBY", "zmienione przez" },
231 { "NEWTOPIC", "nowy temat" },
232 { "RANDURLS", "Pare URL-i" },
233 { "POSTEDBY", "wyslane przez" },
234 { "POSTEDURL", "URL" },
235 { "TOPWORDS", "Najczestsze slowa" },
237 { "OCCURRENCES", "wystapienia" },
238 { "BIGNUMBERS", "Pare wielkich liczb..." },
239 { "NUMBERS", "liczby" },
240 { "TIME", "%d linii (%d dni) sparsowanych w %d sekund" },
241 { "FOOTER", "Statystyki wygenerowane przez" },
242 { "C_SMILE", "jest czesto szczesliwy :)" },
243 { "C_FROWN", "jest czesto smutny :(" },
244 { "C_EXCLAM", "duzo krzyczy !" },
245 { "C_QUESTION", "zadaje duzo pytan ?" },
246 { "C_ME", "lubi /mnie polecenie" },
247 { "C_TOPIC", "czesto zmienia temat" },
248 { "C_MODE", "czesto zmienia tryb" },
249 { "C_KICK", "lubi /kopac" },
250 { "C_KICKED", "czesto go wykopuja" },
251 { "C_URL", "wysyla duzo URL-i" },
252 { "C_JOIN", "nie wie czy zostac czy wyjsc" },
253 { "C_NICK", "czesto zmienia swojego nicka" },
254 { "C_MONOLOGUE", "czesto mowi monologiem" }
256 { /* Finnish language */
257 /* contributed by Antti Huopana <ahuopana@ratol.fi> */
259 { "HEADER", "Kanavan %s tilastot - %s" },
260 { "LEGEND", "Merkkien selitykset" },
261 { "LASTDAYS", "Viime päivien tilastot" },
262 { "TOPHOURS", "Tilastot tunneittain" },
263 { "TOPUSERS", "Aktiivisimmat ihmiset" },
264 { "OTHERS", "Jäljelle jäi %d joita ei listattu..." },
265 { "NBLINES", "rivit" },
267 { "AVGLETTERS", "kirjainta/rivi" },
268 { "HOURS", "tunnit" },
269 { "QUOTE", "satunnainen viesti" },
270 { "TOPUSERSTIME", "Vuorokauden ajan mukaan aktiivisimmat" },
271 { "RANDTOPICS", "Joitakin aiheita" },
272 { "CHANGEDBY", "vaihtaja" },
273 { "NEWTOPIC", "aihe" },
274 { "RANDURLS", "Joitakin URLeja" },
275 { "POSTEDBY", "lähettäjä" },
276 { "POSTEDURL", "URL" },
277 { "TOPWORDS", "Eniten käytettyjä sanoja" },
279 { "OCCURRENCES", "käytetty" },
280 { "BIGNUMBERS", "Joitakin isoja lukuja..." },
281 { "NUMBERS", "luvut" },
282 { "TIME", "%d riviä (%d päivää) parsittu %d sekunnissa" },
283 { "FOOTER", "Tilastot on generoinut" },
284 { "C_SMILE", "on usein iloinen :)" },
285 { "C_FROWN", "on usein surullinen :(" },
286 { "C_EXCLAM", "möykkää paljon !" },
287 { "C_QUESTION", "kyselee liikaa ?" },
288 { "C_ME", "pitää itsestään" },
289 { "C_TOPIC", "vaihtaa usein aihetta" },
290 { "C_MODE", "haluaa elää muuttuvassa maailmassa" },
291 { "C_KICK", "pitää potkimisesta" },
292 { "C_KICKED", "tykkää tulla potkituksi" },
293 { "C_URL", "surffailee liikaa" },
294 { "C_JOIN", "ei tiedä ollakko vai eikö olla" },
295 { "C_NICK", "kärsii identiteettiongelmista" },
296 { "C_MONOLOGUE", "höpöttää paljon itsekseen" }
298 { /* Italian language */
299 /* contributed by Coviello Giuseppe <giuseppecoviello@tin.it> <http://coviello.altervista.org> */
301 { "HEADER", "Statistiche per il canale %s di %s" },
302 { "LEGEND", "Legenda" },
303 { "LASTDAYS", "Statistiche degli ultimi giorni" },
304 { "TOPHOURS", "Statistiche in ore" },
305 { "TOPUSERS", "Utenti più attivi" },
306 { "OTHERS", "Ci sono %d utenti non classificati..." },
307 { "NBLINES", "righe" },
309 { "AVGLETTERS", "lettere/righe" },
311 { "QUOTE", "messaggio casuale" },
312 { "TOPUSERSTIME", "Utenti più attivi del giorno (divisi per fasce orarie)" },
313 { "RANDTOPICS", "Alcuni topic" },
314 { "CHANGEDBY", "cambiato da" },
315 { "NEWTOPIC", "nuovo topic" },
316 { "RANDURLS", "ALcuni URL" },
317 { "POSTEDBY", "postato da" },
318 { "POSTEDURL", "URL" },
319 { "TOPWORDS", "Le parole più usate" },
320 { "WORD", "parola" },
321 { "OCCURRENCES", "usata" },
322 { "BIGNUMBERS", "Alcuni numeri ..." },
323 { "NUMBERS", "numeri" },
324 { "TIME", "%d righe (%d giorni) esaminate in %d secondi" },
325 { "FOOTER", "Statistiche generate da" },
326 { "C_SMILE", "è spesso felice :)" },
327 { "C_FROWN", "è spesso triste :(" },
328 { "C_EXCLAM", "esclama molto !" },
329 { "C_QUESTION", "fa molte domande ?" },
330 { "C_ME", "ama il comando /me" },
331 { "C_TOPIC", "cambia spesso il topic" },
332 { "C_MODE", "cambia spesso i mode" },
333 { "C_KICK", "ama /kick(are)" },
334 { "C_KICKED", "è kickato spesso" },
335 { "C_URL", "posta molti URL" },
336 { "C_JOIN", "non sa se è ora di andare o restare" },
337 { "C_NICK", "cambia spesso il nick" },
338 { "C_MONOLOGUE", "fa molti monologhi" }
340 { /* Dutch language */
341 /* contributed by Jeroen Ubbink <crasp@blackbyte.nl> */
343 { "HEADER", "Statistieken voor %s door %s" },
344 { "LEGEND", "Legenda" },
345 { "LASTDAYS", "Statistieken van de laatste dagen" },
346 { "TOPHOURS", "Statistieken per uur" },
347 { "TOPUSERS", "Meest actieve mensen" },
348 { "OTHERS", "Er zijn nog %d niet in de top..." },
349 { "NBLINES", "regels" },
351 { "AVGLETTERS", "letters/lijn" },
353 { "QUOTE", "Willekeurige regel" },
354 { "TOPUSERSTIME", "Meest actieve mensen per tijdstip per dag" },
355 { "RANDTOPICS", "Enkele topics" },
356 { "CHANGEDBY", "gewijzigd door" },
357 { "NEWTOPIC", "nieuwe topic" },
358 { "RANDURLS", "Enkele URLs" },
359 { "POSTEDBY", "Geplaatst door" },
360 { "POSTEDURL", "URL" },
361 { "TOPWORDS", "Meest gebruikte woorden" },
363 { "OCCURRENCES", "aantal" },
364 { "BIGNUMBERS", "Enkele grote aantallen..." },
365 { "NUMBERS", "numbers" },
366 { "TIME", "%d regels (%d dagen) verwerkt in %d seconden" },
367 { "FOOTER", "Statistieken gegenereert door" },
368 { "C_SMILE", "is vaak vrolijk :)" },
369 { "C_FROWN", "is vaak droevig :(" },
370 { "C_EXCLAM", "schreeuwt veel !" },
371 { "C_QUESTION", "stelt veel vragen ?" },
372 { "C_ME", "vindt /me een leuk commando" },
373 { "C_TOPIC", "verandert vaak de topic" },
374 { "C_MODE", "verandert vaak de modes" },
375 { "C_KICK", "vindt /kick erg leuk" },
376 { "C_KICKED", "wordt vaak gekickt" },
377 { "C_URL", "plaatst veel URLs" },
378 { "C_JOIN", "twijfelt tussen blijven of gaan" },
379 { "C_NICK", "verandert vaak van nick" },
380 { "C_MONOLOGUE", "spreekt veel monologen" }
384 int language=0; /* default to english */
389 for (i=1;i<=NBKEYS;i++) if (strcmp(key,keys[language][i][0])==0) return(keys[language][i][1]);
390 fprintf(stderr,"unknown language key: %s\n",key);
396 int debug=1; /* 0 = none ; 1 = normal ; 2 = verbose */
397 char channel[MAXLINELENGTH]="set_channel_in_config_file";
398 char maintainer[MAXLINELENGTH]="set_maintainer_in_config_file";
399 char theme[MAXLINELENGTH]="default";
400 int refresh_time=0; /* 0 = disabled */
401 int w3c_link=1; /* 0 = disabled */
402 char header[MAXLINELENGTH]="none";
403 char footer[MAXLINELENGTH]="none";
409 char nick[MAXNICKLENGTH];
413 char quote[MAXQUOTELENGTH+1];
414 int counters[NBCOUNTERS];
421 char nick[MAXNICKLENGTH];
422 char url[MAXLINELENGTH];
423 char shorturl[MAXQUOTELENGTH+1];
429 char nick[MAXNICKLENGTH];
430 char topic[MAXQUOTELENGTH+1];
447 struct letter *next[26];
453 char word[MAXLINELENGTH];
456 #define isletter(c) (((c>='a')&&(c<='z'))||((c>='A')&&(c<='Z')))
457 #define lowercase(c) (((c>='A')&&(c<='Z'))?c-'A'+'a':c)
458 void findwords(char *message)
461 struct letter *pos,*tmp;
464 while (!isletter(*message)) if (*message=='\0') return; else message++;
466 while (isletter(*message))
468 c=lowercase(*message)-'a';
469 if (pos->next[(int)c]==NULL)
471 tmp=malloc(sizeof(struct letter));
473 for (i=0;i<26;i++) tmp->next[i]=NULL;
474 pos->next[(int)c]=tmp;
476 pos=pos->next[(int)c];
484 char tempword[MAXLINELENGTH];
485 void bestwords(struct letter pos,int cur)
488 if ((cur>=MINWORDLENGTH)&&(pos.nb>topwords[NBWORDS-1].nb))
490 for (i=0;pos.nb<topwords[i].nb;i++);
491 for (j=NBWORDS-1;j>i;j--)
493 topwords[j].nb=topwords[j-1].nb;
494 strcpy(topwords[j].word,topwords[j-1].word);
496 topwords[i].nb=pos.nb;
497 strcpy(topwords[i].word,tempword);
499 for (i=0;i<26;i++) if (pos.next[i]!=NULL)
502 bestwords(*(pos.next[i]),cur+1);
507 void freewords(struct letter *pos)
510 for (i=0;i<26;i++) if (pos->next[i]!=NULL)
512 freewords(pos->next[i]);
518 void printhtml(FILE *fic,char *string) /* replace < and > by < and > */
520 while (*string!='\0')
524 case '<':fprintf(fic,"<"); break;
525 case '>':fprintf(fic,">"); break;
526 case '&':fprintf(fic,"&"); break;
527 default:fprintf(fic,"%c",*string); break;
534 int dichotomic(char *nick)
536 int i,j,start=0,end=nbusers-1,middle;
539 middle=(start+end)/2;
540 if (strcmp(nick,users[middle].nick)>0) start=middle+1; else end=middle-1;
542 if (strcmp(nick,users[start].nick)!=0)
545 if (nbusers>=MAXUSERS) { fprintf(stderr,"too many users\n"); exit(1); }
546 for (i=nbusers-1;i>start;i--)
548 strcpy(users[i].nick,users[i-1].nick);
549 users[i].lines=users[i-1].lines;
550 users[i].letters=users[i-1].letters;
551 for (j=0;j<4;j++) users[i].hours[j]=users[i-1].hours[j];
552 strcpy(users[i].quote,users[i-1].quote);
553 for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=users[i-1].counters[j];
554 users[i].temp=users[i-1].temp;
556 strcpy(users[start].nick,nick);
557 users[start].lines=0;
558 users[start].letters=0;
559 for (j=0;j<4;j++) users[start].hours[j]=0;
560 users[start].quote[0]='\0';
561 for (j=0;j<NBCOUNTERS;j++) users[start].counters[j]=0;
567 void parse_log(char *logfile)
570 char line[MAXLINELENGTH];
575 int mononick,monolines;
578 if ((fic=fopen(logfile,"rt"))==NULL) { fprintf(stderr,"can't open log file \"%s\"\n",logfile); exit(1); }
579 if (debug) printf("working on %s : ",channel);
580 while (fgets(line,MAXLINELENGTH,fic)!=NULL)
583 for (i=0;line[i]!=0;i++);
584 if (i>=MAXLINELENGTH-1) { fprintf(stderr,"line %d is too long\n",totallines); exit(1); }
588 if (totallines%10000==0 && debug) { printf("."); fflush(stdout); }
589 if (strncmp("--- Day changed",line,15)==0) /* --- Day changed Wed May 01 2002 */
593 lastdays[i].lines=lastdays[i-1].lines;
594 for (j=0;j<4;j++) lastdays[i].hours[j]=lastdays[i-1].hours[j];
597 for (j=0;j<4;j++) lastdays[0].hours[j]=0;
600 else if (strncmp("-!- mode/",&line[6],9)==0) /* 00:00 -!- mode/#channel [...] by (Nick, Nick2, )Nick3 */
602 for (i=strlen(line);line[i]!=' ';i--);
604 users[dichotomic(nick)].counters[D_MODE]++;
606 else if (strncmp("-!-",&line[6],3)==0) /* 00:00 -!- Nick something... */
608 for (i=10;line[i]!=' ';i++);
612 if (strncmp("changed the topic of",message,20)==0) /* 00:00 -!- Nick changed the topic of #channel to: new topic */
614 users[dichotomic(nick)].counters[D_TOPIC]++;
615 for (i=21;message[i]!=':';i++);
616 message=&message[i+2];
618 if ((nbtopics<=NBTOPICS) || (rand()%(nbtopics/NBTOPICS)==0))
620 temp=nbtopics<=NBTOPICS?nbtopics-1:rand()%NBTOPICS;
621 strcpy(topics[temp].nick,nick);
622 strncpy(topics[temp].topic,message,MAXQUOTELENGTH);
625 else if (strncmp("was kicked from",message,15)==0) /* 00:00 -!- Nick was kicked from #channel by Nick [Reason] */
627 users[dichotomic(nick)].counters[D_KICKED]++;
628 for (i=16;message[i]!=' ';i++);
629 message=&message[i+4];
630 for (i=0;message[i]!=' ';i++);
632 users[dichotomic(message)].counters[D_KICK]++;
634 else if (strncmp("is now known as",message,15)==0) /* 00:00 -!- Nick is now known as Nick */
635 users[dichotomic(nick)].counters[D_NICK]++;
636 else if (message[0]=='[') /* 00:00 -!- Nick [user@host] something... */
638 for (i=0;message[i]!=']';i++);
639 message=&message[i+2];
640 if (strncmp("has joined",message,10)==0) /* 00:00 -!- Nick [user@host] has joined #channel */
641 users[dichotomic(nick)].counters[D_JOIN]++;
642 else if (strncmp("has quit",message,8)==0); /* 00:00 -!- Nick [user@host] has quit [Reason] */
643 else if (strncmp("has left",message,8)==0); /* 00:00 -!- Nick [user@host] has left #channel [Reason] */
647 else if ((line[6]=='<') || (line[7]=='*'))
651 if (line[7]=='*') /* 00:00 * Nick the message */
653 for (i=9;line[i]!=' ';i++);
657 else if (line[7]=='>') /* 00:00 <>>>?Nick<<<> the personal message */
658 /* 00:00 <>>?Nick<<> the personal message */
660 for (i=10;line[i]!='<';i++);
662 if (line[9]=='>') nick++;
665 else /* 00:00 <?Nick> the message */
669 * Irssi doesn't log channel mode with show_nickmode = OFF
670 * the following covers op, half-op, voice and show_nickmode_empty
672 if (line[7]=='@' || line[7]=='%' || line[7]=='+' || line[7]==' ') {
678 for (i=nickstart;line[i]!='>';i++);
679 nick=&line[nickstart];
684 if (line[7]=='*') users[i].counters[D_ME]++;
688 if (monolines==5) users[i].counters[D_MONOLOGUE]++;
698 users[i].hours[hour/6]++;
700 lastdays[0].hours[hour/6]++;
703 if (message[j-1]=='?') users[i].counters[D_QUESTION]++;
704 else if (message[j-1]=='!') users[i].counters[D_EXCLAM]++;
705 else if ((message[j-3]==' ')&&(message[j-2]==':'))
707 if (message[j-1]==')') users[i].counters[D_SMILE]++;
708 else if (message[j-1]=='(') users[i].counters[D_FROWN]++;
710 if (rand()%users[i].lines==0) strncpy(users[i].quote,message,MAXQUOTELENGTH);
711 if (strncmp("http://",message,7)==0)
713 users[i].counters[D_URL]++;
714 for (i=0;(message[i]!=' ') && (i<strlen(message));i++);
717 if ((nburls<=NBURLS) || (rand()%(nburls/NBURLS)==0))
719 temp=nburls<=NBURLS?nburls-1:rand()%NBURLS;
720 strcpy(urls[temp].nick,nick);
721 strcpy(urls[temp].url,message);
722 strncpy(urls[temp].shorturl,message,MAXQUOTELENGTH);
730 if (debug) printf(" done\n");
733 void parse_nick(char *nickfile)
738 char line[MAXLINELENGTH];
741 for (i=0;i<nbusers;i++) users[i].temp=users[i].lines;
742 if ((fic=fopen(nickfile,"rt"))==NULL) { fprintf(stderr,"can't open nick file \"%s\"\n",nickfile); exit(1); }
743 while (fscanf(fic,"%s",line)==1)
745 user=dichotomic(line);
746 fscanf(fic,"%s",line);
747 if (regcomp(&preg,line,0)!=0) { fprintf(stderr,"error in nick file"); exit(1); }
748 for (i=0;i<nbusers;i++) if ((i!=user) && (regexec(&preg,users[i].nick,0,0,0)==0) && (users[i].lines>=0))
750 if (users[i].temp>users[user].temp) /* for nick alias, keep the random quote of the most used nick */
752 strcpy(users[user].quote,users[i].quote);
753 users[user].temp=users[i].temp;
755 users[user].lines+=users[i].lines;
756 users[user].letters+=users[i].letters;
757 for (j=0;j<4;j++) users[user].hours[j]+=users[i].hours[j];
758 for (j=0;j<NBCOUNTERS;j++) users[user].counters[j]+=users[i].counters[j];
759 /* "remove" old user */
762 for (j=0;j<4;j++) users[i].hours[j]=-1;
763 for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=-1;
768 /* "remove" the ignored nicks */
769 i=dichotomic("<NULL>");
772 for (j=0;j<4;j++) users[i].hours[j]=-1;
773 for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=-1;
776 void gen_xhtml(char *xhtmlfile)
782 char line[MAXLINELENGTH];
784 if ((fic=fopen(xhtmlfile,"wt"))==NULL) { fprintf(stderr,"can't open xhtml file \"%s\"\n",xhtmlfile); exit(1); }
787 if (strcmp("none",header)==0)
789 fprintf(fic,"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n");
790 fprintf(fic,"<!-- Generated by irssistats %s : %s -->\n\n",VERSION,URL);
791 fprintf(fic,"<html>\n\n<head>\n<title>");
792 fprintf(fic,L("HEADER"),channel,maintainer);
793 fprintf(fic,"</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n");
795 fprintf(fic,"<meta http-equiv=\"Refresh\" content=\"%d\" />\n",refresh_time);
796 fprintf(fic,"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s.css\" />\n",theme);
797 fprintf(fic,"</head>\n\n");
798 fprintf(fic,"<body>\n\n");
802 if ((sfic=fopen(header,"rt"))==NULL) { fprintf(stderr,"can't open header file \"%s\"\n",header); exit(1); }
803 while ((temp=fread(line,1,MAXLINELENGTH,sfic))) fwrite(line,temp,1,fic);
806 fprintf(fic,"<div id=\"irssistats\">\n\n<div id=\"irssistats_header\">\n<h1>");
807 fprintf(fic,L("HEADER"),channel,maintainer);
808 fprintf(fic,"</h1>\n<p>\n%s</p>\n</div>\n\n",ctime(&debut));
811 fprintf(fic,"<div id=\"irssistats_legend\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("LEGEND"));
812 for (i=0;i<4;i++) fprintf(fic,"<td><div class=\"h%d\" style=\"width: 40px\"></div></td><td>%s %d-%d</td>\n",i+1,L("HOURS"),i*6,i*6+5);
813 fprintf(fic,"</tr>\n</table>\n</div>\n\n");
816 fprintf(fic,"<div id=\"irssistats_lastdays\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("LASTDAYS"));
818 for (i=30;i>=0;i--) if (lastdays[i].lines>max) max=lastdays[i].lines;
821 fprintf(fic,"<td align=\"center\" valign=\"bottom\"><small>%d</small>",lastdays[i].lines); /* width=\"15\" */
822 for (j=0;j<4;j++) if (lastdays[i].hours[j]!=0) fprintf(fic,"<div class=\"v%d\" style=\"height:%dpx\"></div>",j+1,150*lastdays[i].hours[j]/max);
823 fprintf(fic,"</td>\n");
825 fprintf(fic,"</tr>\n<tr>\n");
827 fprintf(fic,"<th>%d</th>\n",i);
828 fprintf(fic,"</tr>\n</table>\n</div>\n\n");
831 fprintf(fic,"<div id=\"irssistats_tophours\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("TOPHOURS"));
833 for (i=0;i<24;i++) if (hours[i]>max) max=hours[i];
836 fprintf(fic,"<td align=\"center\" valign=\"bottom\"><small>%.1f%%</small>",lines!=0?(float)100*hours[i]/lines:0); /* width=\"15\" */
837 if (hours[i]!=0) fprintf(fic,"<div class=\"v%d\" style=\"height:%dpx\"></div>",i/6+1,150*hours[i]/max);
838 fprintf(fic,"</td>\n");
840 fprintf(fic,"</tr>\n<tr>\n");
842 fprintf(fic,"<th>%d</th>\n",i);
843 fprintf(fic,"</tr>\n</table>\n</div>\n\n");
846 fprintf(fic,"<div id=\"irssistats_topusers\">\n<h2>%s</h2>\n",L("TOPUSERS"));
847 fprintf(fic,"<table>\n<tr><th></th><th>%s</th><th>%s</th><th>%s</th><th colspan=\"2\">%s</th><th>%s</th></tr>\n",L("NICK"),L("NBLINES"),L("HOURS"),L("AVGLETTERS"),L("QUOTE"));
848 for (i=1;i<=NBUSERS;i++)
852 for (j=0;j<nbusers;j++) if (users[j].lines>max) max=users[user=j].lines;
855 fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].lines);
856 for (j=0;j<4;j++) if (users[user].hours[j]!=0) fprintf(fic,"<div class=\"h%d\" style=\"width:%dpx\"></div>",j+1,100*users[user].hours[j]/users[user].lines);
857 fprintf(fic,"</td><td>%d</td><td><div class=\"hm\" style=\"width:%dpx\"></div></td><td>\"",users[user].lines!=0?users[user].letters/users[user].lines:0,users[user].lines!=0?users[user].letters/users[user].lines:0);
858 printhtml(fic,users[user].quote);
859 fprintf(fic,"\"</td></tr>\n");
860 users[user].lines=-1;
863 fprintf(fic,"</table>\n");
865 for (i=0;i<=nbusers;i++) if (users[i].lines>=0) temp++;
869 fprintf(fic,L("OTHERS"),temp);
870 fprintf(fic,"</p>\n");
872 fprintf(fic,"</div>\n\n");
874 /* top users by time */
875 fprintf(fic,"<div id=\"irssistats_topuserstime\">\n<h2>%s</h2>\n",L("TOPUSERSTIME"));
876 fprintf(fic,"<table>\n<tr><th></th>");
877 for (i=0;i<4;i++) fprintf(fic,"<th colspan=\"2\">%s %d-%d</th>",L("HOURS"),i*6,i*6+5);
878 fprintf(fic,"</tr>\n");
879 for (i=1;i<=NBUSERSTIME;i++)
881 fprintf(fic,"<tr><td>%d</td>",i);
886 for (k=0;k<nbusers;k++) if (users[k].hours[j]>max) max=users[user=k].hours[j];
889 fprintf(fic,"<td>%s</td><td>%d</td>",users[user].nick,users[user].hours[j]);
890 users[user].hours[j]=-1;
892 else fprintf(fic,"<td></td><td></td>");
894 fprintf(fic,"</tr>\n");
896 fprintf(fic,"</table>\n</div>\n\n");
899 fprintf(fic,"<div id=\"irssistats_randtopics\">\n<h2>%s</h2>\n",L("RANDTOPICS"));
900 fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th></tr>\n",L("CHANGEDBY"),L("NEWTOPIC"));
901 for (i=nbtopics<NBTOPICS?nbtopics-1:NBTOPICS-1;i>=0;i--)
903 fprintf(fic,"<tr><td>%s</td><td>\"",topics[i].nick);
904 printhtml(fic,topics[i].topic);
905 fprintf(fic,"\"</td></tr>\n");
907 fprintf(fic,"</table>\n</div>\n\n");
910 fprintf(fic,"<div id=\"irssistats_randurls\">\n<h2>%s</h2>\n",L("RANDURLS"));
911 fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th></tr>\n",L("POSTEDBY"),L("POSTEDURL"));
912 for (i=nburls<NBURLS?nburls-1:NBURLS-1;i>=0;i--)
914 fprintf(fic,"<tr><td>%s</td><td>\"<a href=\"",urls[i].nick);
915 printhtml(fic,urls[i].url);
917 printhtml(fic,urls[i].shorturl);
918 fprintf(fic,"</a>\"</td></tr>\n");
920 fprintf(fic,"</table>\n</div>\n\n");
923 fprintf(fic,"<div id=\"irssistats_topwords\">\n<h2>%s</h2>\n",L("TOPWORDS"));
924 fprintf(fic,"<table>\n<tr><th></th><th>%s</th><th>%s</th></tr>\n",L("WORD"),L("OCCURRENCES"));
925 for (i=0;i<NBWORDS;i++)
926 if (topwords[i].nb!=0) fprintf(fic,"<tr><td>%d</td><td>\"%s\"</td><td>%d</td></tr>\n",i+1,topwords[i].word,topwords[i].nb);
927 fprintf(fic,"</table>\n</div>\n\n");
930 fprintf(fic,"<div id=\"irssistats_bignumbers\">\n<h2>%s</h2>\n",L("BIGNUMBERS"));
931 fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n",L("NICK"),L("NUMBERS"),L("NBLINES"));
932 for (i=0;i<NBCOUNTERS;i++)
936 for (j=0;j<nbusers;j++) if (users[j].counters[i]>max) max=users[user=j].counters[i];
937 if (user!=-1) fprintf(fic,"<tr><td>%s</td><td>%s</td><td>%d</td></tr>",users[user].nick,L(counters[i]),users[user].counters[i]);
939 fprintf(fic,"</table>\n</div>\n\n");
942 fprintf(fic,"<div id=\"irssistats_footer\">\n<p>");
943 fprintf(fic,L("TIME"),totallines,days,(int)(time(NULL)-debut));
944 fprintf(fic,"</p>\n<p>%s <a href=\"%s\">irssistats %s</a></p>\n",L("FOOTER"),URL,VERSION);
947 fprintf(fic,"<p>\n<a href=\"http://validator.w3.org/check/referer\"><img src=\"valid-xhtml10.png\" height=\"31\" width=\"88\" alt=\"Valid XHTML 1.0!\" /></a>\n");
948 fprintf(fic,"<a href=\"http://jigsaw.w3.org/css-validator/check/referer\"><img src=\"valid-css.png\" height=\"31\" width=\"88\" alt=\"Valid CSS!\" /></a>\n</p>\n");
950 fprintf(fic,"</div>\n\n</div>");
951 if (strcmp("none",header)==0)
953 fprintf(fic,"\n\n</body>\n\n</html>\n");
957 if ((sfic=fopen(footer,"rt"))==NULL) { fprintf(stderr,"can't open footer file \"%s\"\n",footer); exit(1); }
958 while ((temp=fread(line,1,MAXLINELENGTH,sfic))) fwrite(line,temp,1,fic);
965 void parse_config(char *configfile)
968 char line[MAXLINELENGTH];
969 char keyword[MAXLINELENGTH];
970 char value[MAXLINELENGTH];
974 if (configfile!=NULL)
976 if ((fic=fopen(configfile,"rt"))==NULL)
978 fprintf(stderr,"can't open config file : \"%s\"\n",configfile);
984 sprintf(line,"%s/.irssistats",getenv("HOME"));
985 if ((fic=fopen(line,"rt"))==NULL)
986 if ((fic=fopen("/etc/irssistats.conf","rt"))==NULL)
988 fprintf(stderr,"can't find config file : \"%s\" nor \"/etc/irssistats.conf\"\n",line);
989 fprintf(stderr,"please give the path to the config file in argument\n");
994 while (fgets(line,MAXLINELENGTH,fic))
997 if (*line!=';' && *line!='#' && *line!='/' && *line!='-' && *line!='\n')
999 if ((sscanf(line,"%s : %s\n",(char *)&keyword,(char *)&value))!=2) { fprintf(stderr,"error in config file : each line must have the format \"keyword : value\" (line %d)\n",configlines); exit(1); }
1001 if (strcmp("debug",keyword)==0)
1003 if (strcmp("none",value)==0) debug=0;
1005 if (strcmp("normal",value)==0) debug=1;
1007 if (strcmp("verbose",value)==0) { debug=2; fprintf(stderr,"switching to verbose output\n"); }
1008 else { fprintf(stderr,"unknown value for \"debug\" option, must be \"normal\", \"verbose\" or \"none\"\n"); exit(1); }
1011 if (strcmp("channel",keyword)==0)
1013 if (debug==2) fprintf(stderr,"setting channel name to \"%s\"\n",value);
1014 strcpy(channel,value);
1018 if (strcmp("maintainer",keyword)==0)
1020 if (debug==2) fprintf(stderr,"setting maintainer to \"%s\"\n",value);
1021 strcpy(maintainer,value);
1025 if (strcmp("language",keyword)==0)
1027 if (debug==2) fprintf(stderr,"setting language to \"%s\"\n",value);
1028 for (i=0;i<NBLANGUAGES;i++) if (strcmp(value,keys[i][0][1])==0) { language=i; break; }
1031 fprintf(stderr,"Invalid language : %s\n",value);
1032 fprintf(stderr,"Supported languages :\n");
1033 for (i=0;i<NBLANGUAGES;i++) fprintf(stderr,"%s = %s\n",keys[i][0][1],keys[i][0][0]);
1039 if (strcmp("theme",keyword)==0)
1041 if (debug==2) fprintf(stderr,"setting theme to \"%s\"\n",value);
1042 strcpy(theme,value);
1046 if (strcmp("refresh_time",keyword)==0)
1048 refresh_time=atoi(value);
1049 if (debug==2) fprintf(stderr,"setting refresh_time to \"%d\"\n",refresh_time);
1053 if (strcmp("w3c_link",keyword)==0)
1055 if (debug==2) fprintf(stderr,"setting w3c_link to \"%s\"\n",value);
1056 if (strcmp("no",value)==0) w3c_link=0;
1057 else if (strcmp("yes",value)==0) w3c_link=1;
1058 else { fprintf(stderr,"unknown value for \"w3c_link\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1062 if (strcmp("header",keyword)==0)
1064 if (debug==2) fprintf(stderr,"setting header to \"%s\"\n",value);
1065 strcpy(header,value);
1069 if (strcmp("footer",keyword)==0)
1071 if (debug==2) fprintf(stderr,"setting footer to \"%s\"\n",value);
1072 strcpy(footer,value);
1076 if (strcmp("input",keyword)==0)
1078 if (debug==2) fprintf(stderr,"parsing log file \"%s\"\n",value);
1083 if (strcmp("nickfile",keyword)==0)
1085 if (debug==2) fprintf(stderr,"nick alias using file \"%s\"\n",value);
1090 if (strcmp("output",keyword)==0)
1092 if (debug==2) fprintf(stderr,"generating xhtml file \"%s\"\n",value);
1096 /* reset variables */
1101 for (i=0;i<24;i++) hours[i]=0;
1104 for (i=0;i<NBWORDS;i++) topwords[i].nb=0;
1109 else { fprintf(stderr,"error in config file : \"%s\" is an unknown keyword (line %d)\n",keyword,configlines); exit(1); }
1115 int main(int argc,char *argv[])
1117 srand(debut=time(NULL));
1118 if (argc==1) parse_config(NULL);
1119 else if (argc==2) parse_config(argv[1]);
1122 fprintf(stderr,"Usage : %s [/path/to/file.conf]\n",argv[0]);
1123 fprintf(stderr,"Version : irssistats %s\n",VERSION);