Create clean tool branch.
[Archlinux-Stable.git] / pkgvers.php
blob7add6a10e7fd63bc3bd233510906a1ca511c78f9
1 #!/usr/bin/php
2 <?PHP
3 function main()
5 $files = find_file('~archers', 'PKGBUILD');
6 foreach ($files as $package)
8 $vals = read_pkg($package);
9 $write_line = format_line($vals);
10 write_line($write_line);
14 function find_file($start_path, $name)
16 // Locate PKGBUILD files to check version of
17 $find_cmd = '/usr/bin/find ' . $start_path . ' -name ' . $name;
18 $res = shell_exec($find_cmd);
19 $vals = explode("\n", $res);
20 array_pop($vals);
21 return $vals;
24 function read_pkg($file)
26 // Opens package and stores in searchable structure
27 $fp = @fopen($file, "r");
28 if ($fp)
30 $data = '';
31 while($line = fgets($fp))
33 // pkgname will return 0 as start char, ie. FALSE. kgname will return 1
34 // = required to not catch sourcelines using $pkgname
35 if (!strpos($line, 'kgname='))
37 echo "No: $line"; // not there yet, skip 'on down to next line
38 } else {
39 $data = 'start'; // good data, start recording
42 if ($data = 'start')
44 if (strpos($line, 'kgrel')) // samething with pkgrel/kgrel as with pkgname/kgname
46 $data = 'stop'; // the end of the data we want
49 echo "$i Yes: $line";
50 $line_value = array_pop(explode('=', $line));
51 $vals[] = $line_value;
54 if ($data = 'stop') // don't make any more loops through here
56 break;
60 return $vals;
63 function write_line($line='blank', $file='default')
65 $flag = FILE_APPEND;
66 // Sends our package version data to a new file
67 // Use default pkgver filename if none provided
68 // Write blank line of no output specified
69 if ($file == 'default')
71 $file = "arch-stable-0.1-pkgvers";
74 if (!file_exists($file))
76 shell_exec("touch $file");
77 $flag = null;
79 file_put_contents($file, $line, $flag);
82 function format_line(&$vals)
84 // Assemble each line of package data for writing
85 // coreutils 6.9-2
86 $rel = rtrim(array_pop($vals));
87 $ver = rtrim(array_pop($vals));
88 $pkgname = rtrim(array_pop($vals));
90 $field_seperator = "\t";
91 $row_seperator = "\n";
93 $pkgver = $ver . $field_seperator . $rel;
94 $line = $pkgname . $field_seperator . $field_seperatorq. $pkgver . $row_seperator;
95 return $line;
98 main();