File: sh_head

package info (click to toggle)
fungw 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,268 kB
  • sloc: ansic: 24,257; makefile: 500; sh: 32; awk: 9; perl: 8; tcl: 7; javascript: 7; ruby: 7; python: 6
file content (71 lines) | stat: -rw-r--r-- 868 bytes parent folder | download | duplicates (3)
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
### header pasted by fungw
fgw_ok()
{
	echo "ok" >&4
}

fgw_func_reg()
{
	local res
	echo "fgw_func_reg $1" >&4
	read res <&3
	if test "$res" = "fr_ok"
	then
		return 0
	else
		return 1
	fi
}

fgw()
{
	local fn cmd arg

	echo "call_begin $#" >&4
	fn="$1"
	shift 1
	while test $# -gt 0
	do
#TODO: quote
		echo "call_arg $1" >&4
		shift 1
	done
	echo "call_end $fn" >&4

	# read the result
	read cmd arg <&3
	if test "$cmd" = "retok"
	then
		echo "$arg"
		return 0
	else
		echo ""
		return 1
	fi
}


fgw_main_loop()
{
	local cmd arg call
	fgw_ok
	while read cmd arg <&3
	do
		case "$cmd" in
			call_begin) call="" ;;
			call_arg) call="$call \"$arg\"" ;;
			call_end)
				call="$arg$call"
				fgw_retval=""
				echo "call=$call"
				eval "$call"
				if test $? = 0
				then
					echo "retok $fgw_retval" >&4
				else
					echo "retfail" >&4
				fi
				;;
		esac
	done
}