1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2004,2008 Oracle.  All rights reserved.
5 */
6
7#include <db.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11
12#ifdef _WIN32
13extern int getopt(int, char * const *, const char *);
14extern char *optarg;
15#define snprintf _snprintf
16#else
17#include <unistd.h>
18#endif
19
20#define DEFAULT_HOMEDIR	"./"
21#define INVENTORY_FILE	"inventory.txt"
22#define VENDORS_FILE	"vendors.txt"
23#define INVENTORYDB	"inventoryDB.db"
24#define ITEMNAMEDB	"itemnameDB.db"
25#define MAXDATABUF	1024
26#define MAXFIELD	20
27#define MAXLINE		150
28#define PRIMARY_DB	0
29#define SECONDARY_DB	1
30#define VENDORDB	"vendorDB.db"
31
32typedef struct stock_dbs {
33    DB *inventory_dbp; /* Database containing inventory information */
34    DB *vendor_dbp;    /* Database containing vendor information */
35    DB *itemname_sdbp; /* Index based on the item name index */
36
37    char *db_home_dir;             /* Directory containing the database files */
38    char *itemname_db_name;  /* Itemname secondary database */
39    char *inventory_db_name; /* Name of the inventory database */
40    char *vendor_db_name;    /* Name of the vendor database */
41} STOCK_DBS;
42
43typedef struct vendor {
44    char name[MAXFIELD];             /* Vendor name */
45    char street[MAXFIELD];           /* Street name and number */
46    char city[MAXFIELD];             /* City */
47    char state[3];                   /* Two-digit US state code */
48    char zipcode[6];                 /* US zipcode */
49    char phone_number[13];           /* Vendor phone number */
50    char sales_rep[MAXFIELD];        /* Name of sales representative */
51    char sales_rep_phone[MAXFIELD];  /* Sales rep's phone number */
52} VENDOR;
53
54/* Function prototypes */
55int	databases_close(STOCK_DBS *);
56int	databases_setup(STOCK_DBS *, const char *, FILE *);
57void	initialize_stockdbs(STOCK_DBS *);
58int	open_database(DB **, const char *, const char *, FILE *, int);
59void	set_db_filenames(STOCK_DBS *my_stock);
60