home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 3
/
CDPDIII.bin
/
pd
/
commodities
/
newedit
/
newedit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-06
|
11KB
|
344 lines
/*----------------------------------------------------------------------------
File : NewEdit.c
Projekt: NewEdit
Inhalt : __main()
disable_hook()
process_messages()
Version: 1.8
Datum : 06. März 1993
Autor : Uwe Röhm
Original aus AmigaPlus 8/92: Oliver Wagner
Adresse: Wörthstr. 18 W-8390 Passau
Bemerkung:
Globaler Edit-Hook mit folgenden Optionen:
ALT CURSOR LEFT Cursor auf Anfang des vorherigen Wortes
ALT CURSOR RIGHT Cursor auf Anfang des nächsten Wortes
ALT BACKSPACE vorheriges Wort löschen
ALT DEL nächstes Wort löschen
RALT CURSOR UP/DOWN zum nächsten/vorherigen Stringgadget springen
ESC Gadget verlassen (mit GADGETUP)
RCommand C Gadgetinhalt in das Clipboard kopieren
RCommand V Inhalt des Clipboards (unit 0) ins Gadget einfügen
Seit Version 1.6 nun als Commodity, das an- und ausgeschaltet werden kann.
----------------------------------------------------------------------------*/
#include "NewEdit.h"
#include <libraries/locale.h>
#include <libraries/commodities.h>
#include <intuition/sghooks.h>
#include <dos/dosextens.h>
#include <exec/semaphores.h>
#include <exec/execbase.h>
#include <exec/memory.h>
/* ------------------------ Prototypes & Pragmas ------------------------ */
#include <clib/commodities_protos.h>
#include <clib/intuition_protos.h>
#include <clib/locale_protos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>
#include <stdlib.h>
#ifdef LATTICE
#include<pragmas/commodities_pragmas.h>
#include<pragmas/intuition_pragmas.h>
#include<pragmas/locale_pragmas.h>
#include<pragmas/exec_pragmas.h>
#include<pragmas/dos_pragmas.h>
int _CXBRK (void) { return 0; } /* Lattice CTRL-C Handling */
int __chkabort(void) { return 0; } /* vollstaendig abschalten */
#endif
#define CATCOMP_NUMBERS
#define CATCOMP_BLOCK
#define CATCOMP_CODE
#include "Catalog.h"
void disable_hook ( void );
void process_messages ( struct MsgPort *port );
/* ------------------------- externe Funktionen ------------------------- */
extern ULONG __saveds __asm string_hook( register __a0 struct Hook *hook,
register __a2 struct SGWork *sgw,
register __a1 unsigned long *msg );
extern BOOL init_iffparse ( void );
extern void close_iffparse ( void );
/* ---------------------------- Textdefines ----------------------------- */
#define BASENAME "NewEdit"
#define SEMAPHORENAME "NewEdit.Semaphore"
#define CATALOG_NAME "NewEdit.catalog"
#define TITLESTRING VERS" by Uwe Röhm"
#define INTUITIONNAME "intuition.library"
#define UTILITYNAME "utility.library"
#define CXNAME "commodities.library"
#define KICKSTART "NewEdit requires at least Kickstart V37!\n"
/* ---------------------------- globale Vars ---------------------------- */
extern struct ExecBase *SysBase;
extern struct Library *DOSBase;
struct Library *IntuitionBase= NULL;
struct Library *UtilityBase = NULL;
struct Library *CxBase = NULL;
struct Hook Edh;
struct Hook *OldHook;
struct SignalSemaphore *Sem;
struct NewBroker MyBroker = { NB_VERSION, BASENAME, TITLESTRING, 0, NBU_NOTIFY | NBU_UNIQUE, 0, 0, 0l, 0 };
BOOL Disabled;
CxObj *Broker = NULL;
struct LocaleInfo LI;
#define LocaleBase LI.li_LocaleBase
#define catalog LI.li_Catalog
LONG Max, Num, Pos, Len;
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Funktion : __main
Parameter : ---
Rückgabe : int
Aufruf von: ---
UnterFunks: init_iffparse()
close_iffparse()
disable_hook()
process_messages()
Autor : Uwe Röhm
Datum : 06. März 1993
Bemerkung : Hauptprogramm zu NewEdit.
- Test auf Kickstart >= 37
- Libraries öffnen/schliessen
- Semaphore einrichten/löschen
- eigene Stringhook setzen/entfernen
- Abbruch mit CTRL-C
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
void __stdargs __main( char *stream )
{
LONG error;
int retcode;
struct Task *mytask;
struct TagItem cattags[] = {
OC_BuiltInLanguage, (ULONG) "deutsch",
TAG_DONE
};
if ( SysBase->LibNode.lib_Version > 36 )
{
/*
* Programmnamen ändern (Hilfreich fuer "Status")
*/
SetProgramName( BASENAME );
/*
* Die Locale Library öffnen
*/
if (LocaleBase = OpenLibrary("locale.library",38))
catalog = OpenCatalogA( NULL, CATALOG_NAME, cattags );
if ( IntuitionBase = OpenLibrary (INTUITIONNAME, 37) )
{
if ( UtilityBase = OpenLibrary (UTILITYNAME, 37) )
{
if ( CxBase = OpenLibrary (CXNAME, 37) )
{
/*
* läuft NewEdit schon? (Da MBU_UNIQUE gesetzt ist, kann
* ein zweites CXObj Namens NewEdit nicht angelegt werden)
*/
Forbid();
mytask = FindTask( NULL );
Permit();
MyBroker.nb_Port = &((struct Process *)mytask)->pr_MsgPort;
MyBroker.nb_Descr= GetString( &LI, MSG_CX_DESCRIPTION );
if ( Broker = CxBroker( &MyBroker, &error ) )
{
/*
* Semaphore anlegen als Sicherung vor zu frühem Entfernen der
* StringHook
*/
if ( Sem = (struct SignalSemaphore *) AllocMem ( sizeof( struct SignalSemaphore ), MEMF_CLEAR ) )
{
Sem->ss_Link.ln_Pri = 0;
Sem->ss_Link.ln_Name = SEMAPHORENAME;
AddSemaphore( Sem );
Edh.h_Entry = (ULONG (*)()) string_hook;
/*
* Hook setzen (vorher die iif.library öffnen und auf das
* Clipboard Unit 0 initialisieren)
*/
if ( init_iffparse() )
{
Disabled = FALSE;
OldHook = SetEditHook( &Edh );
PutStr( GetString( &LI, MSG_HAILSTRING ) );
ActivateCxObj( Broker, 1l );
process_messages( MyBroker.nb_Port );
disable_hook();
close_iffparse();
} /* if init_iff_parse() */
else
retcode = RETURN_FAIL;
RemSemaphore( Sem );
FreeMem( Sem, sizeof( struct SignalSemaphore ) );
PutStr( GetString( &LI, MSG_BYEBYE ) );
} /* if AllocMem() */
else
{
Permit();
PutStr( GetString ( &LI, MSG_ERROR_MEMORY ) );
retcode = RETURN_FAIL;
} /* if !AllocMem() */
DeleteCxObj ( Broker );
} /* if CxBroker() */
else
retcode = RETURN_WARN;
CloseLibrary( CxBase );
} /* if OpenLibrary( "commodities.library"...) */
else
{
retcode = RETURN_FAIL;
Printf ( GetString ( &LI, MSG_ERROR_LIBRARY ), CXNAME, 37 );
} /* if !OpenLibrary() */
CloseLibrary( UtilityBase );
} /* if OpenLibrary( "utility.library"...) */
else
{
retcode = RETURN_FAIL;
Printf ( GetString ( &LI, MSG_ERROR_LIBRARY ), UTILITYNAME, 37 );
} /* if !OpenLibrary() */
CloseLibrary( IntuitionBase );
} /* if OpenLibrary( "intuition.library"...) */
else
{
retcode = RETURN_FAIL;
Printf ( GetString ( &LI, MSG_ERROR_LIBRARY ), INTUITIONNAME, 37 );
} /* if !OpenLibrary() */
if (LocaleBase)
{
CloseCatalog(catalog);
CloseLibrary(LocaleBase);
} /* if LocaleBase */
} /* if lib_Version > 36 */
else
{
retcode = RETURN_FAIL;
Write ( Output(), KICKSTART, sizeof(KICKSTART) );
} /* if lib_Version <= 36 */
__exit( retcode );
}
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Funktion : disable_hook
Parameter : ---
Rückgabe : ---
Aufruf von: ---
UnterFunks: ---
Autor : Uwe Röhm
Datum : 15. September 1992
Bemerkung : Sicherung, damit nicht gerade eine String-Hook aktiv ist,
wenn hier das Programm verlassen wird: Einen exklusiven
Lock auf die Semaphore nehmen.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
void disable_hook()
{
ObtainSemaphore ( Sem );
Disable();
SetEditHook( OldHook );
Enable();
ReleaseSemaphore ( Sem );
}
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Funktion : process_messages
Parameter : struct MsgPort *port (Port des eigenen Prozesses)
Rückgabe : ---
Aufruf von: ---
UnterFunks: disable_hook (s.o.)
Autor : Uwe Röhm
Datum : 15. September 1992
Bemerkung : Den Port nach CxMessages abfragen und darauf reagieren
(nur ENABLE, DISABLE und KILL unterstützt)
CTRL-C und CTRL-F beenden NewEdit
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
void process_messages ( struct MsgPort *port )
{
short sigs,
tasksig;
CxMsg *cxm;
tasksig = (1 << port->mp_SigBit);
do
{
sigs = Wait( tasksig | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_F );
if ( sigs & tasksig )
{
while ( cxm = (CxMsg *) GetMsg(MyBroker.nb_Port) )
{
if ( CxMsgType(cxm) == CXCMD_UNIQUE )
sigs |= SIGBREAKF_CTRL_C;
else
switch ( CxMsgID(cxm) )
{
case CXCMD_DISABLE:
Disabled = TRUE;
ActivateCxObj( Broker, 0l );
break;
case CXCMD_ENABLE:
Disabled = FALSE;
ActivateCxObj( Broker, 1l );
break;
case CXCMD_UNIQUE:
case CXCMD_KILL:
sigs |= SIGBREAKF_CTRL_C;
break;
default:
break;
} /* switch ID */
ReplyMsg( (struct Message*) cxm );
} /* while cxm */
} /* if tasksig */
} while (!(sigs & (SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_F)) );
}