~ubuntu-branches/ubuntu/vivid/libspectre/vivid-proposed

« back to all changes in this revision

Viewing changes to libspectre/spectre-exporter-ps.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Rosewarne
  • Date: 2008-01-06 21:58:55 UTC
  • Revision ID: james.westby@ubuntu.com-20080106215855-zmmkfhf4m3190zsj
Tags: upstream-0.2.0.ds
ImportĀ upstreamĀ versionĀ 0.2.0.ds

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Libspectre.
 
2
 * 
 
3
 * Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
 
4
 * Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
 
5
 *
 
6
 * Libspectre is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2, or (at your option)
 
9
 * any later version.
 
10
 *
 
11
 * Libspectre is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 */
 
20
 
 
21
#include <stdlib.h>
 
22
 
 
23
#include "spectre-private.h"
 
24
 
 
25
static SpectreStatus
 
26
spectre_exporter_ps_begin (SpectreExporter *exporter,
 
27
                           const char      *filename)
 
28
{
 
29
        exporter->from = fopen (exporter->doc->filename, "r");
 
30
        if (!exporter->from)
 
31
                return SPECTRE_STATUS_EXPORTER_ERROR;
 
32
        
 
33
        exporter->to = fopen (filename, "w");
 
34
        if (!exporter->to) {
 
35
                fclose (exporter->from);
 
36
                exporter->from = NULL;
 
37
                return SPECTRE_STATUS_EXPORTER_ERROR;
 
38
        }
 
39
                
 
40
        pscopyheaders (exporter->from, exporter->to, exporter->doc);
 
41
        
 
42
        return SPECTRE_STATUS_SUCCESS;
 
43
}
 
44
 
 
45
static SpectreStatus
 
46
spectre_exporter_ps_do_page (SpectreExporter *exporter,
 
47
                             unsigned int     page_index)
 
48
{
 
49
        if (exporter->doc->numpages <= 0)
 
50
                return SPECTRE_STATUS_SUCCESS;
 
51
        
 
52
        pscopypage (exporter->from, exporter->to, exporter->doc,
 
53
                    page_index, exporter->n_pages++);
 
54
        
 
55
        return SPECTRE_STATUS_SUCCESS;
 
56
}
 
57
 
 
58
static SpectreStatus
 
59
spectre_exporter_ps_end (SpectreExporter *exporter)
 
60
{
 
61
        pscopytrailer (exporter->from, exporter->to, exporter->doc,
 
62
                       exporter->n_pages);
 
63
 
 
64
        fclose (exporter->from);
 
65
        exporter->from = NULL;
 
66
        fclose (exporter->to);
 
67
        exporter->to = NULL;
 
68
        
 
69
        return SPECTRE_STATUS_SUCCESS;
 
70
}
 
71
 
 
72
SpectreExporter *
 
73
_spectre_exporter_ps_new (struct document *doc)
 
74
{
 
75
        SpectreExporter *exporter;
 
76
 
 
77
        exporter = calloc (1, sizeof (SpectreExporter));
 
78
        if (!exporter)
 
79
                return NULL;
 
80
 
 
81
        exporter->doc = psdocreference (doc);
 
82
 
 
83
        exporter->begin = spectre_exporter_ps_begin;
 
84
        exporter->do_page = spectre_exporter_ps_do_page;
 
85
        exporter->end = spectre_exporter_ps_end;
 
86
 
 
87
        return exporter;
 
88
}