summaryrefslogtreecommitdiff
path: root/buildscripts/PhpDocumentor/phpDocumentor/ProceduralPages.inc
blob: 21cd4f18fc59ccdfd1e409d3f90809abd1d5d87a (plain)
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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
<?php
/**
 * Intermediate procedural page parsing structure.
 * This structure parses defines, functions, and global variables by file,
 * and then iterates over the elements to document conflicts.
 * 
 * phpDocumentor :: automatic documentation generator
 * 
 * PHP versions 4 and 5
 *
 * Copyright (c) 2002-2008 Gregory Beaver
 * 
 * LICENSE:
 * 
 * This library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any
 * later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * @category  ToolsAndUtilities
 * @package   phpDocumentor
 * @author    Gregory Beaver <cellog@php.net>
 * @copyright 2002-2008 Gregory Beaver
 * @license   http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @version   CVS: $Id: ProceduralPages.inc 253641 2008-02-24 02:35:44Z ashnazg $
 * @link      http://www.phpdoc.org
 * @link      http://pear.php.net/PhpDocumentor
 * @since     1.1
 * @todo      CS cleanup - change package to PhpDocumentor
 */

/**
 * Intermediate procedural page parsing structure.
 * This structure parses defines, functions, and global variables by file,
 * and then iterates over the elements to document conflicts.
 *
 * @category  ToolsAndUtilities
 * @package   phpDocumentor
 * @author    Greg Beaver <cellog@php.net>
 * @copyright 2002-2008 Gregory Beaver
 * @license   http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @version   Release: 1.4.3
 * @link      http://www.phpdoc.org
 * @link      http://pear.php.net/PhpDocumentor
 * @since     1.1
 * @todo      CS cleanup - change package to PhpDocumentor
 */
class ProceduralPages
{
    /**
     * file being parsed, used in every add function 
     * to match up elements with the file that contains them
     *
     * @see addClass(), addMethod(), addVar(), nextFile()
     * @var string
     */
    var $curfile;
    /**
     * array of all procedural pages ordered by name
     * Format:
     * <pre>
     *     array(
     *         name => array(
     *             fullpath => parserPage,
     *             fullpath => parserPage2 [if there are name conflicts],
     *             ...
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $pages = array();
    /**
     * array of all procedural pages ordered by name 
     * that have been ignored via -po or @access private or @ignore
     * Format:
     * <pre>
     *     array(
     *         name => array(
     *             fullpath => parserPage,
     *             fullpath => parserPage2 [if there are name conflicts],
     *             ...
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $ignorepages = array();
    /**
     * array of all procedural page names ordered by full path to the file
     * Format:
     * <pre>
     *     array(
     *         fullpath => name
     *     )
     * </pre>
     *
     * @var array
     */
    var $pathpages = array();
    /**
     * array of parsed includes organized by the full path 
     * of the file that contains the include.
     * Format:
     * <pre>
     *     array(
     *         full path => array(
     *             includename => {@link parserInclude}
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $includesbyfile = array();
    /**
     * array of parsed functions organized by the full path 
     * of the file that contains the function.
     * Format:
     * <pre>
     *     array(
     *         full path => array(
     *             functionname => {@link parserFunction}
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $functionsbyfile = array();
    /**
     * array of parsed defines organized by the full path 
     * of the file that contains the define.
     * Format:
     * <pre>
     *     array(
     *         full path => array(
     *             definename => {@link parserDefine}
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $definesbyfile = array();
    /**
     * array of parsed global variables organized by the full path 
     * of the file that contains the global variable definition.
     * Format:
     * <pre>
     *     array(
     *         full path => array(
     *             globalname => {@link parserGlobal}
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $globalsbyfile = array();
    /**
     * array of file names organized by functions that are in the file.
     *
     * This structure is designed to handle name conflicts.  Two files can contain
     * functions with the same name, and this array will record both filenames to
     * help control namespace errors
     * Format:
     * <pre>
     *     array(
     *         functionname => array(
     *             full path of file containing functionname,
     *             full path of file 2 containing functionname,
     *             ...
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $functionsbynamefile = array();
    /**
     * array of file names organized by defines that are in the file.
     * This structure is designed to handle name conflicts.  Two files 
     * can contain defines with the same name, and this array will
     * record both filenames to help control namespace errors
     * Format:
     * <pre>
     *     array(
     *         definename => array(
     *             full path of file containing definename,
     *             full path of file 2 containing definename,
     *             ...
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $definesbynamefile = array();
    /**
     * array of file names organized by global variables that are in the file.
     *
     * This structure is designed to handle name conflicts.  Two files can 
     * contain global variables with the same name, and this array will
     * record both filenames to help control namespace errors
     * Format:
     * <pre>
     *     array(
     *         global variablename => array(
     *             full path of file containing global variablename,
     *             full path of file 2 containing global variablename,
     *             ...
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $globalsbynamefile = array();
    /**
     * array of packages ordered by full path
     * Format:
     * <pre>
     *     array(
     *         fullpath => array(
     *             packagename,
     *             subpackagename
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $pagepackages = array();
    /**
     * array of packages assigned to classes in a file, ordered by fullpath
     * Format:
     * <pre>
     *     array(
     *         fullpath => array(
     *             packagename => array(
     *                 subpackagename => 1,
     *                 subpackagename => 1,
     *                 ..
     *             ),
     *             packagename2 => array(...
     *             )
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $pageclasspackages = array();
    /**
     * Namespace conflicts within all documented packages of functions
     * Format:
     * <pre>
     *     array(
     *         functionname => array(
     *             full path,
     *             full path,
     *             ...
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $functionconflicts = array();
    /**
     * Namespace conflicts within all documented pages
     * Format:
     * <pre>
     *     array(
     *         pagename => array(
     *             fullpath,
     *             fullpath,
     *             ...
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $pageconflicts = array();
    /**
     * Namespace conflicts within all documented packages of functions
     * Format:
     * <pre>
     *     array(
     *         functionname => array(
     *             full path,
     *             full path,
     *             ...
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $defineconflicts = array();
    /**
     * Namespace conflicts within all documented packages of functions
     * Format:
     * <pre>
     *     array(
     *         functionname => array(
     *             full path,
     *             full path,
     *             ...
     *         )
     *     )
     * </pre>
     *
     * @var array
     */
    var $globalconflicts = array();
    /**
     * @access private
     * @var array
     */
    var $revcpbf = array();
    /**
     * @access private
     * @var boolean
     */
    var $packagesetup = false;

