Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 17 Sep 2014, 01:56
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
From the creator of BaCon - gtk-server
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 3 [31 Posts]   Goto page: Previous 1, 2, 3 Next
Author Message
mcewanw

Joined: 16 Aug 2007
Posts: 2345
Location: New Zealand

PostPosted: Tue 11 Oct 2011, 15:50    Post subject:  

jamesbond wrote:
If you can get this to work, it would be interesting.


Unfortunately, Puppy Wary uses bash 3.

coproc functionality comes with bash 4...

But it seems to me that using awk is fine anyway, or a mixture of awk and bash version 3.

Awk is a powerful programming language. Puppy users may be more familiar with bash, but awk is there on the system and not a memory hog when running, so perfectly good for programming gtk-server GUIs. So maybe this is a good time to practice/learn awk...

Quote from http://www.ibm.com/developerworks/linux/library/l-awk1/index.html

Quote:

Sure, awk doesn't have a great name. But it is a great language. Awk is geared toward text processing and report generation, yet features many well-designed features that allow for serious programming. And, unlike some languages, awk's syntax is familiar, and borrows some of the best parts of languages like C, python, and bash (although, technically, awk was created before both python and bash). Awk is one of those languages that, once learned, will become a key part of your strategic coding arsenal.


http://www.grymoire.com/Unix/Awk.html:

Quote:

Why is AWK so important? It is an excellent filter and report writer. Many UNIX utilities generates rows and columns of information. AWK is an excellent tool for processing these rows and columns, and is easier to use AWK than most conventional programming languages. It can be considered to be a pseudo-C interpretor, as it understands the same arithmatic operators as C. AWK also has string manipulation functions, so it can search for particular strings and modify the output. AWK also has associative arrays, which are incredible useful, and is a feature most computing languages lack. Associative arrays can make a complex problem a trivial exercise.



http://www.vectorsite.net/tsawk_1.html#m1:

Quote:

Awk statements comprise a programming language. In fact, Awk is useful for simple, quick-and-dirty computational programming. Anybody who can write a BASIC program can use Awk, although Awk's syntax is different from that of BASIC. Anybody who can write a C program can use Awk with little difficulty, and those who would like to learn C may find Awk a useful stepping stone -- with the caution that Awk and C have significant differences beyond their many similarities.

There are, however, things that Awk is not. It is not really well suited for extremely large, complicated tasks. It is also an "interpreted" language -- that is, an Awk program cannot run on its own, it must be executed by the Awk utility itself. That means that it is relatively slow, though it is efficient as interpretive languages go, and that the program can only be used on systems that have Awk.


As an example of memory usage, here is an extract from "top" showing the earlier gtk-server awk program running:

Code:

PID  PPID USER     STAT   VSZ %MEM CPU %CPU COMMAND

 8624  8623 root     S    21544   8%   0   0% gtk-server -stdin
...
 8623 30060 root     S     2320   1%   0   0% /bin/gawk -f gtkprog.awk


Note that an instance of "bash" is heavier in terms of resource usage than gawk (from earlier running bash pipe example):

Code:

PID  PPID USER     STAT   VSZ %MEM CPU %CPU COMMAND
13739     1 root     S    21432   8%   0   0% gtk-server -fifo /tmp/bash.gtk -detach
...
13737 30060 root     S     2948   1%   0   0% gtkprog.bash


So it seems to me like a good time to start writing new Puppy gui utilities using awk (gawk) plus gtk-server, as an alternative to bash/gtkdialogs. It will be interesting to compare awk as an interpretive programming language compared to bash in terms of speed. I think awk will do fine.

_________________
Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
Back to top
View user's profile Send private message Visit poster's website 
sunburnt


Joined: 08 Jun 2005
Posts: 5028
Location: Arizona, U.S.A.

PostPosted: Tue 11 Oct 2011, 19:09    Post subject:  

Puppy524 uses Bash 4 or 4.2 ( I think...), a few other niceities too.

I dnlded the awk manual, but I wanted to see what Bash can do.
I didn`t think of using awk for just communicating. A simple fix...
Using stdin directly would be nice also ( no extra awk to run ).
In the end I`m speed testing all of this to see which is the winner.
As far as ram usage goes, the difference is so small it`s irrelivant.

Q... What GUIs / projects does anyone have planned for gtk-server?
Back to top
View user's profile Send private message 
mcewanw

Joined: 16 Aug 2007
Posts: 2345
Location: New Zealand

PostPosted: Tue 11 Oct 2011, 19:17    Post subject:  

sunburnt wrote:

I didn`t think of using awk for just communicating. A simple fix...


