#include <exec/types.h>
#include <clib/exec_protos.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <clib/intuition_protos.h>
#include <libraries/gadtools.h>
#include <clib/gadtools_protos.h>
#include <libraries/expansion.h>
#include <libraries/expansionbase.h>
#include <libraries/configvars.h>
#include <clib/expansion_protos.h>
#include <graphics/gfx.h>
#include <clib/graphics_protos.h>

#include <ctype.h>
#include <stdlib.h>
#include "rp.h"
#include "boards.h"

#include <reaction/reaction.h>
#include <gadgets/chooser.h>
#include <pragmas/chooser_pragmas.h>
#include <gadgets/string.h>
#include <pragmas/string_pragmas.h>
#include <gadgets/integer.h>
#include <pragmas/integer_pragmas.h>
#include <gadgets/checkbox.h>
#include <pragmas/checkbox_pragmas.h>
#include <gadgets/layout.h>
#include <pragmas/layout_pragmas.h>
#include <gadgets/button.h>
#include <pragmas/button_pragmas.h>
#include <images/label.h>
#include <pragmas/label_pragmas.h>
#include <proto/label.h>
#include <classes/window.h>
#include <pragmas/window_pragmas.h>

#define MANUFS 272

MODULE  ULONG                 querymanuf,
                              queryproduct,
                              boards,
                              whichboard,
                              precedence;
MODULE  UWORD                 selectedmanuf   = 0,
                              selectedproduct = 0;
MODULE  struct ExpansionBase* ExpansionBase   = NULL;
MODULE  TEXT                  cardnumber[10];
MODULE  TEXT                  manuf_buffer[49],
                              product_buffer[49];
MODULE  ABOOL                 foundmanuf,
                              foundproduct;
MODULE  struct List           ManufChooserList;
MODULE  struct ChooserNode*   ManufChooserNodePtr[1 + 1];

MODULE void checklibrary(ULONG whichmanuf, ULONG whichproduct);
MODULE void checkinternal(ULONG whichmanuf, ULONG whichproduct);
MODULE void nomanuf(void);
MODULE void noproduct(void);
MODULE void runquery(ULONG whichmanuf, ULONG whichproduct);
MODULE void updatemanuf(void);
MODULE void autoquery(void);

// from rp.c
IMPORT WORD              xsize;
IMPORT ULONG             signal;
IMPORT SBYTE             page;
IMPORT ABOOL             fillwindows;
IMPORT TEXT              IOBuffer[LONGESTFIELD + 1];
IMPORT struct Window*    MainWindowPtr;
IMPORT struct Library*   BoardsBase;
IMPORT struct Screen*    ScreenPtr;
IMPORT struct Library   *ButtonBase,
                        *CheckBoxBase,
                        *ChooserBase,
                        *IntegerBase,
                        *LabelBase,
                        *LayoutBase,
                        *StringBase,
                        *WindowBase;
IMPORT struct Menu*      MenuPtr;
IMPORT Object*           WinObject[FUNCTIONS + 1];

MODULE struct
{   UWORD manuf;
    UBYTE product;
} board[32]; // how many boards are simultaneously attachable?

AGLOBAL struct Gadget*   manuf_gadgets[GIDS_5 + 1];

STRPTR ManufOptions[1 + 1] =
{   "Library, then internal",
    "Internal, then library"
};

