#import <stdio.h>

#import "ValueStack.h"


main()

{   /* Local Variables */
    char    	    choice;
    unsigned long   size;
    id 	    	    stack;
    double  	    value;


printf("\t1 - Create stack\n");
printf("\t2 - Free stack\n");
printf("\t3 - Push value\n");
printf("\t4 - Peek value\n");
printf("\t5 - Pop  value\n");
printf("\t6 - Get stack size\n");
printf("\t7 - Print stack\n");
printf("\t8 - Clear stack\n");
printf("\tq - quit\n");          

choice = ' ';

while ( choice != 'q' )
    {
    if (choice != '\n')
        printf("\n\tEnter choice: ");

    choice = getc(stdin);

    switch (choice)
    	{
	case '1':   /* create stack */
    	    stack = [[ValueStack alloc] init];
    	    break;

	case '2':   /* Free stack */
    	    [stack free];
    	    break;

	case '3': /* Push value */
    	    printf("\tEnter value: ");
    	    scanf("%lf", &value);
    	    if ([stack Push:value] == nil)
    	    	printf("Push failed\n");
    	    break;

	case '4': /* Peek value */
    	    if ([stack Peek:&value] == nil)
    	    	printf("Peek failed\n");
    	    else
    	    	printf("Peek value = %lf\n", value);
    	    break;

	case '5': /* Pop  value */
    	    if ([stack Pop:&value] == nil)
    	    	printf("Pop failed\n");
    	    else
    	    	printf("Pop value = %lf\n", value);
    	    break;

	case '6': /* Get stack size */
    	    size = [stack GetSize];
    	    printf("Stack size = %ld\n", size);
    	    break;

	case '7': /* Print stack */
    	    [stack PrintStack];
    	    break;

	case '8': /* Clear stack */
    	    [stack ClearStack];
    	    break;

	case 'q': /* quit */
    	    break;

        case '\n':
    	    break;

    	default: /* display menu */
    	    printf("\t1 - Create stack\n");
    	    printf("\t2 - Free stack\n");
    	    printf("\t3 - Push value\n");
    	    printf("\t4 - Peek value\n");
    	    printf("\t5 - Pop  value\n");
    	    printf("\t6 - Get stack size\n");
    	    printf("\t7 - Print stack\n");
    	    printf("\t8 - Clear stack\n");
    	    printf("\tq - quit\n");
    	    break;
    	}/*switch*/

    }/*while*/
}/* END main */
