home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / SA_Examples / cd / CDTest / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  4.0 KB  |  246 lines

  1. /*
  2. **  cd.device Test
  3. **  Written by John J. Szucs
  4. **  Copyright © 1993-1999 Amiga, Inc.
  5. **  All Rights Reserved
  6. */
  7.  
  8. /*
  9. **  ANSI includes
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <math.h>
  16.  
  17. /*
  18. **  System includes
  19. */
  20.  
  21. #include <exec/types.h>
  22. #include <exec/interrupts.h>
  23. #include <exec/io.h>
  24.  
  25. #include <dos/dos.h>
  26.  
  27. #include <devices/cd.h>
  28.  
  29. #include <rexx/rxslib.h>
  30. #include <rexx/storage.h>
  31. #include <rexx/errors.h>
  32.  
  33. #include <clib/exec_protos.h>
  34. #include <clib/dos_protos.h>
  35. #include <clib/rexxsyslib_protos.h>
  36. #include <clib/alib_protos.h>
  37.  
  38. /*
  39. **  Local includes
  40. */
  41.  
  42. #define MAIN
  43.  
  44. #include "simplerexx.h"
  45. #include "cdtest.h"
  46.  
  47. /****** cd/main() ******************************************
  48. *
  49. *   NAME
  50. *       main    -   entry point
  51. *
  52. *   SYNOPSIS
  53. *       main(argc,argv);
  54. *
  55. *       void main(int argc,char *argv[]);
  56. *
  57. *   FUNCTION
  58. *       Main entry point.
  59. *
  60. *   INPUTS
  61. *       argc    -   argument count
  62. *       argv    -   argument value array
  63. *
  64. *   RESULT
  65. *       None
  66. *
  67. *   EXAMPLE
  68. *
  69. *   NOTES
  70. *
  71. *   BUGS
  72. *       If there are any, you can get to 'em from here!
  73. *
  74. *   SEE ALSO
  75. *       goodbye()
  76. *
  77. ******************************************************************************
  78. *
  79. */
  80.  
  81. void main(int argc,char *argv[])
  82. {
  83.  
  84.     BYTE error;
  85.  
  86.     struct options {
  87.         LONG debug;
  88.         LONG noCD;
  89.     } options;
  90.  
  91.     /*
  92.      * Parse arguments
  93.      */
  94.  
  95.     /* Parse command-line arguments */
  96.     memset(&options,0,sizeof(options));
  97.     rdArgs=ReadArgs("DEBUG/S,NOCD/S",(LONG *) &options,NULL);
  98.     if (!rdArgs) {
  99.         PrintFault(IoErr(),PROGRAM_NAME);
  100.         goodbye(RETURN_ERROR);
  101.     }
  102.  
  103.     /* Parse DEBUG */
  104.     debugMode=options.debug;
  105.  
  106.     /* Parse NOCD */
  107.     noCD=options.noCD;
  108.  
  109.     /*
  110.      *  Open devices
  111.      */
  112.  
  113.     /* Create cd.device reply port */
  114.     cdPort=CreateMsgPort();
  115.     if (!cdPort) {
  116.         Printf("%s: Error creating cd.device reply port\n",PROGRAM_NAME);
  117.         goodbye(RETURN_FAIL);
  118.     }
  119.  
  120.     /* Create cd.device I/O request */
  121.     cdRequest=CreateIORequest(cdPort,sizeof(*cdRequest));
  122.     if (!cdRequest) {
  123.         Printf("%s: Error creating cd.device I/O request\n",PROGRAM_NAME);
  124.         goodbye(RETURN_FAIL);
  125.     }
  126.  
  127.     if (!noCD) {
  128.  
  129.         /* Open cd.device */
  130.         error=OpenDevice("cd.device",0,cdRequest,NULL);
  131.         if (error) {
  132.             Printf("%s: Error %ld opening cd.device\n",PROGRAM_NAME,error);
  133.             goodbye(RETURN_FAIL);
  134.         }
  135.  
  136.     }
  137.  
  138.     /*
  139.      *  Set-up ARexx interface
  140.      */
  141.  
  142.     rexxContext=InitARexx(PROGRAM_NAME,REXXSCRIPT_EXTENSION);
  143.     if (!rexxContext) {
  144.         Printf("%s: Error creating ARexx interface\n",PROGRAM_NAME);
  145.     }
  146.     if (debugMode) {
  147.         printf("Ready\n");
  148.     }
  149.  
  150.     /*
  151.      *  Event loop
  152.      */
  153.  
  154.     /* Event loop */
  155.     eventLoop();
  156.  
  157.     /*
  158.      *  Fall-through
  159.      */
  160.  
  161.     /* Success */
  162.     goodbye(RETURN_OK);
  163.  
  164. }
  165.  
  166. /****** cd/goodbye ******************************************
  167. *
  168. *   NAME
  169. *       goodbye     -   terminate program
  170. *
  171. *   SYNOPSIS
  172. *       goodbye(returnCode);
  173. *
  174. *       void goodbye(int returnCode);
  175. *
  176. *   FUNCTION
  177. *       Terminate program.
  178. *
  179. *   INPUTS
  180. *       returnCode  -   return code
  181. *
  182. *   RESULT
  183. *       None
  184. *
  185. *   EXAMPLE
  186. *
  187. *   NOTES
  188. *
  189. *   BUGS
  190. *
  191. *   SEE ALSO
  192. *       main()
  193. *
  194. ******************************************************************************
  195. *
  196. */
  197.  
  198. void goodbye(int returnCode)
  199. {
  200.  
  201.     /*
  202.      *  Close ARexx interface
  203.      */
  204.  
  205.     /*  Free ARexx context */
  206.     if (rexxContext) {
  207.         FreeARexx(rexxContext);
  208.     }
  209.  
  210.     /*
  211.      *  Close devices
  212.      */
  213.  
  214.     /* Close cd.device */
  215.     if (cdOpen) {
  216.         CloseDevice(cdRequest);
  217.     }
  218.  
  219.     /* Delete cd.device I/O request */
  220.     if (cdRequest) {
  221.         DeleteIORequest(cdRequest);
  222.     }
  223.  
  224.     /* Delete cd.device reply port */
  225.     if (cdPort) {
  226.         DeleteMsgPort(cdPort);
  227.     }
  228.  
  229.     /*
  230.      *  Close interface
  231.      */
  232.  
  233.     /* Free dos.library/ReadArgs() control structure */
  234.     if (rdArgs) {
  235.         FreeArgs(rdArgs);
  236.     }
  237.  
  238.     /*
  239.      *  Exit
  240.      */
  241.  
  242.     /* Exit with return code */
  243.     exit(returnCode);
  244.  
  245. }
  246.