// $Id: show.c,v 1.4 2011/01/22 01:29:05 lpoulsen Exp $
//
// Copyright (c) 2008 by Afar Communications Inc, Santa Barbara, CA 93117 USA
//
// "show" command for ECON for Windows
//
// $Log: show.c,v $
// Revision 1.4  2011/01/22 01:29:05  lpoulsen
// Release candidate:
// - allow "show first=1 max=45" to support large systems
// - allow "sort by=distance" to support "connect all reboot"
// - improve download efficiency
//
// Revision 1.3  2008/07/26 02:00:48  lpoulsen
// Econ protocol version 4 - prompt bit
//
// Revision 1.2  2008/07/11 20:14:10  lpoulsen
// Resolve many compiler warnings on Linux
//
// Revision 1.1  2008/07/11 16:31:00  lpoulsen
// ECON 4.0 release candidate
//
//
#ifdef WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include "afartype.h"
#include "parser.h"
#include "epacket.h"  // for MAX_DEVICES
#include "ucon.h"     // for show_radios()

extern Arg      show_args[];
extern_cmd_func econ_show;

Select show_table_sel[] = {
  { "devices",    0             },
  { "radios",     PARSER_NOHELP },
  { NULL,         0             }
};

Select show_format_sel[] = {
  { "short",      0 },
  { "long",       0 },
  { NULL,         0 }
};

Arg show_args[] = {
  { "table",      SELECT(show_table_sel),    0 },
  { "format",     SELECT(show_format_sel),   0 },
  { "first",      INT(1,MAX_DEVICES),        0 },
  { "max-units",  INT(1,MAX_DEVICES),        0 },
  { NULL,         {UNDEF_ARG},               0 }
};

cmd_ret_t
econ_show(Argument_List *a, ucio_session *s)
{
    char   *tmp;
    uint16  sh_fmt;
    int     first, max;
    boolean error;

    tmp = parser_get_value(a, "format");

    if (tmp == NULL)
        tmp = "short";

    sh_fmt = parse_select_match(tmp, show_format_sel);

    tmp = parser_get_value(a, "table");

    if (tmp == NULL)
        tmp = "devices";

    first = parse_number(parser_get_value(a, "first"), 1, &error);

    max = parse_number(parser_get_value(a, "max-units"), 45, &error);

    switch(parse_select_match(tmp, show_table_sel))
    {
    case 0:    // devices
    case 1:    // radios
        show_radios(false, sh_fmt, first, max);
        printf("\n");
        break;
    }
    return CMD_SUCCESS;
}
