home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / IDEHOOK.PAK / SECTCOMP.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  4KB  |  194 lines

  1. //----------------------------------------------------------------------------
  2. // IdeHook - (C) Copyright 1994 by Borland International
  3. //----------------------------------------------------------------------------
  4. #pragma hdrstop
  5.  
  6. #include "idehook.h"
  7. #include "pathspec.h"
  8. #include <string.h>
  9.  
  10. static char realCppCompileName[]    = "CppCompile";
  11. static char sectionCppCompileName[] = "SectionCppCompile";
  12.  
  13.  
  14. class _HOOKCLASS LocalToolClient : public ToolClient
  15. {
  16. public:
  17.     ToolReturn _HOOKEP RunSectionCompiler( ToolInvokeArgs * );
  18.  
  19.     void RegisterMyCallBacks( ToolServer * );
  20.  
  21. private:
  22.  
  23.             int                 registered;
  24.     static  ToolRegisterPack    entryPoints[];
  25.  
  26. };
  27.  
  28. static LocalToolClient  localToolClient;
  29.  
  30. ToolRegisterPack LocalToolClient::entryPoints[] =
  31. {
  32.     { sectionCppCompileName, (ToolMethod)&LocalToolClient::RunSectionCompiler },
  33.     { 0 }
  34. };
  35.  
  36. void
  37. LocalToolClient::RegisterMyCallBacks( ToolServer * ts )
  38. {
  39.     if( !registered )
  40.     {
  41.         registered = 1;
  42.         ts->ToolRegisterImplementor( this, entryPoints );
  43.     }
  44. }
  45.  
  46. ToolReturn _HOOKEP 
  47. LocalToolClient::RunSectionCompiler( ToolInvokeArgs * args )
  48. {
  49.     ProjectNode   node = args->numNodes ? *args->nodeArray : 0;
  50.  
  51.     if( node )
  52.     {
  53.         OptionSetReq    optSetServer;
  54.         const char *    defines;
  55.  
  56.         optSetServer->OptionGet( node, OID_Defines, defines );
  57.  
  58.         const char *    pSectionText;
  59.         static char     szSection[] = "SECTION=";
  60.  
  61.         if( (pSectionText = strstr( defines, szSection)) != 0 )
  62.         {
  63.             ProjectNodeInfo    nodeInfo;
  64.             ProjectReq         projectServer;
  65.  
  66.             projectServer->QueryNodeInfo( node, nodeInfo );
  67.  
  68.             PathSpec           outPath( nodeInfo.outputLocation );
  69.  
  70.             char               newName[ MAXFILE + 2 ];
  71.  
  72.             strcpy( newName, outPath.file() );
  73.  
  74.             int    numberIndex = strlen(newName);
  75.  
  76.             if( numberIndex == 8 )
  77.                 --numberIndex;
  78.  
  79.             newName[ numberIndex++ ] = *(pSectionText + (sizeof(szSection)-1));
  80.             newName[ numberIndex ] = 0;
  81.  
  82.             outPath.file( newName );
  83.  
  84.             optSetServer->OptionApply( node, OID_Intermediate, outPath.path() );
  85.  
  86.         }
  87.  
  88.         ToolReq  server;
  89.         ToolObj  realCompiler = server->ToolFind( realCppCompileName );
  90.  
  91.         return( server->ToolInvoke( realCompiler, node ) );
  92.  
  93.     }
  94.  
  95.     return( NotHandled );
  96.  
  97. }
  98.  
  99.  
  100. //
  101. //  Project stuff
  102. //
  103.  
  104. class _HOOKCLASS LocalProjClient : public ProjectClient
  105. {
  106. public:
  107.    LocalProjClient();
  108.    
  109.     virtual void _HOOKEP    OpenNotify
  110.                                     (
  111.                                         const char * name 
  112.                                     );
  113.  
  114.     virtual void _HOOKEP    CloseNotify();
  115.  
  116.     virtual void _HOOKEP NodeDeleteNotify
  117.                                     (
  118.                                         ProjectNode
  119.                                     );
  120.  
  121.     virtual void _HOOKEP  DependencyQueryResponder
  122.                                     (
  123.                                         ProjectNode ,
  124.                                         const char *
  125.                                     );
  126.  
  127. };
  128.  
  129. static LocalProjClient LocalProjClient;
  130.  
  131. LocalProjClient::LocalProjClient()
  132. {
  133.    ProjectReq ps;
  134.  
  135.    ps->RegisterProjectClient(this);
  136. }
  137.  
  138.  
  139. void _HOOKEP
  140. LocalProjClient::OpenNotify
  141. (
  142.    const char * // name 
  143. )
  144. {
  145.     ToolReq   ts;
  146.  
  147.     localToolClient.RegisterMyCallBacks( ts );
  148.  
  149.     if( !ts->ToolFind( sectionCppCompileName ) )
  150.     {
  151.         ToolObj realCppCompiler;
  152.  
  153.         if( (realCppCompiler = ts->ToolFind( realCppCompileName )) != 0 )
  154.         {
  155.             ToolInfo toolInfo;
  156.  
  157.             ts->QueryToolInfo( realCppCompiler, toolInfo );
  158.  
  159.             toolInfo.name           = sectionCppCompileName;
  160.             toolInfo.menuName       = "&Section Compiler";
  161.             toolInfo.helpHint       = "Munge outname of node then C++ Compile";
  162.             toolInfo.launchId       = CALLBACK_LAUNCH_ID;
  163.  
  164.             ts->ToolAdd( &toolInfo );
  165.         }
  166.     }
  167.    
  168. }
  169.  
  170. void _HOOKEP
  171. LocalProjClient::CloseNotify()
  172. {
  173. }
  174.  
  175. void _HOOKEP
  176. LocalProjClient::NodeDeleteNotify
  177. (
  178.    ProjectNode
  179. )
  180. {
  181. }
  182.  
  183. void _HOOKEP
  184. LocalProjClient::DependencyQueryResponder
  185. (
  186.    ProjectNode ,
  187.    const char *
  188. )
  189. {
  190. }
  191.  
  192. // End of file
  193.  
  194.