cmdla.h
3.84 KB
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
/*
* cmdla.h: Prototypes, defines, etc. for cmdla
*
* Copyright (C) 2006 Georg Steffers. All rights reserved.
*
* This software is licensed under the terms of the GNU Genral Public
* License (GPL). Please see gpl.txt for details or refer to
* http://www.gnu.org/licenses/gpl.html
*
* Author: Georg Steffers <georg@steffers.org>
*
* 01/14/2006: Georg Steffers - First implemented
* 01/15/2006: Georg Steffers - V0.1 ready. Modified this and that
* now long arguments are supported as
* well as arguments with am optional
* parameter.
* 01/23/2006: Georg Steffers - add support for gettext.
*/
#ifndef CMDLA_H
#define CMDLA_H
/* Datatypes of given commandline values */
#define CMDLA_TYPE_STRING 0x00
#define CMDLA_TYPE_INT 0x01
#define CMDLA_TYPE_FLOAT 0x02
/* Indicates wether an arg requires an parameter or not */
#define CMDLA_REQ_ARG 0x01
#define CMDLA_OPT_ARG 0x02
#define CMDLAP_CBT_END { 0, NULL, 0, NULL, 0, NULL, NULL }
#define CMDLAS_CBT_END { 0, NULL, NULL, NULL, NULL }
#define _GNU_SOURCE /* for getopt */
#include <unistd.h>
#include <wchar.h>
#include <getopt.h>
#include <scot_common.h>
/*
* This struct holds all neccesary infomation for the default
* usage callback. It is filled within process_cmd_line and used
* with any usage function that did not specify explicitly different
* behaviour.
*/
struct du_infot
{
const struct cmdlas_cbt *switches;
const struct cmdlap_cbt *arguments;
const char *about;
const char *copyright;
const char *usage_aa;
const char *program_name;
};
typedef int (*cmdlap_cb) (const char *, const int, void *);
typedef int (*cmdlas_cb) (void *);
/*
* CoMmanDLine Argument Parameter CallBack Type.
* This holds the definition of an argument that takes a parameter.
*/
struct cmdlap_cbt {
char carg; /* The single letter argument e.g. -a */
char *sarg; /* The string argument e.g. --arg */
int cmdla_argt; /* Datatype the arg take e.g. CMDLA_TYPE_INT */
cmdlap_cb cb; /* pointer to the callback funtion */
int cmdla_type; /* requires parameter? e.g. CMDLA_REQ_ARG */
void *var; /* this will be given to the callback */
const char *info; /* a short description for the help */
};
/*
* CoMmanDLine Argument Switch CallBack Type.
* This holds the definition of an argument that is a switch.
*/
struct cmdlas_cbt {
char carg; /* The single letter argument e.g. -a */
char *sarg; /* The string argument e.g. --arg */
cmdlas_cb cb; /* pointer to the callback funtion */
void *var; /* this will be given to the callback */
const char *info; /* a short description for the help */
};
/*
* The defaul usage method....this was previously static within
* cmdla but i realised that it is useful to make it callable
* within the calling code to do special usage in special cases
* and call this if no special case occured.
*/
int default_usage_cb (void *);
/*
* a default callback for struct cmdlap_cbt. It simply parses its first
* argument into its last according to the type specified by its sec. arg.
*/
int get_cmdlap_cb (const char *, const int, void *);
/*
* this does all the work.
* Arguments are: (argc, argv, a program description, a copyright string,
* additional text for the usage information,
* a list of arguments with parameter, a list of switches).
*/
int process_cmd_line (
int, char *[], const char*, const char*, const char*,
const struct cmdlap_cbt *, const struct cmdlas_cbt *);
int switch_cb (void *);
int inc_cb (void *);
#endif /* CMDLA_H */