Represents a C-style (null-terminated) string.
Example #1
0
        /// <summary>
        /// Converts character to an ascii c like string representation.
        /// If unicode character is outside the range of an Ascii
        /// character then Convert.NonAsciiCharacter is returned.
        /// </summary>
        /// <param name="value">char to be converted</param>
        /// <returns></returns>
        public unsafe static CString8 *ToCString8(char value)
        {
            CString8 *str1 = CString8.Create(1);

            str1->SetChar(0, ToAscii(value));
            return(str1);
        }
Example #2
0
        /// <summary>
        /// Converts string to its ascii representation terminating with
        /// null.  If unicode character is outside the range of an Ascii
        /// character then Convert.NonAsciiCharacter is returned in its
        /// place.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public unsafe static CString8 *ToCString8(string value)
        {
            CString8 *str1 = CString8.Create(value.Length);

            for (int x = 0; x < value.Length; x++)
            {
                str1->SetChar(x, ToAscii(value [x]));
            }
            return(str1);
        }
Example #3
0
        /// <summary>
        /// Performs a new test, optionally printing it and/or recording it in memory.
        /// </summary>
        public unsafe static void Test(bool result, string source, string name)
        {
            CString8 *sourceStr = CString8.Copy(source);
            CString8 *nameStr   = CString8.Copy(name);

            if (PrintTestcases)
            {
                Debug.COM1.Write(sourceStr);
                Debug.COM1.Write(": ");
                Debug.COM1.Write(nameStr);
                Debug.COM1.Write(" ... ");

                TextMode.SaveAttributes();

                if (result)
                {
                    Debug.COM1.WriteLine("PASS");
                }
                else
                {
                    Debug.COM1.WriteLine("FAIL");
                }

                TextMode.RestoreAttributes();
            }

            if (RecordTestcases)
            {
                TestRecord *rec = (TestRecord *)MemoryManager.Allocate((uint)sizeof(TestRecord));

                rec->Source = sourceStr;
                rec->Name   = nameStr;
                rec->Result = result;
                rec->Next   = null;

                if (Records == null)
                {
                    Records = rec;
                }
                else
                {
                    GetLastTest()->Next = rec;
                }
            }
            else
            {
                MemoryManager.Free(sourceStr);
                MemoryManager.Free(nameStr);
            }
        }
Example #4
0
        private CString8 *Substring_INTERNAL(int index, int count)
        {
            if (count == 0)
            {
                return(CString8.CreateEmpty());
            }

            byte *rslt    = (byte *)SharpOS.Kernel.ADC.MemoryManager.Allocate((uint)count + 1);
            byte *thisPtr = this.Pointer;

            Diagnostics.Assert(rslt != thisPtr, "CString8.Substring_INTERNAL(): Insane memory allocation detected!");

            for (int i = index; i < (index + count); i++)
            {
                rslt [i - index] = thisPtr [i];
            }
            rslt [count] = (byte)'\0';

            return((CString8 *)rslt);
        }
Example #5
0
		public CommandTableEntry* FindCommand (CString8* name)
		{
			Diagnostics.Assert (name != null, "CommandTableHeader::FindCommand(CString8*): Parameter 'name' is null");
			Diagnostics.Assert (firstEntry != null, "CommandTableHeader::FindCommand(CString8*): Cannot search through commands; command list is empty");
			CommandTableEntry* currentEntry;
			for (currentEntry = firstEntry;
					currentEntry != null;
					currentEntry = currentEntry->nextEntry) {
				//FIXME: This needs to be case insensitive!
				if (ByteString.Compare (name->Pointer, currentEntry->name->Pointer) == 0)
					return currentEntry;
				//else
				//{
				//    ADC.TextMode.Write("CommandTableHeader::FindCommand(CString8*): Entered '");
				//    ADC.TextMode.Write(name);
				//    ADC.TextMode.Write("' != '");
				//    ADC.TextMode.Write(currentEntry->name);
				//    ADC.TextMode.WriteLine("'");
				//}
			}

			return null;
		}
Example #6
0
		private static void HandleUnrecognizedCommandEntry (CString8* commandName)
		{
			TextMode.Write ("Unrecognized command: \"");
			TextMode.Write (commandName);
			TextMode.WriteLine ("\"");
		}
