Keep your time right
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

159 lines
4.3 KiB

/*-
* Copyright (c) 2017-2021 Carsten Sonne Larsen <cs@innolan.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "config.h"
#include "global.h"
#include "setting.h"
#include "message.h"
#include "timer.h"
#include "net.h"
#include "mem.h"
#include "ptz.h"
#include "val.h"
#include "tz.h"
#include <workbench/startup.h>
#include "logmod.h"
#define MODULENAME "Main"
const char *vers = "\0$VER: " APP_ID;
static const char *template = KWD_TMPL;
static void GetCliSettings(void);
static void GetWbSettings(struct WBStartup *);
int main(int argc, char **argv)
{
InitMemSafe();
InitMessages();
InitSettings();
LogInfo("%s", APP_TITLE);
if (OpenLibraries() != 0)
{
CloseLibraries();
CleanupSettings();
FreeAllSafe();
return RETURN_FAIL;
}
LoadSettings();
if (Cli() != NULL)
GetCliSettings();
else
GetWbSettings((struct WBStartup *)argv);
ApplySettings();
SanitizeSettings();
ShowSettings();
InitTimezone();
StartBroker();
StopTimezoneCheck();
CloseSocketLibrary();
CloseLibraries();
CleanupSettings();
CleanupARexx();
FreePosixTimezone(Timezone);
FreeAllSafe();
LogNotice("Shutdown complete");
return RETURN_OK;
}
static void GetCliSettings(void)
{
struct AppSettings *settings;
struct RDArgs *inArgs;
LONG args[KEYWORD_COUNT];
int i;
LogTrace("Parsing CLI settings");
for (i = 0; i < KEYWORD_COUNT; i++)
args[i] = 0;
settings = CreateSettings(CliSettingType);
inArgs = ReadArgs((CONST_STRPTR) template, (LONG *)&args, NULL);
if (inArgs)
{
for (i = 0; i < KEYWORD_COUNT; i++)
{
LONG j = FindArg((STRPTR) template, (STRPTR)settingFunctions[i].Name);
if (j != -1 && args[j] != 0)
{
settingFunctions[i].Function(settings, (void *)args[j]);
}
}
FreeArgs(inArgs);
}
CacheSettings(settings);
}
static void GetWbSettings(struct WBStartup *wbs)
{
struct AppSettings *settings;
struct DiskObject *diskObject;
STRPTR filename, arg;
BPTR oldDir;
int argNo, i;
LogTrace("Parsing Workbench settings");
filename = (STRPTR)AllocStringSafe(MAXFILEPATHLEN);
settings = CreateSettings(WbSettingType);
for (argNo = 0; argNo < wbs->sm_NumArgs; ++argNo)
{
if (wbs->sm_ArgList[argNo].wa_Lock != NULL)
{
oldDir = CurrentDir(wbs->sm_ArgList[argNo].wa_Lock);
diskObject = GetDiskObjectNew((void *)wbs->sm_ArgList[argNo].wa_Name);
if (diskObject)
{
for (i = 0; i < KEYWORD_COUNT; i++)
{
arg = FindToolType(diskObject->do_ToolTypes, (STRPTR)settingFunctions[i].Name);
if (arg)
{
settingFunctions[i].Function(settings, (char *)arg);
}
}
FreeDiskObject(diskObject);
}
CurrentDir(oldDir);
}
}
CacheSettings(settings);
FreeMemSafe(filename);
}