
# $Id: edmakexite,v 1.11 2013/09/25 14:03:32 svein Exp $

BEGIN {
  printed = 0;
  binline = 0;
  dirline = 0;
}

/^case "\$XITE_HOSTTYPE" in/, /^esac/ {
   if (binline != 0) {
      print;
      next;
   }

   if ( substr($1, 1, length($1)-1) == xite_hosttype ) {
      binline=NR;
      print;
      next;
   }

   if ($1 == "*)" && binline == 0) {
      print "    " xite_hosttype ")";
      print "        except=" "\"" exceptions "\";;";
      print;
      next;
   }
}

/if \[ ! -d "\$dir" \\/, /then/ {
   if (dirline != 0) {
      print;
      next;
   }

   if ( substr($4, 2, length($4)-2) == xite_hosttype ) {
      dirline=NR;
      print;
      next;
   }

   if ($2 == "then" && dirline == 0) {
      ORS = "";
      print "        -o \"$dir\" = \"";
      ORS = "\n";
      print xite_hosttype "\"" " \\";
      print;
      next;
   }
}

{
   if ( $1 == "XITE_HOME=" && NF == 1) {
      if (home == "#") {
      	 print "#    " $1 home;
      } else {
      	 print "    " $1 home;
      }
      printed = 1;
   }

   if (! printed) print $0;
   else printed = 0;
}