MODULE struct
{   ULONG  number[3];
    UBYTE  howmany; // how many of the three numbers are registered.
    // They go from left to right.
    STRPTR name;
} manuf[MANUFS + 1] =
{
 1012,    -1,    -1, 1, "Access Associates",
 2003,    -1,    -1, 1, "ACDA",
 2149,    -1,    -1, 1, "ACS",
 2070,    -1,    -1, 1, "Active Circuits Inc.",
 1017,    -1,    -1, 1, "ADA Research",
 2056,  2061,    -1, 2, "Adept Development",
 2057,    -1,    -1, 1, "Advanced Computer Design",
 1046,    -1,    -1, 1, "Advanced Micro Innovations",
 2102,    -1,    -1, 0, "Advanced Storage Systems",
 2016,    -1,    -1, 1, "Akron Systems",
 2083,    -1,    -1, 1, "Alberta Micro Electronic Center",
 2130,    -1,    -1, 1, "Alfa-Laval",
 2063,    -1,    -1, 1, "Alphatech",
 2190,    -1,    -1, 1, "Altatech",
 5010,    -1,    -1, 1, "Ambience Creation Technology",
 2068,    -1,    -1, 1, "Amdev",
 2025,  2094,    -1, 2, "American Liquid Light",
 1053,    -1,    -1, 1, "Ameristar",
 2118,    -1,    -1, 1, "The Amiga Centre",
 2055,    -1,    -1, 1, "Amiga Solutions",
 1019,  2041,    -1, 2, "Amigo Business Computers",
 2176,    -1,    -1, 1, "AmiTrix Development",
 2183,    -1,    -1, 1, "AMOK - Amiga Module & Oberon Klub",
 2116,    -1,    -1, 1, "AMS",
 1009,    -1,    -1, 1, "Anakin Research",
 2007,  2121,    -1, 2, "Analog Electronics",
 1061,    -1,    -1, 1, "Analog Precision or D&L Distributing",
 2088,    -1,    -1, 1, "Applied Engineering",
 2207,    -1,    -1, 1, "Applied Magic Inc.",
 2028,  2054,    -1, 2, "Applied Systems & Peripherals/Xebec",
 2132,    -1,    -1, 1, "Archos",
 1023,    -1,    -1, 1, "ASDG Inc.",
 1005,    -1,    -1, 1, "A-Squared",
 2146,    -1,    -1, 1, "Atlantis",
 2036,    -1,    -1, 1, "Atronic",
 2143,    -1,    -1, 1, "Axellabs",
 2160,    -1,    -1, 1, "bbdp Electronics",
 2008,    -1,    -1, 1, "Bell & Howell",
 2093,    -1,    -1, 1, "Bernd Culenfeld",
 2084,    -1,    -1, 1, "Bestech",
 2105,    -1,    -1, 1, "Beta Unlimited",
 2069,    -1,    -1, 1, "Big Brother Security Systems",
 1043,    -1,    -1, 1, "B. J. Freeman",
 2098,    -1,    -1, 1, "Black Belt Systems",
 1011,    -1,    -1, 1, "Bob Krauth",
 2198,    -1,    -1, 1, "Bob Research Group",
 2066,    -1,    -1, 1, "Bowden, Williams, Full & Assoc.",
 2049,  2092,    -1, 2, "BSC (Elaborate Bytes)/Advanced Development Software",
 2033,    -1,    -1, 1, "BVR",
 2010,    -1,    -1, 1, "Byte Corp",
 2050,    -1,    -1, 1, "C. Ltd",
 2021,    -1,    -1, 0, "California Access (Synergy)",
 2018,    -1,    -1, 1, "Calmos",
 1055,    -1,    -1, 1, "Cardiac Pacemakers Inc.",
 2095,    -1,    -1, 1, "CEGITES",
 2074,    -1,    -1, 1, "The Checkered Ball",
 2024,    -1,    -1, 1, "CH Electronics",
 2114,    -1,    -1, 1, "C. H. Helfrich Electronik",
 2082,    -1,    -1, 1, "Circum Design Inc.",
 2077,    -1,    -1, 1, "Clartscreen Ltd. (UK)",
 2044,    -1,    -1, 1, "Clearpoint Research",
 1054,    -1,    -1, 1, "Cline Refrigeration",
26470, 49160,    -1, 0, "Combitec",
  515,    -1,    -1, 0, "Combitech/MacroSystems USA",
 2048,    -1,    -1, 1, "Commodore Braunschweig",
  513,   514,    -1, 0, "Commodore Business Machines",
 2134,    -1,    -1, 1, "Commodore Test Engineering Group",
 1018,    -1,    -1, 1, "Computer Service Italia",
 1026,  2052,    -1, 2, "Computer Tuning",
 1006,    -1,    -1, 1, "Comspec Communications",
 2204,    -1,    -1, 1, "Conspector Entertainment",
 2182,    -1,    -1, 1, "CP Computer",
 5011,    -1,    -1, 1, "Creative Development",
 1058,    -1,    -1, 1, "CSA",
 2122,    -1,    -1, 1, "Cumana",
 2186,    -1,    -1, 1, "Cyborg Design Services",
 2197,    -1,    -1, 1, "Cyon",
 2029,    -1,    -1, 1, "Delaware Valley Software",
 2161,    -1,    -1, 1, "Design Computer Systems",
 1041,    -1,    -1, 1, "Design Labs",
 1057,    -1,    -1, 1, "Diener, Wayne",
 2060,    -1,    -1, 1, "Digital Art Systems",
 2129,    -1,    -1, 1, "Digital Micronics",
 2119,    -1,    -1, 1, "Digital Pacific",
 2160,  2169,    -1, 2, "Digital Processing Systems",
 2015,    -1,    -1, 1, "Digitronics",
 2012,    -1,    -1, 1, "DKB Inc. (\"Michigan Software\")",
 2129,    -1,    -1, 0, "DMI",
 2019,    -1,    -1, 1, "Dover Research",
 2064,    -1,    -1, 1, "Edotronik GmbH",
 2206,    -1,    -1, 1, "Elbox Computer",
 2174,    -1,    -1, 1, "Electronic Design",
 2076,    -1,    -1, 1, "Elmtech Research Ltd. (UK)",
 2005,    -1,    -1, 1, "Elthen Electronics",
 2138,    -1,    -1, 1, "Evesham Micro Ltd.",
 2096,    -1,    -1, 1, "EV Industries",
 8290,    -1,    -1, 0, "Expansion Systems",
 1014,  2062,    -1, 2, "Expansion Technologies (Pacific Cypress)",
 2059,    -1,    -1, 1, "Expert Services",
 2137,    -1,    -1, 1, "Faberushi",
 2177,    -1,    -1, 1, "Ferranti",
 2004,    -1,    -1, 1, "Finn R. Jacobsen",
 4648,    -1,    -1, 1, "Flesch Hornemann Computer Elec.",
 2125,    -1,    -1, 1, "For Your Eyes",
 1015,    -1,    -1, 1, "Fuller Computers",
 2201,    -1,    -1, 1, "Fulvio Ieva",
 2187,    -1,    -1, 1, "G2 Systems",
 1016,    -1,    -1, 1, "Galaxy Computers",
 2079,    -1,    -1, 1, "Galysh Enterprises",
 2081,    -1,    -1, 1, "GBS",
 2142,    -1,    -1, 1, "GfxBase Inc.",
 2109,    -1,    -1, 1, "Gigatron OHG",
 2040,    -1,    -1, 1, "GIT",
 2180,    -1,    -1, 1, "GPSoft Pty. Ltd.",
 1051,    -1,    -1, 1, "GRC Electronics",
 2017,  1761,  2193, 1, "Great Valley Peripherals",
 2011,    -1,    -1, 0, "Hacker",
 2158,    -1,    -1, 1, "HAL Software Hardware Handel",
 2560,    -1,    -1, 0, "Harms",
 2166,    -1,    -1, 1, "Hamren, Thomas",
 2192,    -1,    -1, 1, "Hardware Design Udo Neuroth",
 2195,    -1,    -1, 0, "Helfrich",
 2075,    -1,    -1, 1, "Hi Tension Computer Services Ltd. (UK)",
 2113,    -1,    -1, 1, "H. K. Computers",
 2141,    -1,    -1, 1, "Hohabir, Daniel",
 2038,    -1,    -1, 1, "Howitch",
 1007,    -1,    -1, 1, "HT Electronics",
 2121,    -1,    -1, 0, "Hydra Systems",
 2071,    -1,    -1, 1, "ICD Inc.",
 2133,    -1,    -1, 1, "Icom Simulations",
 2104,    -1,    -1, 1, "Impulse Inc.",
 2031,    -1,    -1, 1, "Incognito Software",
 4626,    -1,    -1, 1, "Individual Computers",
 1047,    -1,    -1, 1, "Industrial Support Services",
 2151,    -1,    -1, 1, "Infinity Systems Design Group",
 1025,    -1,    -1, 1, "Ing. Buero Kalawsky",
 2195,    -1,    -1, 1, "Ingenieurbuero Helfrich",
 2112,    -1,    -1, 1, "Interactive Video Systems",
 1027,    -1,    -1, 1, "Interplan Unternehmensberatung",
 2078,    -1,    -1, 1, "Interworks/Network",
 2184,    -1,    -1, 1, "ITEK Neser & Sieber GbR",
 5000,    -1,    -1, 1, "ITH",
 2087,    -1,    -1, 1, "Ivis",
 2112,    -1,    -1, 0, "IVS",
 2032,    -1,    -1, 1, "Jadesign",
 2175,    -1,    -1, 1, "James Cook University of North Queensland",
 2052,    -1,    -1, 0, "Jochheim",
 2180,    -1,    -1, 1, "Juergen Kommos",
 2123,    -1,    -1, 1, "KAPS 2C Conception",
 2009,    -1,    -1, 1, "Kochler, Roland",
 2045,    -1,    -1, 1, "Kodiak",
 2020,    -1,    -1, 1, "Krehbiel, David",
 2043,    -1,    -1, 1, "Kruse, Ralph",
 2073,  4680,    -1, 1, "Kupke Computertechnik GmbH/Golem",
 1052,    -1,    -1, 1, "Lai, David",
 2085,    -1,    -1, 1, "Lasar Fantasy",
 2205,    -1,    -1, 1, "Laserforum",
 2185,    -1,    -1, 1, "Lello, Phillip C.",
 2178,    -1,    -1, 1, "Leviathan Development",
 2065,    -1,    -1, 1, "Logical Design Works",
 1030,    -1,    -1, 0, "Lowell University/Commodore Business Machines",
 1060,    -1,    -1, 1, "Lucas, David",
 2156,  4754,    -1, 2, "MacroSystems",
  256, 18260,    -1, 0, "MacroSystems USA",
 2159,    -1,    -1, 0, "Mainhattan-Data (A-Team)",
 1081,    -1,    -1, 0, "Marc Michael Groth",
 2194,    -1,    -1, 1, "Marpet Developments",
 2157,    -1,    -1, 1, "Masoboshi GmbH",
 2124,    -1,    -1, 1, "Mason, Mike",
 1042,    -1,    -1, 1, "MCS",
 2106,    -1,    -1, 1, "Memory Expansion Systems Ltd.",
 2159,    -1,    -1, 1, "Michael Lamm Computersysteme",
 1010,    -1,    -1, 1, "MicroBotics",
 2135,    -1,    -1, 1, "Microcreations",
 2042,    -1,    -1, 1, "Micro E Ab",
 1003,    -1,    -1, 1, "The Micro-Forge",
 2023,    -1,    -1, 1, "Micron Technology",
 1020,    -1,    -1, 1, "Micro-Solutions Inc.",
 2203,    -1,    -1, 1, "Micro System Devices",
 2002,    -1,    -1, 1, "Mimetics Corp.",
 1013,    -1,    -1, 1, "Mini Comp Systems Ltd.",
 2189,    -1,    -1, 1, "MSPI (Markt & Technik)",
 2131,    -1,    -1, 1, "Multigros A/S",
 2072,    -1,    -1, 1, "Multi-Meg Electronique",
 2196,    -1,    -1, 1, "The Neo Group",
 2067,    -1,    -1, 1, "NES Inc.",
 2111,    -1,    -1, 1, "New Technologies Group",
 2191,    -1,    -1, 1, "NewTek",
 2006,    -1,    -1, 1, "Nine Tiles Computer Systems Ltd.",
 2181,    -1,    -1, 1, "O. Bausch",
 1028,    -1,    -1, 1, "Ohlich, Peter",
 1045,    -1,    -1, 1, "Oklahoma Personal Comp.",
 2145,    -1,    -1, 1, "Omega Datentechnik",
 2165,    -1,    -1, 1, "Overland Engineering",
 2013,   211,    -1, 1, "Pacific Peripherals",
 2030,    -1,    -1, 1, "Palomax",
 2139,    -1,    -1, 1, "Panagolin Laser Software",
 2110,    -1,    -1, 1, "PG Electronics",
 2172,  8512,    -1, 1, "phase 5",
 2046,  2101, 46504, 2, "Phoenix Electronics",
 2108,    -1,    -1, 1, "Platypus Systems",
 2155,    -1,    -1, 1, "Power Computing Ltd.",
 2102,    -1,    -1, 1, "Preferred Technology",
 1030,    -1,    -1, 1, "Productivity Center",
 2026,   756,    -1, 1, "Progressive Peripherals and Software",
 1049,    -1,    -1, 1, "Prolific Inc.",
 2188,    -1,    -1, 1, "Pro System ComputerSysteme",
 2148,    -1,    -1, 1, "Protar Electronics",
 2086,    -1,    -1, 1, "Pulsar",
 1267,    -1,    -1, 1, "RBM Digitaltechnik",
 1008,    -1,    -1, 1, "RDS Software",
 2100,  8448,    -1, 1, "ReadySoft",
 2080,    -1,    -1, 1, "Realtime Games Software Ltd.",
43437,    -1,    -1, 0, "Reis-Ware",
 2199,    -1,    -1, 1, "Richmond Sound Design Ltd.",
 2144,    -1,    -1, 1, "Roctec Electronics Inc.",
 2103,    -1,    -1, 1, "Rombo Productions",
 1028,  4136,    -1, 0, "Ronin/Imtronics",
 2140,    -1,    -1, 1, "Rudloff, Thomas",
 8704,    -1,    -1, 0, "Sang/CT",
 2128,    -1,    -1, 1, "Scott Advanced Micro Designs",
 2037,    -1,    -1, 1, "Scott Karlin",
 2208,    -1,    -1, 1, "SDL Ltd.",
 2091,    -1,    -1, 1, "Seaview Software",
 2055,    -1,    -1, 0, "Serial Solutions (Checkpoint Technologies)",
 2136,    -1,    -1, 1, "Shoestring Productions",
 1044,    -1,    -1, 1, "Side Effects Inc.",
 2097,    -1,    -1, 1, "Silicon Peace",
 2202,    -1,    -1, 1, "Silicon Studio",
 2058,    -1,    -1, 1, "Sir Netics",
 1050,    -1,    -1, 1, "Softeam Inc.",
 2089,  2120,    -1, 2, "Solid State Design & Development/Solid State Leisure",
32768,    -1,    -1, 0, "SKI Peripherals",
 2147,    -1,    -1, 1, "Skytec Computers",
 2051,    -1,    -1, 1, "Spartanics",
 2034,  2035,    -1, 2, "Spirit Technology",
 2150,    -1,    -1, 0, "SRE",
 1021,    -1,    -1, 1, "Stacar International",
 2162,    -1,    -1, 1, "The Station",
 2039,    -1,    -1, 1, "Sullivan Brothers Visual Engineers",
 2164,  2170,    -1, 2, "Superformance Computer Engineering GmbH",
 2127,    -1,    -1, 1, "Sunrize Industries",
 2153,    -1,    -1, 1, "Suntec Inc.",
 1056,  1004,    -1, 2, "Supra Corp. (Creative Microsystems)", // 1004 is also unofficially claimed by C. Ltd
 2021,    -1,    -1, 1, "Synergy Peripheral Systems",
 2014,    -1,    -1, 1, "Sysaphus Software",
 1048,    -1,    -1, 1, "Technisoft",
 1001,    -1,    -1, 1, "Tecmar",
 1002,    -1,    -1, 1, "Telesys",
 2168,    -1,    -1, 1, "Toolbox Design",
 2152,    -1,    -1, 1, "Trade It",
 2053,    -1,    -1, 1, "Trans Data Systems",
 2128,    -1,    -1, 0, "Triceratops",
 2154,    -1,    -1, 1, "Tritec Marketing",
 1059,    -1,    -1, 1, "Trionix Inc.",
 2179,    -1,    -1, 1, "United Video Inc.",
 2150,    -1,    -1, 1, "University of Illinois",
 2200,    -1,    -1, 1, "US Cybernetics",
 2171,    -1,    -1, 1, "Utilities Unlimited",
 1022,    -1,    -1, 1, "Video Precisions",
 2167,    -1,    -1, 1, "Village Tronic",
 2193,    -1,    -1, 1, "Viona Developments",
 2090,    -1,    -1, 1, "Vision Quest",
 2126,    -1,    -1, 1, "Volkmar Breitfeld Computersysteme",
 2107,  8215,    -1, 1, "Vortex Computer Systems GmbH",
 5001,    -1,    -1, 1, "VMC",
 2027,    -1,    -1, 1, "Wicat Systems",
 2163,    -1,    -1, 1, "Williams, Bryan",
 2115,    -1,    -1, 1, "Xanadu",
 2022,    -1,    -1, 1, "Xetec",
 2117,    -1,    -1, 1, "X-Pert",
 2099,    -1,    -1, 1, "Yaeger, Steve",
 2047,    -1,    -1, 1, "?", // `no name shown'
};

