[Gambas-devel] Gambas 1.9.46 Help

Stefano Palmeri rospolosco at ...29...
Wed Nov 15 15:51:19 CET 2006


Alle 11:48, mercoledì 15 novembre 2006, Benoit Minisini ha scritto:
> On Tuesday 14 November 2006 22:35, Fabien Bodard wrote:
> > this is the corrected Functions.
> >
> > There were three errors
> > First one is the env variable name (it miss _DESKTOP_)
> > Second one: ubuntu and some other distrib not have epiphany so i've added
> > firefox in second case in the gnomedesktop select.
> >
> > Third one was That the which program don't return anything when the
> > required program not exist in debian like distribs.
> >
> > I've done some cleaning on the data receipt (use of the TO key with SHELL
> >
> >
> > PUBLIC FUNCTION CheckProgram(sProg AS String) AS Boolean
> >
> >   DIM bError AS Boolean
> >   DIM iPos AS Integer
> >   DIM sVal AS String
> >
> >   iPos = InStr(sProg, " ")
> >   IF iPos THEN sProg = Left(sProg, iPos - 1)
> >
> >   SHELL "which " & sProg TO sVal
> >
> >   bError = sVal LIKE "which: *" OR IsNull(sVal)
> >
> >   RETURN bError
> >
> > END
> >
> >
> > PUBLIC SUB OpenWebPage(sLink AS String)
> >
> >   DIM sExec AS String
> >   DIM aTest AS String[]
> >   DIM bCheck AS Boolean
> >
> >   IF NOT Browser THEN
> >
> >     SELECT CASE Settings["/Browser"]
> >
> >       CASE "konqueror"
> >         aTest = ["konqueror"]
> >
> >       CASE "epiphany"
> >         aTest = ["epiphany"]
> >
> >       CASE "firefox"
> >         aTest = ["firefox", "mozilla-firefox"]
> >
> >       CASE "seamonkey"
> >         aTest = ["seamonkey"]
> >
> >       CASE ELSE
> >
> >         aTest = [Application.Env["BROWSER"]]
> >
> >         IF Application.Env["KDE_FULL_SESSION"] THEN
> >           aTest.Add("konqueror")
> >         ELSE IF Application.Env["GNOME_DESKTOP_SESSION_ID"] THEN
> >           aTest.Add("epiphany")
> >           aTest.Add("firefox")
> >         ENDIF
> >
> >     END SELECT
> >
> >     aTest.Add("konqueror")
> >     aTest.Add("mozilla-firefox")
> >     aTest.Add("firefox")
> >     aTest.Add("mozilla")
> >     aTest.Add("seamonkey")
> >     aTest.Add("opera")
> >
> >     FOR EACH sExec IN aTest
> >       bCheck = NOT CheckProgram(sExec)
> >       IF bCheck THEN BREAK
> >     NEXT
> >
> >     IF NOT bCheck THEN RETURN
> >
> >     Browser = sExec
> >
> >   ENDIF
> >
> >   IF Left(sLink) = "/" THEN
> >     sLink = "file://" & Replace(sLink, "?", "%3F")
> >   ENDIF
> >
> >   SHELL Browser & " " & Chr$(34) & sLink & Chr$(34)
> >
> > CATCH
> >
> >   Message.Error(Error.Text)
> >
> > END
> >
> > Regards,
> >
> > Fabien Bodard
> 
> Merci Fabien!
> 
> -- 
> Benoit Minisini

Hi, Benoit. 

We had this discussion on the Gambas italian mailing list. Carlo Sorda
suggested to use the exit code of which, that should be consistent
in all distros. I think something like this:

PUBLIC FUNCTION CheckProgram(sProg AS String) AS Boolean

   DIM bError AS Boolean
   DIM iPos AS Integer
   
   iPos = InStr(sProg, " ")
   IF iPos THEN sProg = Left(sProg, iPos - 1)

   SHELL "which " & sProg & " &> /dev/null" WAIT
   
   bError = CBool(Process.LastValue) 

   RETURN bError

END


Anyway, in Fabien's code I should add:

 sVal = Trim$(sVal)

as it was in your original code, to avoid other new problems
with which's output.

Best regards,

Stefano Palmeri


> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Gambas-devel mailing list
> Gambas-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-devel
> 




More information about the Devel mailing list