pkg_tool dependency scanner for the gnome2 packages



As promised, ive code a quick&dirty tool that scans ./configure.in files for PKG_CHECK_MODULE tags, and extracts the package's dependencies that it defines.

This should give us a prety good and relativly complete start on defining dependencies for our .spec files, etc. Also, most of the time the info in these configure.in files is more acurate then what we use in .spec files.

The code is a horification become reality, i know... I thought 'simple' tokenized scanning would be enough to extract these tags, however the consitency in the configure.in files in how they define those pkg_check_modules is very poor, if present at all.

Thus i had to write a basic M4 code parser (weird dialect that is btw), which could detect variables, strings, comments, etc... It's nothing fancy, except that it has a basic knowledge of the tokens used in those M4 scripts, and what kind of comments / strings blocks it uses.

Since writing of this basic parsing took more time then expected, i decided to make a -clean- basic m4 parsing class (m4parser.php) with small pieces of comments and examples, so that could be reusable ;-) All the dirty work is done in a seperate file (generate.php).

A bit of cleaning will be required to clean up it's output and fix the last 2 mis-diagnostics of variable names, but its quite usable already.

Below is the output of the program, you can use this already to fill in the dependencies of the .spec files, and attached are the 2 PHP scripts which do the scanning. (Since coding time was a lot more sparse then CPU time, i decided to use a simple scripting language, so it eats all your CPU cycles for a couple of minutes, and use upto 5 megs of memory ;-)

Enjoy!


Parsing GConf-1.1.6..
 Loading configure.in.. OK.
 Extracting variables.. 52 found.
 Extracting PKG_CHECK_MODULES tags.. Found 5:

Requires:  gmodule >= 1.3.5
Requires:  gobject >= 1.3.5
Requires:  ORBit >= 2.3.94
Requires:  libxml
Requires:  gtk+


Parsing ORBit2-2.3.102..
 Loading configure.in.. OK.
 Extracting variables.. 18 found.
 Extracting PKG_CHECK_MODULES tags.. Found 5:

Requires:  linc >= 0.1.12
Requires:  glib >= 1.3.10
Requires:  gobject >= 1.3.10
Requires:  gmodule >= 1.3.10
Requires:  libIDL >= 0.7.0


Parsing at-spi-0.0.5..
 Loading configure.in.. OK.
 Extracting variables.. 25 found.
 Extracting PKG_CHECK_MODULES tags.. Found 5:

Requires:  libbonobo >= 1.107.0
Requires:  atk >= 0.2
Requires:  gtk+ >= 1.3.2
Requires:  gail
Requires:  gdk-pixbuf >= 1.3.0


Parsing atk-0.9..
 Loading configure.in.. OK.
 Extracting variables.. 25 found.
 Extracting PKG_CHECK_MODULES tags.. Found 3:

Requires:  glib >= 1.3.12
Requires:  gobject
Requires:  gmodule


Parsing audiofile-0.2.3..
 Loading configure.in.. OK.
 Extracting variables.. 10 found.
 Extracting PKG_CHECK_MODULES tags..   Non found.



Parsing bonobo-activation-0.9.3..
 Loading configure.in.. OK.
 Extracting variables.. 25 found.
 Extracting PKG_CHECK_MODULES tags.. Found 4:

Requires:  gmodule >= 1.3.1
Requires:  ORBit >= 2.3.91
Requires:  ORBit-CosNaming >= 2.3.91
Requires:  libxml >= 2.2.8


Parsing bug-buddy-2.1.2..
 Loading configure.in.. OK.
 Extracting variables.. 9 found.
 Extracting PKG_CHECK_MODULES tags.. Found 7:

Requires:  gdk-pixbuf >= 1.3.9
Requires:  gnome-vfs >= 1.9.1
Requires:  libgnome >= 1.104.0
Requires:  libgnomecanvas >= 1.104.0
Requires:  libgnomeui >= 1.104.0
Requires:  libglade >= 1.99.2
Requires:  libxml >= 2.4.6


