Subversion Repositories gelsvn

Rev

Rev 198 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 198 Rev 217
Line 10... Line 10...
10
# Pragmas
10
# Pragmas
11
# ************************************************************
11
# ************************************************************
12
 
12
 
13
use strict;
13
use strict;
14
use FileHandle;
14
use FileHandle;
15
use File::Basename;
-
 
16
 
15
 
17
use Parser;
16
use Parser;
18
 
17
 
19
use vars qw(@ISA);
18
use vars qw(@ISA);
20
@ISA = qw(Parser);
19
@ISA = qw(Parser);
21
 
20
 
22
# ************************************************************
21
# ************************************************************
23
# Data Section
22
# Data Section
24
# ************************************************************
23
# ************************************************************
25
 
24
 
-
 
25
my($assign_key)  = 'assign';
-
 
26
my($gassign_key) = 'global_assign';
-
 
27
 
26
my(@statekeys) = ('global', 'include', 'template', 'ti',
28
my(@statekeys) = ('global', 'include', 'template', 'ti',
27
                  'dynamic', 'static', 'relative', 'addtemp',
29
                  'dynamic', 'static', 'relative', 'addtemp',
28
                  'addproj', 'progress', 'toplevel', 'baseprojs',
30
                  'addproj', 'progress', 'toplevel', 'baseprojs',
29
                  'feature_file', 'features', 'hierarchy',
31
                  'feature_file', 'features', 'hierarchy',
30
                  'name_modifier', 'apply_project', 'into', 'use_env',
32
                  'name_modifier', 'apply_project', 'into', 'use_env',
31
                  'expand_vars',
33
                  'expand_vars', 'language',
32
                 );
34
                 );
33
 
35
 
34
my(%all_written) = ();
36
my(%all_written) = ();
-
 
37
my($onVMS) = ($^O eq 'VMS');
35
 
38
 
36
# ************************************************************
39
# ************************************************************
37
# Subroutine Section
40
# Subroutine Section
38
# ************************************************************
41
# ************************************************************
39
 
42
 
Line 76... Line 79...
76
  $self->{'addproj'}         = $addproj;
79
  $self->{'addproj'}         = $addproj;
77
  $self->{'toplevel'}        = $toplevel;
80
  $self->{'toplevel'}        = $toplevel;
78
  $self->{'files_written'}   = {};
81
  $self->{'files_written'}   = {};
79
  $self->{'real_fwritten'}   = [];
82
  $self->{'real_fwritten'}   = [];
80
  $self->{'reading_global'}  = 0;
83
  $self->{'reading_global'}  = 0;
81
  $self->{'global_assign'}   = {};
84
  $self->{$gassign_key}      = {};
82
  $self->{'assign'}          = {};
85
  $self->{$assign_key}       = {};
83
  $self->{'baseprojs'}       = $baseprojs;
86
  $self->{'baseprojs'}       = $baseprojs;
84
  $self->{'dynamic'}         = $dynamic;
87
  $self->{'dynamic'}         = $dynamic;
85
  $self->{'static'}          = $static;
88
  $self->{'static'}          = $static;
86
  $self->{'feature_file'}    = $feature;
89
  $self->{'feature_file'}    = $feature;
87
  $self->{'features'}        = $features;
90
  $self->{'features'}        = $features;
Line 91... Line 94...
91
  $self->{'into'}            = $into;
94
  $self->{'into'}            = $into;
92
  $self->{'language'}        = $language;
95
  $self->{'language'}        = $language;
93
  $self->{'use_env'}         = $use_env;
96
  $self->{'use_env'}         = $use_env;
94
  $self->{'expand_vars'}     = $expandvars;
97
  $self->{'expand_vars'}     = $expandvars;
95
  $self->{'convert_slashes'} = $self->convert_slashes();
98
  $self->{'convert_slashes'} = $self->convert_slashes();
-
 
99
  $self->{'case_tolerant'}   = $self->case_insensitive();
96
 
100
 
97
  return $self;
101
  return $self;
98
}
102
}
99
 
103
 
100
 
104
 
