Example #1
0
void CTunage::PostURL()
{
	if ( wxGetApp().Prefs.sTunageURL == wxT("") )
		return;

	// create a valid URL
	wxString urltext( wxGetApp().Prefs.sTunageURL );
	ParseTags( urltext );
	urltext = wxURL::ConvertToValidURI( urltext );
	wxURL url( urltext );
	
	if ( url.GetError() != wxURL_NOERR )
	{
		wxMessageBox( wxT("Could not parse Tunage URL"), wxT("Tunage error"), wxOK | wxICON_WARNING );
		
		return;
	}

	// connect to URL
	wxYield();
	wxInputStream *data = url.GetInputStream();
	if ( !data )
	{
		wxMessageBox( wxT("Could not access URL"), wxT("Tunage error"), wxOK | wxICON_WARNING );
	}

	delete data;



}
Example #2
0
void CTunage::WriteFile()
{
	if ( ( wxGetApp().Prefs.sTunageFilename == wxT("") ) || ( wxGetApp().Prefs.sTunageFileLine == wxT("") ) )
		return;

	if ( !wxGetApp().Prefs.bTunageAppendFile )
	{
		if ( wxFileExists( wxGetApp().Prefs.sTunageFilename ) )
			wxRemoveFile( wxGetApp().Prefs.sTunageFilename );
	}

	wxTextFile Out;	
	Out.Create( wxGetApp().Prefs.sTunageFilename );
	Out.Open();

	if ( !Out.IsOpened() )
		return;

	wxString line( wxGetApp().Prefs.sTunageFileLine );
	ParseTags( line );

	Out.AddLine( line );
	Out.Write( Out.GuessType() );
	Out.Close();
}
Example #3
0
void CTunage::RunApp()
{
	if ( wxGetApp().Prefs.sTunageCmdLine == wxT("") )
		return;

	wxString cmd( wxGetApp().Prefs.sTunageCmdLine );
	ParseTags( cmd );

	wxExecute( cmd );
}
BOOL CEventPropertiesFireTriggerDialog::HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	m_hDialog = hwndDlg;

	bool handled = false;
	BOOL bret = InternalHandleMessage( &g_Params, hwndDlg, uMsg, wParam, lParam, handled );
	if ( handled )
		return bret;

	switch(uMsg)
	{
	case WM_PAINT:
		{
			PAINTSTRUCT ps; 
			HDC hdc;
			
            hdc = BeginPaint(hwndDlg, &ps); 
			DrawSpline( hdc, GetControl( IDC_STATIC_SPLINE ), g_Params.m_pEvent );
            EndPaint(hwndDlg, &ps); 

            return FALSE; 
		}
		break;
	case WM_VSCROLL:
		{
			RECT rcOut;
			GetSplineRect( GetControl( IDC_STATIC_SPLINE ), rcOut );

			InvalidateRect( hwndDlg, &rcOut, TRUE );
			UpdateWindow( hwndDlg );
			return FALSE;
		}
		break;
    case WM_INITDIALOG:
		{
			InitDialog( hwndDlg );
		}
		return FALSE;  
		
    case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDOK:
			{
				HWND control = GetControl( IDC_EVENTCHOICES );
				if ( control )
				{
					SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
				}
				GetDlgItemText( m_hDialog, IDC_EVENTNAME, g_Params.m_szName, sizeof( g_Params.m_szName ) );

				if ( !g_Params.m_szName[ 0 ] )
				{
					Q_snprintf( g_Params.m_szName, sizeof( g_Params.m_szName ), "Firetrigger %s", g_Params.m_szParameters );
				}

				char szTime[ 32 ];
				GetDlgItemText( m_hDialog, IDC_STARTTIME, szTime, sizeof( szTime ) );
				g_Params.m_flStartTime = atof( szTime );
				GetDlgItemText( m_hDialog, IDC_ENDTIME, szTime, sizeof( szTime ) );
				g_Params.m_flEndTime = atof( szTime );

				// Parse tokens from tags
				ParseTags( &g_Params );

				EndDialog( hwndDlg, 1 );
			}
			break;
        case IDCANCEL:
			EndDialog( hwndDlg, 0 );
			break;
		case IDC_CHECK_ENDTIME:
			{
				g_Params.m_bHasEndTime = SendMessage( GetControl( IDC_CHECK_ENDTIME ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
				if ( !g_Params.m_bHasEndTime )
				{
					ShowWindow( GetControl( IDC_ENDTIME ), SW_HIDE );
				}
				else
				{
					ShowWindow( GetControl( IDC_ENDTIME ), SW_RESTORE );
				}
			}
			break;
		case IDC_CHECK_RESUMECONDITION:
			{
				g_Params.m_bResumeCondition = SendMessage( GetControl( IDC_CHECK_RESUMECONDITION ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
			}
			break;
		case IDC_EVENTCHOICES:
			{
				HWND control = (HWND)lParam;
				if ( control )
				{
					SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
				}
			}
			break;
		case IDC_ABSOLUTESTART:
			{
				g_Params.m_bUsesTag = false;
				UpdateTagRadioButtons( &g_Params );
			}
			break;
		case IDC_RELATIVESTART:
			{
				g_Params.m_bUsesTag = true;
				UpdateTagRadioButtons( &g_Params );
			}
			break;
		}
		return TRUE;
	}
	return FALSE;
}
Example #5
0
int Parser::Parse()
{
	Tag *tagList;
	TypeDecl *typeDecl;
	Statement *stmt;


	// keep going until there are no more tokens!
	while(t)
	{
		TOKEN allowed[] = 
		{ 
			TOK_LENGTHIS, TOK_SIZEIS, TOK_IGNORE, TOK_STRING,
			TOK_OFFSET, TOK_ALIGN, TOK_BITFLAG, TOK_STYLE, TOK_DISPLAY,
			TOK_ENDIAN,	TOK_SWITCHIS, TOK_CASE, TOK_NAME, 
			TOK_ENUM, TOK_EXPORT, TOK_ASSOC,
			TOK_NULL 

		};

		// save any whitespace before the tags
		FILEREF fileRef;
		lex_fileref(&fileRef);

		if(!ParseTags(&tagList, allowed))
			return 0;
		
		//
		//	Decide what kind of statement/construct we need to parse 
		//
		switch(t)
		{
		case TOK_INCLUDE:
			
			// include-statement (not the same as #include which
			// is a C-preprocessor thing)
			if((stmt = ParseInclude()) == 0)
			{
				return 0;
			}

			curFile->stmtList.push_back(stmt);

			break;

		default:

			size_t s1 = globalFileHistory.size();

			// anything else must be a type-declaration
			if((typeDecl = ParseTypeDecl(tagList, globalIdentifierList, false, true)) == 0)
				return 0;

			size_t s2 = globalFileHistory.size();


			// store in the global list
			typeDecl->fileRef = fileRef;
			globalTypeDeclList.push_back(typeDecl);

			//curFile->typeDeclList.push_back(typeDecl);

			curFile->stmtList.push_back(new Statement(typeDecl));

			// every type-declaration must end with a ';'
			if(!Expected(';'))
				return 0;

			// record any whitespace that appears after the type-decl
			lex_fileref(&typeDecl->postRef);
			 
			break;
		}
	}

	ExportStructs();

	return (errcount == 0) ? 1 : 0;
}
Example #6
0
// Parse file - returns 0 if successful
int LicutSVG::Parse( const char *svgPath )
{
	FILE *f = fopen( svgPath, "r" );
	if (!f)
	{
		printf( "Failed to open %s (errno=%d: %s)\n", svgPath, errno, strerror(errno) );
		return -1;
	}
	struct stat fileInfo;
	if (0 != fstat( fileno(f), &fileInfo ))
	{
		printf( "Failed to get size of %s (errno=%d: %s)\n", svgPath, errno, strerror(errno) );
		fclose( f );
		return -1;
	}
	// If size is greater than the process stack limit we'll get a stack overflow fault
	// here. Use malloc / free if over 1mb *FIXME*
	if (fileInfo.st_size < 1  || fileInfo.st_size > 0x10000)
	{
		printf( "Invalid file size %lu for %s - must be > 0 and <= 1mb\n", fileInfo.st_size, svgPath );
		fclose( f );
		return -1;
	}
	char *data = (char *)alloca( fileInfo.st_size + 1 );
	size_t bytesRead = fread( data, sizeof(char), fileInfo.st_size, f );
	if (bytesRead < fileInfo.st_size)
	{
		printf( "Failed to read contents of %s (%lu requested, %d read, errno=%d: %s)\n",
			svgPath, fileInfo.st_size, bytesRead, errno, strerror(errno) );
		fclose( f );
		return -1;
	}

	fclose( f );

	// NULL-terminate it
	data[bytesRead] = '\0';

	int success = -1;

	/****
	Simple state machine parser
	This is a simplistic, tiny xml parser which doesn't handle CDATA or escapes
	It operates destructively on data, parsing recursively from the outside in
	and setting the end of each tag (</{tagname}> or /> or --> or ?>) to '\0'
	Also null-terminates the name of each tag
	Limited to tag identification for 1024 levels
	****/
	char * tagStack[1024];
	tagStack[0] = (char *)"";
	int stackLevel = 0;
	char * tagData = data;

	if (ParseTags( tagData, stackLevel, tagStack, false ) >= 1)
	{
		success = 0;
	}
	else
	{
		printf( "Did not parse any tags!\n" );
	}

	return success;
}
Example #7
0
// Parse a single node tag recursively at the current level
// Returns 1 if parsed or 0 if not a tag
int LicutSVG::ParseTag( char *& s, int stackLevel, char *tagStack[1024], bool ignore )
{
	if (!*s) return 0;
	// Skip leading whitespace
	s += strspn( s, " \t\r\n" );
	if (!*s) return 0;
	// Expected: <tag, <!-- or <?
	if (s[0] != '<')
	{
		printf( "%s() level %d - unexpected character %c\n", __FUNCTION__, stackLevel, *s );
		if (s[0]) s++;
		return 0;
	}

	int gotTag = 0;

	// Ignore comments
	if (s[1] == '!' && s[2] == '-' && s[3] == '-')
	{
		if (m_verbose) printf( "Skipping comment [%s]\n", _fmt_sample( s, 6 ) );
		char *end = strstr( s, "-->" );
		if (end)
		{
			s = &end[3];
		}
		else
		{
			s += strlen( s );
		}
	}
	// Ignore directives
	else if (s[1] == '?')
	{
		char *end = strstr( s, "?>" );
		if (end)
		{
			if (m_verbose)
			{
				printf( "Got directive [%s]...", _fmt_sample( s, 6 ) );
				printf( "%s\n", _fmt_sample( &end[-4], 5 ) );
			}
			s = &end[2];
		}
		else
		{
			printf( "Unexpected missing end for [%s]\n", _fmt_sample( s, 4 ) );
			s += strlen( s );
		}
	}
	else
	{
		gotTag = 1;
		// Get tag name
		char *tagName = &s[1];
		tagName += strspn( tagName, " \t\r\n" );
		// Name ends in whitespace or end of tag
		s = &tagName[strcspn( tagName, "/> \t\r\n" )];
		bool foundEnd = false;
		bool closedTag = false; // tag ends with />
		char *tagEnd;
		char *tagNext = NULL;
		if (*s == '/')
		{
			foundEnd = true;
			closedTag = true;
			tagEnd = &s[1];
			tagEnd += strspn( tagEnd, " \t\r\n" );
			tagNext = &tagEnd[1];
		}
		else if (*s == '>')
		{
			foundEnd = true;
			tagEnd = s;
			tagNext = &tagEnd[1];
		}
		// Terminate name
		*s = '\0';
		if (m_verbose) printf( "Tag: %s end:%c closed:%c\n", tagName, foundEnd?'Y' : 'n', closedTag ? 'Y' : 'n' );
		// Find end of tag
		if (!foundEnd)
		{
			s++;
			int attrCount = 0;
			int attrWithValueCount = 0;
			if (m_verbose) printf( "Searching for end starting %s\n", _fmt_sample( s, 4 ) );
			while (*s != '/' && *s != '>' && *s)
			{
				// Parse attribute [ = "value" ]
				s += strspn( s, " \t\r\n" );
				if (*s == '/' || *s == '>') break;
				char *attrName = s;
				int attrNameLength = strcspn( attrName, "= \t\r\n" );
				s += attrNameLength;
				s += strspn( s, " \t\r\n" );
				attrCount++;
				char *attrValue = NULL;
				// Check for value
				if (*s == '=')
				{
					attrWithValueCount++;
					s++;
					s += strspn( s, " \t\r\n" );
					// Unquoted values are not kosher but we'll parse them anyway
					if (*s == '"')
					{
						s++;
						attrValue = s;
						s += strcspn( s, "\"" );
						*s = '\0';
						s++;
					}
					else
					{
						attrValue = s;
						s += strcspn( s, " \t\r\n" );
						*s = '\0';
						s++;				
					}
				}
			
				attrName[attrNameLength] = '\0';

				if (m_verbose) printf( "  [%d] %s=%s\n", attrCount, attrName, attrValue );
				if (!strcmp( tagName, "svg" ))
				{
					if (!strcmp( attrName, "width" ))
					{
						printf( "svg width=%s\n", attrValue );
						m_width = atoi( attrValue );
					}
					else if (!strcmp( attrName, "height" ))
					{
						printf( "svg height=%s\n", attrValue );
						m_height = atoi( attrValue );
					}
				}
				if (!ignore && !strcmp( tagName, "g" ))
				{
					if (!strcmp( attrName, "id" ) && attrValue != NULL)
					{
						// FIXME if we wanted to use some layers as guide, the id or label could be 
						// configurable
						printf( "layer id=%s\n", attrValue );
					}
				}
				if (!ignore && !strcmp( tagName, "path" ))
				{
					if (!strcmp( attrName, "d" ) && attrValue != NULL)
					{
						int setsParsed = ParseDrawList( attrValue );
						printf( "path d len=%d sets=%d\n", strlen(attrValue), setsParsed );
					}
				}
			}
			if (m_verbose) printf( "Exited attr parse [%s]\n", _fmt_sample( s, 4 ) );
			// Complain if end not found
			if (*s == '>')
			{
				if (m_verbose) printf( "Got end > [%s]\n", _fmt_sample( s, 4 ) );
				foundEnd = true;
				tagNext = &s[1];
			}
			else if (*s == '/')
			{
				if (m_verbose) printf( "Got end /> [%s]\n", _fmt_sample( s, 4 ) );
				foundEnd = true;
				closedTag = true;
				tagNext = &s[1];
				tagNext += strspn( tagNext, " \t\r\n" );
				s = tagNext;
				tagNext++;
			}
			else
			{
				printf( "Error: tag %s is not properly closed, ends with [%s]\n", tagName, _fmt_sample( s, 4 ) );
				if (!*s) s++;
			}
		}
		// Recurse into container tag
		if (foundEnd && !closedTag)
		{
			// Skip > from end of tag opening
			// If we have a tag with no attributes, we may already have NUL
			if (*s == '>' || *s == '\0') s++;
			// Skip quoted values and find </tagname>
			if (m_verbose) printf( "Searching for end of tag %s in %s\n", tagName, _fmt_sample( s, 8 ) );
			char *containerStart = s;
			char *containerEnd = s;
			bool foundContainerEnd = false;
			while (!foundContainerEnd && containerEnd != NULL)
			{
				containerEnd = strpbrk( containerEnd, "\"<" );
				if (!containerEnd) break;
				if (*containerEnd == '"')
				{
					containerEnd = strchr( &containerEnd[1], '"' );
					if (containerEnd == NULL) break;
					containerEnd++;
				}
				else
				{
					char *containerEndTagStart = containerEnd;
					containerEnd++;
					if (*containerEnd == '/')
					{
						containerEnd++;
						int closeLength = strcspn( containerEnd, "> \t\r\n" );
						if (closeLength == strlen( tagName ) && !strncmp( containerEnd, tagName, closeLength ))
						{
							foundEnd = true;
							foundContainerEnd = true;
							tagNext = &containerEnd[closeLength];
							tagNext += strspn( tagNext, " \t\r\n" );
							// Skip final >
							tagNext++;
							*containerEndTagStart = '\0';
						}
					}
				}
			}
			if (foundContainerEnd)
			{
				// containerStart is null-terminated
				if (stackLevel >= 1023)
				{
					printf( "Error: cannot parse %s at level %d - stack overflow\n", tagName, stackLevel );
				}
				else
				{
					// If container starts with something other than <, treat it as an immediate value
					char *valueCandidate = containerStart;
					valueCandidate += strspn( valueCandidate, " \t\r\n" );
					if (*valueCandidate != '<')
					{
						if (m_verbose) printf( "Got tag enclosed value [%s]\n", valueCandidate );
					}
					else
					{
						stackLevel++;
						tagStack[stackLevel] = tagName;
						if (m_verbose) printf( "Entering level %d container tag %s [%s]\n", stackLevel, tagName, _fmt_sample( containerStart, 4 ) );
						ParseTags( containerStart, stackLevel, tagStack, ignore );
						stackLevel--;
						if (m_verbose) printf( "Returned to level %d tag %s\n", stackLevel, tagName );
					}
				}
			}
			else
			{
				printf( "Did not find container end\n" );
			}
		} // Found container tag
		// Skip to next tag
		if (tagNext != NULL)
		{
			s = tagNext;
			if (m_verbose) 
			{
				printf( "Ending parse with [%s] - ", _fmt_sample( &s[-4], 4 ) );
				printf( "next [%s]\n", _fmt_sample( s, 4 ) );
			}
		}
		// else parsing error occurred
		else
		{
			printf( "Parsing error occurred, no next tag\n" );
		}
	}

	// Skip trailing whitespace
	if (*s) s += strspn( s, " \t\r\n" );

	if (m_verbose) printf( "exiting %s() returning %d\n", __FUNCTION__, gotTag );

	return gotTag;
}