Example #7
0
		/// <summary>
		/// Writes <paramref name="len" /> characters of the string
		/// <paramref name="message" /> to the screen, starting with
		/// the character at index <paramref name="offset" />.
		/// </summary>
		public unsafe static void WriteSubstring (CString8* message, int offset, int len)
		{
			for (int i = offset; message->GetChar (i) != 0 && i < offset + len; ++i)
				WriteChar (message->GetChar (i));
		}
Example #8
0
		private unsafe static bool __StringComp (CString8* str1, CString8* str2)
		{
			byte* s1 = (byte*) str1;
			byte* s2 = (byte*) str2;
			while (*s1 == *s2 && *s1 != 0 && *s2 != 0) {
				++s1;
				++s2;
			}

			return (*s1 == 0 & *s2 == 0);
		}
Example #9
0
		/// <summary>
		/// Sets the current keymap to a built-in one specified by
		/// <paramref name="name" />.
		/// </summary>
		public static void SetKeyMap (CString8* name)
		{
			SetKeyMap (name->Pointer);
		}
Example #10
0
		/// <summary>
		/// Concatenates <paramref name="str" />.
		/// </summary>
		public int Concat (CString8* str)
		{
			return Concat (str, 0, 0);
		}
Example #11
0
		/// <summary>
		/// Compares the string against <paramref name="str" />.
		/// </summary>
		public int Compare (CString8* str)
		{
			return Compare (str, 0);
		}
Example #12
0
		public static unsafe TypeDefRow GetType (CString8 *ns, CString8 *name)
		{
			AssemblyMetadata assembly;
			uint token;

			return GetType (ns, name, out assembly, out token);
		}
Example #13
0
		public static void DISPOSE (CString8* cstr)
		{
			ADC.MemoryManager.Free ((void*) cstr);
		}
Example #14
0
		public static unsafe ModuleRow GetModule (AssemblyMetadata assembly, CString8 *name)
		{
			Diagnostics.Assert (assembly == null,
				"Runtime.GetModule(): parameter `assembly' is null");
			Diagnostics.Assert (name == null,
				"Runtime.GetModule(): parameter `name' is null");

			for (int x = 0; x < assembly.Module.Length; ++x) {
				ModuleRow row = assembly.Module [x];
				int len = GetStringLength (assembly, row.Name);

				if (name->Compare (0, assembly.StringsHeap, (int) row.Name, len) == 0)
					return row;
			}

			return null;
		}
Example #15
0
		public static unsafe TypeDefRow GetType (CString8 *ns, CString8 *name, out AssemblyMetadata assembly, out uint token)
		{
			token = 0;
			assembly = null;

			Diagnostics.Assert (ns != null,
				"Runtime.GetType(): parameter `ns' is null");
			Diagnostics.Assert (name != null,
				"Runtime.GetType(): parameter `name' is null");

			for (int x = 0; x < Root.Assemblies.Length; ++x) {
				TypeDefRow row = GetType (Root.Assemblies [x], ns, name, out token);

				if (row != null) {
					assembly = Root.Assemblies [x];
					return row;
				}
			}

			return null;
		}
Example #16
0
		public static unsafe ModuleRow GetModule (CString8 *name)
		{
			for (int x = 0; x < Root.Assemblies.Length; ++x) {
				ModuleRow result = GetModule (Root.Assemblies [x], name);

				if (result != null)
					return result;
			}

			return null;
		}
Example #17
0
		public static unsafe bool IsBaseClassOf (TypeInfo type, CString8 *baseNS, CString8 *baseType)
		{
			AssemblyMetadata baseAsm;
			uint token;
			TypeRefRow row;
			TypeDefRow def;

			row = GetTypeRef (baseNS, baseType, out baseAsm, out token);

			if (row != null) {
				return IsBaseClassOf (type.Assembly, type.MetadataToken, baseAsm, token);
			} else {
				def = GetType (baseNS, baseType, out baseAsm, out token);

				Diagnostics.Assert (def != null,
					"Runtime.IsBaseClasOf(): couldn't find TypeRef/Def for named type");

				return IsBaseClassOf (type.Assembly, type.MetadataToken, baseAsm, token);
			}
		}
