/* File: enum2.c
   A program that uses enumeration types
   and provides supporting functions.
*/
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"

/* Define a new type called rainbow */
enum rainbow_tag {red, orange, yellow, 
	  green, blue, indigo, violet} ;
typedef enum rainbow_tag rainbow ;

/* The function prototypes */
rainbow next_color(rainbow c) ;
void print_color(rainbow c) ;

/* This function returns the next color */
rainbow next_color(rainbow c) {
  return( (rainbow) (((int) c) + 1) ) ;
}

/* This function prints the name of the color */
void print_color(rainbow c) {
  switch(c) {
  case red:	printf("red") ; break ;
  case orange: 	printf("orange") ; break ;
  case yellow:	printf("yellow") ; break ;
  case green:	printf("green") ; break ;
  case blue:	printf("blue") ; break ;
  case indigo:	printf("indigo") ; break ;
  case violet:	printf("violet") ; break ;
  default: printf("black") ; break ;
  }
}

main() {
   rainbow color ;

   printf("The colors of the rainbow are:\n") ;
   color = red ;
   while (TRUE) {
     print_color(color) ;
     printf("\n") ;
     if (color == violet) break ;
     color = next_color(color) ;
   } 
}

