/* A program shell to maintain a linked list of names */
/* author:  Henry M. Walker */ 

#include "node.h"
#include "list-proc.h"
#include <stdio.h>
#include <string.h>

#define MAXSTRLEN 128

/* Print menu options to the screen */
void
printMenu()
{
  printf("Options available\n");
  printf("I - Insert a name into the list\n");
  printf("D - Delete a name from the list\n");
  printf("C - Count the number of items on the list\n");
  printf("F - Move an item to the front of the list\n");
  printf("L - Print the last item on the list (iteratively)\n");
  printf("P - Print the names on the list (iteratively)\n");
  printf("R - Print the names in reverse order\n");
  printf("Q - Quit\n");
}

/* program to coordinate the menu options and call the requested function */
int
main(void)
{
  struct node * first = NULL;   /* pointer to the first list item */
  char option[MAXSTRLEN];          /* user response to menu selection */

  printf("Program to Maintain a List of Names\n");

  while (1) {
      printMenu(); /* print menu options */
      printf("Enter desired option: "); /* determine user selection */
      scanf("%s", option);
    
      switch (option[0]) {
        case 'I': // eye
        case 'i': addName(&first);
          break;
        case 'D':
        case 'd': deleteName(&first);
          break;
        case 'C':
        case 'c': countList(first);
          break;
        case 'F':
        case 'f': putFirst(&first);
          break;
        case 'L': // ell
        case 'l': printLast(first);
          break;
        case 'P':
        case 'p': print(first);
          break;
        case 'R':
        case 'r': printReverse(first);
          break;
        case 'Q':
        case 'q':
          printf("Program terminated\n");
          return 0;
          break;
        default: printf("Invalid Option - Try Again!\n");
          continue;
      } // switch
  } // while
} // main
