/******************************************************************************
 * program:     wp2latex                                                      *
 * function:    Main wp2latex windows form.                                   *
 * modul:       Frm_MainSheet.cpp                                             *
 * dependency:  C++ Builder                                                   *
 * licency:     Shareware                                                     *
 ******************************************************************************/
#include <vcl.h>
#include <fcntl.h>
#include "param_fix.h"

#pragma hdrstop
USERES("WP2LaTexGUI.res");
USEFORM("Frm_Copyright.cpp", Frm_Copyright1);
USEFORM("FRM_ErrLog.cpp", ErrLog);
USEFORM("Frm_GetPwd.cpp", GetPassword);
USEFORM("Frm_Help.cpp", Frm_Help1);
USEFORM("Frm_MainSheet.cpp", Frm_Main);
USEFORM("Frm_Progress.cpp", Progress);
USEFORM("Frm_Results.cpp", FrmResults);
USEFORM("Frm_Splash.cpp", Frm_Splash);
USEUNIT("CP-TRN.cpp");
USEUNIT("CMSDNHelp.cpp");
USEUNIT("param_fix.cpp");
USEUNIT("share\RegShare.cpp");
USEFILE("..\sources.cc\formulas.cc");
USEUNIT("..\sources.cc\ATOMS\Struct.c");
USEUNIT("..\sources.cc\cole\new_cole.c");
USEUNIT("..\sources.cc\ATOMS\utf8.c");
USEUNIT("..\sources.cc\word\Bintree.c");
USEUNIT("..\sources.cc\word\Wvparser.c");
USEUNIT("inherited\dbllist.cpp");
USEUNIT("inherited\cptran.cpp");
USEUNIT("inherited\charactr.cpp");
USEUNIT("inherited\error.cpp");
USEUNIT("inherited\formulas.cpp");
USEUNIT("inherited\filehnd.cpp");
USEUNIT("inherited\images.cpp");
USEUNIT("inherited\imgsupp.cpp");
USEUNIT("inherited\lists.cpp");
USEUNIT("inherited\mtx_impl.cpp");
USEUNIT("inherited\pass1.cpp");
USEUNIT("inherited\pass1_1.cpp");
USEUNIT("inherited\pass1_3.cpp");
USEUNIT("inherited\pass1_4.cpp");
USEUNIT("inherited\pass1_5.cpp");
USEUNIT("inherited\pass1_6.cpp");
USEUNIT("inherited\pass1602.cpp");
USEUNIT("inherited\pass1abi.cpp");
USEUNIT("inherited\pass1acc.cpp");
USEUNIT("inherited\pass1dcb.cpp");
USEUNIT("inherited\pass1mtf.cpp");
USEUNIT("inherited\pass1ole.cpp");
USEUNIT("inherited\pass1rtf.cpp");
USEUNIT("inherited\pass1wmf.cpp");
USEUNIT("inherited\pass1xml.cpp");
USEUNIT("inherited\pass1c45.cpp");
USEUNIT("inherited\pass1htm.cpp");
USEUNIT("inherited\pass1word.cpp");
USEUNIT("inherited\pass2.cpp");
USEUNIT("inherited\ras_jpg.cpp");
USEUNIT("inherited\ras_png.cpp");
USEUNIT("inherited\raster.cpp");
USEUNIT("inherited\rasterut.cpp");
USEUNIT("inherited\sets.cpp");
USEUNIT("inherited\stack.cpp");
USEUNIT("inherited\strings.cpp");
USEUNIT("inherited\std_str.cpp");
USEUNIT("inherited\vecimage.cpp");
USEUNIT("inherited\WP2L_lib.cpp");
USEUNIT("inherited\wp2lfuti.cpp");
USEUNIT("localiser\locale_set.cpp");
USELIB("E:\libs\src\libpng\1.2.37\libpng-1.2.37-src\projects\cbuilder4\libpng.LIB");
USELIB("E:\libs\src\zlib\1.2.3\zlib-1.2.3\win32\bp\zlib.lib");
USELIB("..\..\localiser\BCC\gettext.lib");
USEUNIT("inherited\jobs.cpp");
USEFORM("Frm_Wait4Jobs.cpp", Frm_WaitForJobs);
USEUNIT("UnitCommon.cpp");
USEUNIT("inherited\vecraster.cpp");
USEUNIT("inherited\wmfsupp.cpp");
USELIB("E:\libs\src\jpeg_9e\bp\libjpeg.lib");
USEUNIT("inherited\ras_gif.cpp");
USEUNIT("inherited\img_futi.cpp");
USEUNIT("inherited\imgut.cpp");
USEUNIT("inherited\ras_bmp.cpp");
USEASM("..\sources.cc\images\img_tool_BCC.asm");
USEASM("..\sources.cc\atoms\raster_BCC.asm");
USEUNIT("..\sources.cc\atoms\xlat_swp.c");
//---------------------------------------------------------------------------
#include "frm_ErrLog.h"
#ifdef _REENTRANT
 #include "../sources.cc/jobs/jobs.h"
#endif

//---------------------------------------------------------------------------
void CheckCompiler(void);


//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR CmdLine, int)
{
try
   {
   if(CreateMutex(NULL, FALSE, "Global\\WP2LaTeX_Mutex")==NULL)  // One global mutex is sufficient enough.
     {		// Create local mutex when global mutex cannot be created.
     CreateMutex(NULL, FALSE, "WP2LaTeX_Mutex");	// Mutex that prevents uninstalling when application is running.
     }

   FileOut = stderr;

   PatchArgs(CmdLine);
#ifdef _REENTRANT
   InitJobs(-1);
#endif
   
   if(!_pipe(TErrLog::PipeHandles,1024,O_BINARY))
      {
      //FileIn = _fdopen(PipeHandles[0],"r");
      FileOut = _fdopen(TErrLog::PipeHandles[1],"w");
      }

   Application->Initialize();

   Application->CreateForm(__classid(TFrm_Main), &Frm_Main);
                 Application->CreateForm(__classid(TFrmResults), &FrmResults);
                 Application->CreateForm(__classid(TGetPassword), &GetPassword);
                 Application->CreateForm(__classid(TProgress), &Progress);
                 Application->CreateForm(__classid(TFrm_Splash), &Frm_Splash);
                 Application->CreateForm(__classid(TFrm_Copyright1), &Frm_Copyright1);
                 Application->CreateForm(__classid(TFrm_WaitForJobs), &Frm_WaitForJobs);
                 Application->CreateForm(__classid(TErrLog), &ErrLog);
                 CheckCompiler();

   Application->Run();
   }
  catch (Exception &exception)
    {
    Application->ShowException(&exception);
    }

#ifdef _REENTRANT
  EndJobs();
#endif

return 0;
}
//---------------------------------------------------------------------------


