├── .gitignore ├── .DS_Store ├── src ├── hi.cpp ├── mv.cpp ├── rm.cpp ├── Timer.h ├── cp.cpp ├── ls.cpp ├── new.cpp └── main.cpp ├── Makefile ├── LICENSE ├── README.md └── tests ├── ls.script ├── piping2.script ├── exec.script ├── signals.script └── piping.script /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hkwan003/rshell/HEAD/.DS_Store -------------------------------------------------------------------------------- /src/hi.cpp: -------------------------------------------------------------------------------- 1 | df f asdfa d fasdf asdfasdf asdfsdfafa 2 | df 3 | asdf 4 | a 5 | sf 6 | a s 7 | f 8 | asd 9 | f 10 | asdf 11 | as 12 | df 13 | 14 | a 15 | fas 16 | f 17 | a 18 | ds 19 | 20 | 21 | asdfasdf f 22 | a 23 | sdf df fdafdf asdf df 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CFGLAGS = -Wall -Werror -ansi -pedantic 3 | FILEPATH = ./src/main.cpp 4 | CPPATH = ./src/cp.cpp 5 | RMPATH = ./src/rm.cpp 6 | LSPATH = ./src/ls.cpp 7 | MVPATH = ./src/mv.cpp 8 | OUTPATH = ./bin/rshell 9 | all: 10 | mkdir -p ./bin 11 | $(CXX) $(CFLAGS) $(FILEPATH) -o $(OUTPATH) 12 | rshell: 13 | mkdir -p ,/bin 14 | $(CXX) $(CFLAGS) $(FILEPATH) -o $(OUTPATH) 15 | cp: 16 | mkdir -p ./bin 17 | $(CXX) $(CFLAGS) $(CPPATH) -o $(OUTPATH) 18 | rm: 19 | mkdir -p ./bin 20 | $(CXX) $(CFLAGS) $(RMPATH) -o $(OUTPATH) 21 | ls: 22 | mkdir -p ./bin 23 | $(CXX) $(CFLAGS) $(LSPATH) -o $(OUTPATH) 24 | mv: 25 | mkdir -p ./bin 26 | $(CXX) $(CFLAGS) $(MVPATH) -o $(OUTPATH) 27 | 28 | clean: 29 | rm -rf ./bin 30 | 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Calvin Kwan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /src/mv.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | using namespace std; 12 | 13 | int main(int argc, char** argv){ 14 | 15 | string first, second; 16 | struct stat buffer; 17 | if(argc <= 2){ 18 | cout << "Error: Not enough arguments!" << endl; 19 | exit(1); 20 | } 21 | first = argv[1]; 22 | if(stat(argv[1], &buffer) == -1){ 23 | cerr << "File does not exist!" << endl; 24 | exit(1);//the first argument is not a file 25 | } 26 | 27 | second = argv[2]; 28 | if(stat(argv[2], &buffer) == 0){ 29 | if(S_ISDIR(buffer.st_mode)){ 30 | //move into dir 31 | second = second + "/" + first; 32 | if(link(first.c_str(), second.c_str()) != -1){ 33 | if(unlink(first.c_str()) == -1){ 34 | perror("unlink()"); 35 | exit(1); 36 | } 37 | return 0; 38 | } 39 | else { 40 | perror("link()"); 41 | exit(1); 42 | } 43 | 44 | return 0; 45 | } 46 | // second file already exists! 47 | else { 48 | cerr << "Error, trying to overwrite an existing file!" << endl; 49 | exit(1);//the second file exists already 50 | } 51 | } 52 | //if it reaches here then move is authorized 53 | //link the two files 54 | if(link(first.c_str(), second.c_str()) != -1){ 55 | if(unlink(first.c_str()) == -1){ 56 | perror("unlink()"); 57 | exit(1); 58 | } 59 | return 0; 60 | } 61 | else{ 62 | perror("link()"); 63 | exit(1); 64 | } 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rshell Linux command 2 | 3 | ## Rshell functionality 4 | 5 | Rshell is a c++ shell that is meant to replicate the same one used in UNIX. It only has basic functionalties for now but more will be added onto it later. 6 | 7 | * A command prompt 8 | * Recognition of various commands 9 | * Exit functionality 10 | * Clear functionality 11 | * User login recognition 12 | * Comment recognition 13 | * Ability to change directories 14 | 15 | ## How to use cd 16 | 17 | * To change directories, type ``cd `` 18 | * Path can be changed for example ``cd home/rshell/bin/rshell`` 19 | * ``cd`` will change back to the home directory 20 | * ``cd -`` will change to the previous directory 21 | * the current directory will be printed after the prompt 22 | * ``^C`` will kill the child process without exiting out of my current rshell 23 | 24 | ## Bugs 25 | 26 | * Multiple piping does not work 27 | * piping only works when it is provide with two arguments 28 | * the ``<<<`` will only work by itself, will not work with any other command 29 | * The ``1>, 1>>, 2>, 2>>`` will also only work by itself. 30 | * The only commands that can be combined together is input and output redirection 31 | 32 | 33 | 34 | ##Limitations 35 | * Commands has a limit of 50,000 characters 36 | * host have a name character limit of 500 characters 37 | * every command in the piping assignment other than input and output redirection can only be used by itself 38 | * piping can only take in two arguments 39 | * <<< command only works by itself 40 | * file descriptor change to stderr only works when used by itself 41 | * `` cat < existingInputFile | tr A-Z a-z | tee newOutputfile1 | tr a-z A-Z > newOutputFile2`` this does not work 42 | * Make file is not attached to other functions like rm, cp, or ls. Will fix in future so make file and deal with other functionality 43 | 44 | -------------------------------------------------------------------------------- /tests/ls.script: -------------------------------------------------------------------------------- 1 | Script started on Fri 01 May 2015 09:04:36 PM PDT 2 | ~ 3 | hkwan003@hammer $ cd CS100/ 4 | ~/CS100 5 | hkwan003@hammer $ ls 6 | Lab1/ Lab2/ Lab3/ rshell/ 7 | ~/CS100 8 | hkwan003@hammer $ cd Rrshell/ 9 | ~/CS100/rshell 10 | hkwan003@hammer $ ls 11 | bin/ LICENSE Makefile README.md src/ tests/ 12 | ~/CS100/rshell 13 | hkwan003@hammer $ cd stests/make 14 | mkdir -p ./bin 15 | g++ ./src/ls.cpp -o ./bin/ls 16 | ~/CS100/rshell 17 | hkwan003@hammer $ bin/ls -a 18 | . .. .git bin LICENSE Makefile README.md src tests 19 | ~/CS100/rshell 20 | hkwan003@hammer $ bin/ls 21 | Nothing passed in to argv. 22 | ~/CS100/rshell 23 | hkwan003@hammer $ bin/ls -R 24 | . .. .git bin LICENSE Makefile README.md src tests 25 | ~/CS100/rshell 26 | hkwan003@hammer $ bin/ls - 27 | . .. .git bin LICENSE Makefile README.md src tests 28 | ~/CS100/rshell 29 | hkwan003@hammer $ Abin/ls -AalR 30 | . .. .git bin LICENSE Makefile README.md src tests 31 | ~/CS100/rshell 32 | hkwan003@hammer $ bin/ls -la 33 | . .. .git bin LICENSE Makefile README.md src tests 34 | ~/CS100/rshell 35 | hkwan003@hammer $ bin/ls #nothing else works but ls -a 36 | Nothing passed in to argv. 37 | ~/CS100/rshell 38 | hkwan003@hammer $ bin/ls #at least it is in alpahabetica lol order 39 | Nothing passed in to argv. 40 | ~/CS100/rshell 41 | hkwan003@hammer $ bin/ls #starting-Aa src 42 | . .. .git bin LICENSE Makefile README.md src tests . . .. .. .git .git bin bin LICENSE LICENSE Makefile Makefile README.md README.md src src tests tests 43 | ~/CS100/rshell 44 | hkwan003@hammer $ bin/ls -`~ 45 | . .. .git bin LICENSE Makefile README.md src tests 46 | ~/CS100/rshell 47 | hkwan003@hammer $ bin/ls a-s #a any#any tsarugment makes it output ls-a 48 | . .. .git bin LICENSE Makefile README.md src tests 49 | ~/CS100/rshell 50 | hkwan003@hammer $ exit 51 | exit 52 | 53 | Script done on Fri 01 May 2015 09:06:22 PM PDT 54 | -------------------------------------------------------------------------------- /src/rm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | string convert(const char * data){return string(data);} 13 | bool containsR(int argc, char * argv[]){ 14 | string c = ""; 15 | for(int i = 0; i < argc; i++){c +=convert(argv[i]);} 16 | for (unsigned i = 0; i < c.size(); i++){ 17 | if (i+1 < c.size() && c.at(i) == '-' && c.at(i+1) == 'r'){ 18 | return true; 19 | } 20 | } 21 | return false; 22 | } 23 | 24 | void rmRdir (const char * file){ 25 | struct stat s; 26 | if (stat(file, &s) == -1){ perror("Failed to get shit");} 27 | bool directory = (S_ISDIR(s.st_mode)); 28 | if (directory){ 29 | DIR * dirp; 30 | if (NULL == (dirp = opendir(const_cast(file)))){ perror("Error opening directory");} 31 | struct dirent * filespecs; 32 | while (NULL != (filespecs = readdir(dirp))){ 33 | if (strcmp(filespecs->d_name, ".") == 0 || strcmp(filespecs->d_name, "..") == 0){ 34 | continue; 35 | } 36 | string new_file = file; new_file.append("/"); new_file.append(filespecs->d_name); 37 | rmRdir(new_file.c_str()); 38 | } 39 | int status; status = rmdir(file); 40 | if (status == -1){ cout << file << endl; perror("Failed to delete directory");} 41 | } 42 | else { unlink(file);} 43 | } 44 | void removeShit(int argc, char * argv[], bool containsR){ 45 | 46 | for (int i = 1; i < argc; i++){ 47 | // Gathers that status of a file/directory 48 | struct stat s; 49 | if (stat(argv[i], &s) == 1){ perror("There was an error gathering total");exit(1);} 50 | if (S_ISDIR(s.st_mode) == -1){ perror(argv[i]); exit(1);} 51 | // If it is a directory AND it does NOT contains the -r flag then DO NOT DELETE 52 | if (S_ISDIR(s.st_mode)){ 53 | if (containsR && !S_ISREG(s.st_mode) && S_ISDIR(s.st_mode)){ 54 | // recursively delete 55 | // cout << "Recursively delete! " << argv[i] << endl; 56 | if (strcmp(argv[i], "-r") == 0){continue;} 57 | rmRdir(argv[i]); 58 | continue; 59 | } 60 | else { 61 | cout << "Warning! You are attempting to remove a directory" << endl; 62 | continue; 63 | } 64 | } 65 | if (!S_ISREG(s.st_mode)) 66 | { 67 | perror(" file doesn not exist" ); 68 | exit(1); 69 | } 70 | if (S_ISREG(s.st_mode) && !(S_ISDIR(s.st_mode))){ 71 | if (unlink(argv[i]) == -1){ perror("shit went wrong"); exit(1);} 72 | } 73 | } 74 | } 75 | int main (int argc, char * argv[] ){ 76 | if (argc <= 1) {cout << "Not enough arguments!" << endl; return 0;} 77 | bool containsFlagR = containsR(argc, argv); 78 | removeShit(argc, argv, containsFlagR); 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /src/Timer.h: -------------------------------------------------------------------------------- 1 | 2 | /* C++ interface for program benchmark timer management. */ 3 | #include 4 | #include 5 | #include 6 | 7 | // extern "C" int gettimeofday(timeval *tp, void *tzp); 8 | // extern "C" int getrusage(int who, struct rusage *rusag); 9 | 10 | class Timer 11 | { 12 | public: 13 | int start(); 14 | int elapsedWallclockTime (double &); 15 | int elapsedUserTime (double &); 16 | int elapsedSystemTime (double &); 17 | int elapsedTime (double &wc, double &us, double &system); 18 | 19 | private: 20 | rusage old_us_time; 21 | rusage new_us_time; 22 | timeval old_wc_time; 23 | timeval new_wc_time; 24 | }; 25 | 26 | 27 | int 28 | Timer::start() 29 | { 30 | if (gettimeofday (&this->old_wc_time, 0) == -1 31 | || getrusage (RUSAGE_SELF, &this->old_us_time) == -1) 32 | return -1; 33 | else 34 | return 0; 35 | } 36 | 37 | int 38 | Timer::elapsedWallclockTime (double &wc) 39 | { 40 | if (gettimeofday (&this->new_wc_time, 0) == -1) 41 | return -1; 42 | wc = (this->new_wc_time.tv_sec - this->old_wc_time.tv_sec) 43 | + (this->new_wc_time.tv_usec - this->old_wc_time.tv_usec) / 1000000.0; 44 | return 0; 45 | } 46 | 47 | int 48 | Timer::elapsedUserTime (double &ut) 49 | { 50 | if (getrusage (RUSAGE_SELF, &this->new_us_time) == -1) 51 | return -1; 52 | 53 | ut = (this->new_us_time.ru_utime.tv_sec - this->old_us_time.ru_utime.tv_sec) 54 | + ((this->new_us_time.ru_utime.tv_usec 55 | - this->old_us_time.ru_utime.tv_usec) / 1000000.0); 56 | return 0; 57 | } 58 | 59 | int 60 | Timer::elapsedSystemTime (double &st) 61 | { 62 | if (getrusage (RUSAGE_SELF, &this->new_us_time) == -1) 63 | return -1; 64 | 65 | st = (this->new_us_time.ru_stime.tv_sec - this->old_us_time.ru_stime.tv_sec) 66 | + ((this->new_us_time.ru_stime.tv_usec 67 | - this->old_us_time.ru_stime.tv_usec) / 1000000.0); 68 | return 0; 69 | } 70 | 71 | int 72 | Timer::elapsedTime (double &wallclock, double &user_time, double &system_time) 73 | { 74 | if (this->elapsedWallclockTime (wallclock) == -1) 75 | return -1; 76 | else 77 | { 78 | if (getrusage (RUSAGE_SELF, &this->new_us_time) == -1) 79 | return -1; 80 | user_time = (this->new_us_time.ru_utime.tv_sec 81 | - this->old_us_time.ru_utime.tv_sec) 82 | + ((this->new_us_time.ru_utime.tv_usec 83 | - this->old_us_time.ru_utime.tv_usec) / 1000000.0); 84 | 85 | system_time = (this->new_us_time.ru_stime.tv_sec 86 | - this->old_us_time.ru_stime.tv_sec) 87 | + ((this->new_us_time.ru_stime.tv_usec 88 | - this->old_us_time.ru_stime.tv_usec) / 1000000.0); 89 | 90 | return 0; 91 | } 92 | } 93 | 94 | /* Example of use 95 | 96 | #include "Timer.h" 97 | #include 98 | 99 | int main() 100 | { 101 | Timer t; 102 | double eTime; 103 | t.start(); 104 | for (int i=0, j; i<1000000000; i++) 105 | j++; 106 | t.elapsedUserTime(eTime); 107 | cout << eTime << endl; 108 | } 109 | */ 110 | -------------------------------------------------------------------------------- /tests/piping2.script: -------------------------------------------------------------------------------- 1 | Script started on Sun 17 May 2015 09:46:16 PM PDT 2 | ~ 3 | hkwan003@hammer $ cs100 4 |  5 | =============================================================================== 6 | | | 7 | | You have enabled settings specific for cs100. Everything you do is being | 8 | | recorded to measure your progress in the class. | 9 | | | 10 | | Important commands for the class: | 11 | | * calcgrade.sh displays a detailed breakdown of your grade | 12 | | * checksyscalls.sh is your cpp file doing proper error checking? | 13 | | * typespeed practice typing unix commands | 14 | | | 15 | | Important commands for general C++ programming: | 16 | | * make don't call g++ manually; let make do the work! | 17 | | * gdb the GNU debugger | 18 | | * valgrind get rid of your memory leaks | 19 | | * cppcheck static analysis tool | 20 | | * man find help about any syscall / terminal command | 21 | | | 22 | =============================================================================== 23 |  24 | %%%%%%%%%%hkwan003@cs100:~ $ make clean 25 | mmake: *** No rule to make target `clean'. Stop. 26 | %%%%%%%%%%hkwan003@cs100:~ $ make 27 | make: *** No targets specified and no makefile found. Stop. 28 | %%%%%%%%%%hkwan003@cs100:~ $ ls 29 | 61 FOLDEER CS100 cs12 CS61 Documents gitlearn Pictures quiz rshell-1 tester_files WINDOWS 30 | calvin cs100#1 CS-14 Desktop Downloads Music Public rshell Templates Videos 31 | %%%%%%%%%%hkwan003@cs100:~ $ cd rshell 32 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ ls 33 | LICENSE Makefile README.md src tests 34 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ make 35 | mkdir -p ./bin 36 | g++ ./src/new.cpp -o ./bin/redirect 37 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ bin/redirect 38 | hkwan003@hammer.cs.ucr.edu $ cat <<< "  "hi output this string" 39 | hi output this string 40 | hkwan003@hammer.cs.ucr.edu $ cout       <<<   cat << '  < "a yay thi so   s outputted" 41 | yay this outputted 42 | hkwan003@hammer.cs.ucr.edu $ exit 43 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ exit 44 | exit 45 | ~ 46 | hkwan003@hammer $ exit 47 | exit 48 | 49 | Script done on Sun 17 May 2015 09:47:02 PM PDT 50 | -------------------------------------------------------------------------------- /src/cp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "Timer.h" 10 | using namespace std; 11 | 12 | int main( int argc, char *argv[] ){ 13 | // if not enough arguments then exit 14 | if ( argc < 3 ) { 15 | cout << "Error! Not enough arguments." << endl; 16 | exit(1); 17 | } 18 | // if optional flag is passed in 19 | if ( argc == 4 ){ 20 | 21 | 22 | 23 | 24 | Timer one; 25 | double oneusrTime; 26 | double onewallTime; 27 | double onesysTime; 28 | one.start(); 29 | //=======================FIRST ONE============================= 30 | cout << "Using istream and ostream" << endl; 31 | //Open file 32 | ifstream fin(argv[1]); 33 | if(!fin.is_open()){ 34 | cout << "Error opening source file" << endl; 35 | exit(1); 36 | } 37 | ifstream fcheck(argv[2]); 38 | if(fcheck.is_open()){ 39 | cout << "Error! Dest file already exists!" << endl; 40 | exit(1); 41 | } 42 | ofstream fout(argv[2]); 43 | 44 | char c; 45 | while (fin.get(c)){ 46 | fout.put(c); 47 | } 48 | fin.close(); 49 | fout.close(); 50 | one.elapsedTime(onewallTime, oneusrTime, onesysTime); 51 | cout << "First Method: " << endl; 52 | cout << "\tWall time: " << onewallTime << endl; 53 | cout << "\tUser time: " << oneusrTime << endl; 54 | cout << "\tSystem time: " << onesysTime << endl << endl; 55 | 56 | 57 | //=========================SECOND ONE=========================== 58 | cout << "Using read() and write()" << endl; 59 | Timer two; 60 | double twousr; 61 | double twowall; 62 | double twosys; 63 | two.start(); 64 | int fdnew; 65 | int fdold; 66 | if(-1 == (fdnew = open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR))) 67 | { 68 | perror("Open"); 69 | exit(1); 70 | } 71 | if(-1 == (fdold = open(argv[1], O_RDONLY))) 72 | { 73 | perror("Open"); 74 | exit(1); 75 | } 76 | int size; 77 | char d; 78 | if(-1 == (size = read(fdold, &d, 1))) 79 | { 80 | perror("Write"); 81 | exit(1); 82 | } 83 | while(size > 0) 84 | { 85 | if(-1 == write(fdnew,&d,size)) 86 | { 87 | perror("write"); 88 | exit(1); 89 | } 90 | if(-1 == (size = read(fdold,&d,1))) 91 | { 92 | perror("read"); 93 | exit(1); 94 | } 95 | } 96 | if(-1 == close(fdnew)) 97 | { 98 | perror("close"); 99 | exit(1); 100 | } 101 | if(-1 == close(fdold)) 102 | { 103 | perror("close"); 104 | exit(1); 105 | } 106 | two.elapsedTime(twowall,twousr,twosys); 107 | cout << "Second Method: " << endl; 108 | cout << "\tWall time: " << twowall << endl; 109 | cout << "\tUser time: " << twousr << endl; 110 | cout << "\tSystem time: " << twosys << endl << endl; 111 | 112 | 113 | //==========================THIRD ONE============================== 114 | cout << "Using read() and write() W/ Buffer" << endl; 115 | //int fdnew; 116 | //int fdold; 117 | Timer three; 118 | double threeusr; 119 | double threewall; 120 | double threesys; 121 | three.start(); 122 | 123 | 124 | if(-1 == (fdnew = open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR))) 125 | { 126 | perror("Open"); 127 | exit(1); 128 | } 129 | if(-1 == (fdold = open(argv[1], O_RDONLY))) 130 | { 131 | perror("Open"); 132 | exit(1); 133 | } 134 | // int size; 135 | char e[BUFSIZ]; 136 | if(-1 == (size = read(fdold, e, sizeof(e)))) 137 | { 138 | perror("Write"); 139 | exit(1); 140 | } 141 | while(size > 0) 142 | { 143 | if(-1 == write(fdnew,e,size)) 144 | { 145 | perror("write"); 146 | exit(1); 147 | } 148 | if(-1 == (size = read(fdold,e,sizeof(e)))) 149 | { 150 | perror("read"); 151 | exit(1); 152 | } 153 | } 154 | if(-1 == close(fdnew)) 155 | { 156 | perror("close"); 157 | exit(1); 158 | } 159 | if(-1 == close(fdold)) 160 | { 161 | perror("close"); 162 | exit(1); 163 | } 164 | 165 | three.elapsedTime(threewall,threeusr,threesys); 166 | cout << "Third Method: " << endl; 167 | cout << "\tWall time: " << threewall << endl; 168 | cout << "\tUser time: " << threeusr << endl; 169 | cout << "\tSystem time: " << threesys << endl << endl; 170 | 171 | 172 | 173 | } 174 | // else run fastest one 175 | else{ 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | cout << "Using read() and write() W/ Buffer" << endl; 188 | int fdnew; 189 | int fdold; 190 | if(-1 == (fdnew = open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR))) 191 | { 192 | perror("Open"); 193 | exit(1); 194 | } 195 | if(-1 == (fdold = open(argv[1], O_RDONLY))) 196 | { 197 | perror("Open"); 198 | exit(1); 199 | } 200 | int size; 201 | char c[BUFSIZ]; 202 | if(-1 == (size = read(fdold, c, sizeof(c)))) 203 | { 204 | perror("Write"); 205 | exit(1); 206 | } 207 | while(size > 0) 208 | { 209 | if(-1 == write(fdnew,c,size)) 210 | { 211 | perror("write"); 212 | exit(1); 213 | } 214 | if(-1 == (size = read(fdold,c,sizeof(c)))) 215 | { 216 | perror("read"); 217 | exit(1); 218 | } 219 | } 220 | if(-1 == close(fdnew)) 221 | { 222 | perror("close"); 223 | exit(1); 224 | } 225 | if(-1 == close(fdold)) 226 | { 227 | perror("close"); 228 | exit(1); 229 | } 230 | 231 | } 232 | return 0; 233 | } 234 | -------------------------------------------------------------------------------- /src/ls.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | using namespace std; 19 | 20 | string filePermission(mode_t file) 21 | { 22 | string file_permiss; 23 | if(S_ISDIR(file)){file_permiss.push_back('d');} 24 | else if(S_ISBLK(file)){file_permiss.push_back('b');} 25 | else if(S_ISCHR(file)){file_permiss.push_back('c');} 26 | else if(S_ISLNK(file)){file_permiss.push_back('l');} 27 | else if(S_ISFIFO(file)) {file_permiss.push_back('p');} 28 | else if(S_ISSOCK(file)) {file_permiss.push_back('s');} 29 | if(file & S_IRUSR) {file_permiss.push_back('r');} 30 | else{file_permiss.push_back('-');} 31 | if(file & S_IWUSR){file_permiss.push_back('w');} 32 | else{file_permiss.push_back('-');} 33 | if(file & S_IXUSR){file_permiss.push_back('x');} 34 | else{file_permiss.push_back('-');} 35 | if(file & S_IRGRP){file_permiss.push_back('r');} 36 | else {file_permiss.push_back('-');} 37 | if(file & S_IWGRP){file_permiss.push_back('w');} 38 | else {file_permiss.push_back('-');} 39 | if(file & S_IXGRP) {file_permiss.push_back('x');} 40 | else {file_permiss.push_back('-');} 41 | if(file & S_IROTH) {file_permiss.push_back('r');} 42 | else {file_permiss.push_back('-');} 43 | if(file & S_IWOTH) {file_permiss.push_back('w');} 44 | else {file_permiss.push_back('-');} 45 | if(file & S_IXOTH) {file_permiss.push_back('x');} 46 | else {file_permiss.push_back('-');} 47 | return file_permiss; 48 | } 49 | bool alphabetical(string c1, string c2) 50 | { 51 | for(unsigned int i = 0; i < c1.size(); i++) 52 | { 53 | c1.at(i) = tolower(c1.at(i)); 54 | } 55 | for(unsigned int i = 0; i < c2.size(); i++) 56 | { 57 | c2.at(i) = tolower(c2.at(i)); 58 | } 59 | return c1.compare(c2) < 0; 60 | } 61 | string displayColorText(mode_t m, string filename) 62 | { 63 | string color; 64 | string bg = "49"; 65 | if (S_ISDIR(m)) color = "34"; 66 | else if (m & S_IXUSR) color = "32"; 67 | else if (S_ISBLK(m)) color = "33"; 68 | else if (S_ISCHR(m)) color = "35"; 69 | else if (S_ISLNK(m)) color = "31"; 70 | else if (S_ISFIFO(m)) color = "36"; 71 | else if (S_ISSOCK(m)) color = "92"; 72 | if (filename.at(0) == '.') bg = "100"; 73 | return "\033[1;" + bg + ";" + color + "m" + filename + "\033[0;00m"; 74 | } 75 | 76 | 77 | void execute(vector filenames, const vector flags, string currentpath, stack &final_change) 78 | { 79 | struct stat info; 80 | int totalblocks = 0; 81 | for (unsigned i = 0; i < filenames.size(); ++i) 82 | { 83 | if (filenames[i].at(0) != '.' || flags[0]) 84 | { 85 | string updatedpath(currentpath + "/" + filenames[i]); 86 | if (stat(updatedpath.c_str(), &info) != 0) 87 | { 88 | perror("Error with stat()"); 89 | exit(1); 90 | } 91 | if (flags[2] && S_ISDIR(info.st_mode) && filenames[i] != "." && filenames[i] != "..") 92 | { 93 | final_change.push(updatedpath); 94 | } 95 | if (flags[1]) 96 | { 97 | cout << filePermission(info.st_mode) << "\t"; 98 | cout << info.st_nlink << "\t"; 99 | struct passwd userinfo = *getpwuid(info.st_uid); 100 | if (&userinfo == NULL) 101 | { 102 | perror("Error with getpwuid()"); 103 | exit(1); 104 | } 105 | cout << userinfo.pw_name << "\t"; 106 | struct group groupinfo = *getgrgid(info.st_gid); 107 | if (&groupinfo == NULL) 108 | { 109 | perror("Error with getgrgid()"); 110 | exit(1); 111 | } 112 | cout << groupinfo.gr_name << "\t"; 113 | cout << info.st_size << "\t"; 114 | char* timeinfo = ctime(&info.st_mtime); 115 | if (timeinfo == NULL) 116 | { 117 | perror("Error with ctime()"); 118 | exit(1); 119 | } 120 | string displaytime(timeinfo); 121 | cout << displaytime.substr(4, 12) << "\t"; 122 | totalblocks += info.st_blocks; 123 | } 124 | if(flags[1] || flags[2]) 125 | { 126 | cout << displayColorText(info.st_mode, filenames[i]) << endl; 127 | } 128 | else 129 | { 130 | cout << displayColorText(info.st_mode, filenames[i]) << " "; 131 | } 132 | } 133 | } 134 | if (flags[1]) 135 | { 136 | cout << "Total blocks: " << totalblocks / 2 << endl; 137 | } 138 | if(!flags[1] || !flags[2]) 139 | { 140 | cout << endl; 141 | } 142 | } 143 | void string_parse(char *prompt, vector &flag_hold, vector &pathnames) 144 | { 145 | if(prompt[0] == '-') 146 | { 147 | if(prompt[1] == '\0') 148 | {cout << "Error: please input in more arguments" << endl;} 149 | for(int x = 1; prompt[x] != '\0'; x++) 150 | { 151 | if(prompt[x] == 'a') 152 | {flag_hold[0] = true;} 153 | else if(prompt[x] == 'l') 154 | {flag_hold[1] = true;} 155 | else if(prompt[x] == 'R') 156 | {flag_hold[2] = true;} 157 | } 158 | } 159 | else 160 | { 161 | string convert(prompt); 162 | pathnames.push_back(convert); 163 | } 164 | } 165 | 166 | vector paths; 167 | vector filenames; 168 | stack final_change; 169 | string directory_name; 170 | int main(int argc, char *argv[]) 171 | { 172 | vector flags(false); //initalizes all vector to be false 173 | for(unsigned int x = 0; x < 3; x++){flags.push_back(false);} 174 | if (argc > 1) 175 | { 176 | for (int i = 1; i < argc; ++i) 177 | { 178 | string_parse(argv[i], flags, paths); 179 | } 180 | } 181 | if(paths.size() == 0){paths.push_back(".");} 182 | dirent *readfile; 183 | for (int i = paths.size() - 1; i >= 0; --i) 184 | { 185 | final_change.push(paths[i]); 186 | } 187 | while (!final_change.empty()) 188 | { 189 | directory_name = final_change.top(); 190 | final_change.pop(); 191 | DIR *dirp = opendir(directory_name.c_str()); 192 | if (dirp == NULL) 193 | { 194 | perror("Error with opendir()"); 195 | exit(1); 196 | } 197 | while((readfile = readdir(dirp))) 198 | { 199 | if (readfile < 0) 200 | { 201 | perror("Error with readdir()"); 202 | exit(1); 203 | } 204 | string s(readfile->d_name); 205 | filenames.push_back(s); 206 | } 207 | sort(filenames.begin(), filenames.end(), alphabetical);//sorts directories and files in vector alphabetcially 208 | execute(filenames, flags, directory_name, final_change); 209 | if (closedir(dirp) == -1) 210 | { 211 | perror("Error with closedir()"); 212 | exit(1); 213 | } 214 | filenames.clear(); 215 | if (!final_change.empty()) 216 | { 217 | cout << endl; 218 | } 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /src/new.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | using namespace std; 19 | 20 | string filePermission(mode_t file) 21 | { 22 | string file_permiss; 23 | if(S_ISDIR(file)){file_permiss.push_back('d');} 24 | else if(S_ISBLK(file)){file_permiss.push_back('b');} 25 | else if(S_ISCHR(file)){file_permiss.push_back('c');} 26 | else if(S_ISLNK(file)){file_permiss.push_back('l');} 27 | else if(S_ISFIFO(file)) {file_permiss.push_back('p');} 28 | else if(S_ISSOCK(file)) {file_permiss.push_back('s');} 29 | if(file & S_IRUSR) {file_permiss.push_back('r');} 30 | else{file_permiss.push_back('-');} 31 | if(file & S_IWUSR){file_permiss.push_back('w');} 32 | else{file_permiss.push_back('-');} 33 | if(file & S_IXUSR){file_permiss.push_back('x');} 34 | else{file_permiss.push_back('-');} 35 | if(file & S_IRGRP){file_permiss.push_back('r');} 36 | else {file_permiss.push_back('-');} 37 | if(file & S_IWGRP){file_permiss.push_back('w');} 38 | else {file_permiss.push_back('-');} 39 | if(file & S_IXGRP) {file_permiss.push_back('x');} 40 | else {file_permiss.push_back('-');} 41 | if(file & S_IROTH) {file_permiss.push_back('r');} 42 | else {file_permiss.push_back('-');} 43 | if(file & S_IWOTH) {file_permiss.push_back('w');} 44 | else {file_permiss.push_back('-');} 45 | if(file & S_IXOTH) {file_permiss.push_back('x');} 46 | else {file_permiss.push_back('-');} 47 | return file_permiss; 48 | } 49 | bool alphabetical(string c1, string c2) 50 | { 51 | for(unsigned int i = 0; i < c1.size(); i++) 52 | { 53 | c1.at(i) = tolower(c1.at(i)); 54 | } 55 | for(unsigned int i = 0; i < c2.size(); i++) 56 | { 57 | c2.at(i) = tolower(c2.at(i)); 58 | } 59 | return c1.compare(c2) < 0; 60 | } 61 | string displayColorText(mode_t m, string filename) 62 | { 63 | string color; 64 | string bg = "49"; 65 | if (S_ISDIR(m)) color = "34"; 66 | else if (m & S_IXUSR) color = "32"; 67 | else if (S_ISBLK(m)) color = "33"; 68 | else if (S_ISCHR(m)) color = "35"; 69 | else if (S_ISLNK(m)) color = "31"; 70 | else if (S_ISFIFO(m)) color = "36"; 71 | else if (S_ISSOCK(m)) color = "92"; 72 | if (filename.at(0) == '.') bg = "100"; 73 | return "\033[1;" + bg + ";" + color + "m" + filename + "\033[0;00m"; 74 | } 75 | 76 | 77 | void execute(vector filenames, const vector flags, string currentpath, stack &final_change) 78 | { 79 | struct stat info; 80 | int totalblocks = 0; 81 | for (unsigned i = 0; i < filenames.size(); ++i) 82 | { 83 | if (filenames[i].at(0) != '.' || flags[0]) 84 | { 85 | string updatedpath(currentpath + "/" + filenames[i]); 86 | if (stat(updatedpath.c_str(), &info) != 0) 87 | { 88 | perror("Error with stat()"); 89 | exit(1); 90 | } 91 | if (flags[2] && S_ISDIR(info.st_mode) && filenames[i] != "." && filenames[i] != "..") 92 | { 93 | final_change.push(updatedpath); 94 | } 95 | if (flags[1]) 96 | { 97 | cout << filePermission(info.st_mode) << "\t"; 98 | cout << info.st_nlink << "\t"; 99 | struct passwd userinfo = *getpwuid(info.st_uid); 100 | if (&userinfo == NULL) 101 | { 102 | perror("Error with getpwuid()"); 103 | exit(1); 104 | } 105 | cout << userinfo.pw_name << "\t"; 106 | struct group groupinfo = *getgrgid(info.st_gid); 107 | if (&groupinfo == NULL) 108 | { 109 | perror("Error with getgrgid()"); 110 | exit(1); 111 | } 112 | cout << groupinfo.gr_name << "\t"; 113 | cout << info.st_size << "\t"; 114 | char* timeinfo = ctime(&info.st_mtime); 115 | if (timeinfo == NULL) 116 | { 117 | perror("Error with ctime()"); 118 | exit(1); 119 | } 120 | string displaytime(timeinfo); 121 | cout << displaytime.substr(4, 12) << "\t"; 122 | totalblocks += info.st_blocks; 123 | } 124 | if(!flags[1] || !flags[2]) 125 | { 126 | cout << displayColorText(info.st_mode, filenames[i]) << " "; 127 | } 128 | else 129 | { 130 | cout << displayColorText(info.st_mode, filenames[i]) << endl; 131 | } 132 | } 133 | } 134 | if (flags[1]) 135 | { 136 | cout << "Total blocks: " << totalblocks / 2 << endl; 137 | } 138 | if(!flags[1] || !flags[2]) 139 | { 140 | cout << endl; 141 | } 142 | } 143 | void string_parse(char *prompt, vector &flag_hold, vector &pathnames) 144 | { 145 | if(prompt[0] == '-') 146 | { 147 | if(prompt[1] == '\0') 148 | {cout << "Error: please input in more arguments" << endl;} 149 | for(int x = 1; prompt[x] != '\0'; x++) 150 | { 151 | if(prompt[x] == 'a') 152 | {flag_hold[0] = true;} 153 | else if(prompt[x] == 'l') 154 | {flag_hold[1] = true;} 155 | else if(prompt[x] == 'R') 156 | {flag_hold[2] = true;} 157 | } 158 | } 159 | else 160 | { 161 | string convert(prompt); 162 | pathnames.push_back(convert); 163 | } 164 | } 165 | 166 | vector paths; 167 | vector filenames; 168 | stack final_change; 169 | string directory_name; 170 | int main(int argc, char *argv[]) 171 | { 172 | vector flags(false); //initalizes all vector to be false 173 | for(unsigned int x = 0; x < 3; x++){flags.push_back(false);} 174 | if (argc > 1) 175 | { 176 | for (int i = 1; i < argc; ++i) 177 | { 178 | string_parse(argv[i], flags, paths); 179 | } 180 | } 181 | if(paths.size() == 0){paths.push_back(".");} 182 | dirent *readfile; 183 | for (int i = paths.size() - 1; i >= 0; --i) 184 | { 185 | final_change.push(paths[i]); 186 | } 187 | while (!final_change.empty()) 188 | { 189 | directory_name = final_change.top(); 190 | final_change.pop(); 191 | DIR *dirp = opendir(directory_name.c_str()); 192 | if (dirp == NULL) 193 | { 194 | perror("Error with opendir()"); 195 | exit(1); 196 | } 197 | while((readfile = readdir(dirp))) 198 | { 199 | if (readfile < 0) 200 | { 201 | perror("Error with readdir()"); 202 | exit(1); 203 | } 204 | string s(readfile->d_name); 205 | filenames.push_back(s); 206 | } 207 | sort(filenames.begin(), filenames.end(), alphabetical);//sorts directories and files in vector alphabetcially 208 | execute(filenames, flags, directory_name, final_change); 209 | if (closedir(dirp) == -1) 210 | { 211 | perror("Error with closedir()"); 212 | exit(1); 213 | } 214 | filenames.clear(); 215 | if (!final_change.empty()) 216 | { 217 | cout << endl; 218 | } 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /tests/exec.script: -------------------------------------------------------------------------------- 1 | Script started on Sun 19 Apr 2015 11:27:55 PM PDT 2 | ~ 3 | hkwan003@hammer $ cs100 4 |  5 | =============================================================================== 6 | | | 7 | | You have enabled settings specific for cs100. Everything you do is being | 8 | | recorded to measure your progress in the class. | 9 | | | 10 | | Important commands for the class: | 11 | | * calcgrade.sh displays a detailed breakdown of your grade | 12 | | * typespeed practice typing unix commands | 13 | | | 14 | | Important commands for general C++ programming: | 15 | | * make don't call g++ manually; let make do the work! | 16 | | * gdb the GNU debugger | 17 | | * valgrind get rid of your memory leaks | 18 | | * cppcheck static analysis tool | 19 | | * man find help about any syscall / terminal command | 20 | | | 21 | =============================================================================== 22 |  23 | %%%%%%%%%%hkwan003@cs100:~ $ ls 24 | c61 FOLDEER CS100 CS-14 Desktop Downloads Music Public Templates WINDOWS 25 | calvin cs12 CS61 Documents gitlearn Pictures quiz Videos 26 | %%%%%%%%%%hkwan003@cs100:~ $ cd CS100/ 27 | %%%%%%%%%%hkwan003@cs100:~/CS100 $ ls 28 | Lab1 Lab2 rshell 29 | %%%%%%%%%%hkwan003@cs100:~/CS100 $ cd rshell/ 30 | %%%%%%%%%%hkwan003@cs100:~/CS100/rshell (exec) $ ls 31 | LICENSE main.cpp Makefile README.md src tests 32 | %%%%%%%%%%hkwan003@cs100:~/CS100/rshell (exec) $ make 33 | mkdir -p ./bin 34 | g++ ./src/main.cpp -o ./bin/rshell 35 | %%%%%%%%%%hkwan003@cs100:~/CS100/rshell (exec) $ bin/rshell 36 | hkwan003@hammer.cs.ucr.edu $ ls 37 | bin LICENSE main.cpp Makefile README.md src tests 38 | hkwan003@hammer.cs.ucr.edu $ ls -a 39 | . .. bin .git LICENSE main.cpp Makefile README.md src tests 40 | hkwan003@hammer.cs.ucr.edu $ ls ;;; la 41 | bin LICENSE main.cpp Makefile README.md src tests 42 | error with passed in argument list: No such file or directory 43 | hkwan003@hammer.cs.ucr.edu $ ls ;; ls -a 44 | bin LICENSE main.cpp Makefile README.md src tests 45 | . .. bin .git LICENSE main.cpp Makefile README.md src tests 46 | hkwan003@hammer.cs.ucr.edu $ ls -l -l -l -l -l -l -l -l ls 47 | ls: cannot access ls: No such file or directory 48 | hkwan003@hammer.cs.ucr.edu $ ls -l -l -l -l -l -l; ls 49 | total 24 50 | drwx------ 2 hkwan003 csmajs 4096 Apr 19 23:22 bin 51 | -rw------- 1 hkwan003 csmajs 1079 Apr 19 22:28 LICENSE 52 | -rw------- 1 hkwan003 csmajs 1052 Apr 19 22:11 main.cpp 53 | -rw------- 1 hkwan003 csmajs 261 Apr 19 23:00 Makefile 54 | -rw------- 1 hkwan003 csmajs 28 Apr 14 12:09 README.md 55 | drwx------ 2 hkwan003 csmajs 4096 Apr 19 23:21 src 56 | drwx------ 2 hkwan003 csmajs 4096 Apr 19 23:22 tests 57 | bin LICENSE main.cpp Makefile README.md src tests 58 | hkwan003@hammer.cs.ucr.edu $ ls -l -l #spaces a  nd tabs 59 | total 24 60 | drwx------ 2 hkwan003 csmajs 4096 Apr 19 23:22 bin 61 | -rw------- 1 hkwan003 csmajs 1079 Apr 19 22:28 LICENSE 62 | -rw------- 1 hkwan003 csmajs 1052 Apr 19 22:11 main.cpp 63 | -rw------- 1 hkwan003 csmajs 261 Apr 19 23:00 Makefile 64 | -rw------- 1 hkwan003 csmajs 28 Apr 14 12:09 README.md 65 | drwx------ 2 hkwan003 csmajs 4096 Apr 19 23:21 src 66 | drwx------ 2 hkwan003 csmajs 4096 Apr 19 23:22 tests 67 | hkwan003@hammer.cs.ucr.edu $ echo hi && echo good bye 68 | hi 69 | good bye 70 | hkwan003@hammer.cs.ucr.edu $ echo hi || go  echo good bye 71 | hi 72 | hkwan003@hammer.cs.ucr.edu $ echo false ||               false || echo good bye 73 | hkwan003@hammer.cs.ucr.edu $ ls 74 | bin LICENSE main.cpp Makefile README.md src tests 75 | hkwan003@hammer.cs.ucr.edu $ ; #incorrectlly      characters 76 | hkwan003@hammer.cs.ucr.edu $ true ; ls #connectors 77 | bin LICENSE main.cpp Makefile README.md src tests 78 | hkwan003@hammer.cs.ucr.edu $ true || ls #\ || conectors 79 | hkwan003@hammer.cs.ucr.edu $ false && ls 80 | bin LICENSE main.cpp Makefile README.md src tests 81 | hkwan003@hammer.cs.ucr.edu $ false && ls #otu  utputs i as error in my code 82 | bin LICENSE main.cpp Makefile README.md src tests 83 | hkwan003@hammer.cs.ucr.edu $ ls #comment will work 84 | bin LICENSE main.cpp Makefile README.md src tests 85 | hkwan003@hammer.cs.ucr.edu $ ls workds 86 | ls: cannot access workds: No such file or directory 87 | hkwan003@hammer.cs.ucr.edu $ alksdjfkaksldf jkjldasfklkljasdklfklasdkflkasjkld #ranc dom 88 | error with passed in argument list: No such file or directory 89 | hkwan003@hammer.cs.ucr.edu $ ls 90 | bin LICENSE main.cpp Makefile README.md src tests 91 | hkwan003@hammer.cs.ucr.edu $ ls ; ls && false || ls; 92 | bin LICENSE main.cpp Makefile README.md src tests 93 | bin LICENSE main.cpp Makefile README.md src tests 94 | hkwan003@hammer.cs.ucr.edu $ #previous op[             echo preb viosly outpu           iously outputted correctly 95 | previously outputted correctly 96 | hkwan003@hammer.cs.ucr.edu $ ls;&&||ls #many connectors 97 | bin LICENSE main.cpp Makefile README.md src tests 98 | error with passed in argument list: No such file or directory 99 | hkwan003@hammer.cs.ucr.edu $ |||||| 100 | error with passed in argument list: No such file or directory 101 | hkwan003@hammer.cs.ucr.edu $ ls 102 | bin LICENSE main.cpp Makefile README.md src tests 103 | hkwan003@hammer.cs.ucr.edu $ mkdir dir 104 | hkwan003@hammer.cs.ucr.edu $ ls 105 | bin dir LICENSE main.cpp Makefile README.md src tests 106 | hkwan003@hammer.cs.ucr.edu $ rm dir 107 | rm: cannot remove `dir': Is a directory 108 | hkwan003@hammer.cs.ucr.edu $ ls 109 | bin dir LICENSE main.cpp Makefile README.md src tests 110 | hkwan003@hammer.cs.ucr.edu $ rmdir r dir 111 | hkwan003@hammer.cs.ucr.edu $ ls 112 | bin LICENSE main.cpp Makefile README.md src tests 113 | hkwan003@hammer.cs.ucr.edu $ exit 114 | %%%%%%%%%%hkwan003@cs100:~/CS100/rshell (exec) $ make clean 115 | rm -rf ./bin 116 | %%%%%%%%%%hkwan003@cs100:~/CS100/rshell (exec) $ make 117 | mkdir -p ./bin 118 | g++ ./src/main.cpp -o ./bin/rshell 119 | %%%%%%%%%%hkwan003@cs100:~/CS100/rshell (exec) $ bin/rshell 120 | hkwan003@hammer.cs.ucr.edu $ ls 121 | bin LICENSE main.cpp Makefile README.md src tests 122 | hkwan003@hammer.cs.ucr.edu $ echo works again 123 | works again 124 | hkwan003@hammer.cs.ucr.edu $ exit 125 | %%%%%%%%%%hkwan003@cs100:~/CS100/rshell (exec) $ clbin /root/ 126 | bash: bin: command not found 127 | %%%%%%%%%%hkwan003@cs100:~/CS100/rshell (exec) $ bin/rshell 128 | hkwan003@hammer.cs.ucr.edu $ clear 129 | hkwan003@hammer.cs.ucr.edu $ exit 130 | %%%%%%%%%%hkwan003@cs100:~/CS100/rshell (exec) $ exit 131 | exit 132 | ~ 133 | hkwan003@hammer $ exit 134 | exit 135 | 136 | Script done on Sun 19 Apr 2015 11:33:14 PM PDT 137 | -------------------------------------------------------------------------------- /tests/signals.script: -------------------------------------------------------------------------------- 1 | Script started on Fri 29 May 2015 09:50:47 PM PDT 2 | ~ 3 | hkwan003@hammer $ ls 4 | 61 FOLDEER/ CS100/ CS-14/ Documents/ hello.cpp Pictures/ rshell-1/ ucr-cs100/ 5 | a.out* cs100#1/ CS61/ Downloads/ ls.cpp Public/ Templates/ Videos/ 6 | calvin/ cs12/ Desktop/ gitlearn/ Music/ quiz/ tester_files/ WINDOWS/ 7 | ~ 8 | hkwan003@hammer $ cd Documents/ 9 | ~/Documents 10 | hkwan003@hammer $ ls 11 | ls.cpp newls.cpp pip.cpp rshell/ 12 | ~/Documents 13 | hkwan003@hammer $ cd rshell/ 14 | ~/Documents/rshell 15 | hkwan003@hammer $ ls 16 | bin/ LICENSE Makefile README.md src/ tests/ 17 | ~/Documents/rshell 18 | hkwan003@hammer $ make clean 19 | rm -rf ./bin 20 | ~/Documents/rshell 21 | hkwan003@hammer $ make 22 | mkdir -p ./bin 23 | g++ ./src/main.cpp -o ./bin/rshell 24 | ~/Documents/rshell 25 | hkwan003@hammer $ bin/rshell 26 | hkwan003@hammer.cs.ucr.edu; /Documents/rshell cd .. 27 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents pwd 28 | /home/csmajs/hkwan003/Documents 29 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents cd .. 30 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd .. 31 | hkwan003@hammer.cs.ucr.edu; home/csmajs cd .. 32 | hkwan003@hammer.cs.ucr.edu; home cd .. 33 | hkwan003@hammer.cs.ucr.edu; cd 34 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd .. 35 | hkwan003@hammer.cs.ucr.edu; home/csmajs cd .. 36 | hkwan003@hammer.cs.ucr.edu; home cd .. 37 | hkwan003@hammer.cs.ucr.edu; cd .. 38 | hkwan003@hammer.cs.ucr.edu; c   cd ~ 39 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd - 40 | hkwan003@hammer.cs.ucr.edu; cd 41 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd ~ 42 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd .. 43 | hkwan003@hammer.cs.ucr.edu; home/csmajs ce d .. 44 | hkwan003@hammer.cs.ucr.edu; home cd .. 45 | hkwan003@hammer.cs.ucr.edu; cd #spaces 46 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd hi 47 | something happened while finding full path: No such file or directory 48 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd no #no direcot  tories 49 | something happened while finding full path: No such file or directory 50 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cat 51 | ^C 52 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ^C 53 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ^C 54 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ^C 55 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ^C 56 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ^C 57 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ^C 58 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ^C 59 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ^C 60 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ps 61 | PID TTY TIME CMD 62 | 24045 pts/43 00:00:00 bash 63 | 24139 pts/43 00:00:00 rshell 64 | 24786 pts/43 00:00:00 ps 65 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 #control C catches cat program and terminates it 66 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ls 67 | 61 FOLDEER CS100 CS-14 Documents hello.cpp Pictures rshell-1 ucr-cs100 68 | a.out cs100#1 CS61 Downloads ls.cpp Public Templates Videos 69 | calvin cs12 Desktop gitlearn Music quiz tester_files WINDOWS 70 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ls -a 71 | . Desktop .gtk-bookmarks Public 72 | .. .dmrc .gtkrc-1.2-gnome2 .pulse 73 | 61 FOLDEER Documents .gvfs .pulse-cookie 74 | .a.cpp.swp Downloads hello.cpp .qt 75 | .adobe .eggcups .ICEauthority quiz 76 | a.out .emacs.d .imsettings.log .recently-used.xbel 77 | .bash_history .esd_auth .kde .redhat 78 | .bash_logout .eshell .lesshst rshell-1 79 | .bashrc .evolution .local .ssh 80 | .cache .fontconfig ls.cpp Templates 81 | calvin .gconf .macromedia tester_files 82 | .config .gconfd .mcop .thumbnails 83 | CS100 .gitconfig .metacity .Trash 84 | cs100#1 gitlearn .mozilla ucr-cs100 85 | cs12 .gitlearn Music Videos 86 | CS-14 .gnome .nautilus .vim 87 | CS61 .gnome2 .nv .viminfo 88 | .dbus .gnome2_private Pictures .vimrc 89 | .DCOPserver_well.cs.ucr.edu_localhost_42 .gnote .pki WINDOWS 90 | .DCOPserver_well.cs.ucr.edu_localhost:42 .gnupg .procmailrc .Xauthority 91 | .DCOPserver_well.cs.ucr.edu_NODISPLAY .gstreamer-0.10 .profile 92 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd Doc 93 | something happened while finding full path: No such file or directory 94 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd doc   Documents 95 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ls 96 | ls.cpp newls.cpp pip.cpp rshell 97 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents cd    ls 98 | ls.cpp newls.cpp pip.cpp rshell 99 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents /rshell/bin/rshell 100 | error with passed in argument list: No such file or directory 101 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ls 102 | ls.cpp newls.cpp pip.cpp rshell 103 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents cd r shell 104 | hkwan003@hammer.cs.ucr.edu; /Documents/rshell ls 105 | bin LICENSE Makefile README.md src tests 106 | hkwan003@hammer.cs.ucr.edu; /Documents/rshell bin/rhs       cd - 107 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents cd  /rshell/bin/rshell 108 | error with passed in argument list: No such file or directory 109 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ls 110 | ls.cpp newls.cpp pip.cpp rshell 111 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents cd rseh  hell 112 | hkwan003@hammer.cs.ucr.edu; /Documents/rshell ls 113 | bin LICENSE Makefile README.md src tests 114 | hkwan003@hammer.cs.ucr.edu; /Documents/rshell bin/    / ./b  bin/      cd .. 115 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ./rshell/bin/rsh hell 116 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ps 117 | PID TTY TIME CMD 118 | 24045 pts/43 00:00:00 bash 119 | 24139 pts/43 00:00:00 rshell 120 | 26332 pts/43 00:00:00 rshell 121 | 26336 pts/43 00:00:00 ps 122 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ^C 123 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ^C 124 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ^C 125 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ^C 126 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ps 127 | PID TTY TIME CMD 128 | 24045 pts/43 00:00:00 bash 129 | 24139 pts/43 00:00:00 rshell 130 | 26332 pts/43 00:00:00 rshell 131 | 26445 pts/43 00:00:00 ps 132 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ls 133 | ls.cpp newls.cpp pip.cpp rshell 134 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ./rshell/a.out 135 | error with passed in argument list: No such file or directory 136 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents pwd 137 | /home/csmajs/hkwan003/Documents 138 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents cd .. 139 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd // 140 | hkwan003@hammer.cs.ucr.edu; cd    ps 141 | PID TTY TIME CMD 142 | 24045 pts/43 00:00:00 bash 143 | 24139 pts/43 00:00:00 rshell 144 | 26332 pts/43 00:00:00 rshell 145 | 27248 pts/43 00:00:00 ps 146 | hkwan003@hammer.cs.ucr.edu; pwd 147 | / 148 | hkwan003@hammer.cs.ucr.edu; cd home 149 | hkwan003@hammer.cs.ucr.edu; home ls 150 | csmajs 151 | hkwan003@hammer.cs.ucr.edu; home cd .. 152 | hkwan003@hammer.cs.ucr.edu; cd home/csmajs/hkwan003/Dpc  ocuments/rshell/                                         /home/csmajs/hkwan003/Documents/rshell/bin/rshell 153 | hkwan003@hammer.cs.ucr.edu; ps 154 | PID TTY TIME CMD 155 | 24045 pts/43 00:00:00 bash 156 | 24139 pts/43 00:00:00 rshell 157 | 26332 pts/43 00:00:00 rshell 158 | 27533 pts/43 00:00:00 rshell 159 | 27541 pts/43 00:00:00 ps 160 | hkwan003@hammer.cs.ucr.edu; pwd 161 | / 162 | hkwan003@hammer.cs.ucr.edu; cd - 163 | hkwan003@hammer.cs.ucr.edu; home ls 164 | csmajs 165 | hkwan003@hammer.cs.ucr.edu; home cd    ./csmajs/hkwan003/Documents/a.out 166 | error with passed in argument list: No such file or directory 167 | hkwan003@hammer.cs.ucr.edu; home ./a.out 168 | error with passed in argument list: No such file or directory 169 | hkwan003@hammer.cs.ucr.edu; home ls 170 | csgrads csmajs 171 | hkwan003@hammer.cs.ucr.edu; home cd cs smajs 172 | hkwan003@hammer.cs.ucr.edu; home/csmajs ls -a 173 | ls: cannot open directory .: Permission denied 174 | hkwan003@hammer.cs.ucr.edu; home/csmajs cd hkwan003 175 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ./a.out 176 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ls 177 | 61 FOLDEER CS100 CS-14 Documents hello.cpp Pictures rshell-1 ucr-cs100 178 | a.out cs100#1 CS61 Downloads ls.cpp Public Templates Videos 179 | calvin cs12 Desktop gitlearn Music quiz tester_files WINDOWS 180 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 ps 181 | PID TTY TIME CMD 182 | 24045 pts/43 00:00:00 bash 183 | 24139 pts/43 00:00:00 rshell 184 | 26332 pts/43 00:00:00 rshell 185 | 27533 pts/43 00:00:00 rshell 186 | 29391 pts/43 00:00:00 ps 187 | hkwan003@hammer.cs.ucr.edu; /csmajs/hkwan003 cd Documents 188 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ls 189 | ls.cpp newls.cpp pip.cpp rshell 190 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents ./a.out 191 | error with passed in argument list: No such file or directory 192 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents edi x  xit 193 | hkwan003@hammer.cs.ucr.edu; exit 194 | 195 | 196 | hkwan003@hammer.cs.ucr.edu; /hkwan003/Documents exit 197 | ~/Documents/rshell 198 | hkwan003@hammer $ exit 199 | exit 200 | 201 | Script done on Fri 29 May 2015 10:09:24 PM PDT 202 | -------------------------------------------------------------------------------- /tests/piping.script: -------------------------------------------------------------------------------- 1 | Script started on Sun 17 May 2015 09:22:53 PM PDT 2 | ~ 3 | hkwan003@hammer $ cds100 4 |  5 | =============================================================================== 6 | | | 7 | | You have enabled settings specific for cs100. Everything you do is being | 8 | | recorded to measure your progress in the class. | 9 | | | 10 | | Important commands for the class: | 11 | | * calcgrade.sh displays a detailed breakdown of your grade | 12 | | * checksyscalls.sh is your cpp file doing proper error checking? | 13 | | * typespeed practice typing unix commands | 14 | | | 15 | | Important commands for general C++ programming: | 16 | | * make don't call g++ manually; let make do the work! | 17 | | * gdb the GNU debugger | 18 | | * valgrind get rid of your memory leaks | 19 | | * cppcheck static analysis tool | 20 | | * man find help about any syscall / terminal command | 21 | | | 22 | =============================================================================== 23 |  24 | %%%%%%%%%%hkwan003@cs100:~ $ ls 25 | 61 FOLDEER CS100 cs12 CS61 Documents gitlearn Pictures quiz rshell-1 tester_files WINDOWS 26 | calvin cs100#1 CS-14 Desktop Downloads Music Public rshell Templates Videos 27 | %%%%%%%%%%hkwan003@cs100:~ $ cd rshell 28 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ ls 29 | LICENSE Makefile README.md src tests 30 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ make clean 31 | rm -rf ./bin 32 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ make 33 | mkdir -p ./bin 34 | g++ ./src/new.cpp -o ./bin/redirect 35 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ 36 | Message from syslogd@hammer at May 17 21:24:49 ... 37 | kernel:[Hardware Error]: MC4 Error (node 3): DRAM ECC error detected on the NB. 38 | 39 | Message from syslogd@hammer at May 17 21:24:49 ... 40 | kernel:[Hardware Error]: MC4 Error (node 3): DRAM ECC error detected on the NB. 41 | 42 | Message from syslogd@hammer at May 17 21:24:49 ... 43 | kernel:[Hardware Error]: Error Status: Corrected error, no action required. 44 | 45 | Message from syslogd@hammer at May 17 21:24:49 ... 46 | kernel:[Hardware Error]: Error Status: Corrected error, no action required. 47 | 48 | Message from syslogd@hammer at May 17 21:24:49 ... 49 | kernel:[Hardware Error]: CPU:18 (10:9:1) MC4_STATUS[Over|CE|MiscV|-|AddrV|CECC]: 0xdc5c410004080a13 50 | 51 | Message from syslogd@hammer at May 17 21:24:49 ... 52 | kernel:[Hardware Error]: CPU:18 (10:9:1) MC4_STATUS[Over|CE|MiscV|-|AddrV|CECC]: 0xdc5c410004080a13 53 | 54 | Message from syslogd@hammer at May 17 21:24:49 ... 55 | kernel:[Hardware Error]: MC4_ADDR: 0x0000001891a88210 56 | 57 | Message from syslogd@hammer at May 17 21:24:49 ... 58 | kernel:[Hardware Error]: MC4_ADDR: 0x0000001891a88210 59 | 60 | Message from syslogd@hammer at May 17 21:24:49 ... 61 | kernel:[Hardware Error]: cache level: L3/GEN, mem/io: MEM, mem-tx: RD, part-proc: RES (no timeout) 62 | 63 | Message from syslogd@hammer at May 17 21:24:49 ... 64 | kernel:[Hardware Error]: cache level: L3/GEN, mem/io: MEM, mem-tx: RD, part-proc: RES (no timeout) 65 | ls 66 | bin LICENSE Makefile README.md src tests 67 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ bin/redirect 68 | hkwan003@hammer.cs.ucr.edu $ ^C 69 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ make clean 70 | rm -rf ./bin 71 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ make 72 | mkdir -p ./bin 73 | g++ ./src/new.cpp -o ./bin/redirect 74 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ lbin/redirect 75 | hkwan003@hammer.cs.ucr.edu $ ls > file 76 | hkwan003@hammer.cs.ucr.edu $ ls  cat file 77 | bin 78 | file 79 | LICENSE 80 | Makefile 81 | README.md 82 | src 83 | tests 84 | hkwan003@hammer.cs.ucr.edu $ ls -a >  > file 85 | hkwan003@hammer.cs.ucr.edu $ cat file 86 | bin 87 | file 88 | LICENSE 89 | Makefile 90 | README.md 91 | src 92 | tests 93 | . 94 | .. 95 | bin 96 | .DS_Store 97 | file 98 | .git 99 | .gitignore 100 | LICENSE 101 | Makefile 102 | README.md 103 | src 104 | tests 105 | hkwan003@hammer.cs.ucr.edu $ wc < file > file 1 106 | hkwan003@hammer.cs.ucr.edu $ cat file 107 | bin 108 | file 109 | LICENSE 110 | Makefile 111 | README.md 112 | src 113 | tests 114 | . 115 | .. 116 | bin 117 | .DS_Store 118 | file 119 | .git 120 | .gitignore 121 | LICENSE 122 | Makefile 123 | README.md 124 | src 125 | tests 126 | hkwan003@hammer.cs.ucr.edu $ cat file 1  1 127 | 19 19 123 file 128 | hkwan003@hammer.cs.ucr.edu $ cat file        cat file   | grep a 129 | Makefile 130 | Makefile 131 | hkwan003@hammer.cs.ucr.edu $ #piping works but with only one pipe 132 | hkwan003@hammer.cs.ucr.edu $ cat file    < file | tee 1-  a-z > new_file 133 | cat: <: No such file or directory 134 | hkwan003@hammer.cs.ucr.edu $ bin 135 | file 136 | LICENSE 137 | Makefile 138 | README.md 139 | src 140 | tests 141 | . 142 | .. 143 | bin 144 | .DS_Store 145 | file 146 | .git 147 | .gitignore 148 | LICENSE 149 | Makefile 150 | README.md 151 | src 152 | tests 153 | l 154 | error with passed in argument list: No such file or directory 155 | hkwan003@hammer.cs.ucr.edu $ ls 156 | > a-z bin file file1 LICENSE Makefile new_file README.md src tests 157 | hkwan003@hammer.cs.ucr.edu $ cat <<< "outputs this string right here" 158 | outputs this string right here 159 | hkwan003@hammer.cs.ucr.edu $ wc <<< "does not just work with cat" 160 | 1 6 28 161 | hkwan003@hammer.cs.ucr.edu $ cat << " all kinda   s of spaces" 162 | open: No such file or directory 163 | open: No such file or directory 164 | cat: ": No such file or directory 165 | cat: all: No such file or directory 166 | cat: kinds: No such file or directory 167 | cat: of: No such file or directory 168 | cat: spaces": No such file or directory 169 | hkwan003@hammer.cs.ucr.edu $ cat <  << "space tabs space" 170 | space tabs space 171 | hkwan003@hammer.cs.ucr.edu $ ls 172 | > a-z bin file file1 LICENSE Makefile new_file README.md src tests 173 | hkwan003@hammer.cs.ucr.edu $ g++ bin 2> new 174 | hkwan003@hammer.cs.ucr.edu $ cat new 175 | bin: file not recognized: Is a directory 176 | collect2: error: ld returned 1 exit status 177 | hkwan003@hammer.cs.ucr.edu $ g++ new_file 2>> new 178 | hkwan003@hammer.cs.ucr.edu $ cat new 179 | bin: file not recognized: Is a directory 180 | collect2: error: ld returned 1 exit status 181 | /opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld:new_file: file format not recognized; treating as linker script 182 | /opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld:new_file:2: syntax error 183 | collect2: error: ld returned 1 exit status 184 | hkwan003@hammer.cs.ucr.edu $ ls -a >> new 185 | hkwan003@hammer.cs.ucr.edu $ cat en    new 186 | bin: file not recognized: Is a directory 187 | collect2: error: ld returned 1 exit status 188 | /opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld:new_file: file format not recognized; treating as linker script 189 | /opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld:new_file:2: syntax error 190 | collect2: error: ld returned 1 exit status 191 | > 192 | . 193 | .. 194 | a-z 195 | bin 196 | .DS_Store 197 | file 198 | file1 199 | .git 200 | .gitignore 201 | LICENSE 202 | Makefile 203 | new 204 | new_file 205 | README.md 206 | src 207 | tests 208 | hkwan003@hammer.cs.ucr.edu $ ls -a >   1> new_test 209 | hkwan003@hammer.cs.ucr.edu $ cat new_test 210 | > 211 | . 212 | .. 213 | a-z 214 | bin 215 | .DS_Store 216 | file 217 | file1 218 | .git 219 | .gitignore 220 | LICENSE 221 | Makefile 222 | new 223 | new_file 224 | new_test 225 | README.md 226 | src 227 | tests 228 | hkwan003@hammer.cs.ucr.edu $ ls -l > 1>> new_test 229 | hkwan003@hammer.cs.ucr.edu $ cat new_test 230 | > 231 | . 232 | .. 233 | a-z 234 | bin 235 | .DS_Store 236 | file 237 | file1 238 | .git 239 | .gitignore 240 | LICENSE 241 | Makefile 242 | new 243 | new_file 244 | new_test 245 | README.md 246 | src 247 | tests 248 | total 48 249 | -rw------- 1 hkwan003 csmajs 123 May 17 21:23 > 250 | -rw------- 1 hkwan003 csmajs 123 May 17 21:23 a-z 251 | drwx------ 2 hkwan003 csmajs 4096 May 17 21:21 bin 252 | -rw------- 1 hkwan003 csmajs 123 May 17 21:21 file 253 | -rw------- 1 hkwan003 csmajs 17 May 17 21:21 file1 254 | -rw------- 1 hkwan003 csmajs 1079 May 17 20:14 LICENSE 255 | -rw------- 1 hkwan003 csmajs 446 May 17 20:40 Makefile 256 | -rw------- 1 hkwan003 csmajs 460 May 17 21:25 new 257 | -rw------- 1 hkwan003 csmajs 123 May 17 21:23 new_file 258 | -rw------- 1 hkwan003 csmajs 111 May 17 21:28 new_test 259 | -rw------- 1 hkwan003 csmajs 891 May 17 20:14 README.md 260 | drwx------ 2 hkwan003 csmajs 4096 May 17 20:43 src 261 | drwx------ 2 hkwan003 csmajs 4096 May 17 21:16 tests 262 | hkwan003@hammer.cs.ucr.edu $ ls -- a s   -s l > new_test 263 | hkwan003@hammer.cs.ucr.edu $ cat new_test             ca t _ new_test 264 | total 44 265 | -rw------- 1 hkwan003 csmajs 123 May 17 21:23 > 266 | -rw------- 1 hkwan003 csmajs 123 May 17 21:23 a-z 267 | drwx------ 2 hkwan003 csmajs 4096 May 17 21:21 bin 268 | -rw------- 1 hkwan003 csmajs 123 May 17 21:21 file 269 | -rw------- 1 hkwan003 csmajs 17 May 17 21:21 file1 270 | -rw------- 1 hkwan003 csmajs 1079 May 17 20:14 LICENSE 271 | -rw------- 1 hkwan003 csmajs 446 May 17 20:40 Makefile 272 | -rw------- 1 hkwan003 csmajs 460 May 17 21:25 new 273 | -rw------- 1 hkwan003 csmajs 123 May 17 21:23 new_file 274 | -rw------- 1 hkwan003 csmajs 0 May 17 21:28 new_test 275 | -rw------- 1 hkwan003 csmajs 891 May 17 20:14 README.md 276 | drwx------ 2 hkwan003 csmajs 4096 May 17 20:43 src 277 | drwx------ 2 hkwan003 csmajs 4096 May 17 21:16 tests 278 | hkwan003@hammer.cs.ucr.edu $ g++ file1 2>> new_test | greb p a 279 | g++: error: 2>>: No such file or directory 280 | hkwan003@hammer.cs.ucr.edu $ ls 281 | > a-z bin file file1 LICENSE Makefile new new_file new_test README.md src tests 282 | hkwan003@hammer.cs.ucr.edu $ exit 283 | hkwan003@hammer.cs.ucr.edu $ exit 284 | %%%%%%%%%%hkwan003@cs100:~/rshell (redirect) $ exit 285 | exit 286 | do_ypcall: clnt_call: RPC: Unable to send; errno = Operation not permitted 287 | ~ 288 | hkwan003@hammer $ exit 289 | exit 290 | 291 | Script done on Sun 17 May 2015 09:36:39 PM PDT 292 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "errno.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | using namespace std; 16 | bool cd_check = true; 17 | bool set_last = false; 18 | bool continue_program = true; 19 | void fixing_spacing_command(char *org_prompt) 20 | { 21 | char *fin_prompt = (char*)malloc(50000); 22 | char connect[4]; 23 | connect[0] = ';'; 24 | connect[1] = '&'; 25 | connect[2] = '|'; 26 | connect[3] = '#'; 27 | //x is passed in prompt 28 | //i is finished prompt after changing spaces 29 | for(int x = 0,i = 0; org_prompt[x] != '\0'; x++, i++) 30 | { 31 | if(org_prompt[x] == connect[3]) 32 | { 33 | org_prompt[x] = '\0'; fin_prompt[i] = '\0'; 34 | } 35 | else if(org_prompt[x] == connect[0]) 36 | { 37 | fin_prompt[i] = ' ';fin_prompt[++i] = ';';fin_prompt[++i] = ' '; 38 | } 39 | else if(org_prompt[x] == connect[1] && org_prompt[x + 1] == connect[1]) 40 | { 41 | fin_prompt[i] = ' ';fin_prompt[++i] = '&';fin_prompt[++i] = '&';fin_prompt[++i] = ' '; 42 | ++x; 43 | } 44 | else if(org_prompt[x] == connect[3] && org_prompt[x + 1] == connect[3]) 45 | { 46 | fin_prompt[i] = ' ';fin_prompt[++i] = '|';fin_prompt[++i] = '|';fin_prompt[++i] = ' '; 47 | ++x; 48 | } 49 | else 50 | { 51 | fin_prompt[i] = org_prompt[x]; 52 | } 53 | if(org_prompt[x + 1] == '\0') fin_prompt[i + 1] = '\0'; 54 | } 55 | strcpy(org_prompt, fin_prompt); //copies altered version 56 | } 57 | string input_hold; 58 | string out_hold; 59 | string add_hold; 60 | bool files_descriptor_change = false; //true if there is need to change file descriptor 61 | string fix_file_name(string s); 62 | vector inputs_G; 63 | vector outputs_G; 64 | vector output_append_G; 65 | vector piping_str; 66 | bool checks_pipes = false; 67 | char *piparr[100]; 68 | bool in = false; 69 | bool out = false; 70 | bool add_out = false; 71 | int return_file_descrption = 0; //file descriptor of what file descriptor to change it to 72 | bool check_change_DIR(char* arr[]) 73 | { 74 | char* dir = arr[0]; 75 | char* path = arr[1]; 76 | char* temp; 77 | if(!strcmp(dir, "cd")) 78 | { 79 | if(path == '\0') 80 | { 81 | char *home, *old; 82 | if((home = getenv("HOME")) == NULL) 83 | { 84 | perror("get enviromente"); 85 | } 86 | if((old = getenv("PWD")) == NULL) 87 | { 88 | perror("get enviromente2"); 89 | } 90 | if(chdir(home) == -1) 91 | { 92 | perror("changing directories 1"); 93 | } 94 | if(setenv("PWD", home, 1) == -1) 95 | { 96 | perror("set those directories1"); 97 | } 98 | if(setenv("OLDPWD", old, 1) == -1) 99 | { 100 | perror("set those directories12"); 101 | } 102 | } 103 | else if(!strcmp(path, "-")) 104 | { 105 | char *old, *newDir; 106 | if((old = getenv("PWD")) == NULL) 107 | { 108 | perror("get working dir"); 109 | } 110 | if((newDir = getenv("OLDPWD")) == NULL) 111 | { 112 | perror("get old working dir"); 113 | } 114 | if(chdir(newDir) == -1) 115 | { 116 | perror("change dir"); 117 | } 118 | if(setenv("PWD", newDir, 1) == -1) 119 | { 120 | perror("set dir"); 121 | } 122 | if(setenv("OLDPWD", old, 1) == -1) 123 | { 124 | perror("setting old direcory"); 125 | } 126 | } 127 | else 128 | { 129 | string strPath; 130 | for(int x = 0; path[x] != '\0'; x++) 131 | { 132 | strPath.push_back(path[x]); 133 | } 134 | if(strPath.size() > 0 && strPath.at(0) == '~') 135 | { 136 | if(strPath.size() == 1 || strPath.at(1) == '/') 137 | { 138 | strPath = strPath.substr(1); 139 | string tempString = getenv("HOME"); 140 | strPath = tempString + strPath; 141 | } 142 | } 143 | char fullPath[50000]; 144 | if(NULL == realpath(strPath.c_str(), fullPath)) 145 | { 146 | perror("something happened while finding full path"); 147 | return -1; 148 | } 149 | if(-1 == chdir(fullPath)) 150 | { 151 | perror("changing those directories"); 152 | return -1; 153 | } 154 | if(-1 == setenv("OLDPWD", getenv("PWD"), 1)) 155 | { 156 | perror("setting good oldPWD"); 157 | return -1; 158 | } 159 | if(-1 == setenv("PWD", fullPath, 1)) 160 | { 161 | perror("setting the usual PWD"); 162 | return -1; 163 | } 164 | } 165 | return true; 166 | } 167 | return false; 168 | } 169 | int exec_status; 170 | bool str_continue = true; 171 | int process_ID = 0; 172 | int status; 173 | bool execute(char* command, char* command_list[], int conect_type) 174 | { 175 | cd_check = check_change_DIR(command_list); 176 | { 177 | if(!cd_check) 178 | { 179 | //cout << "beginning of execution: " << endl; 180 | process_ID = fork(); 181 | if(process_ID <= -1) 182 | { 183 | perror("Error occured during forking()"); 184 | exit(1); 185 | } 186 | else if(process_ID == 0) //child process 187 | { 188 | exec_status = (execvp(command, command_list)); 189 | //cout << "output exec status: " << exec_status << endl; 190 | if(exec_status == -1) 191 | { 192 | perror("error with passed in argument list"); 193 | exit(1); 194 | } 195 | } 196 | else if(process_ID > 0) //parent process 197 | { 198 | int wpid; 199 | do { 200 | wpid = wait(&status); 201 | } while (wpid == -1 && errno == EINTR); 202 | if(wpid == -1) { 203 | //perror("wait error"); 204 | 205 | } 206 | } 207 | return(!(status == 0 && conect_type == -1) ||( status > 0 && conect_type == 2)); 208 | } 209 | } 210 | } 211 | void check_redirection(string &s) 212 | { 213 | return_file_descrption = 0; 214 | input_hold.clear(); 215 | out_hold.clear(); 216 | add_hold.clear(); 217 | for(unsigned int x = 0; x < s.size(); x++) 218 | { 219 | if(s.at(x) == '<' && x < s.size()) 220 | { 221 | s.at(x) = ' '; 222 | unsigned int g = x; 223 | if(g++ < s.size()) 224 | { 225 | for(; g < s.size() && s.at(g) != '>'; g++) 226 | { 227 | input_hold.push_back(s.at(g)); 228 | } 229 | } 230 | in = true; 231 | inputs_G.push_back(input_hold); 232 | } 233 | if(s.at(x) == '>') 234 | { 235 | if(s.at(x + 1) == '>' && x +1 < s.size()) 236 | { 237 | s.at(x) = ' '; 238 | s.at(x + 1) = ' '; 239 | x+=2; 240 | unsigned int i = x; 241 | i++; 242 | //cout << "s.at(i): " << s.at(i) << endl; 243 | for(; i < s.size() && s.at(i) != '>'; i++) 244 | { 245 | //cout << s.at(i) << endl; 246 | add_hold.push_back(s.at(i)); 247 | s.at(i) = ' '; 248 | } 249 | //cout << "add_hold: " << add_hold << endl; 250 | output_append_G.push_back(add_hold); 251 | //cout << "first vecto space: " << output_append_G.at(0) << endl; 252 | add_hold.clear(); 253 | add_out = true; 254 | } 255 | else if(s.at(x + 1) != '>') 256 | { 257 | //cout << "string shows: " << s.at(x + 1) << endl; 258 | //cout << "strings: " << s << endl; 259 | //cout << "why are u mesing with me" << endl; 260 | s.at(x) = ' '; 261 | unsigned int i = x; 262 | i++; 263 | for(; i < s.size() && s.at(i) != '>'; i++) 264 | { 265 | out_hold.push_back(s.at(i)); 266 | s.at(i) = ' '; 267 | } 268 | outputs_G.push_back(out_hold); 269 | out_hold.clear(); 270 | out = true; 271 | //cout << "check boolean: " << out << endl; 272 | } 273 | } 274 | if(s.at(x) == '0' || s.at(x) == '1' || s.at(x) == '2') 275 | { 276 | for(; x < s.size(); x++) 277 | { 278 | files_descriptor_change = true; 279 | if(s.at(x) == '<' && x < s.size()) 280 | { 281 | s.at(x) = ' '; 282 | unsigned int g = x; 283 | if(g++ < s.size()) 284 | { 285 | for(; g < s.size() && s.at(g) != '>'; g++) 286 | { 287 | input_hold.push_back(s.at(g)); 288 | } 289 | } 290 | in = true; 291 | inputs_G.push_back(input_hold); 292 | } 293 | if(x + 1 < s.size()) 294 | { 295 | x++; 296 | } 297 | if(s.at(x) == '>') 298 | { 299 | if(s.at(x + 1) == '>' && x +1 < s.size()) 300 | { 301 | if(s.at(x - 1) == '0') 302 | { 303 | return_file_descrption = 7; //3 equals stdin append 304 | } 305 | if(s.at(x - 1) == '1') 306 | { 307 | s.at(x - 1) = ' '; 308 | return_file_descrption = 4; //4 equals stdout append 309 | } 310 | if(s.at(x - 1) == '2') 311 | { 312 | s.at(x - 1) = ' '; 313 | return_file_descrption = 5; //5 equals stderr append 314 | } 315 | s.at(x) = ' '; 316 | s.at(x + 1) = ' '; 317 | x+=2; 318 | unsigned int i = x; 319 | i++; 320 | //cout << "s.at(i): " << s.at(i) << endl; 321 | for(; i < s.size() && s.at(i) != '>'; i++) 322 | { 323 | //cout << s.at(i) << endl; 324 | add_hold.push_back(s.at(i)); 325 | s.at(i) = ' '; 326 | } 327 | //cout << "add_hold: " << add_hold << endl; 328 | output_append_G.push_back(add_hold); 329 | //cout << "first vecto space: " << output_append_G.at(0) << endl; 330 | add_hold.clear(); 331 | add_out = true; 332 | } 333 | else if(s.at(x + 1) != '>') 334 | { 335 | if(s.at(x - 1) == '0') 336 | { 337 | return_file_descrption = 6; //0 equals stdin trunc 338 | } 339 | if(s.at(x - 1) == '1') 340 | { 341 | s.at(x - 1) = ' '; 342 | return_file_descrption = 1; //1 equals stdout trunc 343 | } 344 | if(s.at(x - 1) == '2') 345 | { 346 | s.at(x - 1) = ' '; 347 | return_file_descrption = 2; //2 equals stderr trunc 348 | } 349 | s.at(x) = ' '; 350 | unsigned int i = x; 351 | i++; 352 | for(; i < s.size() && s.at(i) != '>'; i++) 353 | { 354 | out_hold.push_back(s.at(i)); 355 | s.at(i) = ' '; 356 | } 357 | outputs_G.push_back(out_hold); 358 | out_hold.clear(); 359 | out = true; 360 | } 361 | } 362 | } 363 | } 364 | 365 | } 366 | } 367 | 368 | void execute_piping() 369 | { 370 | int status; 371 | 372 | int process_ID = fork(); 373 | 374 | cout << "process: " << process_ID << endl; 375 | if(process_ID <= -1) 376 | { 377 | perror("Error occured during forking()"); 378 | exit(1); 379 | } 380 | if(process_ID == 0) //child process 381 | { 382 | 383 | //cout << "arguments1: " << argument1[0] << endl; 384 | //exec_status = (execvp(argument1[0], argument1)); 385 | cout << "output exec status: " << exec_status << endl; 386 | if(exec_status == -1) 387 | { 388 | perror("error with passed in argument list"); 389 | exit(1); 390 | } 391 | } 392 | if(process_ID > 0) //parent process 393 | { 394 | if(waitpid(process_ID, &status,0) == -1) 395 | { 396 | perror("error with waitpid()"); 397 | } 398 | } 399 | 400 | //execvp(argument1[0], argument1); 401 | 402 | } 403 | string final_file_name; 404 | string fix_file_name(string s) 405 | { 406 | final_file_name.clear(); 407 | int sz = s.size(); 408 | for(int x = 0; x < sz; x++) 409 | { 410 | if(s.at(x) != ' ') 411 | { 412 | final_file_name.push_back(s.at(x)); 413 | } 414 | } 415 | return final_file_name; 416 | } 417 | 418 | bool redir_exist(string s) 419 | { 420 | for(unsigned int x = 0; x < s.size(); x++) 421 | { 422 | if(s.at(x) == '>' || s.at(x) == '<') 423 | { 424 | return true; 425 | } 426 | } 427 | return false; 428 | } 429 | 430 | unsigned int i; 431 | bool chk_pipes(string s) 432 | { 433 | for(unsigned int x = 0; x < s.size(); x++) 434 | { 435 | //cout << "is this actually checking rn" << endl; 436 | if(s.at(x) == '|') 437 | { 438 | i++; 439 | //cout << "output I: " << i << endl; 440 | } 441 | } 442 | if(i == 1) 443 | { 444 | return true; 445 | } 446 | return false; 447 | 448 | } 449 | 450 | void push_piping_string(string s) 451 | { 452 | string t; 453 | for(unsigned int x = 0; x < s.size(); x++) 454 | { 455 | //cout << "X: " << x << " " << s.at(x) < 0 && connect_check == -1 && str_continue) 636 | { 637 | comd_arr[comd_arr_cnt] = token; 638 | comd_arr_cnt++; 639 | } 640 | else if(connect_check != -1) 641 | { 642 | check_exit(token); 643 | comd_arr[comd_arr_cnt] = '\0' ; 644 | sequence = 0; 645 | comd_arr_cnt = 0; 646 | //cout << "does it output second iteration " << endl; 647 | exec_result = execute(comd_arr[0], comd_arr, connect_check); 648 | //cout << "output exec_status: " << exec_status << endl; 649 | //cout << "output exec_result tho: " << exec_result << endl; 650 | //cout << "connect_check: " << connect_check << endl; 651 | //cout << "str_continue: " << str_continue << endl; 652 | if(exec_status == 0) 653 | { 654 | if(connect_check == 2) 655 | { 656 | str_continue = false; 657 | //cout << "str_continue: " << str_continue << endl; 658 | } 659 | if(connect_check == 1) 660 | { 661 | str_continue = false; 662 | } 663 | } 664 | if(exec_result == 1) 665 | { 666 | if(connect_check == 2) 667 | { 668 | str_continue = true; 669 | } 670 | } 671 | } 672 | token = strtok(NULL, "\t "); 673 | if(connect_check == -1 && token == NULL && exec_result && str_continue) 674 | { 675 | //cout << "guess this executeisw ith this " << endl; 676 | comd_arr[comd_arr_cnt] = '\0'; 677 | execute(comd_arr[0], comd_arr, connect_check); 678 | } 679 | } 680 | } 681 | } 682 | } 683 | 684 | --------------------------------------------------------------------------------