Newer
Older
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
/*
** opt_shopt.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** Started on Tue Mar 21 19:00:38 2006 Seblu
** Last update Sun Jul 30 03:41:36 2006 Seblu
*/
#include <string.h>
#include "../shell/shell.h"
#include "opt.h"
static const char *opts_table[NBR_OPT] =
{
"xpg_echo",
"dotglob",
"extglob",
"nocaseglob",
"nullglob",
"expand_aliases",
};
/*!
** Set a shell option
**
** @param name name of the option to set
** @param shopt structure to apply
**
** @return 0 on failure, else 1
*/
int opt_set(const char *name, ts_opt *shopt)
{
register int i;
for (i = 0; opts_table[i]; ++i)
if (!strcmp(name, opts_table[i]))
{
shopt->item[i] = 1;
return 1;
}
return 0;
}
/*!
** Unset a shell option
**
** @param name name of the option to unset
** @param shopt structure to apply
**
** @return 0 on failure, else 1
*/
int opt_unset(const char *name, ts_opt *shopt)
{
register int i;
for (i = 0; opts_table[i]; ++i)
if (!strcmp(name, opts_table[i]))
{
shopt->item[i] = 0;
return 1;
}
return 0;
}
/*!
** Tell if an option is set. if option nane is not set return -1
**
** @param name name to find
** @param shopt structure where find
**
** @return 0 if unset, 1 if set and -1 if not exist
*/
int opt_isset(const char *name, const ts_opt *shopt)
{
register int i;
for (i = 0; opts_table[i]; ++i)
if (!strcmp(name, opts_table[i]))
return shopt->item[i];
return -1;
}
/*!
** Return a list of know opt
**
** @return list of opt
*/
const char **opt_get()
{
return opts_table;
}