Página principal Juegos de ordenador Programación de juegos Relacionado con el autor Acerca de esta web
Infografía Gráficos por ordenador Desarrollo de Software Página no official de Gráficos Avanzados (URL)
-Página principal
-Infografía
-Juegos de ordenador
-Gráficos por ordenador
-Programación de juegos
-Desarrollo de Software
-Todos los lenguajes
-Legislación y software
-Teoría
-ASP
-CFM
-C/C++
-Misc
-Compiladores
-Microsoft Foundation Classes
-Microsoft Visual Studio
-Delphi
-Java
-Javascript
-Lisp
-Lua
-.NET
-PERL
-PHP
-Pythoon
-SQL
-Visual Basic
-VBScript
-Otros lenguajes
-Desarrollo de Webs
-Herramientas de desarrollo
-Relacionado con el autor
-Página no official de Gráficos Avanzados (URL)
-Acerca de esta web
 

Adjust file classes 
Microsoft Visual Studio
This program changes the name of the .cpp and .h files containing a class, changing .dsp
Autor M.L. Viñas Livschitz  Última actualización 2000-08-07  Inglés
 

<< Using the program Performing changes >>

Developing the program

The mechanism its easy in concept. You must open the .dsp locate the headers and inside them locate the classes, make the correct changes and no more. As you will imagine the solution is not so easy... Let's take a look to the dsp file.

# Microsoft Developer Studio Project File - Name="ODBC_Query" - Package Owner=<4>
...
# Begin Target
# Name "ODBC_Query - Win32 Release"
# Name "ODBC_Query - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\ODBC_Query.cpp
# End Source File
# Begin Source File
SOURCE=.\ODBC_Query.rc
# End Source File
...
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"stdafx.h"
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\ODBC_Query.h
# End Source File
...
# End Target
# End Project


Is the group important? it depends on the developer that manages the project, but it's sure that a source file finishes in .cpp and a header file finishes in .h, and both files are after a # Begin Source File declaration in a line started with SOURCE=.

Then the code is like that:

// contains all files that not have class declarations
CStringList SourceFiles; 
 
CStringList HeaderFiles;
{       
 // Now we need to scan de dsp file
 CString StringFile = _ReadStringFile(m_Project);
 {      
  // Next step: Look for source files and header ones
  SourceFiles.RemoveAll(); // can be avoided (it's always empty)
 
  PD.SetRange(0,StringFile.GetLength());
  PD.SetStatus("Looking for files in the project.");
 
  int ini_pos = 0;
 
  do
  {
   ini_pos=StringFile.Find("# Begin Source File",ini_pos);
   if (ini_pos==-1) break;
   PD.SetStep(ini_pos);
 
   // Ok, there is a source file
   CString     FirstToken = "SOURCE=",
   LastToken = "\n";
 
   // Get the file
   ini_pos = StringFile.Find(FirstToken,ini_pos) 
           + FirstToken.GetLength();
 
   int SFileSize = StringFile.Find(LastToken,ini_pos)
                 - ini_pos-LastToken.GetLength();
 
   CString SFile = StringFile.Mid(ini_pos,SFileSize);
 
   // It's valid?
   SFile.Replace('\\','/');
 
   if (SFile.Left(2)=="./") SFile=SFile.Mid(2);
 
   if (!ExistFileAtWorkingDir(SFile))
   {
    ::AfxMessageBox("The file "+SFile+" "
                    "doesn't exist, avoiding it");
   }
   else
   {
    // It's a header?
    CString Extension = SFile.Right(2);
 
    Extension.MakeUpper();
    if(Extension==".H")
    {
     HeaderFiles.AddTail(SFile);
     m_Headers.AddString(SFile);
    };
 
    Extension = SFile.Right(4);
    Extension.MakeUpper();
    if(Extension==".CPP")
    {
     SourceFiles.AddTail(SFile);
     m_Sources.AddString(SFile);
    };
 
    // other kind of files are not included
   }
  } while(true);
 }
}

The next thing to examine is the definition of a class and it may be the most smart.

