#define NUMBER_OF_CONTESTS 10
#define NUMBER_OF_FIELDS 17
#define MAX_INIT_ITEMS 20
#define MAX_SET_ITEMS 13
#define MAX_KEYER_ITEMS 11
#define NUMBER_OF_SPEEDS 18
#define NUMBER_OF_PORTS 12
#define NUMBER_OF_RMS 3
#define MAX_LOCI 131
#define MAX_COUNTRIES 502
#define MAX_ZONES 41
#define MAX_BMAP_LINES 108
#define DX 0
#define WPX 1
#define FD 2
#define WAE 3
#define NYQP 4
#define WW 5
#define SS 6
#define A160 7
#define TEN 8
#define WAA 9
#define IDT_WELCOME 0
#define IDT_INITIAL 1
#define IDT_KEYER 2
#define IDT_SET 3
#define IDT_SUMMARY 4
#define IDT_LOG 5
#define IDT_LOCUS 6
#define IDT_INFO6 7
#define IDT_COUNTRY 8
#define IDT_HELP 9
#define IDT_ZONE6 10
#define IDT_COUZON 11
#define IDT_PREFIX 12
#define IDT_WHO 13
#define IDT_SUPER 14
#define IDT_PACKET 15
#define IDT_CREADER 16
#define IDT_RADIO 17
#define FT_IBAND 0
#define FT_MODE 1
#define FT_RC 2
#define FT_CALL 3
#define FT_RN 4
#define FT_DATE 5
#define FT_TIME 6
#define FT_SENT 7
#define FT_PX 8
#define FT_QSO 9
#define FT_ONOFF 10
#define FT_DUPE 11
#define FT_PTS 12
#define FT_TX 13
#define FT_NEXT1 NUMBER_OF_FIELDS-3
#define FT_NEXT2 NUMBER_OF_FIELDS-2
#define FT_NEXT3 NUMBER_OF_FIELDS-1
#define TIP_SCROLL 0
#define TIP_TIMER 1
#define TIP_REDRAW 2
#define TIP_PAUSE 3
#define TIP_DELETE 4
#define TIP_EDIT 5
#define TIP_CPACKET 6
#define TIP_SPACKET 7
#define TIP_ENTER 8
#define TIP_OFF 9
static const gchar *contest_abvs[NUMBER_OF_CONTESTS] = {
        [DX]="DX", [WPX]="WPX", [FD]="FD", [WAE]="WAE", [NYQP]="NYQP",
        [WW]="WW", [SS]="SS", [A160]="A160", [TEN]="TEN", [WAA]="WAA"};
static gint both_modes[NUMBER_OF_CONTESTS] = {
        [DX]=FALSE, [WPX]=FALSE, [FD]=TRUE, [WAE]=FALSE, [NYQP]=TRUE,
        [WW]=FALSE, [SS]=FALSE, [A160]=FALSE, [TEN]=TRUE, [WAA]=TRUE};
static const gchar *select_contest_items[NUMBER_OF_CONTESTS] = {
        [DX] = "ARRL Intl DX Contest",
        [WPX]= "CQ World Wide WPX Contest",
        [FD] = "ARRL Field Day",
        [WAE]= "Worked All Europe Contest",
        [NYQP]= "New York Qso Party",
        [WW] = "CQ World Wide DX Contest",
        [SS] = "ARRL November Sweepstakes",
        [A160]="ARRL 160-Meter Contest",
        [TEN]= "ARRL Ten Meter Contest",
        [WAA]= "Work Anyone Anywhere"};
static const gchar *continent_abvs[7] =
                   {"AF", "AN", "AS", "EU", "NA", "OC", "SA"};
static const gchar *continent_names[7] =
                   {"Africa", "Antarctica", "Asia", "Europe",
                    "N. America", "Oceania", "S. America"};
static const gchar *zone_chars[MAX_ZONES] = {" 0",
              " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", "10",
              "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
              "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
              "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"};