Example #18
0
		public static void RenderItem(string title, CString8* value)
		{
			RenderItemTitle(title);

			TextMode.WriteLine(value);
		}
Example #19
0
		/// <summary>
		/// Compares <paramref name="count" /> characters of the
		/// string against <paramref name="str" />.
		/// </summary>
		public int Compare (int from, CString8* str, int offset, int count)
		{
			return ByteString.Compare (Pointer, from, str->Pointer, offset, count);
		}
Example #20
0
		public static unsafe TypeDefRow GetType (AssemblyMetadata assembly, CString8 *ns, CString8 *name)
		{
			uint token;

			return GetType (assembly, name, ns, out token);
		}
Example #21
0
		public static CString8* Copy (CString8* original)
		{
			uint l = (uint) original->Length;
			byte* originalPtr = original->Pointer;
			byte* result = (byte*) ADC.MemoryManager.Allocate (l + 1);

			for (int i = 0; i < l; i++)
				result [i] = originalPtr [i];
			result [l] = (byte) '\0';

			return (CString8*) result;
		}
Example #22
0
		public static unsafe TypeRefRow GetTypeRef (CString8 *ns, CString8 *name, out AssemblyMetadata assembly, out uint token)
		{
			assembly = null;
			token = 0;

			for (int x = 0; x < Root.Assemblies.Length; ++x) {
				TypeRefRow result = GetTypeRef (Root.Assemblies [x], ns, name, out token);

				if (result != null) {
					assembly = Root.Assemblies [x];
					return result;
				}
			}

			return null;
		}
Example #23
0
		/// <summary>
		/// Concatenates from <paramref name="str" /> the
		/// characters at indices <paramref name="offset" /> to
		/// <paramref name="offset" /> + <paramref name="len" />.
		/// </summary>
		public int Concat (CString8* str, int offset, int len)
		{
			return Concat (str->Pointer, str->Length, offset, len);
		}
Example #24
0
		public static unsafe TypeRefRow GetTypeRef (AssemblyMetadata assembly, CString8 *ns, CString8 *name, out uint token)
		{
			TypeRefRow result = null;
			token = 0;

			for (int x = 0; x < assembly.TypeRef.Length; ++x) {
				int nameLength = 0;
				int nsLength = 0;
				TypeRefRow inspect = assembly.TypeRef [x];

				nameLength = GetStringLength (assembly, inspect.Name);
				nsLength = GetStringLength (assembly, inspect.Namespace);

				if (name->Compare (0, assembly.StringsHeap, (int) inspect.Name, nameLength) != 0)
					continue;
				if (ns->Compare (0, assembly.StringsHeap, (int) inspect.Namespace, nsLength) != 0)
					continue;

				result = inspect;
				token = (uint)TokenType.TypeRef | (uint)x+1U;
				break;
			}

			return result;
		}
Example #25
0
		/// <summary>
		/// Compares <paramref name="count" /> characters of the
		/// string against <paramref name="str" />.
		/// </summary>
		public int Compare (CString8* str, int count)
		{
			return ByteString.Compare (Pointer, str->Pointer, count);
		}
Example #26
0
		public int IndexOf (int from, CString8* substr, int offset, int count)
		{
			return IndexOf (from, substr->Pointer, substr->Length, offset, count);
		}
Example #27
0
		static public string ToString (CString8* cstring)
		{
			return InternalSystem.String.CreateStringImpl (cstring);
		}
Example #28
0
		public unsafe static void Write (CString8* str)
		{
			Write (str->Pointer, str->Length);
		}
Example #29
0
		/// <summary>
		/// Gets the address of a builtin keymap included in the kernel
		/// via the keymap archive resource in SharpOS.Kernel.dll. The
		/// archive is generated by the SharpOS keymap compiler.
		/// </summary>
		/// <param name="name">The name.</param>
		/// <param name="nameLen">The name len.</param>
		/// <returns></returns>
		public static void* GetBuiltinKeyMap (CString8* name)
		{
			return GetBuiltinKeyMap (name->Pointer, name->Length);
		}
Example #30
0
		public int IndexOf (int from, CString8* substr)
		{
			return IndexOf (from, substr, 0, 0);
		}
