Anonymous user
Sort a list of object identifiers: Difference between revisions
→{{header|REXX}}: moved data into the GEN subroutine, added/changed comments and whitespace, split some multi-statement lines.
(→{{header|REXX}}: moved data into the GEN subroutine, added/changed comments and whitespace, split some multi-statement lines.) |
|||
Line 1,373:
This REXX version supports negative integers in the OID.
<lang rexx>/*REXX program performs a sort of OID (Object IDentifiers ◄── used in Network data).*/
$= 1.3.6.1.4.1.11.2.17.19.3.4.0.10 , /* ◄──┐ */▼
1.3.6.1.4.1.11.2.17.5.2.0.79 , /* ◄──┤ */▼
1.3.6.1.4.1.11.2.17.19.3.4.0.4 , /* ◄──┼─◄─ six OID numbers (as a list).*/▼
1.3.6.1.4.1.11150.3.4.0.1 , /* ◄──┤ */▼
1.3.6.1.4.1.11.2.17.19.3.4.0.1 , /* ◄──┤ */▼
1.3.6.1.4.1.11150.3.4.0 /* ◄──┘ */▼
call gen /*generate an array (@.) from the OIDs.*/
call show 'before sort ───► ' /*display the @ array before sorting.*/
call adj 1
call bSort # /*sort " " " " " " */
call adj 0 /*shrink " " " " " " */
call show ' after sort ───► ' /*display the @ array after sorting. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
bSort: procedure expose @.; parse arg n; m=n-1
do m=m for m by -1 until ok;
do j=1 for m; _= j + 1
end /*m*/ /* [↑] use a simple bubble sort. */
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen:
1.3.6.1.4.1.11.2.17.5.2.0.79 , /* ◄──┤
▲ 1.3.6.1.4.1.11.2.17.19.3.4.0.4 , /* ◄──┼─◄─ six OID numbers (as a list).*/
w= 0 /*W: max length of #'s.*/
#= words($); do i=1 for #; @.i= word($, i); w= max(w, length(@.i) )
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
adj: arg LZ; do j=1 for #; x= translate(@.j, , .); y=
do k=1 for words(x); _= word(x, k)
if LZ then y= y right(_,
end /*k*/ /*adjust number, append*/
@.j = translate( space(y), ., ' ') /*reconstitute number. */
end /*j*/ /*LZ: Leading Zero(s).
return /*── ─ ─
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do a=1
{{out|output|text= when using the (internal) default input:}}
<pre>
|