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

  1. /**************************
  2.  * doc.c                  *
  3.  **************************
  4.  **************************
  5.  * [1998-06-02, tm]       *
  6.  * - first C version      *
  7.  **************************/
  8.  
  9. #include "doc.h"
  10. #include "link.h"
  11. #include "manager.h"
  12.  
  13.  
  14. void open_doc(int *pipe)
  15. {
  16.     Document *doc = (Document *)malloc(sizeof(Document));
  17.  
  18.     if (doc)
  19.     {
  20.         doc->apID  = pipe[1];
  21.         doc->Group = pipe[5];
  22.         doc->Prev  = NULL;
  23.         doc->Next  = NULL;
  24.         
  25.         if (!docs) docs = doc;
  26.         else
  27.         {
  28.             Document *docd = docs;
  29.             
  30.             while (docd->Next) docd = docd->Next;
  31.             docd->Next = doc;
  32.             doc->Prev = docd;
  33.         }
  34.         
  35.         docCount++;
  36.     }
  37. }
  38.  
  39.  
  40.  
  41. void close_doc(int gv, int *pipe)
  42. {
  43.     Document *docd;
  44.     
  45.     _closedoc:
  46.     docd = docs;
  47.     
  48.     while (docd)
  49.     {
  50.         if (docd->apID == pipe[1])
  51.         {
  52.             if (gv)
  53.             {
  54.                 if (docd->Group != pipe[5]) goto _next;
  55.             }
  56.             
  57.             if ((!docd->Prev) && (!docd->Next)) docs = NULL;
  58.             else
  59.             {
  60.                 if (!docd->Prev) docs = docd->Next;
  61.                 else
  62.                     docd->Prev->Next = docd->Next;
  63.                 
  64.                 if (docd->Next) docd->Next->Prev = docd->Prev;
  65.             }
  66.             
  67.             free(docd);
  68.             docCount--;
  69.             goto _closedoc;
  70.         }
  71.  
  72.         _next:
  73.         docd = docd->Next;
  74.     }
  75. }
  76.  
  77.  
  78.  
  79. void olga_opendoc(int *pipe)
  80. {
  81.     int answ[8];
  82.  
  83.     #ifdef DEBUG
  84.     printf("OLGA: OLGA_OPENDOC App %i Group %i\n",pipe[1],pipe[5]);
  85.     #endif
  86.     
  87.     open_doc(pipe);
  88.  
  89.     answ[0] = OLGA_ACK;
  90.     answ[1] = ap_id;
  91.     answ[2] = 0;
  92.     answ[3] = 0;
  93.     answ[4] = 0;
  94.     answ[5] = pipe[5];
  95.     answ[6] = 0;
  96.     answ[7] = OLGA_OPENDOC;
  97.  
  98.     appl_write(pipe[1],16,answ);
  99. }
  100.  
  101.  
  102.  
  103. void olga_closedoc(int *pipe)
  104. {
  105.     int answ[8];
  106.     
  107.     #ifdef DEBUG
  108.     printf("OLGA: OLGA_CLOSEDOC App %i Group %i\n",pipe[1],pipe[5]);
  109.     #endif
  110.  
  111.     unLink(FALSE,TRUE,pipe);
  112.     close_doc(TRUE,pipe);
  113.  
  114.     answ[0] = OLGA_ACK;
  115.     answ[1] = ap_id;
  116.     answ[2] = 0;
  117.     answ[3] = 0;
  118.     answ[4] = 0;
  119.     answ[5] = pipe[5];
  120.     answ[6] = 0;
  121.     answ[7] = OLGA_CLOSEDOC;
  122.     
  123.     appl_write(pipe[1],16,answ);
  124. }
  125.