
#include <stdlib.h>
#include "ZipGUI.h"
#include "helpers.h"

#ifdef HAVE_SYSLOG
#include "syslog.h"
#endif

ProcessSerialNumber InstallSysLog(void);

extern ZipGUI_Globals	g;
extern Boolean IgnoreEnvironment;

void DoInitToolbox( void )			
{															
	InitGraf( &qd.thePort );		
	InitFonts();					
	TEInit();
	
    InitMenus();
	InitWindows();							
	InitDialogs( nil );		
		
	InitCursor();					
	
	FlushEvents( everyEvent, 0 );	
} /* DoInitToolbox */




void DoCheckSysConfig( void )
{
	long	mySysVers = 0x00;
	OSErr	myErr = 0;
	long		gestaltSFResponse;
	
myErr = Gestalt(gestaltStandardFileAttr, &gestaltSFResponse);
	if ( (myErr != noErr) &&
		 ((gestaltSFResponse & (1 << gestaltStandardFile58) == 0)) )
		DoAlertUser( eWrongSystem, true );

	if ( GetOSTrapAddress( _Gestalt ) == 
			GetToolboxTrapAddress( _Unimplemented ) )
        DoAlertUser( eWrongSystem, true );
	myErr = Gestalt( gestaltSystemVersion, &mySysVers );
    if ( mySysVers < 0x700 )
		DoAlertUser( eWrongSystem, true );
} /* DoCheckSysConfig */




void DoInitGlobals()
{
short countWin = 0;
Str255	itemString;
char *envptr;

g.ContOnNextWin = false;
g.AllMsgOneWin  = true;
g.PauseOnScreen = false;
g.SaveMessages	= false;
g.PathAreOK     = false;

g.CurrentApp	= kZip;
g.LastApp		= kZip;
g.BeSilent      = false;
g.MaczipIsRunning = false;

g.NoWarningBoxes = false;

IgnoreEnvironment = false;
g.is_EnvForExit_valid = false;

/* don't wrap text-lines */
g.DocWidth      = 9999;

g.InputTxtPtr_start = NULL;  	/* used by fgets / PrintMessage */
g.InputLength	= 0;			/* used by fgets / PrintMessage */


GetIndString( itemString, rCurrentAppInfo, g.CurrentApp);
strcpy(g.CurrentAppStr,P2CStr(itemString)); 
	
g.doneFlag = false;
g.ShowCommandParam = false;
g.AppIsRunning = false;
g.inForeground = true;
g.numDocuments = 0;
g.menuAdjust = true;
g.modalFilterUPP = NewModalFilterProc( DoModalFilter ); 	


#ifdef HAVE_SYSLOG
g.myPsn = InstallSysLog();

envptr = getenv("SysLog_Messages");
if (!(envptr == (char *)NULL || *envptr == '\0'))
	{
	if ((stricmp(envptr,"yes") == 0) && (!IgnoreEnvironment))
		{
		Print2Syslog(LOG_INFO, "MacZip Init");
		}
	else g.gHasSyslog = false;
	}
#endif


g.LineBreak = "";

} /* DoInitGlobals */



#ifdef HAVE_SYSLOG
ProcessSerialNumber InstallSysLog(void)
{
  ProcessSerialNumber myPsn;
  OSErr appErr = noErr;
  g.gHasSyslog = false;
  
  GetCurrentProcess (&myPsn);
  
  /* on ppc, make sure we have the shared lib */
  #if TARGET_CPU_PPC
  g.gHasSyslog = SyslogLibAvailable();
  if (g.gHasSyslog){
  #endif
    g.gHasSyslog = IsDaemonRunning (NULL);
    if (!g.gHasSyslog){
      appErr = StartDaemon (NULL, NULL);/* use default folder */
      if (appErr == noErr)
        g.gHasSyslog = true;
    }
  #if TARGET_CPU_PPC
  }
  #endif
  
return myPsn;
}
#endif



