Click here to Skip to main content
15,891,409 members
Articles / Programming Languages / C++

Useful Managers

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
11 Aug 2001 80.5K   1.2K   16  
An add-in for Devstudio that provides tag indexing and search, window, bookmarks, session and other managers
/*****************************************************************************
*   $Id: entry.c,v 8.4 1999/06/22 02:29:38 darren Exp $
*
*   Copyright (c) 1996-1999, Darren Hiebert
*
*   This source code is released for free distribution under the terms of the
*   GNU General Public License.
*
*   This module contains functions for creating tag entries.
// Modified by Mike Melnikov
*****************************************************************************/
#include "stdafx.h"

#include "entry.h"
#include "..\RegularExpressions.h"
#include <algorithm>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

char* g_tagFolders[] =
{
  "class",     //c
  "struct",    //s
  "function",  //f
  "enum",      //g
  "enum const",//e
  "union",     //u
  "define",    //d
  "interface", //
  "member",    //m
  "typedef",   //t
  "variable",  //v
  "extern",    //x
  "file",      //file
  "include",   //include
};

Project Project::commonProject;


tagFile TagFile;

/*----------------------------------------------------------------------------
 *  Tag entry management
 *--------------------------------------------------------------------------*/
void writeCtagsEntry(ClassItem& classItem,tagType type)
{
  classItem.fileIndex = TagFile.currentFile;

  if(classItem.parents.IsEmpty())
  {
	  if(TagFile.classes.m_children[type].size()<0x8fff) // 32...
       TagFile.classes.m_children[type].push_back(classItem);
  }
  else
    TagFile.childrens.m_children[type].push_back(classItem);
}

void operator >> (CArchive& fp,ClassItem& item)
{
  fp >> item.m_name;
  fp >> item.fileIndex;                         
  fp >> item.m_line;
  WORD mask,bit = 1;
  fp >> mask;
  for(int i=0;i<TAG_COUNT;i++)
  {
    if(mask&bit)
      fp >> item.m_children[i];
    bit <<= 1;
  }
  fp >> item.m_ichildren;
  fp >> item.m_iparents;
}

void operator <<(CArchive& fp,const ClassItem& item)
{
  ASSERT(item.m_line>=0);
  fp << item.m_name;
  fp << item.fileIndex;
  fp << item.m_line;
  WORD mask=0,bit = 1;
  for(int i=0;i<TAG_COUNT;i++)
  {
    if(item.m_children[i].size())
      mask |= bit;
    bit <<= 1;
  }
  fp << mask;
  for(   i=0;i<TAG_COUNT;i++)
  {
    if(item.m_children[i].size())
      fp << item.m_children[i];
  }
  fp << item.m_ichildren;
  fp << item.m_iparents;
}

void ClassItem::assign(const ClassItem& item)
{
  m_name       = item.m_name;
  fileIndex    = item.fileIndex;
  m_line       = item.m_line;
  parents      = item.parents;
  for(int i=0;i<TAG_COUNT;i++)
    m_children[i] = item.m_children[i];
  classParents = item.classParents;
  m_ichildren  = item.m_ichildren;
  m_iparents   = item.m_iparents;
//  access = item.access;
}

void ClassItem::clear()
{
  for(int i=0;i<TAG_COUNT;i++)
   m_children[i].clear();
}

bool ClassItem::isEmpty()
{
  for(int i=0;i<TAG_COUNT;i++)
   if(m_children[i].size())
     return false;
  return true;
}

short ClassItem::getLine()
{
  if(m_line)
    return m_line;
  if(m_ichildren.size())
    return m_ichildren[0].line;
  return m_iparents[0].line;
}
CString ClassItem::getFile()
{
  int index = fileIndex<0 ? (m_ichildren.size() ? m_ichildren[0].file : m_iparents[0].file) : fileIndex;
  return TagFile.m_files[index].m_name.c_str();
}

short ClassItem::countDeltaLine(short lineIn,int nFile)
{
  ASSERT(m_line>=0);
  if(m_line!=0)
    return fileIndex==nFile ? lineIn - m_line : -1;
  short delta = 10000;
  for(unsigned int i=0;i<m_ichildren.size();i++)
  {
    if(m_ichildren[i].file==nFile)
    {
      short d = lineIn - m_ichildren[i].line;
      if(d>=0)
       delta = min(d,delta);
    }
  }
  for(int j=0;j<m_iparents.size();j++)
  {
    if(m_iparents[i].file==nFile)
    {
      short d = lineIn - m_iparents[i].line;
      if(d>=0)
       delta = min(d,delta);
    }
  }
  return delta;
}


// utils
CString contact(CString& path,LPCTSTR file)
{
  CString str = path;
  addSlash(str);
  str += file;
  return str;
}

void addSlash(CString& str)
{
	TrimRight(str,"\\");
	str += '\\';
}

/*----------------------------------------------------------------------------
*  Pathname manipulation (O/S dependent!!!)
*--------------------------------------------------------------------------*/
void baseFilename(const CString& file,CString& fileName,CString& filePath)
{
  //  Find whichever of the path delimiters is last.
  static const char PathDelimiters[] = ":/\\";
  int tail=-1;
  for (unsigned int i = 0  ;  i < strlen(PathDelimiters)  ;  ++i)
  {
    int sep = file.ReverseFind(PathDelimiters[i]);
    if (sep > tail)
      tail = sep;
  }
  if(tail<0)
  {
    fileName = file;
    filePath = file;
  }
  else
  {
		fileName = file.Mid(tail+1);
  	filePath = file.Left(tail);
  }
}

short tagFile::getFileIndex(string str)
{
  SourceFile  toFind; toFind.m_name = str;
  SourceFile* found = lower_bound(m_files.begin(),m_files.end(),toFind,less<SourceFile>());
  // check have we such file check if we in some file such as .def
  if(!found || found==m_files.end() || str<found->m_name)
    return 0;
  return found - m_files.begin();
}

void Project::addFile(string file,ParseState state)
{
  m_files.push_back(file);
  string shortName = file.data() + file.rfind('\\') + 1;
  std::ctype<char> t;
  t.tolower(shortName.begin(),shortName.end());
  m_shortNames.push_back(shortName);

  SourceFile sfile;
  sfile.m_name = file;
  sfile.project = this;
  sfile.m_shouldParse = state;
  TagFile.m_files.push_back(sfile);
}

bool Project::Normalize(const string& path,const string& file,string& testFile)
{
  testFile = path + string("\\") + file;
  CFileStatus fileStatus;
  if(CFile::GetStatus(testFile.c_str(), fileStatus))
  {
    testFile = fileStatus.m_szFullName;
    return true;
  }
  return false;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
Mike has been programming in C/C++ for 11 years and Visual C++/MFC for 4 years. His background includes pure and applied mathematics, engineering and physics, and he is currently based in Moscow, Russia.

Comments and Discussions