2 * irssistats version 0.62
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>
34 #define BASEUSERS 1000
35 #define MAXNICKLENGTH 50
36 #define MAXLINELENGTH 2000
37 #define MAXQUOTELENGTH 100
39 #define NBUSERSTIME 10
43 #define MINWORDLENGTH 5
46 #define VERSION "0.62"
47 #define URL "http://royale.zerezo.com/irssistats/"
62 #define D_MONOLOGUE 12
64 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"};
67 #define NBLANGUAGES 11
69 char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and abbreviation */
71 { /* English language */
73 { "CHARSET", "ISO-8859-1" },
74 { "HEADER", "Statistics for %s by %s" },
75 { "LEGEND", "Legend" },
76 { "LASTDAYS", "Lastdays statistics" },
77 { "TOPHOURS", "Hourly statistics" },
78 { "TOPUSERS", "Most active people" },
79 { "OTHERS", "There are %d left not ranked..." },
80 { "NBLINES", "lines" },
82 { "AVGLETTERS", "letters/lines" },
84 { "QUOTE", "random message" },
85 { "TOPUSERSTIME", "Most active people by time of day" },
86 { "RANDTOPICS", "Some topics" },
87 { "CHANGEDBY", "changed by" },
88 { "NEWTOPIC", "new topic" },
89 { "RANDURLS", "Some URLs" },
90 { "POSTEDBY", "posted by" },
91 { "POSTEDURL", "URL" },
92 { "TOPWORDS", "Most used words" },
94 { "OCCURRENCES", "occurrences" },
95 { "BIGNUMBERS", "Some big numbers..." },
96 { "NUMBERS", "numbers" },
97 { "TIME", "%d lines (%d days) parsed in %d seconds" },
98 { "FOOTER", "Statistics generated by" },
99 { "C_SMILE", "is often happy :)" },
100 { "C_FROWN", "is often sad :(" },
101 { "C_EXCLAM", "yells a lot !" },
102 { "C_QUESTION", "asks a lot of questions ?" },
103 { "C_ME", "likes /me command" },
104 { "C_TOPIC", "often changes the topic" },
105 { "C_MODE", "often changes the modes" },
106 { "C_KICK", "likes to /kick" },
107 { "C_KICKED", "is often kicked" },
108 { "C_URL", "posts many URLs" },
109 { "C_JOIN", "doesn't know wether to stay or quit" },
110 { "C_NICK", "often changes his nick" },
111 { "C_MONOLOGUE", "speaks a lot of monologues" }
113 { /* French language */
115 { "CHARSET", "ISO-8859-1" },
116 { "HEADER", "Statistiques de %s par %s" },
117 { "LEGEND", "Légende" },
118 { "LASTDAYS", "Statistiques des derniers jours" },
119 { "TOPHOURS", "Statistiques horaires" },
120 { "TOPUSERS", "Personnes les plus actives" },
121 { "OTHERS", "Il reste %d personnes non classées..." },
122 { "NBLINES", "lignes" },
124 { "AVGLETTERS", "lettres/lignes" },
125 { "HOURS", "heures" },
126 { "QUOTE", "message aléatoire" },
127 { "TOPUSERSTIME", "Personnes les plus actives par période de la journée" },
128 { "RANDTOPICS", "Quelques topics" },
129 { "CHANGEDBY", "changé par" },
130 { "NEWTOPIC", "nouveau topic" },
131 { "RANDURLS", "Quelques URLs" },
132 { "POSTEDBY", "postée par" },
133 { "POSTEDURL", "URL" },
134 { "TOPWORDS", "Mots les plus utilisés" },
136 { "OCCURRENCES", "occurrences" },
137 { "BIGNUMBERS", "Quelques grands nombres..." },
138 { "NUMBERS", "nombres" },
139 { "TIME", "%d lignes (%d jours) traitées en %d secondes" },
140 { "FOOTER", "Statistiques générées par" },
141 { "C_SMILE", "est souvent heureux :)" },
142 { "C_FROWN", "est souvent triste :(" },
143 { "C_EXCLAM", "hurle beaucoup !" },
144 { "C_QUESTION", "pose beaucoup de questions ?" },
145 { "C_ME", "aime la commande /me" },
146 { "C_TOPIC", "change souvent le topic" },
147 { "C_MODE", "change souvent les modes" },
148 { "C_KICK", "aime la commande /kick" },
149 { "C_KICKED", "est souvent kické" },
150 { "C_URL", "poste beaucoup d'URLs" },
151 { "C_JOIN", "ne sait pas s'il doit rester ou partir" },
152 { "C_NICK", "change souvent de nick" },
153 { "C_MONOLOGUE", "parle beaucoup de monologues" }
155 { /* German language */
156 /* contributed by Valentin Gelhorn <valentin.gelhorn@web.de> */
158 { "CHARSET", "ISO-8859-1" },
159 { "HEADER", "Statistiken für %s von %s" },
160 { "LEGEND", "Legende" },
161 { "LASTDAYS", "Statistik der letzten Tage" },
162 { "TOPHOURS", "Stündliche Statistik" },
163 { "TOPUSERS", "Die aktivsten Personen" },
164 { "OTHERS", "Es bleiben noch %d uneingetragene" },
165 { "NBLINES", "Zeilen" },
167 { "AVGLETTERS", "Buchstaben/Zeile" },
168 { "HOURS", "Stunden" },
169 { "QUOTE", "Zufällig ausgewaehlte Zitate" },
170 { "TOPUSERSTIME", "Die aktivsten Personen zur bestimmten Tageszeit" },
171 { "RANDTOPICS", "Ein paar Topics" },
172 { "CHANGEDBY", "Gesetzt von" },
173 { "NEWTOPIC", "Neues topic" },
174 { "RANDURLS", "Ein paar URLs" },
175 { "POSTEDBY", "Geschrieben von" },
176 { "POSTEDURL", "URL" },
177 { "TOPWORDS", "Am häufigsten benutze Wörter" },
179 { "OCCURRENCES", "Vorkommen" },
180 { "BIGNUMBERS", "Ein paar grosse Zahlen" },
181 { "NUMBERS", "Zahlen" },
182 { "TIME", "%d Zeilen (%d Tage) analysiert in %d Sekunden" },
183 { "FOOTER", "Statistiken wurden erstellt von" },
184 { "C_SMILE", "ist oft glüklich :)" },
185 { "C_FROWN", "ist oft traurig :(" },
186 { "C_EXCLAM", "schreit oft !" },
187 { "C_QUESTION", "stellt viele Fragen ?" },
188 { "C_ME", "mag /me'en" },
189 { "C_TOPIC", "aendert oft das Topico" },
190 { "C_MODE", "aendert oft die Modes" },
191 { "C_KICK", "mag /kick'en" },
192 { "C_KICKED", "wird oft gekickt"},
193 { "C_URL", "schreibt viele URLs"},
194 { "C_JOIN", "kann sich nicht entscheiden ob er bleiben oder gehen soll" },
195 { "C_NICK", "ändert oft seinen Nick" },
196 { "C_MONOLOGUE", "spricht oft Monologe" }
198 { /* Spanish language */
199 /* contributed by Alex <ainaker@gmx.net> */
201 { "CHARSET", "ISO-8859-1" },
202 { "HEADER", "Estadísticas de %s por %s" },
203 { "LEGEND", "Leyenda" },
204 { "LASTDAYS", "Estadísticas de los últimos días" },
205 { "TOPHOURS", "Estadísticas por horas" },
206 { "TOPUSERS", "Los que más escriben" },
207 { "OTHERS", "Hay %d más que no llegaron..." },
208 { "NBLINES", "líneas" },
210 { "AVGLETTERS", "letras por línea" },
211 { "HOURS", "horas" },
212 { "QUOTE", "Frase aleatoria" },
213 { "TOPUSERSTIME", "Los que más escriben según la hora" },
214 { "RANDTOPICS", "Algunos topics" },
215 { "CHANGEDBY", "Puestos por" },
216 { "NEWTOPIC", "topic" },
217 { "RANDURLS", "Algunas URLs" },
218 { "POSTEDBY", "puestas por" },
219 { "POSTEDURL", "URL" },
220 { "TOPWORDS", "Palabras más usadas" },
221 { "WORD", "Palabra" },
222 { "OCCURRENCES", "Frecuencia" },
223 { "BIGNUMBERS", "Algunos datos..." },
224 { "NUMBERS", "Número de veces" },
225 { "TIME", "%d lineas (%d días) procesadas en %d segundos" },
226 { "FOOTER", "Estadísticas generadas por" },
227 { "C_SMILE", "Suele estar felíz :)" },
228 { "C_FROWN", "Suele estar triste :(" },
229 { "C_EXCLAM", "Grita mucho !" },
230 { "C_QUESTION", "Hace muchas preguntas ?" },
231 { "C_ME", "Abusa del comando /me" },
232 { "C_TOPIC", "Suele cambiar el topic" },
233 { "C_MODE", "Cambia a veces los modos del canal" },
234 { "C_KICK", "Le gusta patear" },
235 { "C_KICKED", "Es pateado con frecuencia" },
236 { "C_URL", "Pone muchas URLs" },
237 { "C_JOIN", "No sabe si irse o quedarse" },
238 { "C_NICK", "Cambia mucho de nick" },
239 { "C_MONOLOGUE", "Habla solo" }
241 { /* Polish language */
242 /* contributed by Jakub Jankowski <shasta@atn.pl> */
244 { "CHARSET", "ISO-8859-2" },
245 { "HEADER", "Statystyki dla %s zebrane przez %s" },
246 { "LEGEND", "Legenda" },
247 { "LASTDAYS", "Statystyki z ostatnich dni" },
248 { "TOPHOURS", "Statystyki godzinowe" },
249 { "TOPUSERS", "Najaktywniejsi" },
250 { "OTHERS", "Jest jeszcze %d nie sklasyfikowanych..." },
251 { "NBLINES", "linii" },
253 { "AVGLETTERS", "liter/liniê" },
254 { "HOURS", "godziny" },
255 { "QUOTE", "losowa wypowied¼" },
256 { "TOPUSERSTIME", "Najaktywniejsi wed³ug pory dnia" },
257 { "RANDTOPICS", "Kilka topików" },
258 { "CHANGEDBY", "ustawiony przez" },
259 { "NEWTOPIC", "topik" },
260 { "RANDURLS", "Kilka URL-i" },
261 { "POSTEDBY", "poda³(a)" },
262 { "POSTEDURL", "URL" },
263 { "TOPWORDS", "Najczê¶ciej wystêpuj±ce s³owa" },
265 { "OCCURRENCES", "wyst±pieñ" },
266 { "BIGNUMBERS", "Kilka wielkopomnych liczb..." },
267 { "NUMBERS", "kategorie" },
268 { "TIME", "Dokonano analizy %d linii (obejmuj±cych %d dni) w czasie %d sekund" },
269 { "FOOTER", "Statystyki wygenerowane przez" },
270 { "C_SMILE", "jest czêsto szczesliwy(a) :)" },
271 { "C_FROWN", "jest czêsto smutny(a) :(" },
272 { "C_EXCLAM", "czêsto KRZYCZY!" },
273 { "C_QUESTION", "zadaje du¿o pytañ?" },
274 { "C_ME", "lubi u¿ywaæ /me" },
275 { "C_TOPIC", "czêsto zmienia topik" },
276 { "C_MODE", "czêsto zmienia tryby kana³u" },
277 { "C_KICK", "lubi kopaæ" },
278 { "C_KICKED", "czêsto wykopywany(a)" },
279 { "C_URL", "podaje du¿o URL-i" },
280 { "C_JOIN", "nie wie czy zostaæ, czy wyj¶æ" },
281 { "C_NICK", "czêsto zmienia nick" },
282 { "C_MONOLOGUE", "uwielbia monologi" }
284 { /* Polish language */
285 /* contributed by Piotr Jarmuz <coreupper@yahoo.com> */
286 { "Polish", "pl-old" },
287 { "CHARSET", "ISO-8859-1" },
288 { "HEADER", "Statystyki dla %s przez %s" },
289 { "LEGEND", "Legenda" },
290 { "LASTDAYS", "Statystyki z ostatnich dni" },
291 { "TOPHOURS", "Statystyki godzinne" },
292 { "TOPUSERS", "Najaktywniejsi ludzie" },
293 { "OTHERS", "Zostalo jeszcze %d nie sklasyfikowanych..." },
294 { "NBLINES", "linie" },
296 { "AVGLETTERS", "litery/linie" },
297 { "HOURS", "godziny" },
298 { "QUOTE", "przypadkowa wiadomosc" },
299 { "TOPUSERSTIME", "Najaktywniejsi ludzie wedlug czasu dnia" },
300 { "RANDTOPICS", "Pare tematow" },
301 { "CHANGEDBY", "zmienione przez" },
302 { "NEWTOPIC", "nowy temat" },
303 { "RANDURLS", "Pare URL-i" },
304 { "POSTEDBY", "wyslane przez" },
305 { "POSTEDURL", "URL" },
306 { "TOPWORDS", "Najczestsze slowa" },
308 { "OCCURRENCES", "wystapienia" },
309 { "BIGNUMBERS", "Pare wielkich liczb..." },
310 { "NUMBERS", "liczby" },
311 { "TIME", "%d linii (%d dni) sparsowanych w %d sekund" },
312 { "FOOTER", "Statystyki wygenerowane przez" },
313 { "C_SMILE", "jest czesto szczesliwy :)" },
314 { "C_FROWN", "jest czesto smutny :(" },
315 { "C_EXCLAM", "duzo krzyczy !" },
316 { "C_QUESTION", "zadaje duzo pytan ?" },
317 { "C_ME", "lubi /mnie polecenie" },
318 { "C_TOPIC", "czesto zmienia temat" },
319 { "C_MODE", "czesto zmienia tryb" },
320 { "C_KICK", "lubi /kopac" },
321 { "C_KICKED", "czesto go wykopuja" },
322 { "C_URL", "wysyla duzo URL-i" },
323 { "C_JOIN", "nie wie czy zostac czy wyjsc" },
324 { "C_NICK", "czesto zmienia swojego nicka" },
325 { "C_MONOLOGUE", "czesto mowi monologiem" }
327 { /* Finnish language */
328 /* contributed by Antti Huopana <ahuopana@ratol.fi> */
330 { "CHARSET", "ISO-8859-1" },
331 { "HEADER", "Kanavan %s tilastot - %s" },
332 { "LEGEND", "Merkkien selitykset" },
333 { "LASTDAYS", "Viime päivien tilastot" },
334 { "TOPHOURS", "Tilastot tunneittain" },
335 { "TOPUSERS", "Aktiivisimmat ihmiset" },
336 { "OTHERS", "Jäljelle jäi %d joita ei listattu..." },
337 { "NBLINES", "rivit" },
339 { "AVGLETTERS", "kirjainta/rivi" },
340 { "HOURS", "tunnit" },
341 { "QUOTE", "satunnainen viesti" },
342 { "TOPUSERSTIME", "Vuorokauden ajan mukaan aktiivisimmat" },
343 { "RANDTOPICS", "Joitakin aiheita" },
344 { "CHANGEDBY", "vaihtaja" },
345 { "NEWTOPIC", "aihe" },
346 { "RANDURLS", "Joitakin URLeja" },
347 { "POSTEDBY", "lähettäjä" },
348 { "POSTEDURL", "URL" },
349 { "TOPWORDS", "Eniten käytettyjä sanoja" },
351 { "OCCURRENCES", "käytetty" },
352 { "BIGNUMBERS", "Joitakin isoja lukuja..." },
353 { "NUMBERS", "luvut" },
354 { "TIME", "%d riviä (%d päivää) parsittu %d sekunnissa" },
355 { "FOOTER", "Tilastot on generoinut" },
356 { "C_SMILE", "on usein iloinen :)" },
357 { "C_FROWN", "on usein surullinen :(" },
358 { "C_EXCLAM", "möykkää paljon !" },
359 { "C_QUESTION", "kyselee liikaa ?" },
360 { "C_ME", "pitää itsestään" },
361 { "C_TOPIC", "vaihtaa usein aihetta" },
362 { "C_MODE", "haluaa elää muuttuvassa maailmassa" },
363 { "C_KICK", "pitää potkimisesta" },
364 { "C_KICKED", "tykkää tulla potkituksi" },
365 { "C_URL", "surffailee liikaa" },
366 { "C_JOIN", "ei tiedä ollakko vai eikö olla" },
367 { "C_NICK", "kärsii identiteettiongelmista" },
368 { "C_MONOLOGUE", "höpöttää paljon itsekseen" }
370 { /* Italian language */
371 /* contributed by Coviello Giuseppe <giuseppecoviello@tin.it> <http://coviello.altervista.org> */
373 { "CHARSET", "ISO-8859-1" },
374 { "HEADER", "Statistiche per il canale %s di %s" },
375 { "LEGEND", "Legenda" },
376 { "LASTDAYS", "Statistiche degli ultimi giorni" },
377 { "TOPHOURS", "Statistiche in ore" },
378 { "TOPUSERS", "Utenti più attivi" },
379 { "OTHERS", "Ci sono %d utenti non classificati..." },
380 { "NBLINES", "righe" },
382 { "AVGLETTERS", "lettere/righe" },
384 { "QUOTE", "messaggio casuale" },
385 { "TOPUSERSTIME", "Utenti più attivi del giorno (divisi per fasce orarie)" },
386 { "RANDTOPICS", "Alcuni topic" },
387 { "CHANGEDBY", "cambiato da" },
388 { "NEWTOPIC", "nuovo topic" },
389 { "RANDURLS", "ALcuni URL" },
390 { "POSTEDBY", "postato da" },
391 { "POSTEDURL", "URL" },
392 { "TOPWORDS", "Le parole più usate" },
393 { "WORD", "parola" },
394 { "OCCURRENCES", "usata" },
395 { "BIGNUMBERS", "Alcuni numeri ..." },
396 { "NUMBERS", "numeri" },
397 { "TIME", "%d righe (%d giorni) esaminate in %d secondi" },
398 { "FOOTER", "Statistiche generate da" },
399 { "C_SMILE", "è spesso felice :)" },
400 { "C_FROWN", "è spesso triste :(" },
401 { "C_EXCLAM", "esclama molto !" },
402 { "C_QUESTION", "fa molte domande ?" },
403 { "C_ME", "ama il comando /me" },
404 { "C_TOPIC", "cambia spesso il topic" },
405 { "C_MODE", "cambia spesso i mode" },
406 { "C_KICK", "ama /kick(are)" },
407 { "C_KICKED", "è kickato spesso" },
408 { "C_URL", "posta molti URL" },
409 { "C_JOIN", "non sa se è ora di andare o restare" },
410 { "C_NICK", "cambia spesso il nick" },
411 { "C_MONOLOGUE", "fa molti monologhi" }
413 { /* Dutch language */
414 /* contributed by Jeroen Ubbink <crasp@blackbyte.nl> */
416 { "CHARSET", "ISO-8859-1" },
417 { "HEADER", "Statistieken voor %s door %s" },
418 { "LEGEND", "Legenda" },
419 { "LASTDAYS", "Statistieken van de laatste dagen" },
420 { "TOPHOURS", "Statistieken per uur" },
421 { "TOPUSERS", "Meest actieve mensen" },
422 { "OTHERS", "Er zijn nog %d niet in de top..." },
423 { "NBLINES", "regels" },
425 { "AVGLETTERS", "letters/lijn" },
427 { "QUOTE", "Willekeurige regel" },
428 { "TOPUSERSTIME", "Meest actieve mensen per tijdstip per dag" },
429 { "RANDTOPICS", "Enkele topics" },
430 { "CHANGEDBY", "gewijzigd door" },
431 { "NEWTOPIC", "nieuwe topic" },
432 { "RANDURLS", "Enkele URLs" },
433 { "POSTEDBY", "Geplaatst door" },
434 { "POSTEDURL", "URL" },
435 { "TOPWORDS", "Meest gebruikte woorden" },
437 { "OCCURRENCES", "aantal" },
438 { "BIGNUMBERS", "Enkele grote aantallen..." },
439 { "NUMBERS", "numbers" },
440 { "TIME", "%d regels (%d dagen) verwerkt in %d seconden" },
441 { "FOOTER", "Statistieken gegenereert door" },
442 { "C_SMILE", "is vaak vrolijk :)" },
443 { "C_FROWN", "is vaak droevig :(" },
444 { "C_EXCLAM", "schreeuwt veel !" },
445 { "C_QUESTION", "stelt veel vragen ?" },
446 { "C_ME", "vindt /me een leuk commando" },
447 { "C_TOPIC", "verandert vaak de topic" },
448 { "C_MODE", "verandert vaak de modes" },
449 { "C_KICK", "vindt /kick erg leuk" },
450 { "C_KICKED", "wordt vaak gekickt" },
451 { "C_URL", "plaatst veel URLs" },
452 { "C_JOIN", "twijfelt tussen blijven of gaan" },
453 { "C_NICK", "verandert vaak van nick" },
454 { "C_MONOLOGUE", "spreekt veel monologen" }
456 { /* Russian language */
457 /* contributed by kamikaze <kamikaze@rss.lv> */
459 { "CHARSET", "KOI8-R" },
460 { "HEADER", "óÔÁÔÉÓÔÉËÁ ÄÌÑ %s ÏÔ %s" },
461 { "LEGEND", "ïÂÏÚÎÁÞÅÎÉÑ" },
462 { "LASTDAYS", "óÔÁÔÉÓÔÉËÁ ÐÏÓÌÅÄÎÉÈ ÄÎÅÊ" },
463 { "TOPHOURS", "ðÏÞÁÓÏ×ÁÑ ÓÔÁÔÉÓÔÉËÁ" },
464 { "TOPUSERS", "áËÔÉ×ÎÅÊÛÉÅ ÌÀÄÉ" },
465 { "OTHERS", "ïÓÔÁÌÏÓØ %d ÎÅÐÏÄÓÞÉÔÁÎÙÈ..." },
466 { "NBLINES", "ÓÔÒÏËÉ" },
468 { "AVGLETTERS", "ÂÕË×Ù/ÓÔÒÏËÉ" },
470 { "QUOTE", "ÓÌÕÞÁÊÎÏÅ ÓÏÏÂÝÅÎÉÅ" },
471 { "TOPUSERSTIME", "áËÔÉ×ÎÅÊÛÉÅ ÌÀÄÉ ÐÏ ×ÒÅÍÅÎÉ ÄÎÑ" },
472 { "RANDTOPICS", "îÅÓËÏÌØËÏ ÔÏÐÉËÏ×" },
473 { "CHANGEDBY", "ÉÚÍÅΣÎ" },
474 { "NEWTOPIC", "ÎÏ×ÙÊ ÔÏÐÉË" },
475 { "RANDURLS", "îÅÓËÏÌØËÏ URLÏ×" },
476 { "POSTEDBY", "ÏÐÕÂÌÉËÏ×ÁÌ" },
477 { "POSTEDURL", "URL" },
478 { "TOPWORDS", "þÁÓÔÏ ÉÓÐÏÌØÚÕÅÍÙÅ ÓÌÏ×Á" },
480 { "OCCURRENCES", "ÐÒÏÉÛÅÓÔ×ÉÑ" },
481 { "BIGNUMBERS", "îÅÓËÏÌØËÏ ÂÏÌØÛÉÈ ÞÉÓÅÌ..." },
482 { "NUMBERS", "ÞÉÓÌÁ" },
483 { "TIME", "%d ÓÔÒÏË (%d ÄÎÅÊ) ÏÂÒÁÂÏÔÁÎÏ ÚÁ %d ÓÅËÕÎÄ" },
484 { "FOOTER", "óÔÁÔÉÓÔÉËÁ ÓÇÅÎÅÒÉÒÏ×ÁÎÁ" },
485 { "C_SMILE", "ÞÁÓÔÏ ÓÞÁÓÌÉ× :)" },
486 { "C_FROWN", "ÞÁÓÔÏ ÎÅÓÞÁÓÔÅÎ :(" },
487 { "C_EXCLAM", "ÍÎÏÇÏ ×ÏÓËÌÉÃÁÅÔ !" },
488 { "C_QUESTION", "ÚÁÄÁ£Ô ÍÎÏÇÏ ×ÏÐÒÏÓÏ× ?" },
489 { "C_ME", "ÌÀÂÉÔ /me command" },
490 { "C_TOPIC", "ÞÁÓÔÏ ÍÅÎÑÅÔ ÔÏÐÉË" },
491 { "C_MODE", "ÞÁÓÔÏ ÍÅÎÑÅÔ ÒÅÖÉÍÙ" },
492 { "C_KICK", "ÌÀÂÉÔ /kick" },
493 { "C_KICKED", "ÞÁÓÔÏ ×ÙËÉÄÙ×ÁÀÔ" },
494 { "C_URL", "ÐÕÂÌÉËÕÅÔ ÍÎÏÇÏ URLÏ×" },
495 { "C_JOIN", "ÎÅ ÚÎÁÅÔ - ÏÓÔÁÔØÓÑ ÉÌÉ ÕÊÔÉ" },
496 { "C_NICK", "ÞÁÓÔÏ ÍÅÎÑÅÔ Ó×ÏÊ ÎÉË" },
497 { "C_MONOLOGUE", "éÓÐÏÌØÚÕÅÔ ÍÎÏÇÏ ÍÏÎÏÌÏÇÏ×" }
499 { /* Estonian language */
500 /* contributed by Martin Vool <mardicas@hot.ee> */
501 { "Estonian", "et" },
502 { "CHARSET", "ISO-8859-4" },
503 { "HEADER", "Statistika kanalile %s on koostanud %s" },
504 { "LEGEND", "Legend" },
505 { "LASTDAYS", "Viimaste päevade statistika" },
506 { "TOPHOURS", "Tunni statistika" },
507 { "TOPUSERS", "Kõige aktiivsemad inimesed" },
508 { "OTHERS", "%d inimest on rääkinud" },
509 { "NBLINES", "rida" },
511 { "AVGLETTERS", "tähte/rida" },
513 { "QUOTE", "suvaline teade" },
514 { "TOPUSERSTIME", "Kõige aktiivsemad inimesed päeva aja järgi" },
515 { "RANDTOPICS", "Mõned topicud" },
516 { "CHANGEDBY", "muutis" },
517 { "NEWTOPIC", "topicud" },
518 { "RANDURLS", "Mõned aadressid" },
519 { "POSTEDBY", "postitas" },
520 { "POSTEDURL", "URL" },
521 { "TOPWORDS", "Enim kasutatud sõnad" },
523 { "OCCURRENCES", "sagedus" },
524 { "BIGNUMBERS", "Mõned suured numbrid" },
525 { "NUMBERS", "iseloom" },
526 { "TIME", "%d rida (%d päeva) on möödunud %d sekundit" },
527 { "FOOTER", "Statistika on koostanud" },
528 { "C_SMILE", "on tihti õnnelik :)" },
529 { "C_FROWN", "on tihti kurb :(" },
530 { "C_EXCLAM", "põrnitseb palju" },
531 { "C_QUESTION", "küsib palju küsimusi" },
532 { "C_ME", "/me manjakk" },
533 { "C_TOPIC", "vahetab tihti topicut" },
534 { "C_MODE", "vahetab tihti modesid" },
535 { "C_KICK", "kickib palju" },
536 { "C_KICKED", "saab tihti kicke" },
537 { "C_URL", "reklaamib palju" },
538 { "C_JOIN", "sõelub sisse ja välja" },
539 { "C_NICK", "vahetab pidevalt nime" },
540 { "C_MONOLOGUE", "räägib palju monolooge" }
544 int language=0; /* default to english */
549 for (i=1;i<=NBKEYS;i++) if (strcmp(key,keys[language][i][0])==0) return(keys[language][i][1]);
550 fprintf(stderr,"unknown language key: %s\n",key);
556 int debug=1; /* 0 = none ; 1 = normal ; 2 = verbose */
557 char channel[MAXLINELENGTH]="set_channel_in_config_file";
558 char maintainer[MAXLINELENGTH]="set_maintainer_in_config_file";
559 char theme[MAXLINELENGTH]="default,blue,dark,grayscale,namour,pisg,zeduel,zerezo";
560 int refresh_time=0; /* 0 = disabled */
561 int w3c_link=1; /* 0 = disabled */
562 char header[MAXLINELENGTH]="none";
563 char footer[MAXLINELENGTH]="none";
566 int top_words=1; /* 0 = disabled */
567 int ranking=0; /* 0 = lines ; 1 = words ; 2 = letters */
568 int quarter=0; /* 1 = enabled */
572 char nick[MAXNICKLENGTH];
577 char quote[MAXQUOTELENGTH+1];
578 int counters[NBCOUNTERS];
582 int maxusers=BASEUSERS;
586 char nick[MAXNICKLENGTH];
587 char url[MAXLINELENGTH];
588 char shorturl[MAXQUOTELENGTH+1];
594 char nick[MAXNICKLENGTH];
595 char topic[MAXQUOTELENGTH+1];
612 struct letter *next[26];
618 char word[MAXLINELENGTH];
621 #define isletter(c) (((c>='a')&&(c<='z'))||((c>='A')&&(c<='Z')))
622 #define lowercase(c) (((c>='A')&&(c<='Z'))?c-'A'+'a':c)
623 int findwords(char *message)
626 struct letter *pos,*tmp;
629 while (!isletter(*message)) if (*message=='\0') return n; else message++;
631 while (isletter(*message))
633 c=lowercase(*message)-'a';
634 if (pos->next[(int)c]==NULL)
636 tmp=malloc(sizeof(struct letter));
639 fprintf(stderr, "findwords(): malloc failure\n");
643 for (i=0;i<26;i++) tmp->next[i]=NULL;
644 pos->next[(int)c]=tmp;
646 pos=pos->next[(int)c];
655 char tempword[MAXLINELENGTH];
656 void bestwords(struct letter pos,int cur)
659 if ((cur>=MINWORDLENGTH)&&(pos.nb>topwords[NBWORDS-1].nb))
661 for (i=0;pos.nb<topwords[i].nb;i++);
662 for (j=NBWORDS-1;j>i;j--)
664 topwords[j].nb=topwords[j-1].nb;
665 strcpy(topwords[j].word,topwords[j-1].word);
667 topwords[i].nb=pos.nb;
668 strcpy(topwords[i].word,tempword);
670 for (i=0;i<26;i++) if (pos.next[i]!=NULL)
673 bestwords(*(pos.next[i]),cur+1);
678 void freewords(struct letter *pos)
681 for (i=0;i<26;i++) if (pos->next[i]!=NULL)
683 freewords(pos->next[i]);
689 void printhtml(FILE *fic,char *string) /* replace < and > by < and > */
691 while (*string!='\0')
695 case '<':fprintf(fic,"<"); break;
696 case '>':fprintf(fic,">"); break;
697 case '&':fprintf(fic,"&"); break;
698 default:fprintf(fic,"%c",*string); break;
705 int dichotomic(char *nick)
707 int i,j,start=0,end=nbusers-1,middle;
710 middle=(start+end)/2;
711 if (strcmp(nick,users[middle].nick)>0) start=middle+1; else end=middle-1;
713 if (strcmp(nick,users[start].nick)!=0)
716 if (nbusers>=maxusers)
719 if (debug==2) fprintf(stderr,"allocating more users : %d\n",maxusers);
720 if ((users=realloc(users,maxusers*sizeof(struct user)))==NULL) { fprintf(stderr,"too many users : unable to realloc memory\n"); exit(1); }
722 for (i=nbusers-1;i>start;i--)
724 strcpy(users[i].nick,users[i-1].nick);
725 users[i].lines=users[i-1].lines;
726 users[i].words=users[i-1].words;
727 users[i].letters=users[i-1].letters;
728 for (j=0;j<4;j++) users[i].hours[j]=users[i-1].hours[j];
729 strcpy(users[i].quote,users[i-1].quote);
730 for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=users[i-1].counters[j];
731 users[i].temp=users[i-1].temp;
733 strcpy(users[start].nick,nick);
734 users[start].lines=0;
735 users[start].words=0;
736 users[start].letters=0;
737 for (j=0;j<4;j++) users[start].hours[j]=0;
738 users[start].quote[0]='\0';
739 for (j=0;j<NBCOUNTERS;j++) users[start].counters[j]=0;
745 void parse_log(char *logfile)
748 char line[MAXLINELENGTH];
753 int mononick,monolines;
756 if ((fic=fopen(logfile,"rt"))==NULL) { fprintf(stderr,"can't open log file \"%s\"\n",logfile); exit(1); }
757 if (debug) printf("working on %s : ",channel);
758 while (fgets(line,MAXLINELENGTH,fic)!=NULL)
761 for (i=0;line[i]!=0;i++);
762 if (i>=MAXLINELENGTH-1) { fprintf(stderr,"line %d is too long\n",totallines); exit(1); }
766 if (totallines%10000==0 && debug) { printf("."); fflush(stdout); }
767 if (strncmp("--- Day changed",line,15)==0) /* --- Day changed Wed May 01 2002 */
771 lastdays[i].lines=lastdays[i-1].lines;
772 for (j=0;j<4;j++) lastdays[i].hours[j]=lastdays[i-1].hours[j];
775 for (j=0;j<4;j++) lastdays[0].hours[j]=0;
778 else if (strncmp("-!- mode/",&line[6],9)==0) /* 00:00 -!- mode/#channel [...] by (Nick, Nick2, )Nick3 */
780 for (i=strlen(line);line[i]!=' ';i--);
782 users[dichotomic(nick)].counters[D_MODE]++;
784 else if (strncmp("-!-",&line[6],3)==0) /* 00:00 -!- Nick something... */
786 for (i=10;line[i]!=' ';i++);
790 if (strncmp("changed the topic of",message,20)==0) /* 00:00 -!- Nick changed the topic of #channel to: new topic */
792 users[dichotomic(nick)].counters[D_TOPIC]++;
793 for (i=21;message[i]!=':';i++);
794 message=&message[i+2];
796 if ((nbtopics<=NBTOPICS) || (rand()%(nbtopics/NBTOPICS)==0))
798 temp=nbtopics<=NBTOPICS?nbtopics-1:rand()%NBTOPICS;
799 strcpy(topics[temp].nick,nick);
800 strncpy(topics[temp].topic,message,MAXQUOTELENGTH);
803 else if (strncmp("was kicked from",message,15)==0) /* 00:00 -!- Nick was kicked from #channel by Nick [Reason] */
805 users[dichotomic(nick)].counters[D_KICKED]++;
806 for (i=16;message[i]!=' ';i++);
807 message=&message[i+4];
808 for (i=0;message[i]!=' ';i++);
810 users[dichotomic(message)].counters[D_KICK]++;
812 else if (strncmp("is now known as",message,15)==0) /* 00:00 -!- Nick is now known as Nick */
813 users[dichotomic(nick)].counters[D_NICK]++;
814 else if (message[0]=='[') /* 00:00 -!- Nick [user@host] something... */
816 for (i=0;message[i]!=']';i++);
817 message=&message[i+2];
818 if (strncmp("has joined",message,10)==0) /* 00:00 -!- Nick [user@host] has joined #channel */
819 users[dichotomic(nick)].counters[D_JOIN]++;
820 else if (strncmp("has quit",message,8)==0); /* 00:00 -!- Nick [user@host] has quit [Reason] */
821 else if (strncmp("has left",message,8)==0); /* 00:00 -!- Nick [user@host] has left #channel [Reason] */
825 else if ((line[6]=='<') || (line[7]=='*'))
829 if (line[7]=='*') /* 00:00 * Nick the message */
831 for (i=9;line[i]!=' ';i++);
835 else if (line[7]=='>') /* 00:00 <>>>?Nick<<<> the personal message */
836 /* 00:00 <>>?Nick<<> the personal message */
838 for (i=10;line[i]!='<';i++);
840 if (line[9]=='>') nick++;
843 else /* 00:00 <?Nick> the message */
847 * Irssi doesn't log channel mode with show_nickmode = OFF
848 * the following covers op, half-op, voice and show_nickmode_empty
850 if (line[7]=='@' || line[7]=='%' || line[7]=='+' || line[7]==' ') {
856 for (i=nickstart;line[i]!='>';i++);
857 nick=&line[nickstart];
862 if (line[7]=='*') users[i].counters[D_ME]++;
866 if (monolines==5) users[i].counters[D_MONOLOGUE]++;
875 if (top_words || ranking==1) users[i].words+=findwords(message);
877 users[i].hours[hour/6]++;
879 lastdays[0].hours[hour/6]++;
884 hour=hour*4+atoi(&line[3])/15;
887 if (message[j-1]=='?') users[i].counters[D_QUESTION]++;
888 else if (message[j-1]=='!') users[i].counters[D_EXCLAM]++;
889 else if ((message[j-3]==' ')&&(message[j-2]==':'))
891 if (message[j-1]==')') users[i].counters[D_SMILE]++;
892 else if (message[j-1]=='(') users[i].counters[D_FROWN]++;
894 if (rand()%users[i].lines==0) strncpy(users[i].quote,message,MAXQUOTELENGTH);
895 if (strncmp("http://",message,7)==0)
897 users[i].counters[D_URL]++;
898 for (i=0;(message[i]!=' ') && (i<strlen(message));i++);
901 if ((nburls<=NBURLS) || (rand()%(nburls/NBURLS)==0))
903 temp=nburls<=NBURLS?nburls-1:rand()%NBURLS;
904 strcpy(urls[temp].nick,nick);
905 strcpy(urls[temp].url,message);
906 strncpy(urls[temp].shorturl,message,MAXQUOTELENGTH);
913 if (debug) printf(" done\n");
916 void parse_nick(char *nickfile)
921 char line[MAXLINELENGTH];
924 for (i=0;i<nbusers;i++) users[i].temp=users[i].lines;
925 if ((fic=fopen(nickfile,"rt"))==NULL) { fprintf(stderr,"can't open nick file \"%s\"\n",nickfile); exit(1); }
926 while (fscanf(fic,"%s",line)==1)
928 user=dichotomic(line);
929 fscanf(fic,"%s",line);
930 if (regcomp(&preg,line,0)!=0) { fprintf(stderr,"error in nick file"); exit(1); }
931 for (i=0;i<nbusers;i++) if ((i!=user) && (regexec(&preg,users[i].nick,0,0,0)==0) && (users[i].lines>=0))
933 if (users[i].temp>users[user].temp) /* for nick alias, keep the random quote of the most used nick */
935 strcpy(users[user].quote,users[i].quote);
936 users[user].temp=users[i].temp;
938 users[user].lines+=users[i].lines;
939 users[user].words+=users[i].words;
940 users[user].letters+=users[i].letters;
941 for (j=0;j<4;j++) users[user].hours[j]+=users[i].hours[j];
942 for (j=0;j<NBCOUNTERS;j++) users[user].counters[j]+=users[i].counters[j];
943 /* "remove" old user */
947 for (j=0;j<4;j++) users[i].hours[j]=-1;
948 for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=-1;
953 /* "remove" the ignored nicks */
954 i=dichotomic("<NULL>");
958 for (j=0;j<4;j++) users[i].hours[j]=-1;
959 for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=-1;
962 void gen_xhtml(char *xhtmlfile)
968 char line[MAXLINELENGTH];
971 if ((fic=fopen(xhtmlfile,"wt"))==NULL) { fprintf(stderr,"can't open xhtml file \"%s\"\n",xhtmlfile); exit(1); }
974 if (strcmp("none",header)==0)
976 fprintf(fic,"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n");
977 fprintf(fic,"<!-- Generated by irssistats %s : %s -->\n\n",VERSION,URL);
978 fprintf(fic,"<html>\n\n<head>\n<title>");
979 fprintf(fic,L("HEADER"),channel,maintainer);
980 fprintf(fic,"</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" />\n",L("CHARSET"));
982 fprintf(fic,"<meta http-equiv=\"Refresh\" content=\"%d\" />\n",refresh_time);
983 subtheme=strtok(theme,",");
984 fprintf(fic,"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s.css\" title=\"%s\" />\n",subtheme,subtheme);
985 while ((subtheme=strtok(NULL,","))!=NULL)
986 fprintf(fic,"<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"%s.css\" title=\"%s\" />\n",subtheme,subtheme);
987 fprintf(fic,"</head>\n\n");
988 fprintf(fic,"<body>\n\n");
992 if ((sfic=fopen(header,"rt"))==NULL) { fprintf(stderr,"can't open header file \"%s\"\n",header); exit(1); }
993 while ((temp=fread(line,1,MAXLINELENGTH,sfic))) fwrite(line,temp,1,fic);
996 fprintf(fic,"<div id=\"irssistats\">\n\n<div id=\"irssistats_header\">\n<h1>");
997 fprintf(fic,L("HEADER"),channel,maintainer);
998 fprintf(fic,"</h1>\n<p>\n%s</p>\n</div>\n\n",ctime(&debut));
1001 fprintf(fic,"<div id=\"irssistats_legend\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("LEGEND"));
1002 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);
1003 fprintf(fic,"</tr>\n</table>\n</div>\n\n");
1006 fprintf(fic,"<div id=\"irssistats_lastdays\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("LASTDAYS"));
1008 for (i=30;i>=0;i--) if (lastdays[i].lines>max) max=lastdays[i].lines;
1011 fprintf(fic,"<td align=\"center\" valign=\"bottom\"><small>%d</small>",lastdays[i].lines);
1012 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);
1013 fprintf(fic,"</td>\n");
1015 fprintf(fic,"</tr>\n<tr>\n");
1017 fprintf(fic,"<th>%d</th>\n",i);
1018 fprintf(fic,"</tr>\n</table>\n</div>\n\n");
1021 fprintf(fic,"<div id=\"irssistats_tophours\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("TOPHOURS"));
1023 for (i=0;i<24*4;i++) if (hours[i]>max) max=hours[i];
1024 if (quarter) for (i=0;i<24*4;i++)
1026 fprintf(fic,"<td align=\"center\" valign=\"bottom\">");
1027 if (hours[i]!=0) fprintf(fic,"<div class=\"v%d\" style=\"width:4px;height:%dpx\"></div>",i/4/6+1,150*hours[i]/max);
1028 fprintf(fic,"</td>\n");
1030 else for (i=0;i<24;i++)
1032 fprintf(fic,"<td align=\"center\" valign=\"bottom\"><small>%.1f%%</small>",lines!=0?(float)100*hours[i]/lines:0);
1033 if (hours[i]!=0) fprintf(fic,"<div class=\"v%d\" style=\"height:%dpx\"></div>",i/6+1,150*hours[i]/max);
1034 fprintf(fic,"</td>\n");
1036 fprintf(fic,"</tr>\n<tr>\n");
1038 if (quarter) fprintf(fic,"<th colspan=\"4\">%d</th>\n",i);
1039 else fprintf(fic,"<th>%d</th>\n",i);
1040 fprintf(fic,"</tr>\n</table>\n</div>\n\n");
1043 fprintf(fic,"<div id=\"irssistats_topusers\">\n<h2>%s</h2>\n",L("TOPUSERS"));
1047 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"));
1050 /* "letters" and "words" ranking are not yet translated so we use the generic word "rank" ... */
1051 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"),"rank",L("HOURS"),L("AVGLETTERS"),L("QUOTE"));
1054 for (i=1;i<=NBUSERS;i++)
1061 for (j=0;j<nbusers;j++) if (users[j].lines>max) max=users[user=j].lines;
1064 for (j=0;j<nbusers;j++) if (users[j].words>max) max=users[user=j].words;
1067 for (j=0;j<nbusers;j++) if (users[j].letters>max) max=users[user=j].letters;
1075 fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].lines);
1078 fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].words);
1081 fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].letters);
1084 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);
1085 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);
1086 printhtml(fic,users[user].quote);
1087 fprintf(fic,"\"</td></tr>\n");
1088 users[user].lines=-1;
1089 users[user].words=-1;
1090 users[user].letters=-1;
1093 fprintf(fic,"</table>\n");
1095 for (i=0;i<=nbusers;i++) if (users[i].lines>=0) temp++;
1099 fprintf(fic,L("OTHERS"),temp);
1100 fprintf(fic,"</p>\n");
1102 fprintf(fic,"</div>\n\n");
1104 /* top users by time */
1105 fprintf(fic,"<div id=\"irssistats_topuserstime\">\n<h2>%s</h2>\n",L("TOPUSERSTIME"));
1106 fprintf(fic,"<table>\n<tr><th></th>");
1107 for (i=0;i<4;i++) fprintf(fic,"<th colspan=\"2\">%s %d-%d</th>",L("HOURS"),i*6,i*6+5);
1108 fprintf(fic,"</tr>\n");
1109 for (i=1;i<=NBUSERSTIME;i++)
1111 fprintf(fic,"<tr><td>%d</td>",i);
1116 for (k=0;k<nbusers;k++) if (users[k].hours[j]>max) max=users[user=k].hours[j];
1119 fprintf(fic,"<td>%s</td><td>%d</td>",users[user].nick,users[user].hours[j]);
1120 users[user].hours[j]=-1;
1122 else fprintf(fic,"<td></td><td></td>");
1124 fprintf(fic,"</tr>\n");
1126 fprintf(fic,"</table>\n</div>\n\n");
1129 fprintf(fic,"<div id=\"irssistats_randtopics\">\n<h2>%s</h2>\n",L("RANDTOPICS"));
1130 fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th></tr>\n",L("CHANGEDBY"),L("NEWTOPIC"));
1131 for (i=nbtopics<NBTOPICS?nbtopics-1:NBTOPICS-1;i>=0;i--)
1133 fprintf(fic,"<tr><td>%s</td><td>\"",topics[i].nick);
1134 printhtml(fic,topics[i].topic);
1135 fprintf(fic,"\"</td></tr>\n");
1137 fprintf(fic,"</table>\n</div>\n\n");
1140 fprintf(fic,"<div id=\"irssistats_randurls\">\n<h2>%s</h2>\n",L("RANDURLS"));
1141 fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th></tr>\n",L("POSTEDBY"),L("POSTEDURL"));
1142 for (i=nburls<NBURLS?nburls-1:NBURLS-1;i>=0;i--)
1144 fprintf(fic,"<tr><td>%s</td><td>\"<a href=\"",urls[i].nick);
1145 printhtml(fic,urls[i].url);
1147 printhtml(fic,urls[i].shorturl);
1148 fprintf(fic,"</a>\"</td></tr>\n");
1150 fprintf(fic,"</table>\n</div>\n\n");
1155 fprintf(fic,"<div id=\"irssistats_topwords\">\n<h2>%s</h2>\n",L("TOPWORDS"));
1156 fprintf(fic,"<table>\n<tr><th></th><th>%s</th><th>%s</th></tr>\n",L("WORD"),L("OCCURRENCES"));
1157 for (i=0;i<NBWORDS;i++)
1158 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);
1159 fprintf(fic,"</table>\n</div>\n\n");
1163 fprintf(fic,"<div id=\"irssistats_bignumbers\">\n<h2>%s</h2>\n",L("BIGNUMBERS"));
1164 fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n",L("NICK"),L("NUMBERS"),L("NBLINES"));
1165 for (i=0;i<NBCOUNTERS;i++)
1169 for (j=0;j<nbusers;j++) if (users[j].counters[i]>max) max=users[user=j].counters[i];
1170 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]);
1172 fprintf(fic,"</table>\n</div>\n\n");
1175 fprintf(fic,"<div id=\"irssistats_footer\">\n<p>");
1176 fprintf(fic,L("TIME"),totallines,days,(int)(time(NULL)-debut));
1177 fprintf(fic,"</p>\n<p>%s <a href=\"%s\">irssistats %s</a></p>\n",L("FOOTER"),URL,VERSION);
1180 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");
1181 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");
1183 fprintf(fic,"</div>\n\n</div>");
1184 if (strcmp("none",header)==0)
1186 fprintf(fic,"\n\n</body>\n\n</html>\n");
1190 if ((sfic=fopen(footer,"rt"))==NULL) { fprintf(stderr,"can't open footer file \"%s\"\n",footer); exit(1); }
1191 while ((temp=fread(line,1,MAXLINELENGTH,sfic))) fwrite(line,temp,1,fic);
1198 void parse_config(char *configfile)
1201 char line[MAXLINELENGTH];
1202 char keyword[MAXLINELENGTH];
1203 char value[MAXLINELENGTH];
1207 if (configfile!=NULL)
1209 if ((fic=fopen(configfile,"rt"))==NULL)
1211 fprintf(stderr,"can't open config file : \"%s\"\n",configfile);
1217 sprintf(line,"%s/.irssistats",getenv("HOME"));
1218 if ((fic=fopen(line,"rt"))==NULL)
1219 if ((fic=fopen("/etc/irssistats.conf","rt"))==NULL)
1221 fprintf(stderr,"can't find config file : \"%s\" nor \"/etc/irssistats.conf\"\n",line);
1222 fprintf(stderr,"please give the path to the config file in argument\n");
1227 while (fgets(line,MAXLINELENGTH,fic))
1230 if (*line!=';' && *line!='#' && *line!='/' && *line!='-' && *line!='\n')
1232 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); }
1234 if (strcmp("debug",keyword)==0)
1236 if (strcmp("none",value)==0) debug=0;
1238 if (strcmp("normal",value)==0) debug=1;
1240 if (strcmp("verbose",value)==0) { debug=2; fprintf(stderr,"switching to verbose output\n"); }
1241 else { fprintf(stderr,"unknown value for \"debug\" option, must be \"normal\", \"verbose\" or \"none\"\n"); exit(1); }
1245 if (strcmp("channel",keyword)==0)
1247 if (debug==2) fprintf(stderr,"setting channel name to \"%s\"\n",value);
1248 strcpy(channel,value);
1252 if (strcmp("maintainer",keyword)==0)
1254 if (debug==2) fprintf(stderr,"setting maintainer to \"%s\"\n",value);
1255 strcpy(maintainer,value);
1259 if (strcmp("language",keyword)==0)
1261 if (debug==2) fprintf(stderr,"setting language to \"%s\"\n",value);
1262 for (i=0;i<NBLANGUAGES;i++) if (strcmp(value,keys[i][0][1])==0) { language=i; break; }
1265 fprintf(stderr,"Invalid language : %s\n",value);
1266 fprintf(stderr,"Supported languages :\n");
1267 for (i=0;i<NBLANGUAGES;i++) fprintf(stderr,"%s = %s\n",keys[i][0][1],keys[i][0][0]);
1273 if (strcmp("theme",keyword)==0)
1275 if (debug==2) fprintf(stderr,"setting theme to \"%s\"\n",value);
1276 strcpy(theme,value);
1280 if (strcmp("refresh_time",keyword)==0)
1282 refresh_time=atoi(value);
1283 if (debug==2) fprintf(stderr,"setting refresh_time to \"%d\"\n",refresh_time);
1287 if (strcmp("w3c_link",keyword)==0)
1289 if (debug==2) fprintf(stderr,"setting w3c_link to \"%s\"\n",value);
1290 if (strcmp("no",value)==0) w3c_link=0;
1291 else if (strcmp("yes",value)==0) w3c_link=1;
1292 else { fprintf(stderr,"unknown value for \"w3c_link\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1296 if (strcmp("header",keyword)==0)
1298 if (debug==2) fprintf(stderr,"setting header to \"%s\"\n",value);
1299 strcpy(header,value);
1303 if (strcmp("footer",keyword)==0)
1305 if (debug==2) fprintf(stderr,"setting footer to \"%s\"\n",value);
1306 strcpy(footer,value);
1310 if (strcmp("input",keyword)==0)
1312 if (debug==2) fprintf(stderr,"parsing log file \"%s\"\n",value);
1317 if (strcmp("nickfile",keyword)==0)
1319 if (debug==2) fprintf(stderr,"nick alias using file \"%s\"\n",value);
1324 if (strcmp("output",keyword)==0)
1326 if (debug==2) fprintf(stderr,"generating xhtml file \"%s\"\n",value);
1330 /* reset variables */
1335 for (i=0;i<24*4;i++) hours[i]=0;
1338 for (i=0;i<NBWORDS;i++) topwords[i].nb=0;
1344 if (strcmp("top_words",keyword)==0)
1346 if (debug==2) fprintf(stderr,"setting top_words to \"%s\"\n",value);
1347 if (strcmp("no",value)==0) top_words=0;
1348 else if (strcmp("yes",value)==0) top_words=1;
1349 else { fprintf(stderr,"unknown value for \"top_words\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1353 if (strcmp("ranking",keyword)==0)
1355 if (strcmp("lines",value)==0) ranking=0;
1357 if (strcmp("words",value)==0) ranking=1;
1359 if (strcmp("letters",value)==0) ranking=2;
1360 else { fprintf(stderr,"unknown value for \"ranking\" option, must be \"lines\", \"words\" or \"letters\"\n"); exit(1); }
1364 if (strcmp("quarter",keyword)==0)
1366 if (debug==2) fprintf(stderr,"setting quarter to \"%s\"\n",value);
1367 if (strcmp("no",value)==0) quarter=0;
1368 else if (strcmp("yes",value)==0) quarter=1;
1369 else { fprintf(stderr,"unknown value for \"quarter\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1372 else { fprintf(stderr,"error in config file : \"%s\" is an unknown keyword (line %d)\n",keyword,configlines); exit(1); }
1378 int main(int argc,char *argv[])
1380 if ((users=malloc(maxusers*sizeof(struct user)))==NULL) { fprintf(stderr,"unable to malloc memory\n"); exit(1); }
1381 srand(debut=time(NULL));
1382 if (argc==1) parse_config(NULL);
1383 else if (argc==2) parse_config(argv[1]);
1386 fprintf(stderr,"Usage : %s [/path/to/file.conf]\n",argv[0]);
1387 fprintf(stderr,"Version : irssistats %s\n",VERSION);