Beispiel #1
0
/*
** return TRUE if event applies to pszAsset
*/
BOOL CEventDef::CheckAsset (LPCSTR pszAsset) const
{
	// no assets specified means ANY
	if (m_strAssets.IsEmpty())
		return TRUE;
	// else parse the list of included assets
	CString strBuffer(m_strAssets);
	CString strThisOne = BreakString(strBuffer, '\t', TRUE);
	while (strThisOne.GetLength())
	{
		if (0 == strThisOne.CompareNoCase(pszAsset))
			return TRUE;
		strThisOne = BreakString(strBuffer, '\t', TRUE);
	}
	return FALSE;
}
	int ScanLine( const char *tag, T& t )
	{
		std::vector<std::string> strings;
		BreakString( strings, m_acCurrentLine );
		if( strings.size() <= 1 )
			return 0;

		int index = 1;
		conv_to_x( strings, index, t );
		return index - 1;
	}
	int ScanLine( const char *tag, T0& t0, T1& t1, T2& t2, T3& t3 )
	{
		std::vector<std::string> strings;
		BreakString( strings, m_acCurrentLine );
		if( strings.size() <= 1 )
			return 0;

		int index = 1;
		conv_to_x( strings, index, t0 );
		conv_to_x( strings, index, t1 );
		conv_to_x( strings, index, t2 );
		conv_to_x( strings, index, t3 );
		return index - 1;
	}
