home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 530b.lha / BBFormat / lib / sendpkt.c < prev   
Encoding:
C/C++ Source or Header  |  1991-07-03  |  1.7 KB  |  65 lines

  1. /* Filename:    sendpkt.c
  2.  * Authors:        Andy Finkel, Phil Lindsay, Commodore-Amiga
  3.  * Date:        06/29/87
  4.  *
  5.  * This package was derived from "touch.c", written by Andy Finkel
  6.  * and Phil Lindsay of Commodore-Amiga.  
  7.  */
  8.  
  9. #define __NO_PRAGMAS /* DAV */
  10.  
  11. #include "exec/types.h"
  12. #include "exec/ports.h"
  13. #include "exec/io.h"
  14. #include "exec/memory.h"
  15. #include "libraries/dos.h"
  16. #include "libraries/dosextens.h"
  17.  
  18. #ifdef AZTEC_C
  19. #include <functions.h>
  20. #endif
  21.  
  22. LONG 
  23. sendpkt(id,type,args,nargs)
  24.     struct MsgPort *id;                /* process indentifier ... (handler's
  25.                                        message port ) */
  26.     LONG type,                        /* packet type ... (what you want 
  27.                                        handler to do )   */
  28.     args[],                            /* a pointer to argument list */
  29.     nargs;                            /* number of arguments in list  */
  30. {
  31.  
  32.     struct MsgPort     *replyport;
  33.     struct StandardPacket  *packet;
  34.  
  35.     LONG count,*pargs,res1=NULL;
  36.  
  37.     if (!(replyport = (struct MsgPort   *) CreatePort(NULL,NULL)))
  38.         return(NULL);
  39.  
  40.     packet = (struct StandardPacket *)
  41.                AllocMem((LONG)sizeof(*packet),MEMF_PUBLIC|MEMF_CLEAR);
  42.  
  43.     if (packet) {
  44.         packet->sp_Msg.mn_Node.ln_Name = &(packet->sp_Pkt);/* link packet */
  45.         packet->sp_Pkt.dp_Link = &(packet->sp_Msg);/* to message    */
  46.         packet->sp_Pkt.dp_Port = replyport;/* set-up reply port   */
  47.         packet->sp_Pkt.dp_Type = type;/* what to do... */
  48.  
  49.     /* move all the arguments to the packet */
  50.         pargs = &(packet->sp_Pkt.dp_Arg1);/* address of first argument */
  51.         for (count=0; (count < nargs) && (count < 7); count++)
  52.             pargs[count] = args[count];
  53.  
  54.         PutMsg(id,packet);            /* send packet */
  55.         WaitPort(replyport);        /* wait for packet to come back */
  56.         GetMsg(replyport);            /* pull message */
  57.  
  58.         res1 = packet->sp_Pkt.dp_Res1;/* get result */
  59.         FreeMem(packet,(LONG)sizeof(*packet));
  60.  
  61.     }
  62.     DeletePort(replyport);
  63.     return(res1);
  64. }
  65.