    /**
     * sets up the {@link $pages} array
     *
     * @param parserPage &$element the parser page element
     *
     * @return void
     */
    function addPage(&$element)
    {
        $this->curfile
            = $element->getPath();
        $this->pages[$element->getFile()][$element->getPath()]
            = $element;
        $this->pathpages[$this->curfile]
            = $element->getFile();
        $this->addPagePackage($this->curfile, 
            $element->package, $element->subpackage);
    }
    
    /**
     * moves a page from the {@link $pages} array to the {@link $ignorepages} array
     *
     * @param parserPage &$element the parser page element
     *
     * @return void
     */
    function ignorePage(&$element)
    {
        $this->ignorepages[$element->getFile()][$element->getPath()]
            = $this->pages[$element->getFile()][$element->getPath()];
        unset($this->pages[$element->getFile()][$element->getPath()]);
    }

    /**
     * gathers path-related info about a given element
     *
     * @param string $path path to the element
     * @param mixed  &$c   ???
     *
     * @return array|bool an array of path info,
     *                    or FALSE 
     * @todo figure out what &$c is and update the param tag
     */
    function getPathInfo($path, &$c)
    {
        $path = str_replace('/', SMART_PATH_DELIMITER, $path);
        $info = array();
        if (!isset($this->pathpages[$path])) {
            return false;
        }

        $p = $this->pages[$this->pathpages[$path]][$path];
        // fixes [ 1391432 ] Too many underscores in include links.
        $p->name = $p->origName;
        $p->name = $c->getPageName($p);

        $info['package']    = $p->package;
        $info['subpackage'] = $p->subpackage;
        $info['name']       = $p->getFile();
        $info['source_loc'] = $p->getSourceLocation($c);

        $x = new pageLink;
        $x->addLink($p->path, $p->name, $p->file, $p->package, $p->subpackage);

        $info['docs'] = $c->returnSee($x);
        $p->name      = $p->origName;

        return $info;
    }
    
    /**
     * Change a page's name from its file to alias $name
     *
     * This function is used to handle a @name tag in a page-level DocBlock
     *
     * @param string $name the alias
     *
     * @return void
     */
    function setName($name)
    {
        if ($this->pages[$name][$this->curfile]->file == $name) {
            addWarning(PDERROR_NAME_ALIAS_SAME_AS_TARGET,'');

        } else {
            $this->pages[$name][$this->curfile]
                = $this->pages[$this->pathpages[$this->curfile]][$this->curfile];
            $this->pages[$name][$this->curfile]->file
                = $name;

            unset($this->pages[$this->pathpages[$this->curfile]][$this->curfile]);

            $this->pathpages[$this->curfile] = $name;
        }
    }
    
    /**
     * Changes the package of the page represented by $path
     *
     * changes package in both the {@link $pages} array 
     * and the {@link pagepackages} array
     *
     * @param string $path       full path
     * @param string $package    the package name
     * @param string $subpackage the subpackage name
     *
     * @return void
     */
    function addPagePackage($path, $package, $subpackage)
    {
        $this->pages[$this->pathpages[$path]][$path]->package
            = $package;
        $this->pages[$this->pathpages[$path]][$path]->subpackage
            = $subpackage;
        $this->pagepackages[$path]
            = array($package, $subpackage);

        if (isset($this->includesbyfile[$path])) {
            foreach ($this->includesbyfile[$path] as $i => $el) {
                $el->package                     = $package;
                $el->subpackage                  = $subpackage;
                $this->includesbyfile[$path][$i] = $el;
            }
        }
        if (isset($this->functionsbyfile[$path])) {
            foreach ($this->functionsbyfile[$path] as $i => $el) {
                $el->package                      = $package;
                $el->subpackage                   = $subpackage;
                $this->functionsbyfile[$path][$i] = $el;
            }
        }
        if (isset($this->definesbyfile[$path])) {
            foreach ($this->definesbyfile[$path] as $i => $el) {
                $el->package                    = $package;
                $el->subpackage                 = $subpackage;
                $this->definesbyfile[$path][$i] = $el;
            }
        }
        if (isset($this->globalsbyfile[$path])) {
            foreach ($this->globalsbyfile[$path] as $i => $el) {
                $el->package                    = $package;
                $el->subpackage                 = $subpackage;
                $this->globalsbyfile[$path][$i] = $el;
            }
        }
    }

    /**
     * sets up the {@link $includesbyfile} array using {@link $curfile}
     *
     * @param parserInclude &$element the "include" element object
     *
     * @return void
     */
    function addInclude(&$element)
    {
        $this->includesbyfile[$this->curfile][] = $element;
    }

    /**
     * sets up the {@link $functionsbyfile} array using {@link $curfile}
     *
     * @param parserFunction &$element the "function" object
     *
     * @return void
     */
    function addFunction(&$element)
    {
        if (isset($this->functionsbyfile[$this->curfile])) {
            foreach ($this->functionsbyfile[$this->curfile] as $i => $function) {
                if ($function->getName() == $element->getName()) {
                    addWarning(PDERROR_ELEMENT_IGNORED, 'function',
                        $element->getName(), $this->curfile);
                    return;
                }
            }
        }
        $this->functionsbyfile[$this->curfile][]          = $element;
        $this->functionsbynamefile[$element->getName()][] = $this->curfile;
    }

    /**
     * sets up the {@link $globalsbyfile} array using {@link $curfile}
     *
     * @param parserGlobal &$element the "global" element
     *
     * @return void
     */
    function addGlobal(&$element)
    {
        if (isset($this->globalsbyfile[$this->curfile])) {
            foreach ($this->globalsbyfile[$this->curfile] as $i => $global) {
                if ($global->getName() == $element->getName()) {
                    addWarning(PDERROR_ELEMENT_IGNORED, 'global variable',
                        $element->getName(), $this->curfile);
                    return;
                }
            }
        }
        $this->globalsbyfile[$this->curfile][]          = $element;
        $this->globalsbynamefile[$element->getName()][] = $this->curfile;
    }