#define PRODUCTS 174
struct
{   ULONG  manufid,
           number[2];
    STRPTR name;
    STRPTR desc;
} product[PRODUCTS + 1] =
{
 2026, 150,  -1, "Zeus 040",                            "68040 accelerator + 32-bit expansion memory + SCSI host adapter", 1056,  12,  -1, "WordSync HD Interface",               "SCSI host adapter",
 2203,  19,  -1, "Warp Engine",                         "68040 accelerator + 32-bit expansion memory",
  256,  19,  -1, "Warp Engine",                         "68040 accelerator + 32-bit expansion memory",
 1010,  68,  -1, "VXL RAM*32",                          "32-bit expansion memory",
 1010,  69,  -1, "VXL 30",                              "68030/6888x accelerator",
 2064,   8,  -1, "VME-Bus Controller",                  "VME-bus interface board",
18260,   4,  -1, "VLab Y/UV Digitizer",                 "Video digitizer board",
 2117,   2,  -1, "Visiona",                             "Graphics board (I/O area)",
 2117,   1,  -1, "Visiona",                             "Graphics board (memory area)",
 2113, 227,  -1, "Vektor I/O",                          "I/O board",
 2112, 243,  -1, "Vector",                              "68030/68882 accelerator + 32-bit expansion memory",
 2112,  48,  -1, "TrumpCard Classic",                   "SCSI host adapter",
 2112,  52,  -1, "TrumpCard Pro/Grand Slam",            "SCSI host adapter",
 1056,  10,  -1, "SupraRAM",                            "16-bit expansion memory",
 1056,   1,  -1, "SupraDrive 4x4 SCSI",                 "SCSI host adapter",
 1010,   2,  -1, "StarDrive",                           "SCSI host adapter",
 1010,   0,  -1, "StarBoard 2",                         "16-bit expansion memory",
46504,  33,  -1, "ST506 Autoboot",                      "MFM controller",
 2101,  33,  -1, "ST506 Autoboot",                      "MFM controller",
49160,  43,  -1, "SRAM Card",                           "Memory board",
 2034,   3,  -1, "SIN500",                              "16-bit expansion memory",
 2012,   9,  -1, "SecureKey",                           "Access control board",
32768, 128,  -1, "SCSI + Dual Serial",                  "SCSI host adapter/serial board",
46504,  34,  -1, "SCSI Autoboot",                       "SCSI host adapter",
 2101,  34,  -1, "SCSI Autoboot",                       "SCSI host adapter",
 2073,   2,  -1, "SCSI",                                "SCSI host adapter",
43437,  17,  -1, "Scan King",                           "Scanner",
  514,  96,  -1, "Romulator",                           "?",
18260,  16,  -1, "Retina Z3",                           "Graphics board",
18260,   6,  -1, "Retina",                              "Graphics board",
 2129,   1,  -1, "Resolver",                            "Graphics board",
 2088,  16,  -1, "RAM Works",                           "16-bit expansion memory",
 2052,   1,  -1, "RAM Board",                           "16-bit expansion memory",
 2022,   2,  -1, "RAM Board",                           "16-bit expansion memory",
 1023,   1,   2, "RAM Board",                           "16-bit expansion memory",
 2011,   2,  -1, "Quicknet QN2000",                     "Ethernet LAN board",
 2064,   6,  -1, "PIC Prototyping Board",               "Prototyping board",
 2195,  11,  -1, "Piccolo SD64",                        "Graphics board (I/O area)",
 2195,  10,  -1, "Piccolo SD64",                        "Graphics board (memory area)",
 2195,   6,  -1, "Piccolo",                             "Graphics board (I/O area)",
 2195,   5,  -1, "Piccolo",                             "Graphics board (memory area)",
 2167,  13,  -1, "Picasso ][",                          "Graphics board (segmented area)",
 2167,  12,  -1, "Picasso ][",                          "Graphics board (I/O area)",
 2167,  11,  -1, "Picasso ][",                          "Graphics board (memory area)",
 2112,  16,  -1, "OverDrive",                           "SCSI host adapter",
 4680,   1,  -1, "Omti HD Controller",                  "MFM controller",
 2073,   1,  -1, "Omti HD Controller",                  "MFM controller",
 2092,   5,  -1, "Oktagon",                             "SCSI host adapter",
 2034,   6,  -1, "OctaByte",                            "16-bit expansion memory",
 2102,   1,  -1, "Nexus",                               "SCSI host adapter",
 2128,   1,  -1, "Multiport I/O",                       "I/O board",
 2176,   1,  -1, "Multi-I/O",                           "I/O board",
 2092,  16,  17, "MultiFaceCard",                       "Serial/parallel board",
 2092,  18,  -1, "MultiFaceCard ]I[",                   "Serial/parallel board",
 2112,  64,  -1, "Meta-4",                              "16-bit expansion memory",
 2092,   8,  -1, "Memory Master",                       "16-bit expansion memory",
 2073,   3,  -1, "Memory Expansion",                    "16-bit expansion memory",
46504, 190,  -1, "Memory Board",                        "16-bit expansion memory",
 2101, 190,  -1, "Memory Board",                        "16-bit expansion memory",
 1010, 129, 193, "MBX 1200",                            "32-bit expansion memory",
 2021,   1,  -1, "Malibu SCSI",                         "SCSI host adapter",
 1058,  17,  -1, "Magnum 040",                          "68040 accelerator + 32-bit expansion memory",
 8704,   1,  -1, "Link-Interface",                      "Transputer link interface",
 1005,   1,  -1, "LIVE! A2000",                         "Video digitizer board",
 2050,   4,  -1, "Kronos 2000",                         "SCSI host adapter",
 1004,   4,  -1, "Kronos 2000",                         "SCSI host adapter",
 2092,  65,  -1, "ISDN-Master",                         "ISDN board",
 2034,   1,  -1, "Insider IN1000",                      "16-bit expansion memory",
 2034,   2,  -1, "Insider IN500",                       "16-bit expansion memory",
 2034,   8,  -1, "Inmate SCSI/FPU/RAM",                 "?",
 2017,  32,  -1, "Impact Vision 24",                    "Graphics board",
 2017,  11,  -1, "Impact Series ][ SCSI (DPRC)",        "SCSI host adapter (or I/O extender)",
 2017,   3,  -1, "Impact Series I SCSI 16K/3",          "SCSI host adapter",
 2017,   2,  -1, "Impact Series I SCSI 16K/2",          "SCSI host adapter",
 2017,   1,  -1, "Impact Series I SCSI 4K",             "SCSI host adapter",
 1761,   8,  -1, "Impact SCSI",                         "SCSI host adapter",
 2017,   8,  13, "Impact A3001 IDE HD",                 "68030/68882 accelerator + IDE controller",
 2064,   1,  -1, "IEEE-488 Controller",                 "IEEE-488 interface board",
 2159,   1,  -1, "IDE",                                 "IDE controller",
 2121,   1,  -1, "Hydra Ethernet",                      "Ethernet LAN board",
 4136,  57,  87, "Hurricane 2800",                      "68030/6888x accelerator + 32-bit expansion memory",
 1028,  57,  87, "Hurricane 2800",                      "68030/6888x accelerator + 32-bit expansion memory",
 2064,   3,  -1, "High-Speed Multiserial Interface",    "Serial board",
  211,  10,  -1, "HD Controller",                       "SCSI host adapter",
49160,  42,  -1, "HD Controller",                       "SCSI host adapter",
 2034,   4,  -1, "HDA-506",                             "MFM controller",
 1010, 150, 158, "HardFrame/2000",                      "SCSI host adapter",
 2112,   4,  -1, "GrandSlam",                           "SCSI/parallel/serial board",
 1023, 255,  -1, "GPIB or Dual Serial Board",           "IEEE-488 or Twin-X serial card",
 8215,   8,  -1, "GoldenGate 386SX RAM",                "80386SX bridgeboard/Amiga shared RAM",
 8215,   7,  -1, "GoldenGate 386SX",                    "80386SX bridgeboard",
 2150,   1,  -1, "GoldenGate ][",                       "Zorro ][-ISA bridgeboard",
 2017, 255,  -1, "G-Force 040 I/O ('040/2000)",         "Serial/parallel board",
 2142,   0,  -1, "GDA-1 VRAM",                          "Graphics board",
 2142,   1,  -1, "GDA-1",                               "Graphics board",
 2104,   0,  -1, "Firecracker",                         "Frame buffer",
 2092,  32,  -1, "Frame Buffer",                        "Graphics board",
 2022,   1,  -1, "FastTrak HD",                         "SCSI host adapter",
 8512,  10,  -1, "FastLane Z3",                         "SCSI host adapter + 32-bit expansion memory",
 2022,   3,  -1, "FastCard + HD Controller",            "?",
 2067,   0,  -1, "Expansion RAM",                       "16-bit expansion memory",
  756,   2,  -1, "EXP8000",                             "16-bit expansion memory",
 1053,   1,  -1, "Ethernet",                            "Ethernet LAN board",
 2193,   1,  -1, "EGS Spectrum",                        "Graphics board (I/O area)",
 2193,   2,  -1, "EGS Spectrum",                        "Graphics board (memory area)",
 1004,  14,  -1, "Escort",                              "SCSI host adapter",
 1023, 254,  -1, "EB-920 LanRover",                     "Ethernet LAN board",
 1009,   1,  -1, "Easyl",                               "Graphics tablet",
 2064,   9,  -1, "DSP96000 Real Time Data Acquisition", "Data acquisition board",
 2088,  16,  -1, "DL2000",                              "Modem",
 2055,   0,  -1, "Dual Port Serial",                    "Serial board",
 2129,   6,  -1, "Digital Broadcaster 32",              "Image processing board",
 8290,   1,  -1, "DataFlyer 500 SCSI",                  "SCSI host adapter",
 8512,  34,  -1, "CyberVision 64",                      "Graphics board",
 8512,  11,  -1, "CyberStorm",                          "68040 accelerator + 32-bit expansion memory",
 2176,   2,  -1, "CD-RAM",                              "16-bit expansion memory",
 2010,   0,  -1, "Byte Box A500",                       "?",
 8512,  24,  -1, "Blizzard A2060",                      "68060 accelerator + 32-bit expansion memory",
 8512,  17,  -1, "Blizzard 1230",                       "68030/68882 accelerator + 32-bit expansion memory",
 8512,   2,  -1, "Blizzard Turbo",                      "Accelerator board (I/O area)",
 8512,   1,  -1, "Blizzard Turbo",                      "Accelerator board (memory area)",
 2034,   5,  -1, "AX-S IBM Hardware I/O Board",         "I/O board",
 1006,   1,  -1, "AX2000",                              "16-bit expansion memory",
 8448,   1,  -1, "A-Max ][+/A-Max IV",                  "Macintosh emulation board",
 2049,   3,  -1, "ALF 3 SCSI",                          "SCSI host adapter",
 2049,   2,  -1, "ALF 2 SCSI",                          "SCSI host adapter",
 2049,   1,  -1, "ALF 2",                               "MFM controller",
 2071,   1,  -1, "Advantage 2000/AdSCSI",               "SCSI host adapter",
 2167, 201,  -1, "Adriadne",                            "Ethernet LAN + I/O board",
 2071,   4,  -1, "AdRAM 2080",                          "16-bit expansion memory",
 2071,   3,  -1, "AdIDE",                               "IDE controller",
  514,  84,  -1, "A4091",                               "SCSI host adapter",
 1053,  10,  -1, "A4066",                               "Ethernet LAN board",
  514,  97,  -1, "A3000 test fixture",                  "?",
  514,  81,  -1, "A2630",                               "68030/68882 accelerator + 32-bit expansion memory",
  514,  80,  -1, "A2620",                               "68020/68851/6888x accelerator + 32-bit expansion memory",
 1030,   0,  -1, "A2410",                               "Graphics board",
  513, 103,  -1, "A2386SX",                             "80386SX bridgeboard",
  513,   2,  -1, "A2286",                               "80286 bridgeboard",
  514,  70,  -1, "A2232",                               "Serial board",
  514,  69,  -1, "A2232 prototype",                     "Serial board",
  514,   3,  -1, "A2091",                               "SCSI host adapter",
  514,   4,  -1, "A2090B",                              "Autoboot card",
  515,   3,  -1, "A2090/A2090A",                        "MFM controller + SCSI host adapter with new driver",
  514,   1,  -1, "A2090/A2090A",                        "MFM controller + SCSI host adapter",
  513,   1,  -1, "A2088/A2286",                         "8088/80286 bridgeboard",
  514, 112,  -1, "A2065",                               "Ethernet LAN board",
 1053,   9,  -1, "A2060 Arcnet",                        "Arcnet LAN board",
  514,   9,  -1, "A2060",                               "Arcnet LAN board",
  514,  10,  -1, "A205x/A2091/A590",                    "16-bit expansion memory",
 2560, 208,  -1, "A2000 Turboboard 3500 Professional",  "68030/68882 accelerator + 32-bit expansion memory",
 1056,   3,  -1, "A2000 DMA HD Interface",              "SCSI host adapter",
 2017,  22,  -1, "A2000 060 Combo",                     "68060 accelerator + 32-bit expansion memory",
 1004,  12,  -1, "A1000/A2000 SCSI",                    "SCSI host adapter",
 2050,  12,  -1, "A1000 SCSI",                          "SCSI host adapter",
 1056,   2,  -1, "A1000 RAM Expansion",                 "16-bit expansion memory",
  514,   2,  -1, "A590",                                "SCSI host adapter/XT controller",
  514,  32,  -1, "A560",                                "16-bit expansion memory",
 1056,  13,  -1, "A500 ByteSync HD Interface",          "SCSI host adapter",
 1056,   8,  -1, "A500 Autoboot HD Interface",          "SCSI host adapter",
 2073,   5,  -1, "68030 (asynchronous)",                "68030/6888x accelerator",
 2073,   4,  -1, "68030 (synchronous)",                 "68030/6888x accelerator",
 2064,   2,  -1, "8032 Development Adapter",            "CBM-8032 board?",
 1056,  16,  -1, "2400zi+",                             "Modem",
 1056,  11,  -1, "2400zi",                              "Modem",
 1056,   9,  -1, "500/2000 RX",                         "16-bit expansion memory",
 1056,   5,  -1, "500 HD/RAM",                          "SCSI host adapter + 16-bit expansion memory",
 2026, 105,  -1, "040/A2000 Board",                     "68040 accelerator + 32-bit expansion memory",
 2064,   5,  -1, "32-Bit Parallel I/O Interface",       "Parallel board",
 2064,   4,  -1, "24-Bit Real Time Video Digitizer",    "Video digitizer board",
 2064,   7,  -1, "16-Channel ADC Interface",            "Analog to digital board",
 1058,  21,  -1, "12 Gauge",                            "68030/68882 accelerator + 32-bit expansion memory",
 1010,   4,  -1, "8-UP! (Z)",                           "16-bit expansion memory",
 1010,   3,  -1, "8-UP! (A)",                           "16-bit expansion memory"
};

