
/* =========================================================================== *
|                                                                              |
|  Example code for parsing Kobus's CS433 assignnments. It relies heavily on   |
|  the vision group's library (KJB library). You are allowed to use an         |
|  appropriately hacked version of this code in your assignments.              |
|                                                                              |
* =========================================================================== */

#include "l/l_incl.h"

/* -------------------------------------------------------------------------- */

int main(int argc, char* argv[])
{
    char        command[ 100 ];

    kjb_init();   /* Best to do this if using KJB library. */

    if ( ! kjb_isatty(fileno(stdin)))   /* A wrapper for isatty(2) */
    {
        char line[ LARGE_IO_BUFF_SIZE ]; /* A big number. */
        char*       line_pos;
        Int_vector* int_args_vp = NULL;
        int i, num_args; 


        /* 
         * Reads the next line into a buffer of specified size. Blank lines
         * with commnets are ignored. 
        */
        while (get_real_line(stdin, line, sizeof(line)) != EOF)
        {
            line_pos = line; 

            /* 
             * Extracts the first word up to a space or , or tab. */
            if (gen_get_token(&line_pos, command, sizeof(command), " ,\t") > 0)
            {
                /*
                 * Extracts integers into an KJB library data structure for a
                 * vector of integers. 
                */
                if (sget_int_vector(&int_args_vp, line_pos) == ERROR)
                {
                    kjb_print_error();
                    return EXIT_FAILURE;
                }

                /*
                 * Print out what we got to standard error. 
                */

                p_stderr("Your command was: %s\n", command); 

                num_args = int_args_vp->length;

                for (i = 0; i < num_args; i++)
                {
                    p_stderr("    Arg %d is %d\n", i + 1, int_args_vp->elements[ i ]); 
                }

                p_stderr("\n"); 

            }
        }

        free_int_vector(int_args_vp); 
    }

    kjb_cleanup(); /* Almost never needed, but doing it twice is OK. */

    return EXIT_SUCCESS;
}

/*  /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\   */


