Beispiel #1
0
        public void TestGetLiteralStringPointer()
        {
            var String = "Hello World";

            Assert.AreEqual(
                String,
                CLibUtils.GetStringFromPointer(CLibUtils.GetLiteralStringPointer(String))
                );
        }
Beispiel #2
0
        static public int sprintf(__arglist)
        {
            var Arguments = CLibUtils.GetObjectsFromArgsIterator(new ArgIterator(__arglist));
            var Buffer    = (sbyte *)((UIntPtr)Arguments[0]).ToPointer();
            var Format    = CLibUtils.GetStringFromPointer((UIntPtr)Arguments[1]);
            var Str       = CLibUtils.sprintf_hl(Format, Arguments.Skip(2).ToArray());
            var Bytes     = CLibUtils.DefaultEncoding.GetBytes(Str);

            Marshal.Copy(Bytes, 0, new IntPtr(Buffer), Bytes.Length);
            Buffer[Bytes.Length] = 0;
            return(Bytes.Length);
        }
Beispiel #3
0
        static public int fprintf(__arglist)
        {
            var Arguments = CLibUtils.GetObjectsFromArgsIterator(new ArgIterator(__arglist));

            var File        = (FILE *)((UIntPtr)Arguments[0]).ToPointer();
            var Format      = CLibUtils.GetStringFromPointer((UIntPtr)Arguments[1]);
            var Str         = CLibUtils.sprintf_hl(Format, Arguments.Skip(2).ToArray());
            var DataToWrite = CLibUtils.DefaultEncoding.GetBytes(Str);

            fixed(byte *DataToWritePtr = DataToWrite)
            {
                return(fwrite((sbyte *)DataToWritePtr, 1, DataToWrite.Length, File));
            }
        }
Beispiel #4
0
        static public int printf(__arglist)
        {
            var Arguments = CLibUtils.GetObjectsFromArgsIterator(new ArgIterator(__arglist));

            var Format = CLibUtils.GetStringFromPointer((UIntPtr)Arguments[0]);
            var Str    = CLibUtils.sprintf_hl(Format, Arguments.Skip(1).ToArray());

#if true
            var StrBytes = CLibUtils.DefaultEncoding.GetBytes(Str);
            stdout->GetStream().Write(StrBytes, 0, StrBytes.Length);
#else
            Console.Write(Str);
#endif

            return(Str.Length);
        }
        public void TestSimpleIf()
        {
            var TestMethod = CompileProgram(@"
				char *test(int a) {
					if (a > 5) return ""greater than 5"";
					return ""not greater than 5"";
				}
			"            ).GetMethod("test");

            {
                var Result   = (Pointer)TestMethod.Invoke(null, new object[] { 6 });
                var Pointer2 = new IntPtr(Pointer.Unbox(Result));
                Assert.AreEqual("greater than 5", CLibUtils.GetStringFromPointer(Pointer2));
            }
            {
                var Result   = (Pointer)TestMethod.Invoke(null, new object[] { 5 });
                var Pointer2 = new IntPtr(Pointer.Unbox(Result));
                //Console.WriteLine(Marshal.PtrToStringAnsi(Pointer2));
                Assert.AreEqual("not greater than 5", CLibUtils.GetStringFromPointer(Pointer2));
            }
        }