ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/Parse.pm
Revision: 1.11.4.1.2.1
Committed: Thu Mar 13 12:54:49 2008 UTC (17 years, 1 month 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.11.4.1: +3 -2 lines
Log Message:
scram v2.0 for multiple arch support and big lib stuff

File Contents

# Content
1 #
2 # Parse.pm
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 # -----------
8 # maintain parse configurations
9 #
10 # Interface
11 # ---------
12 # new() : A new Parse object
13 # addtag(name,start,text,end,$object) : Add a new tag
14 # addgrouptags() : add <Group> tag functionality
15 # addignoretags() : add <ignore> tag functionality
16 # parse(filename,[streamhandle], [streamexcludetag]) :
17 # parse the given file - turn on the stream
18 # function of the switcher if a filehandle
19 # supplied as a second argument
20 # line() : return the current linenumber in the file
21 # tagstartline() : return the linenumber of the last tag opening
22 # includeparse(Parse) : include the settings from another parse object
23 # tags() : return list of defined tags
24 # cleartags() : clear of all tags
25 # opencontext(name) : open a parse context
26 # closecontext(name) : close a parse context
27 # includecontext(name) : Process when in a given context
28 # excludecontext(name) : No Processing when given context
29 # contexttag(tagname) : Register the tagname as one able to change context
30 # if not registerd - the close tag will be ignored
31 # too if outside of the specified context!
32
33 package ActiveDoc::Parse;
34 require 5.004;
35
36 sub new()
37 {
38 my $class=shift;
39 $self={};
40 bless $self, $class;
41 my ($dataclass, $parse_style,$keep_running_onerr,$xml)=@_;
42 require SCRAM::Plugins::DocParser;
43 $self->{xml}=$xml || 0;
44 $self->{xmlparser} = new SCRAM::Plugins::DocParser($dataclass,$parse_style,$keep_running_onerr);
45 return $self;
46 }
47
48 sub parsefilelist()
49 {
50 my $self=shift;
51 my ($files)=@_;
52 print __PACKAGE__."::parsefilelist(): Not used?\n";
53 }
54
55 sub filehead ()
56 {
57 my $self=shift;
58 my $data=@_;
59 if (@_)
60 {
61 $self->{filehead}=shift;
62 return;
63 }
64 return $self->{filehead} || "";
65 }
66
67 sub filetail ()
68 {
69 my $self=shift;
70 if (@_)
71 {
72 $self->{filetail}=shift;
73 return;
74 }
75 return $self->{filetail} || "";
76 }
77
78 sub parse()
79 {
80 my $self=shift;
81 my ($file)=@_;
82 if (!$self->{xmlparser}->parse($file,$self->getfilestring_($file)))
83 {
84 print STDERR "**** ERROR: Failed parsing file: $file.\n";
85 }
86 return $self;
87 }
88
89 sub getfilestring_()
90 {
91 my $self=shift;
92 my ($file)=@_;
93 my $filestring="";
94 my $read=0;
95 if (($file!~/\.xml$/) && ($self->{xml}==0))
96 {
97 eval("use SCRAM::Plugins::Doc2XML");
98 if (!$@)
99 {
100 my $xmlconvertor = SCRAM::Plugins::Doc2XML->new();
101 my $xml=$xmlconvertor->convert($file);
102 $filestring = join("",@$xml);
103 $xmlconvertor->clean();
104 $read=1;
105 }
106 }
107 if (!$read)
108 {
109 open (IN, "< $file") or die __PACKAGE__.": Cannot read file $file: $!\n";
110 $filestring = join("", <IN>);
111 close (IN) or die __PACKAGE__.": Cannot read file $file: $!\n";
112 }
113 $filestring = $self->filehead().$filestring.$self->filetail();
114 # Strip spaces at the beginning and end of the line:
115 $filestring =~ s/^\s+//g;
116 $filestring =~ s/\s+$//g;
117 $self->{filestring}=$filestring;
118 return $filestring;
119 }
120
121 sub data()
122 {
123 my $self=shift;
124 return $self->{xmlparser}->getOutput();
125 }
126
127 sub includeparse
128 {
129 my $self=shift;
130 my $obj=shift;
131 my $tag;
132
133 # copy the tags from the remote parse object
134 foreach $tag ( $obj->tags() )
135 {
136 $self->addtag($tag,$obj->{tags}->tagsettings($tag));
137 }
138 }
139
140 sub addtag
141 {
142 my $self=shift;
143 $self->{tags}->addtag(@_);
144 }
145
146 1;