コード例 #1
0
ファイル: Program.cs プロジェクト: valentinbreiz/Sharpen
        static void Main(string[] args)
        {
            // Header
            printTopLine();
            Console.WriteLine("\xB3  BUS  \xB3  SLOT \xB3  FUNC \xB3   VENDOR  \xB3   DEVICE  \xB3 CLASS \xB3  SUB  \xB3 INTF  \xB3");
            printSplitLine();

            Directory dir = Directory.Open("devices://pci/");

            Directory.DirEntry entry = dir.Readdir();
            while (entry.Name[0] != '\0')
            {
                string str = Util.CharPtrToString(entry.Name);

                printDevice(str);

                entry = dir.Readdir();
                if (entry.Name[0] != '\0')
                {
                    printSplitLine();
                }
                else
                {
                    printBottomLine();
                }
            }

            dir.Close();
            Heap.Free(dir);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Directory dir = Directory.Open("proc://");

            while (true)
            {
                Directory.DirEntry entry = dir.Readdir();
                if (entry.Name[0] == '\0')
                {
                    break;
                }

                string str = Util.CharPtrToString(entry.Name);
                printProcess(str);
            }

            dir.Close();
            Heap.Free(dir);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: valentinbreiz/Sharpen
        unsafe static void Main(string[] args)
        {
            Console.WriteLine("\nProject Sharpen");
            Console.WriteLine("(c) 2016-2017 SharpNative\n");

            string currentDir = Directory.GetCurrentDirectory();

            while (true)
            {
                // Prompt
                Console.Write(currentDir);
                Console.Write("> ");

                // Read line
                string read = Console.ReadLine();
                if (read.Length == 0)
                {
                    Heap.Free(read);
                    continue;
                }

                // Split command line
                int argc = String.Count(read, ' ') + 1;

                // Copy for NULL ending
                string[] argv  = new string[argc + 1];
                string[] split = read.Split(' ');
                for (int i = 0; i < argc; i++)
                {
                    argv[i] = split[i];
                }

                string command = argv[0];

                Heap.Free(split);

                // Remove the empty arguments
                for (int i = 0; i < argc; i++)
                {
                    if (argv[i].Length == 0)
                    {
                        Heap.Free(argv[i]);
                        argv[i] = null;
                        argc--;
                    }
                }

                // Process commands
                if (command.Equals("cd"))
                {
                    if (argc != 2)
                    {
                        Console.WriteLine("Invalid usage of cd: cd [dirname]");
                    }
                    else
                    {
                        if (!Directory.SetCurrentDirectory(argv[1]))
                        {
                            Console.WriteLine("cd: Couldn't change the directory");
                        }
                        else
                        {
                            string old = currentDir;
                            currentDir = Directory.GetCurrentDirectory();
                            Heap.Free(old);
                        }
                    }
                }
                else if (command.Equals("dir"))
                {
                    Directory dir = Directory.Open(currentDir);

                    while (true)
                    {
                        Directory.DirEntry entry = dir.Readdir();
                        if (entry.Name[0] == '\0')
                        {
                            break;
                        }

                        string str = Util.CharPtrToString(entry.Name);
                        Console.WriteLine(str);
                    }

                    dir.Close();
                    Heap.Free(dir);
                }
                else if (command.Equals("print"))
                {
                    Print(argv, argc);
                }
                else if (command.Equals("echo"))
                {
                    Print(argv, argc);
                }
                else if (command.Equals("exit"))
                {
                    Process.Exit(0);
                }
                else if (command.Equals("background"))
                {
                    // Try to start a process without waiting until exit
                    string[] offsetArgv = (string[])Array.CreateSubArray((object[])argv, 1, argc - 1);

                    int ret = tryStartProcess(offsetArgv[0], offsetArgv);
                    if (ret > 0)
                    {
                        Console.Write("Process started in background with PID ");
                        Console.Write(ret);
                    }
                    Console.Write('\n');
                    Heap.Free(offsetArgv);
                }
                else
                {
                    // Try to start a process and wait until exit to return to prompt
                    int ret = tryStartProcess(command, argv);
                    if (ret > 0)
                    {
                        Process.WaitForExit(ret);
                    }
                    else
                    {
                        Console.Write(command);
                        Console.WriteLine(": Bad command or filename");
                    }
                }

                // Note: command is in the first entry of argv
                for (int i = 0; i < argc; i++)
                {
                    if (argv[i] != null)
                    {
                        Heap.Free(argv[i]);
                    }
                }
                Heap.Free(read);
                Heap.Free(argv);
            }
        }