MODULE void runquery(ULONG whichmanuf, ULONG whichproduct)
{   /* This function takes a manufacturer and product ID and attempts
    to update the text gadgets with a relevant text description.

    If ~0 (-1) is passed for either the manufacturer or product ID,
    the function returns instantly without doing anything. */

    selectedmanuf   =
    selectedproduct = (UWORD) ~0;

    if (whichmanuf == (ULONG) ~0 || whichproduct == (ULONG) ~0)
    {   return;
    }

    SetGadgetAttrs
    (   manuf_gadgets[GID_5_CB1], MainWindowPtr, NULL,
        GA_Selected, FALSE,
        TAG_END
    );
    SetGadgetAttrs
    (   manuf_gadgets[GID_5_CB2], MainWindowPtr, NULL,
        GA_Selected, FALSE,
        TAG_END
    );

    if (precedence == 1)
    {   checkinternal(whichmanuf, whichproduct);
        if (foundmanuf) // found int. manuf, maybe int. product
        {   if (!foundproduct) // found int. manuf but not int. product
            {   noproduct();
        }   }
        else
        {   checklibrary(whichmanuf, whichproduct);
            if (!foundmanuf)
            {   nomanuf();
                noproduct();
    }   }   }
    else
    {   assert(precedence == 0);
        checklibrary(whichmanuf, whichproduct);
        if (!foundmanuf) // can't find lib. manuf/product
        {   checkinternal(whichmanuf, whichproduct);
            if (foundmanuf) // found int. manuf, maybe int. product
            {   if (!foundproduct) // found int. manuf but not int. product
                {   noproduct();
            }   }
            else
            {   nomanuf();
                noproduct();
}   }   }   }

