/*
   <p>Test harness for <i>byteout()</i>.</p>

   <kbd>
   <b>environ - C programming support functions</b><br>
   Copyright (C) 2005  Martin C Gregorie
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the Lesser GNU General Public License.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the Lesser GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   </kbd>
  
   <p>Contact Martin Gregorie at <i>martin@gregorie.org</i></p>
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <environ.h>

int main(int argc, char **argv)
{
   char           *arg;
   int            val;
   unsigned int   uval;
   int            bits;
   char           *result;
   
   if (strcmp(argv[1], "-?") == 0)
   {
      printf("testbyteout val\n");
      printf("    Test harness for byteout()\n");
      printf("    Val is the test value in hex or a character\n");
      printf("    If the value is over 1 character in length it\n");
      printf("    it will be treated as a decimal number.\n");
      printf("    Any sized hex value can be used to test truncation.\n");
      return 0;
   }

   if (argc != 2)
   {
      error("testbyteout", "must supply one argument", "");
   }

   arg = argv[1];
   if (strstr(arg, "0x") == arg ||
       strstr(arg, "0X") == arg)
   {
      sscanf(arg, "%x", &uval);
      val = uval;
   }
   else
   if (strlen(arg) == 1)
   {
      val = arg[0];
   }
   else 
   {
      sscanf(arg, "%d", &val);
   }

   printf("Outputting %c (0X%04X, %d)\n", val, val, val);
   result = byteout(val);
   printf("Result is [%s]\n", result);   
}
