#! /usr/bin/perl use lib "lib"; use Odin; use DBI; use Encode; use Encode::Locale; use Getopt::Std; use POSIX; my $BAD = 0; sub bad ($) { my ($m) = @_; $BAD = 1; print STDERR "$Odin::PROG: $m\n"; } Odin::cmdline_who; sub read_content () { my $c = ""; while (read STDIN, my $buf, 8192) { $c .= $buf; } return Odin::tidy_pastebin_content decode locale => $c; } my $op = shift(@ARGV) // "help"; if ($op eq "help") { print <selectall_arrayref ("SELECT " . Odin::sql_timestamp($db, "stamp") . ", tag, lang, title FROM odin_pastebin WHERE owner = ? ORDER BY stamp", undef, $Odin::WHO)}) { my ($stamp, $tag, $lang, $title) = @$r; my $t = strftime "%Y-%m-%d %H:%M:%S %z", localtime $stamp; printf "%-25s %-12s %-16s %s\n", $t, $tag, $lang, encode locale => $title; } } elsif ($op eq "new") { my %o; getopts "l:t:", \%o and @ARGV == 0 or Odin::fail "usage: new [-l LANG] [-t TITLE]"; my %p = (title => decode(locale => $o{t}), lang => $o{l} // "txt", content => read_content); my $db = Odin::open_db; my $c = ""; while (read STDIN, my $buf, 8192) { $c .= $buf; } $p{content} = read_content; @{$db->selectall_arrayref ("SELECT lang FROM odin_pastebin_lang WHERE lang = ?", undef, $p{lang})} or Odin::fail "unknown language `$p{lang}'"; my ($tag, $edit) = Odin::new_pastebin %p; print "$Odin::PASTEBIN/$url $edit\n"; } elsif ($op eq "get") { @ARGV == 1 or Odin::fail "usage: get TAG"; my ($tag) = @ARGV; Odin::get_pastebin Odin::open_db, $tag, my %p; print encode locale => $p{content}; } elsif ($op eq "claim") { @ARGV == 2 or Odin::fail "usage: claim TAG EDITKEY"; my ($tag, $key) = @ARGV; Odin::claim_pastebin $tag, $key; } elsif ($op eq "rekey") { @ARGV == 1 or Odin::fail "usage: rekey TAG"; my ($tag) = @ARGV; my $key = Odin::rekey_pastebin $tag; print $key, "\n"; } elsif ($op eq "del") { @ARGV or Odin::fail "usage: del TAG ..."; Odin::delete_pastebin map { $_, undef } @ARGV; } elsif ($op eq "update") { my %o; getopts "cl:t:", \%o and @ARGV == 1 or Odin::fail "usage: update [-c] [-l LANG] [-t TITLE] TAG"; my ($tag) = @ARGV; my %p = (title => decode(locale => $o{t}), lang => $o{l}); if ($o{c}) { $p{content} = read_content; } Odin::update_pastebin $tag, undef, %p or Odin::fail "nothing changed"; } else { Odin::fail "unknown operation `$op'"; }