Parsing control-center-1.99.0..
 Loading configure.in.. OK.
 Extracting variables.. 31 found.
 Extracting PKG_CHECK_MODULES tags.. Found 9:

Requires:  gtk+
Requires:  gconf
Requires:  libgnomeui
Requires:  libglade
Requires:  libbonobo
Requires:  libbonoboui
Requires:  libxml
Requires:  gnome-desktop
Requires:  esound


Parsing control-center-plus-1.99.0..
 Loading configure.in.. OK.
 Extracting variables.. 19 found.
 Extracting PKG_CHECK_MODULES tags.. Found 9:

Requires:  libgnomeui
Requires:  libgnomecanvas
Requires:  libglade
Requires:  gnome-desktop
Requires:  gtk+
Requires:  libbonobo
Requires:  gnome-vfs-module
Requires:  gnome-vfs
Requires:  glib


Parsing eel-1.1.2..
 Loading configure.in.. OK.
 Extracting variables.. 28 found.
 Extracting PKG_CHECK_MODULES tags.. Found 10:

Requires:  gconf >= 1.1.5
Requires:  gdk-pixbuf >= 1.3.9
Requires:  glib >= 1.3.9
Requires:  gnome-vfs >= 1.1
Requires:  gtk+ >= 1.3.9
Requires:  libart >= 2.3.8
Requires:  libgnome >= 1.108.0
Requires:  libgnomecanvas >= 1.108.0
Requires:  libgnomeui >= 1.108.0
Requires:  libxml >= 2.2.8


Parsing eog-0.109.1..
 Loading configure.in.. OK.
 Extracting variables.. 28 found.
 Extracting PKG_CHECK_MODULES tags..   Non found.



Parsing esound-0.2.23..
 Loading configure.in.. OK.
 Extracting variables.. 26 found.
 Extracting PKG_CHECK_MODULES tags..   Non found.



Parsing gail-0.5..
 Loading configure.in.. OK.
 Extracting variables.. 27 found.
 Extracting PKG_CHECK_MODULES tags.. Found 3:

Requires:  atk >= 0.7
Requires:  gtk+ >= 1.3.11
Requires:  libgnomecanvas >= 1.105.0


Parsing gdm-2.3.90.1..
 Loading configure.in.. OK.
 Extracting variables.. 71 found.
 Extracting PKG_CHECK_MODULES tags.. Found 5:

Requires:  gdk-pixbuf >= 1.3.1
Requires:  gtk+ >= 1.3.1
Requires:  libgnome >= 1.96.0
Requires:  libgnomeui >= 1.96.0
Requires:  libglade >= 1.99.2


Parsing gedit2-1.109.1..
 Loading configure.in.. OK.
 Extracting variables.. 6 found.
 Extracting PKG_CHECK_MODULES tags.. Found 3:

Requires:  libgnomeui >= 1.106.0
Requires:  libglade >= 1.99.2
Requires:  libgnomeprintui >= 1.106.0


Parsing glib-1.3.12..
 Loading configure.in.. OK.
 Extracting variables.. 120 found.
 Extracting PKG_CHECK_MODULES tags..   Non found.



Parsing gnome-applets-1.90.1..
 Loading configure.in.. OK.
 Extracting variables.. 29 found.
 Extracting PKG_CHECK_MODULES tags.. Found 11:

Requires:  libpanelapplet
Requires:  libgnome >= 1.108.0
Requires:  libgnomeui >= 1.108.0
Requires:  libxml >= 2.4.11
Requires:  gnome-vfs >= 1.9.4
Requires:  gconf >= 1.1.5
Requires:  libgtop >= 1.90.0
Requires:  gdk-pixbuf >= 1.3.11
Requires:  libgnomecanvas >= 1.108.0
Requires:  gtk+ >= 1.3.11
Requires:  libwnck-1.0 >= 0.1


Parsing gnome-common-1.2.4..
 Loading configure.in.. OK.
 Extracting variables.. Non found?