Unfortunately, I don't think it is so simple to use gawk just to communicate with gtk-server afterall, in which case its as well just programming in gawk and calling commandline utils with the gawk "system" command as and when required (or accept using named pipes with bash versions less than 4).

I'll see if the older version of Lucid I have also has bash 4 - I'm pretty sure it is quite easy to get coproc to work with gtk-server. Unfortunately, that wouldn't help bash 3 users, of which I am currently one (using Puppy Wary).

_________________
Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
Back to top
View user's profile Send private message Visit poster's website 
mcewanw

Joined: 16 Aug 2007
Posts: 2345
Location: New Zealand

PostPosted: Tue 11 Oct 2011, 21:26    Post subject: using wiakmv with gtk-server -ipc  

I commented earlier that I preferred using gtk-server -ipc which utilises an inter-process message queue rather than messy named pipes format. However, as I said, the problem is that the published example for doing that requires gtk-server to run two instances of itself, which is heavy on resource usage.

It turns out that the small wiakmv message queue utility can communicate directly with gtk-server message queue, and wiakmv has very low resource usage as the ps output at the bottom of this post illustrates.

I therefore wrote a demo of gtk-server -ipc using wiakmv, which is below. I've copied a pet of the small wiakmv utility here also (the dotpet puts the tiny wiakmv into /usr/local/bin). The source code for wiakmv is GPL and available at http://wiak.org downloads.

Code:

#!/bin/sh
# Bourne shell gtk-server IPC demo using wiakmv (GPL)
#   for the message queue communications with gtk-server
#
# Creation date (YMD): 2011/10/12 (original version 1.0.0)                                       
# Revision date (YMD): 2011/10/12
# (C) Copyright 2011 William McEwan (http://wiak.org); GPL
#
# Using code from Bourne shell named pipe demo with the GTK-server
# by Peter van Eerten; Revision January 15, 2007
#
# Current PID ($$) is used for the unique message queue comms channel
#------------------------------------------------

# Communicate with GTK-server
gtk()
{
  # send the gtk string to gtk-server
  wiakmv --zid=$$ --type=1 --send "$@"
  # receive the gtk-server return string into RESULT
  RESULT=$(wiakmv --zid=$$ --type=1 --receive stdout)
}

# Main starts here

# Start gtk-server in InterProcessComms mode
gtk-server -ipc=$$ -detach

# Setup GUI
gtk "gtk_init NULL NULL"
gtk "gtk_window_new 0"
WIN=$RESULT
gtk "gtk_window_set_title $WIN 'BASH GTK-server demo'"
gtk "gtk_window_set_default_size $WIN 400 200"
gtk "gtk_window_set_position $WIN 1"
gtk "gtk_table_new 10 10 1"
TBL=$RESULT
gtk "gtk_container_add $WIN $TBL"
gtk "gtk_button_new_with_label 'Click to Quit'"
BUT=$RESULT
gtk "gtk_table_attach_defaults $TBL $BUT 5 9 5 9"
gtk "gtk_widget_show_all $WIN"

EVENT=0

# Mainloop
while [[ $EVENT -ne $BUT && $EVENT -ne $WIN ]]
do
    gtk "gtk_server_callback WAIT"
    EVENT=$RESULT
done

# Exit GTK-server
wiakmv --zid=$$ --type=1 --send "gtk_server_exit"
# exit wiakmv
wiakmv --zid=$$ --type=1 --quit
exit 0


Showing the low wiakmv resource usage with ps:

The running gtk-server here uses roughly 21 MByte RAM and wiakmv just 1.5 MB (half what awk would use) and being in memory, message queues are fast comms channel. This is on an old Pentium III 256 MByte system with Wary 5.1.4.1 os.

Code:

# ps ao vsize,pmem,pcpu,cmd | egrep '(gtk-server|wiakmv)'
 21436  3.2  0.0 gtk-server -ipc 9438 -detach
  1508  0.1  0.0 wiakmv --zid=9438 --type=1 --receive stdout
wiakmv-2.3.0.pet
Description  wiakmv provides message queue facility to bash
pet

 Download 
Filename  wiakmv-2.3.0.pet 
Filesize  4.04 KB 
Downloaded  226 Time(s) 

_________________
Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
Back to top
View user's profile Send private message Visit poster's website 
mcewanw

Joined: 16 Aug 2007
Posts: 2345
Location: New Zealand

PostPosted: Tue 11 Oct 2011, 23:46    Post subject:  

