You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-overlay/profiles/patches/app-text/wgetpaste-2.17-18-calculate...

214 lines
8.8 KiB

diff --git a/wgetpaste b/wgetpaste
index 00eea19..7bb9998 100755
--- a/wgetpaste
+++ b/wgetpaste
@@ -6,6 +6,8 @@
VERSION="2.17"
+DEFAULT_SERVICE="calculate"
+
# don't inherit LANGUAGE from the env
unset LANGUAGE
@@ -14,7 +16,7 @@ E=$'\e'
N=$'\n'
### services
-SERVICES="ca codepad dpaste osl pocoo"
+SERVICES="ca codepad dpaste osl pocoo calculate"
# ca
ENGINE_ca=ca
URL_ca="http://pastebin.ca/"
@@ -35,6 +37,17 @@ URL_osl="http://pastebin.osuosl.org/ pastebin.php"
# pocoo
ENGINE_pocoo=pocoo
URL_pocoo="http://paste.pocoo.org/"
+# calculate
+ENGINE_calculate=calculate
+if [[ "$LANG" =~ 'ru_RU' ]]; then
+ URL_calculate="http://pastebin.calculate-linux.ru"
+else
+ URL_calculate="http://pastebin.calculate-linux.org"
+fi
+DEFAULT_LANGUAGE_calculate="Text"
+DEFAULT_PARENT_calculate=""
+DEFAULT_PRIVATE_calculate=0
+SIZE_calculate="25000 25%kB"
# tinyurl
ENGINE_tinyurl=tinyurl
URL_tinyurl="http://tinyurl.com/ api-create.php"
@@ -49,7 +62,7 @@ LANGUAGE_COUNT_ca=0
EXPIRATIONS_ca="Never 5%minutes 10%minutes 15%minutes 30%minutes 45%minutes 1%hour 2%hours \
4%hours 8%hours 12%hours 1%day 2%days 3%days 1%week 2%weeks 3%weeks 1%month 2%months \
3%months 4%months 5%months 6%months 1%year"
-POST_ca="s=Submit+Post name description type expiry % content"
+POST_ca="s=Submit+Post name description type expiry % % content"
REGEX_URL_ca='s|^.*content="[0-9]*;\(http://[^/]*/[0-9]*\)".*$|\1|p'
REGEX_RAW_ca='s|^\(http://[^/]*/\)\([0-9]*\)$|\1raw/\2|'
# codepad
@@ -64,7 +77,7 @@ LANGUAGE_VALUES_dpaste="% Apache Bash Css Diff DjangoTemplate Haskell JScript Py
Ruby Rhtml Sql Xml"
EXPIRATIONS_dpaste="30%days 30%days%after%last%view"
EXPIRATION_VALUES_dpaste="off on"
-POST_dpaste="submit=Paste+it poster title language hold % content"
+POST_dpaste="submit=Paste+it poster title language hold % % content"
REGEX_RAW_dpaste='s|^\(http://[^/]*/\)[^0-9]*\([0-9]*/\)$|\1\2plain/|'
# osl
LANGUAGES_osl="Plain%Text ActionScript Ada Apache%Log%File AppleScript Assembly%(NASM) \
@@ -78,7 +91,7 @@ javascript lisp lua matlab mpasm mysql nsis objc ocaml oobas oracle8 pascal perl
qbasic robots ruby scheme smarty sql tcl vb vbnet visualfoxpro xml"
EXPIRATIONS_osl="Never 1%day 1%month"
EXPIRATION_VALUES_osl="f d m"
-POST_osl="paste=Send poster % format expiry % code2"
+POST_osl="paste=Send poster % format expiry % % code2"
REGEX_RAW_osl='s|^\(http://[^/]*/\)\([0-9]*\)$|\1pastebin.php?dl=\2|'
# pocoo
LANGUAGES_pocoo="Apache%Config%(.htaccess) Bash Batch%(.bat) Boo C C# C++ Clojure Creole%Wiki CSS \
@@ -93,9 +106,25 @@ dylan erlang rhtml gas gcc-messages html+genshi gettext glsl haskell html ini ir
javac-messages js jsp lighttpd literate-haskell llvm lua html+mako matlab matlabsession minid multi \
html+myghty mysql nasm nginx objectpascal ocaml perl html+php php povray python pycon pytb rst ruby \
scala scheme smalltalk smarty sourceslist sql squidconf tex text diff vim xml xslt yaml"
-POST_pocoo="submit=Paste! % % language % % code"
+POST_pocoo="submit=paste! % % language % % % code"
REGEX_RAW_pocoo='s|^\(http://[^/]*/\)show\(/[0-9]*/\)$|\1raw\2|'
+# calculate
+LANGUAGES_calculate="Apache Bash Batch Boo C C# C++ Clojure Creole_Wiki CSS \
+CSV D Debian_control-files Django_Jinja_Templates Dylan Erlang eRuby_rhtml GAS GCC_Messages \
+Genshi_Templates Gettext_catalogs GL_Shader_language Haskell HTML INI_File Interactive_Ruby IO \
+IRC_Logs Java javac_Messages JavaScript JSP Lighttpd Literate_Haskell LLVM Lua Mako_Templates Matlab \
+Matlab_Session MiniD Multi-File Myghty_Templates MySQL Nasm Nginx Object-Pascal OCaml Perl PHP \
+PHP_(inline) Povray Python Python_Console_Sessions Python_Tracebacks reStructuredText Ruby Scala \
+Scheme Smalltalk Smarty sources.list SQL SquidConf TeX_LaTeX Text Unified_Diff Vim XML XSLT YAML"
+LANGUAGE_VALUES_calculate="apache bash bat boo c csharp cpp clojure creole css csv d control html+django \
+dylan erlang rhtml gas gcc-messages html+genshi gettext glsl haskell html ini irb io irc java \
+javac-messages js jsp lighttpd literate-haskell llvm lua html+mako matlab matlabsession minid multi \
+html+myghty mysql nasm nginx objectpascal ocaml perl html+php php povray python pycon pytb rst ruby \
+scala scheme smalltalk smarty sourceslist sql squidconf tex text diff vim xml xslt yaml"
+POST_calculate="submit=paste! % % language % parent private text"
+REGEX_RAW_calculate='s|^\(http://[^/]*/\)show\(/[0-9]*/\)$|\1raw\2|'
+
### errors
die() {
echo "$@" >&2
@@ -283,6 +312,9 @@ Options:
-s, --service SERVICE set service to use (defaults to "$DEFAULT_SERVICE")
-e, --expiration EXPIRATION set when it should expire (defaults to "$DEFAULT_EXPIRATION")
+ -p, --parent PARENT set parent paste (defaults to "$DEFAULT_PARENT", make use id paste) (Calculate pastebin option)
+ -P, --private PRIVATE set private status (defaults to "$DEFAULT_PRIVATE") (Calculate pastebin option)
+
-S, --list-services list supported pastebin services
-L, --list-languages list languages supported by the specified service
-E, --list-expiration list expiration setting supported by the specified service
@@ -370,6 +402,18 @@ showlanguages() {
done | sort
}
+showprivate() {
+ local p priv d
+ priv=PRIVATE_$ENGINE
+ [[ -n $COMPLETIONS ]] && printlist ${!priv} | sort && exit 0
+ echo "Private supported by $(getrecipient) (case sensitive):"
+ [[ -z ${!priv} ]] && echo "$N\"$ENGINE\" has no support for setting language." >&2 && exit 1
+ for p in ${!priv}; do
+ [[ ${p//\%/ } = $DEFAULT_PRIVATE ]] && d="*" || d=" "
+ echo " $d${p//\%/ }"
+ done | sort
+}
+
showexpirations() {
local e expiration info d
expiration=EXPIRATIONS_$ENGINE
@@ -422,7 +466,7 @@ postdata() {
local post nr extra f
post=POST_$ENGINE
nr=${!post//[^ ]}
- [[ 6 = ${#nr} ]] || die "\"${SERVICE}\" is not supported by ${FUNCNAME}()."
+ [[ 7 = ${#nr} ]] || die "\"${SERVICE}\" is not supported by ${FUNCNAME}()."
extra=${!post%% *}
[[ '%' = $extra ]] || echo -n "$extra&"
e() {
@@ -435,7 +479,7 @@ postdata() {
post=${post#$f }
done
}
- e "${!post#$extra }" NICK DESCRIPTION LANGUAGE EXPIRATION CVT_TABS INPUT
+ e "${!post#$extra }" NICK DESCRIPTION LANGUAGE EXPIRATION PARENT PRIVATE INPUT
}
# get url from response from server
@@ -530,6 +574,16 @@ while [[ -n $1 ]]; do
LANGUAGESET=0
LANGUAGE="$2"
;;
+ -p | --parent )
+ requiredarg "$@"
+ PARENTSET=0
+ PARENT="$2"
+ ;;
+ -P | --private )
+ requiredarg "$@"
+ PRIVATESET=0
+ PRIVATE="$2"
+ ;;
-L | --list-languages )
LISTLANGUAGES=0
;;
@@ -610,12 +664,16 @@ load_configs
DEFAULT_NICK=${DEFAULT_NICK:-$(whoami)} || die "whoami failed"
DEFAULT_SERVICE=${DEFAULT_SERVICE:-pocoo}
DEFAULT_LANGUAGE=${DEFAULT_LANGUAGE:-Plain Text}
+DEFAULT_PARENT=${DEFAULT_PARENT:-''}
+DEFAULT_PRIVATE=${DEFAULT_PRIVATE:-0}
DEFAULT_EXPIRATION=${DEFAULT_EXPIRATION:-1 month}
SERVICE=${SERVICE:-${DEFAULT_SERVICE}}
ENGINE=ENGINE_$SERVICE
ENGINE="${!ENGINE}"
default="DEFAULT_NICK_$SERVICE" && [[ -n ${!default} ]] && DEFAULT_NICK=${!default}
default="DEFAULT_LANGUAGE_$SERVICE" && [[ -n ${!default} ]] && DEFAULT_LANGUAGE=${!default}
+default="DEFAULT_PARENT_$SERVICE" && [[ -n ${!default} ]] && DEFAULT_PARENT=${!default}
+default="DEFAULT_PRIVATE_$SERVICE" && [[ -n ${!default} ]] && DEFAULT_PRIVATE=${!default}
default="DEFAULT_EXPIRATION_$SERVICE" && [[ -n ${!default} ]] && DEFAULT_EXPIRATION=${!default}
NICK=${NICK:-$(escape "${DEFAULT_NICK}")}
[[ -z $SOURCE ]] && SOURCE="stdin" && FILES[${#FILES[*]}]="/dev/stdin"
@@ -629,7 +687,7 @@ INFO_ARGS=${INFO_ARGS:-"--ignore-default-opts"}
# show listings if requested
[[ $USAGE ]] && usage && exit 0
[[ $SHOWSERVICES ]] && showservices && exit 0
-[[ $LISTLANGUAGES ]] && showlanguages && exit 0
+[[ $LISTLANGUAGES ]] && showlanguages && exit 0
[[ $LISTEXPIRATION ]] && showexpirations && exit 0
# language and expiration need to be verified before they are escaped but after service and defaults
@@ -637,6 +695,10 @@ INFO_ARGS=${INFO_ARGS:-"--ignore-default-opts"}
LANGUAGE=${LANGUAGE:-${DEFAULT_LANGUAGE}}
verifylanguage
LANGUAGE=$(escape "$LANGUAGE")
+PARENT=${PARENT:-${DEFAULT_PARENT}}
+PARENT=$(escape "$PARENT")
+PRIVATE=${PRIVATE:-${DEFAULT_PRIVATE}}
+PRIVATE=$(escape "$PRIVATE")
EXPIRATION=${EXPIRATION:-${DEFAULT_EXPIRATION}}
verifyexpiration
EXPIRATION=$(escape "$EXPIRATION")
@@ -771,6 +833,7 @@ else
[[ -f $TMPF ]] || TMPF=$(mktemp /tmp/wgetpaste.XXXXXX)
if [[ -f $TMPF ]]; then
postdata > "$TMPF" || die "Failed to write to temporary file: \"$TMPF\"."
+ [[ $LANG =~ ru_RU ]] && enconv $TMPF
WGETARGS="--post-file=$TMPF"
else
# fall back to using --post-data if the temporary file could not be created
@@ -785,8 +848,7 @@ else
else
OUTPUT=$(LC_ALL=C wget -O /dev/null $WGETARGS $RECIPIENT 2>&1)
fi
-
- # clean temporary file if it was created
+ #clean temporary file if it was created
if [[ -f $TMPF ]]; then
if [[ $DEBUG ]]; then
echo "Left temporary file: \"$TMPF\" alone for debugging purposes."