MODULE void updatemanuf(void)
{   if (whichboard == 0)
    {   SetGadgetAttrs
        (   manuf_gadgets[GID_5_BU2], MainWindowPtr, NULL,
            GA_Disabled, TRUE,
            TAG_END
        );
    } else
    {   SetGadgetAttrs
        (   manuf_gadgets[GID_5_BU2], MainWindowPtr, NULL,
            GA_Disabled, FALSE,
            TAG_END
        );
    }

    if (whichboard < boards)
    {   SetGadgetAttrs // next card
        (   manuf_gadgets[GID_5_BU3], MainWindowPtr, NULL,
            GA_Disabled, FALSE,
            TAG_END
        );
        SetGadgetAttrs // manuf ID
        (   manuf_gadgets[GID_5_IN1], MainWindowPtr, NULL,
            GA_Disabled, TRUE,
            INTEGER_Number, board[whichboard].manuf,
            TAG_END
        );
        SetGadgetAttrs // product ID
        (   manuf_gadgets[GID_5_IN2], MainWindowPtr, NULL,
            GA_Disabled, TRUE,
            INTEGER_Number, board[whichboard].product,
            TAG_END
        );
        stcl_d(cardnumber, whichboard + 1);
        SetGadgetAttrs // card
        (   manuf_gadgets[GID_5_ST1], MainWindowPtr, NULL,
            STRINGA_TextVal, cardnumber,
            TAG_END
        );
    } else
    {   SetGadgetAttrs // next card
        (   manuf_gadgets[GID_5_BU3], MainWindowPtr, NULL,
            GA_Disabled, TRUE,
            TAG_END
        );
        SetGadgetAttrs // manuf ID
        (   manuf_gadgets[GID_5_IN1], MainWindowPtr, NULL,
            GA_Disabled, FALSE,
            INTEGER_Number, querymanuf,
            TAG_END
        );
        SetGadgetAttrs // product ID
        (   manuf_gadgets[GID_5_IN2], MainWindowPtr, NULL,
            GA_Disabled, FALSE,
            INTEGER_Number, queryproduct,
            TAG_END
        );
        SetGadgetAttrs // card
        (   manuf_gadgets[GID_5_ST1], MainWindowPtr, NULL,
            STRINGA_TextVal, "Queryable",
            TAG_END
        );
    }
    runquery(board[whichboard].manuf, board[whichboard].product);
}

