version 0.72
[irssistats] / irssistats.c
1 /*
2  * irssistats version 0.72
3  *
4  * This tool generates IRC stats based on irssi logs.
5  * Usage: irssistats [/path/to/file.conf]
6  *
7  * Copyright (C) 2002-2004  Antoine Jacquet <royale@zerezo.com>
8  * http://royale.zerezo.com/irssistats/
9  *
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.
14  *
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.
19  *
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
23  */
24
25
26 #include <sys/types.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <time.h>
30 #include <string.h>
31 #include <locale.h>
32 #ifdef __WIN32__
33 #define GLOBALCONF "irssistats.conf"
34 #else
35 #define GLOBALCONF "/etc/irssistats.conf"
36 #include <regex.h>
37 #endif
38
39 /* Config */
40 #define BASEUSERS 1000
41 #define MAXNICKLENGTH 50
42 #define MAXLINELENGTH 2000
43 #define MAXQUOTELENGTH 100
44 #define NBUSERS 50
45 #define NBUSERSTIME 10
46 #define NBURLS 5
47 #define NBTOPICS 5
48 #define NBWORDS 20
49 #define MINWORDLENGTH 5
50
51 /* irssistats */
52 #define VERSION "0.72"
53 #define URL "http://royale.zerezo.com/irssistats/"
54
55 /* Counters */
56 #define D_SMILE     0
57 #define D_FROWN     1
58 #define D_EXCLAM    2
59 #define D_QUESTION  3
60 #define D_ME        4
61 #define D_TOPIC     5
62 #define D_MODE      6
63 #define D_KICK      7
64 #define D_KICKED    8
65 #define D_URL       9
66 #define D_JOIN      10
67 #define D_NICK      11
68 #define D_MONOLOGUE 12
69 #define NBCOUNTERS  13
70 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"};
71
72 /* Languages */
73 #define NBLANGUAGES 11
74 #define NBKEYS 39
75 char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and abbreviation */
76 {
77   { /* English language */
78     { "English",      "en" },
79     { "CHARSET",      "ISO-8859-1" },
80     { "HEADER",       "Statistics for %s by %s" },
81     { "LEGEND",       "Legend" },
82     { "LASTDAYS",     "Lastdays statistics" },
83     { "TOPHOURS",     "Hourly statistics" },
84     { "TOPUSERS",     "Most active people" },
85     { "OTHERS",       "There are %d left not ranked..." },
86     { "NBLINES",      "lines" },
87     { "NICK",         "nick" },
88     { "AVGLETTERS",   "letters/lines" },
89     { "HOURS",        "hours" },
90     { "QUOTE",        "random message" },
91     { "TOPUSERSTIME", "Most active people by time of day" },
92     { "RANDTOPICS",   "Some topics" },
93     { "CHANGEDBY",    "changed by" },
94     { "NEWTOPIC",     "new topic" },
95     { "RANDURLS",     "Some URLs" },
96     { "POSTEDBY",     "posted by" },
97     { "POSTEDURL",    "URL" },
98     { "TOPWORDS",     "Most used words" },
99     { "WORD",         "word" },
100     { "OCCURRENCES",  "occurrences" },
101     { "BIGNUMBERS",   "Some big numbers..." },
102     { "NUMBERS",      "numbers" },
103     { "TIME",         "%d lines (%d days) parsed in %d seconds" },
104     { "FOOTER",       "Statistics generated by" },
105     { "C_SMILE",      "is often happy :)" },
106     { "C_FROWN",      "is often sad :(" },
107     { "C_EXCLAM",     "yells a lot !" },
108     { "C_QUESTION",   "asks a lot of questions ?" },
109     { "C_ME",         "likes /me command" },
110     { "C_TOPIC",      "often changes the topic" },
111     { "C_MODE",       "often changes the modes" },
112     { "C_KICK",       "likes to /kick" },
113     { "C_KICKED",     "is often kicked" },
114     { "C_URL",        "posts many URLs" },
115     { "C_JOIN",       "doesn't know wether to stay or quit" },
116     { "C_NICK",       "often changes his nick" },
117     { "C_MONOLOGUE",  "speaks a lot of monologues" }
118   },
119   { /* French language */
120     { "French",       "fr" },
121     { "CHARSET",      "ISO-8859-1" },
122     { "HEADER",       "Statistiques de %s par %s" },
123     { "LEGEND",       "L&eacute;gende" },
124     { "LASTDAYS",     "Statistiques des derniers jours" },
125     { "TOPHOURS",     "Statistiques horaires" },
126     { "TOPUSERS",     "Personnes les plus actives" },
127     { "OTHERS",       "Il reste %d personnes non class&eacute;es..." },
128     { "NBLINES",      "lignes" },
129     { "NICK",         "nick" },
130     { "AVGLETTERS",   "lettres/lignes" },
131     { "HOURS",        "heures" },
132     { "QUOTE",        "message al&eacute;atoire" },
133     { "TOPUSERSTIME", "Personnes les plus actives par p&eacute;riode de la journ&eacute;e" },
134     { "RANDTOPICS",   "Quelques topics" },
135     { "CHANGEDBY",    "chang&eacute; par" },
136     { "NEWTOPIC",     "nouveau topic" },
137     { "RANDURLS",     "Quelques URLs" },
138     { "POSTEDBY",     "post&eacute;e par" },
139     { "POSTEDURL",    "URL" },
140     { "TOPWORDS",     "Mots les plus utilis&eacute;s" },
141     { "WORD",         "mot" },
142     { "OCCURRENCES",  "occurrences" },
143     { "BIGNUMBERS",   "Quelques grands nombres..." },
144     { "NUMBERS",      "nombres" },
145     { "TIME",         "%d lignes (%d jours) trait&eacute;es en %d secondes" },
146     { "FOOTER",       "Statistiques g&eacute;n&eacute;r&eacute;es par" },
147     { "C_SMILE",      "est souvent heureux :)" },
148     { "C_FROWN",      "est souvent triste :(" },
149     { "C_EXCLAM",     "hurle beaucoup !" },
150     { "C_QUESTION",   "pose beaucoup de questions ?" },
151     { "C_ME",         "aime la commande /me" },
152     { "C_TOPIC",      "change souvent le topic" },
153     { "C_MODE",       "change souvent les modes" },
154     { "C_KICK",       "aime la commande /kick" },
155     { "C_KICKED",     "est souvent kick&eacute;" },
156     { "C_URL",        "poste beaucoup d'URLs" },
157     { "C_JOIN",       "ne sait pas s'il doit rester ou partir" },
158     { "C_NICK",       "change souvent de nick" },
159     { "C_MONOLOGUE",  "parle beaucoup de monologues" }
160   },
161   { /* German language */
162     /* contributed by Valentin Gelhorn <valentin.gelhorn@web.de> */
163     { "German",       "de" },
164     { "CHARSET",      "ISO-8859-1" },
165     { "HEADER",       "Statistiken f&uuml;r %s von %s" },
166     { "LEGEND",       "Legende" },
167     { "LASTDAYS",     "Statistik der letzten Tage" },
168     { "TOPHOURS",     "St&uuml;ndliche Statistik" },
169     { "TOPUSERS",     "Die aktivsten Personen" },
170     { "OTHERS",       "Es bleiben noch %d uneingetragene" },
171     { "NBLINES",      "Zeilen" },
172     { "NICK",         "Nick" },
173     { "AVGLETTERS",   "Buchstaben/Zeile" },
174     { "HOURS",        "Stunden" },
175     { "QUOTE",        "Zuf&auml;llig ausgewaehlte Zitate" },
176     { "TOPUSERSTIME", "Die aktivsten Personen zur bestimmten Tageszeit" },
177     { "RANDTOPICS",   "Ein paar Topics" },
178     { "CHANGEDBY",    "Gesetzt von" },
179     { "NEWTOPIC",     "Neues topic" },
180     { "RANDURLS",     "Ein paar URLs" },
181     { "POSTEDBY",     "Geschrieben von" },
182     { "POSTEDURL",    "URL" },
183     { "TOPWORDS",     "Am h&auml;ufigsten benutze W&ouml;rter" },
184     { "WORD",         "Wort" },
185     { "OCCURRENCES",  "Vorkommen" },
186     { "BIGNUMBERS",   "Ein paar grosse Zahlen" },
187     { "NUMBERS",      "Zahlen" },
188     { "TIME",         "%d Zeilen (%d Tage) analysiert in %d Sekunden" },
189     { "FOOTER",       "Statistiken wurden erstellt von" },
190     { "C_SMILE",      "ist oft gl&uuml;klich :)" },
191     { "C_FROWN",      "ist oft traurig :(" },
192     { "C_EXCLAM",     "schreit oft !" },
193     { "C_QUESTION",   "stellt viele Fragen ?" },
194     { "C_ME",         "mag /me'en" },
195     { "C_TOPIC",      "aendert oft das Topico" },
196     { "C_MODE",       "aendert oft die Modes" },
197     { "C_KICK",       "mag /kick'en" },
198     { "C_KICKED",     "wird oft gekickt"},
199     { "C_URL",        "schreibt viele URLs"},
200     { "C_JOIN",       "kann sich nicht entscheiden ob er bleiben oder gehen soll" },
201     { "C_NICK",       "&auml;ndert oft seinen Nick" },
202     { "C_MONOLOGUE",  "spricht oft Monologe" }
203   },
204   { /* Spanish language */
205     /* contributed by Alex <ainaker@gmx.net> */
206     { "Spanish",      "es" },
207     { "CHARSET",      "ISO-8859-1" },
208     { "HEADER",       "Estad&iacute;sticas de %s por %s" },
209     { "LEGEND",       "Leyenda" },
210     { "LASTDAYS",     "Estad&iacute;sticas de los &uacute;ltimos d&iacute;as" },
211     { "TOPHOURS",     "Estad&iacute;sticas por horas" },
212     { "TOPUSERS",     "Los que m&aacute;s escriben" },
213     { "OTHERS",       "Hay %d m&aacute;s que no llegaron..." },
214     { "NBLINES",      "l&iacute;neas" },
215     { "NICK",         "nick" },
216     { "AVGLETTERS",   "letras por l&iacute;nea" },
217     { "HOURS",        "horas" },
218     { "QUOTE",        "Frase aleatoria" },
219     { "TOPUSERSTIME", "Los que m&aacute;s escriben seg&uacute;n la hora" },
220     { "RANDTOPICS",   "Algunos topics" },
221     { "CHANGEDBY",    "Puestos por" },
222     { "NEWTOPIC",     "topic" },
223     { "RANDURLS",     "Algunas URLs" },
224     { "POSTEDBY",     "puestas por" },
225     { "POSTEDURL",    "URL" },
226     { "TOPWORDS",     "Palabras m&aacute;s usadas" },
227     { "WORD",         "Palabra" },
228     { "OCCURRENCES",  "Frecuencia" },
229     { "BIGNUMBERS",   "Algunos datos..." },
230     { "NUMBERS",      "N&uacute;mero de veces" },
231     { "TIME",         "%d lineas (%d d&iacute;as) procesadas en %d segundos" },
232     { "FOOTER",       "Estad&iacute;sticas generadas por" },
233     { "C_SMILE",      "Suele estar fel&iacute;z :)" },
234     { "C_FROWN",      "Suele estar triste :(" },
235     { "C_EXCLAM",     "Grita mucho !" },
236     { "C_QUESTION",   "Hace muchas preguntas ?" },
237     { "C_ME",         "Abusa del comando /me" },
238     { "C_TOPIC",      "Suele cambiar el topic" },
239     { "C_MODE",       "Cambia a veces los modos del canal" },
240     { "C_KICK",       "Le gusta patear" },
241     { "C_KICKED",     "Es pateado con frecuencia" },
242     { "C_URL",        "Pone muchas URLs" },
243     { "C_JOIN",       "No sabe si irse o quedarse" },
244     { "C_NICK",       "Cambia mucho de nick" },
245     { "C_MONOLOGUE",  "Habla solo" }
246   },
247   { /* Polish language */
248     /* contributed by Jakub Jankowski <shasta@atn.pl> */
249     { "Polish",       "pl" },
250     { "CHARSET",      "ISO-8859-2" },
251     { "HEADER",       "Statystyki dla %s zebrane przez %s" },
252     { "LEGEND",       "Legenda" },
253     { "LASTDAYS",     "Statystyki z ostatnich dni" },
254     { "TOPHOURS",     "Statystyki godzinowe" },
255     { "TOPUSERS",     "Najaktywniejsi" },
256     { "OTHERS",       "Jest jeszcze %d nie sklasyfikowanych..." },
257     { "NBLINES",      "linii" },
258     { "NICK",         "nick" },
259     { "AVGLETTERS",   "liter/liniê" },
260     { "HOURS",        "godziny" },
261     { "QUOTE",        "losowa wypowied¼" },
262     { "TOPUSERSTIME", "Najaktywniejsi wed³ug pory dnia" },
263     { "RANDTOPICS",   "Kilka topików" },
264     { "CHANGEDBY",    "ustawiony przez" },
265     { "NEWTOPIC",     "topik" },
266     { "RANDURLS",     "Kilka URL-i" },
267     { "POSTEDBY",     "poda³(a)" },
268     { "POSTEDURL",    "URL" },
269     { "TOPWORDS",     "Najczê¶ciej wystêpuj±ce s³owa" },
270     { "WORD",         "s³owo" },
271     { "OCCURRENCES",  "wyst±pieñ" },
272     { "BIGNUMBERS",   "Kilka wielkopomnych liczb..." },
273     { "NUMBERS",      "kategorie" },
274     { "TIME",         "Dokonano analizy %d linii (obejmuj±cych %d dni) w czasie %d sekund" },
275     { "FOOTER",       "Statystyki wygenerowane przez" },
276     { "C_SMILE",      "jest czêsto szczesliwy(a) :)" },
277     { "C_FROWN",      "jest czêsto smutny(a) :(" },
278     { "C_EXCLAM",     "czêsto KRZYCZY!" },
279     { "C_QUESTION",   "zadaje du¿o pytañ?" },
280     { "C_ME",         "lubi u¿ywaæ /me" },
281     { "C_TOPIC",      "czêsto zmienia topik" },
282     { "C_MODE",       "czêsto zmienia tryby kana³u" },
283     { "C_KICK",       "lubi kopaæ" },
284     { "C_KICKED",     "czêsto wykopywany(a)" },
285     { "C_URL",        "podaje du¿o URL-i" },
286     { "C_JOIN",       "nie wie czy zostaæ, czy wyj¶æ" },
287     { "C_NICK",       "czêsto zmienia nick" },
288     { "C_MONOLOGUE",  "uwielbia monologi" }
289   },
290   { /* Polish language */
291     /* contributed by Piotr Jarmuz <coreupper@yahoo.com> */
292     { "Polish",       "pl-old" },
293     { "CHARSET",      "ISO-8859-1" },
294     { "HEADER",       "Statystyki dla %s przez %s" },
295     { "LEGEND",       "Legenda" },
296     { "LASTDAYS",     "Statystyki z ostatnich dni" },
297     { "TOPHOURS",     "Statystyki godzinne" },
298     { "TOPUSERS",     "Najaktywniejsi ludzie" },
299     { "OTHERS",       "Zostalo jeszcze %d nie sklasyfikowanych..." },
300     { "NBLINES",      "linie" },
301     { "NICK",         "nick" },
302     { "AVGLETTERS",   "litery/linie" },
303     { "HOURS",        "godziny" },
304     { "QUOTE",        "przypadkowa wiadomosc" },
305     { "TOPUSERSTIME", "Najaktywniejsi ludzie wedlug czasu dnia" },
306     { "RANDTOPICS",   "Pare tematow" },
307     { "CHANGEDBY",    "zmienione przez" },
308     { "NEWTOPIC",     "nowy temat" },
309     { "RANDURLS",     "Pare URL-i" },
310     { "POSTEDBY",     "wyslane przez" },
311     { "POSTEDURL",    "URL" },
312     { "TOPWORDS",     "Najczestsze slowa" },
313     { "WORD",         "slowo" },
314     { "OCCURRENCES",  "wystapienia" },
315     { "BIGNUMBERS",   "Pare wielkich liczb..." },
316     { "NUMBERS",      "liczby" },
317     { "TIME",         "%d linii (%d dni) sparsowanych w %d sekund" },
318     { "FOOTER",       "Statystyki wygenerowane przez" },
319     { "C_SMILE",      "jest czesto szczesliwy :)" },
320     { "C_FROWN",      "jest czesto smutny :(" },
321     { "C_EXCLAM",     "duzo krzyczy !" },
322     { "C_QUESTION",   "zadaje duzo pytan ?" },
323     { "C_ME",         "lubi /mnie polecenie" },
324     { "C_TOPIC",      "czesto zmienia temat" },
325     { "C_MODE",       "czesto zmienia tryb" },
326     { "C_KICK",       "lubi /kopac" },
327     { "C_KICKED",     "czesto go wykopuja" },
328     { "C_URL",        "wysyla duzo URL-i" },
329     { "C_JOIN",       "nie wie czy zostac czy wyjsc" },
330     { "C_NICK",       "czesto zmienia swojego nicka" },
331     { "C_MONOLOGUE",  "czesto mowi monologiem" }
332   },
333   { /* Finnish language */
334     /* contributed by Antti Huopana <ahuopana@ratol.fi> */
335     { "Finnish",      "fi" },
336     { "CHARSET",      "ISO-8859-1" },
337     { "HEADER",       "Kanavan %s tilastot - %s" },
338     { "LEGEND",       "Merkkien selitykset" },
339     { "LASTDAYS",     "Viime päivien tilastot" },
340     { "TOPHOURS",     "Tilastot tunneittain" },
341     { "TOPUSERS",     "Aktiivisimmat ihmiset" },
342     { "OTHERS",       "Jäljelle jäi %d joita ei listattu..." },
343     { "NBLINES",      "rivit" },
344     { "NICK",         "nikki" },
345     { "AVGLETTERS",   "kirjainta/rivi" },
346     { "HOURS",        "tunnit" },
347     { "QUOTE",        "satunnainen viesti" },
348     { "TOPUSERSTIME", "Vuorokauden ajan mukaan aktiivisimmat" },
349     { "RANDTOPICS",   "Joitakin aiheita" },
350     { "CHANGEDBY",    "vaihtaja" },
351     { "NEWTOPIC",     "aihe" },
352     { "RANDURLS",     "Joitakin URLeja" },
353     { "POSTEDBY",     "lähettäjä" },
354     { "POSTEDURL",    "URL" },
355     { "TOPWORDS",     "Eniten käytettyjä sanoja" },
356     { "WORD",         "sana" },
357     { "OCCURRENCES",  "käytetty" },
358     { "BIGNUMBERS",   "Joitakin isoja lukuja..." },
359     { "NUMBERS",      "luvut" },
360     { "TIME",         "%d riviä (%d päivää) parsittu %d sekunnissa" },
361     { "FOOTER",       "Tilastot on generoinut" },
362     { "C_SMILE",      "on usein iloinen :)" },
363     { "C_FROWN",      "on usein surullinen :(" },
364     { "C_EXCLAM",     "möykkää paljon !" },
365     { "C_QUESTION",   "kyselee liikaa ?" },
366     { "C_ME",         "pitää itsestään" },
367     { "C_TOPIC",      "vaihtaa usein aihetta" },
368     { "C_MODE",       "haluaa elää muuttuvassa maailmassa" },
369     { "C_KICK",       "pitää potkimisesta" },
370     { "C_KICKED",     "tykkää tulla potkituksi" },
371     { "C_URL",        "surffailee liikaa" },
372     { "C_JOIN",       "ei tiedä ollakko vai eikö olla" },
373     { "C_NICK",       "kärsii identiteettiongelmista" },
374     { "C_MONOLOGUE",  "höpöttää paljon itsekseen" }
375   },
376   { /* Italian language */
377     /* contributed by Coviello Giuseppe <giuseppecoviello@tin.it> <http://coviello.altervista.org> */
378     { "Italian",      "it" },
379     { "CHARSET",      "ISO-8859-1" },
380     { "HEADER",       "Statistiche per il canale %s di %s" },
381     { "LEGEND",       "Legenda" },
382     { "LASTDAYS",     "Statistiche degli ultimi giorni" },
383     { "TOPHOURS",     "Statistiche in ore" },
384     { "TOPUSERS",     "Utenti pi&ugrave; attivi" },
385     { "OTHERS",       "Ci sono %d utenti non classificati..." },
386     { "NBLINES",      "righe" },
387     { "NICK",         "nick" },
388     { "AVGLETTERS",   "lettere/righe" },
389     { "HOURS",        "ore" },
390     { "QUOTE",        "messaggio casuale" },
391     { "TOPUSERSTIME", "Utenti più attivi del giorno (divisi per fasce orarie)" },
392     { "RANDTOPICS",   "Alcuni topic" },
393     { "CHANGEDBY",    "cambiato da" },
394     { "NEWTOPIC",     "nuovo topic" },
395     { "RANDURLS",     "ALcuni URL" },
396     { "POSTEDBY",     "postato da" },
397     { "POSTEDURL",    "URL" },
398     { "TOPWORDS",     "Le parole più usate" },
399     { "WORD",         "parola" },
400     { "OCCURRENCES",  "usata" },
401     { "BIGNUMBERS",   "Alcuni numeri ..." },
402     { "NUMBERS",      "numeri" },
403     { "TIME",         "%d righe (%d giorni) esaminate in %d secondi" },
404     { "FOOTER",       "Statistiche generate da" },
405     { "C_SMILE",      "è spesso felice :)" },
406     { "C_FROWN",      "è spesso triste :(" },
407     { "C_EXCLAM",     "esclama molto !" },
408     { "C_QUESTION",   "fa molte domande ?" },
409     { "C_ME",         "ama il comando /me" },
410     { "C_TOPIC",      "cambia spesso il topic" },
411     { "C_MODE",       "cambia spesso i mode" },
412     { "C_KICK",       "ama /kick(are)" },
413     { "C_KICKED",     "è kickato spesso" },
414     { "C_URL",        "posta molti URL" },
415     { "C_JOIN",       "non sa se è ora di andare o restare" },
416     { "C_NICK",       "cambia spesso il nick" },
417     { "C_MONOLOGUE",  "fa molti monologhi" }
418   },
419   { /* Dutch language */
420     /* contributed by Jeroen Ubbink <crasp@blackbyte.nl> */
421     /* updated by Wouter Horré <wouter@ligezin.be> */
422     { "Dutch",        "nl" },
423     { "CHARSET",      "ISO-8859-1" },
424     { "HEADER",       "Statistieken voor %s door %s" },
425     { "LEGEND",       "Legenda" },
426     { "LASTDAYS",     "Statistieken van de laatste dagen" },
427     { "TOPHOURS",     "Statistieken per uur" },
428     { "TOPUSERS",     "Meest actieve mensen" },
429     { "OTHERS",       "Er zijn nog %d mensen die de top niet haalden..." },
430     { "NBLINES",      "regels" },
431     { "NICK",         "nick" },
432     { "AVGLETTERS",   "letters/lijn" },
433     { "HOURS",        "uren" },
434     { "QUOTE",        "Willekeurige regel" },
435     { "TOPUSERSTIME", "Meest actieve mensen per tijdstip per dag" },
436     { "RANDTOPICS",   "Enkele topics" },
437     { "CHANGEDBY",    "gewijzigd door" },
438     { "NEWTOPIC",     "nieuwe topic" },
439     { "RANDURLS",     "Enkele URLs" },
440     { "POSTEDBY",     "Geplaatst door" },
441     { "POSTEDURL",    "URL" },
442     { "TOPWORDS",     "Meest gebruikte woorden" },
443     { "WORD",         "woord" },
444     { "OCCURRENCES",  "aantal" },
445     { "BIGNUMBERS",   "Enkele grote aantallen..." },
446     { "NUMBERS",      "numbers" },
447     { "TIME",         "%d regels (%d dagen) verwerkt in %d seconden" },
448     { "FOOTER",       "Statistieken gegenereerd door" },
449     { "C_SMILE",      "is vaak vrolijk :)" },
450     { "C_FROWN",      "is vaak droevig :(" },
451     { "C_EXCLAM",     "schreeuwt veel !" },
452     { "C_QUESTION",   "stelt veel vragen ?" },
453     { "C_ME",         "vindt /me een leuk commando" },
454     { "C_TOPIC",      "verandert vaak de topic" },
455     { "C_MODE",       "verandert vaak de modes" },
456     { "C_KICK",       "vindt /kick erg leuk" },
457     { "C_KICKED",     "wordt vaak gekickt" },
458     { "C_URL",        "plaatst veel URLs" },
459     { "C_JOIN",       "twijfelt tussen blijven of gaan" },
460     { "C_NICK",       "verandert vaak van nick" },
461     { "C_MONOLOGUE",  "spreekt veel monologen" }
462   },
463   { /* Russian language */
464     /* contributed by kamikaze <kamikaze@rss.lv> */
465     { "Russian",      "ru" },
466     { "CHARSET",      "KOI8-R" },
467     { "HEADER",       "óÔÁÔÉÓÔÉËÁ ÄÌÑ %s ÏÔ %s" },
468     { "LEGEND",       "ïÂÏÚÎÁÞÅÎÉÑ" },
469     { "LASTDAYS",     "óÔÁÔÉÓÔÉËÁ ÐÏÓÌÅÄÎÉÈ ÄÎÅÊ" },
470     { "TOPHOURS",     "ðÏÞÁÓÏ×ÁÑ ÓÔÁÔÉÓÔÉËÁ" },
471     { "TOPUSERS",     "áËÔÉ×ÎÅÊÛÉÅ ÌÀÄÉ" },
472     { "OTHERS",       "ïÓÔÁÌÏÓØ %d ÎÅÐÏÄÓÞÉÔÁÎÙÈ..." },
473     { "NBLINES",      "ÓÔÒÏËÉ" },
474     { "NICK",         "ÎÉË" },
475     { "AVGLETTERS",   "ÂÕË×Ù/ÓÔÒÏËÉ" },
476     { "HOURS",        "ÞÁÓÙ" },
477     { "QUOTE",        "ÓÌÕÞÁÊÎÏÅ ÓÏÏÂÝÅÎÉÅ" },
478     { "TOPUSERSTIME", "áËÔÉ×ÎÅÊÛÉÅ ÌÀÄÉ ÐÏ ×ÒÅÍÅÎÉ ÄÎÑ" },
479     { "RANDTOPICS",   "îÅÓËÏÌØËÏ ÔÏÐÉËÏ×" },
480     { "CHANGEDBY",    "ÉÚÍÅΣÎ" },
481     { "NEWTOPIC",     "ÎÏ×ÙÊ ÔÏÐÉË" },
482     { "RANDURLS",     "îÅÓËÏÌØËÏ URLÏ×" },
483     { "POSTEDBY",     "ÏÐÕÂÌÉËÏ×ÁÌ" },
484     { "POSTEDURL",    "URL" },
485     { "TOPWORDS",     "þÁÓÔÏ ÉÓÐÏÌØÚÕÅÍÙÅ ÓÌÏ×Á" },
486     { "WORD",         "ÓÌÏ×Ï" },
487     { "OCCURRENCES",  "ÐÒÏÉÛÅÓÔ×ÉÑ" },
488     { "BIGNUMBERS",   "îÅÓËÏÌØËÏ ÂÏÌØÛÉÈ ÞÉÓÅÌ..." },
489     { "NUMBERS",      "ÞÉÓÌÁ" },
490     { "TIME",         "%d ÓÔÒÏË (%d ÄÎÅÊ) ÏÂÒÁÂÏÔÁÎÏ ÚÁ %d ÓÅËÕÎÄ" },
491     { "FOOTER",       "óÔÁÔÉÓÔÉËÁ ÓÇÅÎÅÒÉÒÏ×ÁÎÁ" },
492     { "C_SMILE",      "ÞÁÓÔÏ ÓÞÁÓÌÉ× :)" },
493     { "C_FROWN",      "ÞÁÓÔÏ ÎÅÓÞÁÓÔÅΠ:(" },
494     { "C_EXCLAM",     "ÍÎÏÇÏ ×ÏÓËÌÉÃÁÅÔ !" },
495     { "C_QUESTION",   "ÚÁÄÁ£Ô ÍÎÏÇÏ ×ÏÐÒÏÓÏ× ?" },
496     { "C_ME",         "ÌÀÂÉÔ /me command" },
497     { "C_TOPIC",      "ÞÁÓÔÏ ÍÅÎÑÅÔ ÔÏÐÉË" },
498     { "C_MODE",       "ÞÁÓÔÏ ÍÅÎÑÅÔ ÒÅÖÉÍÙ" },
499     { "C_KICK",       "ÌÀÂÉÔ /kick" },
500     { "C_KICKED",     "ÞÁÓÔÏ ×ÙËÉÄÙ×ÁÀÔ" },
501     { "C_URL",        "ÐÕÂÌÉËÕÅÔ ÍÎÏÇÏ URLÏ×" },
502     { "C_JOIN",       "ÎÅ ÚÎÁÅÔ - ÏÓÔÁÔØÓÑ ÉÌÉ ÕÊÔÉ" },
503     { "C_NICK",       "ÞÁÓÔÏ ÍÅÎÑÅÔ Ó×ÏÊ ÎÉË" },
504     { "C_MONOLOGUE",  "éÓÐÏÌØÚÕÅÔ ÍÎÏÇÏ ÍÏÎÏÌÏÇÏ×" }
505   },
506   { /* Estonian language */
507     /* contributed by Martin Vool <mardicas@hot.ee> */
508     { "Estonian",     "et" },
509     { "CHARSET",      "ISO-8859-4" },
510     { "HEADER",       "Statistika kanalile %s on koostanud %s" },
511     { "LEGEND",       "Legend" },
512     { "LASTDAYS",     "Viimaste päevade statistika" },
513     { "TOPHOURS",     "Tunni statistika" },
514     { "TOPUSERS",     "Kõige aktiivsemad inimesed" },
515     { "OTHERS",       "%d inimest on rääkinud" },
516     { "NBLINES",      "rida" },
517     { "NICK",         "nimi" },
518     { "AVGLETTERS",   "tähte/rida" },
519     { "HOURS",        "kell" },
520     { "QUOTE",        "suvaline teade" },
521     { "TOPUSERSTIME", "Kõige aktiivsemad inimesed päeva aja järgi" },
522     { "RANDTOPICS",   "Mõned topicud" },
523     { "CHANGEDBY",    "muutis" },
524     { "NEWTOPIC",     "topicud" },
525     { "RANDURLS",     "Mõned aadressid" },
526     { "POSTEDBY",     "postitas" },
527     { "POSTEDURL",    "URL" },
528     { "TOPWORDS",     "Enim kasutatud sõnad" },
529     { "WORD",         "sõna" },
530     { "OCCURRENCES",  "sagedus" },
531     { "BIGNUMBERS",   "Mõned suured numbrid" },
532     { "NUMBERS",      "iseloom" },
533     { "TIME",         "%d rida (%d päeva) on möödunud %d sekundit" },
534     { "FOOTER",       "Statistika on koostanud" },
535     { "C_SMILE",      "on tihti õnnelik :)" },
536     { "C_FROWN",      "on tihti kurb :(" },
537     { "C_EXCLAM",     "põrnitseb palju" },
538     { "C_QUESTION",   "küsib palju küsimusi" },
539     { "C_ME",         "/me manjakk" },
540     { "C_TOPIC",      "vahetab tihti topicut" },
541     { "C_MODE",       "vahetab tihti modesid" },
542     { "C_KICK",       "kickib palju" },
543     { "C_KICKED",     "saab tihti kicke" },
544     { "C_URL",        "reklaamib palju" },
545     { "C_JOIN",       "sõelub sisse ja välja" },
546     { "C_NICK",       "vahetab pidevalt nime" },
547     { "C_MONOLOGUE",  "räägib palju monolooge" }
548   }
549 };
550
551 int language=0; /* default to english */
552
553 char *L(char *key)
554 {
555   int i;
556   for (i=1;i<=NBKEYS;i++) if (strcmp(key,keys[language][i][0])==0) return(keys[language][i][1]);
557   fprintf(stderr,"unknown language key: %s\n",key);
558   return("");
559 }
560
561 /* Variables */
562
563 int debug=1; /* 0 = none ; 1 = normal ; 2 = verbose */
564 char channel[MAXLINELENGTH]="set_channel_in_config_file";
565 char maintainer[MAXLINELENGTH]="set_maintainer_in_config_file";
566 char theme[MAXLINELENGTH]="default,biseau,blue,dark,damier,grayscale,namour,niflheim,pisg,zeduel,zerezo";
567 int refresh_time=0; /* 0 = disabled */
568 int w3c_link=1; /* 0 = disabled */
569 int logo=1; /* 0 = disabled */
570 char header[MAXLINELENGTH]="none";
571 char footer[MAXLINELENGTH]="none";
572 int totallines=0;
573 time_t debut;
574 int top_words=1; /* 0 = disabled */
575 int ranking=0; /* 0 = lines ; 1 = words ; 2 = letters */
576 int quarter=0; /* 1 = enabled */
577 int photo_size=60;
578
579 struct user
580 {
581   char nick[MAXNICKLENGTH];
582   int lines;
583   int words;
584   int letters;
585   int hours[4];
586   char quote[MAXQUOTELENGTH+1];
587   int counters[NBCOUNTERS];
588   char *photo;
589   int temp;
590 } *users;
591 int nbusers=0;
592 int maxusers=BASEUSERS;
593
594 struct
595 {
596   char nick[MAXNICKLENGTH];
597   char url[MAXLINELENGTH];
598   char shorturl[MAXQUOTELENGTH+1];
599 } urls[NBURLS];
600 int nburls=0;
601
602 struct
603
604   char nick[MAXNICKLENGTH];
605   char topic[MAXQUOTELENGTH+1];
606 } topics[NBTOPICS];
607 int nbtopics=0;
608
609 struct
610 {
611   int lines;
612   int hours[4];
613 } lastdays[31];
614 int days=0;
615 char currday[16];
616
617 int hours[24*4];
618 int lines=0;
619
620 struct letter
621 {
622   int nb;
623   struct letter *next[26];
624 } words;
625
626 struct
627 {
628   int nb;
629   char word[MAXLINELENGTH];
630 } topwords[NBWORDS];
631
632 struct rusletter
633 {
634   int nb;
635   struct rusletter *next[33];
636 } ruswords;
637
638 #define isletter(c) (((c>='a')&&(c<='z'))||((c>='A')&&(c<='Z')))
639 #define lowercase(c) (((c>='A')&&(c<='Z'))?c-'A'+'a':c)
640 //#define lowercase(c) (c | 0x20)
641 #define isrusletter(c) (memchr(koi,c,66)==NULL?0:1)
642
643 const char koi[] = {
644 193,194,215,199,196,197,163,214,218,201,202,203,204,205,206,207,208,210,
645 211,212,213,198,200,195,222,219,221,216,223,217,220,192,209,
646 225,226,247,231,228,229,179,246,250,233,234,235,236,237,238,239,240,242,
647 243,244,245,230,232,227,254,251,253,248,255,249,252,224,241
648 };
649 int lowruscase(char c)
650 {
651   char *ctmp_p;
652   int ch=0;
653   if (memchr(koi,c,66)==NULL) return koi[0];
654   ch=strlen(koi)-strlen(memchr(koi,c,66));
655   if (ch>33) return ch-33; else return ch;
656 }
657 /* cp1251 for encoding into koi8-r
658 const char win[] = {
659 224,225,226,227,228,229,184,230,231,232,233,234,235,236,237,238,239,240,
660 241,242,243,244,245,246,247,248,249,252,250,251,253,254,255,
661 192,193,194,195,196,197,168,198,199,200,201,202,203,204,205,206,207,208,
662 209,210,211,212,213,214,215,216,217,220,218,219,221,222,223
663 };*/
664
665
666
667 int findruswords(char *message)
668 {
669   int i,c,n=0;
670   //char *tmp_p;
671   struct rusletter *pos,*tmp;
672   for (;;)
673   {
674     while (!isrusletter(*message)) if (*message=='\0') return n; else message++;
675     pos=&ruswords;
676     while (isrusletter(*message))
677     {
678       c=lowruscase(*message);
679       /*tmp_p=memchr(koi,message[0],33);
680       if (tmp_p==NULL) return n;
681       c=strlen(koi)-strlen(tmp_p);*/
682       if (pos->next[(int)c]==NULL)
683       {
684         tmp=malloc(sizeof(struct rusletter));
685         if (tmp==NULL)
686         {
687           fprintf(stderr, "findruswords(): malloc failure\n");
688           exit(1);
689         }
690         tmp->nb=0;
691         for (i=0;i<33;i++) tmp->next[i]=NULL;
692         pos->next[(int)c]=tmp;
693       }
694       pos=pos->next[(int)c];
695       message++; 
696     }
697     pos->nb++;
698     n++;
699   }
700   return n;
701 }
702
703
704 void freeruswords(struct rusletter *pos)
705 {
706   int i;
707   for (i=0;i<33;i++) if (pos->next[i]!=NULL)
708   {
709     freeruswords(pos->next[i]);
710     free(pos->next[i]);
711     (*pos).next[i]=NULL;
712   }
713 }
714
715 int findwords(char *message)
716 {
717   int i,c,n=0;
718   struct letter *pos,*tmp;
719   for (;;)
720   {
721     while (!isletter(*message)) if (*message=='\0') return n; else message++;
722     pos=&words;
723     while (isletter(*message))
724     {
725       c=lowercase(*message)-'a';
726       if (pos->next[(int)c]==NULL)
727       {
728         tmp=malloc(sizeof(struct letter));
729         if (tmp==NULL)
730         {
731           fprintf(stderr, "findwords(): malloc failure\n");
732           exit(1);
733         }
734         tmp->nb=0;
735         for (i=0;i<26;i++) tmp->next[i]=NULL;
736         pos->next[(int)c]=tmp;
737       }
738       pos=pos->next[(int)c];
739       message++; 
740     }
741     pos->nb++;
742     n++;
743   }
744   return n;
745 }
746
747 char tempword[MAXLINELENGTH];
748 void bestwords(struct letter pos,int cur)
749 {
750   int i,j;
751   if ((cur>=MINWORDLENGTH)&&(pos.nb>topwords[NBWORDS-1].nb))
752   {
753     for (i=0;pos.nb<topwords[i].nb;i++);
754     for (j=NBWORDS-1;j>i;j--)
755     {
756       topwords[j].nb=topwords[j-1].nb;
757       strcpy(topwords[j].word,topwords[j-1].word);
758     }
759     topwords[i].nb=pos.nb;
760     strcpy(topwords[i].word,tempword);
761   }
762   for (i=0;i<26;i++) if (pos.next[i]!=NULL)
763   {
764     tempword[cur]='a'+i;
765     bestwords(*(pos.next[i]),cur+1);
766   }
767   tempword[cur]='\0';
768 }
769
770 void bestruswords(struct rusletter pos,int cur)
771 {
772   int i,j;
773   if ((cur>=MINWORDLENGTH)&&(pos.nb>topwords[NBWORDS-1].nb))
774   {
775     for (i=0;pos.nb<topwords[i].nb;i++);
776     for (j=NBWORDS-1;j>i;j--)
777     {
778       topwords[j].nb=topwords[j-1].nb;
779       strcpy(topwords[j].word,topwords[j-1].word);
780     }
781     topwords[i].nb=pos.nb;
782     strcpy(topwords[i].word,tempword);
783   }
784   for (i=0;i<33;i++) if (pos.next[i]!=NULL)
785   {
786     tempword[cur]=koi[i];
787     bestruswords(*(pos.next[i]),cur+1);
788   }
789   tempword[cur]='\0';
790 }
791
792 void freewords(struct letter *pos)
793 {
794   int i;
795   for (i=0;i<26;i++) if (pos->next[i]!=NULL)
796   {
797     freewords(pos->next[i]);
798     free(pos->next[i]);
799     (*pos).next[i]=NULL;
800   }
801 }
802
803 void printhtml(FILE *fic,char *string) /* replace < and > by &lt; and &gt; */
804 {
805   while (*string!='\0')
806   {
807     switch (*string)
808     {
809       case '<':fprintf(fic,"&lt;"); break;
810       case '>':fprintf(fic,"&gt;"); break;
811       case '&':fprintf(fic,"&amp;"); break;
812       default:fprintf(fic,"%c",*string); break;
813     }
814     string++;
815   }
816   return;
817 }
818
819 int dichotomic(char *nick)
820 {
821   int i,j,start=0,end=nbusers-1,middle;
822   while (start<=end)
823   {
824     middle=(start+end)/2;
825     if (strcmp(nick,users[middle].nick)>0) start=middle+1; else end=middle-1;
826   }
827   if (strcmp(nick,users[start].nick)!=0)
828   {
829     nbusers++;
830     if (nbusers>=maxusers)
831     {
832       maxusers+=BASEUSERS;
833       if (debug==2) fprintf(stderr,"allocating more users : %d\n",maxusers);
834       if ((users=realloc(users,maxusers*sizeof(struct user)))==NULL) { fprintf(stderr,"too many users : unable to realloc memory\n"); exit(1); }
835     }
836     for (i=nbusers-1;i>start;i--)
837     {
838       strcpy(users[i].nick,users[i-1].nick);
839       users[i].lines=users[i-1].lines;
840       users[i].words=users[i-1].words;
841       users[i].letters=users[i-1].letters;
842       for (j=0;j<4;j++) users[i].hours[j]=users[i-1].hours[j];
843       strcpy(users[i].quote,users[i-1].quote);
844       for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=users[i-1].counters[j];
845       users[i].temp=users[i-1].temp;
846       users[i].photo=users[i-1].photo;
847     }
848     strcpy(users[start].nick,nick);
849     users[start].lines=0;
850     users[start].words=0;
851     users[start].letters=0;
852     for (j=0;j<4;j++) users[start].hours[j]=0;
853     users[start].quote[0]='\0';
854     for (j=0;j<NBCOUNTERS;j++) users[start].counters[j]=0;
855     users[start].temp=0;
856     users[start].photo=NULL;
857   }
858   return(start);
859 }
860
861 void day_changed(char* date)
862 {
863   int i,j;
864   char newday[16];
865
866   memcpy(newday, date, 11);
867   if (date[13]==':')
868     memcpy(newday+11, date+20, 4);
869   else
870     memcpy(newday+11, date+11, 4);
871   newday[15]=0;
872   if (memcmp(currday, newday, 15)!=0)
873   {
874     /* we do not have a "current" day yet? */
875     if (currday[0]!=0)
876     {
877       for (i=30;i>0;i--)
878       {
879         lastdays[i].lines=lastdays[i-1].lines;
880         for (j=0;j<4;j++) lastdays[i].hours[j]=lastdays[i-1].hours[j];
881       }
882       lastdays[0].lines=0;
883       for (j=0;j<4;j++) lastdays[0].hours[j]=0;
884       days++;
885     }
886     memcpy(currday, newday, 15);
887     if (debug==2)
888       fprintf(stderr, "day %d changed to: %s\n", days, currday);
889   } else {
890     if (debug==2)
891       fprintf(stderr, "but day did not change\n");
892   }
893 }
894
895 void parse_log(char *logfile)
896 {
897   FILE *fic;
898   char line[MAXLINELENGTH];
899   int pos;
900   int i,j;
901   char *nick,*message;
902   int nickstart;
903   int mononick=-1,monolines=0;
904   int temp,hour;
905   int timelen;
906
907   if ((fic=fopen(logfile,"rt"))==NULL) { fprintf(stderr,"can't open log file \"%s\"\n",logfile); exit(1); }
908   if (debug) printf("working on %s : ",channel);
909   while (fgets(line,MAXLINELENGTH,fic)!=NULL)
910   {
911     /* remove \n */
912     for (i=0;line[i]!=0 && i<MAXLINELENGTH-1;i++);
913     if (i>=MAXLINELENGTH-1) { 
914       if(debug){
915         fprintf(stderr,"line %d is too long, skipping\n",totallines+1); 
916       }
917       continue; 
918     }
919     if (i<8) {
920       if(debug) {
921         fprintf(stderr, "line %d is too short to be valid, skipping\n",totallines+1);
922       }
923       continue;
924     }
925     line[i-1]='\0';
926     pos=0;
927     totallines++;
928     if (totallines%10000==0 && debug) { printf("."); fflush(stdout); }
929     if (strncmp("--- Log opened",line,14)==0) /* --- Log opened Wed May 01 00:00 2002 */
930     {
931       if (debug==2)
932         fprintf(stderr, "log %s opened, ", logfile);
933       day_changed(line+15);
934     }
935     if (strncmp("--- Day changed",line,15)==0) /* --- Day changed Wed May 01 2002 */
936     {
937       if (debug==2)
938         fprintf(stderr, "within log file, ");
939       day_changed(line+16);
940     }
941     else
942     {
943       /* timelen is number of characters occupied by time 00:00.. plus any space */
944       timelen = 5;
945       if (line[timelen] == ':' && isdigit(line[timelen+1]) && isdigit(line[timelen+2]))
946           timelen += 3;
947       if (line[timelen] == ' ')
948           timelen++;
949       if (strncmp("-!- mode/",&line[timelen],9)==0) /* 00:00 -!- mode/#channel [...] by (Nick, Nick2, )Nick3 */
950       {
951         for (i=strlen(line);line[i]!=' ';i--);
952         nick=&line[i+1];
953         users[dichotomic(nick)].counters[D_MODE]++;
954       }
955       else if (strncmp("-!-",&line[timelen],3)==0) /* 00:00 -!- Nick something... */
956       {
957         for (i=10;line[i]!=' ' && i <= 10 + MAXNICKLENGTH;i++);
958         if(i > 10 + MAXNICKLENGTH) {
959           if(debug) {
960             fprintf(stderr,"nick on line %d is too long, skipping line\n",totallines); 
961           }
962           continue;
963         }
964         line[i]='\0';
965         nick=&line[timelen+4];
966         message=&line[i+1];
967         if (strncmp("changed the topic of",message,20)==0) /* 00:00 -!- Nick changed the topic of #channel to: new topic */
968         {
969           users[dichotomic(nick)].counters[D_TOPIC]++;
970           for (i=21;message[i]!=':';i++);
971           message=&message[i+2];
972           nbtopics++;
973           if ((nbtopics<=NBTOPICS) || (rand()%(nbtopics/NBTOPICS)==0))
974           {
975             temp=nbtopics<=NBTOPICS?nbtopics-1:rand()%NBTOPICS;
976             strcpy(topics[temp].nick,nick);
977             strncpy(topics[temp].topic,message,MAXQUOTELENGTH);
978           }
979         }
980         else if (strncmp("was kicked from",message,15)==0) /* 00:00 -!- Nick was kicked from #channel by Nick [Reason] */
981         {
982           users[dichotomic(nick)].counters[D_KICKED]++;
983           for (i=16;message[i]!=' ';i++);
984           message=&message[i+4];
985           for (i=0;message[i]!=' ';i++);
986           message[i]='\0';
987           users[dichotomic(message)].counters[D_KICK]++;
988         }
989         else if (strncmp("is now known as",message,15)==0) /* 00:00 -!- Nick is now known as Nick */
990           users[dichotomic(nick)].counters[D_NICK]++;
991         else if (message[0]=='[') /* 00:00 -!- Nick [user@host] something... */
992         {
993           for (i=0;message[i]!=']';i++);
994           message=&message[i+2];
995           if (strncmp("has joined",message,10)==0) /* 00:00 -!- Nick [user@host] has joined #channel */
996             users[dichotomic(nick)].counters[D_JOIN]++;
997           else if (strncmp("has quit",message,8)==0); /* 00:00 -!- Nick [user@host] has quit [Reason] */
998           else if (strncmp("has left",message,8)==0); /* 00:00 -!- Nick [user@host] has left #channel [Reason] */
999           else;
1000         }
1001       }
1002       else if ((line[timelen]=='<') || (line[timelen+1]=='*'))
1003       {
1004         line[2]='\0';
1005         hour=atoi(line);
1006         if (line[timelen+1]=='*') /* 00:00  * Nick the message */
1007         {
1008           for (i=timelen+3;line[i]!=' ' && i <= timelen+3+MAXNICKLENGTH;i++);
1009           if(i > timelen+3+MAXNICKLENGTH) {
1010             if(debug) {
1011               fprintf(stderr,"nick on line %d is too long, skipping line\n",totallines); 
1012             }
1013             continue; 
1014           }
1015           nick=&line[timelen+3];
1016           message=&line[i+1];
1017         }
1018         else if (line[timelen+1]=='>') /* 00:00 <>>>?Nick<<<> the personal message */
1019                                /* 00:00 <>>?Nick<<> the personal message */
1020         {
1021           for (i=timelen+4;line[i]!='<' && i <= timelen+4+MAXNICKLENGTH;i++);
1022            if(i > timelen+4+MAXNICKLENGTH) { 
1023             if(debug) {
1024               fprintf(stderr,"nick on line %d is too long, skipping line\n",totallines); 
1025             }
1026             continue; 
1027           }
1028           nick=&line[timelen+4];
1029           if (line[timelen+3]=='>') nick++;
1030           message=&line[i+5];
1031         }
1032         else /* 00:00 <?Nick> the message */
1033         {
1034
1035           /* 
1036            * Irssi doesn't log channel mode with show_nickmode = OFF    
1037            * the following covers op, half-op, voice and show_nickmode_empty                 
1038            */
1039           switch (line[timelen+1])
1040           {
1041             case '@':
1042             case '%':
1043             case '+':
1044             case ' ': 
1045               nickstart = timelen+2; 
1046               break;
1047             default:
1048               nickstart = timelen+1;
1049               break;
1050           }
1051             
1052           for (i=nickstart;line[i]!='>' && i <= nickstart + MAXNICKLENGTH;i++);
1053           if(i > nickstart + MAXNICKLENGTH) { 
1054             if(debug) {
1055               fprintf(stderr,"nick on line %d is too long, skipping line\n",totallines); 
1056             }
1057             continue; 
1058           }
1059           nick=&line[nickstart];
1060           message=&line[i+2];
1061         }
1062         /* remove identified character from nick (invalid nick character anyway) */
1063         if (nick[0] == '+')
1064           fprintf(stderr, "nick starts with +! %s\n", nick);
1065         if (line[i-1] == '+' || line[i-1] == '*')
1066           i--;
1067         line[i]='\0';
1068         i=dichotomic(nick);
1069         if (line[timelen+1]=='*') users[i].counters[D_ME]++;
1070         if (i==mononick)
1071         {
1072           monolines++;
1073           if (monolines==5) users[i].counters[D_MONOLOGUE]++;
1074         }
1075         else
1076         {
1077           mononick=i;
1078           monolines=1;
1079         }
1080         j=strlen(message);
1081         users[i].lines++;
1082         if (top_words || ranking==1) 
1083         {
1084           if (L("CHARSET")=="KOI8-R") users[i].words+=findwords(message)+findruswords(message);
1085           else users[i].words+=findwords(message);
1086         }
1087         users[i].letters+=j;
1088         users[i].hours[hour/6]++;
1089         lastdays[0].lines++;
1090         lastdays[0].hours[hour/6]++;
1091         lines++;
1092         if (quarter)
1093         {
1094           line[5]='\0';
1095           hour=hour*4+atoi(&line[3])/15;
1096         }
1097         hours[hour]++;
1098         if (message[j-1]=='?') users[i].counters[D_QUESTION]++;
1099         else if (message[j-1]=='!') users[i].counters[D_EXCLAM]++;
1100         else if ((message[j-3]==' ')&&(message[j-2]==':'))
1101         {
1102           if (message[j-1]==')') users[i].counters[D_SMILE]++;
1103           else if (message[j-1]=='(') users[i].counters[D_FROWN]++;
1104         }
1105         if (rand()%users[i].lines==0) strncpy(users[i].quote,message,MAXQUOTELENGTH);
1106         if (strncmp("http://",message,7)==0)
1107         {
1108           users[i].counters[D_URL]++;
1109           for (i=0;(message[i]!=' ') && (i<strlen(message));i++);
1110           message[i]='\0';
1111           nburls++;
1112           if ((nburls<=NBURLS) || (rand()%(nburls/NBURLS)==0))
1113           {
1114             temp=nburls<=NBURLS?nburls-1:rand()%NBURLS;
1115             strcpy(urls[temp].nick,nick);
1116             strcpy(urls[temp].url,message);
1117             strncpy(urls[temp].shorturl,message,MAXQUOTELENGTH);
1118           }
1119         }
1120       }
1121     }
1122     pos=0;
1123   }
1124   fclose(fic);
1125   if (debug) printf(" done\n");
1126 }
1127
1128 #ifndef __WIN32__
1129 void parse_nick(char *nickfile)
1130 {
1131   FILE *fic;
1132   int i,j;
1133   regex_t preg;
1134   char line[MAXLINELENGTH];
1135   int user;
1136   
1137   for (i=0;i<nbusers;i++) users[i].temp=users[i].lines;
1138   if ((fic=fopen(nickfile,"rt"))==NULL) { fprintf(stderr,"can't open nick file \"%s\"\n",nickfile); exit(1); }
1139   while (fscanf(fic,"%s",line)==1)
1140   {
1141     user=dichotomic(line);
1142     fscanf(fic,"%s",line);
1143     if (regcomp(&preg,line,0)!=0) { fprintf(stderr,"error in nick file"); exit(1); }
1144     for (i=0;i<nbusers;i++) if ((i!=user) && (regexec(&preg,users[i].nick,0,0,0)==0) && (users[i].lines>=0))
1145     {
1146       if (users[i].temp>users[user].temp) /* for nick alias, keep the random quote of the most used nick */
1147       {
1148         strcpy(users[user].quote,users[i].quote);
1149         users[user].temp=users[i].temp;
1150       }
1151       users[user].lines+=users[i].lines;
1152       users[user].words+=users[i].words;
1153       users[user].letters+=users[i].letters;
1154       for (j=0;j<4;j++) users[user].hours[j]+=users[i].hours[j];
1155       for (j=0;j<NBCOUNTERS;j++) users[user].counters[j]+=users[i].counters[j];
1156       /* "remove" old user */
1157       users[i].lines=-1;
1158       users[i].words=-1;
1159       users[i].letters=-1;
1160       for (j=0;j<4;j++) users[i].hours[j]=-1;
1161       for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=-1;
1162     }
1163     regfree(&preg);
1164   }
1165   fclose(fic);
1166   /* "remove" the ignored nicks */
1167   i=dichotomic("<NULL>");
1168   users[i].lines=-1;
1169   users[i].words=-1;
1170   users[i].letters=-1;
1171   for (j=0;j<4;j++) users[i].hours[j]=-1;
1172   for (j=0;j<NBCOUNTERS;j++) users[i].counters[j]=-1;
1173 }
1174 #endif
1175
1176 void parse_photo(char *photofile)
1177 {
1178   FILE *fic;
1179   char line[MAXLINELENGTH];
1180   int user;
1181   
1182   if ((fic=fopen(photofile,"rt"))==NULL) { fprintf(stderr,"can't open photo file \"%s\"\n",photofile); exit(1); }
1183   while (fscanf(fic,"%s",line)==1)
1184   {
1185     user=dichotomic(line);
1186     fscanf(fic,"%s",line);
1187     users[user].photo=malloc(strlen(line)+1);
1188     strcpy(users[user].photo,line);
1189   }
1190   fclose(fic);
1191 }
1192
1193 void gen_xhtml(char *xhtmlfile)
1194 {
1195   FILE *fic;
1196   FILE *sfic;
1197   int i,j,k;
1198   int user,max,temp;
1199   char line[MAXLINELENGTH];
1200   char *subtheme;
1201   int photos=0;
1202   
1203   for (i=0;i<nbusers;i++) if (users[i].photo!=NULL) photos=1;
1204   
1205   if ((fic=fopen(xhtmlfile,"wt"))==NULL) { fprintf(stderr,"can't open xhtml file \"%s\"\n",xhtmlfile); exit(1); }
1206   
1207   /* header */
1208   if (strcmp("none",header)==0)
1209   {
1210     fprintf(fic,"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n");
1211     fprintf(fic,"<!-- Generated by irssistats %s : %s -->\n\n",VERSION,URL);
1212     fprintf(fic,"<html>\n\n<head>\n<title>");
1213     fprintf(fic,L("HEADER"),channel,maintainer);
1214     fprintf(fic,"</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" />\n",L("CHARSET"));
1215     if (refresh_time)
1216       fprintf(fic,"<meta http-equiv=\"Refresh\" content=\"%d\" />\n",refresh_time);
1217     subtheme=strtok(theme,",");
1218     fprintf(fic,"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s.css\" title=\"%s\" />\n",subtheme,subtheme);
1219     while ((subtheme=strtok(NULL,","))!=NULL)
1220       fprintf(fic,"<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"%s.css\" title=\"%s\" />\n",subtheme,subtheme);
1221     fprintf(fic,"</head>\n\n");
1222     fprintf(fic,"<body>\n\n");
1223   }
1224   else
1225   {
1226     if ((sfic=fopen(header,"rt"))==NULL) { fprintf(stderr,"can't open header file \"%s\"\n",header); exit(1); }
1227     while ((temp=fread(line,1,MAXLINELENGTH,sfic))) fwrite(line,temp,1,fic);
1228     fclose(sfic);
1229   }
1230   fprintf(fic,"<div id=\"irssistats\">\n\n<div id=\"irssistats_header\">\n<h1>");
1231   fprintf(fic,L("HEADER"),channel,maintainer);
1232   fprintf(fic,"</h1>\n<p>\n%s</p>\n</div>\n\n",ctime(&debut));
1233
1234   /* legend */
1235   fprintf(fic,"<div id=\"irssistats_legend\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("LEGEND"));
1236   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);
1237   fprintf(fic,"</tr>\n</table>\n</div>\n\n");
1238   
1239   /* last days */
1240   fprintf(fic,"<div id=\"irssistats_lastdays\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("LASTDAYS"));
1241   max=-1;
1242   for (i=30;i>=0;i--) if (lastdays[i].lines>max) max=lastdays[i].lines;
1243   for (i=30;i>=0;i--)
1244   {
1245     fprintf(fic,"<td align=\"center\" valign=\"bottom\"><small>%d</small>",lastdays[i].lines);
1246     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);
1247     fprintf(fic,"</td>\n");
1248   }
1249   fprintf(fic,"</tr>\n<tr>\n");
1250   for (i=30;i>=0;i--)
1251     fprintf(fic,"<th>%d</th>\n",i);
1252   fprintf(fic,"</tr>\n</table>\n</div>\n\n");
1253   
1254   /* top hours */
1255   fprintf(fic,"<div id=\"irssistats_tophours\">\n<h2>%s</h2>\n<table>\n<tr>\n",L("TOPHOURS"));
1256   max=-1;
1257   for (i=0;i<24*4;i++) if (hours[i]>max) max=hours[i];
1258   if (quarter) for (i=0;i<24*4;i++)
1259   {
1260     fprintf(fic,"<td align=\"center\" valign=\"bottom\">");
1261     if (hours[i]!=0) fprintf(fic,"<div class=\"v%d\" style=\"width:4px;height:%dpx\"></div>",i/4/6+1,150*hours[i]/max);
1262     fprintf(fic,"</td>\n");
1263   }
1264   else for (i=0;i<24;i++)
1265   {
1266     fprintf(fic,"<td align=\"center\" valign=\"bottom\"><small>%.1f%%</small>",lines!=0?(float)100*hours[i]/lines:0);
1267     if (hours[i]!=0) fprintf(fic,"<div class=\"v%d\" style=\"height:%dpx\"></div>",i/6+1,150*hours[i]/max);
1268     fprintf(fic,"</td>\n");
1269   }
1270   fprintf(fic,"</tr>\n<tr>\n");
1271   for (i=0;i<24;i++)
1272     if (quarter) fprintf(fic,"<th colspan=\"4\">%d</th>\n",i);
1273     else fprintf(fic,"<th>%d</th>\n",i);
1274   fprintf(fic,"</tr>\n</table>\n</div>\n\n");
1275   
1276   /* top users */
1277   fprintf(fic,"<div id=\"irssistats_topusers\">\n<h2>%s</h2>\n",L("TOPUSERS"));
1278   switch (ranking)
1279   {
1280     case 0:
1281       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"));
1282       break;
1283     default:
1284       /* "letters" and "words" ranking are not yet translated so we use the generic word "rank" ... */
1285       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"));
1286       break;
1287   }
1288   if (photos) fprintf(fic,"<th></th>");
1289   fprintf(fic,"</tr>");
1290   for (i=1;i<=NBUSERS;i++)
1291   {
1292     user=-1;
1293     max=0;
1294     switch (ranking)
1295     {
1296       case 0:
1297         for (j=0;j<nbusers;j++) if (users[j].lines>max) max=users[user=j].lines;
1298         break;
1299       case 1:
1300         for (j=0;j<nbusers;j++) if (users[j].words>max) max=users[user=j].words;
1301         break;
1302       case 2:
1303         for (j=0;j<nbusers;j++) if (users[j].letters>max) max=users[user=j].letters;
1304         break;
1305     }
1306     if (user!=-1)
1307     {
1308       switch (ranking)
1309       {
1310         case 0:
1311           fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].lines);
1312           break;
1313         case 1:
1314           fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].words);
1315           break;
1316         case 2:
1317           fprintf(fic,"<tr><td>%d</td><td>%s</td><td>%d</td><td class=\"oneline\">",i,users[user].nick,users[user].letters);
1318           break;
1319       }
1320       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);
1321       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);
1322       printhtml(fic,users[user].quote);
1323       fprintf(fic,"\"</td>");
1324       if (photos && users[user].photo!=NULL)
1325       {
1326         if (photo_size)
1327           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);
1328         else
1329           fprintf(fic,"<td class=\"tdphoto\"><img src=\"%s\" class=\"imgphoto\" alt=\"\" /></td>",users[user].photo);
1330       }
1331       fprintf(fic,"</tr>\n");
1332       users[user].lines=-1;
1333       users[user].words=-1;
1334       users[user].letters=-1;
1335     }    
1336   }
1337   fprintf(fic,"</table>\n");
1338   temp=0;
1339   for (i=0;i<=nbusers;i++) if (users[i].lines>=0) temp++;
1340   if (temp>0)
1341   {
1342     fprintf(fic,"<p>");
1343     fprintf(fic,L("OTHERS"),temp);
1344     fprintf(fic,"</p>\n");
1345   }
1346   fprintf(fic,"</div>\n\n");
1347   
1348   /* top users by time */
1349   fprintf(fic,"<div id=\"irssistats_topuserstime\">\n<h2>%s</h2>\n",L("TOPUSERSTIME"));
1350   fprintf(fic,"<table>\n<tr><th></th>");
1351   for (i=0;i<4;i++) fprintf(fic,"<th colspan=\"2\">%s %d-%d</th>",L("HOURS"),i*6,i*6+5);
1352   fprintf(fic,"</tr>\n");
1353   for (i=1;i<=NBUSERSTIME;i++)
1354   {
1355     fprintf(fic,"<tr><td>%d</td>",i);
1356     for (j=0;j<4;j++)
1357     {
1358       user=-1;
1359       max=0;
1360       for (k=0;k<nbusers;k++) if (users[k].hours[j]>max) max=users[user=k].hours[j];
1361       if (user!=-1)
1362       {
1363         fprintf(fic,"<td>%s</td><td>%d</td>",users[user].nick,users[user].hours[j]);
1364         users[user].hours[j]=-1;
1365       }
1366       else fprintf(fic,"<td></td><td></td>");
1367     }
1368     fprintf(fic,"</tr>\n");
1369   }
1370   fprintf(fic,"</table>\n</div>\n\n");
1371
1372   /* random topics */
1373   fprintf(fic,"<div id=\"irssistats_randtopics\">\n<h2>%s</h2>\n",L("RANDTOPICS"));
1374   fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th></tr>\n",L("CHANGEDBY"),L("NEWTOPIC"));
1375   for (i=nbtopics<NBTOPICS?nbtopics-1:NBTOPICS-1;i>=0;i--)
1376   {
1377     fprintf(fic,"<tr><td>%s</td><td>\"",topics[i].nick);
1378     printhtml(fic,topics[i].topic);
1379     fprintf(fic,"\"</td></tr>\n");
1380   }
1381   fprintf(fic,"</table>\n</div>\n\n");
1382   
1383   /* random urls */
1384   fprintf(fic,"<div id=\"irssistats_randurls\">\n<h2>%s</h2>\n",L("RANDURLS"));
1385   fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th></tr>\n",L("POSTEDBY"),L("POSTEDURL"));
1386   for (i=nburls<NBURLS?nburls-1:NBURLS-1;i>=0;i--)
1387   {
1388     fprintf(fic,"<tr><td>%s</td><td>\"<a href=\"",urls[i].nick);
1389     printhtml(fic,urls[i].url);
1390     fprintf(fic,"\">");
1391     printhtml(fic,urls[i].shorturl);
1392     fprintf(fic,"</a>\"</td></tr>\n");
1393   }
1394   fprintf(fic,"</table>\n</div>\n\n");
1395   
1396   /* top words */
1397   if (top_words)
1398   {
1399     fprintf(fic,"<div id=\"irssistats_topwords\">\n<h2>%s</h2>\n",L("TOPWORDS"));
1400     fprintf(fic,"<table>\n<tr><th></th><th>%s</th><th>%s</th></tr>\n",L("WORD"),L("OCCURRENCES"));
1401     for (i=0;i<NBWORDS;i++)
1402       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);
1403     fprintf(fic,"</table>\n</div>\n\n");
1404   }
1405   
1406   /* big numbers */
1407   fprintf(fic,"<div id=\"irssistats_bignumbers\">\n<h2>%s</h2>\n",L("BIGNUMBERS"));
1408   fprintf(fic,"<table>\n<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n",L("NICK"),L("NUMBERS"),L("NBLINES"));
1409   for (i=0;i<NBCOUNTERS;i++)
1410   {
1411     user=-1;
1412     max=0;
1413     for (j=0;j<nbusers;j++) if (users[j].counters[i]>max) max=users[user=j].counters[i];
1414     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]);
1415   }
1416   fprintf(fic,"</table>\n</div>\n\n");
1417   
1418   /* footer */
1419   fprintf(fic,"<div id=\"irssistats_footer\">\n<p>");
1420   fprintf(fic,L("TIME"),totallines,days,(int)(time(NULL)-debut));
1421   fprintf(fic,"</p>\n<p>%s <a href=\"%s\">irssistats %s</a></p>\n",L("FOOTER"),URL,VERSION);
1422   if (w3c_link)
1423   {
1424     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");
1425     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");
1426   }
1427   fprintf(fic,"</div>\n\n");
1428   
1429   /* logo*/
1430   if (logo) fprintf(fic,"<div class=\"logo\"></div>\n\n");
1431   
1432   /* end */
1433   if (strcmp("none",footer)==0)
1434   {
1435     fprintf(fic,"</div>\n\n</body>\n\n</html>\n");
1436   }
1437   else
1438   {
1439     if ((sfic=fopen(footer,"rt"))==NULL) { fprintf(stderr,"can't open footer file \"%s\"\n",footer); exit(1); }
1440     while ((temp=fread(line,1,MAXLINELENGTH,sfic))) fwrite(line,temp,1,fic);
1441     fclose(sfic);
1442   }
1443   
1444   fclose(fic);
1445 }
1446
1447 void parse_config(char *configfile)
1448 {
1449   void expand(char *path)
1450   {
1451     char temp[MAXLINELENGTH];
1452     if (*path=='~')
1453     {
1454       snprintf(temp,MAXLINELENGTH-1,"%s%s",getenv("HOME"),path+1);
1455       temp[MAXLINELENGTH-1]='\0';
1456       strcpy(path,temp);
1457     }
1458   }
1459   
1460   FILE *fic;
1461   char line[MAXLINELENGTH];
1462   char keyword[MAXLINELENGTH];
1463   char value[MAXLINELENGTH];
1464   int configlines=0;
1465   int i;
1466   
1467   if (configfile!=NULL)
1468   {
1469     if ((fic=fopen(configfile,"rt"))==NULL)
1470     {
1471       fprintf(stderr,"can't open config file : \"%s\"\n",configfile);
1472       exit(1);
1473     }
1474   }
1475   else
1476   {
1477     snprintf(line,MAXLINELENGTH-1,"%s/.irssistats",getenv("HOME"));
1478     line[MAXLINELENGTH-1]='\0';
1479     if ((fic=fopen(line,"rt"))==NULL)
1480       if ((fic=fopen(GLOBALCONF,"rt"))==NULL)
1481       {
1482         fprintf(stderr,"can't find config file : \"%s\" nor \"" GLOBALCONF "\"\n",line);
1483         fprintf(stderr,"please give the path to the config file in argument\n");
1484         exit(1);
1485       }
1486   }
1487
1488   while (fgets(line,MAXLINELENGTH,fic))
1489   {
1490     configlines++;
1491     if (*line!=';' && *line!='#' && *line!='/' && *line!='-' && *line!='\n')
1492     {
1493       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); }
1494       
1495       if (strcmp("debug",keyword)==0)
1496       {
1497         if (strcmp("none",value)==0) debug=0;
1498         else
1499         if (strcmp("normal",value)==0) debug=1;
1500         else
1501         if (strcmp("verbose",value)==0) { debug=2; fprintf(stderr,"switching to verbose output\n"); }
1502         else { fprintf(stderr,"unknown value for \"debug\" option, must be \"normal\", \"verbose\" or \"none\"\n"); exit(1); }
1503       }
1504       else
1505       
1506       if (strcmp("channel",keyword)==0)
1507       {
1508         if (debug==2) fprintf(stderr,"setting channel name to \"%s\"\n",value);
1509         strcpy(channel,value);
1510       }
1511       else
1512       
1513       if (strcmp("maintainer",keyword)==0)
1514       {
1515         if (debug==2) fprintf(stderr,"setting maintainer to \"%s\"\n",value);
1516         strcpy(maintainer,value);
1517       }
1518       else
1519       
1520       if (strcmp("language",keyword)==0)
1521       {
1522         if (debug==2) fprintf(stderr,"setting language to \"%s\"\n",value);
1523         for (i=0;i<NBLANGUAGES;i++) if (strcmp(value,keys[i][0][1])==0) { language=i; break; }
1524         if (i==NBLANGUAGES)
1525         {
1526           fprintf(stderr,"Invalid language : %s\n",value);
1527           fprintf(stderr,"Supported languages :\n");
1528           for (i=0;i<NBLANGUAGES;i++) fprintf(stderr,"%s = %s\n",keys[i][0][1],keys[i][0][0]);
1529           exit(1);
1530         }
1531       }
1532       else
1533       
1534       if (strcmp("theme",keyword)==0)
1535       {
1536         if (debug==2) fprintf(stderr,"setting theme to \"%s\"\n",value);
1537         strcpy(theme,value);
1538       }
1539       else
1540       
1541       if (strcmp("refresh_time",keyword)==0)
1542       {
1543         refresh_time=atoi(value);
1544         if (debug==2) fprintf(stderr,"setting refresh_time to \"%d\"\n",refresh_time);
1545       }
1546       else
1547       
1548       if (strcmp("photo_size",keyword)==0)
1549       {
1550         photo_size=atoi(value);
1551         if (debug==2) fprintf(stderr,"setting photo_size to \"%d\"\n",photo_size);
1552       }
1553       else
1554       
1555       if (strcmp("w3c_link",keyword)==0)
1556       {
1557         if (debug==2) fprintf(stderr,"setting w3c_link to \"%s\"\n",value);
1558         if (strcmp("no",value)==0) w3c_link=0;
1559         else if (strcmp("yes",value)==0) w3c_link=1;
1560         else { fprintf(stderr,"unknown value for \"w3c_link\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1561       }
1562       else
1563       
1564       if (strcmp("logo",keyword)==0)
1565       {
1566         if (debug==2) fprintf(stderr,"setting logo to \"%s\"\n",value);
1567         if (strcmp("no",value)==0) logo=0;
1568         else if (strcmp("yes",value)==0) logo=1;
1569         else { fprintf(stderr,"unknown value for \"logo\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1570       }
1571       else
1572       
1573       if (strcmp("header",keyword)==0)
1574       {
1575         expand(value);
1576         if (debug==2) fprintf(stderr,"setting header to \"%s\"\n",value);
1577         strcpy(header,value);
1578       }
1579       else
1580       
1581       if (strcmp("footer",keyword)==0)
1582       {
1583         expand(value);
1584         if (debug==2) fprintf(stderr,"setting footer to \"%s\"\n",value);
1585         strcpy(footer,value);
1586       }
1587       else
1588       
1589       if (strcmp("input",keyword)==0)
1590       {
1591         expand(value);
1592         if (debug==2) fprintf(stderr,"parsing log file \"%s\"\n",value);
1593         parse_log(value);
1594       }
1595       else
1596       
1597       if (strcmp("nickfile",keyword)==0)
1598       {
1599         expand(value);
1600         if (debug==2) fprintf(stderr,"nick alias using file \"%s\"\n",value);
1601 #ifdef __WIN32__
1602         fprintf(stderr,"no support for nickfile in WIN32 version\n");
1603 #else
1604         parse_nick(value);
1605 #endif
1606       }
1607       else
1608       
1609       if (strcmp("photofile",keyword)==0)
1610       {
1611         expand(value);
1612         if (debug==2) fprintf(stderr,"parsing photo file \"%s\"\n",value);
1613         parse_photo(value);
1614       }
1615       else
1616       
1617       if (strcmp("output",keyword)==0)
1618       {
1619         expand(value);
1620         if (debug==2) fprintf(stderr,"generating xhtml file \"%s\"\n",value);
1621         bestwords(words,0);
1622         if (L("CHARSET")=="KOI8-R") bestruswords(ruswords,0);
1623         gen_xhtml(value);
1624         
1625         /* reset variables */
1626         nbusers=0;
1627         nburls=0;
1628         nbtopics=0;
1629         days=0;
1630         for (i=0;i<24*4;i++) hours[i]=0;
1631         lines=0;
1632         freewords(&words);
1633         freeruswords(&ruswords);
1634         for (i=0;i<NBWORDS;i++) topwords[i].nb=0;
1635         totallines=0;
1636         debut=time(NULL);
1637         for (i=0;i<nbusers;i++)
1638         {
1639           free(users[i].photo);
1640           users[i].photo=NULL;
1641         }
1642       }
1643       else
1644       
1645       if (strcmp("top_words",keyword)==0)
1646       {
1647         if (debug==2) fprintf(stderr,"setting top_words to \"%s\"\n",value);
1648         if (strcmp("no",value)==0) top_words=0;
1649         else if (strcmp("yes",value)==0) top_words=1;
1650         else { fprintf(stderr,"unknown value for \"top_words\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1651       }
1652       else
1653       
1654       if (strcmp("ranking",keyword)==0)
1655       {
1656         if (strcmp("lines",value)==0) ranking=0;
1657         else
1658         if (strcmp("words",value)==0) ranking=1;
1659         else
1660         if (strcmp("letters",value)==0) ranking=2;
1661         else { fprintf(stderr,"unknown value for \"ranking\" option, must be \"lines\", \"words\" or \"letters\"\n"); exit(1); }
1662       }
1663       else
1664       
1665       if (strcmp("quarter",keyword)==0)
1666       {
1667         if (debug==2) fprintf(stderr,"setting quarter to \"%s\"\n",value);
1668         if (strcmp("no",value)==0) quarter=0;
1669         else if (strcmp("yes",value)==0) quarter=1;
1670         else { fprintf(stderr,"unknown value for \"quarter\" option, must be \"yes\" or \"no\"\n"); exit(1); }
1671       }
1672
1673       else { fprintf(stderr,"error in config file : \"%s\" is an unknown keyword (line %d)\n",keyword,configlines); exit(1); }        
1674     }
1675   }
1676   fclose(fic);
1677 }
1678
1679 int main(int argc,char *argv[])
1680 {
1681   (void) setlocale(LC_ALL, "");
1682   
1683   if ((users=malloc(maxusers*sizeof(struct user)))==NULL) { fprintf(stderr,"unable to malloc memory\n"); exit(1); }
1684   srand(debut=time(NULL));
1685   if (argc==1) parse_config(NULL);
1686   else if (argc==2) parse_config(argv[1]);
1687   else
1688   {
1689     fprintf(stderr,"Usage : %s [/path/to/file.conf]\n",argv[0]);
1690     fprintf(stderr,"Version : irssistats %s\n",VERSION);
1691     exit(1);
1692   }
1693   return(0);
1694 }