dc53eba8b0d911bbc1c3e36ca13e1ab9bf16a7ca
[pspp-builds.git] / src / command.c
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 #include <config.h>
21 #include "error.h"
22 #include "command.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <ctype.h>
26 #include <errno.h>
27 #include "alloc.h"
28 #include "dictionary.h"
29 #include "error.h"
30 #include "glob.h"
31 #include "getline.h"
32 #include "lexer.h"
33 #include "main.h"
34 #include "settings.h"
35 #include "som.h"
36 #include "str.h"
37 #include "tab.h"
38 #include "var.h"
39 #include "vfm.h"
40
41 #if HAVE_UNISTD_H
42 #include <unistd.h>
43 #endif
44
45 #if HAVE_SYS_WAIT_H
46 #include <sys/wait.h>
47 #endif
48 \f
49 /* Global variables. */
50
51 /* A STATE_* constant giving the current program state. */
52 int pgm_state;
53
54 /* The name of the procedure currently executing, if any. */
55 const char *cur_proc;
56 \f
57 /* Static variables. */
58
59 /* A single command. */
60 struct command
61   {
62     const char *name;           /* Command name. */
63     int transition[4];          /* Transitions to make from each state. */
64     int (*func) (void);         /* Function to call. */
65     int skip_entire_name;       /* If zero, we don't skip the
66                                    final token in the command name. */
67     short debug;                /* Set if this cmd available only in test mode*/
68   };
69
70 /* Define the command array. */
71 #define DEFCMD(NAME, T1, T2, T3, T4, FUNC)              \
72         {NAME, {T1, T2, T3, T4}, FUNC, 1, 0},
73 #define DBGCMD(NAME, T1, T2, T3, T4, FUNC)              \
74         {NAME, {T1, T2, T3, T4}, FUNC, 1, 1},
75 #define SPCCMD(NAME, T1, T2, T3, T4, FUNC)              \
76         {NAME, {T1, T2, T3, T4}, FUNC, 0, 0},
77 #define UNIMPL(NAME, T1, T2, T3, T4)                    \
78         {NAME, {T1, T2, T3, T4}, NULL, 1, 0},
79 static const struct command commands[] = 
80   {
81 #include "command.def"
82   };
83 #undef DEFCMD
84 #undef DBGCMD
85 #undef UNIMPL
86
87
88 /* Complete the line using the name of a command, 
89  * based upon the current prg_state
90  */
91 char * 
92 pspp_completion_function (const char *text,   int state)
93 {
94   static int skip=0;
95   const struct command *cmd = 0;
96   
97   for(;;)
98     {
99       if ( state + skip >= sizeof(commands)/ sizeof(struct command))
100         {
101           skip = 0;
102           return 0;
103         }
104
105       cmd = &commands[state + skip];
106   
107       if ( cmd->transition[pgm_state] == STATE_ERROR || ( cmd->debug  &&  ! test_mode ) ) 
108         {
109           skip++; 
110           continue;
111         }
112       
113       if ( text == 0 || 0 == strncasecmp (cmd->name, text, strlen(text)))
114         {
115           break;
116         }
117
118       skip++;
119     }
120   
121
122   return xstrdup(cmd->name);
123
124 }
125
126
127
128 #define COMMAND_CNT (sizeof commands / sizeof *commands)
129 \f
130 /* Command parser. */
131
132 static const struct command *parse_command_name (void);
133
134 /* Determines whether command C is appropriate to call in this
135    part of a FILE TYPE structure. */
136 static int
137 FILE_TYPE_okay (const struct command *c)
138 {
139   int okay = 0;
140   
141   if (c->func != cmd_record_type
142       && c->func != cmd_data_list
143       && c->func != cmd_repeating_data
144       && c->func != cmd_end_file_type)
145     msg (SE, _("%s not allowed inside FILE TYPE/END FILE TYPE."), c->name);
146 #if 0
147   /* FIXME */
148   else if (c->func == cmd_repeating_data && fty.type == FTY_GROUPED)
149     msg (SE, _("%s not allowed inside FILE TYPE GROUPED/END FILE TYPE."),
150          c->name);
151   else if (!fty.had_rec_type && c->func != cmd_record_type)
152     msg (SE, _("RECORD TYPE must be the first command inside a "
153                       "FILE TYPE structure."));
154 #endif
155   else
156     okay = 1;
157
158 #if 0
159   if (c->func == cmd_record_type)
160     fty.had_rec_type = 1;
161 #endif
162
163   return okay;
164 }
165
166 /* Parses an entire PSPP command.  This includes everything from the
167    command name to the terminating dot.  Does most of its work by
168    passing it off to the respective command dispatchers.  Only called
169    by parse() in main.c. */
170 int
171 cmd_parse (void)
172 {
173   const struct command *cp;     /* Iterator used to find the proper command. */
174
175 #if C_ALLOCA
176   /* The generic alloca package performs garbage collection when it is
177      called with an argument of zero. */
178   alloca (0);
179 #endif /* C_ALLOCA */
180
181   /* Null commands can result from extra empty lines. */
182   if (token == '.')
183     return CMD_SUCCESS;
184
185   /* Parse comments. */
186   if ((token == T_ID && !strcmp (tokid, "COMMENT"))
187       || token == T_EXP || token == '*' || token == '[')
188     {
189       lex_skip_comment ();
190       return CMD_SUCCESS;
191     }
192
193   /* Otherwise the line must begin with a command name, which is
194      always an ID token. */
195   if (token != T_ID)
196     {
197       lex_error (_("expecting command name"));
198       return CMD_FAILURE;
199     }
200
201   /* Parse the command name. */
202   cp = parse_command_name ();
203   if (cp == NULL)
204     return CMD_FAILURE;
205   if (cp->func == NULL)
206     {
207       msg (SE, _("%s is not yet implemented."), cp->name);
208       while (token && token != '.')
209         lex_get ();
210       return CMD_SUCCESS;
211     }
212
213   /* If we're in a FILE TYPE structure, only certain commands can be
214      allowed. */
215   if (pgm_state == STATE_INPUT
216       && case_source_is_class (vfm_source, &file_type_source_class)
217       && !FILE_TYPE_okay (cp))
218     return CMD_FAILURE;
219
220   /* Certain state transitions are not allowed.  Check for these. */
221   assert (pgm_state >= 0 && pgm_state < STATE_ERROR);
222   if (cp->transition[pgm_state] == STATE_ERROR)
223     {
224       static const char *state_name[4] =
225       {
226         N_("%s is not allowed (1) before a command to specify the "
227            "input program, such as DATA LIST, (2) between FILE TYPE "
228            "and END FILE TYPE, (3) between INPUT PROGRAM and END "
229            "INPUT PROGRAM."),
230         N_("%s is not allowed within an input program."),
231         N_("%s is only allowed within an input program."),
232         N_("%s is only allowed within an input program."),
233       };
234
235       msg (SE, gettext (state_name[pgm_state]), cp->name);
236       return CMD_FAILURE;
237     }
238
239   /* The structured output manager numbers all its tables.  Increment
240      the major table number for each separate procedure. */
241   som_new_series ();
242   
243   {
244     int result;
245     
246     /* Call the command dispatcher.  Save and restore the name of
247        the current command around this call. */
248     {
249       const char *prev_proc;
250       
251       prev_proc = cur_proc;
252       cur_proc = cp->name;
253       result = cp->func ();
254       cur_proc = prev_proc;
255     }
256     
257     /* Perform the state transition if the command completed
258        successfully (at least in part). */
259     if (result != CMD_FAILURE)
260       {
261         pgm_state = cp->transition[pgm_state];
262
263         if (pgm_state == STATE_ERROR)
264           {
265             discard_variables ();
266             pgm_state = STATE_INIT;
267           }
268       }
269
270     /* Pass the command's success value up to the caller. */
271     return result;
272   }
273 }
274
275 static size_t
276 match_strings (const char *a, size_t a_len,
277                const char *b, size_t b_len) 
278 {
279   size_t match_len = 0;
280   
281   while (a_len > 0 && b_len > 0) 
282     {
283       /* Mismatch always returns zero. */
284       if (*a++ != *b++)
285         return 0;
286
287       /* Advance. */
288       a_len--;
289       b_len--;
290       match_len++;
291     }
292
293   return match_len;
294 }
295
296 /* Returns the first character in the first word in STRING,
297    storing the word's length in *WORD_LEN.  If no words remain,
298    returns a null pointer and stores 0 in *WORD_LEN.  Words are
299    sequences of alphanumeric characters or single
300    non-alphanumeric characters.  Words are delimited by
301    spaces. */
302 static const char *
303 find_word (const char *string, size_t *word_len) 
304 {
305   /* Skip whitespace and asterisks. */
306   while (isspace (*string))
307     string++;
308
309   /* End of string? */
310   if (*string == '\0') 
311     {
312       *word_len = 0;
313       return NULL;
314     }
315
316   /* Special one-character word? */
317   if (!isalnum ((unsigned char) *string)) 
318     {
319       *word_len = 1;
320       return string;
321     }
322
323   /* Alphanumeric word. */
324   *word_len = 1;
325   while (isalnum ((unsigned char) string[*word_len]))
326     (*word_len)++;
327
328   return string;
329 }
330
331 /* Returns nonzero if strings A and B can be confused based on
332    their first three letters. */
333 static int
334 conflicting_3char_prefixes (const char *a, const char *b) 
335 {
336   size_t aw_len, bw_len;
337   const char *aw, *bw;
338
339   aw = find_word (a, &aw_len);
340   bw = find_word (b, &bw_len);
341   assert (aw != NULL && bw != NULL);
342
343   /* Words that are the same don't conflict. */
344   if (aw_len == bw_len && !memcmp (aw, bw, aw_len))
345     return 0;
346   
347   /* Words that are otherwise the same in the first three letters
348      do conflict. */
349   return ((aw_len > 3 && bw_len > 3)
350           || (aw_len == 3 && bw_len > 3)
351           || (bw_len == 3 && aw_len > 3)) && !memcmp (aw, bw, 3);
352 }
353
354 /* Returns nonzero if CMD can be confused with another command
355    based on the first three letters of its first word. */
356 static int
357 conflicting_3char_prefix_command (const struct command *cmd) 
358 {
359   assert (cmd >= commands && cmd < commands + COMMAND_CNT);
360
361   return ((cmd > commands
362            && conflicting_3char_prefixes (cmd[-1].name, cmd[0].name))
363           || (cmd < commands + COMMAND_CNT
364               && conflicting_3char_prefixes (cmd[0].name, cmd[1].name)));
365 }
366
367 /* Ways that a set of words can match a command name. */
368 enum command_match
369   {
370     MISMATCH,           /* Not a match. */
371     PARTIAL_MATCH,      /* The words begin the command name. */
372     COMPLETE_MATCH      /* The words are the command name. */
373   };
374
375 /* Figures out how well the WORD_CNT words in WORDS match CMD,
376    and returns the appropriate enum value.  If WORDS are a
377    partial match for CMD and the next word in CMD is a dash, then
378    *DASH_POSSIBLE is set to 1 if DASH_POSSIBLE is non-null;
379    otherwise, *DASH_POSSIBLE is unchanged. */
380 static enum command_match
381 cmd_match_words (const struct command *cmd,
382                  char *const words[], size_t word_cnt,
383                  int *dash_possible)
384 {
385   const char *word;
386   size_t word_len;
387   size_t word_idx;
388
389   for (word = find_word (cmd->name, &word_len), word_idx = 0;
390        word != NULL && word_idx < word_cnt;
391        word = find_word (word + word_len, &word_len), word_idx++)
392     if (word_len != strlen (words[word_idx])
393         || memcmp (word, words[word_idx], word_len))
394       {
395         size_t match_chars = match_strings (word, word_len,
396                                             words[word_idx],
397                                             strlen (words[word_idx]));
398         if (match_chars == 0) 
399           {
400             /* Mismatch. */
401             return MISMATCH;
402           }
403         else if (match_chars == 1 || match_chars == 2) 
404           {
405             /* One- and two-character abbreviations are not
406                acceptable. */
407             return MISMATCH; 
408           }
409         else if (match_chars == 3) 
410           {
411             /* Three-character abbreviations are acceptable
412                in the first word of a command if there are
413                no name conflicts.  They are always
414                acceptable after the first word. */
415             if (word_idx == 0 && conflicting_3char_prefix_command (cmd))
416               return MISMATCH;
417           }
418         else /* match_chars > 3 */ 
419           {
420             /* Four-character and longer abbreviations are
421                always acceptable.  */
422           }
423       }
424
425   if (word == NULL && word_idx == word_cnt) 
426     {
427       /* cmd->name = "FOO BAR", words[] = {"FOO", "BAR"}. */
428       return COMPLETE_MATCH;
429     }
430   else if (word == NULL) 
431     {
432       /* cmd->name = "FOO BAR", words[] = {"FOO", "BAR", "BAZ"}. */
433       return MISMATCH; 
434     }
435   else 
436     {
437       /* cmd->name = "FOO BAR BAZ", words[] = {"FOO", "BAR"}. */
438       if (word[0] == '-' && dash_possible != NULL)
439         *dash_possible = 1;
440       return PARTIAL_MATCH; 
441     }
442 }
443
444 /* Returns the number of commands for which the WORD_CNT words in
445    WORDS are a partial or complete match.  If some partial match
446    has a dash as the next word, then *DASH_POSSIBLE is set to 1,
447    otherwise it is set to 0. */
448 static int
449 count_matching_commands (char *const words[], size_t word_cnt,
450                          int *dash_possible) 
451 {
452   const struct command *cmd;
453   int cmd_match_count;
454
455   cmd_match_count = 0;
456   *dash_possible = 0;
457   for (cmd = commands; cmd < commands + COMMAND_CNT; cmd++) 
458     if (cmd_match_words (cmd, words, word_cnt, dash_possible) != MISMATCH) 
459       cmd_match_count++; 
460
461   return cmd_match_count;
462 }
463
464 /* Returns the command for which the WORD_CNT words in WORDS are
465    a complete match.  Returns a null pointer if no such command
466    exists. */
467 static const struct command *
468 get_complete_match (char *const words[], size_t word_cnt) 
469 {
470   const struct command *cmd;
471   
472   for (cmd = commands; cmd < commands + COMMAND_CNT; cmd++) 
473     if (cmd_match_words (cmd, words, word_cnt, NULL) == COMPLETE_MATCH) 
474       return cmd; 
475   
476   return NULL;
477 }
478
479 /* Frees the WORD_CNT words in WORDS. */
480 static void
481 free_words (char *words[], size_t word_cnt) 
482 {
483   size_t idx;
484   
485   for (idx = 0; idx < word_cnt; idx++)
486     free (words[idx]);
487 }
488
489 /* Flags an error that the command whose name is given by the
490    WORD_CNT words in WORDS is unknown. */
491 static void
492 unknown_command_error (char *const words[], size_t word_cnt) 
493 {
494   size_t idx;
495   size_t words_len;
496   char *name, *cp;
497
498   words_len = 0;
499   for (idx = 0; idx < word_cnt; idx++)
500     words_len += strlen (words[idx]);
501
502   cp = name = xmalloc (words_len + word_cnt + 16);
503   for (idx = 0; idx < word_cnt; idx++) 
504     {
505       if (idx != 0)
506         *cp++ = ' ';
507       cp = stpcpy (cp, words[idx]);
508     }
509   *cp = '\0';
510
511   msg (SE, _("Unknown command %s."), name);
512
513   free (name);
514 }
515
516
517 /* Parse the command name and return a pointer to the corresponding
518    struct command if successful.
519    If not successful, return a null pointer. */
520 static const struct command *
521 parse_command_name (void)
522 {
523   char *words[16];
524   int word_cnt;
525   int complete_word_cnt;
526   int dash_possible;
527
528   dash_possible = 0;
529   word_cnt = complete_word_cnt = 0;
530   while (token == T_ID || (dash_possible && token == '-')) 
531     {
532       int cmd_match_cnt;
533       
534       assert (word_cnt < sizeof words / sizeof *words);
535       if (token == T_ID)
536         words[word_cnt++] = xstrdup (ds_c_str (&tokstr));
537       else
538         words[word_cnt++] = xstrdup ("-");
539
540       cmd_match_cnt = count_matching_commands (words, word_cnt,
541                                                &dash_possible);
542       if (cmd_match_cnt == 0) 
543         break;
544       else if (cmd_match_cnt == 1) 
545         {
546           const struct command *command = get_complete_match (words, word_cnt);
547           if (command != NULL) 
548             {
549               if (command->skip_entire_name)
550                 lex_get ();
551               if ( command->debug & !test_mode ) 
552                 goto error;
553               free_words (words, word_cnt);
554               return command;
555             }
556         }
557       else /* cmd_match_cnt > 1 */
558         {
559           /* Do we have a complete command name so far? */
560           if (get_complete_match (words, word_cnt) != NULL)
561             complete_word_cnt = word_cnt;
562         }
563       lex_get ();
564     }
565
566   /* If we saw a complete command name earlier, drop back to
567      it. */
568   if (complete_word_cnt) 
569     {
570       int pushback_word_cnt;
571       const struct command *command;
572
573       /* Get the command. */
574       command = get_complete_match (words, complete_word_cnt);
575       assert (command != NULL);
576
577       /* Figure out how many words we want to keep.
578          We normally want to swallow the entire command. */
579       pushback_word_cnt = complete_word_cnt + 1;
580       if (!command->skip_entire_name)
581         pushback_word_cnt--;
582       
583       /* FIXME: We only support one-token pushback. */
584       assert (pushback_word_cnt + 1 >= word_cnt);
585
586       while (word_cnt > pushback_word_cnt) 
587         {
588           word_cnt--;
589           if (strcmp (words[word_cnt], "-")) 
590             lex_put_back_id (words[word_cnt]);
591           else
592             lex_put_back ('-');
593           free (words[word_cnt]);
594         }
595
596       if ( command->debug && !test_mode ) 
597         goto error;
598
599       free_words (words, word_cnt);
600       return command;
601     }
602
603 error:
604   unknown_command_error (words, word_cnt);
605   free_words (words, word_cnt);
606   return NULL;
607 }
608 \f
609 /* Simple commands. */
610
611 /* Parse and execute EXIT command. */
612 int
613 cmd_exit (void)
614 {
615   if (getl_reading_script)
616     {
617       msg (SE, _("This command is not accepted in a syntax file.  "
618            "Instead, use FINISH to terminate a syntax file."));
619       lex_get ();
620     }
621   else
622     finished = 1;
623
624   return CMD_SUCCESS;
625 }
626
627 /* Parse and execute FINISH command. */
628 int
629 cmd_finish (void)
630 {
631   /* Do not check for `.'
632      Do not fetch any extra tokens. */
633   if (getl_interactive)
634     {
635       msg (SM, _("This command is not executed "
636            "in interactive mode.  Instead, PSPP drops "
637            "down to the command prompt.  Use EXIT if you really want "
638            "to quit."));
639       getl_close_all ();
640     }
641   else
642     finished = 1;
643
644   return CMD_SUCCESS;
645 }
646
647 /* Parses the N command. */
648 int
649 cmd_n_of_cases (void)
650 {
651   /* Value for N. */
652   int x;
653
654   if (!lex_force_int ())
655     return CMD_FAILURE;
656   x = lex_integer ();
657   lex_get ();
658   if (!lex_match_id ("ESTIMATED"))
659     dict_set_case_limit (default_dict, x);
660
661   return lex_end_of_command ();
662 }
663
664 /* Parses, performs the EXECUTE procedure. */
665 int
666 cmd_execute (void)
667 {
668   procedure (NULL, NULL);
669   return lex_end_of_command ();
670 }
671
672 /* Parses, performs the ERASE command. */
673 int
674 cmd_erase (void)
675 {
676   if ( safer_mode() ) 
677     { 
678       msg (SE, _("This command not allowed when the SAFER option is set.")); 
679       return CMD_FAILURE; 
680     } 
681   
682   if (!lex_force_match_id ("FILE"))
683     return CMD_FAILURE;
684   lex_match ('=');
685   if (!lex_force_string ())
686     return CMD_FAILURE;
687
688   if (remove (ds_c_str (&tokstr)) == -1)
689     {
690       msg (SW, _("Error removing `%s': %s."),
691            ds_c_str (&tokstr), strerror (errno));
692       return CMD_FAILURE;
693     }
694
695   return CMD_SUCCESS;
696 }
697
698 #ifdef unix
699 /* Spawn a shell process. */
700 static int
701 shell (void)
702 {
703   int pid;
704   
705   pid = fork ();
706   switch (pid)
707     {
708     case 0:
709       {
710         const char *shell_fn;
711         char *shell_process;
712         
713         {
714           int i;
715           
716           for (i = 3; i < 20; i++)
717             close (i);
718         }
719
720         shell_fn = getenv ("SHELL");
721         if (shell_fn == NULL)
722           shell_fn = "/bin/sh";
723         
724         {
725           const char *cp = strrchr (shell_fn, '/');
726           cp = cp ? &cp[1] : shell_fn;
727           shell_process = local_alloc (strlen (cp) + 8);
728           strcpy (shell_process, "-");
729           strcat (shell_process, cp);
730           if (strcmp (cp, "sh"))
731             shell_process[0] = '+';
732         }
733         
734         execl (shell_fn, shell_process, NULL);
735
736         err_hcf (1);
737       }
738
739     case -1:
740       msg (SE, _("Couldn't fork: %s."), strerror (errno));
741       return 0;
742
743     default:
744       assert (pid > 0);
745       while (wait (NULL) != pid)
746         ;
747       return 1;
748     }
749 }
750 #endif /* unix */
751
752 /* Parses the HOST command argument and executes the specified
753    command.  Returns a suitable command return code. */
754 static int
755 run_command (void)
756 {
757   const char *cmd;
758   int string;
759
760   /* Handle either a string argument or a full-line argument. */
761   {
762     int c = lex_look_ahead ();
763
764     if (c == '\'' || c == '"')
765       {
766         lex_get ();
767         if (!lex_force_string ())
768           return CMD_FAILURE;
769         cmd = ds_c_str (&tokstr);
770         string = 1;
771       }
772     else
773       {
774         cmd = lex_rest_of_line (NULL);
775         lex_discard_line ();
776         string = 0;
777       }
778   }
779
780   /* Execute the command. */
781   if (system (cmd) == -1)
782     msg (SE, _("Error executing command: %s."), strerror (errno));
783
784   /* Finish parsing. */
785   if (string)
786     {
787       lex_get ();
788
789       if (token != '.')
790         {
791           lex_error (_("expecting end of command"));
792           return CMD_TRAILING_GARBAGE;
793         }
794     }
795   else
796     token = '.';
797
798   return CMD_SUCCESS;
799 }
800
801 /* Parses, performs the HOST command. */
802 int
803 cmd_host (void)
804 {
805   int code;
806
807   if ( safer_mode() ) 
808     { 
809       msg (SE, _("This command not allowed when the SAFER option is set.")); 
810       return CMD_FAILURE; 
811     } 
812
813 #ifdef unix
814   /* Figure out whether to invoke an interactive shell or to execute a
815      single shell command. */
816   if (lex_look_ahead () == '.')
817     {
818       lex_get ();
819       code = shell () ? CMD_PART_SUCCESS_MAYBE : CMD_SUCCESS;
820     }
821   else
822     code = run_command ();
823 #else /* !unix */
824   /* Make sure that the system has a command interpreter, then run a
825      command. */
826   if (system (NULL) != 0)
827     code = run_command ();
828   else
829     {
830       msg (SE, _("No operating system support for this command."));
831       code = CMD_FAILURE;
832     }
833 #endif /* !unix */
834
835   return code ? CMD_FAILURE : CMD_SUCCESS;
836 }
837
838 /* Parses, performs the NEW FILE command. */
839 int
840 cmd_new_file (void)
841 {
842   discard_variables ();
843
844   return lex_end_of_command ();
845 }
846
847 /* Parses, performs the CLEAR TRANSFORMATIONS command. */
848 int
849 cmd_clear_transformations (void)
850 {
851   if (getl_reading_script)
852     {
853       msg (SW, _("This command is not valid in a syntax file."));
854       return CMD_FAILURE;
855     }
856
857   cancel_transformations ();
858   /* FIXME: what about variables created by transformations?
859      They need to be properly initialized. */
860
861   return CMD_SUCCESS;
862 }