AGLOBAL void manuf1(void)
{   struct ConfigDev*   ThisConfigDev;
    ULONG               i;
    struct Hook         Hook5Struct;
    
    NewList(&ManufChooserList);
    for (i = 0; i <= 1; i++)
    {   if (!(ManufChooserNodePtr[i] = (struct ChooserNode *) AllocChooserNode(CNA_Text, ManufOptions[i], TAG_DONE)))
        {   rq("Can't allocate chooser node!");
        }
        AddTail(&ManufChooserList, (struct Node *) ManufChooserNodePtr[i]);
    } // automatically freed by ReAction at DisposeObject() time

    if (ExpansionBase = (struct ExpansionBase *) OpenLibrary(EXPANSIONNAME, 0))
    {   /* Use FindConfigDev() to get info on the first expansion board on
        the list maintained by Exec. */

        if (ThisConfigDev = FindConfigDev(NULL, -1, -1))
        {   board[0].manuf = ThisConfigDev->cd_Rom.er_Manufacturer;
            board[0].product = ThisConfigDev->cd_Rom.er_Product;
            boards = 1;

            /* OK, there is at least one board, so loop and get the
            entire list. */
            while (ThisConfigDev = FindConfigDev(ThisConfigDev, -1, -1))
            {   board[boards].manuf = ThisConfigDev->cd_Rom.er_Manufacturer;
                board[boards++].product = ThisConfigDev->cd_Rom.er_Product;
        }   }
        else boards = 0;
        CloseLibrary((struct Library *) ExpansionBase);
    }

    /* Create the window object. */
    lockscreen();
    gadtools();
    InitHook(&Hook5Struct, Hook5Func, NULL);
    if (!(WinObject[5] =          NewObject(WINDOW_GetClass(), NULL,
    // window
    WA_PubScreen,                 ScreenPtr,
    WA_ScreenTitle,               "Report+",
    WA_Title,                     "Report+: Manufacturer IDs",
    WA_Activate,                  TRUE,
    WA_DepthGadget,               TRUE,
    WA_DragBar,                   TRUE,
    WA_CloseGadget,               TRUE,
    WA_SizeGadget,                TRUE,
    WA_IDCMP,                     IDCMP_RAWKEY,
    WA_Width,                     xsize, // kludge
    WINDOW_IDCMPHook,             &Hook5Struct,
    WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
    WINDOW_MenuStrip,             MenuPtr,
    WINDOW_Position,              WPOS_CENTERSCREEN,
    WINDOW_ParentGroup,           manuf_gadgets[GID_5_LY1] =
    NewObject
    (   LAYOUT_GetClass(),        NULL,
        // root-layout
        LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
        LAYOUT_SpaceOuter,        TRUE,
        LAYOUT_DeferLayout,       TRUE,
        LAYOUT_ShrinkWrap,        TRUE,
        LAYOUT_AddChild,          NewObject
        (   LAYOUT_GetClass(),    NULL,
            // layout
            LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
            LAYOUT_SpaceOuter,    TRUE,
            LAYOUT_VertAlignment, LALIGN_CENTER,
            LAYOUT_HorizAlignment,LALIGN_CENTER,
            LAYOUT_BevelStyle,    BVS_NONE,
            LAYOUT_AddChild,
            NewObject
            (   LAYOUT_GetClass(),    NULL,
                // layout
                LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
                LAYOUT_SpaceOuter,    TRUE,
                LAYOUT_VertAlignment, LALIGN_CENTER,
                LAYOUT_HorizAlignment,LALIGN_LEFT,
                LAYOUT_BevelStyle,    BVS_NONE,
                LAYOUT_AddChild,
                NewObject
                (   LAYOUT_GetClass(),        NULL,
                    LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
                    LAYOUT_SpaceOuter,        TRUE,
                    LAYOUT_HorizAlignment,    LALIGN_RIGHT,
                    LAYOUT_BevelStyle,        BVS_FIELD,
                    LAYOUT_AddImage,          NewObject
                    (   LABEL_GetClass(),     NULL,
                        LABEL_Text,           "Card:",
                        LABEL_Justification,  LJ_RIGHT,
                        TAG_END
                    ),
                    TAG_END
                ),
                LAYOUT_AddChild,
                NewObject
                (   LAYOUT_GetClass(),        NULL,
                    LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
                    LAYOUT_SpaceOuter,        TRUE,
                    LAYOUT_HorizAlignment,    LALIGN_RIGHT,
                    LAYOUT_BevelStyle,        BVS_FIELD,
                    LAYOUT_AddImage,          NewObject
                    (   LABEL_GetClass(),     NULL,
                        LABEL_Text,           "Manufacturer:",
                        LABEL_Justification,  LJ_RIGHT,
                        TAG_END
                    ),
                    TAG_END
                ),
                LAYOUT_AddChild,
                NewObject
                (   LAYOUT_GetClass(),        NULL,
                    LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
                    LAYOUT_SpaceOuter,        TRUE,
                    LAYOUT_HorizAlignment,    LALIGN_RIGHT,
                    LAYOUT_BevelStyle,        BVS_FIELD,
                    LAYOUT_AddImage,          NewObject
                    (   LABEL_GetClass(),     NULL,
                        // label
                        LABEL_Text,           "Product:",
                        LABEL_Justification,  LJ_RIGHT,
                        TAG_END
                    ),
                    TAG_END
                ),
                LAYOUT_AddChild,
                NewObject
                (   LAYOUT_GetClass(),        NULL,
                    LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
                    LAYOUT_SpaceOuter,        TRUE,
                    LAYOUT_HorizAlignment,    LALIGN_RIGHT,
                    LAYOUT_BevelStyle,        BVS_FIELD,
                    LAYOUT_AddImage,          NewObject
                    (   LABEL_GetClass(),     NULL,
                        // label
                        LABEL_Text,           "Description:",
                        LABEL_Justification,  LJ_RIGHT,
                        TAG_END
                    ),
                    TAG_END
                ),
                TAG_END
            ),
            CHILD_WeightedWidth,          0,
            LAYOUT_AddChild,
            NewObject
            (   LAYOUT_GetClass(),        NULL,
                // layout
                LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
                LAYOUT_SpaceOuter,        TRUE,
                LAYOUT_VertAlignment,     LALIGN_CENTER,
                LAYOUT_HorizAlignment,    LALIGN_LEFT,
                LAYOUT_BevelStyle,        BVS_NONE,
                LAYOUT_AddChild,          manuf_gadgets[GID_5_ST1] =
                NewObject
                (   STRING_GetClass(),    NULL,
                    GA_ReadOnly,          TRUE,
                    GA_ID,                GID_5_ST1,
                    STRINGA_TextVal,      "-",
                    STRINGA_MinVisible,   9,
                    TAG_END
                ),
                LAYOUT_AddChild,          manuf_gadgets[GID_5_ST2] =
                NewObject
                (   STRING_GetClass(),    NULL,
                    GA_ReadOnly,          TRUE,
                    GA_ID,                GID_5_ST2,
                    STRINGA_TextVal,      "-",
                    TAG_END
                ),
                LAYOUT_AddChild,          manuf_gadgets[GID_5_ST3] =
                NewObject
                (   STRING_GetClass(),    NULL,
                    GA_ReadOnly,          TRUE,
                    GA_ID,                GID_5_ST3,
                    STRINGA_TextVal,      "-",
                    TAG_END
                ),
                LAYOUT_AddChild,          manuf_gadgets[GID_5_ST4] =
                NewObject
                (   STRING_GetClass(),    NULL,
                    GA_ReadOnly,          TRUE,
                    GA_ID,                GID_5_ST4,
                    STRINGA_TextVal,      "-",
                    TAG_END
                ),
                TAG_END
            ),
            CHILD_WeightedHeight,     0,
            LAYOUT_AddChild,
            NewObject
            (   LAYOUT_GetClass(),    NULL,
                // layout
                LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
                LAYOUT_SpaceOuter,    TRUE,
                LAYOUT_VertAlignment, LALIGN_CENTER,
                LAYOUT_HorizAlignment,LALIGN_LEFT,
                LAYOUT_BevelStyle,    BVS_NONE,
                LAYOUT_AddImage,          NewObject
                (   LABEL_GetClass(),     NULL,
                    LABEL_Text,           "",
                    TAG_END
                ),
                LAYOUT_AddChild,
                NewObject
                (   LAYOUT_GetClass(),        NULL,
                    LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
                    LAYOUT_SpaceOuter,        TRUE,
                    LAYOUT_HorizAlignment,    LALIGN_RIGHT,
                    LAYOUT_VertAlignment,     LALIGN_BOTTOM,
                    LAYOUT_BevelStyle,        BVS_NONE,
                    LAYOUT_AddChild,
                    NewObject
                    (   LAYOUT_GetClass(),        NULL,
                        LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
                        LAYOUT_SpaceOuter,        TRUE,
                        LAYOUT_HorizAlignment,    LALIGN_RIGHT,
                        LAYOUT_VertAlignment,     LALIGN_CENTER,
                        LAYOUT_BevelStyle,        BVS_NONE,
                        LAYOUT_AddImage,          NewObject
                        (   LABEL_GetClass(),     NULL,
                            // label
                            LABEL_Text,           "_ID:",
                            LABEL_Justification,  LJ_RIGHT,
                            TAG_END
                        ),
                        TAG_END
                    ),
                    LAYOUT_AddChild,          manuf_gadgets[GID_5_IN1] =
                    NewObject
                    (   INTEGER_GetClass(),   NULL,
                        GA_ID,                GID_5_IN1,
                        GA_RelVerify,         TRUE,
                        GA_TabCycle,          TRUE,
                        INTEGER_Number,       querymanuf,
                        INTEGER_Minimum,      0,
                        INTEGER_Maximum,      65535,
                        INTEGER_MinVisible,   5,
                        TAG_END
                    ),                                      
                    TAG_END
                ),
                CHILD_WeightedHeight,         0,
                LAYOUT_AddChild,
                NewObject
                (   LAYOUT_GetClass(),        NULL,
                    LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
                    LAYOUT_SpaceOuter,        TRUE,
                    LAYOUT_HorizAlignment,    LALIGN_RIGHT,
                    LAYOUT_VertAlignment,     LALIGN_BOTTOM,
                    LAYOUT_BevelStyle,        BVS_NONE,
                    LAYOUT_AddChild,
                    NewObject
                    (   LAYOUT_GetClass(),        NULL,
                        LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
                        LAYOUT_SpaceOuter,        TRUE,
                        LAYOUT_HorizAlignment,    LALIGN_RIGHT,
                        LAYOUT_VertAlignment,     LALIGN_CENTER,
                        LAYOUT_BevelStyle,        BVS_NONE,
                        LAYOUT_AddImage,          NewObject
                        (   LABEL_GetClass(),     NULL,
                            // label
                            LABEL_Text,           "I_D:",
                            LABEL_Justification,  LJ_RIGHT,
                            TAG_END
                        ),
                        TAG_END
                    ),
                    LAYOUT_AddChild,          manuf_gadgets[GID_5_IN2] =
                    NewObject
                    (   INTEGER_GetClass(),   NULL,
                        GA_ID,                GID_5_IN2,
                        GA_RelVerify,         TRUE,
                        GA_TabCycle,          TRUE,
                        INTEGER_Number,       queryproduct,
                        INTEGER_Minimum,      0,
                        INTEGER_Maximum,      255,
                        INTEGER_MinVisible,   5,
                        TAG_END
                    ),
                    TAG_END
                ),
                CHILD_WeightedHeight,     0,
                LAYOUT_AddImage,          NewObject
                (   LABEL_GetClass(),     NULL,
                    LABEL_Text,           "",
                    TAG_END
                ),
                TAG_END
            ),
            CHILD_WeightedWidth,          0,
            TAG_END
        ),
        CHILD_WeightedHeight,             0,
        LAYOUT_AddChild,
        NewObject
        (   LAYOUT_GetClass(),        NULL,
            LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
            LAYOUT_SpaceOuter,        TRUE,
            LAYOUT_HorizAlignment,    LALIGN_CENTER,
            LAYOUT_VertAlignment,     LALIGN_CENTER,
            LAYOUT_BevelStyle,        BVS_FIELD,
            LAYOUT_ShrinkWrap,        TRUE,
            LAYOUT_AddImage,          NewObject
            (   LABEL_GetClass(),     NULL,
                // label
                LABEL_Text,           "P_recedence:",
                LABEL_Justification,  LJ_RIGHT,
                TAG_END
            ),
            CHILD_WeightedWidth,      0,
            LAYOUT_AddChild,          manuf_gadgets[GID_5_CH1] =
            NewObject
            (   CHOOSER_GetClass(),   NULL,
                GA_ID,                GID_5_CH1,
                GA_RelVerify,         TRUE, // otherwise we won't hear the gadget
                CHOOSER_PopUp,        TRUE,
                CHOOSER_Labels,       &ManufChooserList,
                CHOOSER_Selected,     (WORD) precedence,
                TAG_END
            ),
            CHILD_WeightedWidth,      0,
            LAYOUT_AddImage,          NewObject
            (   LABEL_GetClass(),     NULL,
                LABEL_Text,           "",
                TAG_END
            ),
            CHILD_WeightedWidth,      100,
            LAYOUT_AddChild,          manuf_gadgets[GID_5_CB1] =
            NewObject
            (   CHECKBOX_GetClass(),      NULL,
                // button
                GA_ID,                    GID_5_CB1,
                GA_RelVerify,             TRUE,
                GA_Disabled,              TRUE,
                GA_Text,                  "Internal?",
                TAG_END
            ),
            CHILD_WeightedWidth,          0,
            LAYOUT_AddChild,              manuf_gadgets[GID_5_CB2] =
            NewObject
            (   CHECKBOX_GetClass(),      NULL,
                // button
                GA_ID,                    GID_5_CB2,
                GA_RelVerify,             TRUE,
                GA_Disabled,              TRUE,
                GA_Text,                  "Official?",
                TAG_END
            ),
            CHILD_WeightedWidth,          0,
            TAG_END
        ),
        CHILD_WeightedHeight,             0,
        LAYOUT_AddChild,                  NewObject
        (   LAYOUT_GetClass(),            NULL,
            // layout
            LAYOUT_Orientation,           LAYOUT_ORIENT_HORIZ,
            LAYOUT_SpaceOuter,            TRUE,
            LAYOUT_VertAlignment,         LALIGN_CENTER,
            LAYOUT_HorizAlignment,        LALIGN_CENTER,
            LAYOUT_BevelStyle,            BVS_FIELD,
            LAYOUT_AddChild,              manuf_gadgets[GID_5_BU2] =
            NewObject
            (   NULL,                     "button.gadget",
                // button
                GA_ID,                    GID_5_BU2,
                GA_RelVerify,             TRUE,
                GA_Text,                  "_Previous Card",
                TAG_END
            ),
            CHILD_WeightedWidth,          50,
            LAYOUT_AddChild,              manuf_gadgets[GID_5_BU3] =
            NewObject
            (   NULL,                     "button.gadget",
                // button
                GA_ID,                    GID_5_BU3,
                GA_RelVerify,             TRUE,
                GA_Text,                  "_Next Card",
                TAG_END
            ),
            CHILD_WeightedWidth,          50,
            TAG_END
        ),
        TAG_END
    ),
    TAG_END
    )))
    {   rq("Can't create ReAction object(s)!");
    }
    unlockscreen();

    /* boards is the actual number of boards found. 0 to (board - 1).
    We actually use the [board] index as our 'spare' 'queryable' index. */

    openwindow();
    ActivateLayoutGadget(manuf_gadgets[GID_5_LY1], MainWindowPtr, NULL, (Object) manuf_gadgets[GID_5_IN1]);
    updatemanuf();
    loop();
    closewindow();
}

