Tizen 2.1 base
[external/enchant.git] / src / myspell / filemgr.cxx
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 #include "enchant-provider.h"
11
12 int FileMgr::fail(const char * err, const char * par) {
13     fprintf(stderr, err, par);
14     return -1;
15 }
16
17 FileMgr::FileMgr(const char * file, const char * key) {
18     linenum = 0;
19     hin = NULL;
20     fin = enchant_fopen(file, "r");
21     if (!fin) {
22         // check hzipped file
23         char * st = (char *) malloc(strlen(file) + strlen(HZIP_EXTENSION) + 1);
24         if (st) {
25             strcpy(st, file);
26             strcat(st, HZIP_EXTENSION);
27             hin = new Hunzip(st, key);
28             free(st);
29         }
30     }    
31     if (!fin && !hin) fail(MSG_OPEN, file);
32 }
33
34 FileMgr::~FileMgr()
35 {
36     if (fin) fclose(fin);
37     if (hin) delete hin;
38 }
39
40 char * FileMgr::getline() {
41     const char * l;
42     linenum++;
43     if (fin) return fgets(in, BUFSIZE - 1, fin);
44     if (hin && (l = hin->getline())) return strcpy(in, l);
45     linenum--;
46     return NULL;
47 }
48
49 int FileMgr::getlinenum() {
50     return linenum;
51 }