Jump to content

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.*/
say copies('░', 79) say copies('░', 79) /*display " fence, separate before & after*/
call adj 1; call bSort #; call adj 0 /*expand/sort/shrink the internal $ list of OID's numbers. */
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 /*N: is the number of @ array elements.*/
do m=m for m by -1 until ok; ok=1 1 /*keep sorting the @ array until done. */
do j=1 for m; _= j + 1; if @.j>@._ then parse value @.j @._/*calculate 0the withnext @._(index) in @.j okarray*/
end if /*@.j*/>@._ then parse value @.j @._ 0 with @._ /* [↑]@.j swap two out─of─order elements.*/ok
end end /*mj*/; return /* [↑] use a simple /* bubble[↑] sort. swap two out─of─order elements.*/
end /*m*/ /* [↑] use a simple bubble sort. */
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen: #=words($); L=length(#); 1.3.6.1.4.1.11.2.17.19.3.4.0.10 , /* ◄──┐ do i=1 for #; @.i=word($,i); end; return*/
1.3.6.1.4.1.11.2.17.5.2.0.79 , /* ◄──┤ /*length of the number of words in $.*/
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.1111150.23.17.5.24.0.791 , /* ◄──┤ */
$= 1.3.6.1.4.1.11.2.17.19.3.4.0.101 , /* ◄──┐◄──┤ */
1.3.6.1.4.1.11150.3.4.0.1 , /* ◄──┤◄──┘ */
w= 0 /*W: max length of #'s.*/
#= words($); do i=1 for #; @.i= word($, i); w= max(w, length(@.i) )
1.3.6.1.4.1.11.2.17.19.3.4.0.1 , end /*i*/ ◄──┤ /*W: max length of #'s.*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
adj: arg LZ; do j=1 for #; x= translate(@.j, , .); y= /*construct X version. */
do k=1 for words(x); _= word(x, k) /*get a number in X. */
if LZ then y= y right(_,90 w, 0); else y=y _+0 /*add│elide(prepend) leading 0's*/
1.3.6.1.4.1.11150.3.4.0 /*else ◄──┘y= y _ + 0 /* (elide) " " */
end /*k*/ /*adjust number, append*/
@.j = translate( space(y), ., ' ') /*reconstitute number. */
end /*j*/ /*LZ: Leading Zero(s). */
return /*── ─ ─ */
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do a=1 for #; say right("OID number",20) right(a,Llength(#)) arg(1) @.a; end; return</lang>
{{out|output|text=&nbsp; when using the (internal) default input:}}
<pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.