Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: third_party/hunspell/src/hunspell/filemgr.cxx

Issue 2544793003: [spellcheck] Updated Hunspell to 1.5.4 (Closed)
Patch Set: Test Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "license.hunspell" 1 /* ***** BEGIN LICENSE BLOCK *****
2 #include "license.myspell" 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Hunspell, based on MySpell.
15 *
16 * The Initial Developers of the Original Code are
17 * Kevin Hendricks (MySpell) and Németh László (Hunspell).
18 * Portions created by the Initial Developers are Copyright (C) 2002-2005
19 * the Initial Developers. All Rights Reserved.
20 *
21 * Contributor(s): David Einstein, Davide Prina, Giuseppe Modugno,
22 * Gianluca Turconi, Simon Brouwer, Noll János, Bíró Árpád,
23 * Goldman Eleonóra, Sarlós Tamás, Bencsáth Boldizsár, Halácsy Péter,
24 * Dvornik László, Gefferth András, Nagy Viktor, Varga Dániel, Chris Halls,
25 * Rene Engelhard, Bram Moolenaar, Dafydd Jones, Harri Pitkänen
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40 /*
41 * Copyright 2002 Kevin B. Hendricks, Stratford, Ontario, Canada
42 * And Contributors. All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 *
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 *
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 *
55 * 3. All modifications to the source code must be clearly marked as
56 * such. Binary redistributions based on modified source code
57 * must be clearly marked as modified versions in the documentation
58 * and/or other materials provided with the distribution.
59 *
60 * THIS SOFTWARE IS PROVIDED BY KEVIN B. HENDRICKS AND CONTRIBUTORS
61 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
62 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
63 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
64 * KEVIN B. HENDRICKS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
65 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
66 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
67 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * SUCH DAMAGE.
72 */
3 73
4 #include <stdlib.h> 74 #include <stdlib.h>
5 #include <string.h> 75 #include <string.h>
6 #include <stdio.h> 76 #include <stdio.h>
7 77
8 #include "filemgr.hxx" 78 #include "filemgr.hxx"
79 #include "csutil.hxx"
9 80
10 #ifdef HUNSPELL_CHROME_CLIENT 81 #ifdef HUNSPELL_CHROME_CLIENT
11 #include "third_party/hunspell/google/bdict_reader.h" 82 #include "third_party/hunspell/google/bdict_reader.h"
12 83
13 FileMgr::FileMgr(hunspell::LineIterator* iterator) : iterator_(iterator) { 84 FileMgr::FileMgr(hunspell::LineIterator* iterator) : iterator_(iterator) {
14 } 85 }
15 86
16 FileMgr::~FileMgr() { 87 FileMgr::~FileMgr() {
17 } 88 }
18 89
19 char * FileMgr::getline() { 90 bool FileMgr::getline(std::string& line) {
20 // Read one line from a BDICT file and store the line to our line buffer. 91 // Read one line from a BDICT file and return it, if we can read a line
21 // To emulate the original FileMgr::getline(), this function returns 92 // without errors.
22 // the pointer to our line buffer if we can read a line without errors.
23 // Otherwise, this function returns NULL.
24 bool result = iterator_->AdvanceAndCopy(line_, BUFSIZE - 1); 93 bool result = iterator_->AdvanceAndCopy(line_, BUFSIZE - 1);
25 return result ? line_ : NULL; 94 if (result)
95 line = line_;
96 return result;
26 } 97 }
27 98
28 int FileMgr::getlinenum() { 99 int FileMgr::getlinenum() {
29 // This function is used only for displaying a line number that causes a 100 // This function is used only for displaying a line number that causes a
30 // parser error. For a BDICT file, providing a line number doesn't help 101 // parser error. For a BDICT file, providing a line number doesn't help
31 // identifying the place where causes a parser error so much since it is a 102 // identifying the place where causes a parser error so much since it is a
32 // binary file. So, we just return 0. 103 // binary file. So, we just return 0.
33 return 0; 104 return 0;
34 } 105 }
35 #else 106 #else
36 int FileMgr::fail(const char * err, const char * par) { 107 int FileMgr::fail(const char* err, const char* par) {
37 fprintf(stderr, err, par); 108 fprintf(stderr, err, par);
38 return -1; 109 return -1;
39 } 110 }
40 111
41 FileMgr::FileMgr(const char * file, const char * key) { 112 FileMgr::FileMgr(const char* file, const char* key) : hin(NULL), linenum(0) {
42 linenum = 0; 113 in[0] = '\0';
43 hin = NULL; 114
44 fin = fopen(file, "r"); 115 myopen(fin, file, std::ios_base::in);
45 if (!fin) { 116 if (!fin.is_open()) {
46 // check hzipped file 117 // check hzipped file
47 char * st = (char *) malloc(strlen(file) + strlen(HZIP_EXTENSION) + 1); 118 std::string st(file);
48 if (st) { 119 st.append(HZIP_EXTENSION);
49 strcpy(st, file); 120 hin = new Hunzip(st.c_str(), key);
50 strcat(st, HZIP_EXTENSION); 121 }
51 hin = new Hunzip(st, key); 122 if (!fin.is_open() && !hin->is_open())
52 free(st); 123 fail(MSG_OPEN, file);
53 }
54 }
55 if (!fin && !hin) fail(MSG_OPEN, file);
56 } 124 }
57 125
58 FileMgr::~FileMgr() 126 FileMgr::~FileMgr() {
59 { 127 delete hin;
60 if (fin) fclose(fin);
61 if (hin) delete hin;
62 } 128 }
63 129
64 char * FileMgr::getline() { 130 bool FileMgr::getline(std::string& dest) {
65 const char * l; 131 bool ret = false;
66 linenum++; 132 ++linenum;
67 if (fin) return fgets(in, BUFSIZE - 1, fin); 133 if (fin.is_open()) {
68 if (hin && ((l = hin->getline()) != NULL)) return strcpy(in, l); 134 ret = static_cast<bool>(std::getline(fin, dest));
69 linenum--; 135 } else if (hin->is_open()) {
70 return NULL; 136 ret = hin->getline(dest);
137 }
138 if (!ret) {
139 --linenum;
140 }
141 return ret;
71 } 142 }
72 143
73 int FileMgr::getlinenum() { 144 int FileMgr::getlinenum() {
74 return linenum; 145 return linenum;
75 } 146 }
76 #endif 147 #endif
OLDNEW
« no previous file with comments | « third_party/hunspell/src/hunspell/filemgr.hxx ('k') | third_party/hunspell/src/hunspell/hashmgr.hxx » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698