Exemplo n.º 1
0
CORE_PROC(int, RelayInput)( PDATAPATH pdp
												, PTEXT (CPROC *Datacallback)( PDATAPATH pdp, PTEXT pLine ) )
{
	extern int gbTrace;
	if( pdp->pPrior )
	{
		PTEXT p;
		int moved = 0;

		if( gbTrace )
			xlprintf(LOG_NOISE+1)( WIDE("Relay input from %s to %s..........")
										, GetText( pdp->pPrior->pName )
										, GetText( pdp->pName ) );
		do
		{
			if( pdp->pPrior->Read )
			{
				pdp->pPrior->Read( pdp->pPrior );
			}
			if( IsQueueEmpty( &pdp->pPrior->Input ) )
				break;
			//Log( WIDE("Has some input to handle...") );
			while( ( p = (PTEXT)DequeLink( &pdp->pPrior->Input ) ) )
			{
				if( gbTrace )
					lprintf( WIDE("Data is: %s"), GetText( p ) );
				if( Datacallback && !( ( p->flags & TF_RELAY ) == TF_RELAY ) )
				{
					//lprintf( WIDE("Data callback...") );
					for( p = Datacallback( pdp, p ); p; p = Datacallback( pdp, NULL ) )
					{
						moved++;
						if( p != (POINTER)1 )
							EnqueLink( &pdp->Input, p );
						else
							lprintf( WIDE("Data was consumed by datapath.") );
					}
				}
				else
				{
					 PTEXT out = BuildLine( p );
					 Log1( WIDE("Relay In: %s"), GetText( out ) );
					 LineRelease( out );
					moved++;
					EnqueLink( &pdp->Input, p );
				}
			}
			if( gbTrace && !moved && !pdp->pPrior->flags.Closed )
			{
				lprintf( WIDE("Did not result in data, try reading source again, rerelay. %s %s"), GetText( pdp->pName ), GetText( pdp->pPrior->pName ) );
			}
		  } while( !moved &&
					 !pdp->pPrior->flags.Closed );
		// stop relaying closes at datasource points
		//if( !pdp->pPrior->flags.Data_Source )
		pdp->flags.Closed |= pdp->pPrior->flags.Closed;
		return moved;
	}
	return 0;
}
Exemplo n.º 2
0
CORE_PROC(int, RelayOutput)( PDATAPATH pdp
									, PTEXT (CPROC *Datacallback)( PDATAPATH pdp, PTEXT pLine ) )
{
	extern int gbTrace;
	if( pdp->pPrior )
	{
		int moved = 0;
		PTEXT p;
		//if( gbTrace )
		//	lprintf( WIDE("Relay output from %s to %s..........")
		//			 , GetText( pdp->pName )
		//			 , GetText( pdp->pPrior->pName )
		//			 );
		while( ( p = (PTEXT)DequeLink( &pdp->Output ) ) )
		{
			//if( gbTrace )
			//	lprintf( WIDE("Data is: %s"), GetText( p ) );
			if( Datacallback && !( ( p->flags & TF_RELAY ) == TF_RELAY ) )
			{
				for( p = Datacallback( pdp, p ); p; p = Datacallback( pdp, NULL ) )
				{
					EnqueLink( &pdp->pPrior->Output, p );
				}
			}
			else
			{
#ifdef _DEBUG
				//PTEXT out = BuildLine( p );
				//Log1( WIDE("Relay Out: %s"), GetText( out ) );
				//LineRelease( out );
#endif
				EnqueLink( &pdp->pPrior->Output, p );
			}
		}
		// stop relaying closes at datasource points
		//if( !pdp->pPrior->flags.Data_Source )
		pdp->flags.Closed |= pdp->pPrior->flags.Closed;
		if( pdp->pPrior->Write )
			moved = pdp->pPrior->Write( pdp->pPrior );
		return moved;
	}
	else
	{
		PTEXT p;
		while( ( p = (PTEXT)DequeLink( &pdp->Output ) ) )
		{
			if( gbTrace )
			{
				PTEXT pLine = BuildLine( p );
				lprintf( WIDE("Relay to dev NULL... Data is: %s"), GetText( pLine ) );
				LineRelease( pLine );
			}
			LineRelease( p );
		}
	}
	return 0;
}
Exemplo n.º 3
0
//--------------------------------------
int CPROC PARSE( PSENTIENT ps, PTEXT parameters )
{
	PTEXT temp;
	PTEXT devname;
	if( ( devname = GetParam( ps, &parameters ) ) )
	{
	// find device to see if it's already open...
	// by name!
	// but - this causes a problem for nested scripts
	// which are going to have to be artificiailly inceminated
	// with a unique name maybe something like script_#####
		PDATAPATH pdp = FindOpenDevice( ps, devname );
		if( pdp )
		{
			if( !ps->CurrentMacro )
			{
				PVARTEXT pvt;
				pvt = VarTextCreate();
				vtprintf( pvt, WIDE("Device named %s is already open."), GetText( devname ) );
				EnqueLink( &ps->Command->Output, (POINTER)VarTextGet( pvt ) );
				VarTextDestroy( &pvt );
			}
			return -1;
		}
		if( ( temp = GetParam( ps, &parameters ) ) )
		{
			PDATAPATH pdp;
			lprintf( WIDE("Opening device handle named: %s"), GetText( devname ) );
			if( ( pdp = OpenDevice( &ps->Data, ps, temp, parameters ) ) )
			{
				while( devname->flags & TF_INDIRECT )
					devname = GetIndirect( devname );
				pdp->pName = SegDuplicate( devname );
				if( pdp->Type )
				{
					if( ps->CurrentMacro )
					{
						ps->CurrentMacro->state.flags.bSuccess = TRUE;
					}
				}
				else
				{
					DestroyDataPath( pdp ); // new one did not finish open...
				}
			}
		}
		else
		{
			DECLTEXT( msg, WIDE("Parse must specify a name (/(parse/open) <name> <device> <options...)") );
			EnqueLink( &ps->Command->Output, (PTEXT)&msg );
		}
	}
	return FALSE;
}
Exemplo n.º 4
0
//--------------------------------------
int CPROC CMD_GETPARTIAL( PSENTIENT ps, PTEXT parameters )
{
	if( ps->Data )
	{
		PTEXT pSave, temp;
		pSave = parameters;
		if( ( temp = GetParam( ps, &parameters ) ) )
		{
			if( temp == pSave )
			{
				DECLTEXT( msg, WIDE("Parameter to GetPartial was not a variable reference.") );
				EnqueLink( &ps->Command->Output, &msg );
				return FALSE;
			}

			if( GetIndirect( temp ) )
			{
				LineRelease( GetIndirect( temp ) );
				SetIndirect( temp, NULL );
			}

			if( ps->Data->Partial )
			{
				SetIndirect( temp, ps->Data->Partial );
				ps->Data->Partial = NULL;
				if( ps->CurrentMacro )
					ps->CurrentMacro->state.flags.bSuccess = TRUE;
			}
		}
	}
	 return FALSE;
}
Exemplo n.º 5
0
int KeystrokePaste( PCONSOLE_INFO pdp )
{
    if( OpenClipboard(NULL) )
    {
        uint32_t format;
        // successful open...
        format = EnumClipboardFormats( 0 );
        while( format )
        {
            //DECLTEXT( msg, "                                     " );
            //msg.data.size = sprintf( msg.data.data, "Format: %d", format );
            //EnqueLink( pdp->ps->Command->ppOutput, SegDuplicate( (PTEXT)&msg ) );
#ifndef CF_TEXT
#define CF_TEXT 1
#endif
            if( format == CF_TEXT )
            {
                HANDLE hData = GetClipboardData( CF_TEXT );
                LPVOID pData = GlobalLock( hData );
                PTEXT pStroke = SegCreateFromText( pData );
                int ofs, n;
                GlobalUnlock( hData );
                n = ofs = 0;
                while( pStroke->data.data[n] )
                {
                    pStroke->data.data[ofs] = pStroke->data.data[n];
                    if( pStroke->data.data[n] == '\r' ) // trash extra returns... keep newlines
                    {
                        n++;
                        continue;
                    }
                    else
                    {
                        ofs++;
                        n++;
                    }
                }
                pStroke->data.size = ofs;
                pStroke->data.data[ofs] = pStroke->data.data[n];
                if( PSI_DoStroke( pdp, pStroke ) ) 1;
                //   RenderCommandLine( pdp );
                //EnqueLink( pdp->ps->Command->ppOutput, SegDuplicate(pStroke) );
                LineRelease( pStroke );
                break;
            }
            format = EnumClipboardFormats( format );
        }
        CloseClipboard();
    }
    else
    {
#ifdef __DEKWARE__PLUGIN__
        DECLTEXT( msg, "Clipboard was not available" );
        EnqueLink( &pdp->common.Owner->Command->Output, &msg );
#endif
    }
    return 0;

}
Exemplo n.º 6
0
//--------------------------------------
int CPROC MEMORY( PSENTIENT ps, PTEXT parameters )
{
   uint32_t nFree, nUsed, nChunks, nFreeChunks;
	PVARTEXT vt;
	PTEXT temp, next;
   next = GetParam( ps, &parameters );
	while( temp = next )
	{
		if( temp && TextLike( temp, WIDE("log") ) )
		{
			temp = GetParam( ps, &parameters );
			if( temp && TextLike( temp, WIDE("off") ) )
				SetAllocateLogging( FALSE );
			else
			{
				SetAllocateLogging( TRUE );
				if( temp )
				{
					next = temp;
					continue;
				}
			}
		}
		if( temp && TextLike( temp, WIDE("debug") ) )
		{
			temp = GetParam( ps, &parameters );
			if( temp && TextLike( temp, WIDE("off") ) )
				SetAllocateDebug( TRUE );
			else
			{
				SetAllocateDebug( FALSE );
				if( temp )
				{
					next = temp;
					continue;
				}
			}
		}
      next = GetParam( ps, &parameters );
	}

	GetMemStats( &nFree, &nUsed, &nChunks, &nFreeChunks );

   vt = VarTextCreate( );
   vtprintf( vt, WIDE("Memory : Free %ld(%ld), Used %ld(%ld)  (optional paramters \'log\',\'debug\' followed by off to disable."), nFree, nFreeChunks,
                         nUsed, nChunks - nFreeChunks );
   EnqueLink( &ps->Command->Output, VarTextGet( vt ) );
   VarTextDestroy( &vt );
   return FALSE;
}
Exemplo n.º 7
0
int CPROC CHANGEDIR( PSENTIENT ps, PTEXT parameters )
{
   PTEXT pDir, pDir1;
   pDir1 = MacroDuplicateEx( ps, parameters, TRUE, TRUE );
   if( pDir1 )
      pDir = BuildLine( pDir1 );
   else
      return FALSE;
   LineRelease( pDir1 );
   if( SetCurrentPath( GetText( pDir ) ) )
   {
      if( ps->CurrentMacro )
         ps->CurrentMacro->state.flags.bSuccess = TRUE;
      else
      {
			DECLTEXT( msg, WIDE("Changed directory successfully.") );
			{
            TEXTCHAR buf[257];
				GetCurrentPath( buf, sizeof( buf ) );
				SetDefaultFilePath( buf );
			}
         EnqueLink( &ps->Command->Output, &msg );
      }
   }
   else
   {
      if( !ps->CurrentMacro )
      {
         DECLTEXT( msg, WIDE("Failed to change directory.") );
         EnqueLink( &ps->Command->Output, &msg );
      }
   }
   LineRelease( pDir );

   return FALSE;
}
Exemplo n.º 8
0
int CPROC PRIORITY( PSENTIENT ps, PTEXT parameters )
{
	// Just a note : Thread priority does not work 
	// there are MANY MANY threads involved - so only
	// process priority applies...
#if defined( WIN32 ) || defined( _WIN32 )
	PTEXT pTemp;
   HANDLE hToken, hProcess;
   TOKEN_PRIVILEGES tp;
   OSVERSIONINFO osvi;
   DWORD dwPriority = 0xA5A5A5A5;

   osvi.dwOSVersionInfoSize = sizeof( osvi );
   GetVersionEx( &osvi );
   if( osvi.dwPlatformId  == VER_PLATFORM_WIN32_NT )
   {
      // allow shutdown priviledges....
      // wonder if /shutdown will work wihtout this?
      if( DuplicateHandle( GetCurrentProcess(), GetCurrentProcess()
                        , GetCurrentProcess(), &hProcess, 0
                        , FALSE, DUPLICATE_SAME_ACCESS  ) )
         if( OpenProcessToken( hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken ) )
         {
            tp.PrivilegeCount = 1;
            if( LookupPrivilegeValue( NULL
                                    , SE_SHUTDOWN_NAME
                                    , &tp.Privileges[0].Luid ) )
            {
               tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
               AdjustTokenPrivileges( hToken, FALSE, &tp, 0, NULL, NULL );
            }
            else
               GetLastError();
         }
         else
            GetLastError();
      else
         GetLastError();
   }

	if( ps->CurrentMacro )
      ps->CurrentMacro->state.flags.bSuccess = TRUE;

	pTemp = GetParam( ps, &parameters );
	if( pTemp )
	{
		if( TextLike( pTemp, WIDE("idle") ) )
		{
	      dwPriority = IDLE_PRIORITY_CLASS;
		}
		else if( TextLike( pTemp, WIDE("normal") ) )
		{
	      dwPriority = NORMAL_PRIORITY_CLASS;
		}
		else if( TextLike( pTemp, WIDE("high") ) )
		{
	      dwPriority = HIGH_PRIORITY_CLASS;
		}
		else if( TextLike( pTemp, WIDE("realtime") ) )
		{
	      dwPriority = REALTIME_PRIORITY_CLASS;
		}
		else
		{
			if( !ps->CurrentMacro )
			{
				DECLTEXT( msg, WIDE("Invalid process priority (not idle, normal, high, or realtime)") );
				EnqueLink( &ps->Command->Output, &msg );
			}
			else
			{
		      ps->CurrentMacro->state.flags.bSuccess = FALSE;
			}
		}
	}
	else
	{
		if( !ps->CurrentMacro )
		{
			DECLTEXT( msg, WIDE("No process priority specified (idle,normal,high,realtime)") );
			EnqueLink( &ps->Command->Output, &msg );
		}
		else
		{
		   ps->CurrentMacro->state.flags.bSuccess = FALSE;
		}
	}

	if( dwPriority != 0xA5A5A5A5 )
		SetPriorityClass( GetCurrentProcess(), dwPriority );

	if( !b95 )
	{
		// NT type system we opened these handles
		CloseHandle( hProcess );
		CloseHandle( hToken );
	}
#endif
	return 0;
}
Exemplo n.º 9
0
static PTEXT CPROC ParseCommand( PMYDATAPATH pdp, PTEXT buffer )
{
	if( buffer )
	{
		PTEXT pCommand;
     	//Log2( WIDE("buffer: %s(%d)"), GetText( buffer ), GetTextSize( buffer ) );
     	//LogBinary( buffer );
      pCommand = burst( buffer );
      LineRelease( buffer );
      if( pCommand )
      {
         PTEXT pTemp, pStart;
         int bEscaped = FALSE;
         pStart = pTemp = pCommand;
         while( pTemp )
         {
            if( TextIs( pTemp, WIDE("\\") ) )
            {
               if( !bEscaped )
               {
                  PTEXT pNext;
                  pNext = NEXTLINE( pTemp );
                  pNext->format.position.offset.spaces = pTemp->format.position.offset.spaces;
                  LineRelease( SegGrab( pTemp ) );
                  bEscaped = TRUE;
                  pTemp = pNext;
                  continue;
               }
            }
            if( !bEscaped && TextIs( pTemp, WIDE(";") ) )
            {
               PTEXT pPrior;
	           	//Log( WIDE("Splitting the line and enqueing it...") );
               pPrior = pTemp;
               SegBreak( pTemp );
               if( pStart != pTemp )
               {
               	// end of line included!
               	pStart = SegAppend( pStart, SegCreate(0) ); 
                  EnqueLink( &pdp->output, pStart );
               }
               pStart = pTemp = NEXTLINE( pTemp );
               SegBreak( pTemp );
               LineRelease( pPrior ); // remove ';'
               bEscaped = FALSE;
               continue;
            }
            bEscaped = FALSE;
            pTemp = NEXTLINE( pTemp );
         }
         if( pStart )
         {
         	PTEXT line;
         	line = BuildLine( pStart );
         	//Log1( WIDE("Enqueu: %s"), GetText( line ) );
         	LineRelease( line );
            EnqueLink( &pdp->output, pStart );
         }
      }
      else
      {
         // well what now?  I guess pLine got put into Partial...
         // next pass through this all for command recall will blow...
         Log( WIDE("No information from the burst!") );
      }
	}
	return (PTEXT)DequeLink( &pdp->output );
}
Exemplo n.º 10
0
int CPROC MakeProcess( PSENTIENT ps, PENTITY peInit, PTEXT parameters )
{
	// parameters specify command and parameters to launch...
	// perhaps a working directory? May or may not want it
	// in the current directory...
	// /make process test WIDE("command arguments") WIDE("work path") <attributes?>
	// /make process test WIDE("notepad trigger.txt") 
	PSENTIENT ps2;
	PPROCESS process = New( PROCESS );
	TEXTCHAR MyPath[256];
	GetCurrentPath( MyPath, sizeof( MyPath ) );
	ps2 = CreateAwareness( peInit );
	MemSet( process, 0, sizeof( PROCESS ) );
	Log( WIDE("Have a process, and woke it up... setting the link") );
	SetLink( &peInit->pPlugin, iProcess, process );
	SetLink( &peInit->pDestroy, iProcess, DestroyProcess );
	Log( WIDE("Set the link, getting params...") );
	{
		PTEXT text, cmd = NULL;
		text = GetParam( ps, &parameters );
		if( text && TextIs( text, WIDE("\"") ) )
		{
	      Log( WIDE("Found a quote, getting command line") );
			while( (text = GetParam( ps, &parameters )) && !TextIs( text, WIDE("\"") ) )
			{
				cmd = SegAppend( cmd, SegDuplicate( text ) );
			}
			cmd->format.position.offset.spaces = 0;
			process->command = BuildLine( cmd );
			if( text ) // closed, and may have start path....
			{
				text = GetParam( ps, &parameters );
		   	if( text && TextIs( text, WIDE("\"") ) )
				{
					Log( WIDE("Found a quote, getting the path") );
					while( (text = GetParam( ps, &parameters )) && !TextIs( text, WIDE("\"") ) )
					{
						cmd = SegAppend( cmd, SegDuplicate( text ) );
		   		}
		   		cmd->format.position.offset.spaces = 0;
		   		process->directory = BuildLine( cmd );
				}
			}
		}
		else
		{
			DECLTEXT( msg, WIDE("Must specify process to execute in quotes (\")") );
			EnqueLink( &ps->Command->Output, &msg );
		WakeAThread( ps2 );
			return -1; // abort creation.
		}
	}
	Log2( WIDE("Starting %s in %s"), GetText( process->command ), GetText( process->directory ) );
	process->si.cb = sizeof( process->si );
	// remaining startup info members are NULL - specifying we do NOT care
	// why why when where how the process starts.
	if( StartProcess( process ) )
	{
		DECLTEXTSZ( msg, 256 );
		msg.data.size = snprintf( msg.data.data, 256*sizeof(TEXTCHAR), WIDE("Failed to start \"%s\" in \"%s\" error: %ld"),
										 GetText( process->command ),
										 GetText( process->directory ),
										 GetLastError() );
		EnqueLink( &ps->Command->Output, SegDuplicate( (PTEXT)&msg ) );
		WakeAThread( ps2 );
		return -1; // abort creation.
	}
	// well otherwise would seem we've launched a valid application
	// we have valid process and thread handles to it which can be monitored
	// and well that's about that.
	WakeAThread( ps2 );
	return 0;
}
Exemplo n.º 11
0
int InitImage( PSENTIENT ps, PENTITY pe, PTEXT parameters )
{
	INDEX idx;
	for( idx = 0; idx < NUM_IMAGE_VARS; idx++ )
	{
      PTEXT saveparms = parameters;
		PTEXT arg;
		Image parent = GetLink( &FindContainer( pe )->pPlugin, iImage );
		arg = GetParam( ps, &parameters );
		if( IsNumber( arg ) )
		{
			PTEXT arg2 = GetParam( ps, &parameters );
			if( IsNumber( arg2 ) )
			{
            Image image;
				if( parent )
					image = MakeSubImage( parent
											  , 0, 0 // need other 2 arguments.
											  , atoi( GetText( arg ) )
											  , atoi( GetText( arg2 ) )
											  );
            else
					image = MakeImageFile( atoi( GetText( arg ) )
													, atoi( GetText( arg2 ) ) );
				SetLink( &pe->pPlugin, iImage, image );
				if( ps->CurrentMacro )
					ps->CurrentMacro->state.flags.bSuccess = TRUE;
				else
				{
					DECLTEXT( msg, "Invalid second parameter, expecting a number" );
               EnqueLink( &ps->Command->Output, &msg );
				}
				// if more args - warn?
			}
		}
		else
		{
         Image image;
			// expect that the remainder is a name..
			parameters = saveparms;
			arg = GetFileName( ps, &parameters );
         // loaded image file doesn't care for parent status...
			image = LoadImageFile( GetText( arg ) );
			if( image )
			{
				SetLink( &pe->pPlugin, iImage, image );
				if( ps->CurrentMacro )
					ps->CurrentMacro->state.flags.bSuccess = TRUE;
				else
				{
					DECLTEXT( msg, "Failed to load image..." );
               EnqueLink( &ps->Command->Output, &msg );
				}
			}
		}
		AddVolatileVariable( pe, ImageVars + idx, 0 );
		{
			int n;
			for( n = 0; n < NUM_METHODS; n++ )
            AddMethod( pe, ImageMethods + n );
		}

	}
	return 0; // return success
}
Exemplo n.º 12
0
int GetInputData( int bWord, PSENTIENT ps, PTEXT parameters )
{
	if( ps->Data )
	{
		PTEXT pSave, temp;
		PTEXT *pInd = NULL;
		pSave = parameters;
		lprintf( WIDE("Get data from datapath...") );
		if( !( ( temp = GetParam( ps, &parameters ) ) ) )
		{
			lprintf( WIDE("No parameters specified to get line") );
			LineRelease( ps->pLastResult );
			ps->pLastResult = NULL;
			pInd = &ps->pLastResult;
		}
		else
		{
			if( temp == pSave )
			{
				DECLTEXT( msg, WIDE("is not a valid variable reference.") );
				EnqueLink( &ps->Command->Output, SegAppend( SegDuplicate( temp ), (PTEXT)&msg ) );
				return FALSE;
			}
			if( temp->flags & TF_INDIRECT )
			{
				LineRelease( GetIndirect( temp ) );
				SetIndirect( temp, NULL );
				pInd = (PTEXT*)&temp->data.size;
			}
			else
			{
				DECLTEXT( msg, WIDE("is not a valid variable reference(not indirect).") );
				EnqueLink( &ps->Command->Output, SegAppend( SegDuplicate( temp ), (PTEXT)&msg ) );
				return FALSE;
			}
		}

		if( !pInd )
		{
			DECLTEXT( msg, WIDE("FATAL ERROR: Did not set pInd (GetLine)") );
			EnqueLink( &ps->Command->Output, (PTEXT)&msg );
				return FALSE;
		  }
		// try grabbing an existing line - could be put there from BURST of prior...

		if( !ps->Data->CurrentWord ) // just got last word off line...
		{
			if( ps->Data->CurrentLine )
			{
				LineRelease( ps->Data->CurrentLine );
				ps->Data->CurrentLine = NULL;
			}
		}

		if( !ps->Data->CurrentLine )
		{
			 // Gather Data from input source....
		 // data from HT_CLIENT 'appears' asynchrous
		  // to scripting....
			if( ps->Data->Read )
				ps->Data->Read( ps->Data ); // this returns a completeline...
			ps->Data->CurrentLine = (PTEXT)DequeLink( &ps->Data->Input );
		}

		if( ps->Data->CurrentLine )
			if( !ps->Data->CurrentWord )
				ps->Data->CurrentWord = ps->Data->CurrentLine;

		if( ps->Data->CurrentWord )
		{
			// indirect pointer will be null.
			if( bWord )
			{
				*pInd = SegDuplicate( ps->Data->CurrentWord );
				ps->Data->CurrentWord = NEXTLINE( ps->Data->CurrentWord );
			}
			else
			{
				// duplicate to end of line... which may be whole - or
				// may be partial because of prior GETWORD from the line...
				// then release the data input line...
				// must duplicate the data in either case cause
				// it will be deleted with additional setting of the
				// variable...
					 *pInd = TextDuplicate( ps->Data->CurrentWord, FALSE );
				LineRelease( ps->Data->CurrentWord );
				ps->Data->CurrentLine = NULL; // do NOT release this line...
				ps->Data->CurrentWord = NULL; // no word on line
			}
		}
		if( ps->CurrentMacro && *pInd )
			ps->CurrentMacro->state.flags.bSuccess = TRUE;
	}
	 return FALSE;
}
Exemplo n.º 13
0
//--------------------------------------
int CPROC COMMAND( PSENTIENT ps, PTEXT parameters )
{
	PTEXT temp;
	 PTEXT devname;
	 if( ( devname = GetParam( ps, &parameters ) ) )
	 {
		  // find device to see if it's already open...
		  // by name! 
		  // but - this causes a problem for nested scripts
		  // which are going to have to be artificiailly inceminated
		  // with a unique name maybe something like script_#####
		  PDATAPATH pdp = FindOpenDevice( ps, devname );
		  if( pdp )
		  {
			if( !ps->CurrentMacro )
			{
					 PVARTEXT pvt;
					 pvt = VarTextCreate();
					 vtprintf( pvt, WIDE("Device named %s is already open."), GetText( devname ) );
					 EnqueLink( &ps->Command->Output, (POINTER)VarTextGet( pvt ) );
					 VarTextDestroy( &pvt );
				}
				return -1;
		  }
		 if( ( temp = GetParam( ps, &parameters ) ) )
		  {
			  PDATAPATH pdp;

			  //lprintf( WIDE("Opening device handle named: %s"), GetText( devname ) );
			  if( ( pdp = OpenDevice( &ps->Command, ps, temp, parameters ) ) )
			  {
				  PTEXT pCommand;
				  PDATAPATH pOldPath;
				  while( devname->flags & TF_INDIRECT )
					  devname = GetIndirect( devname );
				  pdp->pName = SegDuplicate( devname );
				  if( ps->Command )
				  {
				  // remove old command queue so close won't remove
				  // ps->Command->Input = NULL;
				  // close the command queue...

				  // update to the new queue in the sentience
				  // if the new one is a data source, then we
				  // need to move old commands to new path -
				  // otherwise they may/will get lost.
					  if( ps->Command->flags.Data_Source
						 && !ps->Command->flags.Dont_Relay_Prior)
								 {
									 pOldPath = ps->Command->pPrior;

												 // move all commands from old queue to new queue
									 while( ( pCommand = (PTEXT)DequeLink( &pOldPath->Input ) ) )
									 {
										 EnqueLink( &ps->Command->Input, pCommand );
									 }

									 while( ( pCommand = (PTEXT)DequeLink( &pOldPath->Output ) ) )
									 {
										 EnqueLink( &ps->Command->Output, pCommand );
									 }
								 }
				  }
				  if( ps->CurrentMacro )
					  ps->CurrentMacro->state.flags.bSuccess = TRUE;
			  }
		  }
		  else
		  {
				DECLTEXT( msg, WIDE("Command must specify a name (/command <name> <device> <options...)") );
				EnqueLink( &ps->Command->Output, (PTEXT)&msg );
		  }
	}
	return FALSE;
}