F

From Ghoulwiki
Revision as of 23:48, 20 September 2007 by Ghoulsblade (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#!/usr/bin/php
<?php

$gRedirectLists = array( // helpful for plugin folders
	array(
			"/cavern/wwwroot/scitestuff/robscite/scite/src",		
			"/cavern/wwwroot/scitestuff/robscite/scite/gtk",		
		),
	array(
			"/cavern/wwwroot/scitestuff/robscite",
			"/cavern/wwwroot/scitestuff/robscite/scite",
			"/cavern/wwwroot/scitestuff/robscite/scite/src",
			"/cavern/wwwroot/scitestuff/robscite/scite/gtk",
		),
	array(
			"/cavern/wwwroot/zw05",	
			"/cavern/wwwroot/zw05/info",	
		),
	array(
			"/cavern/wwwroot/sfz/writable/plugins",	
			"/cavern/wwwroot/sfz/writable/system",
			"/cavern/wwwroot/sfz/lua",
			"/cavern/wwwroot/sfz/src",
			"/cavern/wwwroot/sfz/include",
			"/cavern/wwwroot/sfz/mylugre/lua",
			"/cavern/wwwroot/sfz/mylugre/src",
			"/cavern/wwwroot/sfz/mylugre/include",
		),
	array(
			"/cavern/wwwroot/localsfz/data/plugins",	
			"/cavern/wwwroot/localsfz/data/lua",
			"/cavern/wwwroot/localsfz/data/system",
			"/cavern/wwwroot/localsfz/src",
			"/cavern/wwwroot/localsfz/include",
			"/cavern/wwwroot/localsfz/mylugre/lua",
			"/cavern/wwwroot/localsfz/mylugre/src",
			"/cavern/wwwroot/localsfz/mylugre/include",
		),
	array(
			"/cavern/wwwroot/iris/iris_ogre3d/data/lua/gui",
			"/cavern/wwwroot/iris/iris_ogre3d/data/lua/net",
			"/cavern/wwwroot/iris/iris_ogre3d/data/lua/obj",
			"/cavern/wwwroot/iris/iris_ogre3d/data/lua",
			"/cavern/wwwroot/iris/iris_ogre3d/src",
			"/cavern/wwwroot/iris/iris_ogre3d/include",
			"/cavern/wwwroot/iris/iris_ogre3d/mylugre/lua",
			"/cavern/wwwroot/iris/iris_ogre3d/mylugre/src",
			"/cavern/wwwroot/iris/iris_ogre3d/mylugre/include",
		),
	array(
			"/cavern/wwwroot/iris/knut/data/lua/gui",
			"/cavern/wwwroot/iris/knut/data/lua/net",
			"/cavern/wwwroot/iris/knut/data/lua/obj",
			"/cavern/wwwroot/iris/knut/data/lua",
			"/cavern/wwwroot/iris/knut/src",
			"/cavern/wwwroot/iris/knut/include",
		),
);



$curworkingdir = getcwd();
if (in_array($curworkingdir,array("/home/ghoul","/home/ghoul/Desktop"))) die("wrong working dir\n");
$dirlist = array();
$dirlist[] = $curworkingdir;
foreach ($gRedirectLists as $list) if (in_array($curworkingdir,$list)) foreach ($list as $dir) $dirlist[] = $dir;
$dirlist = array_unique($dirlist);

function does_not_have_parent($curdir) {
	global $dirlist;
	$curlen = strlen($curdir);
	foreach ($dirlist as $dir) {
		$len = strlen($dir);
		if ($len < $curlen && strncmp($dir,$curdir,$len) == 0) return false; // parent found
	}
	return true;
}
$dirlist = array_filter($dirlist, "does_not_have_parent");

if ($argc <= 2) {
	echo  "ERROR: missing file-name-pattern, if you really want to search in all files, please specify * as path-part explicitly\n";
	// system('grep -inr "'.$argv[1].'" '.$dir.' | tr -s " \t"');
	die;
}
foreach ($dirlist as $dir) {
	system('grep -inr --include "*'.$argv[2].'" "'.$argv[1].'" '.$dir.' | tr -s " \t"');
}

/*


if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {    $argv[0] is programname


$path = "/cavern/mukke/Sonata Arctica/The Collection/";
function dirfilelist ($path) {
	// plakat/  last slash is important !
	$list = array();
	if (!file_exists($path)) return $list;
	$dir = opendir($path);
	if (!$dir) return $list;
	while (($file = readdir($dir)) !== false)
		if ($file != "." && $file != ".." && is_file($path.$file)) $list[] = $file;
	closedir($dir);
	return $list;
}

$path = $path."/";
$arr = dirfilelist($path);
foreach ($arr as $filepath) {
	$a = strtr($filepath,array(" "=>"_","-"=>"_","'"=>"","("=>"_",")"=>"_"));
	echo $a." : $filepath\n";
	rename($path.$filepath,$path.$a);
}

function MyCommand ($cmd) {
	echo $cmd." : ";
	echo exec($cmd)."\n"; 
	sleep(2);
}
*/

/*
#!/bin/sh
# tr -s " \t"  fasst aufeinanderfolgende spaces und tabs zusammen
# less -S schneidet überlange zeilen ab
# inr : ignore-case , line-numbers , recursive 
# grep $2:  wenn als $2 ".php" übergeben wird, werden nur zeilen dargestellt die mit .php:zeilennummer:  anfangen.
if [ $# -gt 1 ]
	#then fgrep -inr "$1" . | grep "$2:" | tr -s " \t"
	#else fgrep -inr "$1" . | tr -s " \t"
	then grep -inr --include "*$2" "$1" . | tr -s " \t"
	else grep -inr "$1" . | tr -s " \t"
fi
*/
?>