1dnl $Id: m4.ret,v 10.133 2004/08/13 03:38:58 bostic Exp $
2dnl
3dnl ###################################################################
4dnl RETURN VALUES:
5dnl m4_return:
6dnl	#1: API name
7dnl	#2: Variadic list of return conditions
8dnl ###################################################################
9define(m4_return, [dnl
10define([__m4_retapi], [$1])
11m4_p([__m4_retloop(shift($@))])])
12dnl ###################################################################
13dnl __m4_common_ret_txt
14dnl     Standard return text.
15dnl ###################################################################
16define(__m4_common_ret_txt, [dnl
17m4_refT(__m4_retapi)
18ifelse(M4EXCEPT, except_return, [either returns a non-zero error value
19or throws an exception that encapsulates a non-zero error value on
20failure, and returns 0 on success.],
21M4EXCEPT, except_only, [throws an exception that encapsulates a non-zero
22error value on failure.],[returns a non-zero error value on failure
23and 0 on success.])])
24dnl ###################################################################
25dnl __m4_retloop
26dnl     Helper macro: loop through return list.
27dnl ###################################################################
28define(__m4_retloop, [ifelse([$1],,,
29dnl ###################################################################
30dnl "std"
31dnl     Returning 0 or errno.
32dnl ###################################################################
33[$1], std, [The __m4_common_ret_txt
34__m4_retloop(shift($@))],
35dnl ###################################################################
36dnl "prev"
37dnl     Otherwise, returning 0 or errno.
38dnl ###################################################################
39[$1], prev, [Unless otherwise specified, the __m4_common_ret_txt
40__m4_retloop(shift($@))],
41dnl ###################################################################
42dnl "except"
43dnl     Specific return that may be an exception.
44dnl	#2: the condition
45dnl	#3: the return value.
46dnl ###################################################################
47[$1], except, [dnl
48The m4_refT(__m4_retapi)
49ifelse(M4EXCEPT, except_return, [will either return m4_ref($2) or
50throw an exception that encapsulates m4_ref($2)],
51M4EXCEPT, except_only,
52[will throw an exception that encapsulates m4_ref($2)],
53[will return m4_ref($2)]) $3.
54__m4_retloop(shift(shift(shift($@))))],
55dnl ###################################################################
56dnl "specific"
57dnl     Specific return that is never an exception
58dnl	#2: the condition
59dnl	#3: the return value.
60dnl ###################################################################
61[$1], specific, [dnl
62The m4_refT(__m4_retapi) will return m4_ref($2) $3.
63__m4_retloop(shift(shift(shift($@))))],
64dnl ###################################################################
65dnl Everything else.
66dnl ###################################################################
67[$1
68__m4_retloop(shift($@))])])
69