#include "ufk.h"

TABLE  show_table[] =
{
   "all", 1,
   "debug", 2,
   "escape", 3,
   "line", 4,
   "baud", 5,
   "configuration", 6,
   "timeout", 7,
   "filetype", 8,
   "log", 9,
   "duplex", 10,
   "handshake", 11,
   "block_check_type", 12,
   "repeat_quote", 13,
   "retry", 14,
   "packet_length", 15,
   "padding", 16,
   "padchar", 17,
   "start_of_packet", 18,
   "end_of_line", 19,
   "quote", 20,
   "eight_bit_quote", 21,
   "incomplete", 22,
   "delay", 23,
   "warning", 24,
   "mapping", 25,
   "auto_recover", 26,
   "attributes", 27,
   "", 0
};

show()
{
   int   fpoint;

   fpoint = parse(params[1], show_table); /* Parse 'show' command */
   if (fpoint == NULL)                    /* Ambiguous */
      prterr(ER_AMBIGSHW);
   else if (fpoint == ERROR)              /* Unknown */
      prterr(ER_UNKNWSHW);
   else                                   /* Dispatch to command if no error */
      switch(fpoint)
      {
         case 1:
                  show_all();
                  break;
         case 2:
                  show_debug();
                  break;
         case 3:
                  show_escape();
                  break;
         case 4:
                  show_line();
                  break;
         case 5:
                  show_baud();
                  break;
         case 6:
                  show_config();
                  break;
         case 7:
                  show_timeout();
                  break;
         case 8:
                  show_filetype();
                  break;
         case 9:
                  show_log();
                  break;
         case 10:
                  show_dup();
                  break;
         case 11:
                  show_hsh();
                  break;
         case 12:
                  show_block_check_type();
                  break;
         case 13:
                  show_repeat_quote();
                  break;
         case 14:
                  show_retry();
                  break;
         case 15:
                  show_packet_length();
                  break;
         case 16:
                  show_pding();
                  break;
         case 17:
                  show_pdchar();
                  break;
         case 18:
                  show_start_of_packet();
                  break;
         case 19:
                  show_end_of_line();
                  break;
         case 20:
                  show_quote();
                  break;
         case 21:
                  show_eight_bit_quote();
                  break;
         case 22:
                  show_incomplete();
                  break;
         case 23:
                  show_delay();
                  break;
         case 24:
                  show_warning();
                  break;
         case 25:
                  show_mapping();
                  break;
         case 26:
                  show_auto_recover();
                  break;
         case 27:
                  show_attributes();
      }
}

/*
 * Show various parameters
 */

show_all()
{
   show_line();
   show_baud();
   show_config();
   show_escape();
   show_filetype();
   show_warning();
   show_mapping();
   show_auto_recover();
   show_attributes();
   show_log();
   show_dup();
   show_debug();
   show_incomplete();
   show_hsh();
   show_retry();
   show_timeout();
   show_delay();
   show_start_of_packet();
   show_end_of_line();
   show_quote();
   show_eight_bit_quote();
   show_repeat_quote();
   show_packet_length();
   show_pding();
   show_pdchar();
   show_block_check_type();
}

show_debug()
{
   printf("Debug:\t\t\t\t");
   if (debug != 2)
      show_onoff(debug);
   else
      printf("File: %s\n",dbgfname);
}

show_dup()
{
   printf("Duplex:\t\t\t\t");
   if (fulldup)
      printf("Full\n");
   else
      printf("Half\n");
}

show_escape()
{
   printf("Escape character:\t\t%c\n", escchr);
}

show_line()
{
   printf("Line:\t\t\t\t%s\n",tty_descr);
}

show_baud()
{
   printf("Baudrate:\t\t\t%d baud\n", speed);
}

show_config()
{
   static char *conftab[] =
   {
      "7 bits, even parity, 2 stop bits",
      "7 bits, odd parity, 2 stop bits",
      "7 bits, even parity, 1 stop bit",
      "7 bits, odd parity, 1 stop bit",
      "8 bits, no parity, 2 stop bits",
      "8 bits, no parity, 1 stop bit",
      "8 bits, even parity, 1 stop bit",
      "8 bits, odd parity, 1 stop bit"
   };

   printf("Configuration:\t\t\t%s\n", conftab[config]);
}

show_timeout()
{
   printf("Timeout:\t\t\t%d seconds\n", mytime);
}

show_filetype()
{
   printf("Filetype:\t\t\t", image);
   if (image)
      printf("Binary\n");
   else
      printf("Ascii\n");
}

show_log()
{
   printf("Log file:\t\t\t");
   if (logfile[0])
      printf("%s\n", logfile);
   else
      printf("None\n");
}

show_hsh()
{
   if (dstart == 0 || dstop == 0)
      printf("Handshake:\t\toff\n");
   else
   {
      printf("Handshake start:\t\t%d (dec)\n", dstart);
      printf("Handshake stop: \t\t%d (dec)\n", dstop);
   }
}

show_quote()
{
   printf("Quote character:\t\t%c\n", myquote);
}

show_repeat_quote()
{
   printf("Repeat quote character:\t\t");
   if (myrptquote == 0)
      printf("None\n");
   else
      printf("%c\n",myrptquote);
}

show_eight_bit_quote()
{
   printf("Eight-bit quote character:\t");
   if (myeightquote == 0)
      printf("None\n");
   else
      printf("%c\n",myeightquote);
}

show_start_of_packet()
{
   printf("Start of packet:\t\t%02.2x (hex)\n", mypackstart);
}

show_retry()
{
   printf("Maximum retry's:\t\t%d (dec)\n", maxtry);
}

show_packet_length()
{
   printf("Packet length:\t\t\t%d (dec)\n", maxpacksiz);
}

show_end_of_line()
{
   printf("End of line character:\t\t%02.2x (hex)\n", myeol);
}

show_pding()
{
   printf("Padding count:\t\t\t%d (dec)\n", mypad);
}

show_pdchar()
{
   printf("Padding character:\t\t%02.2x (hex)\n", mypchar);
}

show_block_check_type()
{
   printf("Blockcheck type:\t\t");
   switch (myblock_check_type)
   {
      case 1:
               printf("One character checksum\n");
               break;
      case 2:
               printf("Two character checksum\n");
               break;
      case 3:
               printf("Three character CRC-CCITT\n");
               break;
   }
}

show_incomplete()
{
   printf("Incomplete file disposition:\t");
   if (save_file)
      printf("Keep\n");
   else
      printf("Discard\n");
}

show_delay()
{
   printf("Delay before sending:\t\t%d seconds\n",send_delay);
}

show_warning()
{
   printf("File conflict warning:\t\t");
   show_onoff(warning);
}

show_mapping()
{
   printf("Filename case mapping:\t\t");
   show_onoff(mapping);
}

show_auto_recover()
{
   printf("Auto packet length recovery:\t");
   show_onoff(auto_recover);
}

show_attributes()
{
   printf("Automatic file attributes:\t");
   show_onoff(allowattr);
}

show_onoff(flag)
int flag;
{
   if (flag)
      printf("On\n");
   else
      printf("Off\n");
}
