home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
cdity
/
yak
/
src
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-04
|
14KB
|
501 lines
/*
* Yak version 1.58
* ----------------
* [Yak == Yet Another K(?)ommodity
*
* There seems to be a profusion of commodities doing this or that.
* Heres mine, to do what I want it to:
*
* AutoActivate windows (SunMouse)
* ClickToFront, ClickToBack, ScreenCycle
* Close/Zip/Shrink/Zoom/Turn a window via keyboard.
* Bring up a palette on front screen.
* Insert date into read-stream.
* Produce key-click (like my keyclick program).
* Some other things...
*
* Martin W. Scott & Gaël Marziou, 8/93.
*/
#include <exec/types.h>
#include <exec/libraries.h>
#include <exec/memory.h>
#include <devices/inputevent.h>
#include <dos/dos.h>
#include <dos/dostags.h>
#include <graphics/displayinfo.h>
#include <libraries/commodities.h>
#include <libraries/reqtools.h>
#include <libraries/locale.h>
#include <intuition/intuitionbase.h>
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/graphics_protos.h>
#include <clib/commodities_protos.h>
#include <clib/intuition_protos.h>
#include <clib/locale_protos.h>
#include <clib/reqtools_protos.h>
#ifdef __SASC
# include <pragmas/exec_pragmas.h>
# include <pragmas/dos_pragmas.h>
# include <pragmas/graphics_pragmas.h>
# include <pragmas/commodities_pragmas.h>
# include <pragmas/intuition_pragmas.h>
# include <pragmas/locale_pragmas.h>
# include <pragmas/reqtools.h>
#else
# include <proto/exec.h>
# include <proto/dos.h>
# include <proto/graphics.h>
# include <proto/commodities.h>
# include <proto/intuition.h>
# include <proto/locale.h>
# include <proto/reqtools.h>
extern struct Library *DOSBase;
#endif
#include <string.h>
#include <stdarg.h>
#include "code.h"
#include "yak.h"
#include "hotkey_types.h"
#include "beep.h"
#include "icon.h"
#include "version.h"
#define CATCOMP_BLOCK
#define CATCOMP_NUMBERS
#include "locale/yak_locale_strings.h"
#undef CATCOMP_BLOCK
#include "WB2CLI.h" /* we'll be a shell process */
#define DEF_CURRENTDIR "SYS:"
/* local prototypes for main.c */
static void CloseResources(void);
static BOOL OpenResources(void);
static void FreePatterns(void);
static LONG ProcessMsg(void);
void MAIN(void);
LONG (*HandleIDCMP)(void);
extern struct WBStartup *WBMsg;
/*
* libraries opened by startup code; basepointers needed by function pragmas
*/
extern struct Library *SysBase, *DOSBase;
/* global data - library bases and the like */
struct Library *CxBase, *IconBase,
*GadToolsBase, *LayersBase,
*WorkbenchBase, *LocaleBase,
*GfxBase, *IntuitionBase,
*KeymapBase;
struct Locale *locale;
struct Catalog *Catalog;
struct MsgPort *broker_mp;
CxObj *broker;
char *PopKeyStr;
#define POPKEY_EVENT 1L /* cannot clash with YHK event... */
static const char *versionstr=VERSION_STR;
struct NewBroker newbroker = {
NB_VERSION,
"Yak", /* string to identify this broker */
VERSION_BROKER,
"Multi-purpose commodity",
NBU_UNIQUE | NBU_NOTIFY, /* Don't want any new commodities
* starting with this name. If someone
* tries it, let me know */
COF_SHOW_HIDE
};
ULONG wndsigflag; /* here for overlay purposes */
ULONG cxsigflag;
ULONG invariantsigflag;
BYTE palette_count; /* how many palettes are open */
/* from handler.c */
extern ULONG clicksigflag, intuiopsigflag, blankscreensigflag;
extern void (*intui_routine)(APTR); /* for intui_op's */
extern APTR intui_parameter;
/* from icon.c */
extern ULONG appsigflag;
/* close what we opened */
static void
CloseResources()
{
/* NULL pointers are valide so don't waste time to test them */
CloseLibrary(IntuitionBase);
CloseLibrary(GfxBase);
CloseLibrary(CxBase);
CloseLibrary(LayersBase);
CloseLibrary(IconBase);
CloseLibrary(GadToolsBase);
CloseLibrary(WorkbenchBase);
CloseLibrary(KeymapBase);
if (LocaleBase)
{
CloseCatalog (Catalog);
CloseLocale(locale);
CloseLibrary(LocaleBase);
}
}
/* open libraries, devices that we need */
static BOOL
OpenResources(void)
{
if ((IntuitionBase = OpenLibrary("intuition.library", 37L)) &&
(GfxBase = OpenLibrary("graphics.library", 37L)) &&
(CxBase = OpenLibrary("commodities.library", 37L)) &&
(LayersBase = OpenLibrary("layers.library", 37L)) &&
(IconBase = OpenLibrary("icon.library", 37L)) &&
(GadToolsBase = OpenLibrary("gadtools.library", 37L)) &&
(WorkbenchBase = OpenLibrary("workbench.library", 37L)) &&
(KeymapBase = OpenLibrary("keymap.library", 37L)))
{
return TRUE;
}
CloseResources();
return FALSE;
}
/* open locale library and catalog */
void
OpenLocaleStuff(char *language)
{
if (LocaleBase =(struct LocaleBase *)OpenLibrary("locale.library", 38L))
{
if (!(locale = OpenLocale(NULL)))
{
PostError("No locale set!");
CloseLibrary(LocaleBase);
LocaleBase = NULL;
}
Catalog = OpenCatalog( locale, "yak.catalog",
OC_BuiltInLanguage, "english",
OC_Language, language,
OC_Version, 15L,
TAG_DONE );
}
}
/* slighlty modified version of GetString() generated by catcomp */
char
*getString(ULONG MsgID)
{
LONG *l;
UWORD *w;
char *builtIn;
l = (LONG *)CatCompBlock;
while (*l != MsgID )
{
w = (UWORD *)((ULONG)l + 4);
l = (LONG *)((ULONG)l + (ULONG)*w + 6);
}
builtIn = (char *)((ULONG)l + 6);
if (LocaleBase)
return (GetCatalogStr (Catalog, MsgID, builtIn));
return(builtIn);
}
/* simple requester with args */
void
PostError(char *body, ... )
{
struct EasyStruct es;
va_list args;
if (!IntuitionBase)
{
Write(Output(), "Need AmigaDos 2.0+\n", -1);
return;
}
/* setup the argument array */
va_start( args, body );
/* initialise the structure */
es.es_StructSize = sizeof(struct EasyStruct);
es.es_Flags = 0L;
es.es_Title = getString(Error_Requester_Title);
es.es_TextFormat = body;
es.es_GadgetFormat = "OK";
/* display the requester */
EasyRequestArgs(NULL, &es, NULL, args);
/* free the arguments */
va_end( args );
}
/* parse pattern, report errors */
__regargs BOOL
InitPattern(char *newpatstr, UWORD n)
{
char *patstr = newpatstr ? newpatstr : patterns[n].patstr;
char *pat;
LONG len;
if (pat = AllocVec(len = strlen(patstr)*3+10, MEMF_CLEAR))
{
if (ParsePattern(patstr, pat, len) != -1)
{
if (newpatstr) strncpy(patterns[n].patstr, newpatstr, PATLEN);
if (patterns[n].pat) FreeVec(patterns[n].pat);
patterns[n].pat = pat;
return TRUE;
}
PostError("%s:\n\"%s\"", getString(Parsing_Pattern_ERR), patstr);
FreeVec(pat);
}
else PostError(getString(Allocation_ERR));
return FALSE;
}
static void
FreePatterns()
{
UWORD i;
for (i = 0; i < NUM_PATTERNS; i++)
if (patterns[i].pat) FreeVec(patterns[i].pat);
}
#ifdef _DCC
void _waitwbmsg(void);
static void
uncalled(void)
{
_waitwbmsg();
}
#endif
void
MAIN() /* Yak: multi-function commodity */
{
BPTR newdir = NULL, olddir;
if (OpenResources())
{
if (broker_mp = CreateMsgPort())
{
newbroker.nb_Port = broker_mp;
cxsigflag = 1L << broker_mp->mp_SigBit;
/* process tool-types */
GetOurIcon(WBMsg);
newbroker.nb_Pri = (BYTE)TTInt("CX_PRIORITY", 0);
if (WBMsg)
{
if (newdir = Lock(DEF_CURRENTDIR, ACCESS_READ))
olddir = CurrentDir(newdir);
WB2CLI(WBMsg,4000,(struct DosLibrary *)DOSBase); /* g