some linux related questions

Started by handsource-dyko, November 23, 2010, 07:04:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

handsource-dyko

Today I was testing my malvado editor project under linux, and I ran in some issue.
Everything works well as expected, in both native linux as well as wine, except for one thing.

In my editor I added a feature to launch external programs, for wich I call a batch file/shell script
with the exec function.

The exec function works perfectly for calling bgdi with a dcb file, but failed on executing a shell script.
Under windows it works fine. It's not a case sensitivety issue. I also tried adding "./" for the filename.

Here's the code:





//-----------------------------------------------------------------------------
// Process used for viewing the helpscreen
// Entries: -
//         
//-----------------------------------------------------------------------------   
PROCESS help();

PRIVATE
int normalgraph;

string arg[2];

string winpath="mapedithelp.bat";
string unixpath=".\mapedithelp.sh"; // doesn't work
//string unixpath="mapedithelp.sh:; // doesn't work either

BEGIN

   // check if some other routine is buisy.
   IF (working==FALSE)
   
       // disable (hide) the buttons
       gui_show(FALSE,M_MAINMENU);
   
       // set initial state
       action_init();
       
       FRAME(1000);
       delete_text(all_text);
         
       // call the bennu interpreter  with the 1 argument:
       // 1: the name of the program, wich invokes a bath file or shellscript,
       // wich starts the webbrowser with the help file.
       // detect the os, print warning message if applicable.
       SWITCH (os_id)
   
         
   
      CASE OS_LINUX:
         say("");
                  say("OS detected: LINUX");
                  exec(_P_NOWAIT,unixpath,3,&arg);
      END
 
   
      CASE OS_WIN32:
         say("");
                  say("OS detected: Microsoft windows");
                  exec(_P_NOWAIT,winpath,3,&arg);
      END
         END
       
         // update the state, reactivate the selection cursor, and delete the text.
         action_state_cleanup();
     END
END




Contents of the batchfiles:

(mapedithelp.bat)

"C:\Program Files\Mozilla Firefox\firefox.exe" dev-docs\development-manual.html

rem path for win64 users
rem "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" dev-docs\development-manual.html


(mapedithelp.sh)

firefox dev-docs/development-manual.html



(The shell script mapedithelp.sh works fine when I execute it from the shell).

Anyone got a clue on this? It's been quite a few years ago that I really used linux and I'm
a an expert on bash and shell scripts. I just thought I would work. I tested this on Ubuntu.

josebita

It's probably that ".\mapedithelp.sh" should be "./mapedithelp.sh" :)
Also, I'd modifyt the launch script to be like this:

[code language="bash"]#!/bin/bash
xdg-open dev-docs/development-manual.html[/code]

xdg-open will open the user's default browser and it's present in most modern linux distros.

And be sure, to give the script execution permissions (chmod a+x mapedithelp.sh)

handsource-dyko

Thanks, I made the changes.

I didn't now there was a command for starting the default browser.
However, I was unable to test it, because my ubuntu installation is slightly messed up.
There's is some problem with the shell not being able to find bash in the bin directory,
even when it's actually there. I have more issues with shellscripts under unbuntu.

Maybe I messed up my user profile.

O, I just though of something usefull for gui's in bennu programs: zenity.
I believe it's on most linux distro's and I've downloaded the windows version of it.
Maybe I can use that in combination with the exec function, so that I don't have
write a file dialog myself.

handsource-dyko

How stupid of me, there's nothing wrong with my ubuntu installation.... :D

It appears that the shell doesn't like shell scripts to be formatted in MS DOS encoding.
This is the reason that bash threw all sorts of error messages at me. I just assumed
it didn't matter. It seems it want shell scripts to be in unix format.

This sort of thing is not that obvious, and is one of those pesky things about linux/unix
being not a very user friendly system, although it is a great OS, but not really for the
avarage joe.

(Especially case senstive filenames, I dislike that, there's no compelling reason for this to exist
in a modern os, it is only annoying to users, I guess the orginal unix programmers where too
lazy to do a case insensitive string comparision, something that the first mac did right
way back in 1984, I mean how hard can it be to treat ascii values 65 and 97 to be the character 'A',
no matter the case).  ;D

josebita

Well, you should try to run a Unix formatted DOS batch file in windows... it won't run either :)

And for the case-sensitiveness, I see it more like a convention. Once you get used to it it just feel right. The same thing happen with the folder bars "\" vs "/". Everybody does it the right way, except for windows :P

kruz

Just a side note, I was using vim at home and gvim for Windows at work to create .cmd and .bat files, they executed fine in Windows and GNU/Linux as well.  Vim does well of not adding the special characters in plain text files.  Most .cmd files can also have the /path/to/exe.exe and it should work fine.  At least the majority of my scripts did.

handsource-dyko

Luckely Notepad++ allows for easy conversion of line endings.
I simply thought It wouldn't matter, but I now I know.

My personal solution to case sensitivity is to only use lowercase
characters for filenames.

Maybe a good suggestion/tip for bennu users in general, be consistent
with cases in filenames and how you refer to them in your sourcecode.

Any mismatch of case results in the file not being loaded  on unix and
linux based systems, while it don't matter on windows. (I learned the
hard way). This practice will ensure good portability. Especially because
the GPE wiz is linux based and development is more often done on
windows because of the tool anvailibility.

kruz

That is an excellent point and just to add to that, when saving files in Windows, for some reason I find that some applications like to give the extension capitalized if you do not type it in manually.  eg. filename.PNG or filename.PRG instead of .png or .prg