0309ed16 |
1 | <?php |
2 | /** |
3 | * Copyright (c) 2003 Danilo Segan <danilo@kvota.net>. |
4 | * |
5 | * This file is part of PHP-gettext. |
6 | * |
7 | * PHP-gettext is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * PHP-gettext is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with PHP-gettext; if not, write to the Free Software |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 | * |
21 | * @package squirrelmail |
22 | * @subpackage i18n |
23 | */ |
24 | |
25 | /** |
26 | * Class that is used to read .mo files. |
27 | * @package squirrelmail |
28 | * @subpackage i18n |
29 | */ |
30 | class FileReader { |
31 | /** |
32 | * Current position in file |
33 | * @var integer |
34 | */ |
35 | var $_pos; |
36 | /** |
37 | * File descriptor |
38 | * @var resource |
39 | */ |
40 | var $_fd; |
41 | /** |
42 | * File size |
43 | * @var integer |
44 | */ |
45 | var $_length; |
46 | /** |
47 | * contains error codes |
48 | * |
49 | * 2 = File doesn't exist |
50 | * 3 = Can't read file |
51 | * @var integer |
52 | */ |
53 | var $error=0; |
54 | |
55 | /** |
56 | * reads translation file and fills translation input object properties |
57 | * @param string $filename path to file |
58 | * @return boolean false there is a problem with $filename |
59 | */ |
60 | function FileReader($filename) { |
61 | if (file_exists($filename)) { |
62 | |
63 | $this->_length=filesize($filename); |
64 | error_log($this->_length); |
65 | $this->_pos = 0; |
66 | $this->_fd = fopen($filename,'rb'); |
67 | if (!$this->_fd) { |
68 | $this->error = 3; // Cannot read file, probably permissions |
69 | return false; |
70 | } |
71 | } else { |
72 | $this->error = 2; // File doesn't exist |
73 | return false; |
74 | } |
75 | } |
76 | |
77 | /** |
78 | * reads data from current position |
79 | * @param integer $bytes number of bytes to read |
80 | * @return string read data |
81 | */ |
82 | function read($bytes) { |
83 | fseek($this->_fd, $this->_pos); |
84 | $data = fread($this->_fd, $bytes); |
85 | $this->_pos = ftell($this->_fd); |
86 | |
87 | return $data; |
88 | } |
89 | |
90 | /** |
91 | * Moves to defined position in a file |
92 | * @param integer $pos position |
93 | * @return integer current position |
94 | */ |
95 | function seekto($pos) { |
96 | fseek($this->_fd, $pos); |
97 | $this->_pos = ftell($this->_fd); |
98 | return $this->_pos; |
99 | } |
100 | |
101 | /** |
102 | * return current position |
103 | * @return integer current position |
104 | */ |
105 | function currentpos() { |
106 | return $this->_pos; |
107 | } |
108 | |
109 | /** |
110 | * return file length |
111 | * @return integer file length |
112 | */ |
113 | function length() { |
114 | return $this->_length; |
115 | } |
116 | |
117 | /** |
118 | * close translation file |
119 | */ |
120 | function close() { |
121 | fclose($this->_fd); |
122 | } |
123 | } |
124 | ?> |