summaryrefslogtreecommitdiff
path: root/blasource.php
diff options
context:
space:
mode:
Diffstat (limited to 'blasource.php')
-rw-r--r--blasource.php45
1 files changed, 40 insertions, 5 deletions
diff --git a/blasource.php b/blasource.php
index 87c0872..f634584 100644
--- a/blasource.php
+++ b/blasource.php
@@ -8,8 +8,9 @@
// 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.
-
- $version = "BlaSource Version: 0.1.2";
+ // 0.2.0 Fixed -l so it shows 5 results. Added -c Count added -r remove and updated help
+
+ $version = "BlaSource Version: 0.2.0";
// get the input
$stdin = read_stdin();
@@ -20,8 +21,42 @@
{
switch ($stdin[$i])
{
+ case "-c":
+ //count
+ echo exec("cat blasource.txt | wc -l");
+ break;
+ case "-r":
+ if(!isset($stdin[$i+1]))
+ {
+ echo "Please specify the number to remove. [-r X]";
+ break;
+ }
+ //get line number
+ $lineToRemove = $stdin[$i+1];
+ $i++;
+
+ //remove line
+ $data = file_get_contents("blasource.txt");
+ $lines = explode(PHP_EOL,$data);
+ $lineNo = 1;
+ foreach($lines as $line)
+ {
+ if($lineNo != $lineToRemove && $line != "")
+ {
+ exec("echo $line >> blatemp.txt");
+ $lineNo++;
+ }
+ else
+ {
+ $stringRemove = $line;
+ $lineNo++;
+ }
+ }
+ exec("mv blatemp.txt blasource.txt");
+ echo "Removed line " . $lineToRemove . ": " . $stringRemove. ".";
+ break;
case "-l":
- $last = str_replace(":", "",exec("grep -n \"\" blasource.txt | tail -n 1")) / 5 + 1;
+ $last = str_replace(":", "",exec("grep -n \"\" blasource.txt | tail -n 1")) / 5;
$look = 0;
if(!isset($stdin[$i+1]))
{
@@ -44,7 +79,7 @@
$X = ($look*5)-5;
- for($j=0;$j<5;$j++)
+ for($j=0;$j<6;$j++)
{
$bla = $j+$X;
$temp = exec("grep -n \"\" blasource.txt | head -n" . $bla . " | tail -n1") . " ";
@@ -64,7 +99,7 @@
$i = sizeof($stdin);
break;
case "-h":
- $out = "-h for help, -v for version, -new <some-string-like-this> <someurl.html> e.g. !source -new gentoo-portage someurl.html. To view source:just enter a token <like-this-one> or <like this one> e.g. !source gentoo-portage or !source gentoo portage. -l will list the first page (5 records). -l X will show page X.";
+ $out = "-h for help, -v for version, -new <some-string-like-this> <someurl.html> e.g. !source -new gentoo-portage someurl.html. To view source:just enter a token <like-this-one> or <like this one> e.g. !source gentoo-portage or !source gentoo portage. -l will list the first page (5 records). -l X will show page X. -c returns count. -r X removes item X.";
$i = sizeof($stdin);
break;
default: