- const char *allowed[3];
- int allowed_cnt;
- char *s;
-
- allowed_cnt = 0;
- if (command->states & S_INITIAL)
- allowed[allowed_cnt++] = _("before the active file has been defined");
- else if (command->states & S_DATA)
- allowed[allowed_cnt++] = _("after the active file has been defined");
- if (command->states & S_INPUT_PROGRAM)
- allowed[allowed_cnt++] = _("inside INPUT PROGRAM");
- if (command->states & S_FILE_TYPE)
- allowed[allowed_cnt++] = _("inside FILE TYPE");
-
- if (allowed_cnt == 1)
- s = xstrdup (allowed[0]);
- else if (allowed_cnt == 2)
- s = xasprintf (_("%s or %s"), allowed[0], allowed[1]);
- else if (allowed_cnt == 3)
- s = xasprintf (_("%s, %s, or %s"), allowed[0], allowed[1], allowed[2]);
- else
- NOT_REACHED ();
+ case CMD_STATE_INITIAL:
+ case CMD_STATE_DATA:
+ switch ((int) command->states
+ & (S_INITIAL | S_DATA | S_INPUT_PROGRAM | S_FILE_TYPE))
+ {
+ /* One allowed state. */
+ case S_INITIAL:
+ return xasprintf (_("%s is allowed only before the active dataset has "
+ "been defined."), command->name);
+ case S_DATA:
+ return xasprintf (_("%s is allowed only after the active dataset has "
+ "been defined."), command->name);
+ case S_INPUT_PROGRAM:
+ return xasprintf (_("%s is allowed only inside %s."),
+ command->name, "INPUT PROGRAM");
+ case S_FILE_TYPE:
+ return xasprintf (_("%s is allowed only inside %s."), command->name, "FILE TYPE");
+
+ /* Two allowed states. */
+ case S_INITIAL | S_DATA:
+ NOT_REACHED ();
+ case S_INITIAL | S_INPUT_PROGRAM:
+ return xasprintf (_("%s is allowed only before the active dataset "
+ "has been defined or inside %s."),
+ command->name, "INPUT PROGRAM");
+ case S_INITIAL | S_FILE_TYPE:
+ return xasprintf (_("%s is allowed only before the active dataset "
+ "has been defined or inside %s."),
+ command->name, "FILE TYPE");
+ case S_DATA | S_INPUT_PROGRAM:
+ return xasprintf (_("%s is allowed only after the active dataset "
+ "has been defined or inside %s."),
+ command->name, "INPUT PROGRAM");
+ case S_DATA | S_FILE_TYPE:
+ return xasprintf (_("%s is allowed only after the active dataset "
+ "has been defined or inside %s."),
+ command->name, "FILE TYPE");
+ case S_INPUT_PROGRAM | S_FILE_TYPE:
+ return xasprintf (_("%s is allowed only inside %s or inside %s."),
+ command->name, "INPUT PROGRAM", "FILE TYPE");
+
+ /* Three allowed states. */
+ case S_DATA | S_INPUT_PROGRAM | S_FILE_TYPE:
+ return xasprintf (_("%s is allowed only after the active dataset has "
+ "been defined, inside INPUT PROGRAM, or inside "
+ "FILE TYPE."), command->name);
+ case S_INITIAL | S_INPUT_PROGRAM | S_FILE_TYPE:
+ return xasprintf (_("%s is allowed only before the active dataset "
+ "has been defined, inside INPUT PROGRAM, or "
+ "inside FILE TYPE."), command->name);
+ case S_INITIAL | S_DATA | S_FILE_TYPE:
+ NOT_REACHED ();
+ case S_INITIAL | S_DATA | S_INPUT_PROGRAM:
+ NOT_REACHED ();
+
+ /* Four allowed states. */
+ case S_INITIAL | S_DATA | S_INPUT_PROGRAM | S_FILE_TYPE:
+ NOT_REACHED ();
+
+ default:
+ NOT_REACHED ();
+ }
+ break;
+
+ case CMD_STATE_INPUT_PROGRAM:
+ return xasprintf (_("%s is not allowed inside %s."),
+ command->name, "INPUT PROGRAM");