home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 1998 October / STC_CD_10_1998.iso / BASE / OLGA151 / SOURCE / START.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-26  |  6.0 KB  |  360 lines

  1. /****************************
  2.  * start.c                  *
  3.  ****************************
  4.  ****************************
  5.  * [1998-06-02, tm]         *
  6.  * - first C version        *
  7.  ****************************/
  8.  
  9. #include "start.h"
  10. #include "manager.h"
  11.  
  12.  
  13. #define VA_START 0x4711
  14.  
  15.  
  16.  
  17. void server_started(int srvID, int clID, int ext4, int ext5, int running)
  18. {
  19.     Server *ps = server;
  20.     Client *pc = clients;
  21.     int found = FALSE;
  22.     
  23.     while (ps)
  24.     {
  25.         if (ps->clID == clID)
  26.         {
  27.             if (ps->srvID == srvID)
  28.             {
  29.                 if ((ps->ext4 == ext4) && (ps->ext5 == ext5))
  30.                 {
  31.                     found = TRUE;
  32.                     break;
  33.                 }
  34.             }
  35.         }
  36.         
  37.         ps = ps->Next;
  38.     }
  39.     
  40.     if (!found)
  41.     {
  42.         ps = (Server *)malloc(sizeof(Server));
  43.         
  44.         if (ps)
  45.         {
  46.             ps->clID  = clID;
  47.             ps->srvID = srvID;
  48.             ps->ext4  = ext4;
  49.             ps->ext5  = ext5;
  50.             ps->Prev  = NULL;
  51.             ps->Next  = NULL;
  52.             
  53.             if (!server) server = ps;
  54.             else
  55.             {
  56.                 Server *psd = server;
  57.                 
  58.                 while (psd->Next) psd = psd->Next;
  59.                 psd->Next = ps;
  60.                 ps->Prev = psd;
  61.             }
  62.         }
  63.     }
  64.     
  65.     found = FALSE;
  66.     
  67.     while (pc)
  68.     {
  69.         if (pc->srvID == srvID)
  70.         {
  71.             if (pc->clID == clID)
  72.             {
  73.                 found = TRUE;
  74.                 break;
  75.             }
  76.         }
  77.         
  78.         pc = pc->Next;
  79.     }
  80.     
  81.     if (!found)
  82.     {
  83.         pc = (Client *)malloc(sizeof(Client));
  84.         
  85.         if (pc)
  86.         {
  87.             pc->srvID   = srvID;
  88.             pc->clID    = clID;
  89.             pc->runFlag = running;
  90.             pc->Prev    = NULL;
  91.             pc->Next    = NULL;
  92.             
  93.             if (!clients) clients = pc;
  94.             else
  95.             {
  96.                 Client *pcd = clients;
  97.                 
  98.                 while (pcd->Next) pcd = pcd->Next;
  99.                 pcd->Next = pc;
  100.                 pc->Prev = pcd;
  101.             }
  102.         }
  103.     }
  104. }
  105.  
  106.  
  107.  
  108. void olga_start(int *pipe)
  109. {
  110.     long cmdLen = 1L;
  111.     int stID, answ[8];
  112.     char sname[10], *p, *fname = (char *)malloc(512L), *pcmd = *(char **)&pipe[6];
  113.     App *pa = apps;
  114.     
  115.     #ifdef DEBUG
  116.     printf("OLGA: OLGA_START App %i  ",pipe[1]);
  117.     switch(pipe[3])
  118.     {
  119.     case OLS_TYPE:
  120.         printf("OLS_TYPE %c%c",(pipe[5] >> 8) & 0x00ff,pipe[5] & 0x00ff);
  121.         break;
  122.     case OLS_EXTENSION:
  123.         printf("OLS_EXTENSION %c%c%c%c",(pipe[4] >> 8) & 0x00ff,pipe[4] & 0x00ff,(pipe[5] >> 8) & 0x00ff,pipe[5] & 0x00ff);
  124.         break;
  125.     case OLS_NAME:
  126.         printf("OLS_NAME %s",*(char **)&pipe[4]);
  127.         break;
  128.     }
  129.     if (pcmd) printf("  Cmd %s\n",pcmd);
  130.     else
  131.         printf("\n");
  132.     #endif
  133.  
  134.     answ[6] = 0;
  135.  
  136.     while (pa)
  137.     {
  138.         if (pa->apID == pipe[1]) break;
  139.  
  140.         pa = pa->Next;
  141.     }
  142.     
  143.     if ((!pa) || (!fname)) goto _started;
  144.     
  145.     fname[0] = 0;
  146.     
  147.     switch(pipe[3])
  148.     {
  149.     case OLS_TYPE:
  150.         {
  151.             Type *pt = types;
  152.             
  153.             while (pt)
  154.             {
  155.                 if (pt->typ == pipe[5])
  156.                 {
  157.                     strcpy(fname,pt->path);
  158.                     expand_path(fname);
  159.  
  160.                     break;
  161.                 }
  162.                 
  163.                 pt = pt->next;
  164.             }
  165.         }
  166.         break;
  167.     
  168.     case OLS_EXTENSION:
  169.         {
  170.             Extension *pe = extensions;
  171.             
  172.             while (pe)
  173.             {
  174.                 if (pe->ext5 == pipe[5])
  175.                 {
  176.                     if (pe->ext4 == pipe[4])
  177.                     {
  178.                         strcpy(fname,pe->path);
  179.                         expand_path(fname);
  180.                         
  181.                         break;
  182.                     }
  183.                 }
  184.                 
  185.                 pe = pe->next;
  186.             }
  187.         }
  188.         break;
  189.  
  190.     case OLS_NAME:
  191.         strcpy(fname,*(char **)&pipe[4]);
  192.         break;
  193.     }
  194.     
  195.     if (!strlen(fname)) goto _started;
  196.     
  197.     pa->cmdCount++;
  198.     if (pa->cmdCount > CMDMAX) pa->cmdCount = 0;
  199.     
  200.     globalFree(pa->startCmd[pa->cmdCount]);
  201.     
  202.     if (pcmd) cmdLen += strlen(pcmd);
  203.  
  204.     p = strrchr(fname,'\\');
  205.     if (!p) p = fname;
  206.     else
  207.         p++;
  208.     
  209.     strncpy(sname,p,8L);
  210.     sname[8] = 0;
  211.  
  212.     p = strchr(sname,'.');
  213.     if (p) *p = 0;
  214.  
  215.     while (strlen(sname)<8) strcat(sname," ");
  216.     strupr(sname);
  217.     
  218.     stID = appl_find(sname);
  219.     
  220.     if (stID >= 0)
  221.     {
  222.         pa->startCmd[pa->cmdCount] = globalAlloc(cmdLen);
  223.         if (!pa->startCmd[pa->cmdCount]) goto _started;
  224.         
  225.         if (pcmd) strcpy(pa->startCmd[pa->cmdCount],pcmd);
  226.         else
  227.             pa->startCmd[pa->cmdCount][0] = 0;
  228.  
  229.         answ[0] = VA_START;
  230.         answ[1] = ap_id;
  231.         answ[2] = 0;
  232.         answ[3] = (int)(((long)pa->startCmd[pa->cmdCount] >> 16) & 0x0000ffffL);
  233.         answ[4] = (int)((long)pa->startCmd[pa->cmdCount] & 0x0000ffffL);
  234.         answ[5] = 0;
  235.         answ[6] = 0;
  236.         answ[7] = 0;
  237.  
  238.         appl_write(stID,16,answ);
  239.  
  240.         answ[6] = 1;
  241.         
  242.         if ((pipe[3] == OLS_TYPE) || (pipe[3] == OLS_EXTENSION))
  243.             server_started(stID,pipe[1],pipe[4],pipe[5],1);
  244.         else
  245.             server_started(stID,pipe[1],0,0,1);
  246.     }
  247.     else if ((multitos) || (magix))
  248.     {
  249.         int   tmp_drive;
  250.         char *tmp_cwd;
  251.         
  252.         cmdLen++;
  253.  
  254.         pa->startCmd[pa->cmdCount] = globalAlloc(cmdLen);
  255.         if (!pa->startCmd[pa->cmdCount]) goto _started;
  256.         
  257.         pa->startCmd[pa->cmdCount][0] = cmdLen-2;
  258.         
  259.         if (pcmd) strcpy(&(pa->startCmd[pa->cmdCount][1]),pcmd);
  260.         else
  261.             pa->startCmd[pa->cmdCount][1] = 0;
  262.         
  263.         tmp_drive = Dgetdrv();
  264.         
  265.         tmp_cwd = (char *)malloc(512L);
  266.         if (tmp_cwd) Dgetpath(tmp_cwd,tmp_drive+1);
  267.         
  268.         if (strlen(fname) > 1)
  269.         {
  270.             if (fname[1] == ':') Dsetdrv(toupper(fname[0])-65);
  271.         }
  272.  
  273.         p = strrchr(fname,'\\');
  274.         if (p)
  275.         {
  276.             char c = *(++p);
  277.             
  278.             *p = 0;
  279.             Dsetpath(fname);
  280.             *p = c;
  281.         }
  282.  
  283.         if (magix)
  284.             stID = shel_write(1,1,100,fname,pa->startCmd[pa->cmdCount]);
  285.         else
  286.             stID = shel_write(0,1,1,fname,pa->startCmd[pa->cmdCount]);
  287.         
  288.         if (!stID)
  289.         {
  290.             Dsetdrv(tmp_drive);
  291.             if (tmp_cwd) Dsetpath(tmp_cwd);
  292.         }
  293.         else
  294.         {
  295.             answ[6] = 1;
  296.             
  297.             if ((pipe[3] == OLS_TYPE) || (pipe[3] == OLS_EXTENSION))
  298.                 server_started(stID,pipe[1],pipe[4],pipe[5],0);
  299.             else
  300.                 server_started(stID,pipe[1],0,0,0);
  301.         }
  302.         
  303.         if (tmp_cwd) free(tmp_cwd);
  304.     }
  305.  
  306.     _started:
  307.  
  308.     answ[0] = OLGA_ACK;
  309.     answ[1] = ap_id;
  310.     answ[2] = 0;
  311.     answ[3] = pipe[3];
  312.     answ[4] = pipe[4];
  313.     answ[5] = pipe[5];
  314.     answ[7] = OLGA_START;
  315.  
  316.     appl_write(pipe[1],16,answ);
  317.  
  318.     if ((pipe[6]) || (pipe[7]))
  319.     {
  320.         answ[3] = 0;
  321.         answ[4] = pipe[6];
  322.         answ[5] = pipe[7];
  323.  
  324.         appl_write(pipe[1],16,answ);
  325.     }
  326.     
  327.     if (fname) free(fname);
  328. }
  329.  
  330.  
  331.  
  332. void av_started(int *pipe)
  333. {
  334.     char *p = *(char **)&pipe[3];
  335.     App *pa = apps;
  336.     int i;
  337.  
  338.     if (p)
  339.     {
  340.         while (pa)
  341.         {
  342.             if (pa->cmdCount >= 0)
  343.             {
  344.                 for(i=0; i <= pa->cmdCount; i++)
  345.                 {
  346.                     if (p == pa->startCmd[i])
  347.                     {
  348.                         globalFree(pa->startCmd[i]);
  349.                         pa->startCmd[i] = NULL;
  350.                         
  351.                         return;
  352.                     }
  353.                 }
  354.             }
  355.  
  356.             pa = pa->Next;
  357.         }
  358.     }
  359. }
  360.