    /**
     * sets up the {@link $definesbyfile} array using {@link $curfile}
     *
     * @param parserDefine &$element the "define" element
     *
     * @return void
     */
    function addDefine(&$element)
    {
        if (isset($this->definesbyfile[$this->curfile])) {
            foreach ($this->definesbyfile[$this->curfile] as $i => $define) {
                if ($define->getName() == $element->getName()) {
                    addWarning(PDERROR_ELEMENT_IGNORED, 'define',
                        $element->getName(), $this->curfile);
                    return;
                }
            }
        }
        $this->definesbyfile[$this->curfile][]          = $element;
        $this->definesbynamefile[$element->getName()][] = $this->curfile;
    }
    
    /**
     * Used to align an element with the package of its parent page 
     * prior to Conversion.
     *
     * @param parserElement &$element the element to align
     *
     * @return void
     */
    function replaceElement(&$element)
    {
        if ($element->type == 'define') {
            foreach ($this->definesbyfile[$element->getPath()] as $i => $el) {
                if ($el->getName() == $element->getName()) {
                    $this->definesbyfile[$element->getPath()][$i] = &$element;
                }
            }
        } elseif ($element->type == 'global') {
            foreach ($this->globalsbyfile[$element->getPath()] as $i => $el) {
                if ($el->getName() == $element->getName()) {
                    $this->globalsbyfile[$element->getPath()][$i] = &$element;
                }
            }
        } elseif ($element->type == 'include') {
            foreach ($this->includesbyfile[$element->getPath()] as $i => $el) {
                if ($el->getName() == $element->getName()) {
                    $this->includesbyfile[$element->getPath()][$i] = &$element;
                }
            }
        } elseif ($element->type == 'function') {
            foreach ($this->functionsbyfile[$element->getPath()] as $i => $el) {
                if ($el->getName() == $element->getName()) {
                    $this->functionsbyfile[$element->getPath()][$i] = &$element;
                }
            }
        }
    }

    /**
     * adds a package from a class to the current file
     *
     * @param string $file       full path to the file that contains the class
     * @param string $package    package name
     * @param string $subpackage subpackage name
     *
     * @return void
     */
    function addClassPackageToFile($file, $package, $subpackage)
    {
        if (!isset($this->revcpbf[$file][$package][$subpackage])) {
            $this->pageclasspackages[$file][$package][$subpackage] = 1;
        }
        $this->revcpbf[$file][$package][$subpackage] = 1;
    }
    
    /**
     * if there is one class package in a file, 
     * the parent path inherits the package if its package is default.
     * helps with -po to avoid dumb bugs
     *
     * @return void
     */
    function setupPagePackages()
    {
        if ($this->packagesetup) {
            return;
        }
        foreach ($this->pageclasspackages as $fullpath => $packages) {
            if (isset($this->pagepackages[$fullpath])) {
                if ($this->pagepackages[$fullpath][0] 
                    == $GLOBALS['phpDocumentor_DefaultPackageName']
                ) {
                    if (count($packages) == 1) {
                        list($package, $subpackage) = each($packages);
                        if (count($subpackage) == 1) {
                            list($subpackage,) = each($subpackage);
                        } else {
                            $subpackage = '';
                        }
                        $this->addPagePackage($fullpath, $package, $subpackage);
                    }
                }
            }
        }
        $this->packagesetup = true;
    }
    
