home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / Chip_2002-05_cd1.bin / chplus / cpp / 3 / Tools.exe / tdump1.cpp < prev    next >
C/C++ Source or Header  |  1998-02-09  |  42KB  |  1,321 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1998 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. //------------------------------------------------------------
  6.  
  7. #pragma hdrstop
  8. #include <sys\stat.h>
  9. #include <shlobj.h>
  10. #include <WindowsX.h>
  11. #include <registry.hpp>
  12. #include <io.h>
  13. #include <assert.h>
  14.  
  15. #include "TDump1.h"
  16. #include "about.h"
  17.  
  18. #pragma resource "*.dfm"
  19.  
  20. TMainForm *MainForm;
  21. //------------------------------------------------------------
  22. __fastcall TMainForm::TMainForm(TComponent* Owner)
  23.     : TForm(Owner)
  24. {
  25.     GetRegInfo();
  26.     BinPth = "PATH=" + BCBRoot + "bin";
  27.     LibPth = BCBRoot + "lib";
  28.     IncPth = BCBRoot + "include";
  29.     ObjPth = BCBRoot + "lib\\obj";
  30.  
  31.     //Initialize globals
  32.     AppCaption = "BCB Command Line Tools : ";
  33.     Application->Title = "BCB WinTools";
  34.     Application->Icon->LoadFromFile(WintoolsDir + "WinTools.ico");
  35.     //OutFileMi->Checked = true;
  36.     SourceFileSelected = false;
  37.     ObjList = new TStringList();
  38.     Clear = false;
  39.     IsDirty = false;
  40.     BCC32 = true;
  41.     CmdStrRE->Text = "BCC32";
  42.     FilterStr = "*.c;*.cpp";
  43.     MainForm->Caption = AppCaption + "Borland 32bit C++ Compiler";
  44.     WorkDir = "C:\\";
  45. }
  46. //------------------------------------------------------------
  47.  
  48. void TMainForm::GetRegInfo()
  49. {
  50.     const String RegKey = "\\software\\borland\\C++Builder\\3.0";
  51.     TRegistry *MyRegistry = new TRegistry();
  52.     MyRegistry->RootKey = HKEY_LOCAL_MACHINE;
  53.     try {
  54.         if(MyRegistry->OpenKey(RegKey, false)) {
  55.             BCBRoot = MyRegistry->ReadString("RootDir");
  56.             if (!BCBRoot.IsEmpty()) {
  57.                 BCBRoot = BCBRoot + "\\";
  58.                 WintoolsDir = BCBRoot + "examples\\wintools\\";
  59.             }
  60.             else ShowMessage("Registry RootDir error");
  61.         MyRegistry->CloseKey();
  62.         }
  63.     }
  64.     catch(ERegistryException &E) {
  65.         ShowMessage(E.Message);
  66.         delete MyRegistry;
  67.         return;
  68.     }
  69.     delete MyRegistry;
  70. }
  71.  
  72. void TMainForm::SetEnvPath()
  73. {
  74.     String TempPath = "";
  75.     String RawPath;
  76.     String TotPath = "";
  77.     TStringList *PathList = new TStringList();
  78.     PathList->LoadFromFile(WintoolsDir + "Path.txt");
  79.     for (int n = 0; n < PathList->Count; n++) {
  80.         RawPath = "";
  81.         RawPath = PathList->Strings[n];
  82.         if (RawPath.Pos("$(BCB)")) {
  83.             RawPath.Delete(1, 7);
  84.             TempPath = TempPath + BCBRoot + RawPath + ";";
  85.         }
  86.         else  TempPath = TempPath + RawPath + ";";
  87.     }
  88.     TotPath = "PATH=" + TempPath + WorkDir;
  89.     putenv(TotPath.c_str());
  90. }
  91.  
  92. void __fastcall TMainForm::ClearClick(TObject *Sender)
  93. {
  94.  
  95.     Closeall1Click(Sender);
  96.     ClearCtls();
  97.  
  98.     // Reset globals
  99.     IsDirty = false;
  100.     ResetTools();
  101.     SourceFileSelected = false;
  102.     Clear = false;
  103.     DefExt = "";
  104.     OptionString = "";
  105.     SourceFileDir = "";
  106.     StripExt = "";
  107.     ODFileName = "";
  108.     NewDestEdit = "";
  109.     NewSourceEdit = "";
  110.     CmdStrRE->Text = "";
  111.     ObjList->Clear();
  112.  
  113.     // Reset to BCC32
  114.     PageCtl->ActivePage = PageCtl->Pages[0];
  115.     DestEd = ".txt";
  116.     RunBtn->Enabled = false;
  117.     BCC32 = true;
  118.     CmdStrRE->Text = "BCC32";
  119.     MainForm->Caption = AppCaption + "Borland 32bit C++ Compiler";
  120.  
  121.     // Set richedit
  122.     ResultsRE->Lines->Clear();
  123.     BackBtnClick(Sender);
  124.     CmdStrRE->SelStart = 0;
  125.     CmdStrRE->SelLength = CmdStrRE->Text.Length();
  126.     CmdStrRE->SelAttributes->Color = clBlack;
  127.     CmdStrRE->SelStart = 0;
  128.  
  129. }
  130. //------------------------------------------------------------
  131.  
  132. void TMainForm::ResetTools()
  133. {
  134.     // Set all tools to a non-selected state
  135.      TDump = false;
  136.     TLib = false;
  137.     ImpDef = false;
  138.     ImpLib = false;
  139.     BCC32 = false;
  140.     ILink32 = false;
  141.     TLink32 = false;
  142.     Make = false;
  143.     BRCC32 = false;
  144.     CPP32 = false;
  145.     IDEtoBPR = false;
  146.     TDStrp32 = false;
  147.     Grep = false;
  148.     Touch = false;
  149.     Coff = false;
  150.     Convert = false;
  151.     TRegAX = false;
  152.     TlbImp = false;
  153.     Tasm = false;
  154. }
  155.  
  156. void __fastcall TMainForm::ClearCtls()
  157. {
  158.     // Initialize stuff
  159.     Clear = true;
  160.     if (Grep) CmdStrRE->Text = PageCtl->ActivePage->Caption +
  161.                                                          " -";
  162.     else
  163.         CmdStrRE->Text = PageCtl->ActivePage->Caption + " ";
  164.  
  165.  
  166.     ResultsRE->Lines->Clear();
  167.     PosFound = 0;
  168.     ResultPnl->Hide();
  169.     // reset option checkboxes
  170.     TPcb3->Checked = false;
  171.        TPcb4->Checked = false;
  172.     TPcb5->Checked = false;
  173.     TPcb6->Checked = false;
  174.     TPcb7->Checked = false;
  175.     TPcb8->Checked = false;
  176.     TPcb9->Checked = false;
  177.     TLcb4->Checked = false;
  178.        TLcb5->Checked = false;
  179.     TLcb6->Checked = false;
  180.     TLcb7->Checked = false;
  181.     TLcb8->Checked = false;
  182.     TLcb9->Checked = false;
  183.  
  184.     TPcb3->Font->Color = clBlack;
  185.        TPcb4->Font->Color = clBlack;
  186.     TPcb5->Font->Color = clBlack;
  187.     TPcb6->Font->Color = clBlack;
  188.     TPcb7->Font->Color = clBlack;
  189.     TPcb8->Font->Color = clBlack;
  190.     TPcb9->Font->Color = clBlack;
  191.     TLcb4->Font->Color = clBlack;
  192.        TLcb5->Font->Color = clBlack;
  193.     TLcb6->Font->Color = clBlack;
  194.     TLcb7->Font->Color = clBlack;
  195.     TLcb8->Font->Color = clBlack;
  196.     TLcb9->Font->Color = clBlack;
  197.  
  198.  
  199.     // reset checkbox controls and font
  200.     if (ObjList->Count) {
  201.         TCheckBox *CB;
  202.         for (int indx = 0; indx < ObjList->Count; indx++) {
  203.             CB = (TCheckBox *) ObjList->Objects[indx];
  204.             CB->Checked = false;
  205.             CB->Font->Color = clBlack;
  206.         }
  207.     }
  208.     ObjList->Clear();
  209.     OptionString = "";
  210.     Clear = false;
  211. }
  212. //------------------------------------------------------------
  213.  
  214. void TMainForm::PrepareCmdLine()
  215. {
  216.    if (GetFileSize(ODFileName) > 2000000) {
  217.         ShowMessage("File is too large to process. Use dos prompt!");
  218.         ClearClick(DummySender);
  219.         return;
  220.     }
  221.     int FirstIndex;
  222.  
  223.     // Handle options selected if any
  224.     if (ObjList->Count) {
  225.         TCheckBox *CB;
  226.         for (int indx = 0; indx < ObjList->Count; indx++) {
  227.             CB = (TCheckBox *) ObjList->Objects[indx];
  228.             FirstIndex = ObjList->IndexOfObject(ObjList->
  229.                                             Objects[indx]);
  230.             if (FirstIndex >= indx) {
  231.                 if (Grep) {
  232.                     if (CB->Checked) OptionString = OptionString
  233.                                               + CB->Caption;
  234.                 }
  235.                 else
  236.                     if (CB->Checked) OptionString = OptionString
  237.                                          + " " + CB->Caption;
  238.             }
  239.         }
  240.     }
  241.  
  242.     // Prepare command line String for all tools
  243.     const String Cmd = CmdStrRE->Text;
  244.     const String Source = "\"" + ODFileName +"\"";
  245.     const String Dest = "\"" + DestEd + "\"";
  246.     const String Combine = Cmd + OptionString + " ";
  247.     const String Combine2 = Source + " ";
  248.  
  249.     if (TDump || Make || BRCC32 || IDEtoBPR || TDStrp32 || Touch ||TRegAX || Tasm32)
  250.                  CmdStrRE->Text = Combine + Source;
  251.  
  252.     if (BCC32 || CPP32)
  253.         CmdStrRE->Text = Combine + Source;
  254.  
  255.     if (ILink32 || TLink32) {
  256.         CmdStrRE->Text = Combine + Source;
  257.         if (IKcb5->Checked || TKcb5->Checked)   // console app
  258.             CmdStrRE->Text = Combine + "\"" + LibPth +
  259.              "\\c0x32.obj\" " + Source;
  260.         if (IKcb20->Checked || TKcb24->Checked) // win dll
  261.             CmdStrRE->Text = Combine + "\"" + LibPth +
  262.              "\\c0d32.obj\" " + Source;
  263.         if (IKcb21->Checked || TKcb25->Checked) // win exe
  264.             CmdStrRE->Text = Combine + "\"" + LibPth +
  265.              "\\c0w32.obj\" " + "\"" + LibPth +
  266.              "\\import32.lib\" " + "\"" + LibPth +
  267.              "\\cw32mt.lib\" " + Source;
  268.     }
  269.  
  270.     if (ImpLib) {
  271.         String SubFn;
  272.         String MultiSource = OpenDlg->Files->Count?OpenDlg->Files->Strings[0]:String("");
  273.         if (OpenDlg->Files->Count > 1)
  274.             SubFn = StripFileExt(MultiSource) + ".lib\"";
  275.         else SubFn = StripFileExt(Source) + ".lib\"";
  276.         CmdStrRE->Text = Combine + SubFn + " " + Source;
  277.     }
  278.  
  279.     if (ImpDef) {
  280.         DefExt = StripFileExt(Source) + ".def\"";
  281.         CmdStrRE->Text = Combine + DefExt + " " + Source;
  282.     }
  283.     if (Grep) {
  284.         if (!GPcb1->Checked)
  285.         CmdStrRE->Text = Cmd + OptionString + " " +
  286.             Dest + " " + "\"" + ODFileName + "\\*.*\"";
  287.         else
  288.             CmdStrRE->Text = Cmd + OptionString + " " +
  289.                                          Dest + " " + Source;
  290.     }
  291.     
  292.     if (TDump || TLib) OutFileMi->Enabled = true;
  293.     else OutFileMi->Enabled = false;
  294.  
  295.     if (TDump && (OutFileMi->Checked)) CmdStrRE->Text =
  296.                                  CmdStrRE->Text + " " + Dest;
  297.  
  298.     if (Convert) {
  299.         CmdStrRE->Text =  CmdStrRE->Text + OpenDlg->FileName;
  300.         SetCurrentDir(BCBRoot + "bin");
  301.     }
  302.  
  303.     if (TlbImp) {
  304.         bool a = TPcb3->Checked;
  305.            bool b = TPcb4->Checked;
  306.         bool c = TPcb5->Checked;
  307.         bool d = TPcb6->Checked;
  308.         bool e = TPcb7->Checked;
  309.         bool f = TPcb8->Checked;
  310.         bool g = TPcb9->Checked;
  311.         LibOps = "";
  312.         if (a) LibOps = LibOps + " " + TPcb3->Caption;
  313.         if (b) LibOps = LibOps + " " + TPcb4->Caption;
  314.         if (c) LibOps = LibOps + " " + TPcb5->Caption;
  315.         if (d) LibOps = LibOps + " " + TPcb6->Caption;
  316.         if (e) LibOps = LibOps + " " + TPcb7->Caption;
  317.         if (f) LibOps = LibOps + " " + TPcb8->Caption;
  318.         if (g) LibOps = LibOps + " " + TPcb9->Caption;
  319.     }
  320.     if (TLib) {
  321.         bool a = TLcb4->Checked;
  322.            bool b = TLcb5->Checked;
  323.         bool c = TLcb6->Checked;
  324.         bool d = TLcb7->Checked;
  325.         bool e = TLcb8->Checked;
  326.         bool f = TLcb9->Checked;
  327.         LibOps = "";
  328.         if (a) LibOps = LibOps + " " + TLcb4->Caption;
  329.         if (b) LibOps = LibOps + " " + TLcb5->Caption;
  330.         if (c) LibOps = LibOps + " " + TLcb6->Caption;
  331.         if (d) LibOps = LibOps + " " + TLcb7->Caption;
  332.         if (e) LibOps = LibOps + " " + TLcb8->Caption;
  333.         if (f) LibOps = LibOps + " " + "&";
  334.     }
  335.     if (Coff) {
  336.         DefExt = StripFileExt(Source) + "OMF.lib\"";
  337.         CmdStrRE->Text = Combine + Source + " " + DefExt;
  338.     }
  339.  
  340.     if ((TLib || TlbImp) && (OutFileMi->Checked)) CmdStrRE->Text =
  341.                 Combine + Combine2 + LibOps + "," + Dest;
  342.     if ((TLib || TlbImp) && (!OutFileMi->Checked))CmdStrRE->Text =
  343.                             Combine + Combine2 + LibOps;
  344.  
  345.     // Setup color red for word found
  346.     CHARFORMAT SelectWordFmat;
  347.     memset(&SelectWordFmat, 0, sizeof(CHARFORMAT));
  348.     SelectWordFmat.cbSize = sizeof(CHARFORMAT);
  349.     SelectWordFmat.dwMask = CFM_COLOR;
  350.     SelectWordFmat.crTextColor = 0x000000FF;
  351.  
  352.     String OneLine = CmdStrRE->Lines->Strings[0];
  353.     int Len = OneLine.Length();
  354.     String OneChar;
  355.     bool BeginSel = false;
  356.     bool EndSel = false;
  357.     int BeginPos;
  358.     int EndPos;
  359.  
  360.     // Highlight CmdLine items needing modification
  361.     for (int p = 1; p <= Len+1; p++) {
  362.          OneChar = OneLine.SubString(p, 1);
  363.         if ((OneChar == "'") && (!BeginSel)) {
  364.             BeginSel = true;
  365.             BeginPos = p;
  366.         }
  367.         if ((OneChar == "'") && (BeginSel)) {
  368.             if (BeginPos != p) {
  369.                 EndPos = p;
  370.                 EndSel = true;
  371.             }
  372.         }
  373.  
  374.         // Paint highlighted text red
  375.         if ((EndSel) && (BeginSel)) {
  376.             CmdStrRE->Perform(EM_SETSEL, BeginPos-1, EndPos);
  377.             CmdStrRE->Perform(EM_SETCHARFORMAT,
  378.                             SCF_SELECTION,
  379.                            (LPARAM) (CHARFORMAT FAR *)
  380.                            &SelectWordFmat);
  381.             CmdStrRE->Perform(EM_SETSEL, BeginPos - 1, BeginPos - 1);
  382.             BeginSel = false;
  383.             EndSel = false;
  384.         }
  385.     }
  386. }
  387. //------------------------------------------------------------
  388.  
  389. void __fastcall TMainForm::RunBtnClick(TObject *Sender)
  390. {
  391.     if (SourceFileSelected) {
  392.         ResultsRE->Clear();
  393.         int FBreak;
  394.         String TempFile;
  395.         Screen->Cursor = crHourGlass;
  396.         if (!Grep) SetEnvPath();
  397.         if (IsDirty) ResultsRE->Lines->
  398.                         SaveToFile(OpenDlg->FileName);
  399.  
  400.         ViewResults(Sender);
  401.         Application->ProcessMessages();
  402.  
  403.         // If NT do security stuff
  404.         SECURITY_DESCRIPTOR sd;
  405.         SECURITY_ATTRIBUTES sa;
  406.         LPSECURITY_ATTRIBUTES lpsa = NULL;
  407.         if (IsWindowsNT()) {
  408.             InitializeSecurityDescriptor(&sd,
  409.                 SECURITY_DESCRIPTOR_REVISION);
  410.             SetSecurityDescriptorDacl(&sd, true, NULL, false);
  411.             sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  412.             sa.bInheritHandle = true;
  413.             sa.lpSecurityDescriptor = &sd;
  414.             lpsa = &sa;
  415.         }
  416.  
  417.         // Create the Pipe and get r/w handles
  418.         HANDLE hReadPipe;
  419.         HANDLE hWritePipe;
  420.         assert(CreatePipe(&hReadPipe,
  421.                           &hWritePipe,
  422.                           lpsa,
  423.                           2500000));
  424.         // initialize STARTUPINFO struct
  425.         STARTUPINFO si;
  426.         memset(&si, 0, sizeof(STARTUPINFO));
  427.         si.cb = sizeof(STARTUPINFO);
  428.         si.dwFlags = STARTF_USESHOWWINDOW |STARTF_USESTDHANDLES;
  429.         si.wShowWindow = SW_HIDE;
  430.         si.hStdOutput = hWritePipe;
  431.         si.hStdError = hWritePipe;
  432.         PROCESS_INFORMATION pi;
  433.         assert(hWritePipe);
  434.         // Run the cmdLine tool
  435.         ResultsRE->Lines->Add("Working.....");
  436.         Application->ProcessMessages();
  437.  
  438.         assert(CreateProcess(NULL,
  439.                              CmdStrRE->Text.c_str(),
  440.                              NULL,//security
  441.                              NULL,// security
  442.                              TRUE,//inherits handles
  443.                              0,
  444.                              0,
  445.                              0,
  446.                              &si,
  447.                              &pi));
  448.  
  449.  
  450.         CloseHandle(pi.hThread);
  451.         WaitForSingleObject(pi.hProcess, 90000);
  452.  
  453.         // read from the pipe and put in richedit
  454.         assert(hReadPipe);
  455.         DWORD BytesRead; //unsigned long
  456.         char dest[4000];
  457.         bool RdLoopDone = false;
  458.         ResultsRE->Lines->Clear();
  459.         FBreak = 1;
  460.         if (ExitCode) Screen->Cursor = crDefault;
  461.         while (!RdLoopDone) {
  462.             memset(dest, 0, 4000);
  463.             assert(ReadFile(hReadPipe, &dest, sizeof(dest), &BytesRead, NULL));
  464.             ResultsRE->Lines->Add(String(dest));
  465.             if (BytesRead < 4000) RdLoopDone = true;
  466.             if (FBreak > 150) RdLoopDone = true;
  467.             FBreak++;
  468.         }
  469.         ResultsRE->Lines->Add("FINISHED!");
  470.         String RawPath;
  471.         if (BCC32 || CPP32) {
  472.             for (int h = 0; h < OpenDlg->Files->Count; h++) {
  473.                 RawPath = "";
  474.                 RawPath = OpenDlg->Files->Strings[h];
  475.                 TTabSheet *NewTabSheet = new TTabSheet(this);
  476.                 if (CPP32)
  477.                     NewTabSheet->Caption = StripFileExt(
  478.                             ExtractFileName(RawPath)) + ".i";
  479.                 else NewTabSheet->Caption =
  480.                      ExtractFileName(OpenDlg->Files->Strings[h]);
  481.                 NewTabSheet->PageControl= PageCtl2;
  482.                 TRichEdit *NewRichEdit = new TRichEdit(this);
  483.                 NewRichEdit->ScrollBars = ssBoth;
  484.                 NewRichEdit->PlainText = true;
  485.                 NewRichEdit->Parent = NewTabSheet;
  486.                 NewRichEdit->Align = alClient;
  487.                 Application->ProcessMessages();
  488.                 try {
  489.                     if (CPP32) {
  490.                         TempFile = ExtractFilePath(RawPath) +
  491.                                          NewTabSheet->Caption;
  492.                         if (GetFileSize(TempFile) > 4000000)
  493.                             NewRichEdit->Lines->
  494.                                 Add("File size exceeds limit! Use WordPad to view!");
  495.                         else
  496.                             NewRichEdit->Lines->LoadFromFile(TempFile); 
  497.                     }
  498.                     else NewRichEdit->Lines->LoadFromFile(RawPath);
  499.                 }
  500.                 catch(...) {
  501.                     ShowMessage("Unable to open file " + RawPath);
  502.                     Screen->Cursor = crDefault;
  503.                     return;
  504.                 }
  505.             }
  506.         }
  507.  
  508.         try {
  509.             if (TLib || TDump) {
  510.                  if (GetFileSize(DestEd) > 4000000)
  511.                      ResultsRE->Lines->Add("File size exceeds limit! Use WordPad to view!");
  512.                 else
  513.                     ResultsRE->Lines->LoadFromFile(DestEd);
  514.             }
  515.             if (ImpDef) ResultsRE->Lines->
  516.                 LoadFromFile(StripFileExt(OpenDlg->FileName) +
  517.                                                      ".def");
  518.         }
  519.         catch (...) {
  520.             ShowMessage("Unable to open file!");
  521.             Screen->Cursor = crDefault;
  522.             return;
  523.         }
  524.  
  525.         // Process cleanup
  526.         CloseHandle(hReadPipe);
  527.         CloseHandle(hWritePipe);
  528.         CloseHandle(pi.hProcess);
  529.         ResultsRE->Perform(EM_SETSEL,0,0);
  530.         Screen->Cursor = crDefault;
  531.         IsDirty = false;
  532.         BackBtn->Enabled = true;
  533.     }
  534.     else ShowMessage("Select a File!");
  535. }
  536. //------------------------------------------------------------
  537.  
  538. void __fastcall TMainForm::BackBtnClick(TObject *Sender)
  539. {    
  540.     ResultPnl->Hide();
  541.     BackBtn->Enabled = false;
  542. }
  543. //------------------------------------------------------------
  544.  
  545. void __fastcall TMainForm::ToolsMi(TObject *Sender)
  546. {
  547.     ResetTools();
  548.     TMenuItem* Item = dynamic_cast<TMenuItem *>(Sender);
  549.     SetupTool(Item->Caption);
  550. }
  551. //------------------------------------------------------------
  552.  
  553. void __fastcall TMainForm::ToolsPg(TObject *Sender)
  554. {
  555.     ResetTools();
  556.     SetupTool(PageCtl->ActivePage->Caption);
  557. }
  558. //------------------------------------------------------------
  559.  
  560. void TMainForm::SetupTool(String Caption)
  561. {
  562.     OutFileMi->Checked = false;
  563.     BrowseBtn->Enabled = true;
  564.  
  565.     if (Caption == "TDump") {
  566.         OutFileMi->Checked = true;
  567.            PageCtl->ActivePage = PageCtl->Pages[13];
  568.         MainForm->Caption = AppCaption + "Turbo Dump";
  569.            TDump = true;
  570.         FilterStr = "*.*";
  571.     }
  572.     if (Caption == "BCC32") {
  573.         PageCtl->ActivePage = PageCtl->Pages[0];
  574.         MainForm->Caption = AppCaption + "Borland 32bit C++ Compiler";
  575.         BCC32 = true;
  576.         FilterStr = "*.c;*.cpp";
  577.     }
  578.     if (Caption == "ImpLib") {
  579.         PageCtl->ActivePage = PageCtl->Pages[9];
  580.         MainForm->Caption = AppCaption + "Create Import Library from a DLL/DEF";
  581.         ImpLib = true;
  582.         FilterStr = "*.dll;*.def";
  583.     }
  584.     if (Caption == "ImpDef") {
  585.         PageCtl->ActivePage = PageCtl->Pages[8];
  586.         MainForm->Caption = AppCaption + "Create a .DEF File from a DLL";
  587.         ImpDef = true;
  588.         FilterStr = "*.dll";
  589.     }
  590.     if (Caption == "TRegSvr") {
  591.         PageCtl->ActivePage = PageCtl->Pages[18];
  592.         MainForm->Caption = AppCaption + "ActiveX Registration Utility .OCX";
  593.         TRegAX = true;
  594.         FilterStr = "*.ocx";
  595.     }
  596.     if (Caption == "Tasm32") {
  597.         PageCtl->ActivePage = PageCtl->Pages[11];
  598.         MainForm->Caption = AppCaption + "Turbo Assembler";
  599.         Tasm = true;
  600.         FilterStr = "*.asm";
  601.     }
  602.     if (Caption == "TLibImp") {
  603.         PageCtl->ActivePage = PageCtl->Pages[15];
  604.         MainForm->Caption = AppCaption + "Generate a C++ class from Type library .TLB";
  605.         TlbImp = true;
  606.         FilterStr = "*.tlb";
  607.     }
  608.     if (Caption == "TLib") {
  609.         PageCtl->ActivePage = PageCtl->Pages[14];
  610.         MainForm->Caption = AppCaption + "Build or Modify Libraries";
  611.         TLib = true;
  612.         FilterStr = "*.lib";
  613.     }
  614.     if (Caption == "ILink32") {
  615.         MainForm->Caption = AppCaption + "Turbo Incremental Linker";
  616.         PageCtl->ActivePage = PageCtl->Pages[7];
  617.         ILink32 = true;
  618.         FilterStr = "*.obj;*.lib";
  619.     }
  620.     if (Caption == "TLink32") {
  621.         MainForm->Caption = AppCaption + "Turbo Linker";
  622.         PageCtl->ActivePage = PageCtl->Pages[16];
  623.         TLink32 = true;
  624.         FilterStr = "*.obj;*.lib";
  625.     }
  626.     if (Caption == "Make") { //************************************************************************
  627.         PageCtl->ActivePage = PageCtl->Pages[10];
  628.         MainForm->Caption = AppCaption + "MAKE runs rules from a text file (MAKEFILE or .MAK)";
  629.         Make = true;
  630.         FilterStr = "*.mak";
  631.     }
  632.     if (Caption == "BRCC32") {
  633.         PageCtl->ActivePage = PageCtl->Pages[1];
  634.         MainForm->Caption = AppCaption + "Resource Compiler for .RC files";
  635.         BRCC32 = true;
  636.         FilterStr = "*.rc";
  637.     }
  638.     if (Caption == "CPP32") {
  639.         PageCtl->ActivePage = PageCtl->Pages[2];
  640.         MainForm->Caption = AppCaption + "C++ PreProcessor for .Cxx and .Hxx files";
  641.         CPP32 = true;
  642.         FilterStr = "*.c;*.cpp;*.h;*.hpp";
  643.     }
  644.     if (Caption == "IDEtoBPR") {
  645.         PageCtl->ActivePage = PageCtl->Pages[6];
  646.         MainForm->Caption = AppCaption + "Convert .IDE to .BPR File";
  647.         IDEtoBPR = true;
  648.         FilterStr = "*.ide";
  649.     }
  650.     if (Caption == "Coff2omf") {
  651.         PageCtl->ActivePage = PageCtl->Pages[3];
  652.         MainForm->Caption = AppCaption + "Convert Coff import Lib to OMF import lib";
  653.         Coff = true;
  654.         FilterStr = "*.lib";
  655.     }
  656.     if (Caption == "Convert") {
  657.         PageCtl->ActivePage = PageCtl->Pages[4];
  658.         MainForm->Caption = AppCaption + "Convert .DFM to .TXT or .TXT to .DFM";
  659.         Convert = true;
  660.         FilterStr = "*.dfm;*.txt";
  661.     }
  662.     if (Caption == "TDStrp32") {
  663.         PageCtl->ActivePage = PageCtl->Pages[12];
  664.         MainForm->Caption = AppCaption + "Turbo Debugger Symbol Table Stripper for .EXE";
  665.         TDStrp32 = true;
  666.         FilterStr = "*.exe";
  667.     }
  668.     if (Caption == "Grep") {
  669.         GrepMi(DummySender);
  670.     }
  671.     if (Caption == "Touch") {
  672.         PageCtl->ActivePage = PageCtl->Pages[17];
  673.         MainForm->Caption = AppCaption + "Change File Date/Time Attributes";
  674.         Touch = true;
  675.         FilterStr = "*.*";
  676.     }
  677.     ClearCtls();
  678.     CmdStrRE->Text = PageCtl->ActivePage->Caption + " ";
  679.     OptionString = "";
  680.     if (SourceFileSelected) PrepareCmdLine();
  681. }
  682.  
  683. void __fastcall TMainForm::GrepMi(TObject *Sender)
  684. {
  685.     BrowseBtn->Enabled = false;
  686.     ResetTools();
  687.     PageCtl->ActivePage = PageCtl->Pages[5];
  688.     MainForm->Caption = AppCaption + "Grep Text Search Utility";
  689.     String GWord;
  690.     Application->ProcessMessages();
  691.  
  692.     // Use Windows 95 Directory box to get dir
  693.     BROWSEINFO bi;
  694.       char GDir[MAX_PATH];
  695.       char FolderName[MAX_PATH];
  696.       LPITEMIDLIST ItemID;
  697.       memset(&bi, 0, sizeof(BROWSEINFO));
  698.       memset(GDir, 0, MAX_PATH);
  699.       bi.hwndOwner      = Handle;
  700.       bi.pszDisplayName = FolderName;
  701.       bi.lpszTitle      = "Select Directory to Search In!";
  702.       ItemID = SHBrowseForFolder(&bi);
  703.       SHGetPathFromIDList(ItemID, GDir);
  704.       GlobalFreePtr(ItemID);
  705.     String Temp = String(GDir);
  706.     if (Temp == "") return;
  707.  
  708.     // Get the word to search for
  709.     bool SelectOK = InputQuery("Enter Word", "Grep for ?",GWord);
  710.     if (!SelectOK) return;
  711.        Grep = true;
  712.        OptionString = "";
  713.        ObjList->Clear();
  714.        ClearCtls();
  715.        CmdStrRE->Text = "Grep -";
  716.     DestEd = GWord;
  717.     SourceEd = Temp;
  718.     ODFileName = Temp;
  719.     FindDialog1->FindText = GWord;
  720.  
  721.     SourceFileSelected = true;
  722.     CmdStrRE->Text = PageCtl->ActivePage->Caption + " -";
  723.     OptionString = "";
  724.     PrepareCmdLine();
  725.     RunBtn->Enabled = true;
  726.     OpenAtCursor->Enabled = true;
  727. }
  728. //------------------------------------------------------------
  729.  
  730. int TMainForm::HandleOpenDlgs(String FilterStr)
  731. {
  732.     OpenDlg->FileName = FilterStr;
  733.     OpenDlg->InitialDir = WorkDir;
  734.     if (OpenDlg->Execute()) {
  735.         SourceFileSelected = true;
  736.         SourceEd = "";
  737.  
  738.         // For multifiles
  739.         if (OpenDlg->Files->Count > 1) {
  740.             for (int h = 0; h < OpenDlg->Files->Count; h++) {
  741.                 if (h < OpenDlg->Files->Count -1) {
  742.  
  743.                     if (h == 0)
  744.                         SourceEd = SourceEd +
  745.                              OpenDlg->Files->Strings[h] +
  746.                              "\"" + " ";
  747.                     else
  748.                         SourceEd = SourceEd +
  749.                               "\"" + OpenDlg->Files->
  750.                               Strings[h] + "\"" + " ";
  751.                 }
  752.                 else
  753.                     SourceEd = SourceEd + "\"" +
  754.                             OpenDlg->Files->Strings[h];
  755.             }
  756.         }
  757.         else
  758.             SourceEd = OpenDlg->FileName;
  759.  
  760.  
  761.         ODFileName = ExtractFileName(OpenDlg->FileName);
  762.         SourceEd = OpenDlg->FileName;
  763.         SourceFileDir = ExtractFileDir(OpenDlg->FileName);
  764.         SetCurrentDir(SourceFileDir);
  765.         WorkDir = SourceFileDir;
  766.         NewDestEdit = StripFileExt(ODFileName) + ".txt";
  767.         DestEd = SourceFileDir + "\\" + NewDestEdit;
  768.         CmdStrRE->Text = PageCtl->ActivePage->Caption + " ";
  769.         OptionString = "";
  770.         PrepareCmdLine();
  771.         ObjList->Clear();
  772.         RunBtn->Enabled = true;
  773.         return 1;
  774.     }
  775.     else
  776.         return 0;
  777. }
  778. //------------------------------------------------------------
  779.  
  780. void __fastcall TMainForm::FindDialog1Find(TObject *Sender)
  781. {
  782.     const String Search = FindDialog1->FindText;
  783.     FindNext1->Enabled = true;
  784.     FindNext2->Enabled = true;
  785.  
  786.     // Setup color red for word found
  787.     CHARFORMAT SelectWordFmat;
  788.     memset(&SelectWordFmat, 0, sizeof(CHARFORMAT));
  789.     SelectWordFmat.cbSize = sizeof(CHARFORMAT);
  790.     SelectWordFmat.dwMask = CFM_COLOR;
  791.     SelectWordFmat.crTextColor = 0x000000FF;
  792.  
  793.     // Setup search struct
  794.     bool FoundOne;
  795.     TFindText MyTFindText;
  796.     MyTFindText.chrg.cpMin = PosFound;
  797.     if (PosFound)
  798.         MyTFindText.chrg.cpMin = PosFound + Search.Length();
  799.     MyTFindText.chrg.cpMax = -1;
  800.     MyTFindText.lpstrText = strdup(Search.c_str());
  801.  
  802.     // Perform search on active richedit
  803.     TRichEdit *RE = (TRichEdit *) PageCtl2->ActivePage->
  804.                                                 Controls[0];
  805.  
  806.     PosFound = RE->Perform(EM_FINDTEXT, 0, (LPARAM) (&MyTFindText));
  807.     FoundOne = PosFound != -1;
  808.     RE->Perform(EM_SETSEL, PosFound, PosFound + Search.Length());
  809.     RE->Perform(EM_SCROLLCARET, 0, 0);
  810.     RE->SetFocus();
  811.  
  812.     if (!FoundOne) {
  813.         if (Search != "Function name") {
  814.             ShowMessage("End of Page! \"" + Search +
  815.                                          "\" not found!");
  816.             FindNext1->Enabled = false;
  817.             FindNext2->Enabled = false;
  818.             return;
  819.         }
  820.     }
  821.     else{ // Set select color red
  822.         RE->Perform(EM_SETCHARFORMAT,
  823.                             SCF_SELECTION,
  824.                            (LPARAM) (CHARFORMAT FAR *)
  825.                            &SelectWordFmat);
  826.         RE->Perform(EM_SETSEL, PosFound, PosFound);
  827.       }
  828. }
  829. //------------------------------------------------------------
  830.  
  831. void __fastcall TMainForm::Toolcbs(TObject *Sender)
  832. {
  833.     // Handle font colors
  834.     TFontStyles BoldFnt;
  835.     TCheckBox* cb = dynamic_cast<TCheckBox *>(Sender);
  836.     if (cb->State == cbChecked) {
  837.         cb->Font->Color = clBlue;
  838.         BoldFnt << fsBold;
  839.         cb->Font->Style = BoldFnt ;
  840.     }
  841.     else {
  842.         cb->Font->Color = clBlack;
  843.         BoldFnt >> fsBold;
  844.         cb->Font->Style = BoldFnt;
  845.     }
  846.     // Add checked boxes to the object list
  847.     ObjList->AddObject("TCheckBox", Sender);
  848.     if (!SourceFileSelected && !Clear && (ObjList->Count)) {
  849.         ShowMessage("Select a File!");
  850.         ClearCtls();
  851.     }
  852.     else {
  853.         if (Grep) CmdStrRE->Text = PageCtl->
  854.                                 ActivePage->Caption +  " -";
  855.         else
  856.             CmdStrRE->Text = PageCtl->ActivePage->Caption + " ";
  857.         OptionString = "";
  858.         if (SourceFileSelected) PrepareCmdLine();
  859.     }
  860. }
  861. //------------------------------------------------------------
  862.  
  863. void __fastcall TMainForm::LabToCB(TObject *Sender)
  864. {
  865.     // Make label activate corresponding checkbox
  866.     if (SourceFileSelected) {
  867.         String LabToCB;
  868.         String cbName;
  869.         int ctl;
  870.         TCheckBox *CB;
  871.         TLabel* lab = dynamic_cast<TLabel *>(Sender);
  872.         int Len = lab->Name.Length();
  873.  
  874.         LabToCB = lab->Name.SubString(6, Len-5);
  875.         if (TDump) cbName = "TDcb"+LabToCB;
  876.         if (BCC32) cbName = "BCcb"+LabToCB;
  877.         if (ImpLib) cbName = "ILcb"+LabToCB;
  878.         if (ImpDef) cbName = "IDcb"+LabToCB;
  879.         if (TLib) cbName = "TLcb"+LabToCB;
  880.         if (ILink32) cbName = "IKcb"+LabToCB;
  881.         if (TLink32) cbName = "TKcb"+LabToCB;
  882.         if (Make) cbName = "MKcb"+LabToCB;
  883.         if (BRCC32) cbName = "BRcb"+LabToCB;
  884.         if (CPP32) cbName = "CPcb"+LabToCB;
  885.         if (TDStrp32) cbName = "DScb"+LabToCB;
  886.         if (Grep) cbName = "GPcb"+LabToCB;
  887.         if (Touch) cbName = "TCcb"+LabToCB;
  888.         if (Coff) cbName = "CFcb"+LabToCB;
  889.         if (IDEtoBPR) cbName = "BPcb"+LabToCB;
  890.         if (TlbImp) cbName = "TPcb"+LabToCB;
  891.         if (TRegAX) cbName = "TRcb"+LabToCB;
  892.         if (Tasm) cbName = "TScb"+LabToCB;
  893.  
  894.         if (BCC32) {
  895.             if (BCCPnl1->Visible) {
  896.                 for (ctl=0; ctl<BCCPnl1->ControlCount; ctl++) {
  897.                     if (BCCPnl1->Controls[ctl]->Name == cbName) break;
  898.                 }
  899.                 CB = (TCheckBox *) BCCPnl1->Controls[ctl];
  900.             }
  901.             if (BCCPnl2->Visible) {
  902.                 for (ctl=0; ctl<BCCPnl2->ControlCount; ctl++) {
  903.                     if (BCCPnl2->Controls[ctl]->Name == cbName) break;
  904.                 }
  905.                 CB = (TCheckBox *) BCCPnl2->Controls[ctl];
  906.             }
  907.             if (BCCPnl3->Visible) {
  908.                 for (ctl=0; ctl<BCCPnl3->ControlCount; ctl++) {
  909.                     if (BCCPnl3->Controls[ctl]->Name == cbName) break;
  910.                 }
  911.                 CB = (TCheckBox *) BCCPnl3->Controls[ctl];
  912.             }
  913.         }
  914.         else {
  915.             for (ctl=0; ctl<PageCtl->ActivePage->ControlCount; ctl++) {
  916.                 if (PageCtl->ActivePage->Controls[ctl]->
  917.                                         Name == cbName) break;
  918.             }
  919.             CB = (TCheckBox *) PageCtl->ActivePage->Controls[ctl];
  920.         }
  921.         CB->Checked = CB->State==cbUnchecked;
  922.     }
  923.     else ShowMessage("Select a File!");
  924. }
  925. //------------------------------------------------------------
  926.  
  927. void __fastcall TMainForm::Print1Click(TObject *Sender)
  928. {
  929.     if (SourceFileSelected) {
  930.         try {
  931.             TRichEdit *RE = (TRichEdit *) PageCtl2->ActivePage->
  932.                                                 Controls[0];
  933.             if (PrintDialog1->Execute())
  934.                 RE->Print(PageCtl2->ActivePage->Caption);
  935.             else return;
  936.         }
  937.         catch(...) {
  938.             ShowMessage("Could not print file !");
  939.             return;
  940.         }
  941.     }
  942.     else
  943.         ShowMessage("Select a File!");
  944. }
  945. //------------------------------------------------------------
  946.  
  947. void __fastcall TMainForm::AdvBtnClick(TObject *Sender)
  948. {
  949.     BCCPnl1->Hide();
  950.     BCCPnl3->Hide();
  951.     BCCPnl2->Show();
  952. }
  953. //------------------------------------------------------------
  954.  
  955.  
  956.  
  957. void __fastcall TMainForm::ResultsREKeyPress(TObject *Sender,
  958.     char &Key)
  959. {
  960.     IsDirty = true;
  961. }
  962. //------------------------------------------------------------
  963.  
  964. void __fastcall TMainForm::SetWorkingDir1Click(
  965.     TObject *Sender)
  966. {
  967.     // Use Windows 95 Directory box to get dir
  968.     BROWSEINFO bi;
  969.       char WDir[MAX_PATH];
  970.       char FolderName[MAX_PATH];
  971.       LPITEMIDLIST ItemID;
  972.  
  973.       memset(&bi, 0, sizeof(BROWSEINFO));
  974.       memset(WDir, 0, MAX_PATH);
  975.       bi.hwndOwner = Handle;
  976.       bi.pszDisplayName = FolderName;
  977.       bi.lpszTitle = "Select Working Directory!";
  978.       ItemID = SHBrowseForFolder(&bi);
  979.       SHGetPathFromIDList(ItemID, WDir);
  980.       GlobalFreePtr(ItemID);
  981.     if (WorkDir == "") return;
  982.     WorkDir = String(WDir);
  983. }
  984. //------------------------------------------------------------
  985.  
  986. bool TMainForm::IsWindowsNT()
  987. {
  988.     OSVERSIONINFO osv;
  989.     osv.dwOSVersionInfoSize = sizeof(osv);
  990.     GetVersionEx(&osv);
  991.     return (osv.dwPlatformId == VER_PLATFORM_WIN32_NT);
  992. }
  993.  
  994. void __fastcall TMainForm::CloseActive(TObject *Sender)
  995. {
  996.     if (PageCtl2->PageCount > 1) {
  997.           PageCtl2->ActivePage->Free();
  998.           PageCtl2->ActivePage = PageCtl2->Pages[0];
  999.     }
  1000. }
  1001. //------------------------------------------------------------
  1002.  
  1003. void __fastcall TMainForm::Closeall1Click(TObject *Sender)
  1004. {
  1005.     if (PageCtl2->PageCount > 1) {
  1006.           while (PageCtl2->PageCount > 1) {            
  1007.               PageCtl2->ActivePage = PageCtl2->Pages[1];
  1008.             if (PageCtl2->ActivePage->Caption != "Results") {
  1009.                 PageCtl2->ActivePage->Free();
  1010.                  Application->ProcessMessages();
  1011.             }
  1012.         }
  1013.     PageCtl2->ActivePage = PageCtl2->Pages[0];
  1014.     }
  1015. }
  1016. //------------------------------------------------------------
  1017.  
  1018. void __fastcall TMainForm::Save2Click(TObject *Sender)
  1019. {
  1020.     if (SourceFileSelected) {
  1021.         try {
  1022.             TRichEdit *RE = (TRichEdit *) PageCtl2->
  1023.                                 ActivePage->Controls[0];
  1024.             // not saved yet do saveas
  1025.             if (SourceFileDir.IsEmpty()) {
  1026.                 SaveAs2Click(Sender);
  1027.                 return;
  1028.             }
  1029.             RE->Lines->SaveToFile(SourceFileDir + "\\" +
  1030.                          PageCtl2->ActivePage->Caption) ;
  1031.         }
  1032.         catch (...) {
  1033.             ShowMessage("Could not save file " + SourceFileDir +
  1034.                 "\\" + PageCtl2->ActivePage->Caption);
  1035.             return;
  1036.         }
  1037.     }
  1038.     else
  1039.         ShowMessage("Select a File!");
  1040.  
  1041. }
  1042. //------------------------------------------------------------
  1043.  
  1044. void __fastcall TMainForm::SaveAs2Click(TObject *Sender)
  1045. {
  1046.     if (SourceFileSelected) {
  1047.         try {
  1048.             TRichEdit *RE = (TRichEdit *) PageCtl2->ActivePage->
  1049.                                                 Controls[0];
  1050.             if (SaveDialog1->Execute())
  1051.                 RE->Lines->SaveToFile(SaveDialog1->FileName);
  1052.         }
  1053.         catch (...) {
  1054.             ShowMessage("Could not save file " +  SaveDialog1->
  1055.                                                     FileName) ;
  1056.             return;
  1057.         }
  1058.     }
  1059.     else
  1060.         ShowMessage("Select a File!");
  1061. }
  1062. //------------------------------------------------------------
  1063.  
  1064. void __fastcall TMainForm::About1Click(TObject *Sender)
  1065. {
  1066.     AboutBox = new TAboutBox(this);
  1067.     AboutBox->ShowModal();
  1068.     delete AboutBox;
  1069. }
  1070. //------------------------------------------------------------
  1071.  
  1072. void __fastcall TMainForm::OpenAtCursorClick(
  1073.     TObject *Sender)
  1074. {
  1075.     String OneChar;
  1076.     String FilePath = "";
  1077.     int LineNum = ResultsRE->Perform(EM_LINEFROMCHAR,ResultsRE->
  1078.                                                 SelStart,0);
  1079.     String RawPath = ResultsRE->Lines->Strings[LineNum];
  1080.     int x = RawPath.Length() -1; // Skip last char :
  1081.     while (x) {
  1082.         OneChar = RawPath.SubString(x, 1);
  1083.         if (OneChar == " ") break;
  1084.         FilePath.Insert(OneChar, 1);
  1085.         x--;
  1086.     }
  1087.     CreateNewPage(ExtractFileName(FilePath), FilePath);
  1088. }
  1089. //------------------------------------------------------------
  1090.  
  1091. void __fastcall TMainForm::BrowseMi(TObject *Sender)
  1092. {
  1093.     HandleOpenDlgs(FilterStr);
  1094. }
  1095. //------------------------------------------------------------
  1096.  
  1097. void __fastcall TMainForm::Find2Click(TObject *Sender)
  1098. {
  1099.     if (FindDialog1->Execute())    PosFound = 0;
  1100. }
  1101. //------------------------------------------------------------
  1102.  
  1103. void __fastcall TMainForm::Exit1Click(TObject *Sender)
  1104. {
  1105.     Application->Terminate();    
  1106. }
  1107. //------------------------------------------------------------
  1108.  
  1109. void __fastcall TMainForm::OutFileMiClick(TObject *Sender)
  1110. {
  1111.     OutFileMi->Checked = !OutFileMi->Checked;
  1112.     CmdStrRE->Text = PageCtl->ActivePage->Caption + " ";
  1113.     OptionString = "";
  1114.     PrepareCmdLine();
  1115. }
  1116. //------------------------------------------------------------
  1117.  
  1118. void __fastcall TMainForm::ToolHelpMi(
  1119.     TObject *Sender)
  1120. {
  1121.     TMenuItem* Item = dynamic_cast<TMenuItem *>(Sender);
  1122.     CreateNewPage(ExtractFileName(Item->Caption + ".txt"),
  1123.                     WintoolsDir + Item->Caption + ".txt");
  1124.     SourceFileSelected = true;
  1125. }
  1126. //------------------------------------------------------------
  1127.  
  1128. String TMainForm::StripFileExt(String FileName)
  1129. {
  1130.     String Temp;
  1131.     String OneChar;
  1132.     bool FoundDot = false;
  1133.     int Len = FileName.Length();
  1134.  
  1135.     while (Len > 0) {
  1136.         OneChar = FileName.SubString(Len, 1);
  1137.         if (FoundDot) Temp.Insert(OneChar, 0);
  1138.         if (OneChar == ".") FoundDot = true;
  1139.         Len--;
  1140.     }
  1141.     return Temp;
  1142. }
  1143.  
  1144. void __fastcall TMainForm::New1Click(TObject *Sender)
  1145. {
  1146.     MainForm->Caption = AppCaption + "Create a New File";
  1147.     CreateNewPage("New File", "None");
  1148.     TRichEdit *RE = (TRichEdit *) PageCtl2->ActivePage->
  1149.                      Controls[0];
  1150.     RE->SetFocus();
  1151.     CmdStrRE->Text = "";
  1152.     DestEd = "";
  1153.     SourceFileSelected = true;
  1154. }
  1155. //------------------------------------------------------------ 
  1156.  
  1157. void __fastcall TMainForm::OpenClick(TObject *Sender)
  1158. {
  1159.     TMenuItem* mi = dynamic_cast<TMenuItem *>(Sender);
  1160.     String MItem = mi->Caption;
  1161.     MainForm->Caption = AppCaption + "View/Edit a File";
  1162.  
  1163.     if (HandleOpenDlgs("*.*")) {
  1164.         ResultPnl->Parent = this;
  1165.         ResultPnl->Align = alClient;
  1166.         String File = OpenDlg->FileName;
  1167.         CreateNewPage(ExtractFileName(File),File);
  1168.         BackBtn->Enabled = true;
  1169.         RunBtn->Enabled = false;
  1170.         CmdStrRE->Text = "";
  1171.         DestEd = "";
  1172.         TRichEdit *RE = (TRichEdit *) PageCtl2->ActivePage->
  1173.                          Controls[0];
  1174.         RE->SetFocus();
  1175.     }
  1176. }
  1177. //------------------------------------------------------------
  1178.  
  1179. void TMainForm::CreateNewPage(String TabName, String LoadFile)
  1180. {
  1181.     TTabSheet *NewTabSheet = new TTabSheet(this);
  1182.     NewTabSheet->Caption = TabName;
  1183.     NewTabSheet->PageControl = PageCtl2;
  1184.  
  1185.     TRichEdit *NewRichEdit = new TRichEdit(this);
  1186.     NewRichEdit->ScrollBars = ssBoth;
  1187.     NewRichEdit->PlainText = true;
  1188.     NewRichEdit->WordWrap = true;
  1189.     NewRichEdit->Parent = NewTabSheet;
  1190.     NewRichEdit->Align = alClient;
  1191.     NewRichEdit->PopupMenu = PopupMenu1;
  1192.  
  1193.     PageCtl2->ActivePage = PageCtl2->Pages[PageCtl2->PageCount - 1];
  1194.     try {
  1195.         if (LoadFile != "None")
  1196.                 NewRichEdit->Lines->LoadFromFile(LoadFile);
  1197.     }
  1198.     catch(...) {
  1199.         ShowMessage("Unable to open file " + LoadFile);
  1200.         return;
  1201.     }
  1202.     ResultPnl->Parent = this;
  1203.     ResultPnl->Align = alClient;
  1204.     ResultPnl->Show();
  1205.     BackBtn->Enabled = true;
  1206.  
  1207. void __fastcall TMainForm::Operations(TObject *Sender)
  1208. {
  1209.     if (SourceFileSelected) {
  1210.         TFontStyles BoldFnt;
  1211.         TCheckBox* cb = dynamic_cast<TCheckBox *>(Sender);
  1212.         if (cb->State == cbChecked) {
  1213.             cb->Font->Color = clBlue;
  1214.             BoldFnt << fsBold;
  1215.             cb->Font->Style = BoldFnt;
  1216.         }
  1217.         else {
  1218.             cb->Font->Color = clBlack;
  1219.             BoldFnt >> fsBold;
  1220.             cb->Font->Style = BoldFnt;
  1221.         }
  1222.         CmdStrRE->Text = PageCtl->ActivePage->Caption + " ";
  1223.         OptionString = "";
  1224.         PrepareCmdLine();
  1225.     }
  1226.     else ShowMessage("Select a File!");
  1227. }
  1228. //------------------------------------------------------------
  1229.  
  1230. int TMainForm::GetFileSize(String SFile)
  1231. {
  1232.     struct stat statbuf;
  1233.     stat(SFile.c_str(), &statbuf);
  1234.     return statbuf.st_size;
  1235. }
  1236.  
  1237. void __fastcall TMainForm::SymbolBtn(TObject *Sender)
  1238. {
  1239.     if (SourceFileSelected) {
  1240.         TButton* btn = dynamic_cast<TButton *>(Sender);
  1241.         CmdStrRE->Text = CmdStrRE->Text + " " + btn->Caption;
  1242.     }
  1243.     else ShowMessage("Select a File!");
  1244. }
  1245. //------------------------------------------------------------
  1246.  
  1247. void __fastcall TMainForm::Button10Click(TObject *Sender)
  1248. {
  1249.     BCCPnl2->Hide();
  1250.     BCCPnl3->Hide();
  1251.     BCCPnl1->Show();
  1252. }
  1253. //---------------------------------------------------------------------------
  1254.  
  1255. void __fastcall TMainForm::Button8Click(TObject *Sender)
  1256. {
  1257.     BCCPnl1->Hide();
  1258.     BCCPnl3->Hide();
  1259.     BCCPnl2->Show();
  1260. }
  1261. //---------------------------------------------------------------------------
  1262.  
  1263. void __fastcall TMainForm::Button11Click(TObject *Sender)
  1264. {
  1265.     BCCPnl1->Hide();
  1266.     BCCPnl2->Hide();
  1267.     BCCPnl3->Show();
  1268. }
  1269. //---------------------------------------------------------------------------
  1270.  
  1271. void __fastcall TMainForm::ViewResults(TObject *Sender)
  1272. {
  1273.     ResultPnl->Parent = this;
  1274.     ResultPnl->Align = alClient;
  1275.     ResultPnl->Show();
  1276.     BackBtn->Enabled = true;
  1277. }
  1278. //---------------------------------------------------------------------------
  1279.  
  1280.  
  1281. void __fastcall TMainForm::RevisePath1Click(TObject *Sender)
  1282. {
  1283.     CreateNewPage("Path", WintoolsDir + "Path.txt");
  1284.     String AddPath;
  1285.     if (!InputQuery("Add to Path", "",AddPath)) return;
  1286.     TRichEdit *RE = (TRichEdit *) PageCtl2->ActivePage->
  1287.                          Controls[0];
  1288.     RE->Lines->Add(AddPath);
  1289.     RE->Lines->SaveToFile(WintoolsDir + "Path.txt");
  1290.     SetEnvPath();
  1291. }
  1292. //---------------------------------------------------------------------------
  1293.  
  1294.  
  1295.  
  1296.  
  1297. void __fastcall TMainForm::CmdStrREMouseMove(TObject *Sender,
  1298.       TShiftState Shift, int X, int Y)
  1299. {
  1300.     CmdStrRE->Align = alClient;
  1301. }
  1302. //---------------------------------------------------------------------------
  1303.  
  1304. void __fastcall TMainForm::PageCtlMouseMove(TObject *Sender,
  1305.       TShiftState Shift, int X, int Y)
  1306. {
  1307.     CmdStrRE->Align = alNone;
  1308.     CmdStrRE->Width = 343;
  1309. }
  1310. //---------------------------------------------------------------------------
  1311.  
  1312. void __fastcall TMainForm::ResultPnlMouseMove(TObject *Sender,
  1313.       TShiftState Shift, int X, int Y)
  1314. {       
  1315.     CmdStrRE->Align = alNone;
  1316.     CmdStrRE->Width = 343;
  1317. }
  1318. //---------------------------------------------------------------------------
  1319.  
  1320.