Parsing gnome-core-1.5.4..
 Loading configure.in.. OK.
 Extracting variables.. 40 found.
 Extracting PKG_CHECK_MODULES tags.. Found 9:

Requires:  ORBit >= 2.3.91
Requires:  gdk-pixbuf >= 1.3.1
Requires:  gtk+ >= 1.3.1
Requires:  libgnomeui >= 1.96.0
Requires:  libwnck-1.0 >= 0.1
Requires:  libglade >= 1.99.2
Requires:  gnome-vfs-module >= 1.9.3
Requires:  libgnomecanvas >= 1.102.0
Requires:  libzvt >= 1.97.0


Parsing gnome-games-1.90.1..
 Loading configure.in.. OK.
 Extracting variables.. 8 found.
 Extracting PKG_CHECK_MODULES tags.. Found 3:

Requires:  libgnome >= 1.105.0
Requires:  libgnomeui >= 1.105.0
Requires:  gconf >= 1.1.5


Parsing gnome-utils-1.97.0..
 Loading configure.in.. OK.
 Extracting variables.. 37 found.
 Extracting PKG_CHECK_MODULES tags.. Found 9:

Requires:  libgnome >= 1.107.0
Requires:  libgnomeui >= 1.107.0
Requires:  gnome-vfs >= 1.9.3
Requires:  libglade >= 1.99.2
Requires:  libbonoboui >= 1.103.0
Requires:  libxml >= 2.2.8
Requires:  gconf >= 1.1.2
Requires:  gtkhtml >= 0.0.0
Requires:  libpanelapplet >= 1.5.2


Parsing gnome-vfs-1.9.4..
 Loading configure.in.. OK.
 Extracting variables.. 57 found.
 Extracting PKG_CHECK_MODULES tags.. Found 9:

Requires:  glib >= 1.3.9
Requires:  gmodule >= 1.3.9
Requires:  gthread >= 1.3.9
Requires:  libbonobo >= 1.97.0
Requires:  gconf >= 1.1
Requires:  bonobo-activation >= 0.9.1
Requires:  ORBit >= 2.3.90
Requires:  libxml >= 2.2.8
Requires:  gnome-mime-data


Parsing gtk+-1.3.12..
 Loading configure.in.. OK.
 Extracting variables.. 149 found.
 Extracting PKG_CHECK_MODULES tags.. Found 3:

Requires:  glib >= 1.3.12
Requires:  atk >= 0.8
Requires:  pango >= 0.23


Parsing libIDL-0.7.2..
 Loading configure.in.. OK.
 Extracting variables.. 12 found.
 Extracting PKG_CHECK_MODULES tags.. Found 1:

Requires:  glib >= 1.3.7


Parsing libart_lgpl-2.3.8..
 Loading configure.in.. OK.
 Extracting variables.. 13 found.
 Extracting PKG_CHECK_MODULES tags..   Non found.



Parsing libbonobo-1.109.0..
 Loading configure.in.. OK.
 Extracting variables.. 15 found.
 Extracting PKG_CHECK_MODULES tags.. Found 6:

Requires:  ORBit >= 2.3.100
Requires:  ORBit-CosNaming >= 2.3.100
Requires:  glib >= 1.3.11
Requires:  gobject >= 1.3.11
Requires:  gthread >= 1.3.11
Requires:  bonobo-activation >= 0.9.3


Parsing libbonoboui-1.109.2..
 Loading configure.in.. OK.
 Extracting variables.. 3 found.
 Extracting PKG_CHECK_MODULES tags.. Found 4:

Requires:  libgnomecanvas >= 1.109.
Requires:  libbonobo >= 1.109.
Requires:  \
Requires:  libglade >= 1.99.5


Parsing libglade-0.17..
 Loading configure.in.. OK.
 Extracting variables.. 10 found.
 Extracting PKG_CHECK_MODULES tags..   Non found.



Parsing libglade-1.99.5..
 Loading configure.in.. OK.
 Extracting variables.. 4 found.
 Extracting PKG_CHECK_MODULES tags.. Found 3:

