home *** CD-ROM | disk | FTP | other *** search
-
- /* ModuleEntry.c
-
- Of course you may do all your work here, but it is nicer for
- overview, you do here only some simple stuff
-
- */
-
- #include "includes/Project.h"
-
-
- /* At first here you *must* declare your ModuleInfo structure */
-
- ModuleInfo module_info =
- {
- 2, // version - your choice...
- "time.module", // module name (case sensitive !)
- "time.catalog", // catalog name (case sensitive !)
- MODULEF_CALL_STARTUP, // flags
- 1, // number of functions
- { 0, COMMAND_0, MSG_CLOCK_DESC, NULL, CMD_0_TEMPL }
- };
-
- /* If you want to add more functions, set the number before and
- declare ie. :
-
- ModuleFunction module_func[1] =
- {
- { 1, COMMAND_1, NULL, FUNCF_PRIVATE, NULL }
- };
-
- */
-
-
- /* If you are a really nice one, you may add at the following string
- a \0 before and after the string... (I am sooo lazy ;-) ) */
-
- static char version[] = "$VER: " VERSION_STRING " " __AMIGADATE__;
-
- /********************************************************************/
- // EXTERNALS
-
- extern void Deteach( struct Screen *screen );
-
- /********************************************************************/
- // GLOBALS AND LOCAL FUNCTIONS
-
- IPCData *clock_ipc;
-
- ULONG ScanSub( STRPTR template, STRPTR args, USHORT template_count );
- void PrepareClock( struct Screen *screen, char *args );
-
- /********************************************************************/
- // OUR ENTRY
-
- int __asm __saveds L_Module_Entry( register __a0 char *args,
- register __a1 struct Screen *screen,
- register __a2 IPCData *ipc,
- register __a3 IPCData *main_ipc,
- register __d0 ULONG mod_id,
- register __d1 EXT_FUNC(func_callback) )
- {
- char buffer[4];
-
- switch( mod_id )
- {
- case FUNCID_STARTUP:
- /* Check - Should we start ? - If yes, there must be */
- /* our variable in ENV:dopus and must contain "1". */
- /* If not, we simply return at this stage. */
-
- if( GetVar(CLOCKSTARTVAR, buffer, 4, LV_VAR|GVF_GLOBAL_ONLY) < 1 ||
- buffer[0] != '1' )
- return 1;
-
- /* Give DOpus some time to go on, */
- /* so we must later not wait... */
-
- Delay( 300 );
-
- case 0:
- /* we do the same in every case */
- PrepareClock( screen, args );
- break;
- }
-
- /* Always modules should return 1 ... */
- return 1;
- }
-
- /********************************************************************/
- /* This function does parse the arguments (, if there are some) and */
- /* launches the clock deteaching routine, if the clock is not */
- /* already running. If the clock does run, it does pass the given */
- /* arguments to it or even a zero command. So is later no different */
- /* code needed to take care of the arguments. */
- /********************************************************************/
-
- void PrepareClock( struct Screen *screen, char *args )
- {
- ULONG command = NULL, ctr;
- FuncArgs *fargs = NULL;
- CPrefsData *cp = NULL;
-
- /* Like you here see, you should always check if there are arguments */
- /* before you try to parse them. ParseArgs() does not accept NULL ! */
-
- if( *args && (fargs = ParseArgs(CMD_0_TEMPL, args)) )
- {
- /* I use here AllocVec(), because I use later the data_free */
- /* element of IPC_Command() */
-
- if( (cp = AllocVec(sizeof(CPrefsData), MEMF_CLEAR)) )
- {
- /* At first we make a note, what arguments are given */
-
- for( ctr = 0; ctr <= CLOCKARG_COUNT; ctr++ )
- if( fargs->FA_Arguments[ctr] )
- command |= 1 << ctr;
-
- /* If a delay is given, we do it now and delete the bit */
- /* in command */
-
- if( ARG_DELAY )
- {
- Delay( *(ULONG *) ARG_DELAY );
- command ^= 1 << 2;
- }
-
- /* Now we are ready to store all values step by step */
-
- if( ARG_FONT )
- strcpy( cp->fontname, (STRPTR) ARG_FONT );
-
- if( ARG_SIZE )
- cp->txtattr.ta_YSize = *(ULONG *) ARG_SIZE;
-
- if( ARG_APEN )
- cp->ibox.Width = *(ULONG *) ARG_APEN;
-
- if( ARG_BPEN )
- cp->ibox.Height = *(ULONG *) ARG_BPEN;
-
- if( ARG_MODE )
- {
- /* Mode has a subtemplate and must be parsed again */
-
- cp->txtattr.ta_Flags = ScanSub( MODE_TEMPL, (STRPTR) ARG_MODE, 4 );
-
- if( cp->txtattr.ta_Flags & 1 << 0 )
- cp->txtattr.ta_Flags = 0;
- else
- cp->txtattr.ta_Flags >>= 1;
- }
-
- if( ARG_STYLE )
- {
- cp->txtattr.ta_Style = ScanSub( STYLE_TEMPL, (STRPTR) ARG_STYLE, 4 );
-
- if( cp->txtattr.ta_Style & 1 << 0 )
- cp->txtattr.ta_Style = 0;
- else
- cp->txtattr.ta_Style >>= 1;
- }
-
- if( ARG_BORDER )
- {
- if( ScanSub( ON_OFF_TEMPL, (STRPTR) ARG_BORDER, 8 ) < NO_CASE )
- command |= BORDER_ON;
- else
- command |= BORDER_OFF;
- }
-
- if( ARG_PIC )
- strcpy( cp->picture, (STRPTR) ARG_PIC );
-
- if( ARG_LEFT )
- cp->ibox.Left = *(ULONG *) ARG_LEFT;
-
- if( ARG_TOP )
- cp->ibox.Top = *(ULONG *) ARG_TOP;
-
- if( ARG_ALARM )
- {
- /* If ScanSub() does return 0, we should have a time */
- /* as argument ( = else ) */
-
- if( (ctr = ScanSub(ON_OFF_TEMPL, (STRPTR) ARG_ALARM, 8)) )
- {
- if( ctr < NO_CASE )
- command |= ALARM_ON;
- else
- command |= ALARM_OFF;
- }
- else
- {
- strcpy( cp->alarm, (STRPTR) ARG_ALARM );
- command |= ALARM_ON;
- }
- }
-
- if( ARG_SOUND )
- {
- if( ScanSub(ON_OFF_TEMPL, (STRPTR) ARG_SOUND, 8) < NO_CASE )
- command |= SOUND_ON;
- else
- command |= SOUND_OFF;
- }
- }
- }
-
- if( !clock_ipc )
- {
- Deteach( screen );
- while( !clock_ipc )
- Delay( 20 );
- }
-
- IPC_Command( clock_ipc, command, NULL, NULL, cp, REPLY_NO_PORT );
-
- if( fargs )
- DisposeArgs( fargs );
-
- }
-
- /********************************************************************/
-
- ULONG ScanSub( STRPTR template, STRPTR args, USHORT template_count )
- {
- UBYTE ctr;
- ULONG ret = NULL;
- STRPTR ptr;
- FuncArgs *fargs;
-
- ptr = args;
-
- /* More than one argument should be added by the user with */
- /* a "|", but for parsing we need spaces. So we simply replace */
- /* the "|" by spaces... */
-
- while( *ptr )
- {
- if( *ptr == '|' )
- *ptr = ' ';
- ptr++;
- }
-
- /* Now we have a "normal" argument string and can parse it */
-
- if( (fargs = ParseArgs(template, args)) )
- {
- for( ctr = 0; ctr < template_count; ctr++ )
- if( fargs->FA_Arguments[ctr] )
- ret |= 1 << ctr;
-
- DisposeArgs( fargs );
- }
-
- return ret;
- }
-
- /********************************************************************/
-
-
-