If we suppose that a class is defined in one line (As it should be), we have three patterns:

  • class(1) export_d(0-1)...other_stuff(0-1) THECLASS(1) :(1)
  • class(1) export_d(0-1)...other_stuff(0-1) THECLASS(1) {(1)
  • class(1) export_d(0-1)...other_stuff(0-1) THECLASS(1)

Where the '(n)' means the cardinality ( (0-1) means that it may exists or not ).

// Look for the first class definition
bool ClassFound = false;
while(!ClassFound)
{
 CString Buffer;
 
 if (!fHead.ReadString(Buffer)) break;
 
 CString ClassToken = "class ";
 
 if ((Buffer.Left(ClassToken.GetLength())==ClassToken)
 &&(Buffer.Find(';')==-1)) // No pre-declarations here
 {      
  // We found a class definition
  int Pos;
  // First pattern : 
  // 'class(1) export_d(0-1) ... other_stuff(0-1) THECLASS(1) :(1)'
  if ((Pos = Buffer.Find(':'))!=-1) // Ok
  {
   ClassName=Buffer.Left(Pos);
   ClassName.TrimRight();
   Pos = ClassName.ReverseFind(' ');
   ClassName=ClassName.Right(ClassName.GetLength()-(Pos+1));
   ClassFound=true;
  }
 
  // Second pattern : 
  // 'class(1) export_d(0-1) ... other_stuff(0-1) THECLASS(1) {(1)'
  else if ((Pos = Buffer.Find('{'))!=-1) // Ok
  {
   ClassName=Buffer.Left(Pos);
   ClassName.TrimRight();
   Pos = ClassName.ReverseFind(' ');
   ClassName=ClassName.Right(ClassName.GetLength()-(Pos+1));
   ClassFound=true;
  }
  else
  // Third pattern : 
  // 'class(1) export_d(0-1) ... other_stuff(0-1) THECLASS(1)'
  {
   ClassName=Buffer;
   ClassName.TrimRight();
   Pos = ClassName.ReverseFind(' ');
   ClassName=ClassName.Right(ClassName.GetLength()-(Pos+1));
   ClassFound=true;
  }
   if(ClassFound)
  {
   int hItem=m_HeadersClasses.InsertItem(0,"");
   m_HeadersClasses.SetItemText(hItem,0,TheHeader);
   m_HeadersClasses.SetItemText(hItem,1,ClassName);
  
   CString CorrectHeader;
   if (ClassName.Left(1)=='C')
    CorrectHeader=ClassName.Mid(1);
   else
    CorrectHeader=ClassName;
 
   CorrectHeader+=".h";
 
   if (TheHeader!=CorrectHeader)
 
   if (IDNO
   ==  ::AfxMessageBox(CString()+"Shall I change old:"
       +TheHeader+" by new:"+CorrectHeader,MB_YESNO))
   {
    CorrectHeader=TheHeader;
    ClassFound=false;
   }
 
   if(ClassFound)
   {
    if(TheHeader!=CorrectHeader)
    {
     SourceDeps.SetAt(TheHeader,ClassName);
     ClassToCorrectHeader.SetAt(ClassName,CorrectHeader);
     m_HeadersClasses.SetItemText(hItem,2,"Need change");
    }
    else
    {
     m_HeadersClasses.SetItemText(hItem,2,"No need to change");
    }
   }
  }
  m_HeadersClasses.Arrange(LVA_DEFAULT);
 }
}
fHead.Close();

<< Using the program Performing changes >>

Todas y cada una de las marcas mostradas aqui pertenecen a sus respectivos propietarios. Por favor, lea nuestros términos, condiciones e información acerca de la privacidad.
Optimizado para una resolución mayor o igual a 1024x768, true-color, usando Microsoft Internet Explorer 5.0 o superior.
Este sitio fue diseñado y desarrollado por Manuel Lucas Viñas Livschitz.
Copyright 2000-2002 M.L.Viñas Livschitz.
To subscribe send a mail without subject to ultralight_magazine-subscribe@eListas.net
Para suscribirte manda un mail sin asunto a: ultralight_magazine-alta@eListas.net
To cancel subscription send a mail without subject to ultralight_magazine-unsubscribe@eListas.net
Para cancelar tu suscripción manda un mail sin asunto a: ultralight_magazine-baja@eListas.net

Contactar con el webmaster