Requires:  libxml >= 2.4.10
Requires:  atk >= 0.7
Requires:  gtk+ >= 1.3.11


Parsing libgnome-1.109.1..
 Loading configure.in.. OK.
 Extracting variables.. 21 found.
 Extracting PKG_CHECK_MODULES tags.. Found 9:

Requires:  esound >= .2.23
Requires:  audiofile >= .2.2
Requires:  glib >= 1.3.12
Requires:  gmodule >= 1.3.12
Requires:  gnome-vfs >= 1.9.3
Requires:  libxml >= 2.4.12
Requires:  libbonobo >= 1.109.0
Requires:  gconf >= 1.1.1
Requires:  gnome-vfs-module >= 1.9.3


Parsing libgnomecanvas-1.109.0..
 Loading configure.in.. OK.
 Extracting variables.. 7 found.
 Extracting PKG_CHECK_MODULES tags.. Found 5:

Requires:  gtk+ >= 1.3.12
Requires:  libart >= 2.3.8
Requires:  pango >= .23
Requires:  pangoft2 >= .23
Requires:  libglade >= 1.99.3


Parsing libgnomeprint-1.109.1..
 Loading configure.in.. OK.
 Extracting variables.. 18 found.
 Extracting PKG_CHECK_MODULES tags.. Found 7:

Requires:  glib >= 1.3.10
Requires:  gobject >= 1.3.10
Requires:  gmodule >= 1.3.10
Requires:  libart >= 2.3.7
Requires:  pango >= 0.21
Requires:  libxml >= 2.4.7
Requires:  libbonobo >= 1.106.0


Parsing libgnomeprintui-1.109.1..
 Loading configure.in.. OK.
 Extracting variables.. 2 found.
 Extracting PKG_CHECK_MODULES tags.. Found 2:

Requires:  libgnomeprint >= 1.109.1
Requires:  libgnomecanvas >= 1.109.0


Parsing libgnomeui-1.109.0..
 Loading configure.in.. OK.
 Extracting variables.. 21 found.
 Extracting PKG_CHECK_MODULES tags.. Found 8:

Requires:  esound >= .2.23
Requires:  audiofile >= .2.2
Requires:  libgnome >= 1.108.
Requires:  libgnomecanvas >= 1.108.
Requires:  libbonoboui >= 1.108.1
Requires:  gconf >= 1.1.1
Requires:  gnome-vfs-module >= 1.9.3
Requires:  libglade >= 1.99.5


Parsing libgtkhtml-1.99.2..
 Loading configure.in.. OK.
 Extracting variables.. 4 found.
 Extracting PKG_CHECK_MODULES tags.. Found 4:

Requires:  gtk+ >= 1.3.9
Requires:  libxml >= 2.4.1
Requires:  gnome-vfs >= 1.9.1
Requires:  gail >= 0.0.3


Parsing libgtop-1.90.1..
 Loading configure.in.. OK.
 Extracting variables.. 69 found.
 Extracting PKG_CHECK_MODULES tags.. Found 1:

Requires:  glib >= 1.3.10


Parsing librep-0.15.2..
 Loading configure.in.. OK.
 Extracting variables.. 53 found.
 Extracting PKG_CHECK_MODULES tags..   Non found.



Parsing librsvg-1.1.1..
 Loading configure.in.. OK.
 Extracting variables.. 16 found.
 Extracting PKG_CHECK_MODULES tags.. Found 5:

Requires:  gdk-pixbuf >= 1.3.7
Requires:  glib >= 1.3.1
Requires:  libart >= 2.3.8
Requires:  libxml >= 2.2.8
Requires:  pangoft2 >= 0.22


Parsing libwnck-0.2..
 Loading configure.in.. OK.
 Extracting variables.. 12 found.
 Extracting PKG_CHECK_MODULES tags.. Found 1:

Requires:  gtk+ >= 1.3.9


Parsing libzvt-1.109.0..
 Loading configure.in.. OK.
 Extracting variables.. 3 found.
 Extracting PKG_CHECK_MODULES tags.. Found 4:

