// $Id: afarutil.h,v 1.6 2011/08/25 22:32:26 lpoulsen Exp $
//
// Copyright (c) 2008 by AFAR Communications Inc, Santa Barbara, CA 93117 USA
//
// $Log: afarutil.h,v $
// Revision 1.6  2011/08/25 22:32:26  lpoulsen
// Updates to allow Linux build
//
// Revision 1.5  2011/07/08 21:50:30  lpoulsen
// Eliminate (almost all) use of debug_level, use debug_flags instead.
//
// Revision 1.4  2011/05/18 18:51:23  lpoulsen
// Runs on Fedora 14
//
// Revision 1.3  2011/03/22 00:26:10  lpoulsen
// Resolve sequence errors on very weak links
// Resolve hangs when Ctrl-C between "dir" and "download"
// Resolve conflicting build date information
//
// Revision 1.3  2010/11/20 01:49:48  lpoulsen
// Implement more F-keys
//
// Revision 1.2  2009/08/06 17:02:33  lpoulsen
// NRS Toolkit 1.15
//
// Revision 1.1  2009/07/08 00:25:05  lpoulsen
// Additional files for NRSA toolkit
//

#define KEY_BACK      0x100+VK_BACK
#define KEY_DELETE    0x100+VK_DELETE
#define KEY_DOWN      0x100+VK_DOWN
#define KEY_END       0x100+VK_END
#define KEY_HOME      0x100+VK_HOME
#define KEY_LEFT      0x100+VK_LEFT
#define KEY_NEXT      0x100+VK_NEXT
#define KEY_PRIOR     0x100+VK_PRIOR
#define KEY_RETURN    0x100+VK_RETURN
#define KEY_TAB       0x100+VK_TAB
#define KEY_UP        0x100+VK_UP
#define KEY_F1        0x100+VK_F1
#define KEY_F2        0x100+VK_F2
#define KEY_F3        0x100+VK_F3
#define KEY_F4        0x100+VK_F4
#define KEY_F5        0x100+VK_F5

#define KEY_KILL      0x003          // Control-C
#define KEY_ESC       0x01B          // Control-[ or ESCAPE

#define KEY_UNKNOWN  0x4FF

extern int debug_level;

extern char  *afar_date(const time_t t);
extern char  *afar_time(const time_t t);
extern char  *afar_date_64(const time64_t ft);
extern char  *afar_time_64(const time64_t ft);
extern char  *afar_console_gets(char *buffer, const int bufsz, int *terminator);
extern FILE  *afar_fopen_ext(const char *fname, const char *mode,
                                               const char *ext);
extern int    afar_idiv(int a, int b);  // int division rounding to nearest int
extern int    afar_kbhit(void);         // this one consumes the data

extern void   afar_pfc_setup(void);
extern uint32 afar_pfc_read(void);
extern uint32 afar_usec_delta(const uint32 start, const uint32 end);
extern uint32 afar_pfc_freq;

extern void   afar_smooth_setup(int index, int decay, int factor, int div,
                                                                  int initial);
extern void   afar_smooth_count(int index, int value);
extern int    afar_smooth_read(int index);
extern void   afar_smooth_set(int index, int value);

// format a percentage:
//  0.00 to 5.00 show as "2.1"
//  above 5.00   show as " 25"
//
char *fmt_uint_tenths(uint32 ival);
char *fmt_uint_sep(uint32 ival);   // 3,456,789

#ifdef WIN32
struct timezone
{
  int  tz_minuteswest; /* minutes W of Greenwich */
  int  tz_dsttime;     /* type of dst correction */
};
#endif

struct timezone;
extern int   gettimeofday(struct timeval *tv, struct timezone *tz);
extern char *strstr_nocase(const char *s1, const char *s2);
extern int   strncmp_nocase(const char *s1, const char *s2, size_t n);
extern char *strdup(const char *s);

// End
