home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / comm / revrdist.sit / RevRdist / RevRdist src / idle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-13  |  4.1 KB  |  215 lines  |  [TEXT/KAHL]

  1. /*
  2.  * idle.c - the idle process
  3.  *    This is somewhat of a misnomer, since idle() is responsible for
  4.  *    starting the ball rolling and stopping it later.
  5.  */
  6.  
  7. #include "RevRdist.h"
  8. #include "dispatch.h"
  9. #include <TransSkelProto.h>
  10. #include <TransDisplayProto.h>
  11.  
  12.  
  13.  
  14. /*
  15.  *=========================================================================
  16.  * idle - the idle process.
  17.  *        this routine is the bottom routine on the dispatch stack and is
  18.  *        the one which starts things going and shuts them down.
  19.  *=========================================================================
  20.  */
  21.  
  22. DISPATCHED (idle)
  23. {
  24.     struct    lm                        /* local memory */
  25.     {
  26.         frame_t            f;
  27.         dnode_t *        dt;            /* control file tree */
  28.     };
  29.     typedef struct lm    lm_t;
  30.     register lm_t *        m;            /* pointer to local memory */
  31.     OSErr                error;
  32.     short                result;
  33.     Boolean                injunk;        /* for matchFolder call */
  34.     Ptr                    paramv[5];    /* param list for pushCalls */
  35.  
  36.     error = 0;
  37.     result = request;
  38.     m = *(lm_t **)fh;
  39.     switch (request)
  40.     {
  41.     case R_INIT:
  42.     /*
  43.      * Initial call.  Just extend frame by needed local memory.
  44.      */
  45.         if (error = resizeFrame (fh, sizeof (lm_t)))
  46.             break;
  47.         m = *(lm_t **)fh;
  48.         m->f.state = 1;
  49.         result = R_CONT;
  50.         break;
  51.  
  52.     case R_CONT:
  53.     /*
  54.      * Continue call.  Advance from phase to phase of processing on the
  55.      * control file.
  56.      */
  57.         if (Quit && (Flags & DB_STARTUP) == 0)
  58.         {
  59.             /*
  60.              * Possibly save preference file before quitting
  61.              */
  62.             if (PrefDialog)
  63.                 prefDoFMenu (FILE_CLOSE);
  64.         }
  65.         if (Quit)
  66.             if (m->f.state == 1)
  67.                 return R_QUIT;
  68.             else
  69.                 return R_BACKOUT;
  70.         switch (m->f.state)
  71.         {
  72.         /*
  73.          * Normal state when waiting for user to decide what to do.
  74.          * I.e. to open a control file.
  75.          */
  76.         case 1:
  77.             if (Pending == PA_NULL)
  78.             {
  79.                 /*
  80.                  * Nothing requested, possibly update status display,
  81.                  * but otherwise, do nothing.
  82.                  */
  83.                 if (Pause != S_IDLE)
  84.                 {
  85.                     Pause = S_IDLE;
  86.                     setStat ();
  87.                 }
  88.             }
  89.             if (Pending == PA_PREF)
  90.             {
  91.                 Pending = PA_NULL;
  92.                 doPref ();
  93.             }
  94.             if (Pending != PA_GO)
  95.                 break;
  96.  
  97.             /*
  98.              * Check if everything set up, then go to it!
  99.              * Start by parsing the configured distribution control file
  100.              */
  101.             Pending = PA_NULL;
  102.             if (error = getSet ())
  103.             {
  104.                 error = 0;
  105.                 Quit = false;
  106.                 Pending = PA_PREF;
  107.                 break;
  108.             }
  109.             if (Quit)
  110.                 break;
  111.             Depth = 0;
  112.             m->f.state = 2;
  113.             Watch = GetCursor (watchCursor);
  114.             Pause = S_RUNNING;
  115.             setStat ();
  116.             result = pushCall (parseDistFile, nil);
  117.             break;
  118.  
  119.         case 2:
  120.         /*
  121.          * Check result of parseDistFile
  122.          */
  123.             if (argv == nil || argv[0] == nil)
  124.             {
  125.                 if (ClueID > 0)
  126.                     panic (false, ClueID, nil);
  127.                 else
  128.                     panic (false, E_SYS, nil);
  129.                 return R_BACKOUT;        /* failed */
  130.             }
  131.             m->dt = (dnode_t *) argv[0];
  132.             m->f.state = 3;
  133.             break;
  134.  
  135.         case 3:
  136.         /*
  137.          * Control file parsed okay.  Empty the Junk folder in preparation
  138.          * for moving other files there.
  139.          */
  140.             m->f.state = 4;
  141.             result = pushCall (cleanJunk, nil);
  142.             break;
  143.  
  144.         case 4:
  145.             m->f.state = 5;
  146.             break;
  147.  
  148.         case 5:
  149.         /*
  150.          * Set up to match the root folder against the master
  151.          */
  152.             statMsg ((SP)"\p");        /* clear status */
  153.             injunk = false;
  154.             paramv[0] = (Ptr) m->dt;
  155.             paramv[1] = (Ptr) &m->dt->childp->actions;
  156.             paramv[2] = (Ptr) &ServerRoot;
  157.             paramv[3] = (Ptr) &ClientRoot;
  158.             paramv[4] = (Ptr) &injunk;
  159.             m->f.state = 6;
  160.             result = pushCall (matchFolder, paramv);
  161.             break;
  162.  
  163.         case 6:
  164.             updateRoot (m->dt);
  165.             verifyBlessed ();
  166.             result = R_BACKOUT;
  167.             break;
  168.         }
  169.         /*
  170.          * End of R_CONT state switch
  171.          */
  172.         if (error)
  173.         {
  174.             if (error < 0)
  175.             {
  176.                 ClueID = error;
  177.                 error = E_SYS;
  178.             }
  179.             panic (false, error, nil);
  180.             result = R_BACKOUT;
  181.         }
  182.         break;
  183.  
  184.     case R_BACKOUT:
  185.         if (Flags & DB_STARTUP)
  186.         {
  187.             result = R_QUIT;
  188.             break;
  189.         }
  190.         /*
  191.          * When we back out to the idle level, wait for something to do
  192.          */
  193.         notice (L_DONE, nil);
  194.         SysBeep (1);
  195.         SysBeep (1);
  196.         result = R_CONT;
  197.         if (ErrorMsgs)
  198.             doWindowMenu (WIND_ERRORS);
  199.         ErrorMsgs = 0;
  200.         if (SizeResource ((Handle)fh) >= sizeof (lm_t) && m->f.state > 2)
  201.         {
  202.             freeDist (m->dt);
  203.         }
  204.         Quit = false;
  205.         m->f.state = 1;
  206.         break;
  207.  
  208.     case R_QUIT:
  209.         Quit = true;
  210.         SkelWhoa ();
  211.         SkelBackground (nil);
  212.         break;
  213.     }
  214.     return result;
  215. }