Requires:  glib >= 1.3.11
Requires:  gmodule >= 1.3.11
Requires:  gtk+ >= 1.3.11
Requires:  libart >= 2.3.5


Parsing linc-0.1.15..
 Loading configure.in.. OK.
 Extracting variables.. 23 found.
 Extracting PKG_CHECK_MODULES tags.. Found 3:

Requires:  glib >= 1.3.11
Requires:  gobject >= 1.3.11
Requires:  gthread >= 1.3.11


Parsing metatheme-0.9.1..
 Loading configure.in.. OK.
 Extracting variables.. 8 found.
 Extracting PKG_CHECK_MODULES tags.. Found 4:

Requires:  libgnomeui
Requires:  libglade
Requires:  libgnomecanvas
Requires:  "gconf"


Parsing nautilus-1.1.2..
 Loading configure.in.. OK.
 Extracting variables.. 52 found.
 Extracting PKG_CHECK_MODULES tags.. Found 15:

Requires:  esound >= 0.2.23
Requires:  bonobo-activation >= 0.9.3
Requires:  eel >= 1.1.1
Requires:  glib >= 1.3.10
Requires:  gnome-vfs >= 1.1
Requires:  gtk+ >= 1.3.10
Requires:  libart >= 2.3.6
Requires:  libbonobo >= 1.108
Requires:  libbonoboui >= 1.108.1
Requires:  libgnome >= 1.105
Requires:  libgnomecanvas >= 1.105
Requires:  libgnomeui >= 1.105
Requires:  librsvg >= 1.1
Requires:  libxml >= 2.4.6
Requires:  medusa >= 0.5.1


Parsing nautilus-mozilla-1.1.1..
 Loading configure.in.. OK.
 Extracting variables.. 43 found.
 Extracting PKG_CHECK_MODULES tags.. Found 8:

Requires:  eel >= 1.1.1
Requires:  gconf >= 1.1.3
Requires:  glib >= 1.3.10
Requires:  gnome-vfs >= 1.1
Requires:  gtk+ >= 1.3.10
Requires:  libgnome >= 1.105
Requires:  libgnomeui >= 1.105
Requires:  libnautilus >= 1.1.1


Parsing nautilus-mozilla-1.1.2..
 Loading configure.in.. OK.
 Extracting variables.. 43 found.
 Extracting PKG_CHECK_MODULES tags.. Found 8:

Requires:  eel >= 1.1.1
Requires:  gconf >= 1.1.3
Requires:  glib >= 1.3.10
Requires:  gnome-vfs >= 1.1
Requires:  gtk+ >= 1.3.10
Requires:  libgnome >= 1.105
Requires:  libgnomeui >= 1.105
Requires:  libnautilus >= 1.1.1


Parsing pango-0.23..
 Loading configure.in.. OK.
 Extracting variables.. 49 found.
 Extracting PKG_CHECK_MODULES tags..   Non found.



Parsing procman-1.1.2..
 Loading configure.in.. OK.
 Extracting variables.. 9 found.
 Extracting PKG_CHECK_MODULES tags.. Found 6:

Requires:  libgnome >= 1.108.0
Requires:  libgnomeui >= 1.108.0
Requires:  gconf >= 1.1.5
Requires:  libgtop >= 1.90.0
Requires:  libwnck-1.0 >= 0.1
Requires:  gtk+ >= 1.3.11


Parsing rep-gtk..
 Loading configure.in.. OK.
 Extracting variables.. 7 found.
 Extracting PKG_CHECK_MODULES tags.. Found 4:

Requires:  glib >= 1.3
Requires:  gtk+ >= 1.3
Requires:  libglade >= 1.99
Requires:  gdk-pixbuf >= 1.3.11


Parsing sawfish..
 Loading configure.in.. OK.
 Extracting variables.. 41 found.
 Extracting PKG_CHECK_MODULES tags.. Found 4:

