Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / third_party / hunspell / src / hunspell / filemgr.cxx
blob05fc3077896f2bf965e3acc13716e0ebe330b522
1 #include "license.hunspell"
2 #include "license.myspell"
4 #include <stdlib.h>
5 #include <string.h>
6 #include <stdio.h>
8 #include "filemgr.hxx"
10 #ifdef HUNSPELL_CHROME_CLIENT
11 #include "third_party/hunspell/google/bdict_reader.h"
13 FileMgr::FileMgr(hunspell::LineIterator* iterator) : iterator_(iterator) {
16 FileMgr::~FileMgr() {
19 char * FileMgr::getline() {
20 // Read one line from a BDICT file and store the line to our line buffer.
21 // To emulate the original FileMgr::getline(), this function returns
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);
25 return result ? line_ : NULL;
28 int FileMgr::getlinenum() {
29 // 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
31 // identifying the place where causes a parser error so much since it is a
32 // binary file. So, we just return 0.
33 return 0;
35 #else
36 int FileMgr::fail(const char * err, const char * par) {
37 fprintf(stderr, err, par);
38 return -1;
41 FileMgr::FileMgr(const char * file, const char * key) {
42 linenum = 0;
43 hin = NULL;
44 fin = fopen(file, "r");
45 if (!fin) {
46 // check hzipped file
47 char * st = (char *) malloc(strlen(file) + strlen(HZIP_EXTENSION) + 1);
48 if (st) {
49 strcpy(st, file);
50 strcat(st, HZIP_EXTENSION);
51 hin = new Hunzip(st, key);
52 free(st);
55 if (!fin && !hin) fail(MSG_OPEN, file);
58 FileMgr::~FileMgr()
60 if (fin) fclose(fin);
61 if (hin) delete hin;
64 char * FileMgr::getline() {
65 const char * l;
66 linenum++;
67 if (fin) return fgets(in, BUFSIZE - 1, fin);
68 if (hin && ((l = hin->getline()) != NULL)) return strcpy(in, l);
69 linenum--;
70 return NULL;
73 int FileMgr::getlinenum() {
74 return linenum;
76 #endif