An average gtkdialog3 gui seems to consume about the same amount of RAM as gtk-server.

The gtk-server binary occupies around 250 kB on disk, whereas gtkdialog3 occupies around 172kB. However, gtk-server appears to offer much more functionality (Full GTK API available, and more...) and doesn't see too difficult to program (and good for learning gtk more generally). gtk-server seems to be well-supported and under active development in a sizable community. Available for Linux and MS Windows it seems.

I expect a gui created with gtk-server to be faster than a gtkdialog3 one.

Bacon appears to occupy around 392 kB on disk.

The challenge would be to port some bash/gtkdialogs to bash(or awk)/gtk-server and compare the results.

_________________
Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Wed 12 Oct 2011, 00:20    Post subject:  

I posted a pet and a tarball with a bunch of fixed up examples about the time 2.3.1 came out here:
http://murga-linux.com/puppy/viewtopic.php?p=388947#388947

I do recommend installing findutils though for the examples.

I'm interested in trying to use it for SDL, has anyone seen an sdl config file?

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 2155
Location: The Blue Marble

PostPosted: Wed 12 Oct 2011, 00:45    Post subject:  

technosaurus wrote:
I posted a pet and a tarball with a bunch of fixed up examples about the time 2.3.1 came out here:
http://murga-linux.com/puppy/viewtopic.php?p=388947#388947

I do recommend installing findutils though for the examples.

I'm interested in trying to use it for SDL, has anyone seen an sdl config file?
Google failed me, it didn't find your original post when I searched for it. Otherwise I wouldn't have published this as a new thread Embarassed
What's the findutils for?

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5028
Location: Arizona, U.S.A.

PostPosted: Wed 12 Oct 2011, 01:54    Post subject:  

Quote:
Unfortunately, that wouldn't help bash 3 users, of which I am currently one (using Puppy Wary).

Do I smell an SFS file in the making?
I think most Linuxes will be into Bash 4 shortly, so not really much of a problem.

###> BASH update:
Quote:
Lucid 5.25 is the most leading-edge Lucid ever and a Five Digit Update from Lucid 5.2.
It has Bash 4.1.0, an upgrade from Bash 3

Last edited by sunburnt on Wed 12 Oct 2011, 05:12; edited 3 times in total
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Wed 12 Oct 2011, 02:29    Post subject:  

jamesbond wrote:
technosaurus wrote:
I posted a pet and a tarball with a bunch of fixed up examples about the time 2.3.1 came out here:
http://murga-linux.com/puppy/viewtopic.php?p=388947#388947

I do recommend installing findutils though for the examples.

I'm interested in trying to use it for SDL, has anyone seen an sdl config file?
Google failed me, it didn't find your original post when I searched for it. Otherwise I wouldn't have published this as a new thread Embarassed
What's the findutils for?
I'm glad someone started a separate thread.

findutils is for loading images and libraries (updatedb and locate are the specific binaries iirc)

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
mcewanw

Joined: 16 Aug 2007
Posts: 2345
Location: New Zealand

PostPosted: Wed 12 Oct 2011, 04:59    Post subject:  

jamesbond wrote:
If you can get this to work, it would be interesting. I don't like to trap SIGINT while the script is waiting to read the pipe - I'll end up having to kill both the scripts and the gtk-server manually :?


The one required to use gtk-server most efficiently from bash...

Working gtk-server -stdin example, using coproc. You need bash version 4+ for this so won't work in current Puppy Wary I think.

Took a while, but finally got it going (using Lucid 5.2.5). Not heavily tested though, but runs very fast on this old Pentium III 256 MB machine. Probably a couple of extra lines required to tidy up after the coproc complete (maybe need to free up used file descriptors, but maybe done automatically):

Code:

#!/bin/bash
# Bourne shell gtk-server stdin demo using bash ver4 coproc cmd
#   for the message communications with gtk-server
#
# Creation date (YMD): 2011/10/12 (original version 1.0.0)                                       
# Revision date (YMD): 2011/10/12
# (C) Copyright 2011 William McEwan (http://wiak.org); GPL
#
# Using code from Bourne shell named pipe demo with the GTK-server
# by Peter van Eerten; Revision January 15, 2007
#------------------------------------------------

# Communicate with GTK-server
gtk()
{
  # send the gtk string to gtk-server
  echo "$@" >&${COPROC[1]}
  # receive the gtk-server return string into RESULT
  read -u ${COPROC[0]} RESULT
}

# Main starts here

# Start gtk-server in stdin mode
coproc gtk-server -stdin