AGLOBAL void manuf_loop(ULONG gid)
{   switch(gid)
    {
    case GID_5_BU2:
        whichboard--;
        updatemanuf();
    break;
    case GID_5_BU3:
        whichboard++;
        updatemanuf();
    break;
    case GID_5_CH1:
        if (!(GetAttr
        (   CHOOSER_Selected, manuf_gadgets[GID_5_CH1], (ULONG *) &precedence
        )))
        {   rq("Unsupported inquiry!"); // should never happen
        }
        autoquery();
    break;
    case GID_5_IN1:
        autoquery();
    break;
    case GID_5_IN2:
        autoquery();
    break;
    default:
    break;
}   }

AGLOBAL void manuf_die(void)
{   IOBuffer[20] = (UBYTE) precedence;
}
AGLOBAL void manuf_config(void)
{   precedence = (ULONG) IOBuffer[20];
}

MODULE void checklibrary(ULONG whichmanuf, ULONG whichproduct)
{   foundmanuf = foundproduct = FALSE;

    if (BoardsBase)
    {   if (GetBoardName(manuf_buffer, product_buffer, NULL, whichmanuf, whichproduct))
        {   SetGadgetAttrs
            (   manuf_gadgets[GID_5_ST2], MainWindowPtr, NULL,
                STRINGA_TextVal, manuf_buffer,
                TAG_END
            );
            SetGadgetAttrs
            (   manuf_gadgets[GID_5_ST3], MainWindowPtr, NULL,
                STRINGA_TextVal, product_buffer,
                TAG_END
            );
            SetGadgetAttrs
            (   manuf_gadgets[GID_5_ST4], MainWindowPtr, NULL,
                STRINGA_TextVal, "-",
                TAG_END
            );
            foundmanuf = foundproduct = TRUE;
            return; // successful
    }   }
    return; // unsuccessful
}

