#!/bin/ksh # @(#) Show date format codes #..# systems: #..# sites: #..# level: #..# publish: y #..# keys: #..# date: Wed Apr 25 14:54:32 BST 2001 #..# vers: 1.2 03/Aug/2006-15:48 [ $0 = ${0#/} ] && this=$(pwd -H)/$0 || this=$0 tag=${0##*/} tm=/tmp/${tag} tmp=${tm}$$ rm -f ${tm}* set -A AWK $(whence nawk) [ ${#AWK[*]} -gt 0 -a "${AWK[0]}" != no ] && alias awk=${AWK[0]} usage="Usage: $tag " # set -- `getopt vxh $*` while [ $# -gt 0 ]; do case "$1" in -v|-x) set "$1" ;; -vi) lockvi $this; exit ;; -view) view $this; exit ;; -about) echo "$tag was written by David Ledger" echo "dledger@ivdcs.co.uk" echo "Free to use at your own risk" echo "Copyright 2004" exit ;; -ver) ver=$(egrep '#..#[ ]*vers:' $this) ver=${ver#"${ver%%[1-9]*}"} print ${ver%%[!0-9.]*} exit ;; -h) echo "" echo "$usage" echo "" echo "$tag exhaustively checks each % argument for the" echo "current implementation of 'date', for all [a-zA-Z]." echo "" echo "Current output for each is shown, uppercase below" echo "lowercase." echo "" echo "Error arguments are only shown if the corresponding" echo "upper/lower case argumnet is valid, and are shown as ':'." echo "Some valid give non-printing o/p, ie: '%n' -> '\\\n'" echo "and '%t' -> '\\\t'." echo "" echo "Seconds (& overflow to minutes) may differ between the" echo "detail o/p and the default o/p shown first, due to the" echo "time taken to manipulate the data." exit ;; *) ;; esac shift done typeset -u C typeset -i i=0 j=0 J=0 k=0 K=0 m=0 M=0 w=0 date set -A a "" a b c d e f g h i j k l m n o p q r s t u v w x y z i=1 while [ $i -lt ${#a[*]} ]; do c=${a[$i]} C=$c A[$i]=$C #s[$i]="$(date "+%$c" 2>/dev/null)" || s[$i]=":" #S[$i]="$(date "+%$C" 2>/dev/null)" || S[$i]=":" s="$(date "+%$c" 2>/dev/null)" || s=":" S="$(date "+%$C" 2>/dev/null)" || S=":" [ "$s" = ":" -a "$S" = ":" ] && i=$(($i + 1)) && continue s[$i]="$s" S[$i]="$S" k=${#s[$i]} K=${#S[$i]} k[$i]=$k K[$i]=$K p=0; P=0 if [ $k -gt $K ]; then P=$(($k - $K)) elif [ $k -lt $K ]; then p=$(($K - $k)) fi p[$i]=$p P[$i]=$P [ $p -gt $w ] && w=$p || { [ $P -gt $w ] && w=$P; } i=$(($i + 1)) done i=1; W="" while [ $i -le $w ]; do W[$i]="${W[$(($i - 1))]} " i=$(($i + 1)) done i=1; j=0; J=0 while [ $i -lt ${#a[*]} ]; do [ -z "${s[$i]}" -a -z "${S[$i]}" ] && { i=$(($i + 1)); continue; } [ $(($j + 4 + ${k[$i]} + ${p[$i]})) -lt 80 ] && [ $(($J + 4 + ${K[$i]} + ${P[$i]})) -lt 80 ] && { #printf "%s%s%s=%s%s(%s)\n" "${l:-}" "${l:+ }" "${a[$i]}" "${s[$i]}" "${W[${p[$i]}]}" "${p[$i]}" #printf "%s%s%s=%s%s(%s)\n" "${L:-}" "${L:+ }" "${A[$i]}" "${S[$i]}" "${W[${P[$i]}]}" "${P[$i]}" l="$(printf "%s%s%s=%s%s" "${l:-}" "${l:+ }" "${a[$i]}" "${s[$i]}" "${W[${p[$i]}]}")" L="$(printf "%s%s%s=%s%s" "${L:-}" "${L:+ }" "${A[$i]}" "${S[$i]}" "${W[${P[$i]}]}")" #[ $i -gt 1 ] && exit #j=$(($j + 4 + ${k[$i]} + ${p[$i]})) #J=$(($J + 4 + ${K[$i]} + ${P[$i]})) } || { print "$l" print "$L" l="$(printf "%s=%s%s" "${a[$i]}" "${s[$i]}" "${W[${p[$i]}]}")" L="$(printf "%s=%s%s" "${A[$i]}" "${S[$i]}" "${W[${P[$i]}]}")" } j=${#l} J=${#L} i=$(($i + 1)) done print "$l" print "$L"