home *** CD-ROM | disk | FTP | other *** search
/ Millennium Time Capsule / AC2000.BIN / disks / ac7_disk / everest / se_test / se_test.c < prev    next >
C/C++ Source or Header  |  1995-08-18  |  5KB  |  224 lines

  1.  
  2. /********************************************************************
  3. * SE_TEST:  This program demonstrates the SE-protocol with Everest.
  4. *
  5. * 1) Start EVEREST
  6. * 2) Start SE_TEST
  7. *
  8. * This program ignores memory protection. You have to allocate the
  9. * memory for the SE-protocol as public.
  10. ********************************************************************/
  11.  
  12.  
  13. #include <stddef.h>
  14. #include <tos.h>
  15. #include <aes.h>
  16. #include <vdi.h>
  17. #include <ext.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <ctype.h>
  21. #include <string.h>
  22.  
  23. #include "seproto.h"
  24. #include "vaproto.h"
  25. #include "se_test.h"
  26.  
  27. typedef enum {true=1,false=0} boolean;
  28. #define TRUE true
  29. #define FALSE false
  30.  
  31. OBJECT *menu;
  32.  
  33. char *app_name="SE_TEST ";   /* Memory protection ignored!! */
  34. int ap_id; /* Own ID */
  35. int ev_id; /* Everest ID */
  36.  
  37.  
  38. void wait_for_everest(void) {
  39. int send[16];
  40.     do {
  41.         ev_id=appl_find("EVEREST ");
  42.     }while(ev_id<0);
  43.     
  44.     send[0]=SE_INIT;
  45.     send[1]=ap_id;
  46.     send[2]=0;
  47.     send[3]=_SEINIT|_SEQUIT|_SEACK|
  48.             _SETERMINATE|_SECLOSE|_SEOPEN|
  49.             _SEERRFILE|_SEERROR;
  50.             /* SE_TEST is able to send these messages */
  51.     send[4]=0;
  52.     send[5]=_ESQUIT|_ESOK|_ESACK|_ESMAKE|_ESCOMPILE;
  53.             /* SE_TEST is able to understand these messages */
  54.     send[6]=SEPROTOVERSION;
  55.     appl_write(ev_id,16,send);
  56. }
  57.  
  58. ERRINFO errormessage={
  59.     "EVEREST.DOC",
  60.     "This planet has - or rather had - a problem, which was this: most "
  61.   "of the people on it were unhappy for pretty much of the time. "
  62.   "Many solutions were suggested for this problem, but most of these "
  63.   "were largely concerned with the movements of small green pieces "
  64.   "of paper, which is odd because on the whole it wasn't the small "
  65.   "green pieces of paper that were unhappy.",
  66.   0,
  67.   1264,
  68.   70
  69. };
  70.  
  71.  
  72. boolean do_menu(int titel, int eintr) {
  73. int send[16];
  74. boolean ready=false;
  75.     if (titel==FILE) {
  76.         switch(eintr) {
  77.             case OPEN:
  78.                 send[0]=SE_OPEN;
  79.                 send[1]=ap_id;
  80.                 send[2]=0;
  81.                 *((char **)(send+3))="EVEREST.DOC"; /* Memory protection ignored!! */
  82.                 appl_write(ev_id,16,send);
  83.                 break;
  84.             case CLOSE:
  85.                 send[0]=SE_CLOSE;
  86.                 send[1]=ap_id;
  87.                 send[2]=0;
  88.                 appl_write(ev_id,16,send);
  89.                 break;
  90.             case EDQUIT:
  91.                 send[0]=SE_TERMINATE;
  92.                 send[1]=ap_id;
  93.                 send[2]=0;
  94.                 appl_write(ev_id,16,send);
  95.                 break;
  96.             case ERROR:
  97.                 send[0]=SE_ERROR;
  98.                 send[1]=ap_id;
  99.                 send[2]=0;
  100.                 *((ERRINFO **)(send+3))=&errormessage;  /* Memory protection ignored!! */
  101.                 appl_write(ev_id,16,send);
  102.                 break;
  103.             case ERRFILE:
  104.                 send[0]=SE_ERRFILE;
  105.                 send[1]=ap_id;
  106.                 send[2]=0;
  107.                 *((char **)(send+3))=".\\SE_TEST\\ERROR.TXT"; /* Memory protection ignored!! */
  108.                 *((char **)(send+5))=".\\SE_TEST\\SE_TEST.C"; /* Memory protection ignored!! */
  109.                 appl_write(ev_id,16,send);
  110.                 break;
  111.             case QUIT:
  112.                 ready=true;
  113.                 break;
  114.         }
  115.     }
  116.     return ready;
  117. }
  118.  
  119. boolean do_keybd(int taststat, int tastcode) {
  120. boolean ready=false;
  121.     switch(tastcode & 0x00ff) {
  122.         case 'Q'-'@':
  123.             ready=do_menu(FILE,QUIT);
  124.             break;
  125.         case 'O'-'@':
  126.             ready=do_menu(FILE,OPEN);
  127.             break;
  128.         case 'E'-'@':
  129.             ready=do_menu(FILE,ERRFILE);
  130.             break;
  131.         case 'M'-'@':
  132.             ready=do_menu(FILE,ERROR);
  133.             break;
  134.         case 'S'-'@':
  135.             ready=do_menu(FILE,CLOSE);
  136.             break;
  137.         case 'X'-'@':
  138.             ready=do_menu(FILE,EDQUIT);
  139.             break;
  140.     }
  141.     return ready;
  142. }
  143.  
  144. boolean do_messag(int *messag) {
  145. int send[16];
  146. boolean ready=false;
  147. char alstr[800];
  148.     switch(messag[0]) {
  149.         case MN_SELECTED:
  150.             ready=do_menu(messag[3],messag[4]);
  151.             menu_tnormal(menu,messag[3],1);
  152.             break;
  153.         case ES_OK:
  154.             break;
  155.         case ES_ACK:
  156.             break;
  157.         case ES_QUIT:
  158.             evnt_timer(2000,0);
  159.             wait_for_everest();
  160.             break;
  161.         case ES_MAKE:
  162.             form_alert(1,"[1][SE_TEST: |Message received: |ES_MAKE.][  OK  ]");
  163.             break;
  164.         case ES_COMPILE:
  165.             form_alert(1,"[1][SE_TEST: |Message received: |ES_COMPILE.][ Continue ]");
  166.             strcpy(alstr,"[0][SE_TEST: |Compile file: |");
  167.             strcat(alstr,*(char **)(messag+3));
  168.             strcat(alstr,"][  OK  ]");
  169.             form_alert(1,alstr);
  170.             break;
  171.         case AV_PROTOKOLL:
  172.             send[0]=VA_PROTOSTATUS;
  173.             send[1]=ap_id;
  174.             send[2]=0;
  175.             send[3]=1;
  176.             send[4]=send[5]=0;
  177.             *((char * *)(send+6)) = app_name;
  178.             appl_write(messag[1],16,send);
  179.             break;
  180.         case AV_SENDKEY:
  181.             ready=do_keybd(messag[3],messag[4]);
  182.             break;
  183.         
  184.     }
  185.     return ready;
  186. }
  187.  
  188.  
  189. int main(void) {
  190. int error=0,d;
  191. boolean ready=false;
  192. int messag[16],send[16];
  193. int ms;
  194. int taststat,tastcode;
  195.     ap_id=appl_init();
  196.     if (ap_id>0) {
  197.         if (rsrc_load("SE_TEST.RSC")!=0) {
  198.             rsrc_gaddr(R_TREE,MENU,&menu);
  199.             menu_bar(menu,1);
  200.             wait_for_everest();
  201.             do {
  202.                 ms=evnt_multi( MU_KEYBD|MU_MESAG, 0,0,0,0,0,0,0,
  203.                                   0,0,0,0,0,0,
  204.                                   messag,0,0, &d,&d,&d,&taststat,&tastcode,&d);
  205.                 if (ms & MU_KEYBD) {
  206.                     ready=do_keybd(taststat,tastcode);
  207.                 }
  208.                 if (ms & MU_MESAG) {
  209.                     ready=do_messag(messag);
  210.                 }
  211.             }while(!ready);
  212.             rsrc_free();
  213.         }else
  214.             error=-1;
  215.         send[0]=SE_QUIT;
  216.         send[1]=ap_id;
  217.         send[2]=0;
  218.         appl_write(ev_id,16,send);
  219.         appl_exit();
  220.     }else
  221.         error=-1;
  222.     return error;
  223. }
  224.