File: fsview.src

package info (click to toggle)
wml 2.0.12ds1-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,432 kB
  • ctags: 116
  • sloc: perl: 5,634; sh: 3,663; makefile: 1,004
file content (200 lines) | stat: -rw-r--r-- 4,858 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
##
##  wml::imp::fsview - View Box for Filesystem Resource
##  Copyright (c) 1997-2001 Ralf S. Engelschall, All Rights Reserved. 
##

#  The <preserve>/<restore> tags with multiple arguments require WML 2.0.3
#use wml::mod::version
<require 2.0.3 />

#use wml::std::tags

<define-tag fsview>
<preserve src headercolor bodycolor width hl hlcolor />
<set-var %attributes />
<perl>
    $path    = "<get-var src />";
    $width   = "<or <get-var width /> 90% />";
    $hl      = "<get-var hl />";
    $hlcolor = "<or <get-var hlcolor /> #a02020 />";

    if ($hl =~ m|,|) {
        @HL = split(',', $hl);
    }
    else {
        @HL = ($hl);
    }

    #   some special colors
    if ($path =~ m|\.html?$|) {
        $col1 = "<or <get-var headercolor /> #d0dfd0 />";
        $col2 = "<or <get-var bodycolor /> #e0f0e0 />";
    }
    elsif ($path =~ m|\.wml$|) {
        $col1 = "<or <get-var headercolor /> #dfc0c0 />";
        $col2 = "<or <get-var bodycolor /> #ffe0e0 />";
    }
    else {
        $col1 = "<or <get-var headercolor /> #d0d0d0 />";
        $col2 = "<or <get-var bodycolor /> #f0f0f0 />";
    }

    <perl:print>\
       <table* border=0 width="$width" cellpadding=10 cellspacing=0>\
       <tr*>\
       <td* align=left bgcolor="$col1">\
    </perl:print>

    if (-f $path) {
        #
        #   source is a file
        #
        <perl:print>\
           <a href="$path">\
           <font size=5>[ <b>FILE</b> ]</font>\
           </a>\
           &nbsp;&nbsp;&nbsp;\
           <font size=5 color="#404080"><b><tt>$path</tt></b></font>\
           <br />\
           <font* size=-1 color="#606090"><tt*>\
        </perl:print>
        open(FP, "ls -la $path |");
        $line = <*FP>;
        @entries = split(/ +/, $line); 
        ($p, $o, $g, $f) = ($entries[0], $entries[2], $entries[3], $entries[8]);
        $line = "[$p $o $g]";
        $line =~ s|&|&amp;|g;
        $line =~ s|<|&lt;|g;
        $line =~ s|>|&gt;|g;
        <perl:print: $line />
        close(FP);
        <perl:print>\
           </tt*></font*>\
           </td*>\
           </tr*>\
           <tr*>\
           <td* bgcolor="$col2" align=left>\
           <pre*>
</perl:print>
        open(FP, "<$path");
        while (<*FP>) {
            s|&|&amp;|g;
            s|<|&lt;|g;
            s|>|&gt;|g;
            if ($hl ne "") {
                foreach $mark (@HL) {
                    if (m|$mark|) {
                        s|^|<b*><font* color=\"$hlcolor\">|;
                        s|$|</font*></b*>|;
                    }
                }
            }
            <perl:print: $_ />
        }
        close(FP);
        <perl:print></pre*>
</perl:print>
    }
    elsif (-d $path) {
        #
        #   source is a file
        #
        $path =~ s|/$||g;
        $path =~ s|$|/|g;

        <perl:print>\
           <font size=5>[ <b>DIR</b> ]</font>\
           &nbsp;&nbsp;&nbsp;\
           <font size=5 color="#404080"><b><tt>$path</tt></b></font>\
           <br />\
           <font* size=-1 color="#606090"><tt*>\
        </perl:print>
        open(FP, "ls -dla $path |");
        $line = <*FP>;
        @entries = split(/ +/, $line); 
        ($p, $o, $g, $f) = ($entries[0], $entries[2], $entries[3], $entries[8]);
        $line = "[$p $o $g]";
        $line =~ s|&|&amp;|g;
        $line =~ s|<|&lt;|g;
        $line =~ s|>|&gt;|g;
        <perl:print: $line />
        close(FP);
        <perl:print>\
           </tt*></font*>\
           </td*>\
           </tr*>\
           <tr*>\
           <td* bgcolor="#$col2" align=left>\
           <pre*>
</perl:print>
        open(FP, "ls -la $path |");
        while (<*FP>) {
            s|&|&amp;|g;
            s|<|&lt;|g;
            s|>|&gt;|g;
            if ($hl ne "") {
                foreach $mark (@HL) {
                    if (m|$mark|) {
                        s|^|<b*><font* color=\"$hlcolor\">|;
                        s|$|</font*></b*>|;
                    }
                }
            }
            <perl:print: $_ />
        }
        close(FP);
        <perl:print></pre*>
</perl:print>

    }
    else {
        <perl:print><b>ERROR: Cannot open file '<tt>$path</tt>'</b><p*>
</perl:print>
    }
    <perl:print>\
       </td*>\
       </tr*>\
       </table*>\
    </perl:print>
</perl>
<restore  src headercolor bodycolor width hl hlcolor />
</define-tag>

##EOF##
__END__

=head1 NAME

wml::imp::fsview - View Box for Filesystem Resource

=head1 SYNOPSIS

 #use wml::imp::fsview

 <fsview src="file" [hl="keywords"]>

=head1 DESCRIPTION

This tag creates a view box for an external source I<file> and optionally
highlights lines containing I<keywords>.

=head1 AUTHORS

 Ralf S. Engelschall
 rse@engelschall.com
 www.engelschall.com

 Denis Barbier
 barbier@engelschall.com

=head1 REQUIRES

 Internal: P1, P2, P3
 External: --

=head1 SEE ALSO

-

=cut