Line 197... Line 201...
197
sub parse_assignment {
201
sub parse_assignment {
198
  my($self)   = shift;
202
  my($self)   = shift;
199
  my($line)   = shift;
203
  my($line)   = shift;
200
  my($values) = shift;
204
  my($values) = shift;
201
 
205
 
202
  if ($line =~ /^(\w+(::\w+)*)\s*\+=\s*(.*)?/) {
206
  if ($line =~ /^(\w+(::\w+)*)\s*([\-+]?=)\s*(.*)?/) {
203
    my($name)  = lc($1);
-
 
204
    my($value) = $3;
-
 
205
    push(@$values, 'assign_add', $name, $value);
-
 
206
    return 1;
-
 
207
  }
-
 
208
  elsif ($line =~ /^(\w+(::\w+)*)\s*=\s*(.*)?/) {
-
 
209
    my($name)  = lc($1);
-
 
210
    my($value) = $3;
-
 
211
    push(@$values, 'assignment', $name, $value);
207
    push(@$values, $3, lc($1), $4);
212
    return 1;
-
 
213
  }
-
 
214
  elsif ($line =~ /^(\w+(::\w+)*)\s*\-=\s*(.*)?/) {
-
 
215
    my($name)  = lc($1);
-
 
216
    my($value) = $3;
-
 
217
    push(@$values, 'assign_sub', $name, $value);
-
 
218
    return 1;
208
    return 1;
219
  }
209
  }
220
 
210
 
221
  return 0;
211
  return 0;
222
}
212
}
Line 246... Line 236...
246
      $errorString = "Did not find the end of the $type";
236
      $errorString = "Did not find the end of the $type";
247
      $status = 0;
237
      $status = 0;
248
    }
238
    }
