FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ReadInputFile.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
18 
19  public $inputFile;
20  protected $error;
21  protected $fileResource;
22 
32  public function __construct($file) {
33 
34  $this->error = NULL;
35  $this->inputFile = $file;
36  if(!file_exists($file)) {
37  return(FALSE);
38  }
39  //print "DB: RIF: inputFile is:$this->inputFile\n";
40  try {
41  if(FALSE === ($FD = @fopen($this->inputFile, 'r'))) {
42  throw new Exception("Cannot open File $this->inputFile\n");
43  }
44  }
45  catch(Exception $e) {
46  $this->error = $e->getMessage();
47  return(FALSE);
48  }
49  $this->fileResource = $FD;
50  return(TRUE);
51  }
52 
53  public function getError(){
54  return($this->error);
55  }
56 
57  public function getFileResource(){
58  return($this->fileResource);
59  }
78  public function getLine($FD) {
79  while($rline = fgets($FD, 1024)) {
80  $line = trim($rline);
81  // check for blank lines, (null after trim), or comment, skip them
82  if ($line === "") continue;
83  if (preg_match('/^#/', $line)) continue;
84  return($line);
85  }
86  return(FALSE);
87  }
88 };
__construct($file)
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690