FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ReadInputFile.php
1 <?php
2 
3 /***********************************************************
4  Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***********************************************************/
19 
30 
31  public $inputFile;
32  protected $error;
33  protected $fileResource;
34 
44  public function __construct($file) {
45 
46  $this->error = NULL;
47  $this->inputFile = $file;
48  if(!file_exists($file)) {
49  return(FALSE);
50  }
51  //print "DB: RIF: inputFile is:$this->inputFile\n";
52  try {
53  if(FALSE === ($FD = @fopen($this->inputFile, 'r'))) {
54  throw new Exception("Cannot open File $this->inputFile\n");
55  }
56  }
57  catch(Exception $e) {
58  $this->error = $e->getMessage();
59  return(FALSE);
60  }
61  $this->fileResource = $FD;
62  return(TRUE);
63  }
64 
65  public function getError(){
66  return($this->error);
67  }
68 
69  public function getFileResource(){
70  return($this->fileResource);
71  }
90  public function getLine($FD) {
91  while($rline = fgets($FD, 1024)) {
92  $line = trim($rline);
93  // check for blank lines, (null after trim), or comment, skip them
94  if ($line === "") continue;
95  if (preg_match('/^#/', $line)) continue;
96  return($line);
97  }
98  return(FALSE);
99  }
100 };
101 ?>
__construct($file)
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695