├── LICENSE
├── Makefile
├── README.md
├── src
├── Timer.h
├── cp.cpp
├── handler_signal.cpp
├── ls.cpp
├── main.cpp
├── mv.cpp
└── rm.cpp
└── tests
├── exec.script
├── ls.script
├── piping.script
└── signals.script
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CFLAG = -ansi -pedantic -Wall -Werror
2 | COMPILER = g++
3 |
4 | all: rshell ls rm mv cp
5 |
6 |
7 | rshell:
8 | mkdir -p bin
9 | $(COMPILER) $(CFLAG) src/main.cpp -o bin/rshell
10 |
11 | ls:
12 | mkdir -p bin
13 | $(COMPILER) $(CFLAG) src/ls.cpp -o bin/ls
14 |
15 | rm:
16 | mkdir -p bin
17 | $(COMPILER) $(CFLAG) src/rm.cpp -o bin/rm
18 |
19 | mv:
20 | mkdir -p bin
21 | $(COMPILER) $(CFLAG) src/mv.cpp -o bin/mv
22 |
23 | cp:
24 | mkdir -p bin
25 | $(COMPILER) $(CFLAG) src/cp.cpp -o bin/cp
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rshell
2 | This is a command shell. Programmed in C++ and makes use of the system calls using execvp.
3 |
4 | ##Introduction
5 |
6 | This project is built to act as a terminal. It has the same functionality as a regular terminal, it is able to perform all the execvp functions and gives proper feedback on whether the functions have worked or failed.
7 |
8 | ##Install Instructions
9 |
10 | ```
11 | $ clone https://github.com/divyanshch/rshell.git
12 | $ cd rshell
13 | $ git checkout hw3
14 | $ make
15 | $ bin/rshell
16 | ```
17 | ##Bugs/Limitations for signaling
18 |
19 | 1. Does not handle the combination of connectors and `cd`
20 |
21 | ``echo hello && cd ..``
22 |
23 | This would result in the output of `hello` followed by an error.
24 |
25 | 2. If the path when running `cd` does not exist, there is an error message.
26 |
27 | ``cd non_existent_path``
28 |
29 | Output:
30 |
31 | ``chdir: No such file or directory``
32 |
33 | 3. If there is a second paramater passed into `cd` there will be a error.
34 |
35 | ``cd .. hello``
36 |
37 | Output:
38 |
39 | ``Error: invalid call of the cd command``
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/src/Timer.h:
--------------------------------------------------------------------------------
1 |
2 | /* C++ interface for program benchmark timer management. */
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | // extern "C" int gettimeofday(timeval *tp, void *tzp);
9 | // extern "C" int getrusage(int who, struct rusage *rusag);
10 |
11 | class Timer
12 | {
13 | public:
14 | int start();
15 | int elapsedWallclockTime (double &);
16 | int elapsedUserTime (double &);
17 | int elapsedSystemTime (double &);
18 | int elapsedTime (double &wc, double &us, double &system);
19 |
20 | private:
21 | rusage old_us_time;
22 | rusage new_us_time;
23 | timeval old_wc_time;
24 | timeval new_wc_time;
25 | };
26 |
27 |
28 | int
29 | Timer::start()
30 | {
31 | if (gettimeofday (&this->old_wc_time, 0) == -1
32 | || getrusage (RUSAGE_SELF, &this->old_us_time) == -1)
33 | return -1;
34 | else
35 | return 0;
36 | }
37 |
38 | int
39 | Timer::elapsedWallclockTime (double &wc)
40 | {
41 | if (gettimeofday (&this->new_wc_time, 0) == -1)
42 | return -1;
43 | wc = (this->new_wc_time.tv_sec - this->old_wc_time.tv_sec)
44 | + (this->new_wc_time.tv_usec - this->old_wc_time.tv_usec) / 1000000.0;
45 | return 0;
46 | }
47 |
48 | int
49 | Timer::elapsedUserTime (double &ut)
50 | {
51 | if (getrusage (RUSAGE_SELF, &this->new_us_time) == -1)
52 | return -1;
53 |
54 | ut = (this->new_us_time.ru_utime.tv_sec - this->old_us_time.ru_utime.tv_sec)
55 | + ((this->new_us_time.ru_utime.tv_usec
56 | - this->old_us_time.ru_utime.tv_usec) / 1000000.0);
57 | return 0;
58 | }
59 |
60 | int
61 | Timer::elapsedSystemTime (double &st)
62 | {
63 | if (getrusage (RUSAGE_SELF, &this->new_us_time) == -1)
64 | return -1;
65 |
66 | st = (this->new_us_time.ru_stime.tv_sec - this->old_us_time.ru_stime.tv_sec)
67 | + ((this->new_us_time.ru_stime.tv_usec
68 | - this->old_us_time.ru_stime.tv_usec) / 1000000.0);
69 | return 0;
70 | }
71 |
72 | int
73 | Timer::elapsedTime (double &wallclock, double &user_time, double &system_time)
74 | {
75 | if (this->elapsedWallclockTime (wallclock) == -1)
76 | return -1;
77 | else
78 | {
79 | if (getrusage (RUSAGE_SELF, &this->new_us_time) == -1)
80 | return -1;
81 | user_time = (this->new_us_time.ru_utime.tv_sec
82 | - this->old_us_time.ru_utime.tv_sec)
83 | + ((this->new_us_time.ru_utime.tv_usec
84 | - this->old_us_time.ru_utime.tv_usec) / 1000000.0);
85 |
86 | system_time = (this->new_us_time.ru_stime.tv_sec
87 | - this->old_us_time.ru_stime.tv_sec)
88 | + ((this->new_us_time.ru_stime.tv_usec
89 | - this->old_us_time.ru_stime.tv_usec) / 1000000.0);
90 |
91 | return 0;
92 | }
93 | }
94 |
95 | /* Example of use
96 |
97 | #include "Timer.h"
98 | #include
99 |
100 | int main()
101 | {
102 | Timer t;
103 | double eTime;
104 | t.start();
105 | for (int i=0, j; i<1000000000; i++)
106 | j++;
107 | t.elapsedUserTime(eTime);
108 | cout << eTime << endl;
109 | }
110 | */
111 |
--------------------------------------------------------------------------------
/src/cp.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 | #include
14 | #include
15 | #include
16 | #include "Timer.h"
17 | #include
18 |
19 | using namespace std;
20 |
21 | void slow_copy(char* in, char* out)
22 | {
23 |
24 | ifstream is(in);
25 | ofstream outfile(out);
26 |
27 | char c;
28 | while(is.get(c)) {
29 | outfile.put(c);
30 | }
31 | is.close();
32 | }
33 |
34 | void med_copy(char* in, char* out)
35 | {
36 | int size = sizeof(char);
37 | int input_fd, output_fd;
38 | ssize_t ret_in, ret_out;
39 | char buffer[8];
40 |
41 | input_fd = open(in, O_RDONLY);
42 | if(input_fd == -1) {
43 | perror("open");
44 | }
45 |
46 | output_fd = open(out, O_WRONLY | O_CREAT, 0644);
47 | if(output_fd == -1) {
48 | perror("open");
49 | }
50 |
51 | while((ret_in = read(input_fd, &buffer, size)) > 0)
52 | {
53 | if(ret_in==-1)
54 | perror("read");
55 | ret_out = write(output_fd, &buffer, (ssize_t) ret_in);
56 | if(ret_out != ret_in) {
57 | perror("write");
58 | }
59 | }
60 |
61 | if(-1==close (input_fd))
62 | perror("close");
63 |
64 | if(-1==close (output_fd))
65 | perror("close");
66 | }
67 |
68 | void fast_copy(char* in, char* out)
69 | {
70 | int input_fd, output_fd;
71 | ssize_t ret_in, ret_out;
72 | char buffer[BUFSIZ];
73 |
74 | input_fd = open(in, O_RDONLY);
75 | if(input_fd == -1) {
76 | perror("open");
77 | }
78 |
79 | output_fd = open(out, O_WRONLY | O_CREAT, 0644);
80 | if(output_fd == -1) {
81 | perror("open");
82 | }
83 |
84 | while((ret_in = read(input_fd, &buffer, BUFSIZ)) > 0)
85 | {
86 | if(ret_in==-1)
87 | perror("read");
88 | ret_out = write(output_fd, &buffer, (ssize_t) ret_in);
89 | if(ret_out != ret_in) {
90 | perror("write");
91 | }
92 | }
93 |
94 | if(-1==close (input_fd))
95 | perror("close");
96 | if(-1==close (output_fd))
97 | perror("close");
98 | }
99 |
100 | bool file_exists(const char *fileName)
101 | {
102 | ifstream infile(fileName);
103 | return infile.good();
104 | }
105 |
106 |
107 | int main(int argc, char **argv)
108 | {
109 | if(argc < 2) {
110 | cout << "ERROR: Please enter a file to copy" << endl;
111 | return 1;
112 | }
113 |
114 | if(argc < 3) {
115 | cout << "ERROR: Please enter the destination file" << endl;
116 | return 1;
117 | }
118 |
119 | if(!file_exists(argv[1])) {
120 | cout << "ERROR: Source file does not exist" << endl;
121 | return 1;
122 | }
123 |
124 | if(file_exists(argv[2])) {
125 | cout << "ERROR: Destination file already exists" << endl;
126 | return 1;
127 | }
128 |
129 | if(argc == 4) {
130 | fast_copy(argv[1], argv[2]);
131 | }
132 | else {
133 |
134 | Timer t;
135 | double eTime;
136 | t.start();
137 | slow_copy(argv[1], argv[2]);
138 | t.elapsedUserTime(eTime);
139 | cout << "First method took: " << eTime << " seconds" << endl;
140 |
141 | Timer t2;
142 | double eTime2;
143 | t2.start();
144 | med_copy(argv[1], argv[2]);
145 | t2.elapsedUserTime(eTime2);
146 | cout << "Second method took: " << eTime2 << " seconds" << endl;
147 |
148 | Timer t3;
149 | double eTime3;
150 | t3.start();
151 | fast_copy(argv[1], argv[2]);
152 | t3.elapsedUserTime(eTime3);
153 | cout << "Third method took: " << eTime3 << " seconds" << endl;
154 | }
155 |
156 | return 0;
157 | }
158 |
159 |
--------------------------------------------------------------------------------
/src/handler_signal.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | using namespace std;
8 | int c,quit,z=0;
9 |
10 | void handler(int signum)
11 | {
12 | if(signum==SIGQUIT)
13 | {
14 | cout << "\\";
15 | quit++;
16 | }
17 | else if(signum==SIGINT)
18 | {
19 | cout << "c";
20 | c++;
21 | }
22 | else if(signum==SIGTSTP)
23 | {
24 | cout << "s";
25 | z++;
26 | raise(SIGSTOP);
27 |
28 | }
29 | }
30 |
31 | int main()
32 | {
33 | struct sigaction sa;
34 | sa.sa_handler = handler;
35 |
36 | while(1)
37 | {
38 | cout << "x" <
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 | using namespace std;
18 |
19 | bool flag_a, flag_l, flag_R = false;
20 | char blue[] = {"\033[1;34m"};
21 | char white[] = {"\033[100m"};
22 | char green[] = {"\033[1;32m"};
23 | char RESET[] = {"\033[0m"};
24 | void rflag(char *folder);
25 | void printer(vector temp,char *folder)
26 | {
27 | unsigned int max_size;
28 | struct winsize w;
29 | if(-1==ioctl(STDOUT_FILENO, TIOCGWINSZ, &w))
30 | perror("ioctl");
31 |
32 | for(unsigned int i=0;iless)
77 | {
78 | cout <tolower(*rit))
93 | return false;
94 | }
95 | if(one.size() < two.size())
96 | return true;
97 | return false;
98 | }
99 |
100 |
101 |
102 |
103 | void lflag(char *folder,bool flag)
104 | {
105 | vector temp;
106 | DIR *dirp;
107 | if(NULL==(dirp=opendir(folder)))
108 | {
109 | perror("opendir");
110 | exit(1);
111 | }
112 | struct dirent *filespecs;
113 | errno =0;
114 | while(NULL!=(filespecs = readdir(dirp)))
115 | {
116 | if ((!flag) &&((filespecs->d_name)[0]!= '.'))
117 | {
118 | temp.push_back(filespecs->d_name);
119 | }
120 | else if (flag)
121 | temp.push_back(filespecs->d_name);
122 | }
123 | if (errno!=0)
124 | {
125 | perror("readdir");
126 | exit(1);
127 | }
128 | if (-1==closedir(dirp))
129 | {
130 | perror("closedir");
131 | exit(1);
132 | }
133 |
134 | sort (temp.begin(),temp.end(),no_case_sensitivity);
135 |
136 | int total=0;
137 |
138 | for(unsigned int i=0;ipw_name << " ";
232 | cout << grp->gr_name << " ";
233 | cout << setw(7) << right<< buff.st_size << " ";
234 | cout << setw(13) << time;
235 |
236 | if(S_ISDIR(buff.st_mode))
237 | {
238 | if (temp[i][0]=='.')
239 | cout << white << blue << right << temp[i] << RESET;
240 | else
241 | cout << blue << right << temp[i] << RESET ;
242 | }
243 | else if(buff.st_mode & S_IXUSR)
244 | cout << green << right<< temp[i] << RESET ;
245 |
246 | else
247 | cout << right << temp[i];
248 |
249 | cout << endl;
250 |
251 | }
252 | }
253 |
254 | void aflag(char *folder,bool flag)
255 | {
256 | vector temp;
257 | DIR *dirp;
258 | if(NULL==(dirp=opendir(folder)))
259 | {
260 | perror("opendir");
261 | exit(1);
262 | }
263 | struct dirent *filespecs;
264 | errno =0;
265 |
266 | while(NULL!=(filespecs = readdir(dirp)))
267 | {
268 | if ((!flag) &&((filespecs->d_name)[0]!='.')&&((filespecs->d_name)[1]!='.'))
269 | {
270 | temp.push_back(filespecs->d_name);
271 | }
272 | else if (flag&&flag_R&&(filespecs->d_name)[1]!='.')
273 | temp.push_back(filespecs->d_name);
274 | else if (flag)
275 | temp.push_back(filespecs->d_name);
276 |
277 | }
278 |
279 | if (errno!=0)
280 | {
281 | perror("readdir");
282 | exit(1);
283 | }
284 | if (-1==closedir(dirp))
285 | {
286 | perror("closedir");
287 | exit(1);
288 | }
289 | sort (temp.begin(),temp.end(),no_case_sensitivity);
290 | string test3 = folder;
291 | test3[test3.size()-1]=':';
292 | if(flag_R)
293 | cout << test3 << endl;
294 | printer(temp,folder);
295 | if(flag_R)
296 | cout << endl;
297 | if(flag_R)
298 | {
299 | for(unsigned int i=0;i temp;
334 | DIR *dirp;
335 | string ch = folder;
336 |
337 | if(NULL==(dirp=opendir(ch.c_str())))
338 | {
339 | perror("opendir");
340 | exit(1);
341 | }
342 | struct dirent *filespecs;
343 | errno =0;
344 | while(NULL!=(filespecs = readdir(dirp)))
345 | {
346 | if ((!flag) &&((filespecs->d_name)[0]!='.')&&((filespecs->d_name)[1]!='.'))
347 | {
348 | temp.push_back(filespecs->d_name);
349 | }
350 | else if (flag&&flag_R&&(filespecs->d_name)[1]!='.')
351 | temp.push_back(filespecs->d_name);
352 | else if (flag)
353 | temp.push_back(filespecs->d_name);
354 |
355 | }
356 | if (errno!=0)
357 | {
358 | perror("readdir");
359 | exit(1);
360 | }
361 | if (-1==closedir(dirp))
362 | {
363 | perror("closedir");
364 | exit(1);
365 | }
366 |
367 | sort (temp.begin(),temp.end(),no_case_sensitivity);
368 | string test3 = folder;
369 | test3[test3.size()-1]=':';
370 | if(flag_R)
371 | cout << test3 << endl;
372 | if(flag_l)
373 | lflag(folder,flag_a);
374 | else
375 | printer(temp,folder);
376 |
377 | if(flag_R)
378 | cout << endl;
379 | if(flag_R)
380 | {
381 | for(unsigned int i=0;i3)
469 | {
470 | test.resize(test.size()-1);
471 | }
472 |
473 | strcpy(folder,test.c_str());
474 | }
475 | else if(test1[0]!='.' && test1[1]!='/')
476 | {
477 |
478 | test = "./" + test1;
479 | test1 = test;
480 | if(test1.at(test1.size()-1)!='/')
481 | {
482 | test=test1 + "/";
483 | }
484 |
485 | strcpy(folder,test.c_str());
486 | }
487 | else
488 | {
489 | strcpy(folder,test1.c_str());
490 |
491 | }
492 | }
493 |
494 | test = folder;
495 | }
496 | i++;
497 | }
498 | if (!(flag_a||flag_l||flag_R))
499 | {
500 | aflag(folder,flag_a);
501 | exit(0);
502 | }
503 | else if (flag_a && flag_l && flag_R)
504 | {
505 | rflag(folder,flag_a);
506 | }
507 | else if(flag_a && flag_l)
508 | {
509 | lflag(folder,flag_a);
510 | }
511 | else if(flag_a && flag_R)
512 | {
513 | rflag(folder,flag_a);
514 | exit(0);
515 | }
516 | else if(flag_l && flag_R)
517 | {
518 | rflag(folder,flag_a);
519 | }
520 | else if(flag_a)
521 | {
522 | aflag(folder,flag_a);
523 | }
524 | else if(flag_l)
525 | {
526 | lflag(folder,flag_a);
527 | }
528 | else if(flag_R)
529 | {
530 | aflag(folder,flag_a);
531 | }
532 |
533 | delete folder;
534 |
535 | return 0;
536 | }
537 |
--------------------------------------------------------------------------------
/src/main.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 | using namespace std;
16 | void io_pipe(string input);
17 |
18 |
19 |
20 | void handler1(int signum)
21 | {
22 | if(signum==SIGINT)
23 | {
24 | cout << endl<0)//parent process is running
48 | {
49 |
50 | sigignore(SIGINT);
51 | if (-1 == wait(&status))// if the wait fails it displays error and exits
52 | {
53 | perror("wait");
54 | exit(1);
55 | }
56 | struct sigaction sa1;
57 | memset(&sa1, 0, sizeof(sa1));
58 |
59 | sa1.sa_handler = handler1;
60 | if(sigaction(SIGINT,&sa1,NULL)==-1)
61 | perror("sigaction");
62 |
63 |
64 | }
65 | }
66 | void checker(char** argvIN,char **argvOUT,char* ops,int& sz)//this is where the actual strtok takes place
67 | {
68 | int j=0;
69 | char *word= strtok(argvIN[0],ops);//finds whatever operation is put in and breaks it apart
70 |
71 | while (word!=NULL)
72 | {
73 | argvOUT[j] = word;
74 |
75 | word = strtok(NULL, ops);
76 | j++;
77 | }
78 | argvOUT[j]=0;
79 | sz=j; //also outputs the size of how many argv's were made
80 |
81 |
82 |
83 | delete[] word; //deallocates memory
84 | }
85 |
86 |
87 | void initial(char *inputchar, char** argv)//this is needed to initallize the first token to make things easier
88 | {
89 |
90 | char *word = strtok(inputchar,"");
91 | int i =0;
92 | while (word != NULL)
93 | {
94 | argv[i] = word;
95 |
96 | word = strtok(NULL, "");
97 | i++;
98 | }
99 | argv[i]=0;//this is where the string end
100 | delete[] word;
101 | }//the output on this should just be argv[0] which would have all the words in the inputchar
102 |
103 |
104 | void stringtoken(string input)
105 | {
106 | //put the input into characters rather than string
107 | char *inputchar = new char [input.length()+1];//makes a char* from string
108 | strcpy(inputchar,input.c_str());
109 |
110 | bool semi = false;
111 | bool andd = false;
112 | bool orr = false;
113 |
114 | bool spac = true;
115 |
116 | char *se = new char[3];
117 | char *an = new char[3];
118 | char *orrr = new char[3];
119 | char *spa = new char[3];
120 | char *exitC = new char[5];
121 |
122 |
123 | //just defining character pointers
124 | strcpy(exitC,"exit");
125 | strcpy(se,";");
126 | strcpy(an,"&&");
127 | strcpy(orrr,"||");
128 | strcpy(spa," \n");
129 |
130 |
131 |
132 | //these check if the operations are in the string and set the bool value
133 | if (input.find(";") != string::npos)
134 | semi = true;
135 | if (input.find("&&")!= string::npos)
136 | andd = true;
137 | if (input.find("||")!= string::npos)
138 | orr = true;
139 | //giving the size to each of the char **
140 | char **argvSEMI = new char*[strlen(inputchar)];
141 | char **argvANDD = new char*[strlen(inputchar)];
142 | char **argvORR = new char*[strlen(inputchar)];
143 | char **argvSPACE = new char*[strlen(inputchar)];
144 | char **argvIN = new char*[strlen(inputchar)];
145 |
146 | initial(inputchar,argvIN); //this puts the whole input into a char** for further breakdown
147 |
148 | int status = 0;
149 | int status1 =0;
150 |
151 | if(semi||andd||orr||spac)
152 | {
153 | int sz=0;
154 | checker(argvIN,argvSEMI,se,sz);
155 | for (int i=0;i ");
249 |
250 | int sz;
251 |
252 | bool out,dout,in,cerrr = false;
253 | bool sign = false;
254 |
255 |
256 |
257 | //take OPEN [1] tokenize the space out of it and then execute it and the OPEN [2] should be passed into open
258 |
259 | unsigned int first =1;
260 | char *holder;
261 | int x=0;
262 | while (first!=0)
263 | {
264 | if(x==3)
265 | sign = true;
266 | first =0;
267 | if(input.find(">")!=string::npos)
268 | {
269 | unsigned int temp = input.find(">");
270 | first = temp;
271 | if(temp-1>0)
272 | {
273 | if(input.at(temp-1)=='2')
274 | cerrr=true;
275 | }
276 | temp = temp +1;
277 | if(temp')
280 | out=true;
281 | else if(input.at(temp)=='>')
282 | {
283 | out =false;
284 | dout = true;
285 | }
286 | }
287 | }
288 | if(input.find("<")!=string::npos)
289 | {
290 | if(first>input.find("<")||first ==0)
291 | {
292 | first=input.find("<");
293 | out = false;
294 | cerrr=false;
295 | dout = false;
296 | in = true;
297 | }
298 | }
299 | string fake = input;
300 | if(cerrr)
301 | fake.resize(first-1);
302 |
303 | else
304 | fake.resize(first);
305 |
306 | if(first+1)" << endl;
348 |
349 | delete[] inputchar;
350 | delete[] fakechar;
351 | delete[] argvIN;
352 | delete[] argvSPACE;
353 | delete[] argvOPEN;
354 | delete[] spa;
355 | delete[] open1;
356 | return;
357 | }
358 | sign = false;
359 | }
360 |
361 | int status =0;
362 | int pid=fork();
363 | if (pid == -1)//there was an error with the forking
364 | {
365 | perror("fork");//if error does the proper error output
366 | exit(1);
367 | }
368 | else if (pid ==0)//if the child process is running
369 | {
370 | int cl =1;
371 | if(out)
372 | {
373 | if (cerrr)
374 | cl=2;
375 | if(-1==close(cl))
376 | perror("close");
377 | if(-1==open(holder,O_WRONLY|O_CREAT|O_TRUNC,0644))
378 | perror("open");
379 | }
380 | else if(dout)
381 | {
382 | if(cerrr)
383 | cl =2;
384 | if(-1==close(cl))
385 | perror("close");
386 | if(-1==open(holder,O_WRONLY|O_CREAT|O_APPEND,0644))
387 | perror("open");
388 | }
389 | else if(in)
390 | {
391 | if(-1==close(0))
392 | perror("close");
393 | if(-1==open(holder,O_RDONLY))
394 | perror("open");
395 | }
396 | if(-1==execvp(argvSPACE[0],argvSPACE))
397 | {
398 | status = -1;
399 | perror("execvp");
400 | }
401 |
402 | exit (1);
403 | }
404 | else if (pid >0)//parent process is running
405 | {
406 | if (-1 == wait(&status))// if the wait fails it displays error and exits
407 | {
408 | perror("wait");
409 | exit(1);
410 | }
411 | }
412 |
413 | out=false;
414 | dout=false;
415 | in=false;
416 |
417 | delete[] inputchar;
418 | delete[] fakechar;
419 | delete[] argvIN;
420 | delete[] argvSPACE;
421 | delete[] argvOPEN;
422 | delete[] spa;
423 | delete[] open1;
424 |
425 | }
426 |
427 |
428 | void cd1(string input)
429 | {
430 | char *cd = new char[3];
431 | char *spa = new char[3];
432 |
433 | //just defining character pointers
434 | strcpy(cd,"cd");
435 | strcpy(spa," ");
436 | char *inputchar = new char [input.length()+1];//makes a char* from string
437 | strcpy(inputchar,input.c_str());
438 |
439 | char **argvIN = new char*[strlen(inputchar)];
440 | char **argvSPACE = new char*[strlen(inputchar)];
441 | int sz;
442 | initial(inputchar,argvIN);
443 | checker(argvIN,argvSPACE,spa,sz);
444 | string checker=argvSPACE[0];
445 | if (checker!="cd" || sz>2)
446 | {
447 | cout << "Error: invalid call of the cd command" << endl;
448 | delete[] cd;
449 | delete[] spa;
450 |
451 | delete[] inputchar;
452 | delete[] argvIN;
453 | delete[] argvSPACE;
454 | return;
455 | }
456 |
457 | char* pPath;
458 | char* cwd;
459 | char buff[PATH_MAX + 1];
460 |
461 | if(argvSPACE[1]==NULL)//case where its just cd
462 | {
463 | cwd = getcwd( buff, PATH_MAX + 1 );
464 | if( cwd == NULL )
465 | perror("getcwd");
466 | if(-1==setenv("OLDPWD",cwd,1))
467 | perror("setenv");
468 |
469 | pPath=getenv("HOME");
470 | if(pPath==NULL)
471 | perror("getenv");
472 | if(-1==chdir(pPath))
473 | perror("chdir");
474 | if(-1==setenv("PWD",pPath,1))
475 | perror("setenv");
476 | pPath = getenv("OLDPWD");
477 |
478 | delete cd;
479 | delete spa;
480 |
481 | delete[] inputchar;
482 | delete[] argvIN;
483 | delete[] argvSPACE;
484 | return;
485 |
486 | }
487 |
488 | checker = argvSPACE[1];
489 | if(checker=="-")//case where it is cd -
490 | {
491 | cwd=getcwd(buff,PATH_MAX+1);
492 | if(cwd==NULL)
493 | perror("getcwd");
494 | pPath=getenv("OLDPWD");
495 | if(pPath==NULL)
496 | perror("getenv");
497 |
498 | if(-1==chdir(pPath))
499 | perror("chdir");
500 | if(-1==setenv("PWD",pPath,1))
501 | perror("setenv");
502 | if(-1==setenv("OLDPWD",cwd,1))
503 | perror("setenv");
504 |
505 | }
506 | else //case where it is cd
507 | {
508 | cwd = getcwd( buff, PATH_MAX + 1 );
509 | if( cwd == NULL )
510 | perror("getcwd");
511 | if(-1==setenv("OLDPWD",cwd,1))
512 | perror("setenv");
513 | if(checker=="~")
514 | {
515 | pPath = getenv("HOME");
516 | if(pPath==NULL)
517 | perror("getenv");
518 | checker=pPath;
519 | }
520 | if(-1==chdir(checker.c_str()))
521 | perror("chdir");
522 | cwd = getcwd(buff,PATH_MAX+1);
523 | if(cwd==NULL)
524 | perror("getcwd");
525 | if(-1==setenv("PWD",cwd,1))
526 | perror("setenv");
527 | }
528 |
529 | delete cd;
530 | delete spa;
531 |
532 | delete inputchar;
533 | delete[] argvIN;
534 | delete[] argvSPACE;
535 |
536 |
537 |
538 | }
539 |
540 |
541 |
542 | int main()
543 | {
544 | struct sigaction sa1;
545 | memset(&sa1, 0, sizeof(sa1));
546 |
547 | sa1.sa_handler = handler1;
548 |
549 | if(sigaction(SIGINT,&sa1,NULL)==-1)
550 | perror("sigaction");
551 |
552 | char* cwd;
553 |
554 | char buff[PATH_MAX + 1];
555 |
556 | cwd = getcwd( buff, PATH_MAX + 1 );
557 | if( cwd == NULL )
558 | perror("getcwd");
559 |
560 | if(-1==setenv("OLDPWD",cwd,1))
561 | perror("setenv");
562 |
563 | while (1)//infinite loop
564 | {
565 | cin.clear();
566 | string prompt; // make a string for the prompt
567 | char host[333];
568 | char *log = getlogin();
569 | prompt = log;
570 |
571 | if (!log) // get login info
572 | perror("getlogin"); //if its not there error
573 |
574 | if (gethostname(host,300) !=0) //get host info
575 | perror("gethostname"); // error otherwise
576 |
577 |
578 | ////////////////////////////////////////////////////////////////
579 | char* pPath1;
580 | pPath1 = getenv ("HOME");
581 | if (pPath1==NULL)
582 | perror("getenv");
583 |
584 | char* cwd;
585 |
586 | char buff[PATH_MAX + 1];
587 |
588 | cwd = getcwd( buff, PATH_MAX + 1 );
589 | if( cwd == NULL )
590 | perror("getcwd");
591 |
592 | string tpath = pPath1;
593 | string tpath2 = cwd;
594 | string prompt1;
595 | if(tpath2.find(tpath)!=string::npos)
596 | {
597 | prompt1 = tpath2.substr(tpath.size(),tpath2.size());
598 | prompt1 = "~" + prompt1;
599 | }
600 | else
601 | {
602 | prompt1 = tpath2;
603 | }
604 | ///////////////////////////////////////////////////////////////
605 |
606 | if (log && host!=NULL)
607 | {
608 | for (int i=0;i<50;i++)
609 | {
610 | if (host[i]=='.')
611 | host[i]='\0'; //this just makes it so the host ends at EX @hammer.cs.ucr.edu gets shortened to @hammer
612 | }
613 |
614 | prompt = prompt+"@"+host+ prompt1 + " $ "; //puts dchou002@hammer $ together
615 | }
616 | else // if host or login failed
617 | {
618 | prompt = prompt1 + "$ ";
619 |
620 | }
621 | string input;
622 | number_of_io_redirections=0;
623 | cout << prompt;
624 |
625 | getline(cin,input);//gets input
626 |
627 | if (input.find("#") != string::npos)//resizes if the comment is found
628 | {
629 | input.resize(input.find("#"));
630 | }
631 |
632 | bool cd_check = false;
633 |
634 | if(input.find("cd")!=string::npos)
635 | {
636 | char *spa = new char[3];
637 | strcpy(spa," ");
638 | char *inputchar = new char [input.length()+1];//makes a char* from string
639 | strcpy(inputchar,input.c_str());
640 |
641 | char **argvIN = new char*[strlen(inputchar)];
642 | char **argvSPACE = new char*[strlen(inputchar)];
643 | int sz;
644 | initial(inputchar,argvIN);
645 | checker(argvIN,argvSPACE,spa,sz);
646 | string checker=argvSPACE[0];
647 | if(checker == "cd")
648 | {
649 | cd_check = true;
650 | cd1(input);
651 | }
652 |
653 | delete[] spa;
654 | delete[] inputchar;
655 | delete[] argvIN;
656 | delete[] argvSPACE;
657 | }
658 | if(!cd_check)
659 | {
660 | if(input.find(">")!=string::npos || input.find(">>")!=string::npos||input.find("<")!=string::npos)
661 | io_pipe(input);
662 | else
663 | stringtoken(input);
664 | }
665 | }
666 | return 0;
667 | }
668 |
--------------------------------------------------------------------------------
/src/mv.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | using namespace std;
11 |
12 | int main(int argc, char** argv)
13 | {
14 |
15 | struct stat buffer;
16 | if(argc < 3)
17 | {
18 | if(argc < 2)
19 | {
20 | cerr << "mv: missing file operand\nTry mv--help for"<< " information" << endl;
21 | }
22 | else
23 | {
24 | cerr << "mv: missing destination folder after '" << argv[1] << "'\nTry mv--help for mor information" << endl;
25 | }
26 | exit(1);
27 | }
28 |
29 | string param1 = argv[1];
30 | if(stat(param1.c_str(), &buffer) == -1)
31 | {
32 | cerr << "File doesn not exist\n";
33 | exit(1);
34 | }
35 |
36 | string param2 = argv[2];
37 | if(stat(param2.c_str(), &buffer) == 0)
38 | {
39 | if(S_ISDIR(buffer.st_mode))
40 | {
41 | param2.append("/");
42 | param2.append(param1);
43 | if(link(param1.c_str(), param2.c_str()) != -1)
44 | {
45 | if(unlink(param1.c_str()) == -1)
46 | {
47 | perror("unlink");
48 | exit(1);
49 | }
50 | return 0;
51 | }
52 | else
53 | {
54 | perror("link");
55 | exit(1);
56 | }
57 | }
58 |
59 | else
60 | {
61 | cerr << "Directory doesn't exist\n";
62 | exit(1);
63 | }
64 | }
65 |
66 | if(link(param1.c_str(), param2.c_str()) != -1)
67 | {
68 | if(unlink(param1.c_str()) == -1)
69 | {
70 | perror("unlink");
71 | exit(1);
72 | }
73 | return 0;
74 | }
75 | else
76 | {
77 | perror("link");
78 | exit(1);
79 | }
80 |
81 |
82 | return 0;
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/src/rm.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 |
14 | using namespace std;
15 | bool recursive;
16 |
17 |
18 | void d_check(const char *folder,string value)
19 | {
20 | struct stat buff;
21 |
22 | if(lstat((folder),&buff)==-1)
23 | {
24 | perror("lstat");
25 | exit(1);
26 | }
27 |
28 | if(S_ISDIR(buff.st_mode)&& recursive)
29 | {
30 | DIR *dirp;
31 | if(NULL==(dirp=opendir(folder)))
32 | {
33 | perror("opendir");
34 | exit(1);
35 | }
36 | struct dirent *filespecs;
37 | errno =0;
38 | while(NULL!=(filespecs=readdir(dirp)))
39 | {
40 | string word = filespecs->d_name;
41 | string word1 = folder;
42 | if(word!="." && word !="..")
43 | {
44 | word = word1 + "/" +word;
45 | d_check(word.c_str(),value);
46 | }
47 | }
48 |
49 | if(errno!=0)
50 | {
51 | perror("readdir");
52 | exit(1);
53 | }
54 |
55 |
56 | if(-1==closedir(dirp))
57 | {
58 | perror("close");
59 | exit(1);
60 | }
61 |
62 | if(-1==rmdir(folder))
63 | {
64 | perror("rmdir");
65 | printf("%s", folder);
66 | exit(1);
67 | }
68 | return;
69 | }
70 | else if (S_ISDIR(buff.st_mode) && !recursive)
71 | {
72 | cerr << "rm: cannot remove '" << value << "': Is a directory" << endl;
73 | exit(1);
74 |
75 | }
76 | else
77 | {
78 | if(-1== unlink((folder)))
79 | {
80 | perror("unlink");
81 | exit(1);
82 | }
83 | return;
84 |
85 | }
86 |
87 | }
88 |
89 | int main(int argc, char **argv)
90 | {
91 | recursive = false;
92 | vector value;
93 | string word;
94 |
95 | if (argc==1)
96 | {
97 | cerr<<"No arguments" << endl;
98 | exit(1);
99 | }
100 |
101 | for (int i=1;i=(value.size()-1))
118 | break;
119 |
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/tests/exec.script:
--------------------------------------------------------------------------------
1 | Script started on Fri 17 Apr 2015 09:59:33 PM PDT
2 | ~
3 | dchou002@hammer $ cs[Ks1--[K[K00
4 | [0;91m
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 | [0m
23 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~[0;95m [0;36m$[0m cd CS100/rshell/
24 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m ls
25 | exec.script LICENSE Makefile README.md src tests
26 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m make #this should make the bin folder
27 | mkdir -p bin
28 | g++ -ansi -pedantic -Wall -Werror src/main.cpp -o bin/rshell
29 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m ls
30 | bin exec.script LICENSE Makefile README.md src tests
31 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m
[K[s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m
[K[s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m ls [K[K[Kbin/rshell
32 | dchou002@hammer $ ps
33 | PID TTY TIME CMD
34 | 13500 pts/85 00:00:00 bash
35 | 16152 pts/85 00:00:00 rshell
36 | 16154 pts/85 00:00:00 ps
37 | dchou002@hammer $ ls
38 | bin exec.script LICENSE Makefile README.md src tests
39 | dchou002@hammer $ ls -a
40 | . .. bin exec.script .git LICENSE Makefile README.md src tests
41 | dchou002@hammer $ asdf
42 | execvp: No such file or directory
43 | dchou002@hammer $ ls -a -b -c d- -d -g -h -m -n -l -s -r -t
44 | 4.0K drwx------ 6 507 4.0K Apr 17 21:55 .
45 | dchou002@hammer $ bin/rshell
46 | dchou002@hammer $ ps
47 | PID TTY TIME CMD
48 | 13500 pts/85 00:00:00 bash
49 | 16152 pts/85 00:00:00 rshell
50 | 16338 pts/85 00:00:00 rshell
51 | 16339 pts/85 00:00:00 ps
52 | dchou002@hammer $ bin/rshell
53 | dchou002@hammer $ ps
54 | PID TTY TIME CMD
55 | 13500 pts/85 00:00:00 bash
56 | 16152 pts/85 00:00:00 rshell
57 | 16338 pts/85 00:00:00 rshell
58 | 16359 pts/85 00:00:00 rshell
59 | 16360 pts/85 00:00:00 ps
60 | dchou002@hammer $ @ #this shows that therer are multiple rshells running inside eah chother other
61 | dchou002@hammer $ ls a && && ls -a
62 | bin exec.script LICENSE Makefile README.md src tests
63 | . .. bin exec.script .git LICENSE Makefile README.md src tests
64 | dchou002@hammer $ ps #you can even run commands on those other rshells
65 | PID TTY TIME CMD
66 | 13500 pts/85 00:00:00 bash
67 | 16152 pts/85 00:00:00 rshell
68 | 16338 pts/85 00:00:00 rshell
69 | 16359 pts/85 00:00:00 rshell
70 | 16508 pts/85 00:00:00 ps
71 | dchou002@hammer $ eix xit
72 | dchou002@hammer $ ps
73 | PID TTY TIME CMD
74 | 13500 pts/85 00:00:00 bash
75 | 16152 pts/85 00:00:00 rshell
76 | 16338 pts/85 00:00:00 rshell
77 | 16509 pts/85 00:00:00 ps
78 | dchou002@hammer $ exit ; ps
79 | dchou002@hammer $ ps
80 | PID TTY TIME CMD
81 | 13500 pts/85 00:00:00 bash
82 | 16152 pts/85 00:00:00 rshell
83 | 16525 pts/85 00:00:00 ps
84 | dchou002@hammer $ ls -a -l
85 | total 52
86 | drwx------ 6 dchou002 classes 4096 Apr 17 21:55 .
87 | drwx------ 5 dchou002 classes 4096 Apr 16 01:59 ..
88 | drwx------ 2 dchou002 classes 4096 Apr 17 21:55 bin
89 | -rw------- 1 dchou002 classes 0 Apr 17 21:53 exec.script
90 | drwx------ 8 dchou002 classes 4096 Apr 17 20:53 .git
91 | -rw------- 1 dchou002 classes 18047 Apr 8 15:37 LICENSE
92 | -rw------- 1 dchou002 classes 197 Apr 16 21:29 Makefile
93 | -rw------- 1 dchou002 classes 1028 Apr 17 20:32 README.md
94 | drwx------ 2 dchou002 classes 4096 Apr 17 19:28 src
95 | drwx------ 2 dchou002 classes 4096 Apr 17 21:32 tests
96 | dchou002@hammer $ ls && ls -a
97 | bin exec.script LICENSE Makefile README.md src tests
98 | . .. bin exec.script .git LICENSE Makefile README.md src tests
99 | dchou002@hammer $ ls || ls
100 | bin exec.script LICENSE Makefile README.md src tests
101 | dchou002@hammer $ ls || ls a -a
102 | bin exec.script LICENSE Makefile README.md src tests
103 | dchou002@hammer $ asdf || ls
104 | execvp: No such file or directory
105 | bin exec.script LICENSE Makefile README.md src tests
106 | dchou002@hammer $ ls || asdf
107 | bin exec.script LICENSE Makefile README.md src tests
108 | dchou002@hammer $ ls && asdf
109 | bin exec.script LICENSE Makefile README.md src tests
110 | execvp: No such file or directory
111 | dchou002@hammer $ adf && ls
112 | execvp: No such file or directory
113 | execvp: No such file or directory
114 | dchou002@hammer $ asdf && adf
115 | execvp: No such file or directory
116 | execvp: No such file or directory
117 | dchou002@hammer $ ls ; asdf
118 | bin exec.script LICENSE Makefile README.md src tests
119 | execvp: No such file or directory
120 | dchou002@hammer $ asdf ; ls
121 | execvp: No such file or directory
122 | bin exec.script LICENSE Makefile README.md src tests
123 | dchou002@hammer $ ls || ls-a -a && echo works pwd; ls -a && echo ls -t -a ; || adsf || echo pw ls -a -l t t -t ; echo hello
124 | bin exec.script LICENSE Makefile README.md src tests
125 | pwd
126 | . .. bin exec.script .git LICENSE Makefile README.md src tests
127 | execvp: No such file or directory
128 | bin . exec.script tests .git README.md src Makefile .. LICENSE
129 | hello
130 | dchou002@hammer $ ls || asdf && this work pwd
131 | bin exec.script LICENSE Makefile README.md src tests
132 | /class/classes/dchou002/CS100/rshell
133 | dchou002@hammer $ adf || ls && echo works
134 | execvp: No such file or directory
135 | bin exec.script LICENSE Makefile README.md src tests
136 | works
137 | dchou002@hammer $ ls -a || && ls
138 | . .. bin exec.script .git LICENSE Makefile README.md src tests
139 | bin exec.script LICENSE Makefile README.md src tests
140 | dchou002@hammer $ ls asdf || ls && || ls -a
141 | bin exec.script LICENSE Makefile README.md src tests
142 | . .. bin exec.script .git LICENSE Makefile README.md src tests
143 | dchou002@hammer $ ls || && ls -a
144 | bin exec.script LICENSE Makefile README.md src tests
145 | . bin .git Makefile src
146 | .. exec.script LICENSE README.md tests
147 | dchou002@hammer $ asdf || && ls -a
148 | execvp: No such file or directory
149 | execvp: No such file or directory
150 | dchou002@hammer $ ls && || ls -a
151 | bin exec.script LICENSE Makefile README.md src tests
152 | . bin .git Makefile src
153 | .. exec.script LICENSE README.md tests
154 | dchou002@hammer $ ls ; && ls -a
155 | bin exec.script LICENSE Makefile README.md src tests
156 | execvp: No such file or directory
157 | dchou002@hammer $ ls & ls -a
158 | bin exec.script LICENSE Makefile README.md src tests
159 | . bin .git Makefile src
160 | .. exec.script LICENSE README.md tests
161 | dchou002@hammer $ ls ;;;;;;;; ls||asdf
162 | bin exec.script LICENSE Makefile README.md src tests
163 | dchou002@hammer $ asdf||ls
164 | execvp: No such file or directory
165 | bin exec.script LICENSE Makefile README.md src tests
166 | dchou002@hammer $ ls&&ls pwd
167 | bin exec.script LICENSE Makefile README.md src tests
168 | /class/classes/dchou002/CS100/rshell
169 | dchou002@hammer $ pwd adfa&&pwd
170 | execvp: No such file or directory
171 | execvp: No such file or directory
172 | dchou002@hammer $ a pwd* &&ls
173 | /class/classes/dchou002/CS100/rshell
174 | bin exec.script LICENSE Makefile README.md src tests
175 | dchou002@hammer $ exit
176 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m bin/rshell
177 | dchou002@hammer $ exit; -l
178 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m bin/rshell
179 | dchou002@hammer $ exit ; rshel ls
180 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m bin.[K/rshell [K[K[K[K[K[K[K[K[K[K[Kbin/rshell
181 | dchou002@hammer $ ls - l l exit
182 | ls: cannot access exit: No such file or directory
183 | dchou002@hammer $ ; ls - l ls ls && ls -a a exit #doesnt not exit because it is ap passed as an argument parameter
184 | bin exec.script LICENSE Makefile README.md src tests
185 | ls: cannot access exit: No such file or directory
186 | dchou002@hammer $ ls -l;exit ; exit
187 | total 40
188 | drwx------ 2 dchou002 classes 4096 Apr 17 21:55 bin
189 | -rw------- 1 dchou002 classes 0 Apr 17 21:53 exec.script
190 | -rw------- 1 dchou002 classes 18047 Apr 8 15:37 LICENSE
191 | -rw------- 1 dchou002 classes 197 Apr 16 21:29 Makefile
192 | -rw------- 1 dchou002 classes 1028 Apr 17 20:32 README.md
193 | drwx------ 2 dchou002 classes 4096 Apr 17 19:28 src
194 | drwx------ 2 dchou002 classes 4096 Apr 17 21:32 tests
195 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m ls[K[Kbin/rshell
196 | dchou002@hammer $ ls -l # as you can see the comments do not affect anything
197 | total 40
198 | drwx------ 2 dchou002 classes 4096 Apr 17 21:55 bin
199 | -rw------- 1 dchou002 classes 0 Apr 17 21:53 exec.script
200 | -rw------- 1 dchou002 classes 18047 Apr 8 15:37 LICENSE
201 | -rw------- 1 dchou002 classes 197 Apr 16 21:29 Makefile
202 | -rw------- 1 dchou002 classes 1028 Apr 17 20:32 README.md
203 | drwx------ 2 dchou002 classes 4096 Apr 17 19:28 src
204 | drwx------ 2 dchou002 classes 4096 Apr 17 21:32 tests
205 | dchou002@hammer $ % # #comment by comment by itself
206 | dchou002@hammer $ ls -l#comments!!!!
207 | total 40
208 | drwx------ 2 dchou002 classes 4096 Apr 17 21:55 bin
209 | -rw------- 1 dchou002 classes 0 Apr 17 21:53 exec.script
210 | -rw------- 1 dchou002 classes 18047 Apr 8 15:37 LICENSE
211 | -rw------- 1 dchou002 classes 197 Apr 16 21:29 Makefile
212 | -rw------- 1 dchou002 classes 1028 Apr 17 20:32 README.md
213 | drwx------ 2 dchou002 classes 4096 Apr 17 19:28 src
214 | drwx------ 2 dchou002 classes 4096 Apr 17 21:32 tests
215 | dchou002@hammer $ ls -a ps# ls -a #there #as you can se no e no binary files
216 | . bin .git Makefile src
217 | .. exec.script LICENSE README.md tests
218 | dchou002@hammer $ ls || ls -a && ls ; ls || l pw pwd && ls -l ; ps ; echo this works ; bin/rshell &
219 | bin exec.script LICENSE Makefile README.md src tests
220 | bin exec.script LICENSE Makefile README.md src tests
221 | bin exec.script LICENSE Makefile README.md src tests
222 | total 40
223 | drwx------ 2 dchou002 classes 4096 Apr 17 21:55 bin
224 | -rw------- 1 dchou002 classes 0 Apr 17 21:53 exec.script
225 | -rw------- 1 dchou002 classes 18047 Apr 8 15:37 LICENSE
226 | -rw------- 1 dchou002 classes 197 Apr 16 21:29 Makefile
227 | -rw------- 1 dchou002 classes 1028 Apr 17 20:32 README.md
228 | drwx------ 2 dchou002 classes 4096 Apr 17 19:28 src
229 | drwx------ 2 dchou002 classes 4096 Apr 17 21:32 tests
230 | PID TTY TIME CMD
231 | 13500 pts/85 00:00:00 bash
232 | 29522 pts/85 00:00:00 rshell
233 | 30112 pts/85 00:00:00 ps
234 | this works
235 | dchou002@hammer $ cpp exit
236 | dchou002@hammer $ ps
237 | PID TTY TIME CMD
238 | 13500 pts/85 00:00:00 bash
239 | 29522 pts/85 00:00:00 rshell
240 | 30375 pts/85 00:00:00 ps
241 | dchou002@hammer $ exit
242 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m cppcheck vim[K[K[Ksrc/main.cpp
243 | Checking src/main.cpp...
244 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m exit
245 | exit
246 | ~
247 | dchou002@hammer $ exit
248 | exit
249 |
250 | Script done on Fri 17 Apr 2015 10:25:53 PM PDT
251 |
--------------------------------------------------------------------------------
/tests/piping.script:
--------------------------------------------------------------------------------
1 | Script started on Sun 17 May 2015 09:33:50 PM PDT
2 | ~
3 | dchou002@hammer $ cd[Ks100
4 | [0;91m
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 | [0m
24 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~[0;95m [0;36m$[0m cd CS100/rshell/
25 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m ls
26 | bin LICENSE Makefile README.md src tests
27 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m make
28 | mkdir -p bin
29 | g++ -ansi -pedantic -Wall -Werror src/main.cpp -o bin/rshell
30 | g++ -ansi -pedantic -Wall -Werror src/ls.cpp -o bin/ls
31 | g++ -ansi -pedantic -Wall -Werror src/cp.cpp -o bin/cp
32 | g++ -ansi -pedantic -Wall -Werror src/rm.cpp -o bin/rm
33 | g++ -ansi -pedantic -Wall -Werror src/mv.cpp -o bin/mv
34 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m ls
35 | bin LICENSE Makefile README.md src tests
36 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m bin/rshell
37 | dchou002@hammer $ ls
38 | bin LICENSE Makefile README.md src tests
39 | dchou002@hammer $ bin/ ls > this
40 | dchou002@hammer $ ls 0l -l > that
41 | dchou002@hammer $ ls
42 | bin LICENSE Makefile README.md src tests that this
43 | dchou002@hammer $ cat < this
44 | bin
45 | LICENSE
46 | Makefile
47 | README.md
48 | src
49 | tests
50 | this
51 | dchou002@hammer $ cat < that
52 | total 40
53 | drwx------ 2 dchou002 classes 4096 May 17 21:27 bin
54 | -rw------- 1 dchou002 classes 18047 Apr 8 15:37 LICENSE
55 | -rw------- 1 dchou002 classes 639 May 17 20:32 Makefile
56 | -rw------- 1 dchou002 classes 669 May 1 23:57 README.md
57 | drwx------ 2 dchou002 classes 4096 May 17 21:05 src
58 | drwx------ 2 dchou002 classes 4096 May 17 21:27 tests
59 | -rw------- 1 dchou002 classes 0 May 17 21:27 that
60 | -rw------- 1 dchou002 classes 46 May 17 21:27 this
61 | dchou002@hammer $ cat < this < that
62 | total 40
63 | drwx------ 2 dchou002 classes 4096 May 17 21:27 bin
64 | -rw------- 1 dchou002 classes 18047 Apr 8 15:37 LICENSE
65 | -rw------- 1 dchou002 classes 639 May 17 20:32 Makefile
66 | -rw------- 1 dchou002 classes 669 May 1 23:57 README.md
67 | drwx------ 2 dchou002 classes 4096 May 17 21:05 src
68 | drwx------ 2 dchou002 classes 4096 May 17 21:27 tests
69 | -rw------- 1 dchou002 classes 0 May 17 21:27 that
70 | -rw------- 1 dchou002 classes 46 May 17 21:27 this
71 | dchou002@hammer $ cat < ls -a > those this > this >> that >> those
72 | dchou002@hammer $ cat < this < that < those
73 | .
74 | ..
75 | bin
76 | .git
77 | LICENSE
78 | Makefile
79 | README.md
80 | src
81 | tests
82 | that
83 | this
84 | those
85 | dchou002@hammer $ cat < this
86 | bin
87 | LICENSE
88 | Makefile
89 | README.md
90 | src
91 | tests
92 | this
93 | dchou002@hammer $ cat < thos at
94 | total 40
95 | drwx------ 2 dchou002 classes 4096 May 17 21:27 bin
96 | -rw------- 1 dchou002 classes 18047 Apr 8 15:37 LICENSE
97 | -rw------- 1 dchou002 classes 639 May 17 20:32 Makefile
98 | -rw------- 1 dchou002 classes 669 May 1 23:57 README.md
99 | drwx------ 2 dchou002 classes 4096 May 17 21:05 src
100 | drwx------ 2 dchou002 classes 4096 May 17 21:27 tests
101 | -rw------- 1 dchou002 classes 0 May 17 21:27 that
102 | -rw------- 1 dchou002 classes 46 May 17 21:27 this
103 | dchou002@hammer $ ls -l >> this > that >> those
104 | dchou002@hammer $ cat < this
105 | dchou002@hammer $ cat < that
106 | dchou002@hammer $ cat < those
107 | .
108 | ..
109 | bin
110 | .git
111 | LICENSE
112 | Makefile
113 | README.md
114 | src
115 | tests
116 | that
117 | this
118 | those
119 | total 44
120 | drwx------ 2 dchou002 classes 4096 May 17 21:27 bin
121 | -rw------- 1 dchou002 classes 18047 Apr 8 15:37 LICENSE
122 | -rw------- 1 dchou002 classes 639 May 17 20:32 Makefile
123 | -rw------- 1 dchou002 classes 669 May 1 23:57 README.md
124 | drwx------ 2 dchou002 classes 4096 May 17 21:05 src
125 | drwx------ 2 dchou002 classes 4096 May 17 21:27 tests
126 | -rw------- 1 dchou002 classes 0 May 17 21:28 that
127 | -rw------- 1 dchou002 classes 0 May 17 21:28 this
128 | -rw------- 1 dchou002 classes 67 May 17 21:28 those
129 | dchou002@hammer $ ls asdf 2> this
130 | ca dchou002@hammer $ cat < this
131 | ls: cannot access asdf: No such file or directory
132 | dchou002@hammer $ ca ls adsfadsf asdf 2 2>> this
133 | dchou002@hammer $ cat < this
134 | ls: cannot access asdf: No such file or directory
135 | ls: cannot access adsfadsf: No such file or directory
136 | dchou002@hammer $ cat asdfasdf 2 >> this 2 >> > that
137 | dchou002@hammer $ cat M < this
138 | ls: cannot access asdf: No such file or directory
139 | ls: cannot access adsfadsf: No such file or directory
140 | dchou002@hammer $ cat < tho at
141 | cat: asdfasdf: No such file or directory
142 | dchou002@hammer $ cat that
143 | Error: case not handled (cannot combine < and >)
144 | dchou002@hammer $ #this is to shou w it can the eroor ror messages e
145 | dchou002@hammer $ c ls
146 | bin LICENSE Makefile README.md src tests that this those
147 | dchou002@hammer $ bin/rm this that
148 | dchou002@hammer $ bin /rm that
149 | dchou002@hammer $ ls
150 | bin LICENSE Makefile README.md src tests those
151 | dchou002@hammer $ bin / / / n/rm those
152 | dchou002@hammer $ bin / / l ls
153 | [1;34mbin [0m LICENSE Makefile README.md [1;34msrc [0m [1;34mtests [0m
154 | dchou002@hammer $ ei xit
155 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m exit
156 | exit
157 | do_ypcall: clnt_call: RPC: Unable to send; errno = Operation not permitted
158 | do_ypcall: clnt_call: RPC: Unable to send; errno = Operation not permitted
159 | ~
160 | dchou002@hammer $ exit
161 | exit
162 |
163 | Script done on Sun 17 May 2015 09:37:51 PM PDT
164 |
--------------------------------------------------------------------------------
/tests/signals.script:
--------------------------------------------------------------------------------
1 | Script started on Fri 29 May 2015 08:21:34 PM PDT
2 | ~
3 | dchou002@hammer $ cs100
4 | [0;91m
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 | [0m
24 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~[0;95m [0;36m$[0m cd CS100/rshell/
25 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m ls
26 | bin LICENSE Makefile README.md src tests
27 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m make
28 | mkdir -p bin
29 | g++ -ansi -pedantic -Wall -Werror src/main.cpp -o bin/rshell
30 | mkdir -p bin
31 | g++ -ansi -pedantic -Wall -Werror src/ls.cpp -o bin/ls
32 | lsmkdir -p bin
33 | g++ -ansi -pedantic -Wall -Werror src/rm.cpp -o bin/rm
34 | mkdir -p bin
35 | g++ -ansi -pedantic -Wall -Werror src/mv.cpp -o bin/mv
36 | mkdir -p bin
37 | g++ -ansi -pedantic -Wall -Werror src/cp.cpp -o bin/cp
38 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m lsls[K[K
39 | bin LICENSE Makefile README.md src tests
40 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m make
41 | mkdir -p bin
42 | g++ -ansi -pedantic -Wall -Werror src/main.cpp -o bin/rshell
43 | mkdir -p bin
44 | g++ -ansi -pedantic -Wall -Werror src/ls.cpp -o bin/ls
45 | mkdir -p bin
46 | g++ -ansi -pedantic -Wall -Werror src/rm.cpp -o bin/rm
47 | mkdir -p bin
48 | g++ -ansi -pedantic -Wall -Werror src/mv.cpp -o bin/mv
49 | mkdir -p bin
50 | g++ -ansi -pedantic -Wall -Werror src/cp.cpp -o bin/cp
51 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m ls
52 | bin LICENSE Makefile README.md src tests
53 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m bin [K/rshell
54 | dchou002@hammer~/CS100/rshell $ c - d -
55 | dchou002@hammer~/CS100/rshell $ cd -
56 | dchou002@hammer~/CS100/rshell $ cd home
57 | dchou002@hammer~ $ cd -
58 | dchou002@hammer~/CS100/rshell $ cd -
59 | dchou002@hammer~ $ cd -
60 | dchou002@hammer~/CS100/rshell $ cd -
61 | dchou002@hammer~ $ cd ..
62 | dchou002@hammer/class/classes $ cd ..
63 | dchou002@hammer/class $ cd ..
64 | dchou002@hammer/ $ cd -
65 | dchou002@hammer/class $ cd -
66 | dchou002@hammer/ $ cd ~
67 | dchou002@hammer~ $ cd .
68 | dchou002@hammer~ $ cd ..
69 | dchou002@hammer/class/classes $ cd dchou cd ~
70 | dchou002@hammer~ $ cd CS100/rshell
71 | dchou002@hammer~/CS100/rshell $ ls
72 | bin LICENSE Makefile README.md src tests
73 | dchou002@hammer~/CS100/rshell $ cd ll ..
74 | dchou002@hammer~/CS100 $ ls
75 | cheatsheetbash.txt firstrepo lab main.cpp rshell vimcheatsheet.txt
76 | dchou002@hammer~/CS100 $ cs cd cat
77 | ^Cdchou002@hammer~/CS100 $ l s s & cat
78 | cheatsheetbash.txt firstrepo lab main.cpp rshell vimcheatsheet.txt
79 | ^Cdchou002@hammer~/CS100 $ ^C
80 | dchou002@hammer~/CS100 $ ^C
81 | dchou002@hammer~/CS100 $ ^C
82 | dchou002@hammer~/CS100 $ ^C
83 | dchou002@hammer~/CS100 $ echo hello world && cat ce ello $$ %% # @$%^& && echo world; cat
84 | hello
85 | world
86 | ^Cdchou002@hammer~/CS100 $ cd ! ~
87 | dchou002@hammer~ $ cd pwd
88 | /class/classes/dchou002
89 | dchou002@hammer~ $ exit
90 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m export OLDPWD=""[K"
91 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m $old[K[K[KOLDPWD
92 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m BI[K[Kbin/rshell
93 | dchou002@hammer~/CS100/rshell $ cd -
94 | dchou002@hammer~/CS100/rshell $ cd -
95 | dchou002@hammer~/CS100/rshell $ e cd ~
96 | dchou002@hammer~ $ cd CS100rs /rshell
97 | dchou002@hammer~/CS100/rshell $ exit
98 | [s%%%%%%%%%%[u[0;32mdchou002[0;36m@[0;32mcs100[0;36m:[0;32m~/CS100/rshell[0;95m (master) [0;36m$[0m exit
99 | exit
100 | ~
101 | dchou002@hammer $ exi
102 | bash: exi: command not found
103 | ~
104 | dchou002@hammer $ tex[K[K[Kexit
105 | exit
106 |
107 | Script done on Fri 29 May 2015 08:28:08 PM PDT
108 |
--------------------------------------------------------------------------------