[haiku-development] VIm episodes: I. How to guess the name of parent process ...

  • From: Siarzhuk Zharski <zharik@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Wed, 01 Apr 2009 23:44:50 +0200

Hi all!

I have build Vim 7.2 with BeOS GUI on Haiku. Current version of BeOS GUI code in Vim 6.4 use following trick to determine if Vim was started from the Tracker:
---------
   /*
    * XXX Try to determine whether we were started from
    * the Tracker or the terminal.
    * It would be nice to have this work, because the Tracker
    * follows symlinks, so even if you double-click on gvim,
    * when it is a link to vim it will still pass a command name
    * of vim...
    * We try here to see if stdin comes from /dev/null. If so,
    * (or if there is an error, which should never happen) start the GUI.
    * This does the wrong thing for vim - </dev/null, and we're
    * too early to see the command line parsing. Tough.
    * On the other hand, it starts the gui for vim file & which is nice.
    */
   if (!isatty(0)) {
   struct stat stat_stdin, stat_dev_null;

   if (fstat(0, &stat_stdin) == -1 ||
       stat("/dev/null", &stat_dev_null) == -1 ||
       (stat_stdin.st_dev == stat_dev_null.st_dev &&
        stat_stdin.st_ino == stat_dev_null.st_ino))
       gui.starting = TRUE;
   }
---------

But this doesn't work with Haiku.

Note that contents of argv[0] in case starting from Tracker is equal to "vim" both for "gvim" and "evim" links to vim binary.

I have found that call

---------
team_info teamInfo;
get_team_info(getppid(), &teamInfo);
---------

fill the teamInfo.args with "/boot/beos/system/Tracker" in case of call from Tracker and "/bin/sh --login" for call from Terminal. This code snippet can help me to resolve the "Tracker run question" by searching for "Tracker" sub-string. Is it correct enough?

Are there better ways to handle this situation?

Is this correct at all, always start GUI Vim from Tracker?

The only correct way I see now is installing the set of shell scripts (gvim, evim, rvim ...) with corresponding command line parameters. Are there any objections against it?

Thank you for attention!

Kind Regards,
 S.Zharski.


Other related posts: