~ubuntu-branches/ubuntu/precise/gpsmanshp/precise-proposed

« back to all changes in this revision

Viewing changes to tclunindex.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Rogerio Reis
  • Date: 2011-10-23 16:23:13 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20111023162313-4y36jiixf4gpl2ib
Tags: 1.2.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
# This is a Tcl/Tk script to be interpreted by tclsh: \
3
 
exec tclsh "$0" "$@"
4
 
 
5
 
#       tclunindex.tcl --- removes reference to packages in a
6
 
#         Tcl package index file, version 1.1
7
 
#
8
 
#       assumes that each "package ifneeded" is in a single line
9
 
#
10
 
# Copyright (c) 2005 Miguel Filgueiras mig@ncc.up.pt Universidade do Porto
11
 
#
12
 
#    This program is free software; you can redistribute it and/or modify
13
 
#      it under the terms of the GNU General Public License as published by
14
 
#      the Free Software Foundation; either version 2 of the License, or
15
 
#      (at your option) any later version.
16
 
#
17
 
#      This program is distributed in the hope that it will be useful,
18
 
#      but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
#      GNU General Public License for more details.
21
 
#
22
 
#      You should have received a copy of the GNU General Public License
23
 
#      along with this program.
24
 
#
25
 
 
26
 
 
27
 
# last change:  3 October 2005
28
 
 
29
 
set Usage {Usage: tclunindex.tcl FILE PACKAGE [... PACKAGE]}
30
 
 
31
 
if { [llength $argv] < 2 } {
32
 
    puts stderr $Usage
33
 
    exit 1
34
 
}
35
 
 
36
 
if { [catch {set file [open [set fname [lindex $argv 0]] r]}] || \
37
 
         ! [file writable $fname] } {
38
 
    puts stderr "Cannot open file $fname"
39
 
    exit 1
40
 
}
41
 
 
42
 
proc NewTempFileName {} {
43
 
    # return name for temporary file that does not clash with existing files
44
 
 
45
 
    set t [clock seconds]
46
 
    while { [glob -nocomplain tmp-$t] != "" } { incr t 123 }
47
 
    return tmp-$t
48
 
}
49
 
 
50
 
set ntmp [NewTempFileName]
51
 
if { [catch {set tmp [open $ntmp w]}] } {
52
 
    puts stderr "Cannot open temporary file"
53
 
    exit 1
54
 
}
55
 
 
56
 
set paks [lreplace $argv 0 0]
57
 
 
58
 
while { ! [eof $file] } {
59
 
    gets $file line
60
 
    if { $paks != {} && \
61
 
             [regexp \
62
 
                 {^[ \t]*package [ \t]*ifneeded [ \t]*([a-zA-Z_0-9]+) [ \t]*} \
63
 
                  $line m p] } {
64
 
        if { [set i [lsearch -exact $paks $p]] != -1 } {
65
 
            puts "Deleting line: $line"
66
 
            set paks [lreplace $paks $i $i]
67
 
            continue
68
 
        }
69
 
    }
70
 
    puts $tmp $line
71
 
}
72
 
 
73
 
close $file
74
 
close $tmp
75
 
 
76
 
file rename -force -- $ntmp $fname
77
 
 
78
 
exit 0
79
 
 
80
 
 
81