    /**
     * extracts function, define, and global variable name conflicts within the 
     * same package and between different packages.  No two elements with the same
     * name are allowed in the same package, to keep automatic linking possible.
     *
     * @param mixed &$render the renderer object
     *
     * @return void
     * @access private
     * @todo functions, defines, and globals are coded,
     *       but pages section is empty... does it need to be coded?
     */
    function setupConflicts(&$render)
    {
        foreach ($this->functionsbynamefile as $function => $paths) {
            if (count($paths) - 1) {
                //conflict
                $package = array();
                foreach ($paths as $path) {
                    // create a list of conflicting functions in each package
                    $package[$this->pagepackages[$path][0]][] = $path;
                }
                foreach ($package as $pathpackages) {
                    // if at least 2 functions exist in the same package, 
                    // delete all but the first one and add warnings
                    if (count($pathpackages) - 1) {
                        for ($i=1; $i < count($pathpackages); $i++) {
                            addWarning(PDERROR_ELEMENT_IGNORED, 'function',
                                $function, $pathpackages[$i]);
                            foreach ($this->functionsbyfile[$pathpackages[$i]] 
                                as $j => $blah
                            ) {
                                if ($this->functionsbyfile[$pathpackages[$i]][$j]
                                    ->getName() == $function
                                ) {
                                    unset($this
                                        ->functionsbyfile[$pathpackages[$i]][$j]);
                                }
                            }
                            $oth = array_flip($paths);
                            unset($paths[$oth[$pathpackages[$i]]]);
                        }
                    }
                }
                $this->functionconflicts[$function] = $paths;
            }
        }

        foreach ($this->definesbynamefile as $define => $paths) {
            if (count($paths) - 1) { 
                //conflict
                $package = array();
                foreach ($paths as $path) {
                    // create a list of conflicting functions in each package
                    $package[$this->pagepackages[$path][0]][] = $path;
                }
                foreach ($package as $pathpackages) {
                    // if at least 2 functions exist in the same package, 
                    // delete all but the first one and add warnings
                    if (count($pathpackages) - 1) {
                        for ($i=1; $i < count($pathpackages); $i++) {
                            addWarning(PDERROR_ELEMENT_IGNORED, 'define',
                                $define, $pathpackages[$i]);
                            foreach ($this->definesbyfile[$pathpackages[$i]]
                                as $j => $blah
                            ) {
                                if ($this->definesbyfile[$pathpackages[$i]][$j]
                                    ->getName() == $define
                                ) {
                                    unset($this
                                        ->definesbyfile[$pathpackages[$i]][$j]);
                                }
                            }
                            $oth = array_flip($paths);
                            unset($paths[$oth[$pathpackages[$i]]]);
                        }
                    }
                }
                $this->defineconflicts[$define] = $paths;
            }
        }

        foreach ($this->globalsbynamefile as $global => $paths) {
            if (count($paths) - 1) { 
                //conflict
                $package = array();
                foreach ($paths as $path) {
                    // create a list of conflicting functions in each package
                    $package[$this->pagepackages[$path][0]][] = $path;
                }
                foreach ($package as $pathpackages) {
                    // if at least 2 functions exist in the same package, 
                    // delete all but the first one and add warnings
                    if (count($pathpackages) - 1) {
                        for ($i=1; $i < count($pathpackages); $i++) {
                            addWarning(PDERROR_ELEMENT_IGNORED, 'global variable',
                                $global, $pathpackages[$i]);
                            foreach ($this->globalsbyfile[$pathpackages[$i]] 
                                as $j => $blah
                            ) {
                                if ($this->globalsbyfile[$pathpackages[$i]][$j]
                                    ->getName() == $global
                                ) {
                                    unset($this
                                        ->globalsbyfile[$pathpackages[$i]][$j]);
                                }
                            }
                            $oth = array_flip($paths);
                            unset($paths[$oth[$pathpackages[$i]]]);
                        }
                    }
                }
                $this->globalconflicts[$global] = $paths;
            }
        }
        
        /*
         * @todo does this section still need to be coded???
         */
        foreach ($this->pages as $name => $pages) {
            if (count($pages) - 1) { 
                // possible conflict
            }
        }
    }
    
    /**
     * called by {@link parserFunction::getConflicts()} to get 
     * inter-package conflicts, should not be called directly
     *
     * @param string $name the function name to check
     *
     * @access private
     * @return array|bool Format: (package => {@link parserFunction} 
     *                    of conflicting function)
     *                    or FALSE if the function is not recorded as a conflict
     */
    function getFuncConflicts($name)
    {
        if (!isset($this->functionconflicts[$name])) {
            return false;
        }
        $a = array();
        foreach ($this->functionconflicts[$name] as $conflict) {
            foreach ($this->functionsbyfile[$conflict] as $i => $func) {
                if ($func->getName() == $name) {
                    $a[$this->functionsbyfile[$conflict][$i]->docblock->package] 
                        = $this->functionsbyfile[$conflict][$i];
                }
            }
        }
        return $a;
    }
    
