home *** CD-ROM | disk | FTP | other *** search
/ M.u.C.S. Disc 2000 / MUCS2000.iso / anwend / qed453 / src / olga.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-11  |  3.3 KB  |  169 lines

  1. #include "global.h"
  2. #include "comm.h"
  3. #include "options.h"
  4. #include "olga.h"
  5.  
  6. /* lokale Variablem **********************************************************/
  7. static int    olga_id;
  8. static bool    olga_active, have_started = FALSE;
  9.  
  10. /*****************************************************************************/
  11. static void send_ole_init(void)
  12. {
  13.     if (debug_level & DBG_OL)
  14.         debug("send_ole_init\n");
  15.  
  16.     memset(msgbuff, 0, (int)sizeof(msgbuff));
  17.     msgbuff[0] = OLE_INIT;
  18.     msgbuff[1] = gl_apid;
  19.     msgbuff[3] = OL_SERVER;
  20.     msgbuff[7] = 'ED';
  21.     send_msg(olga_id);
  22. }
  23.  
  24. static void send_ole_exit(void)
  25. {
  26.     if (debug_level & DBG_OL)
  27.         debug("send_ole_exit\n");
  28.  
  29.     memset(msgbuff, 0, (int)sizeof(msgbuff));
  30.     msgbuff[0] = OLE_EXIT;
  31.     msgbuff[1] = gl_apid;
  32.     send_msg(olga_id);
  33. }
  34.  
  35. static void send_olga_update(char *filename)
  36. {
  37.     if (debug_level & DBG_OL)
  38.         debug("send_ole_update: %s\n", filename);
  39.  
  40.     memset(msgbuff, 0, (int)sizeof(msgbuff));
  41.     msgbuff[0] = OLGA_UPDATE;
  42.     msgbuff[1] = gl_apid;
  43.     strcpy(global_str1, filename);
  44.     *(char **)(msgbuff + 3) = global_str1;
  45.     send_msg(olga_id);
  46. }
  47.  
  48. static void send_olga_rename(char *oldname, char *newname)
  49. {
  50.     if (debug_level & DBG_OL)
  51.         debug("send_ole_rename: %s -> %s\n", oldname, newname);
  52.  
  53.     memset(msgbuff, 0, (int)sizeof(msgbuff));
  54.     msgbuff[0] = OLGA_RENAME;
  55.     msgbuff[1] = gl_apid;
  56.     strcpy(global_str1, oldname);
  57.     *(char **)(msgbuff + 3) = global_str1;
  58.     strcpy(global_str2, newname);
  59.     *(char **)(msgbuff + 5) = global_str2;
  60.     send_msg(olga_id);
  61. }
  62.  
  63. void handle_olga(int *msg)
  64. {
  65.     switch (msg[0])
  66.     {
  67.         case OLGA_INIT :
  68.             if (debug_level & DBG_OL)
  69.                 debug("receive OLGA_INIT\n");
  70.  
  71. #if 0
  72.     ab N.AES 1.2.0 nicht mehr nötig!
  73.     
  74.             /*
  75.              * Wenn qed OLGA gestartet hat, ist unter N.AES OLGA die aktuelle 
  76.              * Applikation! 
  77.             */
  78.             if (have_started && gl_naes)
  79.             {
  80.                 long    v;
  81.                 
  82.                 appl_control(gl_apid, 12, &v);
  83.                 have_started = FALSE;
  84.             }
  85. #endif
  86.  
  87.             olga_active = TRUE;
  88.             break;
  89.  
  90.         case OLE_NEW :
  91.             if (debug_level & DBG_OL)
  92.                 debug("receive OLE_NEW: id: %d\n", msg[1]);
  93.  
  94.             olga_id = msg[1];
  95.             send_ole_init();
  96.             break;
  97.  
  98.         case OLGA_ACK :
  99.             if (debug_level & DBG_OL)
  100.                 debug("receive OLGA_ACK\n");
  101.             break;
  102.  
  103.         case OLE_EXIT :
  104.             if (debug_level & DBG_OL)
  105.                 debug("receive OLE_EXIT\n");
  106.             olga_active = FALSE;
  107.             break;
  108.     }
  109. }
  110.  
  111. void do_olga(int flag, char *name1, char *name2)
  112. {
  113.     if (olga_active)
  114.     {
  115.         switch (flag)
  116.         {
  117.             case OLGA_UPDATE :
  118.                 if (name1 != NULL)
  119.                     send_olga_update(name1);
  120.                 break;
  121.  
  122.             case OLGA_RENAME :
  123.                 if (name1 != NULL && name2 != NULL)
  124.                     send_olga_rename(name1, name2);
  125.                 break;
  126.         }
  127.     }
  128. }
  129.  
  130. void init_olga(void)
  131. {
  132.     char    *p;
  133.  
  134.     if (!olga_active)
  135.     {
  136.         olga_id = appl_find("OLGA    ");
  137.         if (olga_id > 0)
  138.             send_ole_init();
  139.         else if (olga_autostart)
  140.         {
  141.             p = getenv("OLGAMANAGER");
  142.             if (p != NULL)
  143.             {
  144.                 PATH    olga_path, olga_name, old;
  145.     
  146.                 if (debug_level & DBG_OL)
  147.                     debug("starting OLGA: %s\n", p);
  148.  
  149.                 strcpy(olga_name, p);
  150.                 split_filename(olga_name, olga_path, NULL);
  151.                 get_path(old, 0);
  152.                 set_path(olga_path);
  153.                 if (gl_gem >= 0x400)
  154.                     shel_write(1, 1, 1, olga_name, "");
  155.                 else if (gl_magx)
  156.                     shel_write(1, 1, 100, olga_name, "");
  157.                 have_started = TRUE;
  158.                 set_path(old);
  159.             }
  160.         }
  161.     }
  162. }
  163.  
  164. void term_olga(void)
  165. {
  166.     if (olga_active)
  167.         send_ole_exit();
  168. }
  169.