summaryrefslogtreecommitdiffstats
path: root/tools/tools.h
blob: 767100d7bb25ca3b2c94583ac05e739759835363 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * Copyright (C) 2001  Sistina Software
 *
 * LVM is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * LVM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU CC; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef _LVM_LVM_H
#define _LVM_LVM_H

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>

#include "pool.h"
#include "dbg_malloc.h"
#include "list.h"
#include "log.h"
#include "metadata.h"
#include "config.h"
#include "dev-cache.h"
#include "device.h"
#include "display.h"
#include "errors.h"
#include "filter.h"
#include "filter-persistent.h"
#include "filter-composite.h"
#include "filter-regex.h"
#include "format1.h"
#include "toollib.h"
#include "activate.h"

#define CMD_LEN 256
#define MAX_ARGS 64

/* command functions */
typedef int (*command_fn)(int argc, char **argv);

#define xx(a, b...) int a(int argc, char **argv);
#include "commands.h"
#undef xx

/* define the enums for the command line switches */
enum {
#define xx(a, b, c, d) a ,
#include "args.h"
#undef xx
};

/* a global table of possible arguments */
struct arg {
	char short_arg;
	char *long_arg;
	int (*fn)(struct arg *a);
	int count;
	char *value;
	int i_value;
};

extern struct arg the_args[ARG_COUNT + 1];

void usage(const char *name);

/* the argument verify/normalise functions */
int yes_no_arg(struct arg *a);
int size_arg(struct arg *a);
int int_arg(struct arg *a);
int string_arg(struct arg *a);
int permission_arg(struct arg *a);

char yes_no_prompt(const char *prompt, ...);

/* we use the enums to access the switches */
static inline int arg_count(int a) {
	return the_args[a].count;
}

static inline char *arg_value(int a) {
	return the_args[a].value;
}

static inline char *arg_str_value(int a, char *def)
{
	return arg_count(a) ? the_args[a].value : def;
}

static inline int arg_int_value(int a, int def)
{
	return arg_count(a) ? the_args[a].i_value : def;
}

static inline int arg_count_increment(int a)
{
	return the_args[a].count++;
}

struct config_file *active_config_file(void);
struct dev_filter *active_filter(void);

extern struct io_space *ios;

#endif