#!/usr/local/bin/php -q
<?php
/*****************************************************************

	Convert axfiles

****************************************************************/

	$ariadne="../lib";
	require_once($ariadne."/configs/ariadne.phtml");
	require_once($ariadne."/configs/store.phtml");
	require_once($ariadne."/configs/axstore.phtml");
	require_once($ariadne."/stores/mysqlstore.phtml");
	require_once($ariadne."/stores/axstore.phtml");
	require_once("ax_util/shared_functions.php");

	if ($argc>2) {
		$argv[1]=str_replace('\\', '/', $argv[1]);
		$argv[2]=str_replace('\\', '/', $argv[2]);
		$axfile=$argv[1];

		$tempdir=tempnam($store_config["files"]."temp", "axconvert");
		if (file_exists($tempdir)) {
			unlink($tempdir);
		}
		mkdir($tempdir, 0777);
		if (!untar($axfile, "", $tempdir)) {
			echo "error ($retvar) $error\n";
		} else {
			if (file_exists($tempdir."/nodes.data")) {
				echo "no convert needed\n";
				rm_dir($tempdir);
			} else {
					$obfp=fopen($tempdir."/objects.data","rb");
					if (!$obfp) {
						echo "error: can not open objects.data\n";
						rm_dir($tempdir);
					} else {
						$head=fread($obfp, strlen("O:6:\"object\""));
						fclose($obfp);
						rm_dir($tempdir);
						unset($tempdir);

						for ($i=1; $i<=2; $i++) {
							if ($argv[$i]!="/") {
								// relative, so do a '../' postfix
								$argv[$i]="../".$argv[$i];
							}
						}
						chdir("ax_util");
						if ($head=="O:6:\"object\"") {
							echo "ariadne 2b09 version\n";
							include("convert_b09");
						} else {
							echo "ariadne cvs version\n";
							include("convert_cvs");
						}
						chdir("..");
					}
			}
		}
	} else {
		echo "USAGE: axconvert [old_axfile] [new_axfile]\n";
	}
?>
