-
Notifications
You must be signed in to change notification settings - Fork 4
/
esd.pm
101 lines (83 loc) · 2.03 KB
/
esd.pm
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
#
# PACKAGE EXAMPLE
#
# This is a Perl defined macro extension module. This file should be placed into the
# directory named 'jamal' under the Perl Module library directory. This is
# E:\Perl\lib\jamal on my Windows NT. On UNIX this is something different.
#
# You can also install this program using the program jamint.pl or using jamal.pl
# with the option '-i' if you have an up to date version of Jamal
package jamal::esd;
BEGIN {
$VERSION = '2.0'; #the current module version
&jamal::require('2.0');#require jamal version
$RVERSION = &jamal::version('1.0','2.0');
$RVERSION = $VERSION unless $RVERSION;
# define package specific macros
if( $RVERSION > 1.0 ){
# &jamal::DefineMacro( 'cap' , ',x' , '<font size=+1>x</font>' );
}
# this global variable will hold all the commands
%COMMAND = ();
}
#
# This sub defines the macro 'command'
# There are two arguments. The first one is a key that orders the
# execution of the commands and that also helps to redefine commands.
# These commands defined calling this sub are 'eval'ed for each included
# source file.
#
sub command {
my $arg = shift;
# there should be a key and the command
$arg =~ /^\s+(\w+)\s+(.*)/;
my ($name,$command) = ($1,$2);
$COMMAND{$name} = $command;
return '';
}
#
# This macro can be used to clean all the commands.
#
sub nocommand {
%COMMAND = ();
return '';
}
sub include {
my $arg = shift;
$arg =~ s/^\s+//;
my ($FileName,$StartString,$StopString) = split /\s+/ , $arg;
my $output = '';
my $sw = 0;
open(F,$FileName) or die "Can not open $FileName";
while( <F> ){
chomp;
if( $sw == 0 && $_ eq $StartString ){
$sw = 1;
next;
}
if( $sw == 1 && $_ eq $StopString ){
$sw = 0;
next;
}
my $k;
for $k (keys %COMMAND ){
eval $COMMAND{$k};
}
if( $sw ){
$output .= $_ . "\n";
}
}
close F;
return $output;
}
sub execute {
my $arg = shift;
#
# If ever you want to use this file under UNIX comment this line out
#
$arg =~ s{/}{\\}g;
return `$arg`;
}
END {
}
1;