home *** CD-ROM | disk | FTP | other *** search
-
- /******
- * Various include
- ******/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <libraries/toolmanager.h>
- #include <proto/toolmanager.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <ProgED:sources/include/Ped.h>
-
- #define NUMDOCKS 20
-
-
-
- /******
- * Global structures & variables
- ******/
-
- struct tmTool
- {
- APTR exec,
- icon,
- sound;
- };
-
- struct APIClient MyClient=
- {
- NULL, /* This field will be filled later... */
- NOTIFY_ON_SHOW_HIDE, /* Let me know when you close or open your screen */
- "DOCK Client", /* Client's name (not used, till now) */
- NULL /* Set this to NULL! Thanks */
- };
-
- struct MsgPort *MyPort,
- *PEDPort;
- struct APIMessage msg;
- ULONG NumDock=0;
- UWORD PunDock[NUMDOCKS],
- DockX[NUMDOCKS],
- DockY[NUMDOCKS];
-
-
-
- /*****
- *
- * FUNCTION: void SendMessageToPED(struct APIMessage *msg)
- *
- * AIM: This function sends a message to ProgED.
- *
- * RESULT: -
- *
- ****/
-
- void SendMessageToPED(struct APIMessage *msg)
- {
- msg->am_Message.mn_Node.ln_Succ=NULL;
- msg->am_Message.mn_Node.ln_Pred=NULL;
- msg->am_Message.mn_Node.ln_Type=NT_MESSAGE;
- msg->am_Message.mn_Node.ln_Pri=0;
- msg->am_Message.mn_Node.ln_Name=NULL;
- msg->am_Message.mn_ReplyPort=MyPort;
- msg->am_Message.mn_Length=sizeof(struct APIMessage);
-
- PutMsg(PEDPort,(struct Message *)msg);
- WaitPort(MyPort);
- while(GetMsg(MyPort));
- }
-
-
-
- /*****
- *
- * FUNCTION: struct TagItem *SetupDock(char *config,void *handle)
- *
- * AIM: Create the dock using the name of the config-file
- * and the toolmanager's handle.
- *
- * RESULT: TagItem[] used to create the dock.
- *
- ****/
-
- struct TagItem *SetupDock(char *config,void *handle)
- {
- BPTR file;
- ULONG num=0,
- oldnum=0,
- totnum=0,
- n=0,
- orien=0,
- col=1,
- i;
- struct TagItem *dock;
- struct RDArgs *RDArgs;
- char buffer[300],
- execName[10],
- imageName[10];
-
-
-
- if (file=Open(config,MODE_OLDFILE))
- {
- while(FGets(file,buffer,sizeof(buffer)-1))
- {
- if (!strncmp(buffer,"ADD",3)) totnum++;
- else if (!strncmp(buffer,"DOCK",4)) totnum+=10;
- }
-
- Close(file);
-
- if (dock=(struct TagItem *)calloc(totnum*sizeof(struct TagItem),1))
- {
- if (file=Open(config,MODE_OLDFILE))
- {
- if (RDArgs=AllocDosObject(DOS_RDARGS,NULL))
- {
- while(FGets(file,buffer,sizeof(buffer)-1))
- {
- ULONG args[10]={0,0,0,0,0,0,0,0,0,0};
-
-
-
- RDArgs->RDA_Source.CS_Buffer=buffer+4;
- RDArgs->RDA_Source.CS_Length=strlen(buffer+4);
- RDArgs->RDA_Source.CS_CurChr=0;
- RDArgs->RDA_DAList=NULL;
- RDArgs->RDA_Buffer=NULL;
-
- if (!strncmp(buffer,"ADD",3))
- {
- memset(args,0,sizeof(args));
- if (ReadArgs("COMMAND/K/A,AREXX/S,SHELL/S,DIR/K,OUTPUT/K,IMAGE/K/A",args,RDArgs))
- {
- struct TagItem imageTags[]={
- TMOP_File, NULL,
- TMOP_Data, NULL,
- TAG_END};
-
- struct TagItem execTags[]={
- TMOP_Command, NULL,
- TMOP_ExecType, NULL,
- TMOP_Stack, 10000,
- TMOP_CurrentDir, NULL,
- TMOP_Output, NULL,
- TAG_END};
-
- imageTags[0].ti_Data=(ULONG)strdup((char *)args[5]);
-
- execTags[0].ti_Data=(ULONG)strdup((char *)args[0]);
- execTags[1].ti_Data=args[1] ? TMET_ARexx : TMET_CLI;
- execTags[3].ti_Data=args[3] ? (ULONG)strdup((char *)args[3]) : NULL;
- execTags[4].ti_Data=args[4] ? (ULONG)strdup((char *)args[4]) : NULL;
-
- sprintf(execName,"PED_E%d",num);
- sprintf(imageName,"PED_I%d",num++);
-
- CreateTMObjectTagList(handle,strdup(execName),TMOBJTYPE_EXEC,execTags);
- CreateTMObjectTagList(handle,strdup(imageName),TMOBJTYPE_IMAGE,imageTags);
-
- FreeArgs(RDArgs);
- }
- }
- else if (!strncmp(buffer,"DOCK",4))
- {
- memset(args,0,sizeof(args));
- if (ReadArgs("X/N,Y/N,HORIZONTAL/S,COLUMNS/N",args,RDArgs))
- {
- if (args[0]) DockX[NumDock]=*((ULONG *)args[0]);
- if (args[1]) DockY[NumDock]=*((ULONG *)args[1]);
- if (args[2]) orien=1;
- if (args[3]) col=*((ULONG *)args[3]);
-
- if (num-oldnum>0)
- {
- PunDock[NumDock++]=n;
-
- dock[n].ti_Tag=TMOP_PubScreen;
- dock[n++].ti_Data=NULL;
-
- dock[n].ti_Tag=TMOP_LeftEdge;
- dock[n++].ti_Data=NULL;
-
- dock[n].ti_Tag=TMOP_TopEdge;
- dock[n++].ti_Data=NULL;
-
- dock[n].ti_Tag=TMOP_Activated;
- dock[n++].ti_Data=TRUE;
-
- dock[n].ti_Tag=TMOP_Centered;
- dock[n++].ti_Data=FALSE;
-
- dock[n].ti_Tag=TMOP_Columns;
- dock[n++].ti_Data=col;
-
- dock[n].ti_Tag=TMOP_Vertical;
- dock[n++].ti_Data=orien;
-
- dock[n].ti_Tag=TMOP_Text;
- dock[n++].ti_Data=FALSE;
-
- for(i=oldnum;i<num;i++)
- {
- struct tmTool *tool;
-
- if (tool=(struct tmTool *)calloc(sizeof(struct tmTool),1))
- {
- if ((tool->exec=calloc(12,1))&&(tool->icon=calloc(12,1)))
- {
- sprintf((char *)tool->exec,"PED_E%d",i);
- sprintf((char *)tool->icon,"PED_I%d",i);
-
- dock[n].ti_Tag=TMOP_Tool;
- dock[n++].ti_Data=(ULONG)tool;
- }
- }
- }
-
- dock[n++].ti_Tag=TAG_DONE;
-
- oldnum=num;
- }
-
- FreeArgs(RDArgs);
- }
- }
- }
-
- FreeDosObject(DOS_RDARGS,RDArgs);
- }
-
- Close(file);
- }
- }
- }
-
- return(dock);
- }
-
-
-
- /*****
- *
- * FUNCTION: void HandleMsg(void *handle,struct TagItem *dock)
- *
- * AIM: Messages' handler.
- *
- * RESULT: -
- *
- ****/
-
- void HandleMsg(void *handle,struct TagItem *dock)
- {
- UBYTE finito;
- ULONG i;
- struct APIMessage *mess;
- struct Screen *screen;
- char *pubscrname,
- tmp[25];
-
-
-
- /***** Get the ProgED screen address *****/
- msg.am_MsgType=PED_API_GET_SCREEN_ADDRESS;
- SendMessageToPED(&msg);
- screen=(struct Screen *)msg.am_RC;
-
- /***** Get the ProgED public screen name *****/
- msg.am_MsgType=PED_API_GET_PUBSCRNAME;
- SendMessageToPED(&msg);
- pubscrname=(char *)msg.am_RC;
-
- /***** If the screen is opened then open the dock, too *****/
- if (screen)
- {
- for(i=0;i<NumDock;i++)
- {
- dock[PunDock[i]].ti_Data=(ULONG)pubscrname;
- dock[PunDock[i]+1].ti_Data=(DockX[i] == ~0) ? screen->Width : DockX[i];
- dock[PunDock[i]+2].ti_Data=(DockY[i] == ~0) ? screen->BarHeight+1 : DockY[i];
-
- sprintf(tmp,"PED_DOCK%d",i);
- CreateTMObjectTagList(handle,strdup(tmp),TMOBJTYPE_DOCK,&dock[PunDock[i]]);
- }
- }
-
- /***** Main loop *****/
- finito=FALSE;
- while(!finito)
- {
- WaitPort(MyPort);
- while(mess=(struct APIMessage *)GetMsg(MyPort))
- {
- switch(mess->am_MsgType)
- {
- /***** ProgED is quitting!
- Let's quit, too :-( *****/
- case PED_API_QUIT:
- finito=TRUE;
- break;
-
- /***** ProgED is closing its screen.
- Let's close our window,too *****/
- case PED_API_HIDE:
- for(i=0;i<NumDock;i++)
- {
- sprintf(tmp,"PED_DOCK%d",i);
- DeleteTMObject(handle,tmp);
- }
- break;
-
- /***** ProgED is opening its screen
- Let's open our window,too *****/
- case PED_API_SHOW:
- if (screen=(struct Screen *)mess->am_MsgArg[0])
- {
- for(i=0;i<NumDock;i++)
- {
- dock[PunDock[i]].ti_Data=(ULONG)mess->am_MsgArg[1];
- dock[PunDock[i]+1].ti_Data=(DockX[i] == ~0) ? screen->Width : DockX[i];
- dock[PunDock[i]+2].ti_Data=(DockY[i] == ~0) ? screen->BarHeight+1 : DockY[i];
-
- sprintf(tmp,"PED_DOCK%d",i);
- CreateTMObjectTagList(handle,strdup(tmp),TMOBJTYPE_DOCK,&dock[PunDock[i]]);
- }
- }
- break;
- }
-
- mess->am_RC=0;
-
- ReplyMsg((struct Message *)mess);
- }
- }
- }
-
-
-
- /*****
- *
- * FUNCTION: void main(int argc,char *argv[])
- *
- * AIM: MAIN
- *
- * RESULT: -
- *
- ****/
-
- void main(int argc,char *argv[])
- {
- struct RDArgs *RDArgs;
- ULONG args[2]={(ULONG)"progdir:docks.prefs",0,},
- try,
- i;
- void *handle;
- struct TagItem *dock;
-
-
-
- /***** Delete DockX and DockY arrays *****/
- for(i=0;i<NUMDOCKS;i++) DockX[i]=DockY[i]=(UWORD)~0;
-
- /***** Find the ProgED port *****/
- if (!(PEDPort=FindPort("PED_API")))
- {
- printf("Can't find ProgED API Port!\n");
- exit(0);
- }
-
- /***** Create a message port. It will be used to get msgs from ProgED *****/
- if (!(MyPort=CreateMsgPort()))
- {
- printf("Can't create a MsgPort!\n");
- exit(0);
- }
-
- /***** Fill in the ac_ClientPort field of the structure APIClient which
- will be used for registering *****/
- MyClient.ac_ClientPort=MyPort;
-
- /***** Let's register as client at ProgED port *****/
- msg.am_MsgType=PED_API_REGISTER;
- msg.am_MsgArg[0]=(ULONG)&MyClient;
- SendMessageToPED(&msg);
-
- /***** Main loop *****/
- if (RDArgs=ReadArgs("CONFIG/K",args,NULL))
- {
- /***** Wait for ToolManager *****/
- for (try = 20; !(handle = AllocTMHandle()) && try; try--)
- Delay(10);
-
- if (handle)
- {
- if (dock=SetupDock((char *)args[0],handle))
- HandleMsg(handle,dock);
-
- FreeTMHandle(handle);
- }
-
- FreeArgs(RDArgs);
- }
-
- /***** Exit! *****/
- DeleteMsgPort(MyPort);
- exit(0);
- }
-
-
-
-