Beispiel #4
0
// breaks given text into smaller 'maxChar' length strings and
// displays them as unselectable text on OSD
void cOsdMenu::AddFloatingText(const char* text, int maxChars)
{
	// empty string; display nothing
	if(!text) return;

	char *p = NULL;
	int copied = 0;

	//printf("\tFloating Text (%i): '%s'\n", maxChars, text);
	while(*text)
	{
		// returns a pointer to a char string with atmost maxChars characters (not bytes)
		// p has to be freed; p is NULL if text was null
		p = BreakString(text, maxChars, copied);
		text += copied; //jump bytes not chars
		if(p)
		{
			Add(new cOsdItem(p, osUnknown,false)); // unselectable text
			free(p); p = NULL;
		}
	}
}
//
//    GetRegValue
//    ===========
//
//    Recover a value from the system registry
//
CString CLocaleScanner::GetRegValue (LPCSTR pszRegKey, LPCSTR pszRegItem)
{
	CString strResult;

	// work out which "hive" to access
	CString strRegKey(pszRegKey);
	CString strHive = BreakString(strRegKey, '\\');
	HKEY hkHive = NULL, hkSubKey;
	if (strHive == "HKEY_CLASSES_ROOT")
		hkHive = HKEY_CLASSES_ROOT;
	if (strHive == "HKEY_CURRENT_CONFIG")
		hkHive = HKEY_CURRENT_CONFIG;
	if (strHive == "HKEY_CURRENT_USER")
		hkHive = HKEY_CURRENT_USER;
	if (strHive == "HKEY_LOCAL_MACHINE")
		hkHive = HKEY_LOCAL_MACHINE;
	if (strHive == "HKEY_USERS")
		hkHive = HKEY_USERS;

	if (hkHive)
	{
		int nStatus = RegOpenKeyEx(hkHive, strRegKey, 0, KEY_QUERY_VALUE, &hkSubKey);
		if (nStatus == ERROR_SUCCESS)
		{
			// key opened ok - look for matching item
			DWORD dwIndex = 0;
			unsigned char szThisRegValue[1024];
			DWORD dwType;
			DWORD dwRegValueLen = sizeof(szThisRegValue);

			int nStatus = RegQueryValueEx(hkSubKey ,pszRegItem ,NULL ,&dwType ,szThisRegValue ,&dwRegValueLen);
			if (nStatus == ERROR_SUCCESS)
			{
				// FOUND IT - sort out the type conversion
				switch (dwType)
				{
					case REG_BINARY:
						{
							// write as a sequence of hex values
							for (DWORD dw = 0 ; dw < dwRegValueLen ; dw++)
							{
								BYTE b = szThisRegValue[dw];
								CString strThisBit;
								strThisBit.Format("%2.2X ", b);
								strResult += strThisBit;
							}
							strResult.TrimRight();
						}
						break;

					case REG_DWORD:
//					case REG_DWORD_LITTLE_ENDIAN:
						strResult.Format("%d", *((LPDWORD)szThisRegValue));
						break;
						
					case REG_SZ:
						strResult = szThisRegValue;
						break;

					case REG_EXPAND_SZ:
						{
							char szBuffer[1024];
							ExpandEnvironmentStrings ((LPCSTR)szThisRegValue, szBuffer, sizeof(szBuffer));
							strResult = szBuffer;
						}
						break;

					case REG_MULTI_SZ:
						{
							for (char * p = (LPSTR)szThisRegValue ; *p != NULL ; p += strlen(p) + 1)
							{
								if (strResult.GetLength())
									strResult += ';';
								strResult += p;
							}
						}
						break;

					case REG_DWORD_BIG_ENDIAN:
					case REG_LINK:
					case REG_NONE:
//					case REG_QWORD:
//					case REG_QWORD_LITTLE_ENDIAN:
					case REG_RESOURCE_LIST:
					default:
						strResult.Format("Unsupported Registry Data Type %d", dwType);
						break;
				}
			}
		}
		RegCloseKey(hkSubKey);
	
	
	}
	return strResult;
}
Beispiel #6
0
bool	XObjRead(const char * inFile, XObj& outObj)
{
	vector<string>	tokens;
	string			ascii, vers, tag, line;
	int				cmd_id, count, obj2_op;
	int				version = 1;
	vec_tex			vst;
	vec_rgb			vrgb;
	
	float scanned_st_rgb[4][3]={0,0,0 , 0,0,0,// [corner][color or st]
                               0,0,0 , 0,0,0};	
	
	outObj.cmds.clear();

	/*********************************************************************
	 * READ HEADER
	 *********************************************************************/
	 
	StTextFileScanner	f(inFile, true);
	if (f.done()) return false;

	// First we should have some kind of token telling us whether we're Mac or PC
	// line endings.  But we don't care that much.
	line = f.get();
	BreakString(line, tokens);
	if (tokens.empty()) return false;
	ascii = tokens[0];
	f.next();
	if (f.done()) return false;
	
	// Read the version string.  We expect either '2' or '700'.
	line = f.get();
	
	BreakString(line, tokens);
	if (tokens.empty()) return false;
	vers = tokens[0];
	f.next();
	if (f.done()) return false;	

		 if (vers == "700") version = 7;
	else if (vers == "2"  ) version = 2;
	else					version = 1;
	
	// If we're OBJ7, another token 'OBJ' follows...this is because
	// all XP7 files start with the previous two lines.
	if (version == 7)
	{
		line = f.get();
		BreakString(line, tokens);
		if (tokens.empty()) return false;
		tag = tokens[0];
		f.next();
		if (f.done()) return false;
	}
	
	// The last line of the header is the texture file name.	
	if (version != 1)
	{
		line = f.get();	
		BreakString(line, tokens);
		if (tokens.empty()) return false;
		outObj.texture = tokens[0];
		f.next();
		if (f.done()) return false;
	}
		
	/************************************************************
	 * READ GEOMETRIC COMMANDS
	 ************************************************************/
	bool	first_loop = true;
	while (!f.done())
	{
		XObjCmd	cmd;
		
		// Special case, don't pull from the file for v-1...that
		// version string is really an obj command.
		if (version != 1 || !first_loop)
		{
			line = f.get();
			f.next();
		}		
		first_loop = false;

		BreakString(line, tokens);
		if (tokens.empty()) continue;

		/************************************************************
		 * OBJ2 SCANNING
		 ************************************************************/		
		if (version != 7)
		{
			obj2_op = atoi(tokens[0].c_str());
			switch(obj2_op) {
			case 1:
			case 2:
				// Points and lines.  The header line contains the color x10.
				// The type (pt or line) tell how much geometry follows.
				cmd.cmdID = (obj2_op == 1) ? obj_Light : obj_Line;
				cmd.cmdType = type_PtLine;
				count = obj2_op;
				if (tokens.size() < 4) return false;			
				scanned_st_rgb[0][0]=scanned_st_rgb[1][0]=atof(tokens[1].c_str())*0.1; // r
				scanned_st_rgb[0][1]=scanned_st_rgb[1][1]=atof(tokens[2].c_str())*0.1; // g
				scanned_st_rgb[0][2]=scanned_st_rgb[1][2]=atof(tokens[3].c_str())*0.1; // b

				// Sets of x,y,z follows.
				for (int t = 0; t < count; ++t)
				{
					line = f.get();
					f.next();
					BreakString(line, tokens);
					if (tokens.size() < 3) return false;
					vrgb.v[0] = atof(tokens[0].c_str());
					vrgb.v[1] = atof(tokens[1].c_str());
					vrgb.v[2] = atof(tokens[2].c_str());
					vrgb.rgb[0] = scanned_st_rgb[t][0];
					vrgb.rgb[1] = scanned_st_rgb[t][1];
					vrgb.rgb[2] = scanned_st_rgb[t][2];
					cmd.rgb.push_back(vrgb);
				}
				outObj.cmds.push_back(cmd);					
				break;

			case 3:
			case 4:
			case 5:
				// Finite-size polygons.  The header line contains s1, s2, t1, t2.
				cmd.cmdID = (obj2_op == 5) ? obj_Quad_Hard : obj_Quad;
				if (obj2_op == 3) cmd.cmdID = obj_Tri;
				cmd.cmdType = type_Poly;
				count = obj2_op;
				if (count == 5) count = 4;				
				if (tokens.size() < 5 && version == 2) return false;
				// Make sure to 'spread' the 4 S/T coords to 8 points.  This is 
				// because 
				if (version == 2)
				{
					scanned_st_rgb[2][0]=scanned_st_rgb[3][0]=atof(tokens[1].c_str());	// s1
					scanned_st_rgb[0][0]=scanned_st_rgb[1][0]=atof(tokens[2].c_str());	// s2
					scanned_st_rgb[1][1]=scanned_st_rgb[2][1]=atof(tokens[3].c_str());	// t1
					scanned_st_rgb[0][1]=scanned_st_rgb[3][1]=atof(tokens[4].c_str());  // t2
				} else {
					scanned_st_rgb[2][0]=scanned_st_rgb[3][0]=0.0;
					scanned_st_rgb[0][0]=scanned_st_rgb[1][0]=0.0;
					scanned_st_rgb[1][1]=scanned_st_rgb[2][1]=0.0;
					scanned_st_rgb[0][1]=scanned_st_rgb[3][1]=0.0;
				}
				// Read sets of 3 points.
				for (int t = 0; t < count; ++t)
				{
					line = f.get();
					f.next();
					BreakString(line, tokens);
					if (tokens.size() < 3) return false;
					
					vst.v[0] =  atof(tokens[0].c_str());
					vst.v[1] =  atof(tokens[1].c_str());
					vst.v[2] =  atof(tokens[2].c_str());
					vst.st[0] = scanned_st_rgb[t][0];
					vst.st[1] = scanned_st_rgb[t][1];
					cmd.st.push_back(vst);
				}
				outObj.cmds.push_back(cmd);
				break;				
				
			case 99:
				// 99 is the end token for obj2 files.
				return true;
			default:
				// Negative numbers equal positive
				// quad strips.  The count is the number
				// of vertex pairs, since they are always even.
				if (obj2_op >= 0)
					return false;
				count = -obj2_op;
				cmd.cmdID = obj_Quad_Strip;
				cmd.cmdType = type_Poly;
				
				// Read a pair of x,y,z,s,t coords.
				while (count--)
				{
					line = f.get();
					f.next();
					BreakString(line, tokens);
					if (tokens.size() < 10) return false;
					vst.v[0] = atof(tokens[0].c_str());
					vst.v[1] = atof(tokens[1].c_str());
					vst.v[2] = atof(tokens[2].c_str());
					vst.st[0] = atof(tokens[6].c_str());
					vst.st[1] = atof(tokens[8].c_str());
					cmd.st.push_back(vst);
					vst.v[0] = atof(tokens[3].c_str());
					vst.v[1] = atof(tokens[4].c_str());
					vst.v[2] = atof(tokens[5].c_str());
					vst.st[0] = atof(tokens[7].c_str());
					vst.st[1] = atof(tokens[9].c_str());
					cmd.st.push_back(vst);
				}
				outObj.cmds.push_back(cmd);					
				break;
			}
			
		} else {

			/************************************************************
			 * OBJ7 SCANNING
			 ************************************************************/		
		
			cmd_id = FindObjCmd(tokens[0].c_str());
			
			cmd.cmdType = gCmds[cmd_id].cmd_type;
			cmd.cmdID = gCmds[cmd_id].cmd_id;
			count = gCmds[cmd_id].elem_count;
			
			switch(gCmds[cmd_id].cmd_type) {
			case type_None:
				if (cmd_id == obj_End)
					return true;
				else
					return false;
			case type_PtLine:
			
				if ((count == 0) && (tokens.size() > 1))
					count = atoi(tokens[1].c_str());
				while (count-- && !f.done())
				{
					line = f.get();
					f.next();
					BreakString(line, tokens);
					if (tokens.size() > 5)
					{
						vrgb.v[0] = atof(tokens[0].c_str());
						vrgb.v[1] = atof(tokens[1].c_str());
						vrgb.v[2] = atof(tokens[2].c_str());
						vrgb.rgb[0] = atof(tokens[3].c_str());
						vrgb.rgb[1] = atof(tokens[4].c_str());
						vrgb.rgb[2] = atof(tokens[5].c_str());
						
						cmd.rgb.push_back(vrgb);
					} else
						return false;
				}
				outObj.cmds.push_back(cmd);
				break;
				
			case type_Poly:

				if ((count == 0) && (tokens.size() > 1))
					count = atoi(tokens[1].c_str());
				while (count-- && !f.done())
				{
					line = f.get();
					f.next();
					BreakString(line, tokens);
					if (tokens.size() > 4)
					{
						vst.v[0] = atof(tokens[0].c_str());
						vst.v[1] = atof(tokens[1].c_str());
						vst.v[2] = atof(tokens[2].c_str());
						vst.st[0] = atof(tokens[3].c_str());
						vst.st[1] = atof(tokens[4].c_str());
						
						cmd.st.push_back(vst);
						
						if (tokens.size() > 9)
						{
							--count;
							vst.v[0] = atof(tokens[5].c_str());
							vst.v[1] = atof(tokens[6].c_str());
							vst.v[2] = atof(tokens[7].c_str());
							vst.st[0] = atof(tokens[8].c_str());
							vst.st[1] = atof(tokens[9].c_str());
							
							cmd.st.push_back(vst);
						}
					
					} else
						return false;
				}
				outObj.cmds.push_back(cmd);
				break;
			case type_Attr:
				
				if (tokens.size() > count)
				{
					for (int n = 0; n < count; ++n)
						cmd.attributes.push_back(atof(tokens[n+1].c_str()));
				} else
					return false;
					
				outObj.cmds.push_back(cmd);
				break;
			}

		}	// Obj 7 case

	} // While loop
	return true;
}
int main(int argc, char** argv)
{
    bool32 FlagActivated = 0;
    
    for(int i=0;
        i < argc;
        i++)
    {
        char Flag[MAX_FLAG_CHAR];  

        // NOTE: '-' Indicate that a flag name is what comes next
        if(argv[i][0] == '-')
        {
            int IndexArray = 0;
            for(argv[i][1];
                *argv[i];
                argv[i]++)
            {
                if (IndexArray < (MAX_FLAG_CHAR - 1))
                {
                    Flag[IndexArray] = *argv[i];
                    IndexArray++;
                }
            }

            if (CompareStrings(Flag, "-h", 2) == 0)
            {
                FlagActivated = FlagActivated|HELP_FLAG; //0x00      
                ShowHelpPage();
            }

            else if (CompareStrings(Flag, "-cc", 3) == 0)
            {
                FlagActivated = FlagActivated|CHANGE_TARGET_DIRECTORY_FLAG; // 0x01
            }

            else if (CompareStrings(Flag, "-s", 2) == 0)
            {
                FlagActivated = FlagActivated|SOURCE_FILE_FLAG; // 0x02
            }

            else
            {
                // logging
            }
        }

        // NOTE: '@' represents char that indicates that what comes next is an diretory
        else if(argv[i][0] == '@')
        {
                                    
        }
        
        else
        {
            // logging
        }
        
    }

    bool Running = true;
    bool ProjectAssigned = false;
    tree_directory *TreeRootDirectory;
    tree_directory *TreeActualDirectory;
    char PathToPrepend[MAX_PATH_SIZE]; 
    
    WelcomeMessage();

    while(Running)
    {

        char CommandLine[MAX_LINE_SIZE];
        char CLineLowerCase[MAX_LINE_SIZE];
        char CommandName[MAX_LINE_SIZE];
        char CommandAction[MAX_LINE_SIZE];
        
        printf("\nC-environment Shell> ");

        // TODO: Make space before first world do not count for the string comparisons
        gets_s(CommandLine, MAX_LINE_SIZE); 

        IgnoreSpaces(CommandLine, CharArrayCount(CommandLine));
        printf("CommandLine without spaces before: '%s'", CommandLine);

        
        BreakString(CommandLine, CharArrayCount(CLineLowerCase), CommandName,
                    CommandAction, SPACE_CHAR);
        ToLowerCase(CommandName, CLineLowerCase, MAX_LINE_SIZE);

#if 0
        // NOTE: Debug Lines
        printf("CommandLine: %s\tCLineLowerCase: %s\nCommandAction: %s",CommandLine,
               CLineLowerCase, CommandAction);
#endif


        // TODO: Program still have some problems with parsing the input with spaces before command 
        if(CompareStrings(CLineLowerCase, "setprojectname", sizeof("setprojectname")) == 0)
        {
            if (IS_EMPTY_STRING(CommandAction))
            {
                printf("\nAction for command '%s' not found\n Usage:\t'%s [Project Name]'\n",
                       CLineLowerCase, CLineLowerCase);
            }
            TreeRootDirectory = TreeDirectoryCreate(CommandAction);
            TreeActualDirectory = TreeRootDirectory;
            StringCopy(PathToPrepend, CommandAction, CharArrayCount(CommandAction));
            AppendString(PathToPrepend, "/");
            ProjectAssigned = true;
        }
        
        else if(CompareStrings(CLineLowerCase, "createdir", sizeof("createdir")) == 0)
        {
            char ActualPath[MAX_PATH_SIZE];
            StringCopy(ActualPath, PathToPrepend, CharArrayCount(PathToPrepend));
            
            if (ProjectAssigned && !IS_EMPTY_STRING(CommandAction))
            {
                // TODO: Parse if the directory name is valid
                
                // TODO: Prevent PathToPrepend to grow 
                AppendString(PathToPrepend, CommandAction);
                AppendString(PathToPrepend, "/");
                
                // TODO: Virtual file system structured in a tree   
                tree_directory *TreeDirectory = TreeDirectoryCreate(ActualPath);

                // NOTE: More debug lines
                printf("Path: %s", ActualPath);
                printf("Path2: %s", TreeDirectory->PathName);
                
                TreeDirectoryAddNode(TreeActualDirectory, TreeDirectory);
            }

            else if (!ProjectAssigned)
            {
                // TODO: logging system
            }

            else if (IS_EMPTY_STRING(CommandAction))
            {
                // TODO: Logging system
            }
            StringCopy(PathToPrepend, ActualPath, CharArrayCount(ActualPath));
        }

        // TODO: Not sure how to do pathfinder right now!
        else if(CompareStrings(CLineLowerCase, "setdir", sizeof("setdir")) == 0)
        {
            char *DirName = CommandAction;
            if (!IS_EMPTY_STRING(CommandAction))
            {
                if (TreeDirSearchBrother(TreeActualDirectory, DirName))
                {
                    AppendString(PathToPrepend, CommandAction);
                    AppendString(PathToPrepend, "/");

                    TreeDirGoToDirectory(TreeActualDirectory, DirName);
                }
            }
        }

        else if(CompareStrings(CLineLowerCase, "saveconfig", sizeof("saveconfig")) == 0)
        {
            // TODO: Save settings to a file, that can be evoked lately, or in any other
            // instance of the program
        }
        
        else if(CompareStrings(CLineLowerCase, "exit", sizeof("exit")) == 0)
        {
            Running = false;
        }

        else
        {
            printf("\nCommand not found. Type '-h' for help. Command 'exit' is self explanatory.\n");
        }
    }
    return 0;
}
Beispiel #8
0
int CTriggerScanList::Setup (CEventDefList const & defs, LPCSTR pszAsset)
{
	int nCount = 0;

	for (DWORD dw = 0 ; dw < defs.GetCount() ; dw++)
	{
		CEventDef const & def = defs[dw];
		if (def.CheckAsset(pszAsset))
		{
			CString strEventName = def.GetName();

			// loop through the triggers
			for (DWORD dwTrigger = 0 ; dwTrigger < def.GetCount() ; dwTrigger++)
			{
				CEventTrigger & trigger = def[dwTrigger];

				// get the type...
				CString strBuffer = trigger.GetField();
				CString strType = BreakString(strBuffer, '.', TRUE);

				if (strType == "Hardware")
				{
					int nPos = strBuffer.ReverseFind('.');
					CString strCat = strBuffer.Left(nPos);
					CString strKey = strBuffer.Mid(nPos + 1);
					strCat.Replace('.', HW_SEP);
					Add (new CTriggerScannerHw(strEventName, trigger.GetOpCode(), trigger.GetValue(), strCat, strKey));
					nCount++;
				}

				else if (strType == "System")
				{
					strBuffer.Replace('.', HW_SEP);
					Add (new CTriggerScannerSystem(strEventName, trigger.GetOpCode(), trigger.GetValue(), strBuffer));
					nCount++;
				}

				else if (strType == "Internet")
				{
					Add (new CTriggerScannerIe(strEventName, trigger.GetOpCode(), trigger.GetValue()));
					nCount++;
				}

				else if (strType == "Operating System")
				{
					CString strKey = strBuffer;
					Add (new CTriggerScannerOs(strEventName, trigger.GetOpCode(), trigger.GetValue(), strKey));
					nCount++;
				}

				else if (strType == "Software")
				{
					Add (new CTriggerScannerApp(strEventName, trigger.GetOpCode(), trigger.GetValue()));
					nCount++;
				}

				else
				{
					TRACE("Unknown Trigger Type %s\n", strType);
					ASSERT(FALSE);
				}
			}
		}
	}
	return nCount;
}