# Setup GUI
gtk "gtk_init NULL NULL"
gtk "gtk_window_new 0"
WIN=$RESULT
gtk "gtk_window_set_title $WIN 'BASH GTK-server demo'"
gtk "gtk_window_set_default_size $WIN 400 200"
gtk "gtk_window_set_position $WIN 1"
gtk "gtk_table_new 10 10 1"
TBL=$RESULT
gtk "gtk_container_add $WIN $TBL"
gtk "gtk_button_new_with_label 'Click to Quit'"
BUT=$RESULT
gtk "gtk_table_attach_defaults $TBL $BUT 5 9 5 9"
gtk "gtk_widget_show_all $WIN"

EVENT=0

# Mainloop
while [[ $EVENT -ne $BUT && $EVENT -ne $WIN ]]
do
    gtk "gtk_server_callback WAIT"
    EVENT=$RESULT
done

# Exit GTK-server
gtk "gtk_server_exit"
exit 0

_________________
Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
Back to top
View user's profile Send private message Visit poster's website 
jamesbond

Joined: 26 Feb 2007
Posts: 2155
Location: The Blue Marble

PostPosted: Thu 13 Oct 2011, 19:31    Post subject:  

Thanks mcewannw. This works well. (Fatdog comes with bash4 so bash4 isn't a problem).

cheers!

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Fri 14 Oct 2011, 02:21    Post subject:  

the musl libc wrapper has a coproc-like replacement that should work with even busybox ash
http://git.etalabs.net/cgi-bin/gitweb.cgi?p=musl;a=blob_plain;f=tools/gen-musl-gcc.sh;hb=HEAD

I was pretty sure I was using busybox ash before, but not sure what method I used, I haven't used it in a while (determined it was easier to just use C with tcc in compile and run mode - yes C is a scriptable language now)

also MU made a glade project builder for gtk-server
http://www.murga-linux.com/puppy/viewtopic.php?t=60705

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
mcewanw

Joined: 16 Aug 2007
Posts: 2345
Location: New Zealand

PostPosted: Sun 16 Oct 2011, 15:00    Post subject:  

technosaurus wrote:
the musl libc wrapper has a coproc-like replacement that should work with even busybox ash
http://git.etalabs.net/cgi-bin/gitweb.cgi?p=musl;a=blob_plain;f=tools/gen-musl-gcc.sh;hb=HEAD


This sounds interesting if it can replace coproc. Can you enlighten me on this code? I don't see what it does or how to use it instead of coproc.

_________________
Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Sun 16 Oct 2011, 16:28    Post subject:  

This is the section I was referring to:

Code:
[ "$nolink" ] || {
tmp_specs=$HOME/.specs.tmp.$$
printf '*link_libgcc:\n\n\n' > "$tmp_specs" || exit 1
exec 3<"$tmp_specs"
rm -f "$tmp_specs"
set -- -specs=/proc/self/fd/3 "$libc_start" "$libc_crt" "$@" "$libc_end" \
  -Wl,--start-group -lc -lgcc -lgcc_eh -Wl,--end-group \
  -Wl,-dynamic-linker,"$ldso_pathname" -Wl,-nostdlib
}

I don't fully understand it myself, but when I read the coproc manpage, this was what immediately came to mind... maybe my gut is lying to me, but this is what I _think_ is going on in the wrapper:

sets up a file in /root/.specs.tmp.<Random#>
with the contents:
"*link_libgcc:


"
then:
exec 3 /root/.specs.tmp.<Random#>
establishes a new process in /proc/self/fd/3 and the original file can be removed and the process can be used

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
mcewanw

Joined: 16 Aug 2007
Posts: 2345
Location: New Zealand

PostPosted: Sun 16 Oct 2011, 19:14    Post subject:  

technosaurus wrote:

then:
exec 3 /root/.specs.tmp.<Random#>
establishes a new process in /proc/self/fd/3 and the original file can be removed and the process can be used


Not sure about this. I have written a C prog before that started two processes with a pipe between then (redirecting stdins and stdouts appropriately). Its trickyish to do, and I might have trouble understanding my own code so many years later... I'm not entirely sure if I could communicate with gtkserver via that or not. Lots of interesting things going on just now... alas that means "so many things to do..."

I've also just installed gtk-server on my Windows box at work too, though still to use it for anything there. I want to try it for something I need to do at work, where they don't use Linux. But I'd love to introduce some programmer work colleagues to gtk interface anyway one way or the other.

_________________
Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 2 of 3 [31 Posts]   Goto page: Previous 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1218s ][ Queries: 12 (0.0077s) ][ GZIP on ]