#include <time.h>
#include <stdio.h>
#include <netinet/in.h>

#define BOLD_RESULTS 1

#define VERSION_STRING "1.0.1"
/* Version History
  1.0.0 - 12/12/5 - Added this (version) section.
                  - Added the bold print option.
  1.0.1 - 1/18/6  - Fixed printf compiler warnings on OS X
*/
void bold(void)
{
#ifdef BOLD_RESULTS
    printf("%c[1m", 27);
#endif
}

void normal(void)
{
#ifdef BOLD_RESULTS
  printf("%c[0m", 27);
#endif
}

int bigendian(void)
{
  short int si;

  printf("Assigning 0x0001 to a short int...");
  si = 0x0001;
  printf("Done.\n");

  char *c = (char *) &si;
  printf("Reading individual bytes. [0]=%02d, [1]=%02d\n", c[0], c[1]);

  /* 01 00 = Little endian */
  /* 00 01 = Big endian */
  if(c[0] == 1)
    return(0);
	
  return(1);
}

int main(int argc, char *argv[])
{
  unsigned short ns, ms;

  bold();
  printf("porttool");
  normal();

  printf(" - A tool to check for porting issues between platforms.\n");
  printf("           Version: %s\n\n", VERSION_STRING);

  printf("Data type : Size in bytes\n");
  printf("time_t    : %lu\n", (unsigned long)sizeof(time_t));
  printf("long long : %lu\n", (unsigned long)sizeof(long long));
  printf("double    : %lu\n", (unsigned long)sizeof(double));
  printf("float     : %lu\n", (unsigned long)sizeof(float));
  printf("size_t    : %lu\n", (unsigned long)sizeof(size_t));
  printf("long      : %lu\n", (unsigned long)sizeof(long));
  printf("short     : %lu\n", (unsigned long)sizeof(short));
  printf("char      : %lu\n", (unsigned long)sizeof(char));
  printf("int       : ");
  bold();
  printf("%lu\n", (unsigned long)sizeof(int));
  normal();

  printf("\n");

  if(bigendian())
  {
    printf("\nThis system is ");
    bold();
    printf("big-endian");
  }
  else
  {
    printf("\nThis system is ");
    bold();
    printf("little-endian");
  }

  normal();
  printf(".\n");

  ns = 80;
  ms = htons(ns);

  if(ns == ms)
    printf("htons() has no effect.\n");
  else
    printf("htons() changes a short.\n");

  
  return(0);
}