FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
lib_projxml.h.php
1 <?php
2 /***********************************************************
3  db_postgres.h.php
4  Copyright (C) 2007 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 
46 function write_entry($in_handle, $marker, $out_handle){
47 
48  // The marker is really set AFTER <project>, so <project> needs to
49  // be written.
50  $start = fseek($in_handle, $marker);
51  fwrite($out_handle, " <project>\n");
52  while( false != ($line = fgets($in_handle, 1024))){
53  // </project> is the end tag, write it and return, all done.
54  if (preg_match('|</project>|', $line)){
55  fwrite($out_handle, $line);
56  return;
57  }
58  fwrite($out_handle, $line);
59  }
60 }
61 
77 function get_entry($in_handle, $marker){
78 
79  $project = array();
80 
81  // The marker is really set AFTER <project>, so <project> needs to
82  // be written.
83  $start = fseek($in_handle, $marker);
84  $project[] = " <project>\n";
85  while( false != ($line = fgets($in_handle, 1024))){
86  // </project> is the end tag, save it and return, all done.
87  if (preg_match('|</project>|', $line)){
88  array_push(&$project, $line);
89  return($project);
90  }
91  array_push(&$project, $line);
92  }
93 }
94 
106 function close_tag($handle){
107 
108  $tag = "</project-listing>\n";
109  fwrite($handle, $tag);
110  return;
111 }
123 function parse_fm_input($fm_string){
124  $parms = preg_split
125  ('/([\'|\"])+?/', $fm_string);
126  //("/([\'|\"])/", $fm_string, -1, PREG_SPLIT_DELIM_CAPTURE);
127  //("/([0-9]) ([0-9a-zA-Z]) (\'|\")*?/", $fm_string, -1, PREG_SPLIT_DELIM_CAPTURE);
128  // the split above leave null entries.... remove them.
129  $acnt = count($parms);
130  for ($ai=0; $ai<=$acnt; $ai++){
131  $len = strlen($parms[$ai]);
132  if ($len == 0){
133  //echo "unsetting 0 lenght entry\n";
134  unset($parms[$ai]);
135  }
136  elseif (!(isset($parms[$ai]))){
137  //echo "value not set, unsetting in parms \$parms[$ai]\n";
138  unset($parms[$ai]);
139  }
140  elseif ((isset($parms[$ai]))){
141  if(ereg('^ +', $parms[$ai])){
142  //echo "getting rid of space \$parms[$ai]\n";
143  unset($parms[$ai]);
144  }
145  }
146  }
147  // compact the array so list will work! this is just stupid...
148  $lparms = array_values($parms);
149  //pdbg("ParseFmI: \$parms is:", $lparms);
150  return($lparms);
151 }
152 
169 function pdbg($message, $dump=''){
170 
171  $dbg_msg = 'DBG->' . $message . "\n";
172 
173  echo $dbg_msg;
174 
175  if(isset($dump)){
176  // echo "\$dump is:\n";
177  print_r($dump);
178  echo "\n";
179  }
180  return;
181 }
182 
195 function write_hdr($handle){
196 
197  $xml_hdr = <<< HDR
198 <?xml version="1.0" encoding="ISO-8859-1"?>
199 <!DOCTYPE project-listing SYSTEM "http://freshmeat.net/backend/fm-projects-0.4.dtd">
200 <project-listing>
201 
202 HDR;
203  //pdbg("WHDR: \$xml_hdr is:$xml_hdr");
204  fwrite($handle, $xml_hdr);
205  return;
206 }
207 
221 function write_pxml($file_handle, $pxml){
222  //write_hdr($file_handle);
223  for ($i=0; $i < count($pxml); $i++){
224  fwrite($file_handle, $pxml[$i]);
225  }
226  return;
227 }
228 
241 function save_Yupdated($file_handle, $Updata){
242  //$Updata .= "\n";
243  fwrite($file_handle, $Updata);
244  return;
245 }
246 
260 function xtract($string){
261 
262  $pos = strpos($string, '>');
263  $val_start = $pos + 1;
264  $val_end = strpos($string, '</', $val_start);
265  if(!(is_numeric($val_end))){ // not a valid tag... return null.
266  return(NULL);
267  }
268  $val_len = $val_end - $val_start;
269  $value = substr($string, $val_start, $val_len);
270  return($value);
271 }
272 
288 function read_pfile($xml_file) {
289  /*
290  * Data Structure:
291  *
292  * Key Key Value(s)
293  * --- --- --------
294  * project_rank project_name <zero or more urls to archives>,
295  * <home_url>, <short-description>,
296  * version-info (3 tokens).
297  *
298  */
299  $meatdoc= simplexml_load_file("$xml_file");
300  # echo "read_pfile: Read XML file\n";
301  $fmprojs = array();
302  foreach ($meatdoc->project as $project) {
303  $fmprojs["$project->popularity_rank"] ["$project->projectname_short"] =
304  array ("$project->url_tgz",
305  "$project->url_bz2",
306  "$project->url_zip",
307  "$project->url_homepage",
308  "$project->desc_short"
309  );
310  foreach($project->latest_release as $verdata){
311  array_push(
312  &$fmprojs["$project->popularity_rank"] ["$project->projectname_short"],
313  $verdata->latest_release_version,
314  $verdata->latest_release_id,
315  $verdata->latest_release_date
316  );
317  }
318  }
319  ksort($fmprojs);
320  return($fmprojs);
321 }
322 ?>