#!/bin/mksh # $MirOS: contrib/hosted/tg/verscmp,v 1.2 2014/06/20 22:50:56 tg Exp $ #- # Copyright © 2013, 2014 # Thorsten Glaser # # Provided that these terms and disclaimer and all copyright notices # are retained or reproduced in an accompanying document, permission # is granted to deal in this work without restriction, including un‐ # limited rights to use, publicly perform, distribute, sell, modify, # merge, give away, or sublicence. # # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to # the utmost extent permitted by applicable law, neither express nor # implied; without malicious intent or gross negligence. In no event # may a licensor, author or contributor be held liable for indirect, # direct, other damage, loss, or other issues arising in any way out # of dealing in the work, even if advised of the possibility of such # damage or existence of a defect, except proven that it results out # of said person’s immediate fault when using the work as intended. #- # Compare versions. Syntax: verscmp filea fileb # Files contain IFS-separated: name, version, ignored fa=$1; fb=$2 [[ -n $fa && -s $fa && -n $fb && -s $fb ]] || exit 1 py='# coding: utf-8' nl=$'\n' function str2python { [[ -o utf8-mode ]]; local u=$? set +U local s="$*" t=\" local -i i=0 n=${#s} local -Uui16 -Z5 hv while (( i < n )); do hv=1#${s:(i++):1} t+=\\x${hv#16#} done t+=\" print -nr -- "$t" (( u )) || set -U } function pyadd { local field=$1 file=$2 cola colb rest py+=$nl"$field = {" while read cola colb rest; do py+=$nl"$(str2python "$cola"): $(str2python "$colb")," done <"$file" py+=$nl"}" } pyadd sidea "$fa" pyadd sideb "$fb" py+=$nl"q = '\"'" py+=' comb = {} ckeys = sidea.keys() ckeys.extend(sideb.keys()) ckeys = set(ckeys) for k in ckeys: comb[k] = [None, None] for k, v in sidea.iteritems(): comb[k][0] = v for k, v in sideb.iteritems(): comb[k][1] = v ckeys = list(ckeys) ckeys.sort() for k in ckeys: va = comb[k][0] vb = comb[k][1] if va <> vb: if va is None: da = "None" else: da = q + va + q if vb is None: db = "None" else: db = q + vb + q print k, da, db ' python <<<"$py"