OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [tools/] [dosstrip.tcl] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#! /bin/sh
2
# the next line restarts using tclsh7.6 \
3
unset TCL_LIBRARY; exec tclsh7.6 "$0" "$@"
4
 
5
 
6
if {$argv == {}} {
7
    puts "usage: dosstrip.tcl \[-n|-f\] file"
8
    exit 1
9
}
10
 
11
set files $argv
12
 
13
if {[llength $files] > 1 && [lindex $files 0] == "-n"} {
14
    set test 1
15
    set files [lrange $files 1 end]
16
} else {
17
    set test 0
18
}
19
 
20
if {[llength $files] > 1 && [lindex $files 0] == "-f"} {
21
    set forced 1
22
    set files [lrange $files 1 end]
23
} else {
24
    set forced 0
25
}
26
 
27
foreach file $files {
28
    if [file isdir $file] {
29
        puts stderr "$file is a directory"
30
        continue
31
    }
32
    if [catch {set fd [open $file {RDONLY}]}] {
33
        puts stderr "Cannot open $file for reading"
34
        continue
35
    }
36
    fconfigure $fd -translation binary
37
    set data [read $fd [file size $file]]
38
    close $fd
39
    set ctrlM [format %s \r]
40
    if {[regsub -all $ctrlM $data "" data]} {
41
        if {$test} {
42
            puts "$file contains ^M"
43
        } else {
44
            set chmod 0
45
            if [catch {set fd [open $file {WRONLY TRUNC}]}] {
46
                if $forced {
47
                    catch {exec chmod u+w $file}
48
                    if [catch {set fd [open $file {WRONLY TRUNC}]}] {
49
                        puts stderr "Cannot open $file for writing"
50
                        continue
51
                    }
52
                    set chmod 1
53
                } else {
54
                    puts stderr "Cannot open $file for writing"
55
                    continue
56
                }
57
            }
58
            puts $fd $data
59
            close $fd
60
            if {$chmod} {
61
                catch {exec chmod u-w $file}
62
            }
63
        }
64
        puts "+ $file"
65
    } else {
66
        if {$test} {
67
            puts "$file does not contain ^M"
68
        } else {
69
            puts "- $file"
70
        }
71
    }
72
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.