Example #1
0
// Sends abort from lister to locking process
void lister_send_abort(Lister *lister)
{
	// Do we have a known locker?
	if (lister->locker_ipc)
	{
		// Send abort command
		if ((IPC_SafeCommand(lister->locker_ipc,IPC_ABORT,0,lister,0,0,&GUI->function_list))!=(ULONG)-1)
		{
			// Also signal control C to break MatchFirst/MatchNext
			if (lister->locker_ipc->proc)
			{
				Signal((struct Task *)lister->locker_ipc->proc,(SIGBREAKF_CTRL_C|IPCSIG_QUIT));
			}
		}
	}

	// Set abort flag
	lister->flags|=LISTERF_ABORTED;

	// Custom lister handler?
	if (lister->cur_buffer->buf_CustomHandler[0])
	{
		char port_name[40];

		// Abort trap installed?
		if (FindFunctionTrap("abort",lister->cur_buffer->buf_CustomHandler,port_name))
		{
			// Send abort message
			rexx_handler_msg(
				port_name,
				lister->cur_buffer,
				0,
				HA_String,0,"abort",
				HA_Value,1,lister,
				TAG_END);
		}
	}
}
function_internal_command(
	CommandList *command,
	char *args,
	FunctionHandle *handle,
	InstructionParsed *instruction)
{
	short ret=1;
	Lister *lister;
	DirBuffer *cust_buffer=0;
	Lister *source_lister=0,*dest_lister=0;
	char custom_port[40];
	PathNode *source_n=0,*dest_n=0;

	// Clear instruction flags
	if (handle) handle->instruction_flags=0;

	// Valid command?
	if (!command || !command->name) return 1;

	// Initialise custom port
	custom_port[0]=0;

	// Got a handle?
	if (handle)
	{
		// Get source and dest nodes
		source_n=function_path_current(&handle->source_paths);
		dest_n=function_path_current(&handle->dest_paths);

		// Get current source lister
		if (lister=function_lister_current(&handle->source_paths))
		{
			// Custom handler installed?
			if (lister->cur_buffer->buf_CustomHandler[0])
			{
				// If there's a NEW flag, we won't be using this lister
				if (instruction && !instruction->new_arg)
				{
					// Look for trap handler
					if (FindFunctionTrap(command->name,lister->cur_buffer->buf_CustomHandler,custom_port))
					{
						source_lister=lister;
						dest_lister=function_lister_current(&handle->dest_paths);
						cust_buffer=lister->cur_buffer;
					}
				}
			}
		}

		// If no custom handler, try destination
		if (!cust_buffer &&
			(command->flags&FUNCF_NEED_DEST) &&
			(lister=function_lister_current(&handle->dest_paths)))
		{
			// Custom handler installed?
			if (lister->cur_buffer->buf_CustomHandler[0])
			{
				// Look for trap handler
				if (FindFunctionTrap(command->name,lister->cur_buffer->buf_CustomHandler,custom_port))
				{
					source_lister=function_lister_current(&handle->source_paths);
					dest_lister=lister;
					cust_buffer=lister->cur_buffer;
				}
			}
		}
	}

	// Custom handler?
	if (cust_buffer)
	{
		char *files=0;
		ULONG flags;

		// Need files?
		if (command->flags&FUNCF_NEED_ENTRIES)
		{
			// Build file string
			files=function_build_file_string(
				handle,
				cust_buffer->cust_flags&CUSTF_WANT_QUOTES);
		}

		// Get flags
		flags=RXMF_WARN;
		if (cust_buffer->cust_flags&CUSTF_SYNCTRAPS) flags|=RXMF_SYNC;

		// Send command message
		ret=rexx_handler_msg(
			custom_port,
			cust_buffer,
			flags,
			HA_String,0,command->name,
			HA_Value,1,source_lister,
			HA_String,2,files,
			HA_Value,3,dest_lister,
			HA_String,4,(source_n)?source_n->path:0,
			HA_String,5,args,
			HA_String,7,(dest_n)?dest_n->path:0,
			HA_Value,8,(flags&RXMF_SYNC)?handle:0,
			TAG_END);

		// Free file string
		FreeVec(files);
		return ret;
	}

	// External command?
	if (command->flags&FUNCF_EXTERNAL_FUNCTION)
	{
		struct Library *ModuleBase;
		char *work_buf=0,*buffer;

		// Need to allocate buffer?
		if (!handle)
		{
			work_buf=AllocVec(512,MEMF_CLEAR);
			buffer=work_buf;
		}
		else buffer=handle->work_buffer;

		// No buffer?
		if (!buffer || strcmp(command->stuff.module_name,"!")==0)
		{
		}

		// User command?
		else
		if (strnicmp(command->stuff.module_name,"dopus5:commands/",16)==0)
		{
			// Shouldn't be able to get here!
		}

		// Rexx script?
		else
		if (sufcmp(command->stuff.module_name,".dopus5"))
		{
			// Get rexx function to run
			lsprintf(buffer,
				"dopus5:modules/%s %s %s %ld %ld %s",
				command->stuff.module_name,
				GUI->rexx_port_name,
				command->name,
				(source_n)?source_n->lister:0,
				(dest_n)?dest_n->lister:0,
				args);

			// Run rexx thing
			rexx_send_command(buffer,TRUE);
		}

		// Open module
		else
		if (ModuleBase=OpenModule(command->stuff.module_name))
		{
			// Copy arguments
			strcpy(buffer,args);

			// Add a newline
			if (*buffer) strcat(buffer,"\n");

			// Call module
			ret=Module_Entry(
				(command->flags&FUNCF_NO_ARGS)?0:(struct List *)buffer,
				GUI->screen_pointer,
				(handle)?handle->ipc:0,
				&main_ipc,
				command->function,
				(ULONG)function_external_hook);

			// Close module
			CloseLibrary(ModuleBase);
		}

		// Free buffer
		FreeVec(work_buf);
	}

	// Valid code?
	else
	if (command->stuff.code)
		ret=(int)((int (*)())(command->stuff.code)(command,handle,args,instruction));

	return ret;
}