Requires:  gdk-pixbuf-xlib >= 1.3.12
Requires:  imlib >= 1.9.12
Requires:  audiofile >= 0.2.3
Requires:  esound >= 0.2.23


Parsing yelp-0.1..
 Loading configure.in.. OK.
 Extracting variables.. 8 found.
 Extracting PKG_CHECK_MODULES tags.. Found 4:

Requires:  libgtkhtml >= 1.99.2
Requires:  gnome-vfs >= 1.1
Requires:  libgnomeui >= 1.103.0
Requires:  libbonobo >= 1.108.0




#!/usr/local/bin/php -q
<?
// Copyright 2002, Chris Chabot
// Released under the GNU Public Licence

include("./m4parser.php");

class gnome2parser extends m4parser
{
  var $variables   = array();
  var $next_is_def = FALSE;
  var $what        = '';
  var $value       = '';
  
  
  function ProcessToken($token,$type,$seperator,$line)
  {
	if ($seperator == '=' && $type != 'comment' && $type != 'string' && $token != '') {
	  $this->next_is_def = TRUE;
	  $this->what = $token;
	} elseif ($this->next_is_def && ($seperator == "\n" || $seperator == ';')) {
	  $this->next_is_def = FALSE;
	  $this->value .= $token;
	  // Remove the cruft i didnt feel like parsing inteligently
	  $this->value = str_replace('"','',$this->value);
	  $this->value = str_replace('\'','',$this->value);
	  $this->value = str_replace('(','',$this->value);
	  $this->value = str_replace(')','',$this->value);
	  $this->value = str_replace('}','',$this->value);
	  $this->value = str_replace('{','',$this->value);
	  $this->value = trim($this->value);
	  if (!isset($this->variables[$this->what])) {
		$this->variables[$this->what] = $this->value;
	  }
	  // echo "$this->what  =  $this->value\n";
	  $this->what        = '';
	  $this->value       = '';
	} elseif ($this->what) {
	  $this->value .= $token.$seperator;
	}
  }
  
  
  function Condense()
  {
	reset($this->variables);
	while (list($var,$val) = each($this->variables)) {
	  if ((strpos($val,'$')) !== FALSE) {
		$pos   = strlen($val);
		$found = '';
		$tmp   = substr($val,strpos($val,'$')+1);
		reset($this->tokens);
    	while (list($key,$token) = each($this->tokens)) {
	  	  $newpos = strpos($tmp,$token);
		  if (($newpos !== false) && ($newpos < $pos)) {
			$pos   = $newpos;
			$found = $token;
		  }
		}
		$token = substr($tmp,0,$pos);
		if (!isset($this->variables[$token])) {
		  $this->variables[$token] = 'EXTERNAL';
		}
		$replace = '$'.$token;
		if ($found) {
		  $replace .= $found;
		}
		// echo "Replacing [$replace] with [{$this->variables[$token]}] for $var\n";
		$this->variables[$var] = str_replace($replace,$this->variables[$token]." ",$this->variables[$var]);
	  }
	}
  }
}  



