File: convlog.tcl

package info (click to toggle)
kppp 4:17.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,176 kB
  • sloc: cpp: 13,825; tcl: 49; sh: 19; xml: 15; makefile: 5
file content (64 lines) | stat: -rw-r--r-- 1,307 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/tclsh

proc err { msg } {
    global argv0

    puts stderr "[lindex $argv0 0]: $msg"
}

foreach i [glob -nocomplain ~/.kde/share/apps/kppp/Log/*-199?] {

    if {[catch { set fin [open $i "r"] }]} {
	err "cannot open $i for reading"
	continue
    }

    if {[catch { set fout [open ${i}.log "a"] }]} {
	err "cannot open ${i}.log for writing"
	continue
    }    

    puts -nonewline "converting $i... "
    flush stdout
    
    set PHASE 1
    while {[eof $fin] == 0} {
	gets $fin line

	if {[regexp {(.*:.*:.*):.*:(.*):.*} $line s s1 s2]} {
	    set date [clock scan $s1]
	    if {$PHASE == 2} {
		# newline
		puts $fout ""
	    }
	    puts -nonewline $fout "$date:$s2"
	    set PHASE 2
	} else {
	    set PHASE 1
	    if {[regexp {(.*:.*:.*):} $line s s1]} {
		set date [clock scan $s1]
		
		gets $fin line1
		gets $fin line2
		regexp {.*:\ *([0-9.]+)\ *(.*)} $line1 s s1 s2
		regexp {.*:\ *([0-9.]+)\ *(.*)} $line2 s s3 s4
		puts $fout ":$s2:$date:$s1:$s3:-1:-1"
	    }
	}
    }
    close $fin
    close $fout

    # remove duplicate entries
    if {[catch { exec cat ${i}.log | sort -n | uniq | egrep {^[0-9]} > ${i}.log.new} ret]} {
	err "cannot sort ${i}.log $ret"
    } else {
	catch { exec mv ${i}.log.new ${i}.log }
    }

    catch {
	exec chmod 600 ${i}.log
    }

    puts "done"
}