~ubuntu-branches/ubuntu/vivid/robojournal/vivid-proposed

« back to all changes in this revision

Viewing changes to core/hunspell/filemgr.cxx

  • Committer: Package Import Robot
  • Author(s): Ritesh Raj Sarraf
  • Date: 2014-10-14 15:50:21 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20141014155021-gjd34w00cquge8jf
Tags: 0.5-1
* [d7ce610] Imported Upstream version 0.5
* [ff3b609] Refine what is in the docs/
* [c1e0474] Add doc-base registration
* [68cd341] Install upstream provided xpm icon
* [a627af4] Add patch to override hardcoded doc location

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of RoboJournal.
 
3
    Copyright (c) 2014 by Will Kraft <pwizard@gmail.com>.
 
4
 
 
5
    RoboJournal is free software: you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License as published by
 
7
    the Free Software Foundation, either version 3 of the License, or
 
8
    (at your option) any later version.
 
9
 
 
10
    RoboJournal is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with RoboJournal.  If not, see <http://www.gnu.org/licenses/>.
 
17
  */
 
18
 
 
19
/* ***** BEGIN LICENSE BLOCK *****
 
20
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
21
 *
 
22
 * The contents of this file are subject to the Mozilla Public License Version
 
23
 * 1.1 (the "License"); you may not use this file except in compliance with
 
24
 * the License. You may obtain a copy of the License at
 
25
 * http://www.mozilla.org/MPL/
 
26
 *
 
27
 * Software distributed under the License is distributed on an "AS IS" basis,
 
28
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
29
 * for the specific language governing rights and limitations under the
 
30
 * License.
 
31
 *
 
32
 * The Original Code is Hunspell, based on MySpell.
 
33
 *
 
34
 * The Initial Developers of the Original Code are
 
35
 * Kevin Hendricks (MySpell) and Laszlo Nemeth (Hunspell).
 
36
 * Portions created by the Initial Developers are Copyright (C) 2002-2005
 
37
 * the Initial Developers. All Rights Reserved.
 
38
 *
 
39
 * Contributor(s):
 
40
 * David Einstein
 
41
 * Davide Prina
 
42
 * Giuseppe Modugno
 
43
 * Gianluca Turconi
 
44
 * Simon Brouwer
 
45
 * Noll Janos
 
46
 * Biro Arpad
 
47
 * Goldman Eleonora
 
48
 * Sarlos Tamas
 
49
 * Bencsath Boldizsar
 
50
 * Halacsy Peter
 
51
 * Dvornik Laszlo
 
52
 * Gefferth Andras
 
53
 * Nagy Viktor
 
54
 * Varga Daniel
 
55
 * Chris Halls
 
56
 * Rene Engelhard
 
57
 * Bram Moolenaar
 
58
 * Dafydd Jones
 
59
 * Harri Pitkanen
 
60
 * Andras Timar
 
61
 * Tor Lillqvist
 
62
 *
 
63
 * Alternatively, the contents of this file may be used under the terms of
 
64
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
65
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
66
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
67
 * of those above. If you wish to allow use of your version of this file only
 
68
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
69
 * use your version of this file under the terms of the MPL, indicate your
 
70
 * decision by deleting the provisions above and replace them with the notice
 
71
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
72
 * the provisions above, a recipient may use your version of this file under
 
73
 * the terms of any one of the MPL, the GPL or the LGPL.
 
74
 *
 
75
 * ***** END LICENSE BLOCK ***** */
 
76
 
 
77
#include "license.hunspell"
 
78
#include "license.myspell"
 
79
 
 
80
#include <stdlib.h>
 
81
#include <string.h>
 
82
#include <stdio.h>
 
83
 
 
84
#include "filemgr.hxx"
 
85
 
 
86
int FileMgr::fail(const char * err, const char * par) {
 
87
    fprintf(stderr, err, par);
 
88
    return -1;
 
89
}
 
90
 
 
91
FileMgr::FileMgr(const char * file, const char * key) {
 
92
    linenum = 0;
 
93
    hin = NULL;
 
94
    fin = fopen(file, "r");
 
95
    if (!fin) {
 
96
        // check hzipped file
 
97
        char * st = (char *) malloc(strlen(file) + strlen(HZIP_EXTENSION) + 1);
 
98
        if (st) {
 
99
            strcpy(st, file);
 
100
            strcat(st, HZIP_EXTENSION);
 
101
            hin = new Hunzip(st, key);
 
102
            free(st);
 
103
        }
 
104
    }    
 
105
    if (!fin && !hin) fail(MSG_OPEN, file);
 
106
}
 
107
 
 
108
FileMgr::~FileMgr()
 
109
{
 
110
    if (fin) fclose(fin);
 
111
    if (hin) delete hin;
 
112
}
 
113
 
 
114
char * FileMgr::getline() {
 
115
    const char * l;
 
116
    linenum++;
 
117
    if (fin) return fgets(in, BUFSIZE - 1, fin);
 
118
    if (hin && (l = hin->getline())) return strcpy(in, l);
 
119
    linenum--;
 
120
    return NULL;
 
121
}
 
122
 
 
123
int FileMgr::getlinenum() {
 
124
    return linenum;
 
125
}