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 Mon 22 Oct 2018, 17:32
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Gtkwialog project
Post new topic   Reply to topic View previous topic :: View next topic
Page 4 of 7 [96 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, 7 Next
Author Message
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sat 02 Jun 2018, 11:00    Post subject:  

I've translated quite a few of the gtkdialog examples from zigbert's Gtkdialog Tips thread to use gtkwialog -b mode.

I did it in a hurry so haven't checked if my converted versions will also all run on systems with dash as system shell - but most will; I think a couple might need a few more tweeks. Find them in post 4 of this thread here. Hopefully they will help you convert your own programs should you want to try running them on distributions that have dash or ash or bash as their system shell:

http://www.murga-linux.com/puppy/viewtopic.php?p=993443#993443

I'm going to make a start converting some of my own programs now.

wiak
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3485
Location: holland

PostPosted: Sat 02 Jun 2018, 13:14    Post subject:  

Hi wiak, Just want to say (again) that you've done a great job, not only your discovery resulting in creating gtkwialog, but also the excellent documentation, examples, technical background, etc... etc... Hats Off !

One thing I wonder about, looking at your DebianDog/gtkwialog repository:
I see 7 commits from you containing change of Readme and some more, but are the differences for gtkwialog compared to original gtkdialog there ?

Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sat 02 Jun 2018, 18:57    Post subject:  

fredx181 wrote:

One thing I wonder about, looking at your DebianDog/gtkwialog repository:
I see 7 commits from you containing change of Readme and some more, but are the differences for gtkwialog compared to original gtkdialog there ?
pu
Fred


Not yet, Fred, been too busy and since considering minor code tweeks and not actually using github during my developments I'm not quite ready to push the source code there yet. But will happen soon enough. There is one particular area of code in gtkdialog I want to double-check how it works, just in case I've missed something, and also I want to convert a couple of my apps just as a double check. I've been converting precord, which has quite a lot of bash-related export code so a good test - haven't quite finished it yet. After that I'll push up the source code since it will be ready for proper testing and recompiling and pull requests and so on.

wiak
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sun 03 Jun 2018, 02:45    Post subject:  

What an amazing job Thunor did of re-factoring the original gtkdialog code. I've been reading through some of it and the amount of work he did is far more enormous than any non-C programmer would imagine. It was far from just better implementing the Widgets to more closely match their inherent GtkDialog system capabilities. It would take a near obsession to learn the whole inner-workings of gtkdialog that Thunor obviously did.

My addition is simple, but is hopefully very useful for the very small effort I needed to expend implementing it. Most of my effort was simply background research to try find out why bash -f export didn't work well with gtkdialog - and looking at YAD code gave me the simple solution to that - just a small number of changes needed to gtkdialog itself over a very few files and thus with predictable results since nothing else needed to be touched (so far anyway... luckily).

Just a pity, I feel, that gtkdialog hadn't been written to use vbox and hbox constructions with simple curly bracket groupings (instead of pseudo xml tags) as used in IUP (with Lua and the other languages it supports), which is much nicer to program in (simpler, easier to read, supports comments, and harder to make mistakes in).

wiak
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sun 03 Jun 2018, 06:14    Post subject:  

One, apparently rare, limitation found using gtkwialog on systems that do not use bash as the underlying system shell /bin/sh
(and legacy gtkdialog has that limitation anyway)

I spent one hour tonight converting Precord to use gtkwialog -b. That went fine and worked perfectly when underlying system shell was bash (which is no big deal since old version worked under legacy gtkdialog too with bash as system shell...).

But when I changed /bin/sh to be dash, the legacy gtkdialog version simply couldn't work at all because Precord is written in bash and uses a great many bash export -f functions. That being of course known and expected... But:

Though all the <action> contructs in the gtkwialog -b version of Precord can all find these functions, there is one other construct that happens to be used in current Precord that also calls up one of the bash functions and that is the <input> tag in one of the entry widgets (which calls bash function DateFile1). Unfortunately, none of the code I have added helps with that <input> tag situation, so that is a current limitation. Indeed, despite studying the code, I frankly do not yet know how <input> calls up exported functions - it is certainly not via the system() call.

I can only surmise, from the complex code involved, that it directly reads the function code from the shell environment, via perhaps a gtk library call, and then sends that function code to be processed via the mechanisms I have optionally modified. If so, legacy gtkdialog <input> command processing may expect a shell to interpret the function via system(), which does of course only work if underlying system shell is bash. So calling bash functions from <input> constructs certainly won't work with legacy gtkdialog.

Unfortunately, if my surmise turns out to be correct, then because the execution of that bash exported function requires an instance of bash to be running, which isn't the case with the gtkwialog -a or -b mod glib async or sync calls either (which don't call up any shell process) then that construct simply cannot work whichever mode is used when bash is not the underlying system shell. It is a small limitation, but one that has to be borne in mind.

In summary:

Though gtkwialog -b (or -a) mode can be used to convert many or even most legacy gtkdialog apps to work with dash, it does currently have at least this one newly found limitation:


Quote:
you cannot call bash functions from <input> tags, only from <action> tags if underlying system shell is dash. There may be similar limitation; just remember -a and -b modes are specifically mainly related to <action>tag commandline_string opertion

I will have to therefore make a slight modification to Precord to workaround that remaining dash-related issue.

The easiest way around this for new programs is to never use exported bash functions in <input> tags.

Example of code that will not work when dash is the system shell:

Here is a simple exemplar program that will work using /bin/sh as bash but not when /bin/sh is dash, despite gtkwialog -b being used. Doesn't work with legacy gtkdialog either of course, when /bin/sh is dash:

Code:
#! /bin/bash

hello (){
 echo "hello world"
}
export -f hello

export MAIN_DIALOG='
<vbox>
 <entry>
  <variable>ANYTHING</variable>
  <input>hello</input>
 </entry>
</vbox>
'

gtkwialog -b --program=MAIN_DIALOG


I'll write more on this limitation if I find more or any solution in code, but truthfully I think it probably has to be accepted as a limitation of both gtkdialog and gtkwialog. Fortunately, it is a limitation that can easy be avoided in the case of gtkwialog; not gtkdialog which cannot work at all with dash as system shell when bash exported functions being used anywhere.

Hopefully you understand what I'm talking about, but if not, just accept that as one limitation that has to be avoided if writing dash compatible apps in this manner.

I'm now looking through some other familiar bash/gtkdialog to see which will suffer from this limitation. I'll list any I've looked at here:

