Projects

Project 1: Shell-ing out commands

posted Nov 21, 2017, 5:49 AM by JonAlf Dyrland-Weaver   [ updated Nov 22, 2017, 7:34 AM ]

You (and a partner if desired) are to write a shell. The shell should implement as many of these features as possible. The first being the most basic up to the last which is the most complex.
  1. Read a line at a time, parse the line to separate the command from its arguments. It should then fork and exec the command. The parent process should wait until the exec'd program exits and then it should read the next command.
    • Note: exit and cd cannot be run through a forked child process, you will have to implement these commands on your own.
      • check out the chdir() function
  2. Read and separate multiple commands on one line with ;. That is, the line ls -l ; echo hello should first run the command ls -l and then echo hello.  
  3. Implement simple redirection using > (redirecting stdout) and < (redirecting stdin). - This will be explained in class after Thanksgiving. 
  4. Implement simple pipes, that is: ls | wc would run ls and use the output from ls as the input for wc. - This will be explained in class after Thanksgiving.
    • Check out popen() for this. 
All of these commands work in bash, so use it to check out the functionality of each feature if you are unclear about anything.

Specific requirements
  1. Every function you write must have a function header describing the arguments, return value and what the function does.
    • Use modular design liberally. This is a large program.
  2. You should have a readme file with the following:
    1. A description of what features your shell implements
    2. A description of what features you attempted to implement but were unsuccessful
    3. Any bugs or things you want me to know about your program
      1. I am much more forgiving of reported bugs than bugs I discover while testing
    4. A copy of every function header
    5. An example of the readme file can be found in the github repository for this assignment
  3. This project should use separate C files as necessary.
  4. The project should be built using make and a makefile, I will only compile by using make. 
