FVWM: Small enhancement to Read: Read "| command"

From: Jacques Gelinas <jack_at_solucorp.qc.ca>
Date: Sun, 21 Apr 1996 00:42:37 -0400 (EDT)

I am toying with the reconfiguration of menus "as needed" since the last
thread "tvtwm reload menu file when they change". The scheme I am using
now is pretty simple and work with the following function

AddToFunc fixmenu
+ "I" Read "| .fvwmdir/sh/reread $0"
+ "I" Menu $0 Nop

*FvwmButtons Apps xchess.xpm fixmenu user

As you see, I have extended slightly the Read command to do a popen as
needed. My script .fvwmdir/sh/reread compose a menu and compare it with
what it has previously sent to fvwm. If it is the same, it does nothing.
If it is different, it send a destroymenu command, followed by
"addtomenu"'s command to reprogram the menu.

Currently "reread" is a script. I will rewrite it in C to make it lighter.
On my Linux DX/2 system, this is already quite confortable.

Here is the patch, followed by the script reread.

btw, I find the idea of reloading menu as needed quite nice. At the office,
we are installing quite a few new users on linux-based X terminals. We are
giving them a standard setup at first. It is a tool bar with few predefined
menus. I will define the first button of the tool bar to be a global menu
containing standard tool/feature everybody should have. The nice thing about
this is that I can manage the menu definition and I don't have to tell all
users to do a reload. It is done transparently. This avoid repeating that a
new command/tool is now available on the network.

Comments appreciated :-)

---patch to fvwm/read.c------
*** fvwm-2.0.42/fvwm/read.c Fri Mar 22 15:33:21 1996
--- fvwm-2.0.42-pipe/fvwm/read.c Sat Apr 20 23:55:33 1996
***************
*** 54,60 ****
  
    filename = ofilename;
  
! fd = fopen(filename,"r");
    if((fd == NULL)&&(ofilename[0] != '/'))
      {
        /* find the home directory to look in */
--- 54,67 ----
  
    filename = ofilename;
  
! if (filename[0] == '|')
! {
! fd = popen (filename+1,"r");
! }
! else
! {
! fd = fopen (filename,"r");
! }
    if((fd == NULL)&&(ofilename[0] != '/'))
      {
        /* find the home directory to look in */
***************
*** 122,128 ****
          AddToModList(tline);
        tline = fgets(line,(sizeof line)-1,fd);
      }
! fclose(fd);
    if(thisfileno == 0)
      {
        CaptureAllWindows();
--- 129,142 ----
          AddToModList(tline);
        tline = fgets(line,(sizeof line)-1,fd);
      }
! if (filename[0] == '|')
! {
! pclose (fd);
! }
! else
! {
! fclose (fd);
! }
    if(thisfileno == 0)
      {
        CaptureAllWindows();
---------------------------------------------

-----------reread script---------------------
#!/bin/sh
MENU=$1
TEMP=.fvwmdir/tmp/$MENU.loaded

upd_menufile()
{
        FICH=$1
        if ! cmp -s $FICH $TEMP ; then
                if [ -f $TEMP ] ; then
                        echo DestroyMenu $MENU
                fi
                cp $FICH $TEMP
                cat $FICH
        fi
}

upd_menudir()
{
        DIR=$1
        BUILD=$TEMP.build
        echo AddToMenu $MENU $MENU Title >$BUILD
        for i in `(cd $DIR; ls)`
        do
                if [ -x $DIR/$i ] ; then
                        echo + \"\" Nop >>$BUILD
                        if [ -f /usr/lib/X11/icons/$i.xpm ] ; then
                                echo + $i\%$i.xpm exec $DIR/$i >>$BUILD
                        elif [ -f $DIR/$i.xpm ] ; then
                                echo + $i\%$DIR/$i.xpm exec $DIR/$i >>$BUILD
                        else
                                echo + $i\%tools.xpm exec $DIR/$i >>$BUILD
                        fi
                fi
        done
        if ! cmp -s $BUILD $TEMP ; then
                if [ -f $TEMP ] ; then
                        echo DestroyMenu \"$MENU\"
                fi
                mv $BUILD $TEMP
                cat $TEMP
        fi
}



if [ -f .fvwmdir/menus/$MENU ] ; then
        upd_menufile .fvwmdir/menus/$MENU
elif [ -f /usr/lib/X11/fvwm2/menus/$MENU ] ; then
        upd_menufile /usr/lib/X11/fvwm2/menus/$MENU
elif [ -d .fvwmdir/menus/$MENU ] ; then
        upd_menudir .fvwmdir/menus/$MENU
elif [ -d /usr/lib/X11/fvwm2/menus/$MENU ] ; then
        upd_menudir /usr/lib/X11/fvwm2/menus/$MENU
fi
----------------------------------------------------


--------------------------------------------------------
Jacques Gelinas (jacques_at_solucorp.qc.ca)
Use Linux without reformating: Use UMSDOS.


--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_hpc.uh.edu.
To report problems, send mail to fvwm-owner_at_hpc.uh.edu.
Received on Sat Apr 20 1996 - 23:39:02 BST

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:37:58 BST