Rev 506 | Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 505 | arune | 1 | #!/usr/bin/perl -w |
| 2 | |||
| 3 | $debugmode = 0; |
||
| 4 | |||
| 5 | $outputpath = "outp/"; |
||
| 6 | $linenrpath = "linenr.txt"; |
||
| 7 | $contentspath = "contents.txt"; |
||
| 8 | $currentfilepath = "currentfile.txt"; |
||
| 9 | $logfilepath = "#hobby.log"; |
||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | $numArgs = $#ARGV + 1; |
||
| 14 | if ($numArgs == 1) { |
||
| 15 | if ($ARGV[0] eq "-r") { |
||
| 16 | #reset log system |
||
| 17 | |||
| 18 | $fileopenerr = 0; |
||
| 19 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
||
| 20 | if ($fileopenerr == 0) { |
||
| 21 | print LINENR "0"; |
||
| 22 | close(LINENR); |
||
| 23 | } |
||
| 24 | |||
| 25 | $fileopenerr = 0; |
||
| 26 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
||
| 27 | if ($fileopenerr == 0) { |
||
| 28 | print CONTENTSFILE ""; |
||
| 29 | close(CONTENTSFILE); |
||
| 30 | } |
||
| 31 | close(CONTENTSFILE); |
||
| 32 | |||
| 33 | $fileopenerr = 0; |
||
| 34 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
||
| 35 | if ($fileopenerr == 0) { |
||
| 36 | print CURRFILE ""; |
||
| 37 | close(CURRFILE); |
||
| 38 | } |
||
| 39 | #print "exit\n"; |
||
| 40 | exit; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | |||
| 45 | $startAtLine = 0; |
||
| 46 | $currentfile = ""; |
||
| 47 | |||
| 48 | $fileopenerr = 0; |
||
| 49 | open (LINENR, "<".$linenrpath) or $fileopenerr = 1; |
||
| 50 | if ($fileopenerr == 0) { |
||
| 51 | $startAtLine = <LINENR>; |
||
| 52 | if ($startAtLine =~ /\D/) { |
||
| 53 | print "Not a number\n"; |
||
| 54 | exit; |
||
| 55 | } |
||
| 56 | close(LINENR); |
||
| 57 | } else { |
||
| 58 | print "Could not open ".$linenrpath; |
||
| 59 | exit; |
||
| 60 | } |
||
| 61 | |||
| 62 | $fileopenerr = 0; |
||
| 63 | open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1; |
||
| 64 | if ($fileopenerr == 0) { |
||
| 65 | $currentfile = <CURRFILE>; |
||
| 66 | if (!$currentfile && $startAtLine != 0) { |
||
| 67 | print "Current file not ok\n"; |
||
| 68 | exit; |
||
| 69 | } |
||
| 70 | close(CURRFILE); |
||
| 71 | } else { |
||
| 72 | print "Could not opeen ".$currentfilepath; |
||
| 73 | if ($startAtLine != 0) { |
||
| 74 | exit; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | $fileopenerr = 0; |
||
| 79 | open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1; |
||
| 80 | if ($fileopenerr == 1) { |
||
| 81 | print "Could not open ".$logfilepath; |
||
| 82 | exit; |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($currentfile) { |
||
| 86 | if ($debugmode == 0) { |
||
| 87 | $fileopenerr = 0; |
||
| 88 | open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1; |
||
| 89 | if ($fileopenerr == 1) { |
||
| 90 | print "Could not open ".$outputpath."/".$currentfile; |
||
| 91 | exit; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | $linecnt = 0; |
||
| 97 | while (<LOGFILE>) { |
||
| 98 | #print $linecnt ." "; |
||
| 99 | $line = $_; |
||
| 100 | #$store = ""; |
||
| 101 | if ($linecnt >= $startAtLine) { |
||
| 102 | if ($line =~ m/^Session Time:/) { |
||
| 103 | #print $line; |
||
| 104 | $datetimenice = $line; |
||
| 105 | $datetimenice =~ s/Session Time: //g; |
||
| 106 | $datetimenice =~ s/\n//g; |
||
| 107 | $datetimenice =~ s/\r//g; |
||
| 108 | |||
| 109 | $datetime = $line; |
||
| 110 | $datetime =~ s/Session Time: //g; |
||
| 111 | $datetime =~ s/://g; |
||
| 112 | $datetime =~ s/\n//g; |
||
| 113 | $datetime =~ s/\r//g; |
||
| 114 | $datetime =~ s/ /_/g; |
||
| 115 | |||
| 116 | $currentfile = $datetime .".txt"; |
||
| 117 | # skriv $datetimenice och $datetime till $contentspath |
||
| 118 | $fileopenerr = 0; |
||
| 119 | open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1; |
||
| 120 | if ($fileopenerr == 0) { |
||
| 121 | @contentsfilecontents = <CONTENTSFILE>; |
||
| 122 | close(CONTENTSFILE); |
||
| 123 | if ($debugmode == 0) { |
||
| 124 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
||
| 125 | if ($fileopenerr == 0) { |
||
| 126 | print CONTENTSFILE "[[$datetime|$datetimenice]] \\\\ \n"; |
||
| 127 | foreach (@contentsfilecontents) { |
||
| 128 | print CONTENTSFILE $_; |
||
| 129 | } |
||
| 130 | close(CONTENTSFILE); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | } else { |
||
| 134 | exit; |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($debugmode == 0) { |
||
| 138 | $fileopenerr = 0; |
||
| 139 | open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1; |
||
| 140 | if ($fileopenerr == 1) { |
||
| 141 | print "Could not open ".$outputpath."/".$currentfile; |
||
| 142 | exit; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | #print $datetime; |
||
| 147 | } |
||
| 148 | |||
| 149 | if ($currentfile) { |
||
| 150 | $parsedLine = $line; |
||
| 151 | $parsedLine =~ s/\n//g; |
||
| 152 | $parsedLine =~ s/\r//g; |
||
| 153 | $parsedLine =~ s/å/å/g; |
||
| 154 | $parsedLine =~ s/ä/ä/g; |
||
| 155 | $parsedLine =~ s/ö/ö/g; |
||
| 156 | $parsedLine =~ s/Å/Å/g; |
||
| 157 | $parsedLine =~ s/Ä/Ä/g; |
||
| 158 | $parsedLine =~ s/Ö/Ö/g; |
||
| 159 | $parsedLine =~ s/</</g; |
||
| 160 | $parsedLine =~ s/>/>/g; |
||
| 161 | |||
| 162 | $parsedLine .= "\\\\"."\n"; |
||
| 163 | if ($debugmode == 0) { |
||
| 164 | print OUTFILE $parsedLine; |
||
| 165 | } |
||
| 166 | } |
||
| 167 | #print $store; |
||
| 168 | |||
| 169 | } |
||
| 170 | $linecnt++; |
||
| 171 | } |
||
| 172 | |||
| 173 | if ($debugmode == 0) { |
||
| 174 | $fileopenerr = 0; |
||
| 175 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
||
| 176 | if ($fileopenerr == 0) { |
||
| 177 | print LINENR $linecnt; |
||
| 178 | close(LINENR); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | if ($debugmode == 0) { |
||
| 183 | $fileopenerr = 0; |
||
| 184 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
||
| 185 | if ($fileopenerr == 0) { |
||
| 186 | print CURRFILE $currentfile; |
||
| 187 | close(CURRFILE); |
||
| 188 | } else { |
||
| 189 | print "Could not open ".$currentfilepath; |
||
| 190 | exit; |
||
| 191 | } |
||
| 192 | } |
||
| 193 | |||
| 194 | #print $linecnt-1 ." - ". $line; |
||
| 195 | |||
| 196 | |||
| 197 | |||
| 198 | |||
| 199 | |||
| 200 | |||
| 201 |