]>
Commit | Line | Data |
---|---|---|
e726ef8d MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2012 IPFire Network Development Team # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | # | |
22 | # Functions for nice handling of lists. | |
23 | # | |
24 | ||
25 | function list_append() { | |
26 | local list=${1} | |
27 | shift | |
28 | ||
29 | assert isset list | |
30 | ||
7aa696d1 MT |
31 | if [ -n "${!list}" ]; then |
32 | printf -v ${list} "${!list} $@" | |
33 | else | |
34 | printf -v ${list} "$@" | |
35 | fi | |
e726ef8d MT |
36 | } |
37 | ||
38 | function list_remove() { | |
39 | local list=${1} | |
40 | shift | |
41 | ||
42 | assert isset list | |
43 | ||
44 | local _list k | |
45 | for k in ${!list}; do | |
46 | listmatch ${k} $@ && continue | |
47 | ||
48 | _list="${_list} ${k}" | |
49 | done | |
50 | ||
51 | eval "${list}=\"${_list}\"" | |
52 | } | |
53 | ||
54 | function list_sort() { | |
55 | local i | |
56 | for i in $@; do | |
57 | print "${i}" | |
58 | done | sort | tr '\n' ' ' | |
59 | ||
60 | } | |
61 | ||
62 | function list_match() { | |
63 | local match=${1} | |
64 | shift | |
65 | ||
66 | local i | |
67 | for i in $@; do | |
68 | [ "${match}" = "${i}" ] && return ${EXIT_OK} | |
69 | done | |
70 | ||
71 | return ${EXIT_ERROR} | |
72 | } | |
73 | ||
74 | function list_length() { | |
75 | local length=0 | |
76 | ||
77 | local i | |
78 | for i in $@; do | |
79 | length=$(( ${length} + 1 )) | |
80 | done | |
81 | ||
82 | print "${length}" | |
83 | } |