home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / C_C++ / BisonFlexWizard / data1.cab / Src / Wizard / ParserAw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-16  |  6.5 KB  |  214 lines

  1. // Parseraw.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Parser.h"
  6. #include "Parseraw.h"
  7. #include "chooser.h"
  8. #include <comdef.h>
  9.  
  10. #ifdef _PSEUDO_DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. IApplication *iapp = 0;
  16. // This is called immediately after the custom AppWizard is loaded.  Initialize
  17. //  the state of the custom AppWizard here.
  18. void CParserAppWiz::InitCustomAppWiz()
  19. {
  20.     // Create a new dialog chooser; CDialogChooser's constructor initializes
  21.     //  its internal array with pointers to the steps.
  22.     m_pChooser = new CDialogChooser;
  23.  
  24.     // Set the maximum number of steps.
  25.     SetNumberOfSteps(LAST_DLG);
  26. //    SetNumberOfSteps(0);
  27.  
  28.     // TODO: Add any other custom AppWizard-wide initialization here.
  29. }
  30.  
  31. // This is called just before the custom AppWizard is unloaded.
  32. void CParserAppWiz::ExitCustomAppWiz()
  33. {
  34.     // Deallocate memory used for the dialog chooser
  35.     ASSERT(m_pChooser != NULL);
  36.     delete m_pChooser;
  37.     m_pChooser = NULL;
  38.     // TODO: Add code here to deallocate resources used by the custom AppWizard
  39.  
  40.     CString s;
  41.     CString c_only;
  42.     m_Dictionary.Lookup(_T("root"),s);
  43.     m_Dictionary.Lookup(_T("C_ONLY"),c_only);
  44.     
  45.     if (c_only.IsEmpty())
  46.     {
  47.         DeleteFile(s+".cpp");
  48.         DeleteFile(s+".l.cpp");
  49.         DeleteFile(s+".cpp.h");
  50.     }
  51.     else
  52.     {
  53.         DeleteFile(s+".tab.c");
  54.         DeleteFile(s+".l.c");
  55.         DeleteFile(s+".tab.h");
  56.     }
  57.     //CopyFile(s+"_tmp.dsp", s+".dsp", FALSE);
  58.     //DeleteFile(s+"_tmp.dsp");
  59.  
  60.     if (iapp!=0)
  61.     {
  62.         //ReloadProject(iapp);
  63.         iapp->Release();
  64.     }
  65.  
  66.  
  67. }
  68.  
  69. // This is called when the user clicks "Create..." on the New Project dialog
  70. //  or "Next" on one of the custom AppWizard's steps.
  71. CAppWizStepDlg* CParserAppWiz::Next(CAppWizStepDlg* pDlg)
  72. {
  73.     // Delegate to the dialog chooser
  74.     return m_pChooser->Next(pDlg);
  75. }
  76.  
  77. // This is called when the user clicks "Back" on one of the custom
  78. //  AppWizard's steps.
  79. CAppWizStepDlg* CParserAppWiz::Back(CAppWizStepDlg* pDlg)
  80. {
  81.     // Delegate to the dialog chooser
  82.     return m_pChooser->Back(pDlg);
  83. }
  84.  
  85. void CParserAppWiz::CustomizeProject(IBuildProject* pProject)
  86. {
  87.     // TODO: Add code here to customize the project.  If you don't wish
  88.     //  to customize project, you may remove this virtual override.
  89.     
  90.     // This is called immediately after the default Debug and Release
  91.     //  configurations have been created for each platform.  You may customize
  92.     //  existing configurations on this project by using the methods
  93.     //  of IBuildProject and IConfiguration such as AddToolSettings,
  94.     //  RemoveToolSettings, and AddCustomBuildStep. These are documented in
  95.     //  the Developer Studio object model documentation.
  96.  
  97.     // WARNING!!  IBuildProject and all interfaces you can get from it are OLE
  98.     //  COM interfaces.  You must be careful to release all new interfaces
  99.     //  you acquire.  In accordance with the standard rules of COM, you must
  100.     //  NOT release pProject, unless you explicitly AddRef it, since pProject
  101.     //  is passed as an "in" parameter to this function.  See the documentation
  102.     //  on CCustomAppWiz::CustomizeProject for more information.
  103.  
  104.     CString root;
  105.     CString c_only;
  106.     m_Dictionary.Lookup(_T("root"),root);
  107.     m_Dictionary.Lookup(_T("C_ONLY"),c_only);
  108.  
  109.  
  110.      IConfigurations *iCfgs;        //pointer to all configurations
  111.      IConfiguration *iSingleCfg; //pointer to a individual configuration
  112.      long lCount;                          //number of configurations
  113.      long i;
  114.      
  115.      pProject->get_Application((IDispatch**)&iapp);
  116.      pProject->get_Configurations(&iCfgs);
  117.  
  118.  
  119.      iCfgs->get_Count(&lCount);
  120.  
  121.      for(i=0;i<lCount;i++)    // walk through all configurations
  122.      {    COleVariant cv(i+1L); // one-based index!!!
  123.           COleVariant cvReserved("");
  124.  
  125.           iCfgs->Item(cv,&iSingleCfg); 
  126.  
  127. /*          BSTR bstr;
  128.         iCfgs->get_Name(&bstr);
  129.         _bstr_t bsLoc = bstr;
  130.         char* lpStr = (char*)bsLoc;
  131.         AfxMessageBox(lpStr);
  132. */
  133.           // use wide-character strings...
  134.           iSingleCfg->RemoveToolSettings(L"link.exe",L"/subsystem:windows",cvReserved);
  135. //          iSingleCfg->AddCustomBuildStep(L"aaa",L"bb",L"CCC",cvReserved);
  136.           iSingleCfg->AddToolSettings(L"link.exe",L"libflex.lib",cvReserved);
  137.           iSingleCfg->AddToolSettings(L"cl.exe",L"/DYY_NEVER_INTERACTIVE",cvReserved);
  138.           
  139.          // _bstr_t lcommand("flex.exe " + s + ".l");
  140.          // _bstr_t lout(s + "l.c");
  141.          // iSingleCfg->AddCustomBuildStepToFile ( lfile, lcommand, lout, L"building lexer", cvReserved);
  142.           
  143.           _bstr_t lfile(root + ".l");
  144.           _bstr_t yfile(root + ".y");
  145.           
  146.           if (c_only.IsEmpty())
  147.           {
  148.               _bstr_t lcommand("flex.exe -P" + root + " -t $(InputName).l > $(InputName).l.cpp");
  149.               iSingleCfg->AddCustomBuildStepToFile (lfile, lcommand, L"$(InputName).l.cpp", L"Building Lexer", cvReserved);
  150.               _bstr_t ycommand("bison.exe -p" + root + " -o " + root + ".cpp -d $(InputName).y");
  151.               iSingleCfg->AddCustomBuildStepToFile (yfile, ycommand, L"$(InputName).cpp", L"Building Parser", cvReserved);
  152.           }
  153.           else
  154.           {
  155.               _bstr_t lcommand("flex.exe -P" + root + " -t $(InputName).l > $(InputName).l.c");
  156.               iSingleCfg->AddCustomBuildStepToFile (lfile, lcommand, L"$(InputName).l.c", L"Building Lexer", cvReserved);
  157.               _bstr_t ycommand("bison.exe -p" + root + " -d $(InputName).y");
  158.               iSingleCfg->AddCustomBuildStepToFile (yfile, ycommand, L"$(InputName).tab.c", L"Building Parser", cvReserved);
  159.           }
  160.           
  161.           iSingleCfg->Release();
  162.      }
  163.  
  164.     iCfgs->Release();
  165. }
  166.  
  167. void CParserAppWiz::ReloadProject(IApplication * app)
  168. {
  169.     IDocuments *idocs;
  170.     IGenericProject *iprj;
  171.     app->get_ActiveProject((IDispatch**)&iprj);
  172. //    iprj->AddRef();
  173.     BSTR name;
  174.     iprj->get_FullName(&name);
  175.     _bstr_t bsLoc = name;
  176.     
  177.     char* lpStr = (char*)bsLoc;
  178.     char *p = strstr(lpStr, "dsp");
  179.     p[2] = 'w';
  180.     DeleteFile(lpStr);
  181. //    char aaa[100];
  182. //    strcpy(aaa, lpStr);
  183. //    BSTR name1 = (BSTR)(_bstr_t)aaa;
  184.  
  185. /*        _bstr_t bsLoc1 = name1;
  186.         char* lpStr1 = (char*)bsLoc1;
  187.         AfxMessageBox(lpStr1);
  188. */
  189.     app->get_Documents((IDispatch**)&idocs);
  190. //    idocs->AddRef();
  191.     IGenericDocument *aa;
  192.     COleVariant openas("Auto");
  193.     COleVariant ro(0L);
  194. //    idocs->CloseAll(ro,0);
  195.     idocs->Open(name,openas,ro,(IDispatch**)&aa);
  196. //    DsSaveStatus ss;
  197. //    COleVariant ro1(0L);
  198. //    aa->Close(ro1, 0);
  199. //    aa->Release();
  200. //    idocs->Open(name1,openas,ro,(IDispatch**)&aa);
  201. //    aa->Release();
  202.     idocs->Release();
  203.     iprj->Release();    
  204.  
  205.  
  206.  
  207. }
  208.  
  209. // Here we define one instance of the CParserAppWiz class.  You can access
  210. //  m_Dictionary and any other public members of this class through the
  211. //  global Parseraw.
  212. CParserAppWiz Parseraw;
  213.  
  214.