    /**
     * called by {@link parserGlobal::getConflicts()} 
     * to get inter-package conflicts, should not be called directly
     *
     * @param string $name the global name to check
     *
     * @access private
     * @return array|bool Format: (package => {@link parserGlobal} 
     *                    of conflicting global variable)
     *                    or FALSE if the global is not recorded as a conflict
     */
    function getGlobalConflicts($name)
    {
        if (!isset($this->globalconflicts[$name])) {
            return false;
        }
        $a = array();
        foreach ($this->globalconflicts[$name] as $conflict) {
            foreach ($this->globalsbyfile[$conflict] as $i => $func) {
                if ($func->getName() == $name) {
                    $a[$this->globalsbyfile[$conflict][$i]->docblock->package] 
                        = $this->globalsbyfile[$conflict][$i];
                }
            }
        }
        return $a;
    }
    
    /**
     * called by {@link parserDefine::getConflicts()} 
     * to get inter-package conflicts, should not be called directly
     *
     * @param string $name the define name to check
     *
     * @access private
     * @return array|bool Format: (package => {@link parserDefine} 
     *                    of conflicting define)
     *                    or FALSE if the define is not recorded as a conflict
     */
    function getDefineConflicts($name)
    {
        if (!isset($this->defineconflicts[$name])) {
            return false;
        }
        $a = array();
        foreach ($this->defineconflicts[$name] as $conflict) {
            foreach ($this->definesbyfile[$conflict] as $i => $func) {
                if ($func->getName() == $name) {
                    $a[$this->definesbyfile[$conflict][$i]->docblock->package] 
                        = $this->definesbyfile[$conflict][$i];
                }
            }
        }
        return $a;
    }
    
    /**
     * Adjusts packages of all pages and removes name conflicts within a package
     *
     * Automatic linking requires that each linkable name have exactly one element 
     * associated with it.  In other words, there cannot be two functions named 
     * foo() in the same package.
     *
     * This also adheres to php rules with one exception:
     *
     * <code>
     * if ($test == 3) {
     *    define('whatever', 'this thing');
     * } else {
     *    define('whatever', 'this other thing');
     * }
     * </code>
     *
     * phpDocumentor is not aware of conditional control structures because it 
     * would slow things down considerably.  So, what phpDocumentor does is 
     * automatically ignore the second define and raise a warning.  The warning can
     * be eliminated with an @ignore tag on the second element like so:
     *
     * <code>
     * if ($test == 3) {
     *    define('whatever', 'this thing');
     * } else {
     *    /**
     *     * @ignore
     *     {@*}
     *    define('whatever', 'this other thing');
     * }
     * </code>
     *
     * If there are two files that contain the same procedural elements in the 
     * same package (for example, a common configuration file common.php), they 
     * will also be ignored as if they were in the same file.  The reasoning
     * behind this is simple.  A package is an indivisible set of files and 
     * classes that a user will include in their code.  Name conflicts must be 
     * avoided to allow successful execution.
     *
     * This function also plays the all-important role of calling 
     * {@link phpDocumentor_IntermediateParser::addElementToPage()} in order to add 
     * processed elements to their pages for Conversion.
     *
     * @param phpDocumentor_IntermediateParser &$render the parser
     *
     * @return void
     */
    function setupPages(&$render)
    {
        global $_phpDocumentor_setting;
        phpDocumentor_out("\nProcessing Procedural Page Element Name Conflicts\n\n");
        flush();
        $this->setupPagePackages();
        $this->setupConflicts($render);
        // phpDocumentor_out("\nProcessing Procedural Pages\n\n");
        foreach ($this->pathpages as $path => $name) {
            // phpDocumentor_out("Processing $path\n");
            $a = $this->pagepackages[$path];
            $b = &$this->pages[$name][$path];
            $render->addPage($b, $path);
            $render->addUses($b, $path);
            if (isset($this->includesbyfile[$path])) {
                foreach ($this->includesbyfile[$path] as $include) {
                    $include->docblock->package    = $a[0];
                    $include->docblock->subpackage = $a[1];
                    $render->addElementToPage($include, $path);
                }
            }
    
            if (isset($this->functionsbyfile[$path])) {
                foreach ($this->functionsbyfile[$path] as $function) {
                    $function->docblock->package    = $a[0];
                    $function->docblock->subpackage = $a[1];
                    $render->addElementToPage($function, $path);
                    $render->addUses($function, $path);
                }
            }
    
            if (isset($this->definesbyfile[$path])) {
                foreach ($this->definesbyfile[$path] as $define) {
                    $define->docblock->package    = $a[0];
                    $define->docblock->subpackage = $a[1];
                    $render->addElementToPage($define, $path);
                    $render->addUses($define, $path);
                }
            }
    
            if (isset($this->globalsbyfile[$path])) {
                foreach ($this->globalsbyfile[$path] as $global) {
                    $global->docblock->package    = $a[0];
                    $global->docblock->subpackage = $a[1];
                    $render->addElementToPage($global, $path);
                    $render->addUses($global, $path);
                }
            }
        }
    }
    