Project hints (If you're having trouble)
  1. To make your life easier, you could require that all items on the command line are to be separated by a single space.
  2. When parsing the line, it might help to count the number of tokens (individual pieces), before parsing.
  3. You can restrict the locations and ordering of > and <. 
  4. You can limit piping (|) to a single pipe. 
If you would like to implement other features after getting these ones down, please do. Look at what bash does and see what else you can do!

Github links (one directory per group - naming convention: lastF-lastF:
https://github.com/mks65/shell.git

Project 0: my_tunez

posted Oct 16, 2017, 7:15 AM by JonAlf Dyrland-Weaver   [ updated Oct 19, 2017, 12:30 PM ]

PROJECT DUE: 10:00pm Friday 10/20

You may work with up to 1 other person, and that is highly encouraged.

Write a program in C that implements a music library organizer. The data structure should consist of an array of 26 slots, one for each letter from 'a' to 'z' (you can convert everything to lower case to make comparisons easier). Each slot will contain a linked list of all the artists that have names with the corresponding letter. When you add a song, it should go on to a linked list at the appropriate array slot in the correct position alphabetically. Assume no duplicates.

Your nodes/links should be able to hold a song's title and artist. You might use structures like the following:
struct song_node{ 
  char name[256];
  char artist[256];
  struct song_node *next;
};


//and later:

struct song_node * table[27];

You should start by making your linked lists work with the following functionality:
  • insert nodes at the front
  • insert nodes in order
  • print the entire list
  • find and return a pointer to a node based on artist and song name
  • find and return a pointer to the first song of an artist based on artist name
  • Return a pointer to random element in the list.
  • remove a single specified node from the list
  • free the entire list
Then create your array of linked lists for the full program and have the following functions:
  • Add song nodes.
  • Search for a song given song and artist name (return a pointer).
  • Search for an artist (return a pointer).
  • Print out all the entries under a certain letter.
  • Print out all the songs of a certain artist
  • Print out the entire library.
  • Shuffle - print out a series of randomly chosen songs.
  • Delete a song
  • Delete all the nodes.
Files you should have:
  • A .c file that contains the main function you use to test all your work
  • At least one set of .h/.c files
    • For example, you can put your struct definition and your linked list headers in a .h file
    • You may also want to set up a .h/.c set for the playlist specific functions and a separate set for the linked list functions.
  • A makefile that will compile all the parts of your code and generate a single executable program
Git clone link:
https://github.com/mks65/my_tunez.git

You must test all the functions in your main function in order to receive full credit!!!

Example of reasonable testing output:
LINKED LIST TESTS
====================================

Testing print_list:
ac/dc: thunderstruck | pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
====================================

Testing print_node:
ac/dc: thunderstruck
====================================

Testing find_node:
looking for [pearl jam: even flow]
node found! pearl jam: even flow
looking for [pearl jam: daughter]
node not found
====================================

Testing find_artist:
looking for [pink floyd]
artist found! pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
looking for [pearl jam]
artist found! pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
looking for [presidents of the united states of america]
artist not found
====================================

Testing songcmp (helper function):
Comparing [pearl jam: even flow] to [pearl jam: even flow]
0
Comparing [pearl jam: even flow] to [pearl jam: alive]
4
Comparing [pearl jam: alive] to [pearl jam: even flow]
-4
Comparing [pearl jam: even flow] to [pink floyd: time]
-4
====================================

Testing random:
radiohead: paranoid android
radiohead: street spirit (fade out)
radiohead: street spirit (fade out)
radiohead: paranoid android
====================================

Testing remove:
Removing [pearl jam: alive]
ac/dc: thunderstruck | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
Removing [pearl jam: yellow ledbetter]
ac/dc: thunderstruck | pearl jam: even flow | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
Removing [pink floyd: alive]
pearl jam - alive not found
ac/dc: thunderstruck | pearl jam: even flow | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
====================================

Testing free_list
freeing node: ac/dc - thunderstruck
freeing node: pearl jam - even flow
freeing node: pink floyd - time
freeing node: radiohead - paranoid android
freeing node: radiohead - street spirit (fade out)
list after free_list:

====================================

MUSIC LIBRARY TESTS

====================================

Testing print_library
a list
ac/dc: thunderstruck | 
p list
pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | presidents of the united states of america: peaches | 
r list
radiohead: paranoid android | radiohead: street spirit (fade out) | 
====================================

Testing print_letter
p list
pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | presidents of the united states of america: peaches | 
====================================

Testing find:
looking for [pearl jam: alive]
song found! pearl jam: alive
looking for [pearl jam: time]
song not found
====================================

Testing find artist:
looking for [pearl jam]
artist found! pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | presidents of the united states of america: peaches | 
looking for [pink floyd]
artist found! pink floyd: time | presidents of the united states of america: peaches | 
looking for [bob dylan]
artist not found
====================================

Testing remove_song
removing: [pearl jam: alive]
a list
ac/dc: thunderstruck | 
p list
pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | presidents of the united states of america: peaches | 
r list
radiohead: paranoid android | radiohead: street spirit (fade out) | 

removing: [pearl jam: yellow ledbetter]
a list
ac/dc: thunderstruck | 
p list
pearl jam: even flow | pink floyd: time | presidents of the united states of america: peaches | 
r list
radiohead: paranoid android | radiohead: street spirit (fade out) | 
====================================

Testing clear_library:
freeing node: ac/dc - thunderstruck
freeing node: pearl jam - even flow
freeing node: pink floyd - time
freeing node: presidents of the united states of america - peaches
freeing node: radiohead - paranoid android
freeing node: radiohead - street spirit (fade out)

Library after clear:
====================================

Adding songs to empty library
a list
ac/dc: thunderstruck | 
p list
pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | 
====================================

Testing print_artist:
Printing [pearl jam]
[pearl jam: alive]
[pearl jam: even flow]
[pearl jam: yellow ledbetter]

Printing [ac/dc]
[ac/dc: thunderstruck]
====================================

Testing shuffle
ac/dc: thunderstruck
ac/dc: thunderstruck
pearl jam: yellow ledbetter
====================================

1-2 of 2