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