Skip to content

Commit

Permalink
Merge pull request #43 from whiteinge/msysgit-fixes
Browse files Browse the repository at this point in the history
Small fixes for msysgit
  • Loading branch information
whiteinge authored Jun 22, 2017
2 parents dc6af68 + 903fbad commit 18a6f37
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export LINFO=4 # Info-level log messages.
export LDEBUG=5 # Debug-level log messages.
export LSUMMARY=6 # Summary output.

# We need this path for when we reset our env.
awk_bin=$(command -v awk)

# Generate a carriage return so we can match on it.
# Using a variable because these are tough to specify in a portable way.
cr=$(printf '\r')

# ## Main
# Generic functions not necessarily specific to working with GitHub.

Expand Down Expand Up @@ -183,7 +190,7 @@ __main() {
local OPTARG
local OPTIND
local quiet=0
local temp_dir="/tmp/${NAME}.${$}.$(awk \
local temp_dir="${TMPDIR-/tmp}/${NAME}.${$}.$(awk \
'BEGIN {srand(); printf "%d\n", rand() * 10^10}')"
local summary_fifo="${temp_dir}/oksh_summary.fifo"

Expand Down Expand Up @@ -345,11 +352,12 @@ _format_json() {

_log debug "Formatting ${#} parameters as JSON."

env -i "$@" awk '
env -i "$@" "$awk_bin" '
function isnum(x){ return (x == x + 0) }
function isbool(x){ if (x == "true" || x == "false") return 1 }
BEGIN {
delete ENVIRON["AWKPATH"] # GNU addition.
delete ENVIRON["AWKLIBPATH"]
printf("{")
for (name in ENVIRON) {
Expand Down Expand Up @@ -388,7 +396,7 @@ _format_urlencode() {

_log debug "Formatting ${#} parameters as urlencoded"

env -i "$@" awk '
env -i "$@" "$awk_bin" '
function escape(str, c, len, res) {
len = length(str)
res = ""
Expand All @@ -406,6 +414,7 @@ _format_urlencode() {
for (i = 0; i <= 255; i += 1) ord[sprintf("%c", i)] = i;
delete ENVIRON["AWKPATH"] # GNU addition.
delete ENVIRON["AWKLIBPATH"]
for (name in ENVIRON) {
if (substr(name, 1, 1) == "_") continue
val = ENVIRON[name]
Expand Down Expand Up @@ -692,7 +701,7 @@ _response() {
_log debug 'Processing response.'

read -r http_version status_code status_text
status_text="${status_text%}"
status_text="${status_text%${cr}}"
http_version="${http_version#HTTP/}"

_log debug "Response status is: ${status_code} ${status_text}"
Expand All @@ -703,8 +712,8 @@ status_text: ${status_text}
"
while IFS=": " read -r hdr val; do
# Headers stop at the first blank line.
[ "$hdr" = "" ] && break
val="${val%}"
[ "$hdr" = "$cr" ] && break
val="${val%${cr}}"

# Process each header; reformat some to work better with sh tools.
case "$hdr" in
Expand Down

0 comments on commit 18a6f37

Please sign in to comment.