static GdkPixmap *pixmap = NULL;
static GdkGC *gc = NULL;
static PangoLayout *layout = NULL;
static guint GTK_TIME_DELAY = 10;
static gint BLACK = 0;
static gint BLUE = 1;
static gint GREEN = 2;
static gint CYAN = 3;
static gint RED = 4;
static gint MAGENTA = 5;
static gint ORANGE = 6;
static gint LT_GRAY = 7;
static gint DK_GRAY = 8;
static gint HI_BLUE = 9;
static gint HI_GREEN = 10;
static gint HI_CYAN = 11;
static gint HI_RED = 12;
static gint HI_MAGENTA = 13;
static gint YELLOW = 14;
static gint WHITE = 15;
static gint MID_GRAY = 16;
static gint NUMBER_OF_ROWS = 25;
static gint NUMBER_OF_COLUMNS = 80;
static gint REDRAW = 1;
static gint CLEAR = 1;
static gint SAVEPIX = 1;
static gint COPY = 1;
static gint CW = 0;
static gint PH = 1;
static gint CLOSE_SP = 0;
static gint OPEN_SP = 1;
static gint CURSOR_OFF = 0;
static gint LINE_CURSOR = 1;
static gint RESTART = 1;
static gint SPLIT_OFF = 0;
static gint SPLIT_ON = 1;
static gint main_cursor_type = 1;
static gint cursor_offset = 4;
static gint idisplay_type = 0;
static gint idt_save = 0;
static gint ireset_display = FALSE;
static gint ialt_de = FALSE;
static gint ialt_box = FALSE;
static gint ialt_p = FALSE;
static gint icaps_lock = FALSE;
static gint inum_lock = FALSE;
static gint log_lines[18] = {0, 0, 0, -1, 5, 19, 7, 12, 5, 5,
                             6, 12, 5, 5, 5, 5, 5, 5};
static gint ipage_screen[2][18] = {
                  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                  {0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 40, 0, 0, 0, 1, 0, 0}};
