Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / data / any-writer.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2006, 2011 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18
19 #include "data/any-writer.h"
20
21 #include <assert.h>
22 #include <errno.h>
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #include "data/file-handle-def.h"
28 #include "data/file-name.h"
29 #include "data/por-file-writer.h"
30 #include "data/scratch-writer.h"
31 #include "data/sys-file-writer.h"
32 #include "libpspp/assertion.h"
33 #include "libpspp/message.h"
34 #include "libpspp/str.h"
35
36 #include "gl/xalloc.h"
37
38 #include "gettext.h"
39 #define _(msgid) gettext (msgid)
40
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)
44 {
45   switch (fh_get_referent (handle))
46     {
47     case FH_REF_FILE:
48       {
49         struct casewriter *writer;
50         char *extension;
51
52         extension = fn_extension (fh_get_file_name (handle));
53         str_lowercase (extension);
54
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);
62
63         return writer;
64       }
65
66     case FH_REF_INLINE:
67       msg (ME, _("The inline file is not allowed here."));
68       return NULL;
69
70     case FH_REF_SCRATCH:
71       return scratch_writer_open (handle, dict);
72     }
73
74   NOT_REACHED ();
75 }