File: objects.pm

package info (click to toggle)
pica 0.4.1-10
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 536 kB
  • ctags: 78
  • sloc: perl: 2,498; makefile: 107
file content (718 lines) | stat: -rw-r--r-- 12,413 bytes parent folder | download | duplicates (2)
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
####################################################################
#
#    This file was generated using Parse::Yapp version 1.05.
#
#        Don't edit this file, use source file instead.
#
#             ANY CHANGE MADE HERE WILL BE LOST !
#
####################################################################
package objects;
use vars qw ( @ISA );
use strict;

@ISA= qw ( Parse::Yapp::Driver );
use Parse::Yapp::Driver;

#line 31 "dist/pica-0.4.1/objects.yp"

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');


sub new {
        my($class)=shift;
        ref($class)
    and $class=ref($class);

    my($self)=$class->SUPER::new( yyversion => '1.05',
                                  yystates =>
[
	{#State 0
		ACTIONS => {
			"file" => 2,
			"alarm" => 1,
			"defaults" => 4,
			"group" => 10
		},
		GOTOS => {
			'statements' => 3,
			'group' => 5,
			'statement' => 6,
			'object' => 7,
			'alarm' => 8,
			'defaults' => 9,
			'config_file' => 11,
			'file' => 12
		}
	},
	{#State 1
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 16
		}
	},
	{#State 2
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 17
		}
	},
	{#State 3
		ACTIONS => {
			"file" => 2,
			"alarm" => 1,
			"defaults" => 4,
			"group" => 10
		},
		DEFAULT => -1,
		GOTOS => {
			'object' => 7,
			'defaults' => 9,
			'alarm' => 8,
			'group' => 5,
			'statement' => 18,
			'file' => 12
		}
	},
	{#State 4
		ACTIONS => {
			"{" => 19
		}
	},
	{#State 5
		DEFAULT => -6
	},
	{#State 6
		DEFAULT => -2
	},
	{#State 7
		DEFAULT => -5
	},
	{#State 8
		DEFAULT => -27
	},
	{#State 9
		DEFAULT => -4
	},
	{#State 10
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 20
		}
	},
	{#State 11
		ACTIONS => {
			'' => 21
		}
	},
	{#State 12
		DEFAULT => -26
	},
	{#State 13
		DEFAULT => -38
	},
	{#State 14
		DEFAULT => -36
	},
	{#State 15
		DEFAULT => -37
	},
	{#State 16
		DEFAULT => -9,
		GOTOS => {
			'@1-2' => 22
		}
	},
	{#State 17
		ACTIONS => {
			"{" => 23
		}
	},
	{#State 18
		DEFAULT => -3
	},
	{#State 19
		DEFAULT => -28,
		GOTOS => {
			'attributes' => 24
		}
	},
	{#State 20
		DEFAULT => -20,
		GOTOS => {
			'@4-2' => 25
		}
	},
	{#State 21
		DEFAULT => -0
	},
	{#State 22
		ACTIONS => {
			"{" => 26
		}
	},
	{#State 23
		DEFAULT => -28,
		GOTOS => {
			'attributes' => 27
		}
	},
	{#State 24
		ACTIONS => {
			'WORD' => 29,
			"}" => 31,
			"vars" => 32
		},
		GOTOS => {
			'attribute' => 28,
			'vars_env' => 30
		}
	},
	{#State 25
		ACTIONS => {
			"{" => 33
		}
	},
	{#State 26
		DEFAULT => -11,
		GOTOS => {
			'alarm_attributes' => 34
		}
	},
	{#State 27
		ACTIONS => {
			'WORD' => 29,
			"}" => 35,
			"vars" => 32
		},
		GOTOS => {
			'attribute' => 28,
			'vars_env' => 30
		}
	},
	{#State 28
		DEFAULT => -30
	},
	{#State 29
		ACTIONS => {
			"=" => 36
		}
	},
	{#State 30
		DEFAULT => -29
	},
	{#State 31
		DEFAULT => -7
	},
	{#State 32
		ACTIONS => {
			"{" => 37
		}
	},
	{#State 33
		DEFAULT => -22,
		GOTOS => {
			'group_attributes' => 38
		}
	},
	{#State 34
		ACTIONS => {
			'WORD' => 29,
			"uses" => 42,
			"}" => 43,
			"vars" => 32
		},
		GOTOS => {
			'attribute' => 39,
			'vars_env' => 41,
			'uses_env' => 40
		}
	},
	{#State 35
		DEFAULT => -8
	},
	{#State 36
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 44
		}
	},
	{#State 37
		DEFAULT => -33,
		GOTOS => {
			'vars' => 45
		}
	},
	{#State 38
		ACTIONS => {
			"file" => 2,
			"alarm" => 1,
			'WORD' => 29,
			"}" => 49,
			"vars" => 32
		},
		GOTOS => {
			'object' => 47,
			'attribute' => 46,
			'alarm' => 8,
			'vars_env' => 48,
			'file' => 12
		}
	},
	{#State 39
		DEFAULT => -12
	},
	{#State 40
		DEFAULT => -14
	},
	{#State 41
		DEFAULT => -13
	},
	{#State 42
		ACTIONS => {
			"{" => 50
		}
	},
	{#State 43
		DEFAULT => -10
	},
	{#State 44
		ACTIONS => {
			";" => 51
		}
	},
	{#State 45
		ACTIONS => {
			'WORD' => 53,
			"}" => 54
		},
		GOTOS => {
			'var' => 52
		}
	},
	{#State 46
		DEFAULT => -24
	},
	{#State 47
		DEFAULT => -23
	},
	{#State 48
		DEFAULT => -25
	},
	{#State 49
		DEFAULT => -21
	},
	{#State 50
		DEFAULT => -15,
		GOTOS => {
			'@2-2' => 55
		}
	},
	{#State 51
		DEFAULT => -31
	},
	{#State 52
		DEFAULT => -34
	},
	{#State 53
		ACTIONS => {
			"=" => 56
		}
	},
	{#State 54
		DEFAULT => -32
	},
	{#State 55
		DEFAULT => -18,
		GOTOS => {
			'deps' => 57
		}
	},
	{#State 56
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 58
		}
	},
	{#State 57
		ACTIONS => {
			"file" => 2
		},
		DEFAULT => -16,
		GOTOS => {
			'@3-4' => 60,
			'file' => 59
		}
	},
	{#State 58
		ACTIONS => {
			";" => 61
		}
	},
	{#State 59
		DEFAULT => -19
	},
	{#State 60
		ACTIONS => {
			"}" => 62
		}
	},
	{#State 61
		DEFAULT => -35
	},
	{#State 62
		DEFAULT => -17
	}
],
                                  yyrules  =>
