📄 main.cc
字号:
#define MAIN#include "copyright.h"#undef MAIN#include "utility.h"#include "system.h"#ifdef THREADSextern int testnum;#endif// External functions used by this fileextern void ThreadTest(void), Copy(char *unixFile, char *nachosFile);extern void PrintFile(char *file);extern void PerformanceTest(int layer);extern void StartProcess(char *file), ConsoleTest(char *in, char *out);extern void MailTest(int networkID);extern void RenameFile(char *src, char *des);extern void RemoveFile(char *src);extern void CopyFile(char *src, char *des);extern void MultiThreadsTest();extern void LoadProc(char *fileName);//----------------------------------------------------------------------// main// Bootstrap the operating system kernel. // // Check command line arguments// Initialize data structures// (optionally) Call test procedure//// "argc" is the number of command line arguments (including the name// of the command) -- ex: "nachos -d +" -> argc = 3 // "argv" is an array of strings, one for each command line argument// ex: "nachos -d +" -> argv = {"nachos", "-d", "+"}//----------------------------------------------------------------------intmain(int argc, char **argv){ int argCount; // the number of arguments // for a particular command puts("**********FangWenBin LiShowChao LvMingXian MaXiaoMing**********"); DEBUG('t', "Entering main"); (void) Initialize(argc, argv); /*#ifdef THREADS for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount) { argCount = 1; switch (argv[0][1]) { case 'q': testnum = atoi(argv[1]); argCount++; break; default: testnum = 1; break; } } ThreadTest();#endif*/ for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount) { argCount = 1; if (!strcmp(*argv, "-z")) // print copyright printf (copyright);#ifdef USER_PROGRAM if (!strcmp(*argv, "-x")) { // run a user program ASSERT(argc > 1); StartProcess(*(argv + 1)); argCount = 2; } else if (!strcmp(*argv, "-c")) { // test the console if (argc == 1) ConsoleTest(NULL, NULL); else { ASSERT(argc > 2); ConsoleTest(*(argv + 1), *(argv + 2)); argCount = 3; } interrupt->Halt(); // once we start the console, then }//end else if (!strcmp(*argv, "-c") else if (!strcmp(*argv, "-mem")) { for (int i = 0; i < atoi(*(argv+1)); i++) LoadProc("/halt"); int TotalMem = 4096*32; for (int i = 0; i < TotalMem; i++) { printf("%2.2x ", (machine->mainMemory[i]&0xff)); if (i % 16 == 0 && i != 0) putchar('\n'); } argCount = 3; }//end else if (!strcmp(*argv, "-mem")#endif // USER_PROGRAM#ifdef FILESYS if (!strcmp(*argv, "-cp")) { // copy from UNIX to Nachos Copy(*(argv + 1), *(argv + 2)); printf("Copy %s from unix to %s in nachos!!\n",*(argv+1), *(argv+2)); } else if (!strcmp(*argv, "-p")) { // print a Nachos file if (argc != 2) { printf("error: nachos -p filename"); goto OUT; } PrintFile(*(argv+1)); argCount = 3; } else if (!strcmp(*argv, "-r")) { // remove Nachos file if (argc != 2) { printf("error: nachos -r filename"); goto OUT; } RemoveFile(*(argv+1)); printf("%s has been removed!\n", *(argv+1)); argCount = 3; } else if (!strcmp(*argv, "-l")) { // list Nachos directory if (argc != 2) { printf("error: nachos -l dir\n"); break; } fileSystem->s_List(*(argv+1)); argCount = 3; } else if (!strcmp(*argv, "-D")) { // print entire filesystem ; } else if (!strcmp(*argv, "-t")) { // performance test if (argc != 2) { printf("error: nachos -t layer"); goto OUT; } PerformanceTest(atoi(*(argv+1))); } else if (!strcmp(*argv, "-copy")) { if (argc != 3) { printf("error: nachos -copy src des\n"); goto OUT; } CopyFile(*(argv+1), *(argv+2)); printf("%s has been copied to %s\n", *(argv+1), *(argv+2)); argCount = 4; } else if (!strcmp(*argv, "-rename")) { if (argc != 3) { printf("error: nachos -rename oldname newname\n"); goto OUT; } RenameFile(*(argv+1), *(argv+2)); printf("%s has been renamed to %s\n", *(argv+1), *(argv+2)); argCount = 3; } else if (!strcmp(*argv, "-nf")) { if (argc != 2) { printf("error: nachos -nd filename\n"); goto OUT; } fileSystem->s_CreateFile(*(argv+1)); printf("%s has been created\n", *(argv+1)); argCount = 3; } else if (!strcmp(*argv, "-nd")) { if (argc != 2) { printf("error: nachos -nd dirname\n"); goto OUT; } fileSystem->s_CreateDir(*(argv+1)); printf("%s has been created\n", *(argv+1)); argCount = 3; } else if (!strcmp(*argv, "-w")) { if (argc != 3) { printf("error: nachos -w path contents\n"); goto OUT; } fileSystem->s_WriteFile(*(argv+1), strlen(*(argv+2)), *(argv+2)); printf("%s has been writen\n", *(argv+1)); argCount = 3; } else if (!strcmp(*argv, "-s")) { MultiThreadsTest(); }#endif // FILESYS#ifdef NETWORK if (!strcmp(*argv, "-o")) { ASSERT(argc > 1); Delay(2); // delay for 2 seconds // to give the user time to // start up another nachos MailTest(atoi(*(argv + 1))); argCount = 2; }#endif // NETWORK }OUT: puts("\n**********FangWenBin LiShowChao LvMingXian MaXiaoMing**********"); puts("\n\n"); currentThread->Finish(); // NOTE: if the procedure "main" // returns, then the program "nachos" // will exit (as any other normal program // would). But there may be other // threads on the ready list. We switch // to those threads by saying that the // "main" thread is finished, preventing // it from returning. return(0); // Not reached...}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -