Rev 728 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 728 | Rev 800 | ||
|---|---|---|---|
| 1 | #!/usr/bin/perl -w |
1 | #!/usr/bin/perl -w |
| 2 | 2 | ||
| 3 | $debugmode = 0; |
3 | $debugmode = 0; |
| 4 | 4 | ||
| 5 | $outputpath = "outp/"; |
5 | $outputpath = "outp/"; |
| 6 | $linenrpath = "linenr.txt"; |
6 | $linenrpath = "linenr.txt"; |
| 7 | $contentspath = "contents.txt"; |
7 | $contentspath = "contents.txt"; |
| 8 | $currentfilepath = "currentfile.txt"; |
8 | $currentfilepath = "currentfile.txt"; |
| 9 | $logfilepath = "#hobby_small.log"; |
9 | $logfilepath = "#hobby_small.log"; |
| 10 | $contentsfileoutput = "outp/"; |
10 | $contentsfileoutput = "outp/"; |
| 11 | $contentsfilename = "hobby.txt"; |
11 | $contentsfilename = "hobby.txt"; |
| 12 | $contentsheader = "====== Log of #hobby-channel ======\n"; |
12 | $contentsheader = "====== Log of #hobby-channel ======\n"; |
| 13 | $namespace = "common:irc:hobby:"; |
13 | $namespace = "common:irc:hobby:"; |
| 14 | 14 | ||
| 15 | require "settings.pl"; |
15 | require "settings.pl"; |
| 16 | 16 | ||
| 17 | $numArgs = $#ARGV + 1; |
17 | $numArgs = $#ARGV + 1; |
| 18 | if ($numArgs == 1) { |
18 | if ($numArgs == 1) { |
| 19 | if ($ARGV[0] eq "-r") { |
19 | if ($ARGV[0] eq "-r") { |
| 20 | #reset log system |
20 | #reset log system |
| 21 | 21 | ||
| 22 | $fileopenerr = 0; |
22 | $fileopenerr = 0; |
| 23 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
23 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
| 24 | if ($fileopenerr == 0) { |
24 | if ($fileopenerr == 0) { |
| 25 | print LINENR "0"; |
25 | print LINENR "0"; |
| 26 | close(LINENR); |
26 | close(LINENR); |
| 27 | } |
27 | } |
| 28 | 28 | ||
| 29 | $fileopenerr = 0; |
29 | $fileopenerr = 0; |
| 30 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
30 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
| 31 | if ($fileopenerr == 0) { |
31 | if ($fileopenerr == 0) { |
| 32 | print CONTENTSFILE ""; |
32 | print CONTENTSFILE ""; |
| 33 | close(CONTENTSFILE); |
33 | close(CONTENTSFILE); |
| 34 | } |
34 | } |
| 35 | close(CONTENTSFILE); |
35 | close(CONTENTSFILE); |
| 36 | 36 | ||
| 37 | $fileopenerr = 0; |
37 | $fileopenerr = 0; |
| 38 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
38 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
| 39 | if ($fileopenerr == 0) { |
39 | if ($fileopenerr == 0) { |
| 40 | print CURRFILE ""; |
40 | print CURRFILE ""; |
| 41 | close(CURRFILE); |
41 | close(CURRFILE); |
| 42 | } |
42 | } |
| 43 | #print "exit\n"; |
43 | #print "exit\n"; |
| 44 | exit; |
44 | exit; |
| 45 | } |
45 | } |
| 46 | } |
46 | } |
| 47 | 47 | ||
| 48 | $startAtLine = 0; |
48 | $startAtLine = 0; |
| 49 | $currentfile = ""; |
49 | $currentfile = ""; |
| 50 | 50 | ||
| 51 | $fileopenerr = 0; |
51 | $fileopenerr = 0; |
| 52 | open (LINENR, "<".$linenrpath) or $fileopenerr = 1; |
52 | open (LINENR, "<".$linenrpath) or $fileopenerr = 1; |
| 53 | if ($fileopenerr == 0) { |
53 | if ($fileopenerr == 0) { |
| 54 | $startAtLine = <LINENR>; |
54 | $startAtLine = <LINENR>; |
| 55 | if ($startAtLine =~ /\D/) { |
55 | if ($startAtLine =~ /\D/) { |
| 56 | print "Not a number\n"; |
56 | print "Not a number\n"; |
| 57 | exit; |
57 | exit; |
| 58 | } |
58 | } |
| 59 | close(LINENR); |
59 | close(LINENR); |
| 60 | } else { |
60 | } else { |
| 61 | print "Could not open ".$linenrpath; |
61 | print "Could not open ".$linenrpath; |
| 62 | exit; |
62 | exit; |
| 63 | } |
63 | } |
| 64 | 64 | ||
| 65 | $fileopenerr = 0; |
65 | $fileopenerr = 0; |
| 66 | open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1; |
66 | open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1; |
| 67 | if ($fileopenerr == 0) { |
67 | if ($fileopenerr == 0) { |
| 68 | $currentfile = <CURRFILE>; |
68 | $currentfile = <CURRFILE>; |
| 69 | if (!$currentfile && $startAtLine != 0) { |
69 | if (!$currentfile && $startAtLine != 0) { |
| 70 | print "Current file not ok\n"; |
70 | print "Current file not ok\n"; |
| 71 | exit; |
71 | exit; |
| 72 | } |
72 | } |
| 73 | close(CURRFILE); |
73 | close(CURRFILE); |
| 74 | } else { |
74 | } else { |
| 75 | print "Could not opeen ".$currentfilepath; |
75 | print "Could not opeen ".$currentfilepath; |
| 76 | if ($startAtLine != 0) { |
76 | if ($startAtLine != 0) { |
| 77 | exit; |
77 | exit; |
| 78 | } |
78 | } |
| 79 | } |
79 | } |
| 80 | 80 | ||
| 81 | $fileopenerr = 0; |
81 | $fileopenerr = 0; |
| 82 | open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1; |
82 | open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1; |
| 83 | if ($fileopenerr == 1) { |
83 | if ($fileopenerr == 1) { |
| 84 | print "Could not open ".$logfilepath; |
84 | print "Could not open ".$logfilepath; |
| 85 | exit; |
85 | exit; |
| 86 | } |
86 | } |
| 87 | 87 | ||
| 88 | if ($currentfile) { |
88 | if ($currentfile) { |
| 89 | if ($debugmode == 0) { |
89 | if ($debugmode == 0) { |
| 90 | $fileopenerr = 0; |
90 | $fileopenerr = 0; |
| 91 | open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1; |
91 | open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1; |
| 92 | if ($fileopenerr == 1) { |
92 | if ($fileopenerr == 1) { |
| 93 | print "Could not open ".$outputpath."/".$currentfile; |
93 | print "Could not open ".$outputpath."/".$currentfile; |
| 94 | exit; |
94 | exit; |
| 95 | } |
95 | } |
| 96 | } |
96 | } |
| 97 | } |
97 | } |
| 98 | 98 | ||
| 99 | @colors = ("#2F4F4F","#696969","#A0522D","#D2691E","#DAA520","#191970","#0000CD","#4682B4","#7FEFD4","#556B2F","#008B8B","#808000","#2E8B57","#32CD32","#483D8B","#6A5ACD","#8A2BE2","#BDB76B","#EF4500","#C71585","#8B0000","#DC143C","#E9967A","#CD5C5C","#B0E0E6","#E0E0C0"); |
99 | @colors = ("#2F4F4F","#696969","#A0522D","#D2691E","#DAA520","#191970","#0000CD","#4682B4","#7FEFD4","#556B2F","#008B8B","#808000","#2E8B57","#32CD32","#483D8B","#6A5ACD","#8A2BE2","#BDB76B","#EF4500","#C71585","#8B0000","#DC143C","#E9967A","#CD5C5C","#B0E0E6","#E0E0C0"); |
| 100 | $nrofcolors = @colors; |
100 | $nrofcolors = @colors; |
| 101 | 101 | ||
| 102 | $linecnt = 0; |
102 | $linecnt = 0; |
| 103 | while (<LOGFILE>) { |
103 | while (<LOGFILE>) { |
| 104 | #print $linecnt ." "; |
104 | #print $linecnt ." "; |
| 105 | $line = $_; |
105 | $line = $_; |
| 106 | #$store = ""; |
106 | #$store = ""; |
| 107 | if ($linecnt >= $startAtLine) { |
107 | if ($linecnt >= $startAtLine) { |
| 108 | if ($line =~ m/^Session Time:/) { |
108 | if ($line =~ m/^Session Time:/) { |
| 109 | #print $line; |
109 | #print $line; |
| 110 | $datetimenice = $line; |
110 | $datetimenice = $line; |
| 111 | $datetimenice =~ s/Session Time: //g; |
111 | $datetimenice =~ s/Session Time: //g; |
| 112 | $datetimenice =~ s/\n//g; |
112 | $datetimenice =~ s/\n//g; |
| 113 | $datetimenice =~ s/\r//g; |
113 | $datetimenice =~ s/\r//g; |
| 114 | 114 | ||
| 115 | $datetime = $line; |
115 | $datetime = $line; |
| 116 | $datetime =~ s/Session Time: //g; |
116 | $datetime =~ s/Session Time: //g; |
| 117 | $datetime =~ s/://g; |
117 | $datetime =~ s/://g; |
| 118 | $datetime =~ s/\n//g; |
118 | $datetime =~ s/\n//g; |
| 119 | $datetime =~ s/\r//g; |
119 | $datetime =~ s/\r//g; |
| 120 | $datetime =~ s/ /_/g; |
120 | $datetime =~ s/ /_/g; |
| 121 | $datetime = lc($datetime); |
121 | $datetime = lc($datetime); |
| 122 | 122 | ||
| 123 | if ($currentfile) { |
123 | if ($currentfile) { |
| 124 | if ($debugmode == 0) { |
124 | if ($debugmode == 0) { |
| 125 | print OUTFILE "\n\\\\\nNext page: [[".$datetime."]] \\\\ \n"; |
125 | print OUTFILE "\n\\\\\nNext page: [[".$datetime."]] \\\\ \n"; |
| 126 | print OUTFILE "Back to index: [[".$namespace."]] \\\\ \n"; |
126 | print OUTFILE "Back to index: [[".$namespace."]] \\\\ \n"; |
| 127 | 127 | ||
| 128 | } |
128 | } |
| 129 | } |
129 | } |
| 130 | 130 | ||
| 131 | $currentfile = $datetime .".txt"; |
131 | $currentfile = $datetime .".txt"; |
| 132 | # skriv $datetimenice och $datetime till $contentspath |
132 | # skriv $datetimenice och $datetime till $contentspath |
| 133 | $fileopenerr = 0; |
133 | $fileopenerr = 0; |
| 134 | open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1; |
134 | open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1; |
| 135 | if ($fileopenerr == 0) { |
135 | if ($fileopenerr == 0) { |
| 136 | @contentsfilecontents = <CONTENTSFILE>; |
136 | @contentsfilecontents = <CONTENTSFILE>; |
| 137 | close(CONTENTSFILE); |
137 | close(CONTENTSFILE); |
| 138 | if ($debugmode == 0) { |
138 | if ($debugmode == 0) { |
| 139 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
139 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
| 140 | if ($fileopenerr == 0) { |
140 | if ($fileopenerr == 0) { |
| 141 | print CONTENTSFILE "[[$namespace$datetime|$datetimenice]] \\\\ \n"; |
141 | print CONTENTSFILE "[[$namespace$datetime|$datetimenice]] \\\\ \n"; |
| 142 | foreach (@contentsfilecontents) { |
142 | foreach (@contentsfilecontents) { |
| 143 | print CONTENTSFILE $_; |
143 | print CONTENTSFILE $_; |
| 144 | } |
144 | } |
| 145 | close(CONTENTSFILE); |
145 | close(CONTENTSFILE); |
| 146 | } |
146 | } |
| 147 | } |
147 | } |
| 148 | } else { |
148 | } else { |
| 149 | exit; |
149 | exit; |
| 150 | } |
150 | } |
| 151 | 151 | ||
| 152 | if ($debugmode == 0) { |
152 | if ($debugmode == 0) { |
| 153 | $fileopenerr = 0; |
153 | $fileopenerr = 0; |
| 154 | open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1; |
154 | open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1; |
| 155 | if ($fileopenerr == 1) { |
155 | if ($fileopenerr == 1) { |
| 156 | print "Could not open ".$outputpath."/".$currentfile; |
156 | print "Could not open ".$outputpath."/".$currentfile; |
| 157 | exit; |
157 | exit; |
| 158 | } |
158 | } |
| 159 | } |
159 | } |
| 160 | if ($currentfile) { |
160 | if ($currentfile) { |
| 161 | if ($debugmode == 0) { |
161 | if ($debugmode == 0) { |
| 162 | print OUTFILE "====== ".$datetimenice." ======\n"; |
162 | print OUTFILE "====== ".$datetimenice." ======\n"; |
| 163 | } |
163 | } |
| 164 | } |
164 | } |
| 165 | #print $datetime; |
165 | #print $datetime; |
| 166 | } |
166 | } |
| 167 | 167 | ||
| 168 | elsif ($currentfile) { |
168 | elsif ($currentfile) { |
| 169 | $parsedLine = $line; |
169 | $parsedLine = $line; |
| 170 | $parsedLine =~ s/\n//g; |
170 | $parsedLine =~ s/\n//g; |
| 171 | $parsedLine =~ s/\r//g; |
171 | $parsedLine =~ s/\r//g; |
| 172 | #$parsedLine = $parsedLine; |
172 | #$parsedLine = $parsedLine; |
| 173 | 173 | ||
| 174 | #<color #aaaaaa> |
174 | #<color #aaaaaa> |
| 175 | #</color> |
175 | #</color> |
| 176 | 176 | ||
| 177 | $nickLine = $parsedLine; |
177 | $nickLine = $parsedLine; |
| 178 | if ($nickLine =~ m/.*<(\w{1,9})>.*/) { |
178 | if ($nickLine =~ m/.*<(\w{1,9})>.*/) { |
| 179 | $nick = $1; |
179 | $nick = $1; |
| 180 | $nickVal = 0; |
180 | $nickVal = 0; |
| 181 | my @chars = split //, $nick; |
181 | my @chars = split //, $nick; |
| 182 | foreach my $char (@chars) { |
182 | foreach my $char (@chars) { |
| 183 | #for ($i = 0; $i < length($nick); $i++) { |
183 | #for ($i = 0; $i < length($nick); $i++) { |
| 184 | #$charval = ord(substr($nick, $i, 1)); |
184 | #$charval = ord(substr($nick, $i, 1)); |
| 185 | $nickVal += ord($char); |
185 | $nickVal += ord($char); |
| 186 | #$nickVal += $charval; |
186 | #$nickVal += $charval; |
| 187 | 187 | ||
| 188 | } |
188 | } |
| 189 | #$temp = $nickVal; |
189 | #$temp = $nickVal; |
| 190 | $nickVal = ($nickVal) % $nrofcolors; |
190 | $nickVal = ($nickVal) % $nrofcolors; |
| 191 | #$nickB = sprintf("%x", ((($nickVal & 7)**2)*2.3+5)); |
191 | #$nickB = sprintf("%x", ((($nickVal & 7)**2)*2.3+5)); |
| 192 | #$nickG = sprintf("%x", (((($nickVal >> 3) & 7)**2.3)*2+5)); |
192 | #$nickG = sprintf("%x", (((($nickVal >> 3) & 7)**2.3)*2+5)); |
| 193 | #$nickR = sprintf("%x", (((($nickVal >> 6) & 7)**2.3)*2+5)); |
193 | #$nickR = sprintf("%x", (((($nickVal >> 6) & 7)**2.3)*2+5)); |
| 194 | #if (length($nickB) == 1) { |
194 | #if (length($nickB) == 1) { |
| 195 | # $nickB = "0".$nickB; |
195 | # $nickB = "0".$nickB; |
| 196 | #} |
196 | #} |
| 197 | #if (length($nickG) == 1) { |
197 | #if (length($nickG) == 1) { |
| 198 | # $nickG = "0".$nickG; |
198 | # $nickG = "0".$nickG; |
| 199 | #} |
199 | #} |
| 200 | #if (length($nickR) == 1) { |
200 | #if (length($nickR) == 1) { |
| 201 | # $nickR = "0".$nickR; |
201 | # $nickR = "0".$nickR; |
| 202 | #} |
202 | #} |
| 203 | 203 | ||
| 204 | #print "$nick $temp $nickVal $colors[$nickVal] \n"; |
204 | #print "$nick $temp $nickVal $colors[$nickVal] \n"; |
| 205 | #$color = "#$nickR$nickG$nickB"; |
205 | #$color = "#$nickR$nickG$nickB"; |
| 206 | $parsedLine =~ s/<$nick>/<color $colors[$nickVal]><$nick><\/color>/; |
206 | $parsedLine =~ s/<$nick>/<color $colors[$nickVal]><$nick><\/color>/; |
| 207 | #print $nick." ".$nickVal."\n"; |
207 | #print $nick." ".$nickVal."\n"; |
| 208 | #print $parsedLine ."\n"; |
208 | #print $parsedLine ."\n"; |
| 209 | } |
209 | } |
| 210 | 210 | ||
| 211 | $parsedLine =~ s/\x{e5}/å/g; |
211 | $parsedLine =~ s/\x{e5}/å/g; |
| 212 | $parsedLine =~ s/\x{e4}/ä/g; |
212 | $parsedLine =~ s/\x{e4}/ä/g; |
| 213 | $parsedLine =~ s/\x{f6}/ö/g; |
213 | $parsedLine =~ s/\x{f6}/ö/g; |
| 214 | $parsedLine =~ s/\x{c5}/Å/g; |
214 | $parsedLine =~ s/\x{c5}/Å/g; |
| 215 | $parsedLine =~ s/\x{c4}/Ä/g; |
215 | $parsedLine =~ s/\x{c4}/Ä/g; |
| 216 | $parsedLine =~ s/\x{d6}/Ö/g; |
216 | $parsedLine =~ s/\x{d6}/Ö/g; |
| 217 | 217 | ||
| 218 | $parsedLine =~ s/\[wiki\]/**[wiki]**/g; |
218 | $parsedLine =~ s/\[wiki\]/**[wiki]**/g; |
| 219 | $parsedLine =~ s/\[svn\]/**[svn]**/g; |
219 | $parsedLine =~ s/\[svn\]/**[svn]**/g; |
| 220 | 220 | ||
| 221 | $parsedLine .= " "; |
221 | $parsedLine .= " "; |
| 222 | $parsedLine =~ s/http:\/\/projekt\.auml\.se\/(.+) /[[:$1]] /g; |
222 | $parsedLine =~ s/http:\/\/projekt\.auml\.se\/(.+) /[[:$1]] /g; |
| 223 | 223 | ||
| 224 | $parsedLine .= "\\\\"."\n"; |
224 | $parsedLine .= "\\\\"."\n"; |
| 225 | if ($debugmode == 0) { |
225 | if ($debugmode == 0) { |
| 226 | print OUTFILE $parsedLine; |
226 | print OUTFILE $parsedLine; |
| 227 | } |
227 | } |
| 228 | } |
228 | } |
| 229 | #print $store; |
229 | #print $store; |
| 230 | 230 | ||
| 231 | } |
231 | } |
| 232 | $linecnt++; |
232 | $linecnt++; |
| 233 | } |
233 | } |
| 234 | 234 | ||
| 235 | if ($debugmode == 0) { |
235 | if ($debugmode == 0) { |
| 236 | $fileopenerr = 0; |
236 | $fileopenerr = 0; |
| 237 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
237 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
| 238 | if ($fileopenerr == 0) { |
238 | if ($fileopenerr == 0) { |
| 239 | print LINENR $linecnt; |
239 | print LINENR $linecnt; |
| 240 | close(LINENR); |
240 | close(LINENR); |
| 241 | } |
241 | } |
| 242 | } |
242 | } |
| 243 | 243 | ||
| 244 | if ($debugmode == 0) { |
244 | if ($debugmode == 0) { |
| 245 | $fileopenerr = 0; |
245 | $fileopenerr = 0; |
| 246 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
246 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
| 247 | if ($fileopenerr == 0) { |
247 | if ($fileopenerr == 0) { |
| 248 | print CURRFILE $currentfile; |
248 | print CURRFILE $currentfile; |
| 249 | close(CURRFILE); |
249 | close(CURRFILE); |
| 250 | } else { |
250 | } else { |
| 251 | print "Could not open ".$currentfilepath; |
251 | print "Could not open ".$currentfilepath; |
| 252 | exit; |
252 | exit; |
| 253 | } |
253 | } |
| 254 | } |
254 | } |
| 255 | 255 | ||
| 256 | if ($debugmode == 0) { |
256 | if ($debugmode == 0) { |
| 257 | $fileopenerr = 0; |
257 | $fileopenerr = 0; |
| 258 | open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1; |
258 | open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1; |
| 259 | if ($fileopenerr == 0) { |
259 | if ($fileopenerr == 0) { |
| 260 | open (NICECONTENTSFILE, ">".$contentsfileoutput.$contentsfilename) or $fileopenerr = 1; |
260 | open (NICECONTENTSFILE, ">".$contentsfileoutput.$contentsfilename) or $fileopenerr = 1; |
| 261 | if ($fileopenerr == 0) { |
261 | if ($fileopenerr == 0) { |
| 262 | @contentsfilecontents = <CONTENTSFILE>; |
262 | @contentsfilecontents = <CONTENTSFILE>; |
| 263 | print NICECONTENTSFILE $contentsheader; |
263 | print NICECONTENTSFILE $contentsheader; |
| 264 | foreach (@contentsfilecontents) { |
264 | foreach (@contentsfilecontents) { |
| 265 | print NICECONTENTSFILE $_; |
265 | print NICECONTENTSFILE $_; |
| 266 | } |
266 | } |
| 267 | close(NICECONTENTSFILE); |
267 | close(NICECONTENTSFILE); |
| 268 | } else { |
268 | } else { |
| 269 | print "Could not open ".$contentsfileoutput.$contentsfilename; |
269 | print "Could not open ".$contentsfileoutput.$contentsfilename; |
| 270 | exit; |
270 | exit; |
| 271 | } |
271 | } |
| 272 | close(CONTENTSFILE); |
272 | close(CONTENTSFILE); |
| 273 | } else { |
273 | } else { |
| 274 | print "Could not open ".$contentspath; |
274 | print "Could not open ".$contentspath; |
| 275 | exit; |
275 | exit; |
| 276 | } |
276 | } |
| 277 | } |
277 | } |
| 278 | 278 | ||
| 279 | #print $linecnt-1 ." - ". $line; |
279 | #print $linecnt-1 ." - ". $line; |
| 280 | 280 | ||
| 281 | 281 | ||
| 282 | 282 | ||
| 283 | 283 | ||
| 284 | 284 | ||
| 285 | 285 | ||
| 286 | 286 | ||
| 287 | 287 | ||