1 This file is break.def, from which is created break.c.
2 It implements the builtins "break" and "continue" in Bash.
4 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING. If not, write to the Free Software
20 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
25 $FUNCTION break_builtin
27 Exit from within a FOR, WHILE or UNTIL loop. If N is specified,
32 #if defined (HAVE_UNISTD_H)
34 # include <sys/types.h>
42 extern char *this_command_name;
43 extern int posixly_correct;
45 static int check_loop_level ();
47 /* The depth of while's and until's. */
50 /* Non-zero when a "break" instruction is encountered. */
53 /* Non-zero when we have encountered a continue instruction. */
56 /* Set up to break x levels, where x defaults to 1, but can be specified
57 as the first argument. */
64 if (check_loop_level () == 0)
65 return (EXECUTION_SUCCESS);
67 newbreak = get_numeric_arg (list, 1);
71 builtin_error ("loop count must be > 0");
72 breaking = loop_level;
73 return (EXECUTION_FAILURE);
76 if (newbreak > loop_level)
77 newbreak = loop_level;
81 return (EXECUTION_SUCCESS);
85 $FUNCTION continue_builtin
86 $SHORT_DOC continue [n]
87 Resume the next iteration of the enclosing FOR, WHILE or UNTIL loop.
88 If N is specified, resume at the N-th enclosing loop.
91 /* Set up to continue x levels, where x defaults to 1, but can be specified
92 as the first argument. */
94 continue_builtin (list)
99 if (check_loop_level () == 0)
100 return (EXECUTION_SUCCESS);
102 newcont = get_numeric_arg (list, 1);
106 builtin_error ("loop count must be > 0");
107 breaking = loop_level;
108 return (EXECUTION_FAILURE);
111 if (newcont > loop_level)
112 newcont = loop_level;
114 continuing = newcont;
116 return (EXECUTION_SUCCESS);
119 /* Return non-zero if a break or continue command would be okay.
120 Print an error message if break or continue is meaningless here. */
124 #if defined (BREAK_COMPLAINS)
125 if (loop_level == 0 && posixly_correct == 0)
126 builtin_error ("only meaningful in a `for', `while', or `until' loop");
127 #endif /* BREAK_COMPLAINS */