/*======================================================================*/
/*  Calculator SHOW Command Routine(s)                                  */
/*======================================================================*/

#include stdio
#include ctype

/* calculator common definitions */

#include "calc_include.h"

/* global flags and variables */

extern int  debug_flag;
extern int  error_flag;


/*----------------------------------------------------------------------*/
/*  Display All Existing Symbols and Their Values                       */
/*                                                                      */
/*  Parameter  Description                                              */
/*                                                                      */
/*  options    processing option flags                                  */
/*  stringcnt  length of input string                                   */
/*  stringptr  address of input string                                  */
/*  tokencnt   length of current token                                  */
/*  tokenptr   address of current token                                 */
/*  character  character value of character token                       */
/*  number     binary value of numeric token                            */
/*  parameter  user supplied argument                                   */
/*                                                                      */
/*----------------------------------------------------------------------*/

int show_all_symbols (options,stringcnt,stringptr,tokencnt,
                      tokenptr,character,number,parameter)
int  options,stringcnt,tokencnt,number,parameter;
char character,stringptr[],tokenptr[];
{
   int i;

   display_all_symbols();

   return 1;
}


/*----------------------------------------------------------------------*/
/*  Display A Specified Symbol                                          */
/*                                                                      */
/*  Parameter  Description                                              */
/*                                                                      */
/*  options    processing option flags                                  */
/*  stringcnt  length of input string                                   */
/*  stringptr  address of input string                                  */
/*  tokencnt   length of current token                                  */
/*  tokenptr   address of current token                                 */
/*  character  character value of character token                       */
/*  number     binary value of numeric token                            */
/*  parameter  user supplied argument                                   */
/*                                                                      */
/*----------------------------------------------------------------------*/

int show_a_symbol (options,stringcnt,stringptr,tokencnt,
                   tokenptr,character,number,parameter)
int  options,stringcnt,tokencnt,number,parameter;
char character,stringptr[],tokenptr[];
{
   int  i,idx,limit;
   char var[strsize];

   if (debug_flag)
      printf("Symbol:     %.*s\n",tokencnt,tokenptr);

   /* calculate the number of characters to copy */

   if (tokencnt > strsize - 1)
      limit = strsize - 1;
   else  
      limit = tokencnt;

   /* extract symbol string from the command string*/

   for (i=0;i<limit;i++) var[i] = _toupper(tokenptr[i]);
   var[limit] = '\0';

   if (debug_flag)
      printf("Symbol      %s\n",var);

   /* search for and display the symbol */

   if (locate_symbol(&idx,var))
      display_a_symbol(idx);
   else
      printf("-- Symbol %s is currently not defined\n",var);

   return 1;
}
