ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleDoc.pm
Revision: 1.7.4.1.2.1
Committed: Thu Mar 13 12:54:49 2008 UTC (17 years, 2 months ago) by muzaffar
Content type: text/plain
Branch: SCRAM_V2_0
CVS Tags: V2_2_2, V2_2_2_pre4, V2_2_2_pre3, V2_2_2_pre2, V2_2_2_pre1, V2_2_2-pre1, V2_2_1, forV2_2_1, V2_2_0, sm100112, V2_1_4, V2_1_3, V2_1_2, V2_1_1, V2_1_0, V2_0_6, V2_0_5, V2_0_4, V2_0_4_relcand2, V2_0_4_relcand1, V2_0_3, V2_0_3_relcand3, V2_0_3_relcand2, V2_0_3_relcand1, V2_0_2, V2_0_2_relcand1, V2_0_1, V2_0_1_relcand4, V2_0_1_relcand3, V2_0_1_relcand2, V2_0_1_relcand1, V2_0_0_relcand4, V2_0_0, V2_0_0_relcand3, V2_0_0_relcand2, V2_0_0_relcand1
Changes since 1.7.4.1: +1 -1 lines
Log Message:
scram v2.0 for multiple arch support and big lib stuff

File Contents

# Content
1 #
2 # SimpleDoc.pm
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 # -----------
8 # Simple multi parsing functionality and group manipulation
9 #
10 # Interface
11 # ---------
12 # new([DocVersionTag]) : A new ActiveDoc object. You can also
13 # specify an alternative doc version tag
14 # filetoparse([filename]) : Set/Return the filename of document
15 # newparse(parselabel) : Create a new parse type
16 # parse(parselabel) : Parse the document file for the given parse level
17 # checktag(tagname, hashref, param) : check for existence of param in
18 # hashref from a tag call
19 # currentparser() : return the current parser object
20 # currentparsename([name]) : get/set current parse name
21 #
22 # filenameref(string) : A string to refer to the file in parse error messages
23 # etc. Default is filetoparse
24 # --------------- Error handling routines ---------------
25 # verbose(string) : Print string in verbosity mode
26 # verbosity(0|1) : verbosity off|on
27 # parseerror(string) : print error and associate with line number etc.
28 # error(string) : handle an error
29
30 package ActiveDoc::SimpleDoc;
31 require 5.004;
32 use ActiveDoc::Parse;
33
34 sub new()
35 {
36 my $class=shift;
37 $self={};
38 bless $self, $class;
39 return $self;
40 }
41
42 sub filenameref()
43 {
44 my $self=shift;
45 if ( @_ )
46 {
47 $self->{filenameref}=shift;
48 }
49 return (defined $self->{filenameref})?$self->{filenameref} : $self->filetoparse();
50 }
51
52 sub verbosity()
53 {
54 my $self=shift;
55 $self->{verbose}=shift;
56 }
57
58 sub verbose()
59 {
60 my $self=shift;
61 my $string=shift;
62
63 if ( $self->{verbose} )
64 {
65 print ">".ref($self)."($self) : \n->".$string."\n";
66 }
67 }
68
69 # ----- parse related routines --------------
70 sub parse()
71 {
72 my $self=shift;
73 $parselabel=shift;
74 my $fhead=shift || "";
75 my $ftail=shift || "";
76 my $file=$self->filetoparse();
77
78 if ( -f $file )
79 {
80 if ( exists $self->{parsers}{$parselabel} )
81 {
82 $self->verbose("Parsing $parselabel in file $file");
83 $self->{currentparsename}=$parselabel;
84 $self->{currentparser}=$self->{parsers}{$parselabel};
85 # Parse and store the returned data in content (only for Streams style):
86 $self->{parsers}{$parselabel}->filehead($fhead);
87 $self->{parsers}{$parselabel}->filetail($ftail);
88 $self->{content} = $self->{parsers}{$parselabel}->parse($file,@_)->data();
89 delete $self->{currentparser};
90 $self->{currentparsename}="";
91 $self->verbose("Parse $parselabel Complete");
92 }
93 }
94 else
95 {
96 $self->error("Cannot parse \"$parselabel\" - file $file not known");
97 }
98 }
99
100 sub parsefilelist()
101 {
102 my $self=shift;
103 my $parselabel=shift;
104 my ($filenames)=@_;
105
106 if ( exists $self->{parsers}{$parselabel} )
107 {
108 $self->verbose("ParsingFileList: Label = $parselabel (files = ".join(",",@$filenames)." ");
109 $self->{currentparsename}=$parselabel;
110 $self->{currentparser}=$self->{parsers}{$parselabel};
111 $self->{parsers}{$parselabel}->parsefilelist($filenames);
112 delete $self->{currentparser};
113 $self->{currentparsename}="";
114 $self->verbose("ParseFileList $parselabel Complete");
115 }
116 else
117 {
118 $self->error("Cannot parse \"$parselabel\" - Unknown parser!!");
119 }
120 }
121
122 sub currentparsename()
123 {
124 my $self=shift;
125 @_?$self->{currentparsename}=shift
126 :(defined $self->{currentparsename}?$self->{currentparsename}:"");
127 }
128
129 sub currentparser()
130 {
131 my $self=shift;
132 return $self->{currentparser};
133 }
134
135 sub newparse()
136 {
137 my $self=shift;
138 my $parselabel=shift;
139 my $dataclass=shift;
140 my $parse_style=shift;
141 $dataclass ||= "ParsedDoc";
142 $parse_style ||= 'Objects';
143 $self->{parsers}{$parselabel}=ActiveDoc::Parse->new($dataclass,$parse_style,shift,shift);
144 }
145
146 sub filetoparse()
147 {
148 my $self=shift;
149
150 if ( @_ )
151 {
152 $self->{filename}=shift;
153 }
154 return $self->{filename};
155 }
156
157 sub content()
158 {
159 my $self=shift;
160 return $self->{content};
161 }
162
163 # -------- Error Handling and Error services --------------
164 sub error()
165 {
166 my $self=shift;
167 my $string=shift;
168
169 die $string."\n";
170 }
171
172 sub parseerror
173 {
174 my $self=shift;
175 my $string=shift;
176
177 if ( $self->currentparsename() eq "" )
178 {
179 $self->error("Error In file ".$self->filenameref."\n".$string);
180 }
181 else
182 {
183 $line=$self->line();
184 print "Parse Error in ".$self->filenameref().", line ".
185 $line."\n";
186 print $string."\n";
187 exit;
188 }
189 }
190
191 sub checktag()
192 {
193 my $self=shift;
194 my $tagname=shift;
195 my $hashref=shift;
196 my $param=shift;
197
198 if ( ! exists $$hashref{$param} )
199 {
200 $self->parseerror("Incomplete Tag <$tagname> : $param required");
201 }
202 }
203
204 # -- dummy tag routines
205 sub doc()
206 {
207 my $self=shift;
208 }
209
210 sub doc_()
211 {
212 my $self=shift;
213 }
214
215 1;