home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 594b.lha / Dautostart / src / savepath.c < prev    next >
C/C++ Source or Header  |  1991-09-11  |  2KB  |  69 lines

  1.  
  2. /*
  3.  *  SAVEPATH.C
  4.  *
  5.  *  Saves current path list to global message port, replacing any previously
  6.  *  saved path
  7.  *
  8.  *  COMPILE:    DCC savepath.c -o sys:bin/savepath -r -proto -mRR
  9.  */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <dos/dos.h>
  14. #include <dos/dosextens.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/alib_protos.h>
  18. #include <string.h>
  19.  
  20. #define PORTNAME    "SavePath.PORT"
  21.  
  22. typedef struct Process            Process;
  23. typedef struct CommandLineInterface Cli;
  24. typedef struct FileLock         FileLock;
  25. typedef struct MsgPort            MsgPort;
  26. typedef struct Node            Node;
  27.  
  28. typedef struct LockList {
  29.     BPTR    NextPath;
  30.     BPTR    PathLock;
  31. } LockList;
  32.  
  33. _main()
  34. {
  35.     Process *proc = (Process *)FindTask(NULL);
  36.     Cli     *cli = (Cli *)BADDR(proc->pr_CLI);
  37.     MsgPort *port;
  38.  
  39.     Forbid();
  40.     if (port = FindPort(PORTNAME)) {
  41.     Node *node;
  42.     while (node = RemHead(&port->mp_MsgList)) {
  43.         UnLock((BPTR)node->ln_Name);    /*  temporarily breaks Forbid   */
  44.         FreeMem(node, sizeof(Node));
  45.     }
  46.     } else {
  47.     char *name = strcpy(AllocMem(sizeof(PORTNAME), MEMF_PUBLIC), PORTNAME);
  48.     port = CreatePort(name, 0);
  49.     }
  50.     Permit();
  51.  
  52.     if (cli) {
  53.     LockList *ll;
  54.  
  55.     for (ll = (LockList *)BADDR(cli->cli_CommandDir); ll; ll = (LockList *)BADDR(ll->NextPath)) {
  56.         if (ll->PathLock) {
  57.         Node *node = AllocMem(sizeof(Node), MEMF_PUBLIC|MEMF_CLEAR);
  58.         node->ln_Name = (char *)DupLock(ll->PathLock);
  59.         Forbid();
  60.         AddTail(&port->mp_MsgList, node);
  61.         Permit();
  62.         }
  63.     }
  64.     }
  65.     return(0);
  66. }
  67.  
  68.  
  69.