Lab Assignment--Tokenizing and Parsing

Part 1-Examine and Modify Existing Code

Use the following line to copy this week's code (A modification of a small part of Dr. Hilderman's HALshell):
cp /net/data/ftp/pub/class/330/Linux/Hilder_Exercise/Exercise/* .
  1. Store the answer to the following questions as comments at the beginning of main.cpp:
    1. What is Dr. Hilderman's code tokenizing based on (ie. what delimeter(s) separate(s) his words)?
    2. What are two reasons why his tokens are strings instead of c strings
  2. Add functionality to the ProcessCommand function so that "lo" will also cause the shell to exit

Part 2-Extend the Code

We want to be able to turn the tokens array into an array of c strings (In other words, in the format of char **). Build the following functions and call them from main:

A sample run might look something like the following

HALshell> This is a test
The words in reverse are: test a is This
HALshell> to see what happens
The words in reverse are: happens what see to
HALshell> It is a success
The words in reverse are: success a is It
HALshell> lo
The words in reverse are: lo

HALshell: terminating ...

When you run your code through valgrind using:
valgrind --leak-check=yes ./demo
A message like the following should be displayed:

==23683== HEAP SUMMARY:
==23683==     in use at exit: 0 bytes in 0 blocks
==23683==   total heap usage: 46 allocs, 46 frees, 992 bytes allocated
==23683== All heap blocks were freed -- no leaks are possible
==23683== For counts of detected and suppressed errors, rerun with: -v
==23683== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


Submit 4 files to URCourses:
  1. code for HALmod.cpp
  2. code for HALmod.h
  3. code for main.cpp
  4. script of run using valgrind