ToolsMenu/main.c

155 rindas
3.8 KiB
C
Executable File

/*
ToolsMenu - Add tools to the Workbench Tools menu
Copyright (C) 2015, 2018 Kim Fastrup Larsen
This program is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either ver-
sion 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be use-
ful, but WITHOUT ANY WARRANTY; without even the implied war-
ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public Li-
cense along with this program. If not, see
<http://www.gnu.org/licenses/>.
The author can be contacted on <kimflarsen@hotmail.com>
*/
#include <exec/libraries.h>
#include <clib/exec_protos.h>
#ifdef USE_PRAGMAS
#include <proto/exec.h>
#endif
#include <stdlib.h>
#define CATCOMP_NUMBERS
#include "args.h"
#include "broker.h"
#include "catalog.h"
#include "error.h"
#include "gui.h"
#include "strings.h"
#include "toolrun.h"
#include "wb.h"
#define OS_REQUIRED 37
extern struct Library *SysBase;
extern struct Library *DOSBase;
char *version = "\0$VER: " TITLE " (" DATE ")";
struct Library *CxBase;
struct Library *GadToolsBase;
struct Library *IconBase;
struct Library *IntuitionBase;
struct Library *LocaleBase;
struct Library *WorkbenchBase;
static ULONG signals = SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_F;
static ULONG wb_signal, tr_signal, broker_signal, gui_signal;
static void check_system_version(void)
{
if (SysBase->lib_Version<OS_REQUIRED||DOSBase->lib_Version<OS_REQUIRED)
exit(RETURN_FAIL);
}
static struct Library *open_library(STRPTR name)
{
struct Library *base;
if ((base = OpenLibrary(name, OS_REQUIRED)) == NULL) {
error_message(get_string(MSG_ERR_OPEN), name);
exit(RETURN_FAIL);
}
return base;
}
static void open_libraries(void)
{
IntuitionBase = open_library("intuition.library");
IconBase = open_library("icon.library");
CxBase = open_library("commodities.library");
GadToolsBase = open_library("gadtools.library");
WorkbenchBase = open_library("workbench.library");
}
static void set_up(int argc, char **argv)
{
LocaleBase = OpenLibrary("locale.library", 38);
open_catalog(CATALOG);
open_libraries();
args_set_up(argc, argv);
signals |= wb_signal = wb_set_up();
signals |= tr_signal = tr_set_up();
signals |= broker_signal = broker_set_up();
signals |= gui_signal = gui_set_up();
cx_set_up();
}
static void main_loop(void)
{
ULONG received;
for (;;) {
received = Wait(signals);
if (received & wb_signal)
wb_handle_signal();
if (received & tr_signal)
tr_handle_signal();
if (received & broker_signal)
broker_handle_signal();
if (received & gui_signal)
gui_handle_signal();
if (received & SIGBREAKF_CTRL_C)
cx_quit();
if (received & SIGBREAKF_CTRL_F)
cx_show();
}
}
static void close_libraries(void)
{
CloseLibrary(WorkbenchBase);
CloseLibrary(GadToolsBase);
CloseLibrary(CxBase);
CloseLibrary(IconBase);
CloseLibrary(IntuitionBase);
}
/* Clean up as much as possible, then wait for the all tools started by us to
quit before finishing up. */
static void clean_up(void)
{
cx_clean_up();
gui_clean_up();
broker_clean_up();
/* tr_clean_up() won't return until all tools have quit. */
tr_clean_up();
wb_clean_up();
args_clean_up();
close_libraries();
close_catalog();
CloseLibrary(LocaleBase);
}
int main(int argc, char **argv)
{
check_system_version();
atexit(clean_up);
set_up(argc, argv);
if (args.cx_popup)
cx_show();
main_loop();
}