strtok helper function
[openwrt-10.03/.git] / package / base-files / default / etc / functions.sh
index 9c3057ed00f1e0d8adee9edf57dd4b7394fc2187..aa5b000644d8d0fcd5426116e8f3a46e5c0d6b1a 100755 (executable)
@@ -10,13 +10,6 @@ N="
 
 _C=0
 
-# valid interface?
-if_valid () (
-  ifconfig "$1" >&- 2>&- ||
-  [ "${1%%[0-9]}" = "br" ] ||
-  { debug "# missing interface '$1' ignored"; false; }
-)
-
 hotplug_dev() {
        env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net
 }
@@ -84,6 +77,7 @@ config_clear() {
 }
 
 config_load() {
+       CONFIG_SECTION=
        local DIR="./"
        _C=0
        [ \! -e "$1" -a -e "/etc/config/$1" ] && {
@@ -117,3 +111,34 @@ include() {
                . $file
        done
 }
+
+find_mtd_part() {
+       local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
+       PART="${PART##mtd}"
+       echo "${PART:+/dev/mtdblock/$PART}"
+}
+
+strtok() { # <string> <variable> [<separator>] ...
+       local right
+       local left="$1"
+       local count=0
+
+       shift
+
+       while [ $# -gt 1 ]; do
+               right="${left%%$2*}"
+
+               [ "$right" = "$left" ] && break
+
+               left="${left#$right$2}"
+
+               export $1="$right"; count=$((count+1))
+               shift 2
+       done
+
+       if [ $# -gt 0 -a "$left" ]; then
+               export $1="$left"; count=$((count+1))
+       fi
+
+       return $count
+}