home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / cdgsxl / XLMSG / xlmsg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  2.6 KB  |  130 lines

  1. date ; /*
  2.  
  3. failat 1
  4. SC LINK MODIFIED NOSTKCHK NOICONS xlmsg TO xlmsg
  5. quit
  6.  
  7. */
  8.  
  9. /*************
  10.  
  11.   xlmsgtest.c
  12.  
  13.   W.D.L 930708
  14.  
  15. **************/
  16.  
  17. /*
  18.  * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1993-1999
  19.  * Amiga, Inc.  All rights reserved.
  20.  *
  21.  * DISCLAIMER: This software is provided "as is".  No representations or
  22.  * warranties are made with respect to the accuracy, reliability, performance,
  23.  * currentness, or operation of this software, and all use is at your own risk.
  24.  * Neither Amiga nor the authors assume any responsibility or liability
  25.  * whatsoever with respect to your use of this software.
  26.  */
  27.  
  28. // Tab size is 8!
  29.  
  30. #include <exec/types.h>
  31. #include <exec/ports.h>
  32. #include <exec/memory.h>
  33. #include <dos/dos.h>
  34. #include <clib/exec_protos.h>
  35. #include <clib/alib_protos.h>
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39.  
  40. #include "xlm.h"
  41.  
  42. /*
  43.  * print the status bits as a string.
  44.  */
  45. VOID
  46. status2str( ULONG status )
  47. {
  48.     int          i;
  49.     UBYTE      str[250];
  50.  
  51.     static struct status_def {
  52.     ULONG       status;
  53.     UBYTE    * str;
  54.     } stat[] = {
  55.     XLM_STATUS_PLAYING,    "XLM_STATUS_PLAYING",
  56.     XLM_STATUS_ABORTING,    "XLM_STATUS_ABORTING",
  57.     0,
  58.     };
  59.  
  60.     *str = 0;
  61.  
  62.     for ( i=0; stat[i].status; i++ ) {
  63.     if ( status & stat[i].status ) {
  64.         if (*str)
  65.         strcat(str,", ");
  66.  
  67.         strcat( str, stat[i].str );
  68.     }
  69.     }
  70.  
  71.     printf("status:\n'%ls'\n\n",str);
  72.  
  73. } // status2str()
  74.  
  75.  
  76. VOID
  77. main( LONG argc,char * argv[] )
  78. {
  79.     UBYTE        * portname;
  80.     struct MsgPort    * port,* replyport;
  81.     XLMESSAGE        * xlm,* reply;
  82.  
  83.     if ( (argc < 2) || !(portname = argv[1]) )
  84.     exit( RETURN_ERROR );
  85.  
  86.     if ( replyport = CreatePort(0,0) ) {
  87.     if (xlm = (XLMESSAGE *)AllocMem( sizeof (*xlm), MEMF_PUBLIC | MEMF_CLEAR)) {
  88.         xlm->msg.mn_Node.ln_Type = NT_MESSAGE;
  89.         xlm->msg.mn_Length = sizeof (*xlm);
  90.         xlm->msg.mn_ReplyPort = replyport;
  91.  
  92.         xlm->command = XLM_CMD_QUERY;
  93.         Forbid();
  94.         if ( port = FindPort( portname ) ) {
  95.         PutMsg( port, (struct Message *)xlm );
  96.         }
  97.         Permit();
  98.  
  99.         if ( port ) {
  100.         WaitPort( replyport );
  101.         if ( reply = (XLMESSAGE *)GetMsg( replyport ) ) {
  102.             printf("status= %ld\n",reply->status);
  103.             status2str( reply->status );
  104.         }
  105.         }
  106.  
  107.         xlm->command = XLM_CMD_ABORT;
  108.         Forbid();
  109.         if ( port = FindPort( portname ) ) {
  110.         PutMsg( port, (struct Message *)xlm );
  111.         }
  112.         Permit();
  113.  
  114.         if ( port ) {
  115.         WaitPort( replyport );
  116.         if ( reply = (XLMESSAGE *)GetMsg( replyport ) ) {
  117.             printf("status= %ld\n",reply->status);
  118.             status2str( reply->status );
  119.         }
  120.         }
  121.  
  122.         FreeMem( xlm, sizeof (*xlm) );
  123.     }
  124.     DeletePort( replyport );
  125.     }
  126.  
  127.     exit( RETURN_OK );
  128.  
  129. } // main()
  130.