Orb/Doxygen/src/filename.cpp
changeset 0 42188c7ea2d9
child 4 468f4c8d3d5b
equal deleted inserted replaced
-1:000000000000 0:42188c7ea2d9
       
     1 /******************************************************************************
       
     2  *
       
     3  * 
       
     4  *
       
     5  * Copyright (C) 1997-2008 by Dimitri van Heesch.
       
     6  *
       
     7  * Permission to use, copy, modify, and distribute this software and its
       
     8  * documentation under the terms of the GNU General Public License is hereby 
       
     9  * granted. No representations are made about the suitability of this software 
       
    10  * for any purpose. It is provided "as is" without express or implied warranty.
       
    11  * See the GNU General Public License for more details.
       
    12  *
       
    13  * Documents produced by Doxygen are derivative works derived from the
       
    14  * input used in their production; they are not affected by this license.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "filename.h"
       
    19 #include "util.h"
       
    20 
       
    21 FileName::FileName(const char *fn,const char *n) : FileList()
       
    22 {
       
    23   setAutoDelete(TRUE);
       
    24   fName=fn;
       
    25   name=n;
       
    26 }
       
    27 
       
    28 FileName::~FileName()
       
    29 {
       
    30 }
       
    31 
       
    32 
       
    33 void FileName::generateDiskNames()
       
    34 {
       
    35   //QCString commonPrefix;
       
    36   FileDef *fd=first();
       
    37   int count=0;
       
    38   while (fd) 
       
    39   { 
       
    40     if (!fd->isReference()) count++; 
       
    41     fd=next(); 
       
    42   }
       
    43   if (count==1)
       
    44   {
       
    45     fd=first();
       
    46     // skip references
       
    47     while (fd && fd->isReference()) fd=next();
       
    48     // name if unique, so diskname is simply the name
       
    49     //printf("!!!!!!!! Unique disk name=%s for fd=%s\n",name.data(),fd->diskname.data());
       
    50     fd->diskname=name.copy();
       
    51   }
       
    52   else if (count>1) // multiple occurrences of the same file name
       
    53   {
       
    54     //printf("Multiple occurrences of %s\n",name.data());
       
    55     int i=0,j=0;
       
    56     bool found=FALSE;
       
    57     while (!found) // search for the common prefix of all paths
       
    58     {
       
    59       fd=first();
       
    60       while (fd && fd->isReference()) fd=next();
       
    61       char c=fd->path.at(i);
       
    62       if (c=='/') j=i; // remember last position of dirname
       
    63       fd=next();
       
    64       while (fd && !found)
       
    65       {
       
    66         if (!fd->isReference())
       
    67         {
       
    68           //printf("i=%d j=%d fd->path=`%s' fd->name=`%s'\n",i,j,fd->path.left(i).data(),fd->name().data());
       
    69           if (i==(int)fd->path.length())
       
    70           {
       
    71             //warning("Warning: Input file %s found multiple times!\n"
       
    72             //        "         The generated documentation for this file may not be correct!\n",fd->absFilePath().data());
       
    73             found=TRUE;
       
    74           }
       
    75           else if (fd->path[i]!=c)
       
    76           {
       
    77             found=TRUE;  
       
    78           }
       
    79         } 
       
    80         fd=next();
       
    81       }
       
    82       i++;
       
    83     }
       
    84     fd=first();
       
    85     while (fd)
       
    86     {
       
    87       //printf("fd->setName(%s)\n",(fd->path.right(fd->path.length()-j-1)+name).data());
       
    88       if (!fd->isReference())
       
    89       {
       
    90         QCString prefix = fd->path.right(fd->path.length()-j-1);
       
    91         fd->setName(prefix+name);
       
    92         //printf("!!!!!!!! non unique disk name=%s for fd=%s\n",(prefix+name).data(),fd->diskname.data());
       
    93         fd->diskname=prefix+name;
       
    94       }
       
    95       fd=next();
       
    96     }
       
    97   }
       
    98 }
       
    99 
       
   100 int FileName::compareItems(GCI item1, GCI item2)
       
   101 {
       
   102   FileName *f1=(FileName *)item1;
       
   103   FileName *f2=(FileName *)item2;
       
   104   return stricmp(f1->fileName(),f2->fileName());
       
   105 }
       
   106 
       
   107 FileNameIterator::FileNameIterator(const FileName &fname) :
       
   108   QListIterator<FileDef>(fname)
       
   109 {
       
   110 }
       
   111 
       
   112 FileNameList::FileNameList() : QList<FileName>()
       
   113 {
       
   114 }
       
   115 
       
   116 FileNameList::~FileNameList()
       
   117 {
       
   118 }
       
   119 
       
   120 void FileNameList::generateDiskNames()
       
   121 {
       
   122   FileName *fn=first();
       
   123   while (fn)
       
   124   {
       
   125     fn->generateDiskNames();
       
   126     fn=next();
       
   127   }
       
   128 }
       
   129 
       
   130 int FileNameList::compareItems(GCI item1, GCI item2)
       
   131 {
       
   132   FileName *f1=(FileName *)item1;
       
   133   FileName *f2=(FileName *)item2;
       
   134   //printf("FileNameList::compareItems `%s'<->`%s'\n",
       
   135   //    f1->fileName(),f2->fileName());
       
   136   return Config_getBool("FULL_PATH_NAMES") ?
       
   137          stricmp(f1->fullName(),f2->fullName()) :
       
   138          stricmp(f1->fileName(),f2->fileName());
       
   139 }
       
   140 
       
   141 FileNameListIterator::FileNameListIterator(const FileNameList &fnlist) :
       
   142   QListIterator<FileName>(fnlist)
       
   143 {
       
   144 }