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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
##
## Source for PICA objects file parser
## $Id: objects.yp,v 1.7.2.10 2002/06/04 23:02:43 cvs Exp $
##
##
## PICA Config File Grammar
##
## Perl Instaler and Configuration Agent (PICA)
## or
## PICA Is for C{ompetent,ompulsive,razy} Admins
##
## Copyright (C) 2001,2002 Miguel Armas, Esteban Manchado
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%{
use Data::Dumper;
my %attributes;
my %alarmattributes;
my @currentgroup;
my (%vars, %groupvars);
use vars qw($objref $currentline);
*objref = *main::objref;
$currentline = 1;
my @objectattrs = ('uid', 'gid', 'perms', 'verbatim', 'path', 'source', 'priority');
%}
%%
config_file: statements
{
return 'ok';
}
;
statements: statement
| statements statement
;
statement: defaults
| object
| group
;
defaults: 'defaults' '{' attributes '}'
{
$objref->{'defaults'} = { %attributes };
%attributes = ();
}
;
##
## File Object Definition
##
file: 'file' literal '{' attributes '}'
{
$attributes{'type'} = 'file';
if (scalar @currentgroup) {
push @{$currentgroup[0]}, $_[2];
$attributes{'group'} = ${$currentgroup[0]}[0];
}
# Check if already exists!
die "Duplicated object '$_[2]' in line ", $currentline, "\n"
if exists $objref->{$_[2]};
$objref->{$_[2]} = { %attributes };
%attributes = ();
}
;
##
## Alarm Object Definition
##
alarm: 'alarm' literal { unshift @currentgroup, [ ($_[2]) ]; }
'{' alarm_attributes '}'
{
$attributes{'type'} = 'alarm';
# Add all the members to the 'members' attribute and delete the
# temporary list
$attributes{'members'} = [ @{$currentgroup[0]}[1 ..
$#{$currentgroup[0]}] ];
shift @currentgroup;
# Add ourselves to the current group, if any
if (scalar @currentgroup) {
push @{$currentgroup[0]}, $_[2];
$attributes{'group'} = ${$currentgroup[0]}[0];
}
# Check if already exists!
die "Duplicated alarm '$_[2]' in line ", $currentline, "\n"
if exists $objref->{$_[2]};
# Add the alarm entry to $objref
$objref->{$_[2]} = { %attributes };
%attributes = ();
}
;
alarm_attributes: # Empty
| alarm_attributes attribute
| alarm_attributes vars_env
| alarm_attributes uses_env
;
uses_env: 'uses' '{' { %alarmattributes = %attributes;
%attributes = (); }
deps { %attributes = %alarmattributes;
%alarmattributes = (); }
'}'
;
deps: # Empty
| deps file
;
##
## Group Object Definition
##
group: 'group' literal { unshift @currentgroup, [ ($_[2]) ]; }
'{' group_attributes '}'
{
$attributes{'vars'} = { %groupvars };
$attributes{'type'} = 'group';
# The group is ended. Store all the members (the second to last
# elements, first is the group name) in the attribute 'members', and
# delete the members list
$attributes{'members'} = [ @{$currentgroup[0]}[1 ..
$#{$currentgroup[0]}] ];
shift @currentgroup;
# If there is any group out there, add ourselves to its member list
if (scalar @currentgroup) {
push @{$currentgroup[0]}, $_[2];
$attributes{'group'} = ${$currentgroup[0]}[0];
}
# Check if already exists!
die "Duplicated group '$_[2]' in line ", $currentline, "\n"
if exists $objref->{$_[2]};
# Add group entry to $objref
$objref->{$_[2]} = { %attributes };
%attributes = ();
%groupvars = ();
}
;
group_attributes: # Empty
| group_attributes object
| group_attributes attribute
| group_attributes vars_env
{
%groupvars = %{ $attributes{'vars'} };
delete $attributes{'vars'};
}
;
object: file
| alarm
;
attributes: # Empty
| attributes vars_env
| attributes attribute
;
attribute: WORD '=' literal ';'
{
grep /^$_[1]$/, @objectattrs or die "Unkown object property $_[1]\n";
$attributes{$_[1]} = $_[3];
}
;
vars_env: 'vars' '{' vars '}'
{
# print 'variables ', $_[1], "\n";
$attributes{'vars'} = { %vars };
%vars = ();
}
;
vars: # Empty
| vars var
;
var: WORD '=' literal ';'
{
$vars{$_[1]} = $_[3];
}
;
literal: WORD
| SQUOTED
| DQUOTED
;
%%
use vars qw($inputfile);
sub _Error {
exists $_[0]->YYData->{ERRMSG}
and do {
print $_[0]->YYData->{ERRMSG};
delete $_[0]->YYData->{ERRMSG};
die;
};
print STDERR "Syntax error reading objects file at line ", $currentline, ": expecting ";
# Expected tokens
my @exptoks;
foreach my $i ($_[0]->YYExpect) {
push @exptoks, tokname($i);
}
if (scalar @exptoks > 1) {
print STDERR "one of ", join (',', @exptoks), ", ";
} else {
print STDERR $exptoks[0], ', ';
}
# Found token
print STDERR "found ", tokname($_[0]->YYCurtok), ".\n";
}
sub tokname {
my $token = shift ;
if ($token eq 'SQUOTED') {
return 'single quote';
} elsif ($token eq 'DQUOTED') {
return 'double quote';
} elsif ($token eq 'WORD') {
return 'word';
}
return "'$token'";
}
sub _Lexer {
my $parser = shift;
if (! $parser->YYData->{INPUT}) {
if ($inputfile) {
open F, $inputfile or die "Can't open config file $inputfile";
$inputfile = "";
}
$parser->YYData->{INPUT} or $parser->YYData->{INPUT} = join '', <F>
or return ('', undef);
}
while ($parser->YYData->{INPUT} =~ /^[ \t\n]+/ or
$parser->YYData->{INPUT} =~ /^#.*/) {
$parser->YYData->{INPUT} =~ s/^(\n+)//;
$currentline += length ($1 or "");
$parser->YYData->{INPUT} =~ s/^[ \t]+//;
$parser->YYData->{INPUT} =~ s/^#.*//;
}
for ($parser->YYData->{INPUT}) {
if (s:^((\w|/|\.|-)+)::) {
($1 eq 'defaults') and return ('defaults', 'defaults');
($1 eq 'file') and return ('file', 'file');
($1 eq 'alarm') and return ('alarm', 'alarm');
($1 eq 'group') and return ('group', 'group');
($1 eq 'vars') and return ('vars', 'vars');
($1 eq 'uses') and return ('uses', 'uses');
return ('WORD', $1);
}
s/^"(([^"]|\\")*)"//
and return ('DQUOTED', $1);
s/^'(([^']|\\')*)'//
and return ('SQUOTED', $1);
s/^(.)//
and return($1,$1);
}
}
sub fillObjRef {
my $self;
($self, $inputfile) = (shift, shift);
return ($self->YYParse (yylex => \&_Lexer, yyerror => \&_Error))?1:0;
}
|