function parse_file($file_name,$package_name)
{
  echo "Parsing $package_name..\n";
  echo "  Loading configure.in.. "; flush();
  if (!$file_buffer = file($file_name)) {
	echo "no configure.in found!\n";
	return;
  } else {
	echo "OK.\n";
  }

  echo "  Extracting variables.. "; flush();
  // create a parser->variables lookup table
  $parser = new gnome2parser($file_buffer);
  $parser->Process();
  $parser->Condense();
  if ($var_cnt = count($parser->variables)) {
	echo "$var_cnt found.\n";
  } else {
	echo "Non found?\n";
	return;
  }

  echo "  Extracting PKG_CHECK_MODULES tags.. ";
  $line = str_replace("\n"," ",implode('',$file_buffer));
  $pkg_list = '';
  while (($pos = strpos($line,'PKG_CHECK_MODULES')) !== FALSE) {
	// remove everything upto and including PCK_CHECK tag
	$line = substr($line,$pos+strlen('PKG_CHECK_MODULES')+1);
	$pkgs = $line;
	// remove the "module_name," part
	$trim = strpos($pkgs,',');
	$pkgs = substr($pkgs,$trim+1);
	$end  = strpos($pkgs,')');
	$pkgs = trim(str_replace('\\','',substr($pkgs,0,$end)));
	// remove extra params from tag (such as custom messages etc)
	$extra = strpos($pkgs,',');
	if ($extra) {
	  $pkgs = substr($pkgs,0,$extra);
	}
	while (($pos = strpos($pkgs,'$')) !== FALSE) {
	  $tmp = substr($pkgs,$pos+1);
	  if (($endpos = strpos($tmp,' ')) !== FALSE) {
	    $var = substr($tmp,0,$endpos);
	  } else {
		$var = $tmp;
	  }
	  $var = str_replace('[','',$var);
	  $var = str_replace(']','',$var);

	  if (isset($parser->variables[$var])) {
		$value = $parser->variables[$var];
	  } else {
		echo "Warning: $var is not defined. ";
		$value = ' ';
	  }
	  $pkgs = str_replace('$'.$var,$value,$pkgs);
	}
	//remove any final leftover cruft
	$pkgs = str_replace('[','',$pkgs);
	$pkgs = str_replace(']','',$pkgs);
	$pkgs = str_replace("\n",'',$pkgs);
	$pkgs = str_replace("\r",'',$pkgs);
	$pkgs = str_replace("\t",'',$pkgs);
	$pkgs = str_replace('-2.0','',$pkgs);
	$pkgs = str_replace('-2.','',$pkgs);
	$pkgs = str_replace(' >= ','>=',$pkgs);
	while ($pkgs != str_replace('  ',' ',$pkgs)) {
	  $pkgs = str_replace('  ',' ',$pkgs);
	}
	if ($pkg_list) $pkg_list .= " ";
	$pkg_list .= trim($pkgs);
  }
  if ($pkg_list) {
	$pkgs = array();
	$pkg_list = explode(" ",$pkg_list);
	while (list(,$entry) = each($pkg_list)) {
	  if (strpos($entry,'>=') !== FALSE) {
		$pkg = substr($entry,0,strpos($entry,'>='));
		$ver = substr($entry,strpos($entry,'>=')+2);
	  } else {
		$pkg = $entry;
		$ver = '';
	  }
	  if (!isset($pkgs[$pkg])) {
		$pkgs[$pkg] = $ver;
	  }
	}
	echo "Found ".count($pkgs).":\n";
	reset($pkgs);
	while (list($pkg,$ver) = each($pkgs)) {
	  echo "\nRequires:  $pkg";
	  if ($ver) {
		echo " >= $ver";
	  }
	}
  } else {
	echo "  Non found.\n";
  }
  echo "\n";
}


function main()
{
  $dh = opendir(".");
  while ($dir = readdir($dh)) {
	if (is_dir($dir) && $dir != '.' && $dir != '..') {
	  parse_file($dir."/configure.in",$dir);
	  echo "\n\n"; flush();
	}
  }
  closedir($dh);
//  parse_file("./gnome-applets-1.90.1/configure.in","gnome-applets-1.90.1");
}


main();


?>
<?
// Copyright 2002, Chris Chabot
// Released under the GNU Public Licence


class m4parser {
  var $file_array = array();
  var $string = '';

  // Tokens defines the strings on which the parses searches the input buffer
  // these include operands (such as + and -), block statements (such as { and }) and
  // any other language constructs that sepparate commands
  // When modifying, keep in mind that order matters! forinstance if you would 
  // include '=','==' .. it would never find the '==' since it will always find the '='
  // first, so include tokens from largest (ie ===) to smallest (ie =)

  // WOOPS: ' is not a string identifier in m4 ;-) removed

  var $tokens = array('>=','dnl',"\r\n","\t","\r",'::','#',' ',';','(',')',',','===','!==','==','!=','!','.',
					  '"','++','--','[',']','->','>','<=','=<','=>','>=','>>','<<',
					  '<','>','-','+','&&','||','&','|','{','}',"\n",'$','=');

