home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 177.lha / DRes_v1.3 / util / testipc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-28  |  2.3 KB  |  117 lines

  1.  
  2. /*
  3.  *  TESTIPC <appname> <file> <file> <file> ...    <inputfile
  4.  *
  5.  *  input file format:
  6.  *
  7.  *  appname delay file text
  8.  *
  9.  */
  10.  
  11. #include <local/typedefs.h>
  12. #include <local/ipc.h>
  13. #include <local/xmisc.h>
  14. #include <stdio.h>
  15.  
  16. extern int Enable_Abort;
  17.  
  18. extern PORT *OpenIPC();
  19.  
  20. char **Av;
  21. short Ac;
  22.  
  23. main(ac, av)
  24. char *av[];
  25. {
  26.     PORT *port;
  27.  
  28.     Av = av;
  29.     Ac = ac;
  30.     if (ac == 1) {
  31.     puts("TESTIPC <appname> <subname> ... <subname>  <inputfile");
  32.     puts("input file format:");
  33.     puts("<appname> <delay-1/50ths> <subname> <text>");
  34.     exit(1);
  35.     }
  36.     Enable_Abort = 0;
  37.     if (openlibs(DRES_LIB) <= 0) {
  38.     puts("Unable to open dres.library");
  39.     exit(1);
  40.     }
  41.     port = OpenIPC(av[1], 0);
  42.     if (port == NULL) {
  43.     puts("unable to open port");
  44.     closelibs(-1);
  45.     exit(1);
  46.     }
  47.     printf("port: %08lx\n", port);
  48.     {
  49.     char apname[32];
  50.     long delay;
  51.     char subname[32];
  52.     char text[64];
  53.     char tbuf[128];
  54.     IPCMSG msg;
  55.     extern void handler();
  56.  
  57.     BZero(&msg, sizeof(msg));
  58.     msg.Msg.mn_ReplyPort = CreatePort(NULL, 0);
  59.  
  60.     puts("scanf");
  61.     while (scanf("%s %ld %s %s", apname, &delay, subname, text) == 4) {
  62.         printf("DO(%s %ld %s %s) ", apname, delay, subname, text);
  63.         fflush(stdout);
  64.         strcpy(tbuf, subname);
  65.         strcpy(tbuf+strlen(subname)+1, text);
  66.         msg.TBuf = (APTR)tbuf;
  67.         msg.TLen = strlen(subname)+strlen(text)+2;
  68.         DoIPC2(apname, &msg, handler, port);
  69.         if (msg.RFlags & IF_NOTFND) {
  70.         if (msg.RFlags & IF_NOAPP)
  71.             puts("Application not found");
  72.         else
  73.             puts("subname not found");
  74.         } else {
  75.         if (msg.RFlags & IF_ERROR)
  76.             printf("Error: %s\n", msg.RBuf);
  77.         else
  78.             printf("OK: %s\n", msg.RBuf);
  79.         }
  80.         FreeIPC(&msg);
  81.         if (delay)
  82.         Delay(delay);
  83.         if (CheckPort(port))
  84.         handler(port);
  85.     }
  86.     DeletePort(msg.Msg.mn_ReplyPort);
  87.     }
  88.     CloseIPC(port);
  89.     closelibs(-1);
  90. }
  91.  
  92. void
  93. handler(port)
  94. PORT *port;
  95. {
  96.     IPCMSG *msg;
  97.     short i, j;
  98.  
  99.     while (msg = GetMsg(port)) {
  100.     register char *ptr = (char *)msg->TBuf;
  101.     printf("Received IPC command: %s  ", ptr);
  102.     for (j = 0; ptr[j] && ptr[j] != ' '; ++j);
  103.     for (i = 2; i < Ac; ++i) {
  104.         if (strlen(Av[i]) == j && strncmp(Av[i], ptr, j) == 0)
  105.         break;
  106.     }
  107.     if (i < Ac) {
  108.         puts("MATCH");
  109.         ReplyIPC(msg, "GotIt!", 7, 0);
  110.     } else {
  111.         puts("PASSED");
  112.         ReplyIPC(msg, "Failed", 7, IF_NOTFND);
  113.     }
  114.     }
  115. }
  116.  
  117.