コード例 #1
0
ファイル: checker.c プロジェクト: ErisBlastar/osfree
int chkr_PDC_getclipboard(char **contents, long *length)
{
   int rc;

   stubs_chkr_check_addr(contents, sizeof (char **), CHKR_MW, "contents");
   stubs_chkr_check_addr(length, sizeof (long *), CHKR_MW, "length");
   if ((rc = PDC_getclipboard(contents,length)) == PDC_CLIP_SUCCESS)
      stubs_chkr_set_right(*contents, *length, CHKR_RW);
   return(rc);
}
コード例 #2
0
ファイル: testcurs.c プロジェクト: Bill-Gray/PDCurses
void clipboardTest(WINDOW *win)
{
    static const char *text =
        "This string placed in clipboard by PDCurses test program, testcurs.";
    char *ptr = NULL;
    long i, length = 0;

    mvaddstr(1, 1,
             "This test will display the contents of the system clipboard");

    Continue2();

    scrollok(stdscr, TRUE);
    i = PDC_getclipboard(&ptr, &length);

    switch(i)
    {
    case PDC_CLIP_ACCESS_ERROR:
        mvaddstr(3, 1, "There was an error accessing the clipboard");
        refresh();
        break;

    case PDC_CLIP_MEMORY_ERROR:
        mvaddstr(3, 1,
            "Unable to allocate memory for clipboard contents");
        break;

    case PDC_CLIP_EMPTY:
        mvaddstr(3, 1, "There was no text in the clipboard");
        break;

    default:
        wsetscrreg(stdscr, 0, LINES - 1);
        clear();
        mvaddstr(1, 1, "Clipboard contents...");
        mvprintw(2, 1, "%s\n", ptr);
    }

    Continue2();

    clear();
    mvaddstr(1, 1,
        "This test will place the following string in the system clipboard:");
    mvaddstr(2, 1, text);

    i = PDC_setclipboard(text, strlen(text));

    switch(i)
    {
    case PDC_CLIP_ACCESS_ERROR:
        mvaddstr(3, 1, "There was an error accessing the clipboard");
        break;

    case PDC_CLIP_MEMORY_ERROR:
        mvaddstr(3, 1, "Unable to allocate memory for clipboard contents");
        break;

    default:
        mvaddstr(3, 1, "The string was placed in the clipboard successfully");
    }

    Continue2();
}
コード例 #3
0
ファイル: ccbot.cpp プロジェクト: Danteoriginal/ccbot
int main( )
{
	// seed the RNG
	
	srand( (unsigned int) time( NULL ) );
	
	// check if the log folder exists
	
	if( !UTIL_FileExists( "log" ) )
	{
#ifdef WIN32
		CreateDirectoryA( "log", NULL );
#else
		system( "mkdir log" );
		system( "chmod 777 log" );
#endif
	}
	
	// check if the cfg folder exists
	
	if( !UTIL_FileExists( "cfg" ) )
	{
#ifdef WIN32
		CreateDirectoryA( "cfg", NULL );
#else
		system( "mkdir cfg" );
		system( "chmod 777 cfg" );
#endif
	}
	
	// read config file

	CConfig CFG;
	CFG.Read( CFGFile );
	gLog = CFG.GetInt( "bot_log", 1 ) == 0 ? false : true;
	
	// catch SIGABRT and SIGINT

	signal( SIGABRT, SignalCatcher );
	signal( SIGINT, SignalCatcher );

#ifndef WIN32
	// disable SIGPIPE since some systems like OS X don't define MSG_NOSIGNAL

	signal( SIGPIPE, SIG_IGN );
#endif

	// initialize curses

	gCurses = true;
	initscr( );
#ifdef WIN32
	resize_term( 28, 97 );
#endif
	clear( );
	noecho( );
	cbreak( );
	gMainWindow = newwin( LINES - 3, COLS - 17, 0, 0 );
	gBottomBorder = newwin( 1, COLS, LINES - 3, 0 );
	gRightBorder = newwin( LINES - 3, 1, 0, COLS - 17 );
	gInputWindow = newwin( 2, COLS, LINES - 2, 0 );
	gChannelWindow = newwin( LINES - 3, 16, 0, COLS - 16 );
	mvwhline( gBottomBorder, 0, 0, 0, COLS );
	mvwvline( gRightBorder, 0, 0, 0, LINES );
	wrefresh( gBottomBorder );
	wrefresh( gRightBorder );
	scrollok( gMainWindow, TRUE );
	keypad( gInputWindow, TRUE );
	scrollok( gInputWindow, TRUE );
	CONSOLE_Draw( );
	nodelay( gInputWindow, TRUE );	
	
	// print something for logging purposes

	CONSOLE_Print( "[CCBOT] starting up" );

#ifdef WIN32

	// increase process priority

	CONSOLE_Print( "[CCBOT] setting process priority to \"high\"" );
	SetPriorityClass( GetCurrentProcess( ), HIGH_PRIORITY_CLASS );

	// initialize winsock

	CONSOLE_Print( "[CCBOT] starting winsock" );
	WSADATA wsadata;

	if( WSAStartup( MAKEWORD( 2, 2 ), &wsadata ) != 0 )
	{
		CONSOLE_Print( "[CCBOT] error starting winsock" );
		return 1;
	}
#endif

	// initialize ccbot

	gCCBot = new CCCBot( &CFG );

	while( true )
	{
		// block for 50ms on all sockets - if you intend to perform any timed actions more frequently you should change this
		// that said it's likely we'll loop more often than this due to there being data waiting on one of the sockets but there aren't any guarantees

		if( gCCBot->Update( ) )
			break;

		bool Quit = false;
		int c = wgetch( gInputWindow );
		
		while( c != ERR )
		{ 
			if( c == 8 || c == 127 || c == KEY_BACKSPACE || c == KEY_DC )
			{
				// Backspace, Delete

				if( !gInputBuffer.empty( ) )
					gInputBuffer.erase( gInputBuffer.size( ) - 1, 1 );
			}
			else if( c == 9 )
			{
				// Tab
			}
#ifdef WIN32
			else if( c == 10 || c == 13 || c == PADENTER )
#else
			else if( c == 10 || c == 13 )
#endif
			{
				// CR, LF
				// process input buffer now

				string Command = gInputBuffer;

				if( Command[0] == gCCBot->m_BNETs[0]->GetCommandTrigger( ) )
				{
					CONSOLE_Print( "[CONSOLE] " + Command );
					
					CIncomingChatEvent event = CIncomingChatEvent( CBNETProtocol :: CONSOLE_INPUT, 0, 0, gCCBot->m_BNETs[0]->GetRootAdmin( ), Command );
					gCCBot->m_BNETs[0]->ProcessChatEvent( &event );
				}
				else
					gCCBot->m_BNETs[0]->QueueChatCommand( Command, false );				

				gInputBuffer.clear( );
			}
#ifdef WIN32
			else if( c == 22 )
			{
				// Paste

				char *clipboard = NULL;
				long length = 0;

				if( PDC_getclipboard( &clipboard, &length ) == PDC_CLIP_SUCCESS )
				{
					gInputBuffer += string( clipboard, length );
					PDC_freeclipboard( clipboard );
				}
			}
#endif
			else if( c == 27 )
			{
				// Escape button

				gInputBuffer.clear( );
			}
			else if( c >= 32 && c <= 255 )
			{
				// Printable characters

				gInputBuffer.push_back( c );
			}
#ifdef WIN32
			else if( c == PADSLASH )
				gInputBuffer.push_back( '/' );
			else if( c == PADSTAR )
				gInputBuffer.push_back( '*' );
			else if( c == PADMINUS )
				gInputBuffer.push_back( '-' );
			else if( c == PADPLUS )
				gInputBuffer.push_back( '+' );
#endif
			else if( c == KEY_RESIZE )
				CONSOLE_Resize( );

			// clamp input buffer size

			if( gInputBuffer.size( ) > 200 )
				gInputBuffer.erase( 200 );

			c = wgetch( gInputWindow );
			gInputWindowChanged = true;
		}

		CONSOLE_Draw( );

		if( Quit )
			break;
	}

	// shutdown ghost

	CONSOLE_Print( "[CCBOT] shutting down" );
	delete gCCBot;
	gCCBot = NULL;

#ifdef WIN32
	// shutdown winsock

	CONSOLE_Print( "[CCBOT] shutting down winsock" );
	WSACleanup( );
#endif

	// shutdown curses

	endwin( );
	
	if( gRestart )
	{
#ifdef WIN32
	_spawnl( _P_OVERLAY, "ccbot.exe", "ccbot.exe", NULL );
#else		
	execl( "ccbot++", "ccbot++", NULL );				
#endif
	}

	return 0;
}
コード例 #4
0
ファイル: widget.cpp プロジェクト: ProDotaTrY/ghostcb
void CTextEdit::update(int c)
{
	if(_visible)
	{
		bool alwaysFocused = false;
#ifdef NO_MOUSE
		alwaysfocused = true; // If we have no mouse, we can't focus widgets so let's have it always focused.
#endif

		if((_requireFocused ? focused() : true) && (_parent ? _parent->focused() || alwaysFocused : true))
		{
			switch(c)
			{
			case ERR:
				break;
#ifdef __PDCURSES__
			case 3: // copy
				{
					string clipboard = UTIL_Latin1ToUTF8(_text);
					PDC_setclipboard(clipboard.c_str(), clipboard.length());
					break;
				}
			case 22: // paste
				{
					char *clipboard = NULL;
					long length = 0;

					if(PDC_getclipboard(&clipboard, &length) == PDC_CLIP_SUCCESS)
					{
						_text += string(clipboard, length);
						PDC_freeclipboard(clipboard);
					}
					break;
				}
#endif
			case KEY_UP:
				if(!_history.empty())
				{
					if(_selectedHistory > 0)
						_text = _history[--_selectedHistory];
					else if(_selectedHistory == 0)
						_text = _history[0];
				}
				break;
			case KEY_DOWN:
				if(!_history.empty())
				{
					if(_selectedHistory < _history.size() - 1)
						_text = _history[++_selectedHistory];
					else if(_selectedHistory == _history.size() - 1)
						_text = _history[_history.size() - 1];
				}
				break;
			case 8:
			case 127:
			case KEY_BACKSPACE:
			case KEY_DC:
				if(!_text.empty())
					_text.erase(_text.end() - 1);
				break;
			case 27:
				_text.clear();
				break;
			case 10:
			case 13:
#ifdef WIN32
			case PADENTER:
#endif
				if(!_text.empty())
				{
					_history.push_back(_text);
					_selectedHistory = _history.size();
					forward( new CFwdData(_fwdTypeEnter, _text, 0 ));
					_text.clear();
				}
				break;
#ifdef WIN32
			case PADSLASH:
				_text += '/';
				break;
			case PADSTAR:
				_text += '*';
				break;
			case PADMINUS:
				_text += '-';
				break;
			case PADPLUS:
				_text += '+';
				break;
#endif
			default:
				if(c >= 32 && c <= 255)
					_text += c;
				break;
			}
		}

		if(c != ERR)
		{
			move_panel(_panel, _pos.y(), _pos.x());
			top_panel(_panel);
			wclear(_window);

			string temp = UTIL_Latin1ToUTF8(_text);

			// print text
			mvwaddstr(_window, 0, 0, temp.c_str());
		}
	}
}