2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 12:04:08 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 12:04:08 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 12:04:08 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 12:04:08 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 12:04:08 +00:00
|
|
|
* OpenOffice.org 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 version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 12:04:08 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 23:48:05 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2000-09-22 15:41:03 +00:00
|
|
|
#include <sys/stat.h>
|
2007-06-27 21:06:03 +00:00
|
|
|
#include <tools/stream.hxx>
|
2011-08-16 08:54:49 +01:00
|
|
|
#include <rtl/strbuf.hxx>
|
|
|
|
#include <comphelper/string.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "cppdep.hxx"
|
|
|
|
|
|
|
|
CppDep::CppDep()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CppDep::~CppDep()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CppDep::Execute()
|
|
|
|
{
|
2011-11-27 08:21:00 +00:00
|
|
|
size_t nCount = m_aSources.size();
|
|
|
|
for ( size_t n = 0; n < nCount; ++n )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-11-27 08:21:00 +00:00
|
|
|
const rtl::OString &rStr = m_aSources[n];
|
|
|
|
Search(rStr);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-27 08:21:00 +00:00
|
|
|
sal_Bool CppDep::AddSearchPath( const char* pPath )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-11-27 08:21:00 +00:00
|
|
|
m_aSearchPath.push_back( rtl::OString(pPath) );
|
2010-07-29 10:56:19 +08:00
|
|
|
return sal_False;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2011-11-27 08:21:00 +00:00
|
|
|
sal_Bool CppDep::AddSource( const char* pSource )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-11-27 08:21:00 +00:00
|
|
|
m_aSources.push_back( rtl::OString(pSource) );
|
2010-07-29 10:56:19 +08:00
|
|
|
return sal_False;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 23:32:42 +00:00
|
|
|
sal_Bool CppDep::Search(const rtl::OString &rFileName)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-12-06 23:32:42 +00:00
|
|
|
fprintf( stderr, "SEARCH : %s\n", rFileName.getStr());
|
2001-06-13 12:43:51 +00:00
|
|
|
#endif
|
2010-07-29 10:56:19 +08:00
|
|
|
sal_Bool bRet = sal_False;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
SvFileStream aFile;
|
2011-11-13 23:17:06 +00:00
|
|
|
rtl::OString aReadLine;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-12-06 23:32:42 +00:00
|
|
|
UniString suFileName(rtl::OStringToOUString(rFileName, osl_getThreadTextEncoding()));
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
aFile.Open( suFileName, STREAM_READ );
|
|
|
|
while ( aFile.ReadLine( aReadLine ))
|
|
|
|
{
|
2011-11-13 23:17:06 +00:00
|
|
|
using comphelper::string::indexOfL;
|
|
|
|
sal_Int32 nPos = indexOfL(aReadLine,
|
|
|
|
RTL_CONSTASCII_STRINGPARAM("include"));
|
|
|
|
if ( nPos != -1 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-11-13 23:17:06 +00:00
|
|
|
fprintf( stderr, "found : %d %s\n", nPos, aReadLine.getStr() );
|
2001-06-13 12:43:51 +00:00
|
|
|
#endif
|
2011-12-06 23:32:42 +00:00
|
|
|
rtl::OString aResult = IsIncludeStatement( aReadLine );
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-12-06 23:32:42 +00:00
|
|
|
fprintf( stderr, "Result : %s\n", aResult.getStr() );
|
2001-06-13 12:43:51 +00:00
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-11-27 08:21:00 +00:00
|
|
|
rtl::OString aNewFile;
|
2011-12-06 23:32:42 +00:00
|
|
|
if (!aResult.isEmpty())
|
2011-11-27 08:21:00 +00:00
|
|
|
if ( (aNewFile = Exists( aResult )).getLength() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-07-29 10:56:19 +08:00
|
|
|
sal_Bool bFound = sal_False;
|
2011-11-27 08:21:00 +00:00
|
|
|
size_t nCount = m_aFileList.size();
|
|
|
|
for ( size_t i = 0; i < nCount; ++i )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-11-27 08:21:00 +00:00
|
|
|
const rtl::OString &rStr = m_aFileList[i];
|
|
|
|
if ( rStr == aNewFile )
|
2010-07-29 10:56:19 +08:00
|
|
|
bFound = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-11-13 23:17:06 +00:00
|
|
|
fprintf( stderr, "not in list : %d %s\n", nPos, aReadLine.getStr() );
|
2001-06-13 12:43:51 +00:00
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
if ( !bFound )
|
|
|
|
{
|
2011-11-27 08:21:00 +00:00
|
|
|
m_aFileList.push_back(aNewFile);
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-11-27 08:21:00 +00:00
|
|
|
fprintf( stderr, " CppDep %s\\\n", aNewFile.getStr() );
|
2001-06-13 12:43:51 +00:00
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
Search(aNewFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aFile.Close();
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2011-12-06 23:32:42 +00:00
|
|
|
rtl::OString CppDep::Exists(const rtl::OString &rFileName)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2003-03-27 16:05:12 +00:00
|
|
|
char pFullName[1023];
|
|
|
|
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-12-06 23:32:42 +00:00
|
|
|
fprintf( stderr, "Searching %s \n", rFileName.getStr() );
|
2001-06-13 12:43:51 +00:00
|
|
|
#endif
|
2003-03-27 16:05:12 +00:00
|
|
|
|
2011-11-27 08:21:00 +00:00
|
|
|
size_t nCount = m_aSearchPath.size();
|
|
|
|
for ( size_t n = 0; n < nCount; ++n )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
struct stat aBuf;
|
2011-11-27 08:21:00 +00:00
|
|
|
const rtl::OString &rPathName = m_aSearchPath[n];
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-11-27 08:21:00 +00:00
|
|
|
strcpy( pFullName, rPathName.getStr());
|
2000-09-18 16:07:07 +00:00
|
|
|
strcat( pFullName, DIR_SEP );
|
2011-12-06 23:32:42 +00:00
|
|
|
strcat( pFullName, rFileName.getStr());
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2003-03-27 16:05:12 +00:00
|
|
|
fprintf( stderr, "looking for %s\t ", pFullName );
|
2001-06-13 12:43:51 +00:00
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
if ( stat( pFullName, &aBuf ) == 0 )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_VERBOSE
|
|
|
|
fprintf( stderr, "Got Dependency ", pFullName );
|
|
|
|
#endif
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
|
|
|
fprintf( stderr, "%s \\\n", pFullName );
|
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-11-27 08:21:00 +00:00
|
|
|
return rtl::OString(pFullName);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-27 08:21:00 +00:00
|
|
|
return rtl::OString();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2011-08-16 08:54:49 +01:00
|
|
|
rtl::OString CppDep::IsIncludeStatement(rtl::OString aLine)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-08-16 08:54:49 +01:00
|
|
|
sal_Int32 nIndex;
|
|
|
|
|
|
|
|
nIndex = aLine.indexOf("/*");
|
|
|
|
if ( nIndex != -1 )
|
2008-10-15 08:43:33 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-08-16 08:54:49 +01:00
|
|
|
fprintf( stderr, "found starting C comment : %s\n", aLine.getStr() );
|
2008-10-15 08:43:33 +00:00
|
|
|
#endif
|
2011-08-16 08:54:49 +01:00
|
|
|
aLine = aLine.copy(0, nIndex);
|
2008-10-15 08:43:33 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-08-16 08:54:49 +01:00
|
|
|
fprintf( stderr, "cleaned string : %s\n", aLine.getStr() );
|
2008-10-15 08:43:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
2011-08-16 08:54:49 +01:00
|
|
|
|
|
|
|
nIndex = aLine.indexOf("//");
|
|
|
|
if ( nIndex != -1 )
|
2008-10-15 08:43:33 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-08-16 08:54:49 +01:00
|
|
|
fprintf( stderr, "found C++ comment : %s\n", aLine.getStr() );
|
2008-10-15 08:43:33 +00:00
|
|
|
#endif
|
2011-08-16 08:54:49 +01:00
|
|
|
aLine = aLine.copy(0, nIndex);
|
2008-10-15 08:43:33 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-08-16 08:54:49 +01:00
|
|
|
fprintf( stderr, "cleaned string : %s\n", aLine.getStr() );
|
2008-10-15 08:43:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
// WhiteSpacesfressen
|
2011-08-16 08:54:49 +01:00
|
|
|
using comphelper::string::replace;
|
|
|
|
aLine = replace(aLine, rtl::OString(' '), rtl::OString());
|
|
|
|
aLine = replace(aLine, rtl::OString('\t'), rtl::OString());
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-08-16 08:54:49 +01:00
|
|
|
fprintf( stderr, "now : %s\n", aLine.getStr() );
|
2001-06-13 12:43:51 +00:00
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
// ist der erste Teil ein #include ?
|
2011-08-16 08:54:49 +01:00
|
|
|
rtl::OString aRetStr;
|
|
|
|
if (
|
|
|
|
aLine.getLength() >= 10 &&
|
|
|
|
aLine.match(rtl::OString(RTL_CONSTASCII_STRINGPARAM("#include")))
|
|
|
|
)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-08-16 08:54:49 +01:00
|
|
|
//#include<foo> or #include"foo"
|
|
|
|
aLine = aLine.copy(9, aLine.getLength()-10);
|
2001-06-13 12:43:51 +00:00
|
|
|
#ifdef DEBUG_VERBOSE
|
2011-08-16 08:54:49 +01:00
|
|
|
fprintf( stderr, "Gotcha : %s\n", aLine.getStr() );
|
2001-06-13 12:43:51 +00:00
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
aRetStr = aLine;
|
|
|
|
}
|
|
|
|
return aRetStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TEST
|
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
2011-08-17 15:31:50 +01:00
|
|
|
CppDep *pDep = new CppDep();
|
2000-09-18 16:07:07 +00:00
|
|
|
pDep->AddSearchPath(".");
|
|
|
|
pDep->AddSearchPath("/usr/include");
|
|
|
|
pDep->AddSearchPath("/usr/local/include");
|
|
|
|
pDep->AddSearchPath("/usr/include/sys");
|
|
|
|
pDep->AddSearchPath("/usr/include/X11");
|
|
|
|
pDep->Execute();
|
|
|
|
delete pDep;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|