+#if defined (ARITH_FOR_COMMAND)
+static WORD_LIST *
+make_arith_for_expr (s)
+ char *s;
+{
+ WORD_LIST *result;
+ WORD_DESC *wd;
+
+ if (s == 0 || *s == '\0')
+ return ((WORD_LIST *)NULL);
+ wd = make_word (s);
+ wd->flags |= W_NOGLOB|W_NOSPLIT|W_QUOTED|W_DQUOTE; /* no word splitting or globbing */
+#if defined (PROCESS_SUBSTITUTION)
+ wd->flags |= W_NOPROCSUB; /* no process substitution */
+#endif
+ result = make_word_list (wd, (WORD_LIST *)NULL);
+ return result;
+}
+#endif
+
+/* Note that this function calls dispose_words on EXPRS, since it doesn't
+ use the word list directly. We free it here rather than at the caller
+ because no other function in this file requires that the caller free
+ any arguments. */
+COMMAND *
+make_arith_for_command (exprs, action, lineno)
+ WORD_LIST *exprs;
+ COMMAND *action;
+ int lineno;
+{
+#if defined (ARITH_FOR_COMMAND)
+ ARITH_FOR_COM *temp;
+ WORD_LIST *init, *test, *step;
+ char *s, *t, *start;
+ int nsemi, i;
+
+ init = test = step = (WORD_LIST *)NULL;
+ /* Parse the string into the three component sub-expressions. */
+ start = t = s = exprs->word->word;
+ for (nsemi = 0; ;)
+ {
+ /* skip whitespace at the start of each sub-expression. */
+ while (whitespace (*s))
+ s++;
+ start = s;
+ /* skip to the semicolon or EOS */
+ i = skip_to_delim (start, 0, ";", SD_NOJMP|SD_NOPROCSUB);
+ s = start + i;
+
+ t = (i > 0) ? substring (start, 0, i) : (char *)NULL;
+
+ nsemi++;
+ switch (nsemi)
+ {
+ case 1:
+ init = make_arith_for_expr (t);
+ break;
+ case 2:
+ test = make_arith_for_expr (t);
+ break;
+ case 3:
+ step = make_arith_for_expr (t);
+ break;
+ }
+
+ FREE (t);
+ if (*s == '\0')
+ break;
+ s++; /* skip over semicolon */
+ }
+
+ if (nsemi != 3)
+ {
+ if (nsemi < 3)
+ parser_error (lineno, _("syntax error: arithmetic expression required"));
+ else
+ parser_error (lineno, _("syntax error: `;' unexpected"));
+ parser_error (lineno, _("syntax error: `((%s))'"), exprs->word->word);
+ free (init);
+ free (test);
+ free (step);
+ last_command_exit_value = 2;
+ return ((COMMAND *)NULL);
+ }
+
+ temp = (ARITH_FOR_COM *)xmalloc (sizeof (ARITH_FOR_COM));
+ temp->flags = 0;
+ temp->line = lineno;
+ temp->init = init ? init : make_arith_for_expr ("1");
+ temp->test = test ? test : make_arith_for_expr ("1");
+ temp->step = step ? step : make_arith_for_expr ("1");
+ temp->action = action;
+
+ dispose_words (exprs);
+ return (make_command (cm_arith_for, (SIMPLE_COM *)temp));
+#else
+ dispose_words (exprs);
+ last_command_exit_value = 2;
+ return ((COMMAND *)NULL);
+#endif /* ARITH_FOR_COMMAND */
+}
+