FOSSology  4.4.0
Open Source License Compliance by Open Source Software
parse_license.php
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2014 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
14 if ($argc < 2 || empty($argv[1])) {
15  print "please specify the file you want to parse.\n";
16  exit;
17 }
18 
19 $scanning_file = $argv[1];
20 //print "scanning_file is:$scanning_file\n";
21 $handle = fopen($scanning_file, "r");
22 if ($handle) {
23  while (($line = fgets($handle)) !== false) {
24  if (empty($line)) exit;
25 
26  if (strstr($line, "LS_")) print "$line";
27  else { // not include 'LS_'
28  $res = explode("\"", $line);
29  $count = count($res);
30  if (2 > $count) continue; // no found
31  //print_r($res);
32  //print "count is:$count, line is:$line";
33  for($i = $count - 1; $i >=0; $i--)
34  {
35  if (strstr($res[$i], ";")) // ignore the string include ';'
36  {
37  //print "res[$i] is:$res[$i]\n";
38  continue;
39  }
40  else {
41  print "$res[$i]\n";
42  break;
43  }
44  } // for
45  } // not include 'LS_'
46  } // while
47 } else {
48  // error opening the file.
49 }
50 fclose($handle);