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 >
Wrap
C/C++ Source or Header
|
1991-09-11
|
2KB
|
69 lines
/*
* SAVEPATH.C
*
* Saves current path list to global message port, replacing any previously
* saved path
*
* COMPILE: DCC savepath.c -o sys:bin/savepath -r -proto -mRR
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>
#include <string.h>
#define PORTNAME "SavePath.PORT"
typedef struct Process Process;
typedef struct CommandLineInterface Cli;
typedef struct FileLock FileLock;
typedef struct MsgPort MsgPort;
typedef struct Node Node;
typedef struct LockList {
BPTR NextPath;
BPTR PathLock;
} LockList;
_main()
{
Process *proc = (Process *)FindTask(NULL);
Cli *cli = (Cli *)BADDR(proc->pr_CLI);
MsgPort *port;
Forbid();
if (port = FindPort(PORTNAME)) {
Node *node;
while (node = RemHead(&port->mp_MsgList)) {
UnLock((BPTR)node->ln_Name); /* temporarily breaks Forbid */
FreeMem(node, sizeof(Node));
}
} else {
char *name = strcpy(AllocMem(sizeof(PORTNAME), MEMF_PUBLIC), PORTNAME);
port = CreatePort(name, 0);
}
Permit();
if (cli) {
LockList *ll;
for (ll = (LockList *)BADDR(cli->cli_CommandDir); ll; ll = (LockList *)BADDR(ll->NextPath)) {
if (ll->PathLock) {
Node *node = AllocMem(sizeof(Node), MEMF_PUBLIC|MEMF_CLEAR);
node->ln_Name = (char *)DupLock(ll->PathLock);
Forbid();
AddTail(&port->mp_MsgList, node);
Permit();
}
}
}
return(0);
}