Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Feb 2000 01:06:28 +0000
From:      "W.H.Scholten" <whs@xs4all.nl>
To:        tech@openbsd.org
Cc:        hackers@freebsd.org
Subject:   ls: alpha - numeric sorting
Message-ID:  <38A36094.794BDF32@xs4all.nl>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

--------------1CFBAE3959E2B60015FB7483
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

L.S.

Here are patches for FreeBSD's ls (from version 3.3 release) and
OpenBSD's ls (version 2.6, didn't actually test this obsd patch as I'm
working on a FreeBSD machine at the moment).

What it does is add an option (yes another one) to sort alpha & numeric
separately, i.e. instead of something like

gsi-0.9.3p1.tgz
gsi-0.9.3p10.tgz
gsi-0.9.3p11.tgz
gsi-0.9.3p12.tgz
gsi-0.9.3p13.tgz
gsi-0.9.3p14.tgz
gsi-0.9.3p15.tgz
gsi-0.9.3p16.tgz
gsi-0.9.3p17.tgz
gsi-0.9.3p18.tgz
gsi-0.9.3p2.tgz
gsi-0.9.3p3.tgz
gsi-0.9.3p4.tgz
gsi-0.9.3p5.tgz
gsi-0.9.3p6.tgz
gsi-0.9.3p7.tgz
gsi-0.9.3p8.tgz
gsi-0.9.3p9.tgz

you will get:

gsi-0.9.3p1.tgz
gsi-0.9.3p2.tgz
gsi-0.9.3p3.tgz
gsi-0.9.3p4.tgz
gsi-0.9.3p5.tgz
gsi-0.9.3p6.tgz
gsi-0.9.3p7.tgz
gsi-0.9.3p8.tgz
gsi-0.9.3p9.tgz
gsi-0.9.3p10.tgz
gsi-0.9.3p11.tgz
gsi-0.9.3p12.tgz
gsi-0.9.3p13.tgz
gsi-0.9.3p14.tgz
gsi-0.9.3p15.tgz
gsi-0.9.3p16.tgz
gsi-0.9.3p17.tgz
gsi-0.9.3p18.tgz

Much better! This would be great on ftp servers (trying to find the
latest tgz for a given package in a list of around 50 or more is a
nuisance with lexicographical ordering).

The sort option is invoked with -n on fbsd, -N on obsd (change as you
like...).

