From the creator of BaCon - gtk-server

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#21 Post by technosaurus »

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. ... 947#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?
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#22 Post by jamesbond »

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. ... 947#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 :oops:
What's the findutils for?
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#23 Post by sunburnt »

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:
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, 09:12, edited 3 times in total.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#24 Post by technosaurus »

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. ... 947#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 :oops:
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)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#25 Post by mcewanw »

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: Select all

#!/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
github mcewanw

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#26 Post by jamesbond »

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

cheers!
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#27 Post by technosaurus »

the musl libc wrapper has a coproc-like replacement that should work with even busybox ash
http://git.etalabs.net/cgi-bin/gitweb.c ... 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
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#28 Post by mcewanw »

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.c ... 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.
github mcewanw

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#29 Post by technosaurus »

This is the section I was referring to:

Code: Select all

[ "$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
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#30 Post by mcewanw »

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.
github mcewanw

User avatar
DocSalvage
Posts: 11
Joined: Sat 30 Jun 2012, 18:59
Location: Tallahassee, FL, USA
Contact:

#31 Post by DocSalvage »

Though this is a very old thread, let me just add that it bash 4 confuses things even more as it adds support for '|&' but it doesn't mean the same thing. It is shorthand for '2>&1 |'.

The '<>' operator creates a bidirectional pipe.

See...
http://wiki.bash-hackers.org/syntax/redirection
http://wiki.bash-hackers.org/howto/redirection_tutorial
http://www.tldp.org/LDP/abs/html/io-redirection.html
[i][color=blue]DocSalvager (a.k.a. DocSalvage)[/color][/i]
[url]http://www.docsalvage.info[/url], [url]http://www.softwarerevisions.net[/url]

Post Reply