| OLD | NEW |
| (Empty) |
| 1 #include "license.hunspell" | |
| 2 #include "license.myspell" | |
| 3 | |
| 4 #include <stdlib.h> | |
| 5 #include <string.h> | |
| 6 #include <stdio.h> | |
| 7 | |
| 8 #include "filemgr.hxx" | |
| 9 | |
| 10 #ifdef HUNSPELL_CHROME_CLIENT | |
| 11 #include "third_party/hunspell_new/google/bdict_reader.h" | |
| 12 | |
| 13 FileMgr::FileMgr(hunspell::LineIterator* iterator) : iterator_(iterator) { | |
| 14 } | |
| 15 | |
| 16 FileMgr::~FileMgr() { | |
| 17 } | |
| 18 | |
| 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; | |
| 26 } | |
| 27 | |
| 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; | |
| 34 } | |
| 35 #else | |
| 36 int FileMgr::fail(const char * err, const char * par) { | |
| 37 fprintf(stderr, err, par); | |
| 38 return -1; | |
| 39 } | |
| 40 | |
| 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); | |
| 53 } | |
| 54 } | |
| 55 if (!fin && !hin) fail(MSG_OPEN, file); | |
| 56 } | |
| 57 | |
| 58 FileMgr::~FileMgr() | |
| 59 { | |
| 60 if (fin) fclose(fin); | |
| 61 if (hin) delete hin; | |
| 62 } | |
| 63 | |
| 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; | |
| 71 } | |
| 72 | |
| 73 int FileMgr::getlinenum() { | |
| 74 return linenum; | |
| 75 } | |
| 76 #endif | |
| OLD | NEW |