[
	[#Rule 0
		 '$start', 2, undef
	],
	[#Rule 1
		 'config_file', 1,
sub
#line 49 "dist/pica-0.4.1/objects.yp"
{
         return 'ok';
      }
	],
	[#Rule 2
		 'statements', 1, undef
	],
	[#Rule 3
		 'statements', 2, undef
	],
	[#Rule 4
		 'statement', 1, undef
	],
	[#Rule 5
		 'statement', 1, undef
	],
	[#Rule 6
		 'statement', 1, undef
	],
	[#Rule 7
		 'defaults', 4,
sub
#line 64 "dist/pica-0.4.1/objects.yp"
{
         $objref->{'defaults'} = { %attributes };
         %attributes = ();
      }
	],
	[#Rule 8
		 'file', 5,
sub
#line 74 "dist/pica-0.4.1/objects.yp"
{
         $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 = ();
      }
	],
	[#Rule 9
		 '@1-2', 0,
sub
#line 91 "dist/pica-0.4.1/objects.yp"
{ unshift @currentgroup, [ ($_[2]) ]; }
	],
	[#Rule 10
		 'alarm', 6,
sub
#line 93 "dist/pica-0.4.1/objects.yp"
{
         $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 = ();
      }
	],
	[#Rule 11
		 'alarm_attributes', 0, undef
	],
	[#Rule 12
		 'alarm_attributes', 2, undef
	],
	[#Rule 13
		 'alarm_attributes', 2, undef
	],
	[#Rule 14
		 'alarm_attributes', 2, undef
	],
	[#Rule 15
		 '@2-2', 0,
sub
#line 121 "dist/pica-0.4.1/objects.yp"
{ %alarmattributes = %attributes;
                             %attributes = (); }
	],
	[#Rule 16
		 '@3-4', 0,
sub
#line 123 "dist/pica-0.4.1/objects.yp"
{ %attributes = %alarmattributes;
                             %alarmattributes = (); }
	],
	[#Rule 17
		 'uses_env', 6, undef
	],
	[#Rule 18
		 'deps', 0, undef
	],
	[#Rule 19
		 'deps', 2, undef
	],
	[#Rule 20
		 '@4-2', 0,
sub
#line 135 "dist/pica-0.4.1/objects.yp"
{ unshift @currentgroup, [ ($_[2]) ]; }
	],
	[#Rule 21
		 'group', 6,
sub
#line 137 "dist/pica-0.4.1/objects.yp"
{
         $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 = ();
      }
	],
	[#Rule 22
		 'group_attributes', 0, undef
	],
	[#Rule 23
		 'group_attributes', 2, undef
	],
	[#Rule 24
		 'group_attributes', 2, undef
	],
	[#Rule 25
		 'group_attributes', 2,
sub
#line 165 "dist/pica-0.4.1/objects.yp"
{
         %groupvars = %{ $attributes{'vars'} };
         delete $attributes{'vars'};
      }
	],
	[#Rule 26
		 'object', 1, undef
	],
	[#Rule 27
		 'object', 1, undef
	],
	[#Rule 28
		 'attributes', 0, undef
	],
	[#Rule 29
		 'attributes', 2, undef
	],
	[#Rule 30
		 'attributes', 2, undef
	],
	[#Rule 31
		 'attribute', 4,
sub
#line 181 "dist/pica-0.4.1/objects.yp"
{
         grep /^$_[1]$/, @objectattrs or die "Unkown object property $_[1]\n";
         $attributes{$_[1]} = $_[3];
      }
	],
	[#Rule 32
		 'vars_env', 4,
sub
#line 188 "dist/pica-0.4.1/objects.yp"
{
         # print 'variables ', $_[1], "\n";
	 $attributes{'vars'} = { %vars };
	 %vars = ();
      }
	],
	[#Rule 33
		 'vars', 0, undef
	],
	[#Rule 34
		 'vars', 2, undef
	],
	[#Rule 35
		 'var', 4,
sub
#line 200 "dist/pica-0.4.1/objects.yp"
{
         $vars{$_[1]} = $_[3];
      }
	],
	[#Rule 36
		 'literal', 1, undef
	],
	[#Rule 37
		 'literal', 1, undef
	],
	[#Rule 38
		 'literal', 1, undef
	]
],
                                  @_);
    bless($self,$class);
}

#line 210 "dist/pica-0.4.1/objects.yp"


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);
	   $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;
}

1;