Beispiel #1
0
int main(void) {
	//_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

    FileSystem fs;

    string userCommand, commandArr[MAXCOMMANDS];
    string user = "******";    // Change this if you want another user to be displayed
    string currentDir = "/";    // current directory, used for output

    bool bRun = true;
	fs.format();
	//HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    do {
		currentDir = fs.GetCWD();
		string data = "";
		//SetConsoleTextAttribute(hConsole, 10);
		cout << user << " ";
		//SetConsoleTextAttribute(hConsole, 14);
		cout << currentDir << endl;
		//SetConsoleTextAttribute(hConsole, 15);
		cout << "$ ";
        getline(cin, userCommand);

		for (unsigned i = 0; i < MAXCOMMANDS; ++i)
			commandArr[i] = "";

        int nrOfCommands = parseCommandString(userCommand, commandArr);
        if (nrOfCommands > 0) {

            int cIndex = findCommand(commandArr[0]);
            switch(cIndex) {

            case 0: // quit
                bRun = false;
                cout << "Exiting\n";
                break;
            case 1: // format
				fs.format();
                break;
            case 2: // ls
				if (commandArr[1] == "")
					fs.ls();
				else
					fs.ls(commandArr[1]);
                break;
            case 3: // create
				printf("Please Insert Data:\n");
				getline( cin, data );
				fs.create(commandArr[1],data);
                break;
            case 4: // cat
				fs.cat(commandArr[1]);
                break;
            case 5: // createImage
				fs.createImage( commandArr[1] );
                break;
            case 6: // restoreImage
				fs.restoreImage( commandArr[1] );
                break;
            case 7: // rm
				fs.rm(commandArr[1]);
                break;

            case 8: // copy
				fs.copy( commandArr[1], commandArr[2] );
                break;

            case 9: // append
				fs.append( commandArr[1], commandArr[2] );
                break;

            case 10: // rename
				fs.rename( commandArr[1], commandArr[2] );
                break;

            case 11: // mkdir
				fs.mkdir(commandArr[1]);
                break;

            case 12: // cd
				fs.cd(commandArr[1]);
                break;

            case 13: // pwd
				cout << fs.GetCWD() << endl;
                break;

            case 14: // help
                cout << help() << endl;
                break;

			case 15: // rmdir
				fs.rmdir(commandArr[1]);
				break;

			case 16: // chmod
				fs.chmod( atoi( commandArr[1].c_str() ), commandArr[2] );
				break;

            default:
                cout << "Unknown command: " << commandArr[0] << endl;

            }

			cout << endl;
        }
    } while (bRun == true);

    return 0;
}