× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.






Hello Jon,

I just want to display it in the sequence they want to see it in, so
that .12 comes before .119. I don't care how it's sorted in the
database. I am using RPG but SQL is not an option as they don't have
5722-ST1.

Okay... now that I know you intend to use qsort, let me make another recommendation...

Instead of trying to add leading zeros to the digits (which is a bad idea) consider sorting based on the output of inet_addr(). The inet_addr() routine will convert the IP address to a 32-bit unsigned integer (which is what's REALLY used in network packets, the dotted-decimal representation of the octets is just for human consumption).

For example:

H DFTACTGRP(*NO) BNDDIR('QC2LE')

D inet_addr PR 10U 0 ExtProc('inet_addr')
D char_addr * value options(*string)

D qsort PR ExtProc('qsort')
D base * value
D num 10U 0 value
D width 10U 0 value
D compare * procptr value

D asIpAddr PR 10i 0
D elem1 like(list)
D elem2 like(list)

D List s 15a dim(10)
D x s 10i 0
/free

list(1) = '192.44.208.119';
list(2) = '192.44.208.12';
list(3) = '192.44.208.120';
list(4) = '192.168.5.1';
list(5) = '192.168.207.100';

qsort( %addr(list)
: %elem(list)
: %size(list)
: %paddr(asIpAddr) );

for x = 1 to %elem(list);
dsply list(x);
endfor;

*inlr = *on;
/end-free


*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* asIpAddr(): This proc is used by qsort() to compare
* array elements. It determines which
* element shoudl come before another...
*
* returns 1 if elem1 should come after elem2
* -1 if elem1 should come before elem2
* 0 if they are the same
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P asIpAddr B
D asIpAddr PI 10i 0
D elem1 like(list)
D elem2 like(list)

D ip1 s 10u 0 static
D ip2 s 10u 0 static
/free
if (elem1 = *blanks);
ip1 = *hival;
else;
ip1 = inet_addr(elem1);
endif;

if (elem2 = *blanks);
ip2 = *hival;
else;
ip2 = inet_addr(elem2);
endif;

select;
when ip1 < ip2;
return -1;
when ip1 > ip2;
return 1;
other;
return 0;
endsl;

/end-free
P E



I also need to be able to allow them to position on the
xxx.xxx.xxx.xxx. I have never used qsort so I will check it out.


For that, you can just spin through the array (or subfile) until you find a matching address and position the cursor there, right? That should be trivial.

If the array is really long and you want a more efficient method of searching, you could use bsearch()... but I doubt your array is long enough to make that worth the extra code...

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.