Post Top Ad

Your Ad Spot

Nov 21, 2018

I got more... "advice"!

Yesterday morning I installed a new test virual machine and, as usual, I needed to know its own IP address. So I opened the shell and gave the 'ifconfig -a' command to get it. I wondered if I could have something better than that, like a way to get the same information with two mouse clicks, and I implemented a "IP Address" option in Magellan's "Icaros" menu, which basically targeted ifconfig's oputput to a reader. Good. I had what I needed, with the only problem it was ugly and unpractical. It opened a fullscreen sized window to show few text lines. I had to change it.

So I decided that if I could output that window to a RequestChoice (RC) window it would have been fine. There were two problems, though: RC's output capabilities are quite limited and, unluckily, I simply could not use a command like


RequestChoice "IP Address" "`ifconfig -a`" "OK"

because the way ifconfig shows its output is not compatible with RC's exprectations. For instance, something like:

lo0: flags=9<UP,LOOPBACK> mtu 1536
    inet 127.0.0.1 netmask 0xff000000
net0: flags=822<BROADCAST,NOTRAILERS,SIMPLEX>
    inet 0.0.0.0 netmask 0xffffff00 broadcast 0.0.0.255


would need to be cleaned of special tab characters (the ones before "inet" words) and all line feeds replaced by the *N code, so it would appear like this:

"lo0: flags=9<UP,LOOPBACK> mtu 1536*Ninet 127.0.0.1 netmask 0xff000000*Nnet0: flags=822<BROADCAST,NOTRAILERS,SIMPLEX>*Ninet 0.0.0.0 netmask 0xffffff00 broadcast 0.0.0.255"

But how to get this done? The answer is, once more, an old cli utility called gsar, which I built for AROS many months ago. Gsar can search for control characters and replace them as I like, so in a nutshell I could write these lines of code

ifconfig -a >t:currIP
gsar -i -o -s:x09 -r:x20:x20 t:currIP >NIL:
gsar -i -o -s:x0a -r*N t:currIP >NIL:


and place them in a new script. These lines basically transform the output of 'ifconfig -a' into a text line which requestcoice can understand. In fact, the following line is:

RequestChoice "IP Address" "${t:currIP}" "Close" >nil:

Which  is exactly what I needed to get this:

the actual script on Icaros Desktop also includes a 'Change' button to open Prefs/Network

So, why did I got some "advice"? Because I discovered this on Aminet, a RequestChioce clone for AmigaOS 2+ which can use a text file as value for the BODY parameter. The archive on Aminet includes also the source in C but, due to my very very very limited skills, I could not even get it to build. With advice, the above script would have looked like:

ifconfig -a >t:currIP
Advice TITLE "IP Address" BODY t:currIP BUTTONTEXT "Close"

I posted this help request on AROS-EXEC, and I sincerely hope someone will help me bringing this to AROS, since it can be very useful with script someone immediately helped me, giving me the hints I needed to fix the original sources and let them compile under Icaros Desktop (I used AROS gcc version included in the distribution). So, thank you Cavemann, thank you Neil (and thank you Wawa), it's always a pleasure to interact with smart people like you! :-)

Advice for AROS, and modified source, will be posted on the Archives as soon as possible.



Post Top Ad

Your Ad Spot