2 * irssistats version 0.71
4 * This tool generates IRC stats based on irssi logs.
5 * Usage: irssistats [/path/to/file.conf]
7 * Copyright (C) 2002-2004 Antoine Jacquet <royale@zerezo.com>
8 * http://royale.zerezo.com/irssistats/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/types.h>
32 #define GLOBALCONF "irssistats.conf"
34 #define GLOBALCONF "/etc/irssistats.conf"
39 #define BASEUSERS 1000
40 #define MAXNICKLENGTH 50
41 #define MAXLINELENGTH 2000
42 #define MAXQUOTELENGTH 100
44 #define NBUSERSTIME 10
48 #define MINWORDLENGTH 5
51 #define VERSION "0.71"
52 #define URL "http://royale.zerezo.com/irssistats/"
67 #define D_MONOLOGUE 12
69 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"};
72 #define NBLANGUAGES 11
74 char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and abbreviation */
76 { /* English language */
78 { "CHARSET", "ISO-8859-1" },
79 { "HEADER", "Statistics for %s by %s" },
80 { "LEGEND", "Legend" },
81 { "LASTDAYS", "Lastdays statistics" },
82 { "TOPHOURS", "Hourly statistics" },
83 { "TOPUSERS", "Most active people" },
84 { "OTHERS", "There are %d left not ranked..." },
85 { "NBLINES", "lines" },
87 { "AVGLETTERS", "letters/lines" },
89 { "QUOTE", "random message" },
90 { "TOPUSERSTIME", "Most active people by time of day" },
91 { "RANDTOPICS", "Some topics" },
92 { "CHANGEDBY", "changed by" },
93 { "NEWTOPIC", "new topic" },
94 { "RANDURLS", "Some URLs" },
95 { "POSTEDBY", "posted by" },
96 { "POSTEDURL", "URL" },
97 { "TOPWORDS", "Most used words" },
99 { "OCCURRENCES", "occurrences" },
100 { "BIGNUMBERS", "Some big numbers..." },
101 { "NUMBERS", "numbers" },
102 { "TIME", "%d lines (%d days) parsed in %d seconds" },
103 { "FOOTER", "Statistics generated by" },
104 { "C_SMILE", "is often happy :)" },
105 { "C_FROWN", "is often sad :(" },
106 { "C_EXCLAM", "yells a lot !" },
107 { "C_QUESTION", "asks a lot of questions ?" },
108 { "C_ME", "likes /me command" },
109 { "C_TOPIC", "often changes the topic" },
110 { "C_MODE", "often changes the modes" },
111 { "C_KICK", "likes to /kick" },
112 { "C_KICKED", "is often kicked" },
113 { "C_URL", "posts many URLs" },
114 { "C_JOIN", "doesn't know wether to stay or quit" },
115 { "C_NICK", "often changes his nick" },
116 { "C_MONOLOGUE", "speaks a lot of monologues" }
118 { /* French language */
120 { "CHARSET", "ISO-8859-1" },
121 { "HEADER", "Statistiques de %s par %s" },
122 { "LEGEND", "Légende" },
123 { "LASTDAYS", "Statistiques des derniers jours" },
124 { "TOPHOURS", "Statistiques horaires" },
125 { "TOPUSERS", "Personnes les plus actives" },
126 { "OTHERS", "Il reste %d personnes non classées..." },
127 { "NBLINES", "lignes" },
129 { "AVGLETTERS", "lettres/lignes" },
130 { "HOURS", "heures" },
131 { "QUOTE", "message aléatoire" },
132 { "TOPUSERSTIME", "Personnes les plus actives par période de la journée" },
133 { "RANDTOPICS", "Quelques topics" },
134 { "CHANGEDBY", "changé par" },
135 { "NEWTOPIC", "nouveau topic" },
136 { "RANDURLS", "Quelques URLs" },
137 { "POSTEDBY", "postée par" },
138 { "POSTEDURL", "URL" },
139 { "TOPWORDS", "Mots les plus utilisés" },
141 { "OCCURRENCES", "occurrences" },
142 { "BIGNUMBERS", "Quelques grands nombres..." },
143 { "NUMBERS", "nombres" },
144 { "TIME", "%d lignes (%d jours) traitées en %d secondes" },
145 { "FOOTER", "Statistiques générées par" },
146 { "C_SMILE", "est souvent heureux :)" },
147 { "C_FROWN", "est souvent triste :(" },
148 { "C_EXCLAM", "hurle beaucoup !" },
149 { "C_QUESTION", "pose beaucoup de questions ?" },
150 { "C_ME", "aime la commande /me" },
151 { "C_TOPIC", "change souvent le topic" },
152 { "C_MODE", "change souvent les modes" },
153 { "C_KICK", "aime la commande /kick" },
154 { "C_KICKED", "est souvent kické" },
155 { "C_URL", "poste beaucoup d'URLs" },
156 { "C_JOIN", "ne sait pas s'il doit rester ou partir" },
157 { "C_NICK", "change souvent de nick" },
158 { "C_MONOLOGUE", "parle beaucoup de monologues" }
160 { /* German language */
161 /* contributed by Valentin Gelhorn <valentin.gelhorn@web.de> */
163 { "CHARSET", "ISO-8859-1" },
164 { "HEADER", "Statistiken für %s von %s" },
165 { "LEGEND", "Legende" },
166 { "LASTDAYS", "Statistik der letzten Tage" },
167 { "TOPHOURS", "Stündliche Statistik" },
168 { "TOPUSERS", "Die aktivsten Personen" },
169 { "OTHERS", "Es bleiben noch %d uneingetragene" },
170 { "NBLINES", "Zeilen" },
172 { "AVGLETTERS", "Buchstaben/Zeile" },
173 { "HOURS", "Stunden" },
174 { "QUOTE", "Zufällig ausgewaehlte Zitate" },
175 { "TOPUSERSTIME", "Die aktivsten Personen zur bestimmten Tageszeit" },
176 { "RANDTOPICS", "Ein paar Topics" },
177 { "CHANGEDBY", "Gesetzt von" },
178 { "NEWTOPIC", "Neues topic" },
179 { "RANDURLS", "Ein paar URLs" },
180 { "POSTEDBY", "Geschrieben von" },
181 { "POSTEDURL", "URL" },
182 { "TOPWORDS", "Am häufigsten benutze Wörter" },
184 { "OCCURRENCES", "Vorkommen" },
185 { "BIGNUMBERS", "Ein paar grosse Zahlen" },
186 { "NUMBERS", "Zahlen" },
187 { "TIME", "%d Zeilen (%d Tage) analysiert in %d Sekunden" },
188 { "FOOTER", "Statistiken wurden erstellt von" },
189 { "C_SMILE", "ist oft glüklich :)" },
190 { "C_FROWN", "ist oft traurig :(" },
191 { "C_EXCLAM", "schreit oft !" },
192 { "C_QUESTION", "stellt viele Fragen ?" },
193 { "C_ME", "mag /me'en" },
194 { "C_TOPIC", "aendert oft das Topico" },
195 { "C_MODE", "aendert oft die Modes" },
196 { "C_KICK", "mag /kick'en" },
197 { "C_KICKED", "wird oft gekickt"},
198 { "C_URL", "schreibt viele URLs"},
199 { "C_JOIN", "kann sich nicht entscheiden ob er bleiben oder gehen soll" },
200 { "C_NICK", "ändert oft seinen Nick" },
201 { "C_MONOLOGUE", "spricht oft Monologe" }
203 { /* Spanish language */
204 /* contributed by Alex <ainaker@gmx.net> */
206 { "CHARSET", "ISO-8859-1" },
207 { "HEADER", "Estadísticas de %s por %s" },
208 { "LEGEND", "Leyenda" },
209 { "LASTDAYS", "Estadísticas de los últimos días" },
210 { "TOPHOURS", "Estadísticas por horas" },
211 { "TOPUSERS", "Los que más escriben" },
212 { "OTHERS", "Hay %d más que no llegaron..." },
213 { "NBLINES", "líneas" },
215 { "AVGLETTERS", "letras por línea" },
216 { "HOURS", "horas" },
217 { "QUOTE", "Frase aleatoria" },
218 { "TOPUSERSTIME", "Los que más escriben según la hora" },
219 { "RANDTOPICS", "Algunos topics" },
220 { "CHANGEDBY", "Puestos por" },
221 { "NEWTOPIC", "topic" },
222 { "RANDURLS", "Algunas URLs" },
223 { "POSTEDBY", "puestas por" },
224 { "POSTEDURL", "URL" },
225 { "TOPWORDS", "Palabras más usadas" },
226 { "WORD", "Palabra" },
227 { "OCCURRENCES", "Frecuencia" },
228 { "BIGNUMBERS", "Algunos datos..." },
229 { "NUMBERS", "Número de veces" },
230 { "TIME", "%d lineas (%d días) procesadas en %d segundos" },
231 { "FOOTER", "Estadísticas generadas por" },
232 { "C_SMILE", "Suele estar felíz :)" },
233 { "C_FROWN", "Suele estar triste :(" },
234 { "C_EXCLAM", "Grita mucho !" },
235 { "C_QUESTION", "Hace muchas preguntas ?" },
236 { "C_ME", "Abusa del comando /me" },
237 { "C_TOPIC", "Suele cambiar el topic" },
238 { "C_MODE", "Cambia a veces los modos del canal" },
239 { "C_KICK", "Le gusta patear" },
240 { "C_KICKED", "Es pateado con frecuencia" },
241 { "C_URL", "Pone muchas URLs" },
242 { "C_JOIN", "No sabe si irse o quedarse" },
243 { "C_NICK", "Cambia mucho de nick" },
244 { "C_MONOLOGUE", "Habla solo" }
246 { /* Polish language */
247 /* contributed by Jakub Jankowski <shasta@atn.pl> */
249 { "CHARSET", "ISO-8859-2" },
250 { "HEADER", "Statystyki dla %s zebrane przez %s" },
251 { "LEGEND", "Legenda" },
252 { "LASTDAYS", "Statystyki z ostatnich dni" },
253 { "TOPHOURS", "Statystyki godzinowe" },
254 { "TOPUSERS", "Najaktywniejsi" },
255 { "OTHERS", "Jest jeszcze %d nie sklasyfikowanych..." },
256 { "NBLINES", "linii" },
258 { "AVGLETTERS", "liter/liniê" },
259 { "HOURS", "godziny" },
260 { "QUOTE", "losowa wypowied¼" },
261 { "TOPUSERSTIME", "Najaktywniejsi wed³ug pory dnia" },
262 { "RANDTOPICS", "Kilka topików" },
263 { "CHANGEDBY", "ustawiony przez" },
264 { "NEWTOPIC", "topik" },
265 { "RANDURLS", "Kilka URL-i" },
266 { "POSTEDBY", "poda³(a)" },
267 { "POSTEDURL", "URL" },
268 { "TOPWORDS", "Najczê¶ciej wystêpuj±ce s³owa" },
270 { "OCCURRENCES", "wyst±pieñ" },
271 { "BIGNUMBERS", "Kilka wielkopomnych liczb..." },
272 { "NUMBERS", "kategorie" },
273 { "TIME", "Dokonano analizy %d linii (obejmuj±cych %d dni) w czasie %d sekund" },
274 { "FOOTER", "Statystyki wygenerowane przez" },
275 { "C_SMILE", "jest czêsto szczesliwy(a) :)" },
276 { "C_FROWN", "jest czêsto smutny(a) :(" },
277 { "C_EXCLAM", "czêsto KRZYCZY!" },
278 { "C_QUESTION", "zadaje du¿o pytañ?" },
279 { "C_ME", "lubi u¿ywaæ /me" },
280 { "C_TOPIC", "czêsto zmienia topik" },
281 { "C_MODE", "czêsto zmienia tryby kana³u" },
282 { "C_KICK", "lubi kopaæ" },
283 { "C_KICKED", "czêsto wykopywany(a)" },
284 { "C_URL", "podaje du¿o URL-i" },
285 { "C_JOIN", "nie wie czy zostaæ, czy wyj¶æ" },
286 { "C_NICK", "czêsto zmienia nick" },
287 { "C_MONOLOGUE", "uwielbia monologi" }
289 { /* Polish language */
290 /* contributed by Piotr Jarmuz <coreupper@yahoo.com> */
291 { "Polish", "pl-old" },
292 { "CHARSET", "ISO-8859-1" },
293 { "HEADER", "Statystyki dla %s przez %s" },
294 { "LEGEND", "Legenda" },
295 { "LASTDAYS", "Statystyki z ostatnich dni" },
296 { "TOPHOURS", "Statystyki godzinne" },
297 { "TOPUSERS", "Najaktywniejsi ludzie" },
298 { "OTHERS", "Zostalo jeszcze %d nie sklasyfikowanych..." },
299 { "NBLINES", "linie" },
301 { "AVGLETTERS", "litery/linie" },
302 { "HOURS", "godziny" },
303 { "QUOTE", "przypadkowa wiadomosc" },
304 { "TOPUSERSTIME", "Najaktywniejsi ludzie wedlug czasu dnia" },
305 { "RANDTOPICS", "Pare tematow" },
306 { "CHANGEDBY", "zmienione przez" },
307 { "NEWTOPIC", "nowy temat" },
308 { "RANDURLS", "Pare URL-i" },
309 { "POSTEDBY", "wyslane przez" },
310 { "POSTEDURL", "URL" },
311 { "TOPWORDS", "Najczestsze slowa" },
313 { "OCCURRENCES", "wystapienia" },
314 { "BIGNUMBERS", "Pare wielkich liczb..." },
315 { "NUMBERS", "liczby" },
316 { "TIME", "%d linii (%d dni) sparsowanych w %d sekund" },
317 { "FOOTER", "Statystyki wygenerowane przez" },
318 { "C_SMILE", "jest czesto szczesliwy :)" },
319 { "C_FROWN", "jest czesto smutny :(" },
320 { "C_EXCLAM", "duzo krzyczy !" },
321 { "C_QUESTION", "zadaje duzo pytan ?" },
322 { "C_ME", "lubi /mnie polecenie" },
323 { "C_TOPIC", "czesto zmienia temat" },
324 { "C_MODE", "czesto zmienia tryb" },
325 { "C_KICK", "lubi /kopac" },
326 { "C_KICKED", "czesto go wykopuja" },
327 { "C_URL", "wysyla duzo URL-i" },
328 { "C_JOIN", "nie wie czy zostac czy wyjsc" },
329 { "C_NICK", "czesto zmienia swojego nicka" },
330 { "C_MONOLOGUE", "czesto mowi monologiem" }
332 { /* Finnish language */
333 /* contributed by Antti Huopana <ahuopana@ratol.fi> */
335 { "CHARSET", "ISO-8859-1" },
336 { "HEADER", "Kanavan %s tilastot - %s" },
337 { "LEGEND", "Merkkien selitykset" },
338 { "LASTDAYS", "Viime päivien tilastot" },
339 { "TOPHOURS", "Tilastot tunneittain" },
340 { "TOPUSERS", "Aktiivisimmat ihmiset" },
341 { "OTHERS", "Jäljelle jäi %d joita ei listattu..." },
342 { "NBLINES", "rivit" },
344 { "AVGLETTERS", "kirjainta/rivi" },
345 { "HOURS", "tunnit" },
346 { "QUOTE", "satunnainen viesti" },
347 { "TOPUSERSTIME", "Vuorokauden ajan mukaan aktiivisimmat" },
348 { "RANDTOPICS", "Joitakin aiheita" },
349 { "CHANGEDBY", "vaihtaja" },
350 { "NEWTOPIC", "aihe" },
351 { "RANDURLS", "Joitakin URLeja" },
352 { "POSTEDBY", "lähettäjä" },
353 { "POSTEDURL", "URL" },
354 { "TOPWORDS", "Eniten käytettyjä sanoja" },
356 { "OCCURRENCES", "käytetty" },
357 { "BIGNUMBERS", "Joitakin isoja lukuja..." },
358 { "NUMBERS", "luvut" },
359 { "TIME", "%d riviä (%d päivää) parsittu %d sekunnissa" },
360 { "FOOTER", "Tilastot on generoinut" },
361 { "C_SMILE", "on usein iloinen :)" },
362 { "C_FROWN", "on usein surullinen :(" },
363 { "C_EXCLAM", "möykkää paljon !" },
364 { "C_QUESTION", "kyselee liikaa ?" },
365 { "C_ME", "pitää itsestään" },
366 { "C_TOPIC", "vaihtaa usein aihetta" },
367 { "C_MODE", "haluaa elää muuttuvassa maailmassa" },
368 { "C_KICK", "pitää potkimisesta" },
369 { "C_KICKED", "tykkää tulla potkituksi" },
370 { "C_URL", "surffailee liikaa" },
371 { "C_JOIN", "ei tiedä ollakko vai eikö olla" },
372 { "C_NICK", "kärsii identiteettiongelmista" },
373 { "C_MONOLOGUE", "höpöttää paljon itsekseen" }
375 { /* Italian language */
376 /* contributed by Coviello Giuseppe <giuseppecoviello@tin.it> <http://coviello.altervista.org> */
378 { "CHARSET", "ISO-8859-1" },
379 { "HEADER", "Statistiche per il canale %s di %s" },
380 { "LEGEND", "Legenda" },
381 { "LASTDAYS", "Statistiche degli ultimi giorni" },
382 { "TOPHOURS", "Statistiche in ore" },
383 { "TOPUSERS", "Utenti più attivi" },
384 { "OTHERS", "Ci sono %d utenti non classificati..." },
385 { "NBLINES", "righe" },
387 { "AVGLETTERS", "lettere/righe" },
389 { "QUOTE", "messaggio casuale" },
390 { "TOPUSERSTIME", "Utenti più attivi del giorno (divisi per fasce orarie)" },
391 { "RANDTOPICS", "Alcuni topic" },
392 { "CHANGEDBY", "cambiato da" },
393 { "NEWTOPIC", "nuovo topic" },
394 { "RANDURLS", "ALcuni URL" },
395 { "POSTEDBY", "postato da" },
396 { "POSTEDURL", "URL" },
397 { "TOPWORDS", "Le parole più usate" },
398 { "WORD", "parola" },
399 { "OCCURRENCES", "usata" },
400 { "BIGNUMBERS", "Alcuni numeri ..." },
401 { "NUMBERS", "numeri" },
402 { "TIME", "%d righe (%d giorni) esaminate in %d secondi" },
403 { "FOOTER", "Statistiche generate da" },
404 { "C_SMILE", "è spesso felice :)" },
405 { "C_FROWN", "è spesso triste :(" },
406 { "C_EXCLAM", "esclama molto !" },
407 { "C_QUESTION", "fa molte domande ?" },
408 { "C_ME", "ama il comando /me" },
409 { "C_TOPIC", "cambia spesso il topic" },
410 { "C_MODE", "cambia spesso i mode" },
411 { "C_KICK", "ama /kick(are)" },
412 { "C_KICKED", "è kickato spesso" },
413 { "C_URL", "posta molti URL" },
414 { "C_JOIN", "non sa se è ora di andare o restare" },
415 { "C_NICK", "cambia spesso il nick" },
416 { "C_MONOLOGUE", "fa molti monologhi" }
418 { /* Dutch language */
419 /* contributed by Jeroen Ubbink <crasp@blackbyte.nl> */
420 /* updated by Wouter Horré <wouter@ligezin.be> */
422 { "CHARSET", "ISO-8859-1" },
423 { "HEADER", "Statistieken voor %s door %s" },
424 { "LEGEND", "Legenda" },
425 { "LASTDAYS", "Statistieken van de laatste dagen" },
426 { "TOPHOURS", "Statistieken per uur" },
427 { "TOPUSERS", "Meest actieve mensen" },
428 { "OTHERS", "Er zijn nog %d mensen die de top niet haalden..." },
429 { "NBLINES", "regels" },
431 { "AVGLETTERS", "letters/lijn" },
433 { "QUOTE", "Willekeurige regel" },
434 { "TOPUSERSTIME", "Meest actieve mensen per tijdstip per dag" },
435 { "RANDTOPICS", "Enkele topics" },
436 { "CHANGEDBY", "gewijzigd door" },
437 { "NEWTOPIC", "nieuwe topic" },
438 { "RANDURLS", "Enkele URLs" },
439 { "POSTEDBY", "Geplaatst door" },
440 { "POSTEDURL", "URL" },
441 { "TOPWORDS", "Meest gebruikte woorden" },
443 { "OCCURRENCES", "aantal" },
444 { "BIGNUMBERS", "Enkele grote aantallen..." },
445 { "NUMBERS", "numbers" },
446 { "TIME", "%d regels (%d dagen) verwerkt in %d seconden" },
447 { "FOOTER", "Statistieken gegenereerd door" },
448 { "C_SMILE", "is vaak vrolijk :)" },
449 { "C_FROWN", "is vaak droevig :(" },
450 { "C_EXCLAM", "schreeuwt veel !" },
451 { "C_QUESTION", "stelt veel vragen ?" },
452 { "C_ME", "vindt /me een leuk commando" },
453 { "C_TOPIC", "verandert vaak de topic" },
454 { "C_MODE", "verandert vaak de modes" },
455 { "C_KICK", "vindt /kick erg leuk" },
456 { "C_KICKED", "wordt vaak gekickt" },
457 { "C_URL", "plaatst veel URLs" },
458 { "C_JOIN", "twijfelt tussen blijven of gaan" },
459 { "C_NICK", "verandert vaak van nick" },
460 { "C_MONOLOGUE", "spreekt veel monologen" }
462 { /* Russian language */
463 /* contributed by kamikaze <kamikaze@rss.lv> */
465 { "CHARSET", "KOI8-R" },
466 { "HEADER", "óÔÁÔÉÓÔÉËÁ ÄÌÑ %s ÏÔ %s" },
467 { "LEGEND", "ïÂÏÚÎÁÞÅÎÉÑ" },
468 { "LASTDAYS", "óÔÁÔÉÓÔÉËÁ ÐÏÓÌÅÄÎÉÈ ÄÎÅÊ" },
469 { "TOPHOURS", "ðÏÞÁÓÏ×ÁÑ ÓÔÁÔÉÓÔÉËÁ" },
470 { "TOPUSERS", "áËÔÉ×ÎÅÊÛÉÅ ÌÀÄÉ" },
471 { "OTHERS", "ïÓÔÁÌÏÓØ %d ÎÅÐÏÄÓÞÉÔÁÎÙÈ..." },
472 { "NBLINES", "ÓÔÒÏËÉ" },
474 { "AVGLETTERS", "ÂÕË×Ù/ÓÔÒÏËÉ" },
476 { "QUOTE", "ÓÌÕÞÁÊÎÏÅ ÓÏÏÂÝÅÎÉÅ" },
477 { "TOPUSERSTIME", "áËÔÉ×ÎÅÊÛÉÅ ÌÀÄÉ ÐÏ ×ÒÅÍÅÎÉ ÄÎÑ" },
478 { "RANDTOPICS", "îÅÓËÏÌØËÏ ÔÏÐÉËÏ×" },
479 { "CHANGEDBY", "ÉÚÍÅΣÎ" },
480 { "NEWTOPIC", "ÎÏ×ÙÊ ÔÏÐÉË" },
481 { "RANDURLS", "îÅÓËÏÌØËÏ URLÏ×" },
482 { "POSTEDBY", "ÏÐÕÂÌÉËÏ×ÁÌ" },
483 { "POSTEDURL", "URL" },
484 { "TOPWORDS", "þÁÓÔÏ ÉÓÐÏÌØÚÕÅÍÙÅ ÓÌÏ×Á" },
486 { "OCCURRENCES", "ÐÒÏÉÛÅÓÔ×ÉÑ" },
487 { "BIGNUMBERS", "îÅÓËÏÌØËÏ ÂÏÌØÛÉÈ ÞÉÓÅÌ..." },
488 { "NUMBERS", "ÞÉÓÌÁ" },
489 { "TIME", "%d ÓÔÒÏË (%d ÄÎÅÊ) ÏÂÒÁÂÏÔÁÎÏ ÚÁ %d ÓÅËÕÎÄ" },
490 { "FOOTER", "óÔÁÔÉÓÔÉËÁ ÓÇÅÎÅÒÉÒÏ×ÁÎÁ" },
491 { "C_SMILE", "ÞÁÓÔÏ ÓÞÁÓÌÉ× :)" },
492 { "C_FROWN", "ÞÁÓÔÏ ÎÅÓÞÁÓÔÅÎ :(" },
493 { "C_EXCLAM", "ÍÎÏÇÏ ×ÏÓËÌÉÃÁÅÔ !" },
494 { "C_QUESTION", "ÚÁÄÁ£Ô ÍÎÏÇÏ ×ÏÐÒÏÓÏ× ?" },
495 { "C_ME", "ÌÀÂÉÔ /me command" },
496 { "C_TOPIC", "ÞÁÓÔÏ ÍÅÎÑÅÔ ÔÏÐÉË" },
497 { "C_MODE", "ÞÁÓÔÏ ÍÅÎÑÅÔ ÒÅÖÉÍÙ" },
498 { "C_KICK", "ÌÀÂÉÔ /kick" },
499 { "C_KICKED", "ÞÁÓÔÏ ×ÙËÉÄÙ×ÁÀÔ" },
500 { "C_URL", "ÐÕÂÌÉËÕÅÔ ÍÎÏÇÏ URLÏ×" },
501 { "C_JOIN", "ÎÅ ÚÎÁÅÔ - ÏÓÔÁÔØÓÑ ÉÌÉ ÕÊÔÉ" },
502 { "C_NICK", "ÞÁÓÔÏ ÍÅÎÑÅÔ Ó×ÏÊ ÎÉË" },
503 { "C_MONOLOGUE", "éÓÐÏÌØÚÕÅÔ ÍÎÏÇÏ ÍÏÎÏÌÏÇÏ×" }
505 { /* Estonian language */
506 /* contributed by Martin Vool <mardicas@hot.ee> */
507 { "Estonian", "et" },
508 { "CHARSET", "ISO-8859-4" },
509 { "HEADER", "Statistika kanalile %s on koostanud %s" },
510 { "LEGEND", "Legend" },
511 { "LASTDAYS", "Viimaste päevade statistika" },
512 { "TOPHOURS", "Tunni statistika" },
513 { "TOPUSERS", "Kõige aktiivsemad inimesed" },
514 { "OTHERS", "%d inimest on rääkinud" },
515 { "NBLINES", "rida" },
517 { "AVGLETTERS", "tähte/rida" },
519 { "QUOTE", "suvaline teade" },
520 { "TOPUSERSTIME", "Kõige aktiivsemad inimesed päeva aja järgi" },
521 { "RANDTOPICS", "Mõned topicud" },
522 { "CHANGEDBY", "muutis" },
523 { "NEWTOPIC", "topicud" },
524 { "RANDURLS", "Mõned aadressid" },
525 { "POSTEDBY", "postitas" },
526 { "POSTEDURL", "URL" },
527 { "TOPWORDS", "Enim kasutatud sõnad" },
529 { "OCCURRENCES", "sagedus" },
530 { "BIGNUMBERS", "Mõned suured numbrid" },
531 { "NUMBERS", "iseloom" },
532 { "TIME", "%d rida (%d päeva) on möödunud %d sekundit" },
533 { "FOOTER", "Statistika on koostanud" },
534 { "C_SMILE", "on tihti õnnelik :)" },
535 { "C_FROWN", "on tihti kurb :(" },
536 { "C_EXCLAM", "põrnitseb palju" },
537 { "C_QUESTION", "küsib palju küsimusi" },
538 { "C_ME", "/me manjakk" },
539 { "C_TOPIC", "vahetab tihti topicut" },
540 { "C_MODE", "vahetab tihti modesid" },
541 { "C_KICK", "kickib palju" },
542 { "C_KICKED", "saab tihti kicke" },
543 { "C_URL", "reklaamib palju" },
544 { "C_JOIN", "sõelub sisse ja välja" },
545 { "C_NICK", "vahetab pidevalt nime" },
546 { "C_MONOLOGUE", "räägib palju monolooge" }
550 int language=0; /* default to english */
555 for (i=1;i<=NBKEYS;i++) if (strcmp(key,keys[language][i][0])==0) return(keys[language][i][1]);
556 fprintf(stderr,"unknown language key: %s\n",key);
562 int debug=1; /* 0 = none ; 1 = normal ; 2 = verbose */
563 char channel[MAXLINELENGTH]="set_channel_in_config_file";
564 char maintainer[MAXLINELENGTH]="set_maintainer_in_config_file";
565 char theme[MAXLINELENGTH]="default,biseau,blue,dark,damier,grayscale,namour,niflheim,pisg,zeduel,zerezo";
566 int refresh_time=0; /* 0 = disabled */
567 int w3c_link=1; /* 0 = disabled */
568 int logo=1; /* 0 = disabled */
569 char header[MAXLINELENGTH]="none";
570 char footer[MAXLINELENGTH]="none";
573 int top_words=1; /* 0 = disabled */
574 int ranking=0; /* 0 = lines ; 1 = words ; 2 = letters */
575 int quarter=0; /* 1 = enabled */
580 char nick[MAXNICKLENGTH];
585 char quote[MAXQUOTELENGTH+1];
586 int counters[NBCOUNTERS];
591 int maxusers=BASEUSERS;
595 char nick[MAXNICKLENGTH];
596 char url[MAXLINELENGTH];
597 char shorturl[MAXQUOTELENGTH+1];
603 char nick[MAXNICKLENGTH];
604 char topic[MAXQUOTELENGTH+1];
621 struct letter *next[26];
627 char word[MAXLINELENGTH];
630 #define isletter(c) (((c>='a')&&(c<='z'))||((c>='A')&&(c<='Z')))
631 #define lowercase(c) (((c>='A')&&(c<='Z'))?c-'A'+'a':c)
632 int findwords(char *message)
635 struct letter *pos,*tmp;
638 while (!isletter(*message)) if (*message=='\0') return n; else message++;
640 while (isletter(*message))
642 c=lowercase(*message)-'a';
643 if (pos->next[(int)c]==NULL)
645 tmp=malloc(sizeof(struct letter));
648 fprintf(stderr, "findwords(): malloc failure\n");
652 for (i=0;i<26;i++) tmp->next[i]=NULL;
653 pos->next[(int)c]=tmp;
655 pos=pos->next[(int)c];
664 char tempword[MAXLINELENGTH];
665 void bestwords(struct letter pos,int cur)
668 if ((cur>=MINWORDLENGTH)&&(pos.nb>topwords[NBWORDS-1].nb))
670 for (i=0;pos.nb<topwords[i].nb;i++);
671 for (j=NBWORDS-1;j>i;j--)
673 topwords[j].nb=topwords[j-1].nb;
674 strcpy(topwords[j].word,topwords[j-1].word);
676 topwords[i].nb=pos.nb;
677 strcpy(topwords[i].word,tempword);
679 for (i=0;i<26;i++) if (pos.next[i]!=NULL)
682 bestwords(*(pos.next[i]),cur+1);
687 void freewords(struct letter *pos)
690 for (i=0;i<26;i++) if (pos->next[i]!=NULL)
692 freewords(pos->next[i]);
698 void printhtml(FILE *fic,char *string) /* replace < and > by < and > */
700 while (*string!='\0')
704 case '<':fprintf(fic,"<"); break;
705 case '>':fprintf(fic,">"); break;
706 case '&':fprintf(fic,"&"); break;
707 default:fprintf(fic,"%c",*string); break;
714 int dichotomic(char *nick)
716 int i,j,start=0,end=nbusers-1,middle;
719 middle=(start+end)/2;
720 if (strcmp(nick,users[middle].nick)>0) start=middle+1; else end=middle-1;
722 if (strcmp(nick,users[start].nick)!=0)
725 if (nbusers>=maxusers)
728 if (debug==2) fprintf(stderr,"allocating more users : %d\n",maxusers);
729 if ((users=realloc(users,maxusers*sizeof(struct user)))==NULL) { fprintf(stderr,"too many users : unable to realloc memory\n"); exit(1); }
731 for (i=nbusers-1;i>start;i--)
733 strcpy(users[i].nick,users[i-1].nick);
734 users[i].lines=users[i-1].lines;
735 users[i].words=users[i-1].words;
736 users[i].letters=users[i-1].letters;
737 for (j=0;j<4;j++) users[i].hours[j]=users[i-1].hours[j];
738 strcpy(users[i].quote,users[i-1].quote);
739 for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=users[i-1].counters[j];
740 users[i].temp=users[i-1].temp;
741 users[i].photo=users[i-1].photo;
743 strcpy(users[start].nick,nick);
744 users[start].lines=0;
745 users[start].words=0;
746 users[start].letters=0;
747 for (j=0;j<4;j++) users[start].hours[j]=0;
748 users[start].quote[0]='\0';
749 for (j=0;j<NBCOUNTERS;j++) users[start].counters[j]=0;
751 users[start].photo=NULL;
756 void parse_log(char *logfile)
759 char line[MAXLINELENGTH];
764 int mononick,monolines;
767 if ((fic=fopen(logfile,"rt"))==NULL) { fprintf(stderr,"can't open log file \"%s\"\n",logfile); exit(1); }
768 if (debug) printf("working on %s : ",channel);
769 while (fgets(line,MAXLINELENGTH,fic)!=NULL)
772 for (i=0;line[i]!=0 && i<MAXLINELENGTH-1;i++);
773 if (i>=MAXLINELENGTH-1) {
775 fprintf(stderr,"line %d is too long, skipping\n",totallines+1);
781 fprintf(stderr, "line %d is too short to be valid, skipping\n",totallines+1);
788 if (totallines%10000==0 && debug) { printf("."); fflush(stdout); }
789 if (strncmp("--- Day changed",line,15)==0) /* --- Day changed Wed May 01 2002 */
793 lastdays[i].lines=lastdays[i-1].lines;
794 for (j=0;j<4;j++) lastdays[i].hours[j]=lastdays[i-1].hours[j];
797 for (j=0;j<4;j++) lastdays[0].hours[j]=0;
800 else if (strncmp("-!- mode/",&line[6],9)==0) /* 00:00 -!- mode/#channel [...] by (Nick, Nick2, )Nick3 */
802 for (i=strlen(line);line[i]!=' ';i--);
804 users[dichotomic(nick)].counters[D_MODE]++;
806 else if (strncmp("-!-",&line[6],3)==0) /* 00:00 -!- Nick something... */
808 for (i=10;line[i]!=' ' && i <= 10 + MAXNICKLENGTH;i++);
809 if(i > 10 + MAXNICKLENGTH) {
811 fprintf(stderr,"nick on line %d is too long, skipping line\n",totallines);
818 if (strncmp("changed the topic of",message,20)==0) /* 00:00 -!- Nick changed the topic of #channel to: new topic */
820 users[dichotomic(nick)].counters[D_TOPIC]++;
821 for (i=21;message[i]!=':';i++);
822 message=&message[i+2];
824 if ((nbtopics<=NBTOPICS) || (rand()%(nbtopics/NBTOPICS)==0))
826 temp=nbtopics<=NBTOPICS?nbtopics-1:rand()%NBTOPICS;
827 strcpy(topics[temp].nick,nick);
828 strncpy(topics[temp].topic,message,MAXQUOTELENGTH);
831 else if (strncmp("was kicked from",message,15)==0) /* 00:00 -!- Nick was kicked from #channel by Nick [Reason] */
833 users[dichotomic(nick)].counters[D_KICKED]++;
834 for (i=16;message[i]!=' ';i++);
835 message=&message[i+4];
836 for (i=0;message[i]!=' ';i++);
838 users[dichotomic(message)].counters[D_KICK]++;
840 else if (strncmp("is now known as",message,15)==0) /* 00:00 -!- Nick is now known as Nick */
841 users[dichotomic(nick)].counters[D_NICK]++;
842 else if (message[0]=='[') /* 00:00 -!- Nick [user@host] something... */
844 for (i=0;message[i]!=']';i++);
845 message=&message[i+2];
846 if (strncmp("has joined",message,10)==0) /* 00:00 -!- Nick [user@host] has joined #channel */
847 users[dichotomic(nick)].counters[D_JOIN]++;
848 else if (strncmp("has quit",message,8)==0); /* 00:00 -!- Nick [user@host] has quit [Reason] */
849 else if (strncmp("has left",message,8)==0); /* 00:00 -!- Nick [user@host] has left #channel [Reason] */
853 else if ((line[6]=='<') || (line[7]=='*'))
857 if (line[7]=='*') /* 00:00 * Nick the message */
859 for (i=9;line[i]!=' ' && i <= 9 + MAXNICKLENGTH;i++);
860 if(i > 9 + MAXNICKLENGTH) {
862 fprintf(stderr,"nick on line %d is too long, skipping line\n",totallines);
869 else if (line[7]=='>') /* 00:00 <>>>?Nick<<<> the personal message */
870 /* 00:00 <>>?Nick<<> the personal message */
872 for (i=10;line[i]!='<' && i <= 10 + MAXNICKLENGTH;i++);
873 if(i > 10 + MAXNICKLENGTH) {
875 fprintf(stderr,"nick on line %d is too long, skipping line\n",totallines);
880 if (line[9]=='>') nick++;
883 else /* 00:00 <?Nick> the message */
887 * Irssi doesn't log channel mode with show_nickmode = OFF
888 * the following covers op, half-op, voice and show_nickmode_empty
890 if (line[7]=='@' || line[7]=='%' || line[7]=='+' || line[7]==' ') {
896 for (i=nickstart;line[i]!='>' && i <= nickstart + MAXNICKLENGTH;i++);
897 if(i > nickstart + MAXNICKLENGTH) {
899 fprintf(stderr,"nick on line %d is too long, skipping line\n",totallines);
903 nick=&line[nickstart];
908 if (line[7]=='*') users[i].counters[D_ME]++;
912 if (monolines==5) users[i].counters[D_MONOLOGUE]++;
921 if (top_words || ranking==1) users[i].words+=findwords(message);
923 users[i].hours[hour/6]++;
925 lastdays[0].hours[hour/6]++;
930 hour=hour*4+atoi(&line[3])/15;
933 if (message[j-1]=='?') users[i].counters[D_QUESTION]++;
934 else if (message[j-1]=='!') users[i].counters[D_EXCLAM]++;
935 else if ((message[j-3]==' ')&&(message[j-2]==':'))
937 if (message[j-1]==')') users[i].counters[D_SMILE]++;
938 else if (message[j-1]=='(') users[i].counters[D_FROWN]++;
940 if (rand()%users[i].lines==0) strncpy(users[i].quote,message,MAXQUOTELENGTH);
941 if (strncmp("http://",message,7)==0)
943 users[i].counters[D_URL]++;
944 for (i=0;(message[i]!=' ') && (i<strlen(message));i++);
947 if ((nburls<=NBURLS) || (rand()%(nburls/NBURLS)==0))
949 temp=nburls<=NBURLS?nburls-1:rand()%NBURLS;
950 strcpy(urls[temp].nick,nick);
951 strcpy(urls[temp].url,message);
952 strncpy(urls[temp].shorturl,message,MAXQUOTELENGTH);
959 if (debug) printf(" done\n");
963 void parse_nick(char *nickfile)
968 char line[MAXLINELENGTH];
971 for (i=0;i<nbusers;i++) users[i].temp=users[i].lines;
972 if ((fic=fopen(nickfile,"rt"))==NULL) { fprintf(stderr,"can't open nick file \"%s\"\n",nickfile); exit(1); }
973 while (fscanf(fic,"%s",line)==1)
975 user=dichotomic(line);
976 fscanf(fic,"%s",line);
977 if (regcomp(&preg,line,0)!=0) { fprintf(stderr,"error in nick file"); exit(1); }
978 for (i=0;i<nbusers;i++) if ((i!=user) && (regexec(&preg,users[i].nick,0,0,0)==0) && (users[i].lines>=0))
980 if (users[i].temp>users[user].temp) /* for nick alias, keep the random quote of the most used nick */
982 strcpy(users[user].quote,users[i].quote);
983 users[user].temp=users[i].temp;
985 users[user].lines+=users[i].lines;
986 users[user].words+=users[i].words;
987 users[user].letters+=users[i].letters;
988 for (j=0;j<4;j++) users[user].hours[j]+=users[i].hours[j];
989 for (j=0;j<NBCOUNTERS;j++) users[user].counters[j]+=users[i].counters[j];
990 /* "remove" old user */
994 for (j=0;j<4;j++) users[i].hours[j]=-1;
995 for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=-1;
1000 /* "remove" the ignored nicks */
1001 i=dichotomic("<NULL>");
1004 users[i].letters=-1;
1005 for (j=0;j<4;j++) users[i].hours[j]=-1;
1006 for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=-1;
1010 void parse_photo(char *photofile)
1013 char line[MAXLINELENGTH];
1016 if ((fic=fopen(photofile,"rt"))==NULL) { fprintf(stderr,"can't open photo file \"%s\"\n",photofile); exit(1); }
1017 while (fscanf(fic,"%s",line)==1)
1019 user=dichotomic(line);
1020 fscanf(fic,"%s",line);
1021 users[user].photo=malloc(strlen(line)+1);
1022 strcpy(users[user].photo,line);
1027 void gen_xhtml(char *xhtmlfile)
1033 char line[MAXLINELENGTH];
1037 for (i=0;i<nbusers;i++) if (users[i].photo!=NULL) photos=1;
1039 if ((fic=fopen(xhtmlfile,"wt"))==NULL) { fprintf(stderr,"can't open xhtml file \"%s\"\n",xhtmlfile); exit(1); }
1042 if (strcmp("none",header)==0)
1044 fprintf(fic,"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n");
1045 fprintf(fic,"<!-- Generated by irssistats %s : %s -->\n\n",VERSION,URL);
1046 fprintf(fic,"<html>\n\n<head>\n<title>");
1047 fprintf(fic,L("HEADER"),channel,maintainer);
1048 fprintf(fic,"</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" />\n",L("CHARSET"));
1050 fprintf(fic,"<meta http-equiv=\"Refresh\" content=\"%d\" />\n",refresh_time);
1051 subtheme=strtok(theme,",");
1052 fprintf(fic,"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s.css\" title=\"%s\" />\n",subtheme,subtheme);
1053 while ((subtheme=strtok(NULL,","))!=NULL)
1054 fprintf(fic,"<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"%s.css\" title=\"%s\" />\n",subtheme,subtheme);
1055 fprintf(fic,"</head>\n\n");
1056 fprintf(fic,"<body>\n\n");
1060 if ((sfic=fopen(header,"rt"))==NULL) { fprintf(stderr,"can't open header file \"%s\"\n",header); exit(1); }
1061 while ((temp=fread(line,1,MAXLINELENGTH,sfic))) fwrite(line,temp,1,fic);
1064 fprintf(fic,"<div id=\"irssistats\">\n\n<div id=\"irssistats_header\">\n<h1>");
1065 fprintf(fic,L("HEADER"),channel,maintainer);
1066 fprintf(fic,"</h1>\n<p>\n%s</p>\n</div>\n\n",ctime(&debut));
1069 fprintf(fic,"<div id=\"irssistats_legend\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("LEGEND"));
1070 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);
1071 fprintf(fic,"</tr>\n</table>\n</div>\n\n");
1074 fprintf(fic,"<div id=\"irssistats_lastdays\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("LASTDAYS"));
1076 for (i=30;i>=0;i--) if (lastdays[i].lines>max) max=lastdays[i].lines;
1079 fprintf(fic,"<td align=\"center\" valign=\"bottom\"><small>%d</small>",lastdays[i].lines);
1080 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);
1081 fprintf(fic,"</td>\n");
1083 fprintf(fic,"</tr>\n<tr>\n");
1085 fprintf(fic,"<th>%d</th>\n",i);
1086 fprintf(fic,"</tr>\n</table>\n</div>\n\n");
1089 fprintf(fic,"<div id=\"irssistats_tophours\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("TOPHOURS"));
1091 for (i=0;i<24*4;i++) if (hours[i]>max) max=hours[i];
1092 if (quarter) for (i=0;i<24*4;i++)
1094 fprintf(fic,"<td align=\"center\" valign=\"bottom\">");
1095 if (hours[i]!=0) fprintf(fic,"<div class=\"v%d\" style=\"width:4px;height:%dpx\"></div>",i/4/6+1,150*hours[i]/max);
1096 fprintf(fic,"</td>\n");
1098 else for (i=0;i<24;i++)
1100 fprintf(fic,"<td align=\"center\" valign=\"bottom\"><small>%.1f%%</small>",lines!=0?(float)100*hours[i]/lines:0);
1101 if (hours[i]!=0) fprintf(fic,"<div class=\"v%d\" style=\"height:%dpx\"></div>",i/6+1,150*hours[i]/max);
1102 fprintf(fic,"</td>\n");
1104 fprintf(fic,"</tr>\n<tr>\n");
1106 if (quarter) fprintf(fic,"<th colspan=\"4\">%d</th>\n",i);
1107 else fprintf(fic,"<th>%d</th>\n",i);
1108 fprintf(fic,"</tr>\n</table>\n</div>\n\n");
1111 fprintf(fic,"<div id=\"irssistats_topusers\">\n<h2>%s</h2>\n",L("TOPUSERS"));
1115 fprintf(fic,"<table>\n<tr><th></th><th>%s</th><th>%s</th><th>%s</th><th colspan=\"2\">%s</th><th>%s</th>\n",L("NICK"),L("NBLINES"),L("HOURS"),L("AVGLETTERS"),L("QUOTE"));
1118 /* "letters" and "words" ranking are not yet translated so we use the generic word "rank" ... */
1119 fprintf(fic,"<table>\n<tr><th></th><th>%s</th><th>%s</th><th>%s</th><th colspan=\"2\">%s</th><th>%s</th>\n",L("NICK"),"rank",L("HOURS"),L("AVGLETTERS"),L("QUOTE"));
1122 if (photos) fprintf(fic,"<th></th>");
1123 fprintf(fic,"</tr>");
1124 for (i=1;i<=NBUSERS;i++)
1131 for (j=0;j<nbusers;j++) if (users[j].lines>max) max=users[user=j].lines;
1134 for (j=0;j<nbusers;j++) if (users[j].words>max) max=users[user=j].words;
1137 for (j=0;j<nbusers;j++) if (users[j].letters>max) max=users[user=j].letters;
1145 fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].lines);
1148 fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].words);
1151 fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].letters);
1154 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);
1155 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);
1156 printhtml(fic,users[user].quote);
1157 fprintf(fic,"\"</td>");
1158 if (photos && users[user].photo!=NULL)
1161 fprintf(fic,"<td class=\"tdphoto\"><a href=\"%s\"><img src=\"%s\" class=\"imgphoto\" width=\"%d\" height=\"%d\" alt=\"\" style=\"border: 0\" /></a></td>",users[user].photo,users[user].photo,photo_size,photo_size);
1163 fprintf(fic,"<td class=\"tdphoto\"><img src=\"%s\" class=\"imgphoto\" alt=\"\" /></td>",users[user].photo,users[user].photo);
1165 fprintf(fic,"</tr>\n");
1166 users[user].lines=-1;
1167 users[user].words=-1;
1168 users[user].letters=-1;
1171 fprintf(fic,"</table>\n");
1173 for (i=0;i<=nbusers;i++) if (users[i].lines>=0) temp++;
1177 fprintf(fic,L("OTHERS"),temp);
1178 fprintf(fic,"</p>\n");
1180 fprintf(fic,"</div>\n\n");
1182 /* top users by time */
1183 fprintf(fic,"<div id=\"irssistats_topuserstime\">\n<h2>%s</h2>\n",L("TOPUSERSTIME"));
1184 fprintf(fic,"<table>\n<tr><th></th>");
1185 for (i=0;i<4;i++) fprintf(fic,"<th colspan=\"2\">%s %d-%d</th>",L("HOURS"),i*6,i*6+5);
1186 fprintf(fic,"</tr>\n");
1187 for (i=1;i<=NBUSERSTIME;i++)
1189 fprintf(fic,"<tr><td>%d</td>",i);
1194 for (k=0;k<nbusers;k++) if (users[k].hours[j]>max) max=users[user=k].hours[j];
1197 fprintf(fic,"<td>%s</td><td>%d</td>",users[user].nick,users[user].hours[j]);
1198 users[user].hours[j]=-1;
1200 else fprintf(fic,"<td></td><td></td>");
1202 fprintf(fic,"</tr>\n");
1204 fprintf(fic,"</table>\n</div>\n\n");
1207 fprintf(fic,"<div id=\"irssistats_randtopics\">\n<h2>%s</h2>\n",L("RANDTOPICS"));
1208 fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th></tr>\n",L("CHANGEDBY"),L("NEWTOPIC"));
1209 for (i=nbtopics<NBTOPICS?nbtopics-1:NBTOPICS-1;i>=0;i--)
1211 fprintf(fic,"<tr><td>%s</td><td>\"",topics[i].nick);
1212 printhtml(fic,topics[i].topic);
1213 fprintf(fic,"\"</td></tr>\n");
1215 fprintf(fic,"</table>\n</div>\n\n");
1218 fprintf(fic,"<div id=\"irssistats_randurls\">\n<h2>%s</h2>\n",L("RANDURLS"));
1219 fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th></tr>\n",L("POSTEDBY"),L("POSTEDURL"));
1220 for (i=nburls<NBURLS?nburls-1:NBURLS-1;i>=0;i--)
1222 fprintf(fic,"<tr><td>%s</td><td>\"<a href=\"",urls[i].nick);
1223 printhtml(fic,urls[i].url);
1225 printhtml(fic,urls[i].shorturl);
1226 fprintf(fic,"</a>\"</td></tr>\n");
1228 fprintf(fic,"</table>\n</div>\n\n");
1233 fprintf(fic,"<div id=\"irssistats_topwords\">\n<h2>%s</h2>\n",L("TOPWORDS"));
1234 fprintf(fic,"<table>\n<tr><th></th><th>%s</th><th>%s</th></tr>\n",L("WORD"),L("OCCURRENCES"));
1235 for (i=0;i<NBWORDS;i++)
1236 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);
1237 fprintf(fic,"</table>\n</div>\n\n");
1241 fprintf(fic,"<div id=\"irssistats_bignumbers\">\n<h2>%s</h2>\n",L("BIGNUMBERS"));
1242 fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n",L("NICK"),L("NUMBERS"),L("NBLINES"));
1243 for (i=0;i<NBCOUNTERS;i++)
1247 for (j=0;j<nbusers;j++) if (users[j].counters[i]>max) max=users[user=j].counters[i];
1248 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]);
1250 fprintf(fic,"</table>\n</div>\n\n");
1253 fprintf(fic,"<div id=\"irssistats_footer\">\n<p>");
1254 fprintf(fic,L("TIME"),totallines,days,(int)(time(NULL)-debut));
1255 fprintf(fic,"</p>\n<p>%s <a href=\"%s\">irssistats %s</a></p>\n",L("FOOTER"),URL,VERSION);
1258 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");
1259 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");
1261 fprintf(fic,"</div>\n\n");
1264 if (logo) fprintf(fic,"<div class=\"logo\"></div>\n\n");
1267 if (strcmp("none",footer)==0)
1269 fprintf(fic,"</div>\n\n</body>\n\n</html>\n");
1273 if ((sfic=fopen(footer,"rt"))==NULL) { fprintf(stderr,"can't open footer file \"%s\"\n",footer); exit(1); }
1274 while ((temp=fread(line,1,MAXLINELENGTH,sfic))) fwrite(line,temp,1,fic);
1281 void parse_config(char *configfile)
1283 void expand(char *path)
1285 char temp[MAXLINELENGTH];
1288 snprintf(temp,MAXLINELENGTH-1,"%s%s",getenv("HOME"),path+1);
1289 temp[MAXLINELENGTH-1]='\0';
1295 char line[MAXLINELENGTH];
1296 char keyword[MAXLINELENGTH];
1297 char value[MAXLINELENGTH];
1301 if (configfile!=NULL)
1303 if ((fic=fopen(configfile,"rt"))==NULL)
1305 fprintf(stderr,"can't open config file : \"%s\"\n",configfile);
1311 snprintf(line,MAXLINELENGTH-1,"%s/.irssistats",getenv("HOME"));
1312 line[MAXLINELENGTH-1]='\0';
1313 if ((fic=fopen(line,"rt"))==NULL)
1314 if ((fic=fopen(GLOBALCONF,"rt"))==NULL)
1316 fprintf(stderr,"can't find config file : \"%s\" nor \"" GLOBALCONF "\"\n",line);
1317 fprintf(stderr,"please give the path to the config file in argument\n");
1322 while (fgets(line,MAXLINELENGTH,fic))
1325 if (*line!=';' && *line!='#' && *line!='/' && *line!='-' && *line!='\n')
1327 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); }
1329 if (strcmp("debug",keyword)==0)
1331 if (strcmp("none",value)==0) debug=0;
1333 if (strcmp("normal",value)==0) debug=1;
1335 if (strcmp("verbose",value)==0) { debug=2; fprintf(stderr,"switching to verbose output\n"); }
1336 else { fprintf(stderr,"unknown value for \"debug\" option, must be \"normal\", \"verbose\" or \"none\"\n"); exit(1); }
1340 if (strcmp("channel",keyword)==0)
1342 if (debug==2) fprintf(stderr,"setting channel name to \"%s\"\n",value);
1343 strcpy(channel,value);
1347 if (strcmp("maintainer",keyword)==0)
1349 if (debug==2) fprintf(stderr,"setting maintainer to \"%s\"\n",value);
1350 strcpy(maintainer,value);
1354 if (strcmp("language",keyword)==0)
1356 if (debug==2) fprintf(stderr,"setting language to \"%s\"\n",value);
1357 for (i=0;i<NBLANGUAGES;i++) if (strcmp(value,keys[i][0][1])==0) { language=i; break; }
1360 fprintf(stderr,"Invalid language : %s\n",value);
1361 fprintf(stderr,"Supported languages :\n");
1362 for (i=0;i<NBLANGUAGES;i++) fprintf(stderr,"%s = %s\n",keys[i][0][1],keys[i][0][0]);
1368 if (strcmp("theme",keyword)==0)
1370 if (debug==2) fprintf(stderr,"setting theme to \"%s\"\n",value);
1371 strcpy(theme,value);
1375 if (strcmp("refresh_time",keyword)==0)
1377 refresh_time=atoi(value);
1378 if (debug==2) fprintf(stderr,"setting refresh_time to \"%d\"\n",refresh_time);
1382 if (strcmp("photo_size",keyword)==0)
1384 photo_size=atoi(value);
1385 if (debug==2) fprintf(stderr,"setting photo_size to \"%d\"\n",photo_size);
1389 if (strcmp("w3c_link",keyword)==0)
1391 if (debug==2) fprintf(stderr,"setting w3c_link to \"%s\"\n",value);
1392 if (strcmp("no",value)==0) w3c_link=0;
1393 else if (strcmp("yes",value)==0) w3c_link=1;
1394 else { fprintf(stderr,"unknown value for \"w3c_link\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1398 if (strcmp("logo",keyword)==0)
1400 if (debug==2) fprintf(stderr,"setting logo to \"%s\"\n",value);
1401 if (strcmp("no",value)==0) logo=0;
1402 else if (strcmp("yes",value)==0) logo=1;
1403 else { fprintf(stderr,"unknown value for \"logo\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1407 if (strcmp("header",keyword)==0)
1410 if (debug==2) fprintf(stderr,"setting header to \"%s\"\n",value);
1411 strcpy(header,value);
1415 if (strcmp("footer",keyword)==0)
1418 if (debug==2) fprintf(stderr,"setting footer to \"%s\"\n",value);
1419 strcpy(footer,value);
1423 if (strcmp("input",keyword)==0)
1426 if (debug==2) fprintf(stderr,"parsing log file \"%s\"\n",value);
1431 if (strcmp("nickfile",keyword)==0)
1434 if (debug==2) fprintf(stderr,"nick alias using file \"%s\"\n",value);
1436 fprintf(stderr,"no support for nickfile in WIN32 version\n");
1443 if (strcmp("photofile",keyword)==0)
1446 if (debug==2) fprintf(stderr,"parsing photo file \"%s\"\n",value);
1451 if (strcmp("output",keyword)==0)
1454 if (debug==2) fprintf(stderr,"generating xhtml file \"%s\"\n",value);
1458 /* reset variables */
1463 for (i=0;i<24*4;i++) hours[i]=0;
1466 for (i=0;i<NBWORDS;i++) topwords[i].nb=0;
1469 for (i=0;i<nbusers;i++)
1471 free(users[i].photo);
1472 users[i].photo=NULL;
1477 if (strcmp("top_words",keyword)==0)
1479 if (debug==2) fprintf(stderr,"setting top_words to \"%s\"\n",value);
1480 if (strcmp("no",value)==0) top_words=0;
1481 else if (strcmp("yes",value)==0) top_words=1;
1482 else { fprintf(stderr,"unknown value for \"top_words\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1486 if (strcmp("ranking",keyword)==0)
1488 if (strcmp("lines",value)==0) ranking=0;
1490 if (strcmp("words",value)==0) ranking=1;
1492 if (strcmp("letters",value)==0) ranking=2;
1493 else { fprintf(stderr,"unknown value for \"ranking\" option, must be \"lines\", \"words\" or \"letters\"\n"); exit(1); }
1497 if (strcmp("quarter",keyword)==0)
1499 if (debug==2) fprintf(stderr,"setting quarter to \"%s\"\n",value);
1500 if (strcmp("no",value)==0) quarter=0;
1501 else if (strcmp("yes",value)==0) quarter=1;
1502 else { fprintf(stderr,"unknown value for \"quarter\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1505 else { fprintf(stderr,"error in config file : \"%s\" is an unknown keyword (line %d)\n",keyword,configlines); exit(1); }
1511 int main(int argc,char *argv[])
1513 if ((users=malloc(maxusers*sizeof(struct user)))==NULL) { fprintf(stderr,"unable to malloc memory\n"); exit(1); }
1514 srand(debut=time(NULL));
1515 if (argc==1) parse_config(NULL);
1516 else if (argc==2) parse_config(argv[1]);
1519 fprintf(stderr,"Usage : %s [/path/to/file.conf]\n",argv[0]);
1520 fprintf(stderr,"Version : irssistats %s\n",VERSION);