1. peasywifi, does not use <input> tags in the above manner so should convert nicely with gtkwialog -b for use with underneath dash shell (though its shebang would also need changed to #!/bin/bash for the exported functions to work.

2. My program cast2chrome should also convert nicely.

3. As fredx181 has I believe already proved, debdog-install (and xenialdog-install) should convert nicely (don't think these call exported functions anyway)

4. My program domyfile should convert nicely.

5. Despite being derived from Precord (albeit a long chain of ancestry) it looks like weX will convert nicely.

6. peasypdf should convert nicely (and probably most peasy apps).

7. ffconvert looks like it will convert okay.

Hmmm... I can't find any other problematic ones... only Precord... trust me to try to convert that first! Wink

Quite a number of old Puppy util/apps don't use bash export -f at all, so they shouldn't generally need to be converted at all - just use gtkwialog in legacy mode (needs no switch for that).

Oh well, time will tell - I'll try converting cast2chrome next and come back to finish Precord later. If there is any particular app you'd like me to check (and maybe even convert), just let me know.

All going well with a couple of conversions in the next few days, I'll upload the source code to the DD organization github repository thereafter since I'm not planning any non-compatible changes if most basically converting fine.

wiak
Back to top
View user's profile Send private message 
anikin

Joined: 10 May 2012
Posts: 1020

PostPosted: Sun 03 Jun 2018, 10:58    Post subject:  

wiak,

1. Can you, please have a look at the original mount-wizard script (see attachment). It is fred's mod of iguleder's script, that I brought to old DD. Will it work under dash? Unfortunately, It's been removed from the repos.

2. Please, also have a look at peasyglue - will it work with dash?

Thank you in advance,
mount-wizard.gz
Description 
gz

 Download 
Filename  mount-wizard.gz 
Filesize  1.96 KB 
Downloaded  54 Time(s) 
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sun 03 Jun 2018, 11:33    Post subject:  

I'll have a try tomorrow anikin cos its late night/morning here. I'm pretty sure peasyglue will work. Have to check out mount wizard.

Just got Precord running with dash as system shell underneath - first time I've had that on dash system, though did need slight tweak I mentioned in earlier post.

wiak
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3485
Location: holland

PostPosted: Sun 03 Jun 2018, 11:41    Post subject:  

Hi wiak, I had a look at pburn and it seems the only exported function is in /usr/local/pburn/box_tail and it has "tailing" exported to a <input>.... line
If you have time, can you have a look ?

Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sun 03 Jun 2018, 11:41    Post subject:  

@anikin: what is the issue with that mount-wizard with dash anyway. I can't see what existing problem would be at a glance. There are no export -f functions in it, which is main problem gtkwialog solves (allows bash exported functions). If its some kind of permission problem that would be a different matter altogether; please let me know.

peasyglue, on the other hand, needs gtkwialog -b, and I'll try that out - it should work then.

wiak
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sun 03 Jun 2018, 11:42    Post subject:  

fredx181 wrote:
Hi wiak, I had a look at pburn and it seems the only exported function is in /usr/local/pburn/box_tail and it has "tailing" exported to a <input>.... line
If you have time, can you have a look ?

Fred


Yep, I'll add that to tomorrows list. If there is an <input> issue it can always be worked around as I managed with Precord.

EDIT: I see what you mean, in the while construct... tailing. Yes, that'll need a workaround I think. I'll try tomorrow later - can be done that's for sure.

wiak
Back to top
View user's profile Send private message 
anikin

Joined: 10 May 2012
Posts: 1020

PostPosted: Sun 03 Jun 2018, 12:06    Post subject:  

@wiak

My bad, I must have panicked and confused myself and you. Mount-wizard does work with both dash and bash. Thank you for setting this straight!
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sun 03 Jun 2018, 12:19    Post subject:  

Code:
#! /bin/bash
printf '
 #!/bin/bash
 echo "hello world"
' >/tmp/hello
chmod +x /tmp/hello


export MAIN_DIALOG="
<vbox>
 <entry>
  <variable>ANYTHING</variable>
  <input>/tmp/hello</input>
 </entry>
</vbox>
"

gtkwialog -b --program=MAIN_DIALOG


Or better maybe sometimes to use a HERE document instead of printf:

Code:
cat >/tmp/hello <<'here_hello_function'
#! /bin/bash
echo "hello world"
here_hello_function
chmod +x /tmp/hello


Single quoting the <<'here_hello_function' to turn off parameter substitution in the HERE document body.

The above is a workaround to the <input> bash exported function issue I posted a few posts back. There may be better ways, but above method worked well even with a big function.
It's the same methodology I employed with that one problem exported bash function in Precord. This is just a simple example but really the same method. In Precord the /tmp/file I created actually had two functions in it. Pretty simple when only one <input> with that issue. Pburn should work likewise I'd say.

wiak

Last edited by wiak on Tue 05 Jun 2018, 07:07; edited 3 times in total
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3485
Location: holland

PostPosted: Sun 03 Jun 2018, 13:42    Post subject:  

Hi wiak, I took on pfind to convert (I thought it should be less complicated than pburn)
It turned out to be a real challenge (for me anyway cos I'm a gtkdialog noob), replaced every instance of gtkdialog with "gtkwialog -b" in all related scripts (and sh symlinked to dash of course), but just doesn't work, the Search button does nothing.
I suspect at least some <action> or <input> lines are containing other bashism's than exported functions, but not sure.
I tried with this pfind:
https://fredx181.github.io/StretchDog/i386/Packages/Included/pfind_6.3_all.deb
(newer version than included in e.g. Xenialdog)

EDIT: I think I suspected right, e.g. this (in /usr/local/pfind/pfind):
Code:
 <action>. '$PROGPATH'/func -search</action>

Should probably become something like this:
Code:
 <action>bash -c ". '$PROGPATH'/func -search"</action>


EDIT2: There's checkbashisms (part of package "devscripts"), but unfortunately it doesn't work to check for bashisms inside <action>..</action>
https://linux.die.net/man/1/checkbashisms

Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sun 03 Jun 2018, 19:54    Post subject:  

fredx181 wrote:

I suspect at least some <action> or <input> lines are containing other bashism's than exported functions, but not sure.


Yes, that could be the issue you've come across. Of course if '<action>commandstrings' contain bashisms they are going to need bash -c (with gtkwialog -b mode) to interpret them), so not just for export -f cases, that's true.

But it's also the case that if an '<action>commandstring' requires a shell to do file expansion or job control, for example, either sh -c or bash -c will be required by gtkwialog in the -b mode (since that mode does not itself exec any shell automatically). The command mode -b glib mechanism does do UNIX style parsing, but:

Quote:
Parses a command line into an argument vector, in much the same way the shell would, but without many of the expansions the shell would perform (variable expansion, globs, operators, filename expansion, etc. are not supported).


Hence '<action>commandstring' entries that need filename expansion or such need to include an appropriate (sh -c or bash -c) shell command at the front.

I'll add pfind to my list Wink But this list may take a while to look at...

My own bash/gtkdialog programs (and most of rcrsn51's peasy scripts) do not contain that external file function method so will generally be easy to convert (since mainly just the export -f situation to deal with). Problem with the split file function method is that there are so many of them(!) so you have to grep the whole folder looking for suspects...

Then I generally load suspect files up in geany and use search/replace with search term <action> and replace term <action>bash -c " and 'carefully' use the Find button to take a look before I commit anything (and finish off by putting a " symbol at the end - though I sometimes adjust replace term with sh -c if bash -c not required) but hopefully I'll work out a more automatic convert method eventually... I also thereafter do a quick search through the <input> lines, though usually not many of these. Have you any quicker technique?

wiak
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 957
Location: not Bulgaria

PostPosted: Sun 03 Jun 2018, 20:11    Post subject:  

Are you sure that line you mention in pfind is actually a bashism. It does contain '.' (source in bash) so does need a shell. I'd think this is what is required for that line (including the double/single start/end quote syntax shown:

"'<action>sh -c ". '$PROGPATH'/func -search"</action>'"

If it's a bashism should be bash -c. Either way the shell command is needed at the front here to interpret the '.'

I note there are a few other <action> lines in pfind that contain that '.' at the beginning.

wiak
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 4 of 7 [96 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, 7 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.0716s ][ Queries: 14 (0.0105s) ][ GZIP on ]