I've also attached a complete little test program with debug output etc.
The code could be improved by renaming some variables to longer names
(couldn't think of any good ones ;) and probably the implementation too
(haven't tried to optimize).

Enjoy,

Wouter

--------------1CFBAE3959E2B60015FB7483
Content-Type: application/x-gzip; name="alpha_num_cmp.c.gz"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="alpha_num_cmp.c.gz"

H4sICHhZozgAA2FscGhhX251bV9jbXAuYwCVV39T20gS/dv+FH3ZymFj4Qizu3fBkC1hC1CV
kTlJDkuxFCvJMtZGP3ySHI69zXe/1zMj22AgdVQqmpnued39prtn/GGXBvnisYjv5xW1Bm3q
6bpOV93zrhvO86SKsmaTiJxoGpdVEQfLKs4z8rMpLcuI4ozKfFmEkVgJ4swvHmmWF2mp0UNc
zSkveDcP82VFaT6NZ3HoM4ZGfhHRIirSuKqiKS2K/Gs8xaCa+xX+i4CTJPlDnN0zRJhn05j3
lWJfGlWHvLzffeZaSfms9inMp9BclhUVUeXDV0b1g/wri1TMDIK/LK/iMNKgEZeUAI9hNm1m
06c+EYyGiR+nUdFljN62IzC4wUjtCOKcLuHcyhflwcqj/98XhbD2iFSs0zxcplFW+fWhfcgL
yiEpKPWrqIj9pFwRr1DEsYnNG8FwiCz3zi2X3PGpd2U4JmF86Yw/W0NzSCfXEJpkTLzzsUOG
PaTB2PYc62TijR2Xfv/dcBnAcnd2hNSwr8n89dIxXZewwbq4HFmAAa5j2J5luhpZ9mA0GVr2
mUZAIXvsMcLIurA8aHpjTVjc3knjU7owncE5psaJNbK8a2Hy1PJsmGOQU/aRLg3HswaTkeHQ
5cS5HLvwH2ENLXcwMqwLc9iFwzYMk/nZtD1yz43RiI0yhIoU/54EemLCQ+NkZEobiHJoOebA
43DUSPBgD0Ab/Btp5F6aA4sH5q8mgjGca03Buua/JlCCkIbGhXFmCudb28Q8YQVnMpg45gW7
DCrcyYnrWd7EM+lsPB4KCMC7pvPZGphun0ZjV3A2cU0NdjxDmAcKCIMY45OJa9XUWbZnOs7k
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Bz/+9PM//vlRlFgjDDYUgi2F
l0pjjxDe8fspRyg+oZyFPBNFIaPXVODCDihuwZm/HWOB/voLIvp0DEUxDsQ4kDE2EKD0KatJ
1kRZKDQBJ/HSBbbQqiBEPvOLXOaoOEX8BphFBZ6lfIzYtx1Oq9feMAZb76dtEcWWzbpkxQlg
ylXcaMC8m2ubLsSlSP7ST/GwxpuW84tj5KCFQGarXxdbyTBUR/GAF3NEwUpYF1HZpwcGfeSF
ICrKT1K/RH4fBYcqvu3wDtpsfI9EKqgDUgsyrDoqucZLIrCXjkFtWZP/ikl/m9I6NwSj2PvE
tCRUmAWdyCc48/cNSuVZ1qSyLuiy0UHAyNzHTyxUeJ5/IfVjThEk2sBGO0q7kqRMFYWoiU74
UllkwVol6IQvFgY8daKUf+CpzkT6TqksiDIGRCb4lFWOqaT3YR4nEXo63aj6J7yqjmlH3+F0
Vnv39vq1tNPpk+BGdgWGDVawPBXNpYYNathgGzZYwwZrWD5OZRX1KRVfPdsf2ysPaeWPOlsp
2FMImyf8bMvqtF9qLn5Hxn38Hp08kJNATPgs0dzqVGrVmm2Ma8V27YZqgE+y+Ptbvp/cP23k
tgLTaqQVkHrBbGe4Ylsy/TrLP4NlpUOtPOMsLynNi3Wu8RW4U24ZkiS/TTB3ljhbRocom45o
3YH4ol6iB8n6nRypiu1kog12skCQLhYkgWKxLanmBF9J2QHOjJWOePV8a/4PLjpZjQMSAAA=
--------------1CFBAE3959E2B60015FB7483
Content-Type: application/x-gzip; name="whs_fbsd_ls.diff.gz"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="whs_fbsd_ls.diff.gz"

H4sICPRcozgAA3doc19mYnNkX2xzLmRpZmYArVhpc9poEv4Mv6LHMzU24TDg+MJxJjLItrYw
sEjE49ra8kjiBVQREiOJOJ6d/Pd9uiVxGE/VJLupFHqPPp4+1fLYm0yoGi175Me1MPKmh+58
UXOxSxfFarW6fVUwlwFpyyk1z6lx0mo0W29PqHF+fl4sl8srvsJdGNC1cohO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XVwp+B+l/eFOtVqdF6iSRTOyUHtExd1MI15gp8vuKFCboz3rjEh9fvS9rcu
coi2L9JYYZz26RQaqdq0Rk2Y2qhXMKHXm+/yBc7qTXwqPovGxYIB+soe58j+UFHIKGbK/cR3
KS6QBNNkhgvuc3AqJsBnNDJMSr764rnhNLIXMwaUwfTiMBB5eB+LJbkEeVmIRTXuXmmg5NN5
95M7/3bGR8L2NzOP6D4OfD6QnYudu9oF2AW8y/fq6ZEp5OmkzyDb53T8AXJwcZEO2KlMmUN4
59uYHOAJ2ICskeHEd9ZHTimjczM6N15wxtFevdE8ent8cnp2vpeyuc4GhbNLkQ9LkIQhHdR/
/gnb6P0l7JW1I2sng1ngD0ERGOQeq0i6p/4opUpTifMFmGiV55Kl/GZOE0/iwkORivBqkriA
Mf/rRD6SFb6mEGVWDiuborxYMjNO/0CC4QJKGS3Dl4s0key8FGKRQzmcJ7z+FDmr2zzF4wt6
YqnPfOBg8n6f0uNTw37ntHKgOU4H9evagjWD+pqH3CyIa79sCcmMzQTAVNe+hOSfN8xN/ZUb
LOQwpccfpYpmNuYZVEYYfqJsdsrAS/lsFPK8lhkQZJkjiVN2X82dwFnTOGX3L7IHcIdqzhNV
VtZU349zLZL3MjZf5HvJ2cxl2XelTf/KSob+TZeXtF/f59TJuKvVi/y2XL6gzEtpKbFoZy2a
92lV5qKdXLSzK9pZi3Y2RXOUMt2oiZT0RchyaOuK/ov4w7hyCr5UAZp07ZTylvA30yLDlOLZ
wSI4tjCwiyWs5VwFe0aCWA6kezDl1+J/AWjfqgx4FQAA
--------------1CFBAE3959E2B60015FB7483
Content-Type: application/x-gzip; name="whs_obsd_ls.diff.gz"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="whs_obsd_ls.diff.gz"

H4sICPpcozgAA3doc19vYnNkX2xzLmRpZmYArVhpc9pYFv0Mv+KOu6oNFmAWx44hTlsG2dYU
Bo8k4vZMTdGSeIDKQiKSiOPuzn+fc58kFpOeSVKTStlvucu567vyxJtOq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bvOAJWvSD4OZiPPpERMjuveFHbygWaAtoXVwp+B+l/eFOtVqdF6maRQu
yEHtExd1MIt5uF8suaFCbixqpE9JfFzZ/s5FDtH2pTRWGKd9OoVGojarUROmNuoVwhvSfJcv
cFZv4gvxRWpcLhmgL+xJjux3EYWMYi7cJ75LcYEkmCVzXHCfg1Mx272gkZGNm8+eG84iezln
QBlMLw4DKQ/PvbQklyAfC2lRjbtXGij5wbzz3bvzxYzxf/dLmWdDHwc+H8idi5273gXYBbzL
9+J5zBTyt5P+DrJ9TsefFqVOJx2jU5ly9uCdb/PokESwAVkjBxLf2Rw55YzOzejceMkZRwf1
RrN18ub07O35QcrmOlsUzj6F1I0JCZIwiYP6zz9hG72/gL1y7ci1k8Es8DeiFBjkHqvIdE/9
US5vZi7cg4nWeS6zlF/mNPFkXHgoEhGeJhkXHrayv0msx7AvKUT+XjLDyrYoL5aZGad/FcFw
AaWMluHLizSR7LwUYimHcjjPeP4EOevbPMXjDj2z1Bc+cDB/v0/pY+TeO6edA81xOqhf15ZY
M6hf85CbBXHjlx0hmbGZAJjq2heQ/POWuam/coMlOUwZ8EenoLmNeQaVEYZPlM1OGXhZPluF
vKhlBgRZ5sjEUdyv5k7gbGgcxf2L7AFcQyx4osrKmuqHca5F5r2cnDv5XuZs5rLs69Gmf2Ul
Q/+miws6rB9y6mTc1Wonv1WUDmVeSkuJRTsb0bxPqzIX7eSinX3Rzka0sy2ao5TpRk2kpK9C
lkPbVPRfxB/GKSn4cgVo0rVTzlvCN6ZFhinFs4dF4tjBwC6WYVVyFewZGUQlkN2DKb8U/wOn
f/ENbRUAAA==
--------------1CFBAE3959E2B60015FB7483--




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?38A36094.794BDF32>