    /**
     * sets the parser base
     *
     * @param mixed $pbase the parser base
     *
     * @return void
     */
    function setParseBase($pbase)
    {
        $this->_parsedbase = $pbase;
    }
    
    /**
     * checks to see if the parsed file matches the given path
     *
     * @param string $path   the path to look for
     * @param string $infile the file to check
     *
     * @return parserPage|bool matched parserPage if found,
     *                         or FALSE if not found
     */
    function pathMatchesParsedFile($path, $infile)
    {
        $test = $this->getRealPath($path, $infile);
        if (is_string($test)) {
            if (isset($this->pathpages[$test])) {
                return $this->pages[$this->pathpages[$test]][$test];
            }
            if (PHPDOCUMENTOR_WINDOWS) {
                $test = str_replace('/', '\\', $test);
            }
            if (isset($this->pathpages[$test])) {
                $a = $this->pages[$this->pathpages[$test]][$test];
                if (is_array($a->packageOutput) 
                    && !in_array($a->package, $a->packageOutput)
                ) {
                    return false;
                }
                return $this->pages[$this->pathpages[$test]][$test];
            }
        } else {
            foreach ($test as $file) {
                if (isset($this->pathpages[$file])) {
                    return $this->pages[$this->pathpages[$file]][$file];
                }
                if (PHPDOCUMENTOR_WINDOWS) {
                    $file = str_replace('/', '\\', $file);
                }
                if (isset($this->pathpages[$file])) {
                    $a = $this->pages[$this->pathpages[$file]][$file];
                    if (is_array($a->packageOutput) 
                        && !in_array($a->package, $a->packageOutput)
                    ) {
                        return false;
                    }
                    return $this->pages[$this->pathpages[$file]][$file];
                }
            }
        }
        return false;
    }
    
    /**
     * Ensures the path to the file is an absolute path
     * 
     * @param string $path path to the file
     * @param string $file the file name
     *
     * @return array|string returns an array of possible file locations or
     *                      a string if there is an exact match
     */
    function getRealPath($path, $file)
    {
        $curdir = str_replace('\\', '/', dirname($file));
        $path   = str_replace('\\', '/', $path);
        if (strpos($path, ':') !== false) {
            // windows, and we have a drive letter
            return $path;
        } elseif (strpos($path, '/') === 0) {
            return $path;
        }
        // not an absolute path
        $path = explode('/', $path);
        if ($path[0] == '.') {
            $path[0] = dirname($file);
            return join($path, '/');
        } elseif ($path[0] == '..') {
            $dirfile = explode('/', dirname(str_replace('\\', '/', $file)));
            // remove the current directory
            array_pop($dirfile); 
            if (!count($dirfile)) {
                // we were at a top-level dir!
                return false;
            }
            // replace .. with parent dirname
            $path[0] = join($dirfile, '/');
            return join($path, '/');
        } else {
            $path = join($path, '/');
            return array($curdir . PATH_DELIMITER . $path,
                str_replace('\\', '/', PHPDOCUMENTOR_BASE)
                . PATH_DELIMITER . $path);
        }
    }
}
?>