-/* EXPORT procedure. */
-struct export_proc
- {
- struct pfm_writer *writer; /* System file writer. */
- struct case_map *map; /* Map from active file to system file dict. */
- struct ccase bounce; /* Bounce buffer. */
- };
-
-static int export_write_case_func (struct ccase *, void *);
-static void export_proc_free (struct export_proc *);
-
-/* Parses the EXPORT command. */
-/* FIXME: same as cmd_save_internal(). */
-int
-cmd_export (void)
-{
- struct file_handle *fh;
- struct dictionary *dict;
- struct export_proc *proc;
-
- proc = xmalloc (sizeof *proc);
- proc->writer = NULL;
- proc->map = NULL;
- case_nullify (&proc->bounce);
-
- lex_match ('/');
- if (lex_match_id ("OUTFILE"))
- lex_match ('=');
- fh = fh_parse ();
- if (fh == NULL)
- return CMD_FAILURE;
-
- dict = dict_clone (default_dict);
- start_case_map (dict);
- if (!trim_dictionary (dict, OP_EXPORT, NULL))
- goto error;
- proc->map = finish_case_map (dict);
- if (proc->map != NULL)
- case_create (&proc->bounce, dict_get_next_value_idx (dict));
-
- proc->writer = pfm_open_writer (fh, dict);
- if (proc->writer == NULL)
- goto error;
-
- dict_destroy (dict);
-
- procedure (export_write_case_func, proc);
- export_proc_free (proc);
- free (proc);
-
- return CMD_SUCCESS;
-
- error:
- dict_destroy (dict);
- export_proc_free (proc);
- free (proc);
- return CMD_FAILURE;
-}
-
-/* Writes case C to the EXPORT file. */
-static int
-export_write_case_func (struct ccase *c, void *aux)
-{
- struct export_proc *proc = aux;
- if (proc->map == NULL)
- pfm_write_case (proc->writer, c);
- else
- {
- map_case (proc->map, c, &proc->bounce);
- pfm_write_case (proc->writer, &proc->bounce);
- }
- return 1;
-}
-
-static void
-export_proc_free (struct export_proc *proc)
-{
- if (proc != NULL)
- {
- pfm_close_writer (proc->writer);
- destroy_case_map (proc->map);
- case_destroy (&proc->bounce);
- }
-}
-\f