static gint knowledge_index = -1;
static gint knowledge_zindex = 0;
static gchar knowledge_prefix[6] = "";
static gint beam_index = -1;
static gint insert_mode = 0;
static gint icall_count = 0;
static gint iscroll_log = 0;
static gint isys_server = -1;
static gint isys_packet = -1;
static gint isys_creader = -1;
static gint restart_creader = FALSE;
static gint fd_fifocr = -1;
static const gchar *fifocr="kbfifo_c";
static gint creader_vol = 1;
static gint creader_freq = 65;
static gint creader_speed = 34;
static gint creader_line_num = -1;
static gchar creader_array[9][77] = {"", "", "", "", "", "", "", "", ""};
static const gchar *month_num = "010203040506070809101112";
static const gchar *month_array[12] = {"Jan", "Feb", "Mar", "Apr", "May",
                  "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static const gchar *fnn_char[2] = {"599", "59"};
static const gchar *mode_char[2] = {"CW", "PH"};
static const gchar *mode_bracket[2] = {"<CW>", "<PH>"};
static const gchar *mode_title[2] = {" CW", " Phone"};
static gint mode = 0;

#ifdef KBVHF
static const gchar *bandf[6] = {" 50", "144", "222", "432", "902", "1.2"};
static const gchar *bandw[6] = {"  6", "  2", "1.3", " 70", " 33", " 23"};
static const gchar *bandw_bracket[6] = {"<  6>", "<  2>", "<1.3>",
                                        "< 70>", "< 33>", "< 23>"};
#else
static const gchar *bandf[6] = {"1.8", "3.5", "7.0", " 14", " 21", " 28"};
static const gchar *bandw[6] = {"160", " 80", " 40", " 20", " 15", " 10"};
static const gchar *bandw_bracket[6] = {"<160>", "< 80>", "< 40>",
                                        "< 20>", "< 15>", "< 10>"};
#endif

static gdouble packet_band_limits[6][2] = {
                {1800.0, 2000.0}, {3500.0, 4000.0}, {7000.0, 7300.0},
                {14000.0, 14350.0}, {21000.0, 21450.0}, {28000.0, 29700.0}};
static gdouble phone_band_limits[6] = {1800.0, 3600.0, 7125.0,
                                        14150.0, 21200.0, 28300.0};
static const gchar *radio_default_freq[2][6] = {
        {"1830.0", "3530.0", "7030.0", "14030.0", "21030.0", "28030.0"},
        {"1830.0", "3830.0", "7230.0", "14230.0", "21300.0", "28500.0"}};
static gint iband = 0;
static gint packet_band=0;
static gint packet_bmap_page=0;
static const gchar *on_off_char[3] = {"   ", " ON", "OFF"};
static const gchar *power_bracket[3] = {"<QRP>", "<LOW>", "<HIGH>"};
static const gchar *category_bracket[8] = {"<SINGLE-OP>", "<SO-ASSIST>",
                    "<SO-TRI/SE>", "<M-SINGLE>", "<M-TWO/1>", "<M-TWO/2>",
                    "<M-MULTI>", "<SCHOOL>"};
static const gchar *speed_bracket[NUMBER_OF_SPEEDS] =
                    {"<12.0>", "<13.1>", "<14.4>", "<16.0>", "<16.9>",
                     "<18.0>", "<19.2>", "<20.6>", "<22.2>", "<24.0>",
                     "<26.2>", "<28.8>", "<32.0>", "<36.0>", "<41.1>",
                     "<48.0>", "<57.6>", "<72.0>"};

#ifdef BSD
 static const gchar *port_bracket[NUMBER_OF_PORTS] =
                     {"<OFF>", "<ttyd0>", "<ttyd1>", "<ttyU0>",
                      "<ttyU1>", "<ttyU2>", "<ttyU3>", "<ttyU4>",
                      "<ttyU5>", "<ttyU6>", "<ttyU7>", "<TELNET>"};
#else
 static const gchar *port_bracket[NUMBER_OF_PORTS] =
                     {"<OFF>", "<ttyS0>", "<ttyS1>", "<ttyUSB0>",
                      "<ttyUSB1>", "<ttyUSB2>", "<ttyUSB3>", "<ttyUSB4>",
                      "<ttyUSB5>", "<ttyUSB6>", "<ttyUSB7>", "<TELNET>"};
#endif

static const gchar *yn_bracket[2] = {"<YES>", "<NO>"};
static const gchar *dupe_bracket[2] = {"<ASK>", "<ALWAYS>"};
static const gchar *partial_bracket[3] = {"<NO>", "<2>", "<3>"};
static const gchar *radio_bracket[NUMBER_OF_RMS+1] =
                    {"<NONE>", "<FT-1000>", "<FT-950>", "<FT-5000>"};
static const gchar *cat_bracket[3] = {"<OFF>", "<KB>", "<USER>"};
static const gchar *init_screen_items[MAX_INIT_ITEMS] = {
                    " Station Call Sign", "Operator Call Sign",
                    "     Operator Name", "           Address",
                    "           Address", "              City",
                    "    State/Province", "   Zip/Postal Code",
                    "          Latitude", "         Longitude",
                    "     Offset to UTC", "    Entry Category",
                    "             Power", "      Contest Type",
                    "      Startup Band", "      Startup Mode",
                    "     CW Keyer Port", "       Packet Port",
                    "        Radio Port", "       Radio Model"};
static gchar init_screen_choices[MAX_INIT_ITEMS][26] = {"", "", "", "",
              "", "", "", "", "0.0N", "0.0W", "", "<SINGLE-OP>", "<HIGH>",
              "", "<10>", "<PH>", "<OFF>", "<OFF>", "<OFF>", "<NONE>"};
static gint init_length[MAX_INIT_ITEMS] = {13, 13, 25, 25, 25, 25, 2, 10, 5,
                                           6, 3, 11, 6, 4, 5, 4, 9, 9, 9, 10};
static const gchar *set_screen_items[MAX_SET_ITEMS] = {
                    "Default Sent Report", "          Dupe Mode",
                    "     Home Call List", "         Sound Bell",
                    "  New Mult Messages", "  Repeat Msg Number",
                    "   Repeat Msg Delay", " Calls for 1st Rate",
                    " Calls for 2nd Rate", " Threshold Off Time",
                    "Super Check Partial", "Shift Function Keys",
                    "     Radio Settings"};
static gchar set_screen_choices[MAX_SET_ITEMS][9] = {"", "<ASK>","<YES>",
      "<YES>", "<YES>", "1", "2000", "10", "50", "", "<3>", "<NO>", "<OFF>"};
static gint set_length[MAX_SET_ITEMS] = {6, 8, 5, 5, 5, 2, 4,
                                         3, 3, 4, 4, 5, 6};
static const gchar *keyer_screen_items[MAX_KEYER_ITEMS] = {
                    " Keyer Speed", "  Msgs 10-12",
                    "   Message 1", "   Message 2",
                    "   Message 3", "   Message 4",
                    "   Message 5", "   Message 6",
                    "   Message 7", "   Message 8",
                    "   Message 9"};
static gchar keyer_screen_choices[MAX_KEYER_ITEMS][63] = {"<24.0>",
              "<LOGGED CALL>, <?>, <TU>",
              "", "", "", "", "", "", "", "", ""};
static gint keyer_length[MAX_KEYER_ITEMS] = {6, 24, 62, 62, 62, 62, 62, 62,
                                             62, 62, 62};
static gint shift_fkeys = FALSE;
static FILE *fp_keyer = NULL;
static gint sending_cw = FALSE;
static gint repeat_message = FALSE;
static gint tuning_up = FALSE;
static gdouble cw_speed_adj = 1.0;
static gchar cw_line[81];
static FILE *fp_radio = NULL;
static gchar year_char[3];
static gchar full_year[5];
static gchar ini_file_name[13];
static gchar contest_file_base[9];
static gchar contest_file_name[13];
static gint hrow, wcol;
static gint isel_contest;
static gint utc_offset;
static struct tm kb_time;
struct kb_date_time
{
  gchar date[7];
  gchar time[7];
};
static struct kb_date_time kb_dt;
struct edit_string_vars
{
  guint ikey;
  gint cursor_row;
  gint *cursor_colp;
  gint field_col;
  gint field_length;
  gchar *field_linep;
};
typedef struct edit_string_vars ESVars;
struct call_record
{
  gint iband;
  gint mode;
  gchar rec_county[20];
  gchar call[14];
  gchar rec_num[8];
  gchar date[7];
  gchar time[7];
  gchar sent[7];
  gchar prefix[6];
  gchar qso[5];
  gchar on_off[4];
  gchar dupe[2];
  gchar points[2];
  gchar tx[2];
  gint mult[4];
};
static struct call_record cr_array[6500];
struct cyan_bar_vars
{
  gint row1;
  gint col1[NUMBER_OF_FIELDS];
  gint field_length[NUMBER_OF_FIELDS];
  gint item_order[NUMBER_OF_FIELDS];
  gint item;
  gint vf_w[8];
  gint cursor_row;
  gint cursor_col;
};
static struct cyan_bar_vars cbv = {.row1 = 24, .item = FT_CALL,
        .field_length = {3, 2, 19, 13, 7, 2, 4, 6, 5, 4,
                         3, 1, 1, 1, 13, 13, 13},
        .vf_w = {FT_CALL, FT_RN, -1, -1, -1, FT_NEXT1, FT_NEXT2, FT_NEXT3}};
struct comma_calls
{
  gint inq;
  gchar call[3][14];
};
static struct comma_calls qued = {.inq = FALSE, .call = {"", "", ""}};
struct locus_record
{ 
  gint number_of_loci;
  gint number_of_usloci;
  gint number_of_countyloci;
  gint locus_index;
  gint locus_worked[12][MAX_LOCI];
  gdouble locus_lat[MAX_LOCI];
  gdouble locus_long[MAX_LOCI];
  gchar locus_name[MAX_LOCI][23];
  gchar locus_abv[MAX_LOCI][5];
};
static struct locus_record loci;
struct country_record
{ 
  gint number_of_countries;
  gint icountry_index;
  gint iplus_country_index;
  gint izone_index;
  gint icountry_worked[6][MAX_COUNTRIES];
  gint izone_worked[6][MAX_ZONES];
  gdouble country_lat[MAX_COUNTRIES];
  gdouble country_long[MAX_COUNTRIES];
  gchar country_syn[MAX_COUNTRIES][151];
  gchar country_name[MAX_COUNTRIES][32];
  gchar country_abv[MAX_COUNTRIES][8];
  gchar continent_abv[MAX_COUNTRIES][3];
  gchar zones_in_country[MAX_COUNTRIES][21];
};
static struct country_record countries = {.number_of_countries = 0};
struct pick_box_vars
{
  gint num_match;
  gint item;
  gint pick_index[20];
  gint mouse_cols[2];
  guint key_handler_id;
  gint done;
};
static struct pick_box_vars pbv = {.done = TRUE};
struct tree_vars
{
  gint cmatch;
  gint clow;
  gint chigh;
  gint mbmatch;
  gint sort_order[6500];
};
static struct tree_vars call_tree;
struct px_tree_vars
{
  gint pmatch;
  gint npx;
  gchar px_array[6500][6];
};
static struct px_tree_vars px_tree;
struct call_lib_vars
{
  gint number_of_calls;
  gchar filnam[13];
  gchar call[10000][14];
  gchar year[10000][5];
  gchar country[10000][8];
  gchar cqzone[10000][3];
  gchar iaruzone[10000][3];
  gchar state[10000][3];
  gchar section[10000][4];
  gchar county[10000][20];
  gchar check[10000][3];
};
static struct call_lib_vars clib;
struct help_box_vars
{
  gint nhl;
  gchar help_lines[300][77];
};
static struct help_box_vars helpbv;
struct score_by_mode_band
{
  gint qsos[2][6];
  gint dupes[2][6];
  gint mults[2][6];
  gint zones[2][6];
  gint points[2][6];
  gchar values_char[6][2];
  gchar your_country[8];
};
static struct score_by_mode_band score_mb = {
  .qsos =   {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
  .dupes =  {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
  .mults =  {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
  .zones =  {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
  .points = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
  .your_country = {"UNKNOWN"}
};
struct boxed_message_vars
{
  gint row1;
  gint col1;
  gint row2;
  gint col2;
  gint box_color;
  guint answer;
  guint key_handler_id;
  gint done;
};
typedef struct boxed_message_vars BMVars;
struct mouse_click_vars
{
  gint row;
  gint col;
  gint row_prev;
  gint col_prev;
  gint button;
  gint button_prev;
};
static struct mouse_click_vars mcv = {.row = 0, .col = 0, .button = 0};
static void welcome_screen(GtkWidget *widget);
static void super_partial_box(GtkWidget *widget);
static void message_box(GtkWidget *widget, const gchar *message_line,
                        gint idraw, gint iclear);
static void knowledge_box(GtkWidget *widget, gint idraw);
static void search_tree (gint qnum, gint icc);
