home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / extfuncproc_387.lzh / ExtFuncProc / Test.c < prev    next >
C/C++ Source or Header  |  1990-10-22  |  3KB  |  114 lines

  1.  
  2. /***************************************************************************
  3. *
  4. *        Programm:   test
  5. *        Modul:      test.c
  6. *        Funktion:   testet ExtFuncProc
  7. *
  8. *        Datum:            01.05.90
  9. *        letzte Änderung:
  10. *
  11. ***************************************************************************/
  12.  
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15.  
  16. void
  17. end(struct MsgPort *port,char *s)
  18.  
  19. {
  20.    puts(s);
  21.    if (port)
  22.       DeletePort(port);
  23.    exit(10);
  24. }
  25.  
  26. void
  27. main(int argc,char **argv)
  28.  
  29. {
  30.    long segment;
  31.    struct ExtFuncPort *efp;
  32.    struct ExtFuncMessage efm;
  33.    struct FileHandle *fh;
  34.    struct MsgPort *myport;
  35.    char buffer[16];
  36.    void *proc_id;
  37.  
  38.    if (!(myport = CreatePort(NULL,0L)))
  39.       end(NULL,"no replyport");
  40.    efm.efm_Msg.mn_ReplyPort = myport;
  41.    efm.efm_Msg.mn_Length = sizeof(struct ExtFuncPort);
  42.    if (!(efp = (struct ExtFuncPort *)FindPort((char *)EFP_PORTNAME))) {
  43.       if (!(segment = LoadSeg((char *)"ExtFuncProc")))
  44.          end(myport,"no segment");
  45.       if (!(proc_id = CreateProc((char *)"ExtFuncProc",0L,segment,4000L)))
  46.          end(myport,"no process");
  47.       PutMsg(proc_id,(struct Message *)&efm);
  48.       WaitPort(myport);
  49.       GetMsg(myport);
  50.       efp = (struct ExtFuncPort *)FindPort((char *)EFP_PORTNAME);
  51.    }
  52.    if (efp && ((efp->efp_MatchWord!=EFP_MATCHWORD) || (efp->efp_MatchTag!=efp)))
  53.       /* war irgend ein anderer Port,
  54.          sollte zumindest beim 1. Mal geprüft werden */
  55.       efp = NULL;
  56.    if (!efp)
  57.       end(myport,"no port");
  58.    /* */
  59.    efm.efm_LibName = (UBYTE *)"dos.library";
  60.    efm.efm_LibVersion = 0L;
  61.    /* Open */
  62.    efm.efm_LibVectorOffset = -30;
  63.    efm.efm_ArgD1 = (long)"con:0/0/300/70/test";
  64.    efm.efm_ArgD2 = 1006L;
  65.    PutMsg((struct MsgPort *)efp,(struct Message *)&efm);
  66.    WaitPort(myport);
  67.    GetMsg(myport);
  68.    if (efm.efm_Error)
  69.       end(myport,"no library");
  70.    if (!(fh = (struct FileHandle *)efm.efm_Result))
  71.       end(myport,"open error");
  72.    /* Write */
  73.    efm.efm_LibVectorOffset = -48;
  74.    efm.efm_ArgD1 = (long)fh;
  75.    efm.efm_ArgD2 = (long)"this is a test\nhit RETURN\nand wait\n";
  76.    efm.efm_ArgD3 = 35L;
  77.    PutMsg((struct MsgPort *)efp,(struct Message *)&efm);
  78.    WaitPort(myport);
  79.    GetMsg(myport);
  80.    if (efm.efm_Error)
  81.       end(myport,"no library");
  82.    if (efm.efm_Result != efm.efm_ArgD3)
  83.       end(myport,"write error");
  84.    /* Read */
  85.    efm.efm_LibVectorOffset = -42;
  86.    efm.efm_ArgD1 = (long)fh;
  87.    efm.efm_ArgD2 = (long)buffer;
  88.    efm.efm_ArgD3 = 1L;
  89.    PutMsg((struct MsgPort *)efp,(struct Message *)&efm);
  90.    WaitPort(myport);
  91.    GetMsg(myport);
  92.    if (efm.efm_Error)
  93.       end(myport,"no library");
  94.    if (efm.efm_Result != efm.efm_ArgD3)
  95.       end(myport,"read error");
  96.    /* Delay */
  97.    efm.efm_LibVectorOffset = -198;
  98.    efm.efm_ArgD1 = 100L;
  99.    PutMsg((struct MsgPort *)efp,(struct Message *)&efm);
  100.    WaitPort(myport);
  101.    GetMsg(myport);
  102.    if (efm.efm_Error)
  103.       end(myport,"no library");
  104.    /* Close */
  105.    efm.efm_LibVectorOffset = -36;
  106.    efm.efm_ArgD1 = (long)fh;
  107.    PutMsg((struct MsgPort *)efp,(struct Message *)&efm);
  108.    WaitPort(myport);
  109.    GetMsg(myport);
  110.    if (efm.efm_Error)
  111.       end(myport,"no library");
  112. }
  113.  
  114.