From 4fae1f4d2d72cab22841258a92474e769f32d6f8 Mon Sep 17 00:00:00 2001 From: mbm Date: Mon, 20 Nov 2006 19:30:50 +0000 Subject: [PATCH] strtok helper function git-svn-id: svn://svn.openwrt.org/openwrt/trunk@5592 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/etc/functions.sh | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/package/base-files/default/etc/functions.sh b/package/base-files/default/etc/functions.sh index f7cb878bc..aa5b00064 100755 --- a/package/base-files/default/etc/functions.sh +++ b/package/base-files/default/etc/functions.sh @@ -118,3 +118,27 @@ find_mtd_part() { echo "${PART:+/dev/mtdblock/$PART}" } +strtok() { # [] ... + 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 +} -- 2.20.1