00001 /****************************************************************************** 00002 * 00003 * $Id: filename.cpp,v 1.18 2001/03/19 19:27:40 root Exp $ 00004 * 00005 * Copyright (C) 1997-2008 by Dimitri van Heesch. 00006 * 00007 * Permission to use, copy, modify, and distribute this software and its 00008 * documentation under the terms of the GNU General Public License is hereby 00009 * granted. No representations are made about the suitability of this software 00010 * for any purpose. It is provided "as is" without express or implied warranty. 00011 * See the GNU General Public License for more details. 00012 * 00013 * Documents produced by Doxygen are derivative works derived from the 00014 * input used in their production; they are not affected by this license. 00015 * 00016 */ 00017 00018 #include "filename.h" 00019 #include "util.h" 00020 00021 FileName::FileName(const char *fn,const char *n) : FileList() 00022 { 00023 setAutoDelete(TRUE); 00024 fName=fn; 00025 name=n; 00026 } 00027 00028 FileName::~FileName() 00029 { 00030 } 00031 00032 00033 void FileName::generateDiskNames() 00034 { 00035 //QCString commonPrefix; 00036 FileDef *fd=first(); 00037 int count=0; 00038 while (fd) 00039 { 00040 if (!fd->isReference()) count++; 00041 fd=next(); 00042 } 00043 if (count==1) 00044 { 00045 fd=first(); 00046 // skip references 00047 while (fd && fd->isReference()) fd=next(); 00048 // name if unique, so diskname is simply the name 00049 //printf("!!!!!!!! Unique disk name=%s for fd=%s\n",name.data(),fd->diskname.data()); 00050 fd->diskname=name.copy(); 00051 } 00052 else if (count>1) // multiple occurrences of the same file name 00053 { 00054 //printf("Multiple occurrences of %s\n",name.data()); 00055 int i=0,j=0; 00056 bool found=FALSE; 00057 while (!found) // search for the common prefix of all paths 00058 { 00059 fd=first(); 00060 while (fd && fd->isReference()) fd=next(); 00061 char c=fd->path.at(i); 00062 if (c=='/') j=i; // remember last position of dirname 00063 fd=next(); 00064 while (fd && !found) 00065 { 00066 if (!fd->isReference()) 00067 { 00068 //printf("i=%d j=%d fd->path=`%s' fd->name=`%s'\n",i,j,fd->path.left(i).data(),fd->name().data()); 00069 if (i==(int)fd->path.length()) 00070 { 00071 //warning("Warning: Input file %s found multiple times!\n" 00072 // " The generated documentation for this file may not be correct!\n",fd->absFilePath().data()); 00073 found=TRUE; 00074 } 00075 else if (fd->path[i]!=c) 00076 { 00077 found=TRUE; 00078 } 00079 } 00080 fd=next(); 00081 } 00082 i++; 00083 } 00084 fd=first(); 00085 while (fd) 00086 { 00087 //printf("fd->setName(%s)\n",(fd->path.right(fd->path.length()-j-1)+name).data()); 00088 if (!fd->isReference()) 00089 { 00090 QCString prefix = fd->path.right(fd->path.length()-j-1); 00091 fd->setName(prefix+name); 00092 //printf("!!!!!!!! non unique disk name=%s for fd=%s\n",(prefix+name).data(),fd->diskname.data()); 00093 fd->diskname=prefix+name; 00094 } 00095 fd=next(); 00096 } 00097 } 00098 } 00099 00100 int FileName::compareItems(GCI item1, GCI item2) 00101 { 00102 FileName *f1=(FileName *)item1; 00103 FileName *f2=(FileName *)item2; 00104 return stricmp(f1->fileName(),f2->fileName()); 00105 } 00106 00107 FileNameIterator::FileNameIterator(const FileName &fname) : 00108 QListIterator<FileDef>(fname) 00109 { 00110 } 00111 00112 FileNameList::FileNameList() : QList<FileName>() 00113 { 00114 } 00115 00116 FileNameList::~FileNameList() 00117 { 00118 } 00119 00120 void FileNameList::generateDiskNames() 00121 { 00122 FileName *fn=first(); 00123 while (fn) 00124 { 00125 fn->generateDiskNames(); 00126 fn=next(); 00127 } 00128 } 00129 00130 int FileNameList::compareItems(GCI item1, GCI item2) 00131 { 00132 FileName *f1=(FileName *)item1; 00133 FileName *f2=(FileName *)item2; 00134 //printf("FileNameList::compareItems `%s'<->`%s'\n", 00135 // f1->fileName(),f2->fileName()); 00136 return Config_getBool("FULL_PATH_NAMES") ? 00137 stricmp(f1->fullName(),f2->fullName()) : 00138 stricmp(f1->fileName(),f2->fileName()); 00139 } 00140 00141 FileNameListIterator::FileNameListIterator(const FileNameList &fnlist) : 00142 QListIterator<FileName>(fnlist) 00143 { 00144 }