Example #31
0
		internal CommandExecutionAttemptResult HandleLine (CString8* input, bool verboseFailure, bool useHelp)
		{
			Diagnostics.Assert (input != null, "Prompter::HandleLine(CString8*): Parameter 'input' is null");
#if Prompter_DebuggingVerbosity
			Diagnostics.Message("Prompter::HandleLine(CString8*): Function started");
#endif

			if (input->Length == 0) {
#if Prompter_DebuggingVerbosity
			Diagnostics.Message("Prompter::HandleLine(CString8*): Raw input is blank");
#endif
				if (verboseFailure)
					HandleEmptyCommandEntry ();

#if Prompter_DebuggingVerbosity
			Diagnostics.Message("Prompter::HandleLine(CString8*): RET");
#endif
				return CommandExecutionAttemptResult.BlankEntry;
			}
			CString8* trimmedInput = input->Trim ();
			if (trimmedInput->Length == 0) {
#if Prompter_DebuggingVerbosity
			Diagnostics.Message("Prompter::HandleLine(CString8*): Trimmed input is blank");
#endif
				CString8.DISPOSE (trimmedInput);

				if (verboseFailure)
					HandleEmptyCommandEntry ();

#if Prompter_DebuggingVerbosity
			Diagnostics.Message("Prompter::HandleLine(CString8*): RET");
#endif
				return CommandExecutionAttemptResult.BlankEntry;
			}

			int firstSpace = trimmedInput->IndexOf (" ");
			CString8* commandName;
			CString8* parameters;
			if (firstSpace < 0) {
				commandName = trimmedInput;
				parameters = CString8.CreateEmpty ();
			}
			else {
				commandName = trimmedInput->Substring (0, firstSpace);
				parameters = trimmedInput->Substring (firstSpace + 1);
			}

			CommandTableEntry* command = this.FindCommand (commandName);
			if (command == null) {
#if Prompter_DebuggingVerbosity
				Diagnostics.Message("Prompter::HandleLine(CString8*): Command not found");
#endif
				if (verboseFailure)
					HandleUnrecognizedCommandEntry (commandName);

#if Prompter_DebuggingVerbosity
				Diagnostics.Message("Prompter::HandleLine(CString8*): Freeing contextual stuff");
#endif
				//Free up what we used
				if (commandName != trimmedInput)
					CString8.DISPOSE (commandName);
				CString8.DISPOSE (trimmedInput);
				CString8.DISPOSE (parameters);
#if Prompter_DebuggingVerbosity
				Diagnostics.Message("Prompter::HandleLine(CString8*): RET");
#endif
				return CommandExecutionAttemptResult.NotFound;
			}
			CommandExecutionContext* commandExecutionContext = CommandExecutionContext.CREATE ();
			commandExecutionContext->parameters = parameters;

#if Prompter_DebuggingVerbosity
			Diagnostics.Message("Prompter::HandleLine(CString8*): Getting ready to call command");
#endif
			if (!useHelp)
				ADC.MemoryUtil.Call (command->func_Execute, (void*)commandExecutionContext);
			else
				ADC.MemoryUtil.Call (command->func_GetHelp, (void*)commandExecutionContext);
#if Prompter_DebuggingVerbosity
			Diagnostics.Message("Prompter::HandleLine(CString8*): Done calling command");
#endif

			//Free up what we used
#if Prompter_DebuggingVerbosity
			Diagnostics.Message("Prompter::HandleLine(CString8*): Freeing contextual stuff");
#endif
			if (commandName != trimmedInput)
				CString8.DISPOSE (commandName);
			CString8.DISPOSE (trimmedInput);
			CString8.DISPOSE (parameters);
			CommandExecutionContext.DISPOSE (commandExecutionContext);
#if Prompter_DebuggingVerbosity
			Diagnostics.Message("Prompter::HandleLine(CString8*): RET");
#endif
			return CommandExecutionAttemptResult.Success;
		}
Example #32
0
		public int IndexOf (CString8* substr)
		{
			return IndexOf (0, substr, 0, 0);
		}
Example #33
0
		public int IndexOf (int from, CString8* substr, int count)
		{
			return IndexOf (from, substr, 0, count);
		}
Example #34
0
		public unsafe static void WriteLine (CString8* message, int value)
		{
			Write (message);
			Write (value);
			WriteLine ();
		}