// Version History // 0.0.1 Created blasource.php // 0.1.0 Added -l option for listing for sources. // 0.1.1 Fixed -l option for listing for sources. // 0.1.2 Checked -l page number to see if there are any results. // 0.2.0 Fixed -l so it shows 5 results. Added -c Count added -r remove and updated help // 0.2.1 Fixed -l (showing too many results) and -r (Not showing text of removed line // 0.2.2 Changed -new to --add // 0.2.3 Updated help added --WORD to all -? parameters. $version = "BlaSource Version: 0.2.3"; // get the input $stdin = read_stdin(); $stdin = explode(" ", $stdin); $out = ""; $token = ""; for ($i=0 ; $i> blatemp.txt"); $lineNo++; } else if ($line != "") { $stringRemove = $line; $lineNo++; } } exec("mv blatemp.txt blasource.txt"); echo "Removed line " . $lineToRemove . ": " . $stringRemove. "."; break; case "-l": case "--list": $last = str_replace(":", "",exec("grep -n \"\" blasource.txt | tail -n 1")) / 5 + 1; $page = 0; if(!isset($stdin[$i+1])) { $page = 1; } else { if($stdin[$i+1] > $last) { echo "No more source found."; $i++; break; } else { $page = $stdin[$i+1]; $i++; } } $X = ($page*5)-5; for($j=1;$j<6;$j++) { $bla = $j+$X; $temp = exec("grep -n \"\" blasource.txt | head -n" . $bla . " | tail -n1") . " "; $out .= $temp; } break; case "--add": case "-a": $name = $stdin[$i+1]; $link = $stdin[$i+2]; $file_handle = fopen("blasource.txt", "rb"); exec ("echo $name $link >> blasource.txt"); $out = $name . ": " . $link . " added."; $i = sizeof($stdin); break; case "-v": case "--version" $out = $version; $i = sizeof($stdin); break; case "-h": case "--help": $out = "-h|--help for help, -v|--version for version, --add (-a) e.g. !source --add(-a) gentoo-portage someurl.html. To view source:just enter a token or e.g. !source gentoo-portage or !source gentoo portage. -l will list the first page (5 records). -l|--list X will show page X. -c --count returns count. -r --remove X removes item X."; $i = sizeof($stdin); break; default: for($j=$i;$j1) { if($parts[0] == $token) { $out = $parts[0] . ": " . $parts[1]; break; } $out = "No Source Found!"; } } fclose($file_handle); break; } } echo $out . "\n"; function read_stdin() { $fr=fopen("php://stdin","r"); // open our file pointer to read from stdin $input = fgets($fr,128); // read a maximum of 128 characters $input = rtrim($input); // trim any trailing spaces. fclose ($fr); // close the file handle return $input; // return the text entered } ?>