MODULE void checkinternal(ULONG whichmanuf, ULONG whichproduct)
{   SWORD i, /* i must be signed and at least 16 bits wide */
          j;

    foundmanuf = foundproduct = FALSE;
    for (i = 0; i <= MANUFS; i++) // go through each manufacturer
    {   for (j = 0; j <= 2; j++)  // each manufacturer has up to 3 IDs
        {   if (whichmanuf == manuf[i].number[j])
            {   selectedmanuf = i;
                foundmanuf = TRUE;
                SetGadgetAttrs
                (   manuf_gadgets[GID_5_ST2], MainWindowPtr, NULL,
                    STRINGA_TextVal, manuf[selectedmanuf].name,
                    TAG_END
                );
                SetGadgetAttrs
                (   manuf_gadgets[GID_5_CB1], MainWindowPtr, NULL,
                    GA_Selected, TRUE,
                    TAG_END
                );
                // official gadget has been already cleared by this point
                if (j < manuf[i].howmany)
                {   SetGadgetAttrs
                    (   manuf_gadgets[GID_5_CB2], MainWindowPtr, NULL,
                        GA_Selected, TRUE,
                        TAG_END
                    );
                }

                selectedproduct = (UWORD) ~0;
                for (i = 0; i <= PRODUCTS; i++)
                {   if (whichmanuf == product[i].manufid)
                    {   for (j = 0; j <= 1; j++)
                        {   if (whichproduct == product[i].number[j])
                            {   selectedproduct = i;
                                // show product details
                                SetGadgetAttrs
                                (   manuf_gadgets[GID_5_ST3], MainWindowPtr, NULL,
                                    STRINGA_TextVal, product[selectedproduct].name,
                                    TAG_END
                                );
                                SetGadgetAttrs
                                (   manuf_gadgets[GID_5_ST4], MainWindowPtr, NULL,
                                    STRINGA_TextVal, product[selectedproduct].desc,
                                    TAG_END
                                );
                                foundproduct = TRUE;
                                return; // found both
                }   }   }   }
                return; // found manuf only
    }   }   }
    return; // completely unsuccessful
}

MODULE void nomanuf(void)
{   SetGadgetAttrs
    (   manuf_gadgets[GID_5_ST2], MainWindowPtr, NULL,
        STRINGA_TextVal, "-",
        TAG_END
    );
}

MODULE void noproduct(void)
{   SetGadgetAttrs
    (   manuf_gadgets[GID_5_ST3], MainWindowPtr, NULL,
        STRINGA_TextVal, "-",
        TAG_END
    );
    SetGadgetAttrs
    (   manuf_gadgets[GID_5_ST4], MainWindowPtr, NULL,
        STRINGA_TextVal, "-",
        TAG_END
    );
}

AGLOBAL ULONG Hook5Func(struct Hook *h, VOID *o, VOID *msg)
{   /* "When the hook is called, the data argument points to the 
    window object and message argument to the IntuiMessage." */

    UWORD code, qual;

    geta4(); // wait till here before doing anything

    code = ((struct IntuiMessage *) msg)->Code;
    qual = ((struct IntuiMessage *) msg)->Qualifier;

    switch(code)
    {
    case SCAN_HELP:
        helpabout();
    break;
    case SCAN_ESCAPE:
        if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
        {   cleanexit(EXIT_SUCCESS);
        } else page = 0;
    break;
    case SCAN_R:
        if (precedence == 0)
        {   precedence = 1;
        } else
        {   // assert(precedence == 1);
            precedence = 0;
        }
        SetGadgetAttrs
        (   manuf_gadgets[GID_5_CH1], MainWindowPtr, NULL,
            CHOOSER_Selected, (WORD) precedence,
            TAG_END
        );
        autoquery();
    break;
    case SCAN_I:
        ActivateLayoutGadget(manuf_gadgets[GID_5_LY1], MainWindowPtr, NULL, (Object) manuf_gadgets[GID_5_IN1]);
    break;
    case SCAN_D:
        ActivateLayoutGadget(manuf_gadgets[GID_5_LY1], MainWindowPtr, NULL, (Object) manuf_gadgets[GID_5_IN2]);
    break;
    default:
    break;
    }

    return(1);
}

MODULE void autoquery(void)
{   if (!(GetAttr
    (   INTEGER_Number, manuf_gadgets[GID_5_IN1], (ULONG *) &querymanuf
    )))
    {   rq("Unsupported inquiry!"); // should never happen
    }
    if (!(GetAttr
    (   INTEGER_Number, manuf_gadgets[GID_5_IN2], (ULONG *) &queryproduct
    )))
    {   rq("Unsupported inquiry!"); // should never happen
    }
    runquery(querymanuf, queryproduct);
}

