Rev 505 | Rev 507 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 505 | Rev 506 | ||
|---|---|---|---|
| Line 5... | Line 5... | ||
| 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.log"; |
9 | $logfilepath = "#hobby.log"; |
| 10 | - | ||
| 11 | - | ||
| - | 10 | $contentsfileoutput = "./"; |
|
| - | 11 | $contentsfilename = "hobby.txt"; |
|
| - | 12 | $contentsheader = "====== Log of #hobby-channel ======\n"; |
|
| 12 | 13 | ||
| 13 | $numArgs = $#ARGV + 1; |
14 | $numArgs = $#ARGV + 1; |
| 14 | if ($numArgs == 1) { |
15 | if ($numArgs == 1) { |
| 15 | if ($ARGV[0] eq "-r") { |
16 | if ($ARGV[0] eq "-r") { |
| 16 | #reset log system |
17 | #reset log system |
| 17 | 18 | ||
| 18 | $fileopenerr = 0; |
19 | $fileopenerr = 0; |
| 19 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
20 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
| 20 | if ($fileopenerr == 0) { |
21 | if ($fileopenerr == 0) { |
| 21 | print LINENR "0"; |
22 | print LINENR "0"; |
| 22 | close(LINENR); |
23 | close(LINENR); |
| 23 | } |
24 | } |
| 24 | 25 | ||
| 25 | $fileopenerr = 0; |
26 | $fileopenerr = 0; |
| 26 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
27 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
| 27 | if ($fileopenerr == 0) { |
28 | if ($fileopenerr == 0) { |
| 28 | print CONTENTSFILE ""; |
29 | print CONTENTSFILE ""; |
| 29 | close(CONTENTSFILE); |
30 | close(CONTENTSFILE); |
| 30 | } |
31 | } |
| 31 | close(CONTENTSFILE); |
32 | close(CONTENTSFILE); |
| 32 | 33 | ||
| 33 | $fileopenerr = 0; |
34 | $fileopenerr = 0; |
| 34 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
35 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
| 35 | if ($fileopenerr == 0) { |
36 | if ($fileopenerr == 0) { |
| 36 | print CURRFILE ""; |
37 | print CURRFILE ""; |
| 37 | close(CURRFILE); |
38 | close(CURRFILE); |
| 38 | } |
39 | } |
| 39 | #print "exit\n"; |
40 | #print "exit\n"; |
| 40 | exit; |
41 | exit; |
| 41 | } |
42 | } |
| 42 | } |
43 | } |
| 43 | 44 | ||
| 44 | 45 | ||
| 45 | $startAtLine = 0; |
46 | $startAtLine = 0; |
| 46 | $currentfile = ""; |
47 | $currentfile = ""; |
| 47 | 48 | ||
| Line 49... | Line 50... | ||
| 49 | open (LINENR, "<".$linenrpath) or $fileopenerr = 1; |
50 | open (LINENR, "<".$linenrpath) or $fileopenerr = 1; |
| 50 | if ($fileopenerr == 0) { |
51 | if ($fileopenerr == 0) { |
| 51 | $startAtLine = <LINENR>; |
52 | $startAtLine = <LINENR>; |
| 52 | if ($startAtLine =~ /\D/) { |
53 | if ($startAtLine =~ /\D/) { |
| 53 | print "Not a number\n"; |
54 | print "Not a number\n"; |
| 54 | exit; |
55 | exit; |
| 55 | } |
56 | } |
| 56 | close(LINENR); |
57 | close(LINENR); |
| 57 | } else { |
58 | } else { |
| 58 | print "Could not open ".$linenrpath; |
59 | print "Could not open ".$linenrpath; |
| 59 | exit; |
60 | exit; |
| 60 | } |
61 | } |
| 61 | 62 | ||
| 62 | $fileopenerr = 0; |
63 | $fileopenerr = 0; |
| 63 | open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1; |
64 | open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1; |
| 64 | if ($fileopenerr == 0) { |
65 | if ($fileopenerr == 0) { |
| 65 | $currentfile = <CURRFILE>; |
66 | $currentfile = <CURRFILE>; |
| 66 | if (!$currentfile && $startAtLine != 0) { |
67 | if (!$currentfile && $startAtLine != 0) { |
| 67 | print "Current file not ok\n"; |
68 | print "Current file not ok\n"; |
| 68 | exit; |
69 | exit; |
| 69 | } |
70 | } |
| 70 | close(CURRFILE); |
71 | close(CURRFILE); |
| 71 | } else { |
72 | } else { |
| 72 | print "Could not opeen ".$currentfilepath; |
73 | print "Could not opeen ".$currentfilepath; |
| 73 | if ($startAtLine != 0) { |
74 | if ($startAtLine != 0) { |
| 74 | exit; |
75 | exit; |
| 75 | } |
76 | } |
| 76 | } |
77 | } |
| 77 | 78 | ||
| 78 | $fileopenerr = 0; |
79 | $fileopenerr = 0; |
| 79 | open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1; |
80 | open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1; |
| 80 | if ($fileopenerr == 1) { |
81 | if ($fileopenerr == 1) { |
| 81 | print "Could not open ".$logfilepath; |
82 | print "Could not open ".$logfilepath; |
| 82 | exit; |
83 | exit; |
| 83 | } |
84 | } |
| Line 113... | Line 114... | ||
| 113 | $datetime =~ s/\r//g; |
114 | $datetime =~ s/\r//g; |
| 114 | $datetime =~ s/ /_/g; |
115 | $datetime =~ s/ /_/g; |
| 115 | 116 | ||
| 116 | $currentfile = $datetime .".txt"; |
117 | $currentfile = $datetime .".txt"; |
| 117 | # skriv $datetimenice och $datetime till $contentspath |
118 | # skriv $datetimenice och $datetime till $contentspath |
| 118 | $fileopenerr = 0; |
119 | $fileopenerr = 0; |
| 119 | open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1; |
120 | open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1; |
| 120 | if ($fileopenerr == 0) { |
121 | if ($fileopenerr == 0) { |
| 121 | @contentsfilecontents = <CONTENTSFILE>; |
122 | @contentsfilecontents = <CONTENTSFILE>; |
| 122 | close(CONTENTSFILE); |
123 | close(CONTENTSFILE); |
| 123 | if ($debugmode == 0) { |
124 | if ($debugmode == 0) { |
| 124 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
125 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
| 125 | if ($fileopenerr == 0) { |
126 | if ($fileopenerr == 0) { |
| 126 | print CONTENTSFILE "[[$datetime|$datetimenice]] \\\\ \n"; |
127 | print CONTENTSFILE "[[$datetime|$datetimenice]] \\\\ \n"; |
| 127 | foreach (@contentsfilecontents) { |
128 | foreach (@contentsfilecontents) { |
| 128 | print CONTENTSFILE $_; |
129 | print CONTENTSFILE $_; |
| 129 | } |
130 | } |
| 130 | close(CONTENTSFILE); |
131 | close(CONTENTSFILE); |
| 131 | } |
132 | } |
| 132 | } |
133 | } |
| 133 | } else { |
134 | } else { |
| 134 | exit; |
135 | exit; |
| 135 | } |
136 | } |
| 136 | 137 | ||
| 137 | if ($debugmode == 0) { |
138 | if ($debugmode == 0) { |
| 138 | $fileopenerr = 0; |
139 | $fileopenerr = 0; |
| 139 | open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1; |
140 | open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1; |
| 140 | if ($fileopenerr == 1) { |
141 | if ($fileopenerr == 1) { |
| 141 | print "Could not open ".$outputpath."/".$currentfile; |
142 | print "Could not open ".$outputpath."/".$currentfile; |
| 142 | exit; |
143 | exit; |
| 143 | } |
144 | } |
| 144 | } |
145 | } |
| 145 | 146 | ||
| 146 | #print $datetime; |
147 | #print $datetime; |
| 147 | } |
148 | } |
| 148 | 149 | ||
| 149 | if ($currentfile) { |
150 | if ($currentfile) { |
| 150 | $parsedLine = $line; |
151 | $parsedLine = $line; |
| Line 185... | Line 186... | ||
| 185 | if ($fileopenerr == 0) { |
186 | if ($fileopenerr == 0) { |
| 186 | print CURRFILE $currentfile; |
187 | print CURRFILE $currentfile; |
| 187 | close(CURRFILE); |
188 | close(CURRFILE); |
| 188 | } else { |
189 | } else { |
| 189 | print "Could not open ".$currentfilepath; |
190 | print "Could not open ".$currentfilepath; |
| - | 191 | exit; |
|
| - | 192 | } |
|
| - | 193 | } |
|
| - | 194 | ||
| - | 195 | if ($debugmode == 0) { |
|
| - | 196 | $fileopenerr = 0; |
|
| - | 197 | open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1; |
|
| - | 198 | if ($fileopenerr == 0) { |
|
| - | 199 | open (NICECONTENTSFILE, ">".$contentsfileoutput.$contentsfilename) or $fileopenerr = 1; |
|
| - | 200 | if ($fileopenerr == 0) { |
|
| - | 201 | @contentsfilecontents = <CONTENTSFILE>; |
|
| - | 202 | print NICECONTENTSFILE $contentsheader; |
|
| - | 203 | foreach (@contentsfilecontents) { |
|
| - | 204 | print NICECONTENTSFILE $_; |
|
| - | 205 | } |
|
| - | 206 | close(NICECONTENTSFILE); |
|
| - | 207 | } else { |
|
| - | 208 | print "Could not open ".$contentsfileoutput.$contentsfilename; |
|
| - | 209 | exit; |
|
| - | 210 | } |
|
| - | 211 | close(CONTENTSFILE); |
|
| - | 212 | } else { |
|
| - | 213 | print "Could not open ".$contentspath; |
|
| 190 | exit; |
214 | exit; |
| 191 | } |
215 | } |
| 192 | } |
216 | } |
| 193 | 217 | ||
| 194 | #print $linecnt-1 ." - ". $line; |
218 | #print $linecnt-1 ." - ". $line; |