pc+-file-reader: Fix memory leak.
[pspp.git] / src / data / any-writer.c
blob170702bab36c333f4d9e4bb54aca596e70f70e25
1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2006, 2010, 2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #include <config.h>
19 #include "data/any-writer.h"
21 #include <assert.h>
22 #include <errno.h>
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "data/dataset-writer.h"
28 #include "data/file-handle-def.h"
29 #include "data/file-name.h"
30 #include "data/por-file-writer.h"
31 #include "data/sys-file-writer.h"
32 #include "libpspp/assertion.h"
33 #include "libpspp/message.h"
34 #include "libpspp/str.h"
36 #include "gl/xalloc.h"
38 #include "gettext.h"
39 #define _(msgid) gettext (msgid)
41 /* Creates and returns a writer for HANDLE with the given DICT. */
42 struct casewriter *
43 any_writer_open (struct file_handle *handle, struct dictionary *dict)
45 switch (fh_get_referent (handle))
47 case FH_REF_FILE:
49 struct casewriter *writer;
50 char *extension;
52 extension = fn_extension (handle);
53 str_lowercase (extension);
55 if (!strcmp (extension, ".por"))
56 writer = pfm_open_writer (handle, dict,
57 pfm_writer_default_options ());
58 else
59 writer = sfm_open_writer (handle, dict,
60 sfm_writer_default_options ());
61 free (extension);
63 return writer;
66 case FH_REF_INLINE:
67 msg (ME, _("The inline file is not allowed here."));
68 return NULL;
70 case FH_REF_DATASET:
71 return dataset_writer_open (handle, dict);
74 NOT_REACHED ();