  // initialise the internal buffers, fill them with the input file, and strip comments
  // filling in the flat string w/o comments into $string, ready for processing

  function m4parser($file_buffer,$debug = false)
  {
	if (!method_exists($this,'ProcessToken')) {
	  die("Please Inherit the m4parser class, and create a function\n".
		  "   ProcessToken($p_token,$type,$seperator)\n".
		  "in the inheriting class.\n".
		  "  Token is the current 'word' being parsed\n".
		  "  type is either string or m4.\n");
	}
	$this->file_array = $file_buffer;
	while (list($key,$string) = each($this->file_array)) {
	  while (($new_string = str_replace('  ',' ',$string)) != $string) {
	    $string = $new_string;
	  }
	  $this->string .= trim($string)."\n";
	  unset($new_string);
	}
  }


  // This function takes the $string buffer, and parses it, calling 
  // ProcessToken on every found 'token'.
  function Process()
  {
	$words       = 0;
	$line        = 1;
	$in_dstring  = false;
	$in_sstring  = false;
	$in_comment  = false;
	
	$word        = '';
	$str         = $this->string;
	while (strlen($str)) {
	  if ($word) $prev_word = $word;
	  $pos = strlen($str);
	  $found  = '';
	  $newpos = false;
	  reset($this->tokens);
	  while (list($key,$token) = each($this->tokens)) {
		$newpos = strpos($str,$token);
		if (($newpos !== false) && ($newpos < $pos)) {
		  $pos   = $newpos;
		  $found = $token;
		}
	  }
	  if ($pos !== false) {
		$word = substr($str,0,$pos);
	    $str  = substr($str,$pos + strlen($found));
	  } else {
	    // force an end of loop on last part of string
	    $word = $str;
	  }
	  $words++;
	  $html     = '';
	  $string   = '';
	  $m4       = '';
	  $comment  = '';
	  
	  if (!$in_comment && !$in_sstring && $found == '"') {
		if (substr($word,strlen($word)-1) != "\\") {
		  $in_dstring = !$in_dstring;
		  if (!$in_dstring) $string = $word;
		}
		
	  } elseif (!$in_comment && !$in_dstring && $found == '[') {
		$in_sstring = TRUE;
	  } elseif ($in_sstring && $found == ']') {
		$string     = $word;
		$in_sstring = FALSE;

	  } elseif ($found == "\n" || $found == "\r" || $found == "\r\n") {
		$line++;
		if ($in_comment) {
		  $in_comment = false;
		  $comment    = $word;
		  $word       = '';
		}
		
	  } elseif (($found == '#' || $found == 'dnl') && !$in_sstring && !$in_dstring && !$in_comment) {
		$in_comment = true;
		$comment     = $word;
		$word        = '';
	  }

	  if (!$m4 && !$string && !$comment) {
		if ($in_sstring || $in_dstring) {
		  $string   = $word;
		  $p_type   = 'string';
		} elseif ($in_comment) {
		  $comment  = $word;
		  $p_type   = 'comment';
		} else {
		  $m4    = $word;
		  $p_type = 'm4';
		}
	  }
	  
	  if ($string) {
	    $p_token = $string;
	  } elseif ($comment) {
		$p_token = $comment;
	  } else {
		$p_token = $m4;
	  }
	  $this->ProcessToken($p_token,$p_type,$found,$line);
	}
	// return the amount of tokens processed
	return $words;
  }
}


// Demo class that shows how to use the ProcessTokens
// This simply dumps all seperators and tokens
// This example only outputs m4 code, not strings.
// This to make the output more clear to understand
// To use this example, create a php program which does:
//
//    $class = new m4DumpTokens('./myfile.m4');
//    $class->Process();
//
class m4DumpTokens extends m4parser {

  function ProcessToken($token,$type,$seperator,$line)
  {
	$seperator = addslashes($seperator);
	if ($type == 'm4') {
	  echo "[$line $seperator] $token\n";
	}
  }
}


?>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]