#!/bin/bash
 
tmp=/tmp/menu-convert.tmp

function conv () {
 fromfile=$1
 
 if test -f "$fromfile"; then
   (echo 'function f () { 
      needs=$1;shift
      section=$1;shift;shift
      icon=$1;shift
      title=$1; shift
      command=$*
      if test $needs = "X11"; then
        needs="x11"
      fi
      if test "$4" = "none"; then
        echo "?package("'$fromfile'"):"needs=\"$needs\" \
             sectionb=\"$section\" \
	     title=\""$title"\" \
	     command=\""$command"\"
      else
        echo "?package("'$fromfile'"):"needs=\"$needs\" \
             section=\""$section"\" \
   	     icon=\""$icon"\" \
	     title=\""$title"\" \
	     command=\""$command"\"
     fi
    } ';\
    sed -e "s/#.*$//" $fromfile|sed -e "/[^ ]/s/^/f /"\
                                    -e 's/[()]/\\&/g' \
                                    -e 's/["]/\\\\\\\"/g')|sh > $tmp
   mv $tmp $fromfile  
 else
   echo File "$fromfile" doesn"'"t exist
 fi
}

if test "$*" = ""; then
  echo "usage: file-to-convert ..."
  echo "converts from old to new format. Overwrites the old files."
else
  for f in $*; do
    conv $f;
  done
fi

