home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d540 / browser.lha / Browser / BrowserII_Src.LZH / Process.c < prev    next >
C/C++ Source or Header  |  1991-07-20  |  6KB  |  250 lines

  1. /*
  2.  *    Process.c - Copyright © 1991 by S.R. & P.C.
  3.  *
  4.  *    Created:    01 Jun 1991  17:58:12
  5.  *    Modified:    20 Jul 1991  12:26:54
  6.  *
  7.  *    Make>> make
  8.  */
  9.  
  10. #include "Global.h"
  11. #include "FileList.h"
  12. #include "Process.h"
  13. #include "Actions.h"
  14. #include "proto/Process.h"
  15. #include "proto/Windows.h"    /* for SetWaitPointer() */
  16. #include "proto/FileList.h"
  17. #include "proto/File.h"
  18. #include "proto/Actions.h"
  19. #include "proto/Copy.h"
  20. #include "proto/ActionBack.h"
  21.  
  22. extern struct ExecBase *SysBase;
  23. extern struct ArpBase *ArpBase;
  24. extern struct Process *MainProcess;
  25. extern struct BrowserWindow *CurrentWin;
  26. extern struct Config Config;
  27. extern struct ParMConfig ParMConfig;
  28. extern struct MsgPort *ProcessPort;
  29. extern short NumProcess;
  30. extern char *ReqTitle;
  31. extern char *Copyright;
  32.  
  33. void DummySegment(void);    /* for CreateProc() */
  34. void geta4(void);
  35.  
  36. BPTR UntrackedDupLock(BPTR);
  37. void UntrackedUnLock(BPTR);
  38. #pragma    amicall(ArpBase, 0x60, UntrackedDupLock(d1))
  39. #pragma    amicall(ArpBase, 0x5a, UntrackedUnLock(d1))
  40.  
  41.  
  42. void FreeBrowserMsg(struct BrowserMsg *Msg)
  43. {
  44.     switch(Msg->bm_Type) {
  45.     case BM_STARTUP:
  46.         UntrackedUnLock(Msg->bm_Info.Startup.Lock);
  47.         break;
  48.     case BM_ACTIONBACK:
  49.         CleanFileInfo(&Msg->bm_Info.ActionBack.sfi.FileInfo);
  50.         break;
  51.     case BM_UPDATEDIR:
  52.         break;
  53.     }
  54.     FreeMem(Msg, sizeof(struct BrowserMsg));
  55. }
  56.  
  57.  
  58. void FreeProcessRepliedMsg(struct TaskData *TaskData)
  59. {
  60.     struct BrowserMsg *Msg;
  61.  
  62.     while(Msg = (struct BrowserMsg *)GetMsg(TaskData->td_ReplyPort)) {
  63.         FreeBrowserMsg(Msg);
  64.         TaskData->td_MsgCount--;
  65.     }
  66. }
  67.  
  68.  
  69. void WaitAllMsg(struct TaskData *TaskData)
  70. {
  71.     while(TaskData->td_MsgCount > 0) {
  72.         WaitPort(TaskData->td_ReplyPort);
  73.         FreeProcessRepliedMsg(TaskData);
  74.     }
  75. }
  76.  
  77.  
  78. struct BrowserMsg *AllocBrowserMsg(void)
  79. {
  80.     struct BrowserMsg *Msg;
  81.  
  82.     if (Msg = AllocMem(sizeof(struct BrowserMsg), MEMF_PUBLIC|MEMF_CLEAR)) {
  83.         Msg->bm_ExecMessage.mn_Length = sizeof(struct BrowserMsg);
  84.         Msg->bm_ExecMessage.mn_Node.ln_Type = NT_MESSAGE;
  85.     }
  86.     return Msg;
  87. }
  88.  
  89.  
  90. static struct BrowserMsg *AllocStartupMsg(void)
  91. {
  92.     struct BrowserMsg *Msg;
  93.  
  94.     if (!(Msg = AllocBrowserMsg()))
  95.         return NULL;
  96.     Msg->bm_ExecMessage.mn_ReplyPort = ProcessPort;
  97.     Msg->bm_Type = BM_STARTUP;
  98.     Msg->bm_Info.Startup.Lock = UntrackedDupLock(MainProcess->pr_CurrentDir);
  99.     return Msg;
  100. }
  101.  
  102.  
  103. static void CreateBrowserProcess(struct BrowserMsg *Msg)
  104. {
  105.     struct MsgPort *Process;
  106.     BPTR Segment;
  107.  
  108.     Segment = (long)DummySegment >> 2;
  109.     if (Process = CreateProc("BrowserII Background Process", 0, Segment, 4096)) {
  110.         PutMsg(Process, (struct Message *)Msg);
  111.         NumProcess++;
  112.     }
  113.     else {
  114.         SimpleRequest(ReqTitle, "Couldn't create process.\n%s.", StrIoErr());
  115.         FreeMem(Msg, sizeof(struct BrowserMsg));
  116.     }
  117. }
  118.  
  119.  
  120. void RunAction(struct HeadFileList *hfl, short ActionNum)
  121. {
  122.     struct BrowserMsg *Msg;
  123.     BPTR DestDir = NULL;
  124.     BOOL ASync;
  125.  
  126.     ASync = (Config.Options & OPT_ASYNCHRONOUS);
  127.     if (ASync) {
  128.         if (!(Msg = AllocStartupMsg()))
  129.             return;
  130.         Msg->bm_Info.Startup.ActionNum = ActionNum;
  131.         Msg->bm_Info.Startup.hfl = hfl;
  132.     }
  133.     else {
  134.         SetWaitPointer(TRUE);
  135.         SetTaskPri((struct Task *)MainProcess, 0);
  136.     }
  137.     switch(ActionNum) {
  138.     case BROWSERACTION_COPYMOVE:
  139.         if (ASync)
  140.             CreateBrowserProcess(Msg);
  141.         else
  142.             CopyMove(hfl);
  143.         break;
  144.     default:
  145.         if (CurrentWin->bw_Type == BW_DIR)
  146.             DestDir = DupLock(CurrentWin->bw_DirLock);
  147.         if(hfl = MakeSelectedList(NULL, DestDir, NULL)) {
  148.             if (ASync) {
  149.                 Msg->bm_Info.Startup.hfl = hfl;
  150.                 CreateBrowserProcess(Msg);
  151.             }
  152.             else
  153.                 InitAndDoAction(hfl, ActionNum);
  154.         }
  155.     }
  156.     if (!ASync) {
  157.         FreeFileList(hfl);
  158.         SetWaitPointer(FALSE);
  159.         SetTaskPri((struct Task *)MainProcess, 1);
  160.     }
  161. }
  162.  
  163.  
  164. void ASyncWBRun(struct ParMConfig *PCfg, struct Extended_WBStartup *EWBS, BYTE Pri)
  165. {
  166.     struct BrowserMsg *Msg;
  167.     struct Window *W;
  168.     char buf[80];
  169.  
  170.     if (Config.Options & OPT_ASYNCHRONOUS) {
  171.         if (!(Msg = AllocStartupMsg()))
  172.             return;
  173.         W = CurrentWin->bw_Window;
  174.         SPrintf(buf, "BrowserII: Attempting to load \"%s\".", EWBS->WBStartup.sm_ArgList->wa_Name);
  175.         SetWindowTitles(W, (char *)W->Title, buf);
  176.         Msg->bm_Info.Startup.EWBS = EWBS;
  177.         Msg->bm_Info.Startup.Pri = Pri;
  178.         Msg->bm_Info.Startup.ActionNum = BROWSERACTION_WBRUN;
  179.         CreateBrowserProcess(Msg);
  180.         Delay(20);    /* Let user see the message */
  181.         SetWindowTitles(W, (char *)W->Title, Copyright);
  182.     }
  183.     else
  184.         WBRun(PCfg, EWBS, Pri);
  185. }
  186.  
  187.  
  188. /* Entry point of browser processes */
  189.  
  190. void BrowserProcess(void)
  191. {
  192.     struct Process *pp;
  193.     struct BrowserMsg *Msg;
  194.     struct TaskData *TaskData;
  195.     struct HeadFileList *hfl;
  196.     short ActionNum;
  197.  
  198.     geta4();
  199.     pp = (struct Process *)SysBase->ThisTask;
  200.     WaitPort(&pp->pr_MsgPort);
  201.     Msg = (struct BrowserMsg *)GetMsg(&pp->pr_MsgPort);
  202.     OpenLibrary("arp.library", 39L);    /* Arp resources are tracked for each process */
  203.     CurrentDir(((struct BrowserMsg *)Msg)->bm_Info.Startup.Lock);
  204.     pp->pr_COS = MainProcess->pr_COS;
  205.     pp->pr_CIS = MainProcess->pr_CIS;
  206.     TaskData = AllocMem(sizeof(struct TaskData), MEMF_PUBLIC|MEMF_CLEAR);
  207.     TaskData->td_ReplyPort = CreatePort(0,0);
  208.     pp->pr_Task.tc_UserData = (APTR)TaskData;
  209.     hfl = Msg->bm_Info.Startup.hfl;
  210.     ActionNum = Msg->bm_Info.Startup.ActionNum;
  211.     switch(ActionNum) {
  212.     case BROWSERACTION_COPYMOVE:
  213.         CopyMove(hfl);
  214.         FreeFileList(hfl);
  215.         break;
  216.     case BROWSERACTION_WBRUN:
  217.         WBRun(&ParMConfig, Msg->bm_Info.Startup.EWBS, Msg->bm_Info.Startup.Pri);
  218.         break;
  219.     default:
  220.         InitAndDoAction(hfl, ActionNum);
  221.         FreeFileList(hfl);
  222.     }
  223.     WaitAllMsg(TaskData);
  224.     DeletePort(TaskData->td_ReplyPort);
  225.     FreeMem(TaskData, sizeof(struct TaskData));
  226.     CloseLibrary(ArpBase);
  227.     Forbid();
  228.     ReplyMsg((struct Message *)Msg);
  229.     /* end of Browser processes */
  230. }
  231.  
  232.  
  233.  
  234. #asm
  235.  
  236.     public _DummySegment
  237.     public _BrowserProcess
  238.  
  239.     cseg
  240.  
  241. _DummySegment:
  242.     dc.l    0
  243.     nop
  244.     nop
  245.     jmp        _BrowserProcess
  246.  
  247. #endasm
  248.  
  249.  
  250.