249
    else {
239
    else {
250
      if (defined $parents) {
240
      if (defined $parents) {
251
        my(@parents) = ();
-
 
252
        $parents =~ s/^://;
241
        $parents =~ s/^:\s*//;
253
        foreach my $parent (split(',', $parents)) {
-
 
254
          $parent =~ s/^\s+//;
-
 
255
          $parent =~ s/\s+$//;
242
        $parents =~ s/\s+$//;
256
          if ($parent ne '') {
-
 
257
            push(@parents, $parent);
243
        my(@parents) = split(/\s*,\s*/, $parents);
258
          }
-
 
259
        }
-
 
260
        if (!defined $parents[0]) {
244
        if (!defined $parents[0]) {
261
          ## The : was used, but no parents followed.  This
245
          ## The : was used, but no parents followed.  This
262
          ## is an error.
246
          ## is an error.
263
          $errorString = 'No parents listed';
247
          $errorString = 'No parents listed';
264
          $status = 0;
248
          $status = 0;
Line 282... Line 266...
282
    my($name)    = $2;
266
    my($name)    = $2;
283
    my($parents) = $3;
267
    my($parents) = $3;
284
    my(@names)   = split(/\s*,\s*/, $name);
268
    my(@names)   = split(/\s*,\s*/, $name);
285
 
269
 
286
    if (defined $parents) {
270
    if (defined $parents) {
287
      my(@parents) = ();
-
 
288
      $parents =~ s/^://;
271
      $parents =~ s/^:\s*//;
289
      foreach my $parent (split(',', $parents)) {
-
 
290
        $parent =~ s/^\s+//;
-
 
291
        $parent =~ s/\s+$//;
272
      $parents =~ s/\s+$//;
292
        if ($parent ne '') {
-
 
293
          push(@parents, $parent);
273
      my(@parents) = split(/\s*,\s*/, $parents);
294
        }
-
 
295
      }
-
 
296
      if (!defined $parents[0]) {
274
      if (!defined $parents[0]) {
297
        ## The : was used, but no parents followed.  This
275
        ## The : was used, but no parents followed.  This
298
        ## is an error.
276
        ## is an error.
299
        $errorString = 'No parents listed';
277
        $errorString = 'No parents listed';
300
        $status = 0;
278
        $status = 0;
Line 381... Line 359...
381
    }
359
    }
382
    else {
360
    else {
383
      my(@values) = ();
361
      my(@values) = ();
384
      if (defined $validNames && $self->parse_assignment($line, \@values)) {
362
      if (defined $validNames && $self->parse_assignment($line, \@values)) {
385
        if (defined $$validNames{$values[1]}) {
363
        if (defined $$validNames{$values[1]}) {
386
          if ($values[0] eq 'assignment') {
364
          if ($values[0] eq '=') {
387
            $self->process_assignment($values[1], $values[2], $flags);
365
            $self->process_assignment($values[1], $values[2], $flags);
388
          }
366
          }
389
          elsif ($values[0] eq 'assign_add') {
367
          elsif ($values[0] eq '+=') {
390
            $self->process_assignment_add($values[1], $values[2], $flags);
368
            $self->process_assignment_add($values[1], $values[2], $flags);
391
          }
369
          }
392
          elsif ($values[0] eq 'assign_sub') {
370
          elsif ($values[0] eq '-=') {
393
            $self->process_assignment_sub($values[1], $values[2], $flags);
371
            $self->process_assignment_sub($values[1], $values[2], $flags);
394
          }
372
          }
395
        }
373
        }
396
        else {
374
        else {
397
          ($status,
375
          ($status,
Line 417... Line 395...
417
}
395
}
418
 
396
 
419
 
397
 
420
sub base_directory {
398
sub base_directory {
421
  my($self) = shift;
399
  my($self) = shift;
422
  return basename($self->getcwd());
400
  return $self->mpc_basename($self->getcwd());
423
}
401
}
424
 
402
 
425
 
403
 
426
sub generate_default_file_list {
404
sub generate_default_file_list {
427
  my($self)    = shift;
405
  my($self)    = shift;
428
  my($dir)     = shift;
406
  my($dir)     = shift;
429
  my($exclude) = shift;
407
  my($exclude) = shift;
-
 
408
  my($fileexc) = shift;
430
  my($recurse) = shift;
409
  my($recurse) = shift;
431
  my($dh)      = new FileHandle();
410
  my($dh)      = new FileHandle();
432
  my(@files)   = ();
411
  my(@files)   = ();
433
 
412
 
434
  if (opendir($dh, $dir)) {
413
  if (opendir($dh, $dir)) {
435
    my($need_dir) = ($dir ne '.');
414
    my($need_dir) = ($dir ne '.');
436
    my($skip)     = 0;
415
    my($skip)     = 0;
437
    foreach my $file (grep(!/^\.\.?$/, readdir($dh))) {
416
    foreach my $file (grep(!/^\.\.?$/, readdir($dh))) {
438
      $file =~ s/\.dir$// if ($^O eq 'VMS');
417
      $file =~ s/\.dir$// if ($onVMS);
439
 
418
 
440
      ## Prefix each file name with the directory only if it's not '.'
419
      ## Prefix each file name with the directory only if it's not '.'
441
      my($full) = ($need_dir ? "$dir/" : '') . $file;
420
      my($full) = ($need_dir ? "$dir/" : '') . $file;
442
 
421
 
443
      if (defined $$exclude[0]) {
422
      if (defined $$exclude[0]) {
Line 449... Line 428...
449
        }
428
        }
450
      }
429
      }
451
 
430
 
452
      if ($skip) {
431
      if ($skip) {
453
        $skip = 0;
432
        $skip = 0;
-
 
433
        $$fileexc = 1 if (defined $fileexc);
454
      }
434
      }
455
      else {
435
      else {
456
        if ($recurse && -d $full) {
436
        if ($recurse && -d $full) {
457
          push(@files,
437
          push(@files,
458
               $self->generate_default_file_list($full, $exclude, $recurse));
438
               $self->generate_default_file_list($full, $exclude,
-
 
439
                                                 $fileexc, $recurse));
459
        }
440
        }
460
        else {
441
        else {
461
          push(@files, $full);
442
          push(@files, $full);
462
        }
443
        }
463
      }
444
      }
Line 493... Line 474...
493
  my($self) = shift;
474
  my($self) = shift;
494
  my($file) = shift;
475
  my($file) = shift;
495
  my($key)  = lc($file);
476
  my($key)  = lc($file);
496
 
477
 
497
  if (defined $self->{'files_written'}->{$key}) {
478
  if (defined $self->{'files_written'}->{$key}) {
498
    $self->warning("$self->{'grammar_type'} $file has " .
479
    $self->warning("$self->{'grammar_type'} $file " .
-
 
480
                   ($self->{'case_tolerant'} ?
499
                   "possibly been overwritten.");
481
                           "has been overwritten." :
-
 
482
                           "of differing case has been processed."));
500
  }
483
  }
501
  else {
484
  else {
502
    $self->{'files_written'}->{$key} = $file;
485
    $self->{'files_written'}->{$key} = $file;
503
    push(@{$self->{'real_fwritten'}}, $file);
486
    push(@{$self->{'real_fwritten'}}, $file);
504
  }
487
  }
Line 515... Line 498...
515
  my($fh)      = new FileHandle();
498
  my($fh)      = new FileHandle();
516
  my(@files)   = ();
499
  my(@files)   = ();
517
 
500
 
518
  if (opendir($fh, $dir)) {
501
  if (opendir($fh, $dir)) {
519
    foreach my $file (grep(!/^\.\.?$/, readdir($fh))) {
502
    foreach my $file (grep(!/^\.\.?$/, readdir($fh))) {
520
      $file =~ s/\.dir$// if ($^O eq 'VMS');
503
      $file =~ s/\.dir$// if ($onVMS);
521
 
504
 
522
      my($skip) = 0;
505
      my($skip) = 0;
523
      my($full) = ($dir ne '.' ? "$dir/" : '') . $file;
506
      my($full) = ($dir ne '.' ? "$dir/" : '') . $file;
524
 
507
 
525
      ## Check for command line exclusions
508
      ## Check for command line exclusions
Line 554... Line 537...
554
sub modify_assignment_value {
537
sub modify_assignment_value {
555
  my($self)  = shift;
538
  my($self)  = shift;
556
  my($name)  = shift;
539
  my($name)  = shift;
557
  my($value) = shift;
540
  my($value) = shift;
558
 
541
 
559
  if ($self->{'convert_slashes'} && $name !~ /flags/) {
542
  if ($self->{'convert_slashes'} && index($name, 'flags') == -1) {
560
    $value = $self->slash_to_backslash($value);
543
    $value =~ s/\//\\/g;
561
  }
544
  }
562
  return $value;
545
  return $value;
563
}
546
}
564
 
547
 
565
 
548
 
566
sub get_assignment_hash {
549
sub get_assignment_hash {
567
  ## NOTE: If anything in this block changes, then you must make the
550
  ## NOTE: If anything in this block changes, then you must make the
568
  ## same change in process_assignment.
551
  ## same change in process_assignment.
569
  my($self)   = shift;
552
  my($self) = shift;
570
  my($tag)    = ($self->{'reading_global'} ? 'global_assign' : 'assign');
553
  return $self->{$self->{'reading_global'} ? $gassign_key : $assign_key};
571
  my($assign) = $self->{$tag};
-
 
572
 
-
 
573
  ## If we haven't yet defined the hash table in this project
-
 
574
  if (!defined $assign) {
-
 
575
    $assign = {};
-
 
576
    $self->{$tag} = $assign;
-
 
577
  }
-
 
578
 
-
 
579
  return $assign;
-
 
580
}
554
}
581
 
555
 
582
 
556
 
583
sub process_assignment {
557
sub process_assignment {
584
  my($self)   = shift;
558
  my($self)   = shift;
Line 588... Line 562...
588
 
562
 
589
  ## If no hash table was passed in
563
  ## If no hash table was passed in
590
  if (!defined $assign) {
564
  if (!defined $assign) {
591
    ## NOTE: If anything in this block changes, then you must make the
565
    ## NOTE: If anything in this block changes, then you must make the
592
    ## same change in get_assignment_hash.
566
    ## same change in get_assignment_hash.
593
    my($tag) = ($self->{'reading_global'} ? 'global_assign' : 'assign');
-
 
594
    $assign  = $self->{$tag};
567
    $assign  = $self->{$self->{'reading_global'} ?
595
 
-
 
596
    ## If we haven't yet defined the hash table in this project
568
                               $gassign_key : $assign_key};
597
    if (!defined $assign) {
-
 
598
      $assign = {};
-
 
599
      $self->{$tag} = $assign;
-
 
600
    }
-
 
601
  }
569
  }
602
 
570
 
603
  if (defined $value) {
571
  if (defined $value) {
604
    $value =~ s/^\s+//;
572
    $value =~ s/^\s+//;
605
    $value =~ s/\s+$//;
573
    $value =~ s/\s+$//;
Line 646... Line 614...
646
sub process_assignment_sub {
614
sub process_assignment_sub {
647
  my($self)   = shift;
615
  my($self)   = shift;
648
  my($name)   = shift;
616
  my($name)   = shift;
649
  my($value)  = shift;
617
  my($value)  = shift;
650
  my($assign) = shift;
618
  my($assign) = shift;
651
  my($nval)   = $self->get_assignment_for_modification($name, $assign, 1);
619
  my($nval)   = $self->get_assignment_for_modification($name, $assign);
652
 
620
 
653
  if (defined $nval) {
621
  if (defined $nval) {
654
    ## Remove double quotes if there are any
622
    ## Remove double quotes if there are any
655
    $value =~ s/^\"(.*)\"$/$1/;
623
    $value =~ s/^\"(.*)\"$/$1/;
656
 
624
 
657
    ## Escape any regular expression special characters
625
    ## Escape any regular expression special characters
658
    $value = $self->escape_regex_special($value);
626
    $value = $self->escape_regex_special($value);
659
 
627
 
-
 
628
    my($last)  = 1;
-
 
629
    my($found) = undef;
660
    ## Due to the way process_assignment() works, we only need to
630
    for(my $i = 0; $i <= $last; $i++) {
-
 
631
      if ($i == $last) {
661
    ## attempt to remove a value that is either followed by a space
632
        ## If we did not find the string to subtract in the original
662
    ## or at the end of the line (single values are always at the end
633
        ## value, try again after expanding template variables for
663
    ## of the line).
634
        ## subtraction.
664
    if ($nval =~ s/$value\s+// || $nval =~ s/$value$//) {
-
 
665
      $self->process_assignment($name, $nval, $assign);
635
        $nval = $self->get_assignment_for_modification($name, $assign, 1);
666
    }
636
      }
667
    else {
637
      for(my $j = 0; $j <= $last; $j++) {
668
      ## Try the same thing only with double quotes around the value.
638
        ## If we didn't find it the first time, try again with quotes
-
 
639
        my($re) = ($j == $last ? '"' . $value . '"' : $value);
-
 
640
 
-
 
641
        ## Due to the way process_assignment() works, we only need to
669
      ## Double quotes will be preserved in the value when the value
642
        ## attempt to remove a value that is either followed by a space
670
      ## contains spaces.
643
        ## or at the end of the line (single values are always at the end
671
      $value = '"' . $value . '"';
644
        ## of the line).
672
      if ($nval =~ s/$value\s+// || $nval =~ s/$value$//) {
645
        if ($nval =~ s/$re\s+// || $nval =~ s/$re$//) {
673
        $self->process_assignment($name, $nval, $assign);
646
          $self->process_assignment($name, $nval, $assign);
-
 
647
          $found = 1;
-
 
648
          last;
-
 
649
        }
674
      }
650
      }
-
 
651
      last if ($found);
675
    }
652
    }
676
  }
653
  }
677
}
654
}
678
 
655
 
679
 
656
 
Line 859... Line 836...
859
  my($name)   = shift;
836
  my($name)   = shift;
860
  my($assign) = shift;
837
  my($assign) = shift;
861
 
838
 
862
  ## If no hash table was passed in
839
  ## If no hash table was passed in
863
  if (!defined $assign) {
840
  if (!defined $assign) {
864
    my($tag) = ($self->{'reading_global'} ? 'global_assign' : 'assign');
841
    $assign = $self->{$self->{'reading_global'} ?
865
    $assign = $self->{$tag};
842
                              $gassign_key : $assign_key};
866
  }
843
  }
867
 
844
 
868
  return $$assign{$name};
845
  return $$assign{$name};
869
}
846
}
870
 
847
 
Line 923... Line 900...
923
sub get_language {
900
sub get_language {
924
  my($self) = shift;
901
  my($self) = shift;
925
  return $self->{'language'};
902
  return $self->{'language'};
926
}
903
}
927
 
904
 
-
 
905
 
928
sub get_outdir {
906
sub get_outdir {
929
  my($self) = shift;
907
  my($self) = shift;
930
  if (defined $self->{'into'}) {
908
  if (defined $self->{'into'}) {
931
    my($outdir) = $self->getcwd();
909
    my($outdir) = $self->getcwd();
932
    my($re)     = $self->escape_regex_special($self->getstartdir());
910
    my($re)     = $self->escape_regex_special($self->getstartdir());
Line 1009... Line 987...
1009
  return 1;
987
  return 1;
1010
}
988
}
1011
 
989
 
1012
 
990
 
1013
sub file_sorter {
991
sub file_sorter {
1014
  my($self)  = shift;
992
  #my($self)  = shift;
1015
  my($left)  = shift;
993
  #my($left)  = shift;
1016
  my($right) = shift;
994
  #my($right) = shift;
1017
  return $left cmp $right;
995
  return $_[1] cmp $_[2];
1018
}
996
}
1019
 
997
 
1020
 
998
 
1021
sub read_global_configuration {
999
sub read_global_configuration {
1022
  #my($self)  = shift;
1000
  #my($self)  = shift;