1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2005,2008 Oracle.  All rights reserved.
5 *
6 * $Id: csv.h,v 1.20 2008/01/08 20:58:23 bostic Exp $
7 */
8
9#include <sys/types.h>
10#include <sys/stat.h>
11
12#include <ctype.h>
13#include <errno.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17
18#ifdef _WIN32
19#define	WIN32_LEAN_AND_MEAN	1
20
21#include <direct.h>
22#include <db.h>
23
24extern int getopt(int, char * const *, const char *);
25extern char *optarg;
26extern int optind;
27#else
28#define	HAVE_WILDCARD_SUPPORT	1
29
30#include <regex.h>
31#include <unistd.h>
32#endif
33
34#include "db.h"
35
36/*
37 * MAP_VERSION
38 * This code has hooks for versioning, but does not directly support it.
39 * See the README file for details.
40 */
41#define	MAP_VERSION	1
42
43/*
44 * Supported formats.
45 *
46 * FORMAT_NL:		<nl> separated
47 * FORMAT_EXCEL:	Excel dumped flat text.
48 */
49typedef enum { FORMAT_EXCEL, FORMAT_NL } input_fmt;
50
51/*
52 * OFFSET_LEN
53 *	The length of any item can be calculated from the two offset fields.
54 * OFFSET_OOB
55 *	An offset that's illegal, used to detect unavailable fields.
56 */
57#define	OFFSET_LEN(offset, indx)					\
58	(((offset)[(indx) + 1] - (offset)[(indx)]) - 1)
59
60#define	OFFSET_OOB	0
61
62/*
63 * Field comparison operators.
64 */
65typedef enum { EQ=1, NEQ, GT, GTEQ, LT, LTEQ, WC, NWC } OPERATOR;
66
67/*
68 * Supported data types.
69 */
70typedef enum { NOTSET=1, DOUBLE, STRING, UNSIGNED_LONG } datatype;
71
72/*
73 * C structure that describes the csv fields.
74 */
75typedef struct {
76	char	 *name;				/* Field name */
77	u_int32_t fieldno;			/* Field index */
78	datatype  type;				/* Data type */
79
80	int	  indx;				/* Indexed */
81	DB	 *secondary;			/* Secondary index handle */
82
83#define	FIELD_OFFSET(field)	((size_t)(&(((DbRecord *)0)->field)))
84	size_t	  offset;			/* DbRecord field offset */
85} DbField;
86
87/*
88 * Globals
89 */
90extern DB	 *db;				/* Primary database */
91extern DbField	  fieldlist[];			/* Field list */
92extern DB_ENV	 *dbenv;			/* Database environment */
93extern char	 *progname;			/* Program name */
94extern int	  verbose;			/* Program verbosity */
95#ifdef _WIN32
96#undef strcasecmp
97#define	strcasecmp _stricmp
98#undef strncasecmp
99#define	strncasecmp _strnicmp
100#define	mkdir(d, perm) _mkdir(d)
101#endif
102