/* This file is part of the origami distribution. (Amiga Port)
 *
 * Source code written by Thomas Hadig in September 1991
 * Version : 1.6.92.1, February 1994
 * (C) 1991-94 by Thomas Hadig
 * may be distributed unchanged ! (see copyright notes)
 */

/*{{{}}}*/
/*{{{  #includes*/
/*{{{  standard includes*/
#include <exec/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <limits.h>
/*}}}  */

/*{{{  amiga system includes*/
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <intuition/screens.h>
#include <exec/io.h>
#include <devices/timer.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <dos.h>
/*}}}  */
/*{{{  amiga prototype includes*/
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/console_protos.h>
#include <clib/icon_protos.h>
#include <clib/dos_protos.h>
#include <clib/graphics_protos.h>
/*}}}  */

#define INITRESET_C
#define I_SIGNALS_C
#define I_PROMPT_C
#define I_GETTK_C
#define I_KEYTAB_C
#define I_MAIN_C
#define I_FOLDING_C
#define I_VIRTUAL_C
#define I_SCREEN_C
#define I_GETMSG_C
#define I_INIT_C
#define I_MESSAGES_C
#define I_LOOP_C
#define I_BUFFLOOP_C
#define I_DISPLAY_C
#define I_STRING_C

#include <origami/origami.h>
#include <h/envvar_str.h>

#include <graphics/gfxbase.h>
#include <amiga/h/ori_arexx.h>
/*}}}  */

/*{{{  variables*/
/*{{{  menu variables*/
#ifdef MENU
  public boolean     menu_on = False;
  public struct Menu *menu_root=(struct Menu *)0;
#endif
/*}}}  */
/*{{{  arexx variables*/
#ifdef AREXX
  public boolean arexx = False;
  public _AREXX *_arexx=(_AREXX *)0;
  public struct Library *RexxSysBase;
#endif
/*}}}  */
#define MAX_NUM_WORKBENCH_ARGS 32
private char **arg_ptr=(char **)0;
/*{{{  window & screen global variables*/
private struct Screen   *my_screen;
private struct IOStdReq isr;
public struct Screen    *beep_screen=(struct Screen *)0;
public struct Window    *wind;
public struct RastPort  *rp;

public short   screenw=0,screenh=0,windx=0,windy= -1,windw=0,windh=0,
               height, mul_x=1,mul_y=1,off_y=1,off_y_base=0, init_wind=0;
public boolean screen_yes = False;
public char window_name[_POSIX_PATH_MAX+1] = "Origami";
/*}}}  */
/*{{{  get key global variables*/
public struct MsgPort     *mpp=(struct MsgPort *)0;
public struct timerequest *tr=(struct timerequest *)0;
public ULONG              my_signal=0;
/*}}}  */
/*{{{  Libraries*/
struct Library         *ConsoleDevice;
struct Library         *IconBase;
#ifdef CUTPASTE
struct Library         *IFFParseBase=(struct Library *)0;
#endif
extern struct GfxBase  *GfxBase;   /* will be opened by the startup-code */
extern struct IntuitionBase *IntuitionBase;
long __OSlibversion=37;
/*}}}  */
/*{{{  startup-variables*/
private struct WBStartup *old_argv = (struct WBStartup *)0, **old_argv_addr;
char  *__procname = "Origami-Editor";
long  __stack = 25000L, __priority = 0, __BackGroundIO = 1;
extern BPTR _Backstdout;
/*}}}  */
/*{{{  MOUSY*/
#ifdef MOUSY
mouse_typ use_mouse=amiga;
public int mouse_b_count[mouse_supports]=
 { 0
      ,AMIGA_MOUSE_COUNT
 };
#ifdef AMIGA_MOUSE_TAG
  char *a_m_n[]=AMIGA_MOUSE_NAMES;
#  define A_M_N   ,a_m_n
#endif
public char **mouse_b_names[mouse_supports]=
 { 0
   A_M_N   /* Amiga-names */
 };
#endif
/*}}}  */
extern int __msflag;
extern int opterr;
/*}}}  */

void __regargs __chkabort(void) {}
/*{{{  get icon tool types (get_tool_args)*/
private int get_tool_args (struct DiskObject *dis, int pos)
 {
  char *ptr;
  int i = 0;

  while (ptr = dis->do_ToolTypes[i])
   {
    if ((pos<MAX_NUM_WORKBENCH_ARGS-1)&&(*(stpblk (ptr))!=0x00))
      if (!(arg_ptr[pos++]=strdup (dis->do_ToolTypes[i]))) exit (12);
    i++;
   }
  FreeDiskObject (dis);
  return pos;
 }
/*}}}  */
/*{{{  reset_amiga*/
public void reset_amiga (void)
 {
  if (init_wind&0x01) ClrScr();
  if (ConsoleDevice)
   /*{{{  close console device*/
   {
    CloseDevice ((struct IORequest *)&isr);
    ConsoleDevice = (struct Library *)0;
   }
   /*}}}  */
  /*{{{  close iffparse.library*/
#  ifdef CUTPASTE
  if (IFFParseBase)
   {
    CloseLibrary (IFFParseBase);
    IFFParseBase=(struct Library *)0;
   }
#  endif
  /*}}}  */
  if (tr)
   /*{{{  clear timer*/
   {
    if (timer_running!=False) alarm (0);
    CloseDevice ((struct IORequest *)tr);
    DeleteIORequest (tr);
    tr = NULL;
    DeletePort (mpp);
   }
   /*}}}  */
  /*{{{  only AREXX*/
#  ifdef AREXX
  if (_arexx)
   {
    struct Message *rmsg;

    *(_arexx->portname)=0;
    while (_arexx->outstanding)
     /*{{{  reply all outstanding messages*/
     {
      WaitPort (_arexx->port);
      while (rmsg=(struct Message *)GetARexxMsg())
       {
        SetARexxLastError (rmsg,"99: Port Closed !");
        ReplyARexxMsg ((struct RexxMsg *)rmsg,NULL,100);
       }
     }
     /*}}}  */
    if (_arexx->port)
     /*{{{  delete port*/
     {
      while (rmsg=(struct Message *)GetARexxMsg())
      {
        SetARexxLastError (rmsg,"99: Port Closed !");
        ReplyARexxMsg ((struct RexxMsg *)rmsg,NULL,100);
      }
      DeletePort (_arexx->port);
     }
     /*}}}  */
    if (RexxSysBase)
      CloseLibrary(RexxSysBase);
    free (_arexx);
    _arexx=(_AREXX *)0;
   }
#  endif
  /*}}}  */
  /*{{{  only Menu*/
#  ifdef MENU
  if (menu_on==True) { ClearMenuStrip(wind); menu_on = False; }
#  endif
  /*}}}  */
  if (wind) { CloseWindow (wind); wind = (struct Window *)0; }
  if (my_screen)
   /*{{{  close my screen, if there is no other window*/
   {
    if (!(my_screen->FirstWindow)) CloseScreen (my_screen);
    my_screen = (struct Screen *)0;
   }
   /*}}}  */
  if (old_argv)
   /*{{{  reset to old args*/
   {
    if (arg_ptr)
     {
      int i=1;

      while (arg_ptr[i]) free (arg_ptr[i++]);
      free (arg_ptr);
     }
    *old_argv_addr = old_argv;
    old_argv = 0;
   }
   /*}}}  */
  return;
 }
/*}}}  */
/*{{{  init_amiga_pre_arg*/
public void init_amiga_pre_arg (int *argc,struct WBStartup **argv)
 {
  /*{{{  variables*/
  /*{{{  structures*/
  struct FileInfoBlock fib;
  struct FileLock      *fl;
  struct DiskObject    *dis;
  /*}}}  */
  char   name[_POSIX_PATH_MAX],*dev=(char *)0,*ptr,f2[_POSIX_PATH_MAX],*dptr;
  int i,j;
  /*}}}  */

  /*{{{  gets font sizes*/
  mul_x = GfxBase->DefaultFont->tf_XSize;
  mul_y = GfxBase->DefaultFont->tf_YSize+1;
  off_y_base = GfxBase->DefaultFont->tf_Baseline;
  /*}}}  */
  opterr=0; /* do not send error messages to stderr (getopt) */
  if (!*argc)
   /*{{{  started form Workbench ?*/
   {
    /*{{{  malloc pointer list*/
    if (!(arg_ptr =
      (char **)malloc (MAX_NUM_WORKBENCH_ARGS*sizeof (char *))))
     {
      reset_amiga();
      exit (11);
     }
    /*}}}  */
    arg_ptr[0] = (*argv)->sm_ArgList[0].wa_Name;
    j=1;
    /*{{{  look for arguments in .info file*/
    if (IconBase = (struct Library *)OpenLibrary ("icon.library",NULL))
     {
      if (dis = GetDiskObject (arg_ptr[0])) j = get_tool_args (dis,j);
      if ((*argv)->sm_NumArgs>1)
        if (dis = GetDiskObject ((*argv)->sm_ArgList[1].wa_Name))
          j = get_tool_args (dis,j);
     }
    /*}}}  */
    i=1;
    /*{{{  get additonal filenames as arguments*/
    while ((i<(*argv)->sm_NumArgs)&&(j<MAX_NUM_WORKBENCH_ARGS))
     {
      strcpy (name,(*argv)->sm_ArgList[i].wa_Name);
      fl = (struct FileLock *)(*argv)->sm_ArgList[i].wa_Lock;
      if (arg_ptr[j] = malloc (_POSIX_PATH_MAX))
       /*{{{  add path in front of filename*/
       {
        do
         /*{{{  get complete path in front of filename*/
         {
          if (Examine ((BPTR)fl, &fib))
           /*{{{  copy oldname to f2, newname : directory[/:]oldname*/
           {
            strcpy (f2, name);
            strcpy (name, fib.fib_FileName);
            if ((strlen (name))&&(name[strlen (name)-1]!='/')&&
                (name[strlen (name)-1]!=':'))
              strncat (name, "/",_POSIX_PATH_MAX-strlen(name));
            strncat (name, f2, _POSIX_PATH_MAX - strlen(name));
           }
           /*}}}  */
         } while (fl = (struct FileLock *)ParentDir ((BPTR)fl));
         /*}}}  */
        if (ptr = strchr (name,'/')) ptr[0]=':';
        strcpy (arg_ptr[j++], name);
       }
       /*}}}  */
      i++;
     }
    /*}}}  */
    arg_ptr[j] = (char *)0;
    *argc = j;
    old_argv_addr = argv;
    old_argv = *argv;
    *argv = (struct WBStartup *)arg_ptr;
   }
   /*}}}  */
  else
   /*{{{  look for ms-dos wildcards*/
   {
    __msflag = 1;
    i=1;
    j=0;
    while (i<*argc)
     /*{{{  test all args and expand if wildcards exist*/
     {
      if (strpbrk(((char **)(*argv))[i],"?*"))
       /*{{{  expand filename, copy all arguments to new argument list*/
       {
        int n;

        if (!dev)
         /*{{{  copy previous arguments to dev*/
         {
          if (!(dev = malloc (300*sizeof(char *)))) exit(1);
          for (j=0; j<i; ((char **)dev)[j]=((char **)(*argv))[j++]);
          j=i;
         }
         /*}}}  */
        if (ptr = calloc (1,1000))
         /*{{{  copy all matching filenames to dev*/
         {
          n = getfnl (dptr = ((char **)(*argv))[i],ptr,3000,0);
          if (n>0)
            j += strbpl (&(((char **)dev)[j]),300-j-1,ptr);
          else
            ((char **)dev)[j++]=dptr;
         }
         /*}}}  */
        else ((char **)dev)[j++]=((char **)(*argv))[i];
       }
       /*}}}  */
      else
       /*{{{  add argument if dev already exists*/
       if (dev) ((char **)dev)[j++]=((char **)(*argv))[i];
       /*}}}  */
      i++;
     }
     /*}}}  */
    if (dev)
     /*{{{  set new list as argument list*/
     {
      ((char **)dev)[j]=(char *)0;
      old_argv_addr = argv;
      old_argv = *argv;
      *argv=(struct WBStartup *)dev;
      *argc=j;
     }
     /*}}}  */
   }
   /*}}}  */
  /*{{{  Set exit trap to reset_amiga*/
  if (atexit (&reset_amiga))
   {
    reset_amiga();
    exit (10);
   }
  /*}}}  */
  /*{{{  Prepare auto-save*/
  if ((mpp =CreatePort ("Origami-Timer",0L))!=(struct MsgPort *)0)
   {
    my_signal = 1<<mpp->mp_SigBit;
    if (!(tr = CreateIORequest (mpp,sizeof (struct timerequest))))
     /*{{{  no request -> delete port, no timer functions*/
     {
      DeletePort (mpp);
      my_signal=0;
     }
     /*}}}  */
    else
     {
      if (OpenDevice (TIMERNAME,0,(struct IORequest *)tr,0))
       /*{{{  no timer device -> delete port, no timer functions*/
       {
        DeleteIORequest (tr);
        DeletePort (mpp);
        my_signal=0;
        tr =NULL;
       }
       /*}}}  */
     }
  }
  /*}}}  */
  /*{{{  Open Console Device*/
  if (OpenDevice ("console.device",CONU_LIBRARY,
                  (struct IORequest *)&isr,0)) exit (5);
  ConsoleDevice = (struct Library *)isr.io_Device;
  /*}}}  */
  /*{{{  Open IFFParseLibrary (CUTPASTE only)*/
#  ifdef CUTPASTE
  IFFParseBase = OpenLibrary ("iffparse.library",0L);
#  endif
  /*}}}  */
 }
/*}}}  */
/*{{{  init_amiga_post_arg*/
public void init_amiga_post_arg (void)
 {
  /*{{{  variables*/
  short screen_height, screen_width, width, x, y;
#  ifdef ICONIFY
  /*{{{  */
  /*{{{  image data*/
  __chip static UWORD imd[] =
    {
      0x0000, 0x0000,
      0x807F, 0x8100,
      0x81C0, 0xE100,
      0x8380, 0x7100,
      0x860C, 0x1900,
      0x8C1E, 0x0D00,
      0x8C1E, 0x0D00,
      0x860C, 0x1900,
      0x8380, 0x7100,
      0x81C0, 0xE100,
      0x807F, 0x8100,

      0xFFFF, 0xFF00,
      0x4000, 0x0000,
      0x4000, 0x0000,
      0x4000, 0x0000,
      0x4000, 0x0000,
      0x4000, 0x0000,
      0x4000, 0x0000,
      0x4000, 0x0000,
      0x4000, 0x0000,
      0x4000, 0x0000,
      0x4000, 0x0000
    };
  /*}}}  */
  static struct Image ima = { -1,0, 24,11, 2, NULL, 0x03,0x00, NULL };
  static struct Gadget gad = {NULL, -68, 0, 24,10,
         GFLG_RELRIGHT | GFLG_GADGIMAGE,
         GACT_TOPBORDER | GACT_IMMEDIATE,
         GTYP_BOOLGADGET, NULL, NULL, NULL, NULL, NULL, 1, NULL };
  /*}}}  */
#  endif
  struct NewWindow nw = {0,0,0,0,UCHAR_MAX,UCHAR_MAX,
         IDCMP_MENUPICK | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_RAWKEY |
#  ifdef PRIORITY
           IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW |
#  endif
#  ifdef ICONIFY
           IDCMP_GADGETDOWN | IDCMP_CHANGEWINDOW |
#  endif
           IDCMP_MOUSEBUTTONS,
         WFLG_SIZEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET |
           WFLG_CLOSEGADGET | WFLG_ACTIVATE ,
         NULL, NULL, window_name, NULL, NULL, 150,
         /*{{{  minimum height*/
#         ifdef ICONIFY
         10,
#         else
         50,
#         endif
         /*}}}  */
         (UWORD)~0,(UWORD)~0,
         WBENCHSCREEN };
  int mode=HIRES;
  /*}}}  */

  /*{{{  open terminal window*/
  /*{{{  Calc screen size*/
  /*{{{  on own screen*/
  if (screen_yes==True)
   {
    /*{{{  Exists Screen ?*/
    int not_equal;

    my_screen = IntuitionBase->FirstScreen;
    do
     {
      if (not_equal = strcmp(my_screen->Title,"Origami"))
        my_screen = my_screen->NextScreen;
     } while (not_equal && my_screen);
    /*}}}  */
    /*{{{  yes*/
    if (my_screen)
     {
      beep_screen=my_screen;
      off_y=my_screen->Font->ta_YSize;
      screen_height = my_screen->Height;
      screen_width = my_screen->Width;
     }
    /*}}}  */
    /*{{{  no*/
    else
     {
      /*{{{  Get Y offset and mode*/
      struct Screen *wscreen;

      if (wscreen = LockPubScreen (NULL))
       {
        off_y=wscreen->Font->ta_YSize;
        mode = GetVPModeID(&wscreen->ViewPort);
        if (mode==INVALID_ID) mode=HIRES;
        UnlockPubScreen (NULL,wscreen);
        beep_screen = wscreen;
       }
      /*}}}  */
      /*{{{  Get height*/
      if (screenh) screen_height = screenh;
      else
       {
        screen_height = STDSCREENHEIGHT;
       }
      /*}}}  */
      /*{{{  Get width*/
      if (screenw) screen_width = screenw;
      else screen_width = STDSCREENWIDTH;
      /*}}}  */
     }
    /*}}}  */
   }
  /*}}}  */
  /*{{{  use workbenchscreen*/
  else
   {
    struct Screen *wscreen;

    if (wscreen = LockPubScreen (NULL))
     {
      beep_screen = wscreen;
      off_y=wscreen->Font->ta_YSize;
      screen_height = wscreen->Height;
      screen_width = wscreen->Width;
      UnlockPubScreen (NULL,wscreen);
     }
    else exit (15);
   }
  /*}}}  */
  /*}}}  */
  /*{{{  Calc window size*/
  x=windx;
  if (windy!=-1) y=windy;
  else y=off_y;
  if (windw) width=windw;
  else
   /*{{{  get window width (visible screen width)*/
   {
    struct Screen wbscreen;

    if (GetScreenData ((APTR)&wbscreen,sizeof (struct Screen),
        WBENCHSCREEN,NULL))
     {
      width=min (wbscreen.Width,screen_width-x);
      if (!windh)
       {
        windh=wbscreen.Height;
        if ((screen_height!=STDSCREENHEIGHT)&&(screen_height-y-1<wbscreen.Height))
          windh = screen_height-y-1;
       }
     }
   }
   /*}}}  */
  if (windh) height=windh;
  else if (screen_height==STDSCREENHEIGHT) height=STDSCREENHEIGHT;
  else height=screen_height-y-1;
  /*}}}  */
  if (screen_yes==True)
   /*{{{  Open Screen & Window*/
   {
    /*{{{  Open Screen*/
    if (!my_screen)
    {
      struct NewScreen ns = {0,0,STDSCREENHEIGHT,STDSCREENWIDTH,2,
               0,1,HIRES,CUSTOMSCREEN,NULL,"Origami",NULL,NULL};

      ns.ViewModes = mode;
      ns.Height = screen_height;
      ns.Width = screen_width;
      if (!(my_screen = (struct Screen *)
        OpenScreenTags (&ns,SA_DisplayID, mode, SA_PubName, "Origami")))
        exit (16);
      /*{{{  Get Font Size*/
      off_y=my_screen->Font->ta_YSize;
      /*}}}  */
    }
    /*}}}  */
    /*{{{  Open Window*/
    nw.Type = CUSTOMSCREEN;
    nw.MaxWidth = (UWORD)~0;
    nw.MaxHeight = (UWORD)~0;
    nw.Screen = my_screen;
    if ((height==STDSCREENHEIGHT)||(height+y>my_screen->Height))
      nw.Height = my_screen->Height-y-1;
    else nw.Height = height;
    if (width==STDSCREENWIDTH) nw.Width = my_screen->Width-x-1;
    else nw.Width = width;
    nw.TopEdge = y;
    nw.LeftEdge = x;
    if (!(wind = (struct Window *) OpenWindow (&nw))) exit (17);
    /*}}}  */
   }
   /*}}}  */
  else
   /*{{{  Open Window*/
   {
    nw.LeftEdge = x;
    nw.TopEdge = y;
    nw.Width = width;
    nw.Height = height;

    if (!(wind = (struct Window *) OpenWindow (&nw))) exit (18);
   }
   /*}}}  */
  /*}}}  */
  /*{{{  add iconify gadget*/
#  ifdef ICONIFY
  ima.ImageData = imd;
  gad.GadgetRender = (APTR)&ima;
  AddGadget (wind, &gad, 0);
  RefreshWindowFrame (wind);
#  endif
  /*}}}  */
  /*{{{  inits window specify things for screen*/
  rp = wind->RPort;
  SetFont (rp,GfxBase->DefaultFont);
  get_terminal_capability();
  init_wind|=0x01;
  /*}}}  */
  /*{{{  only AREXX*/
#  ifdef AREXX
  /*{{{  Create Arexx Port*/
  /*{{{  get structure memory*/
  if (!(_arexx=(_AREXX *)malloc (sizeof (_AREXX))))
    exit (19);
  /*}}}  */
  /*{{{  open arexx port*/
  if (arexx==True)
   /*{{{  open arexx port if wished*/
   {
    /*{{{  Open Library*/
    if (!(RexxSysBase=OpenLibrary("rexxsyslib.library",NULL)))
     /*{{{  error*/
     {
      arexx=False;
      _arexx->signal = 0;
      _arexx->port = (struct MsgPort *)0;
     }
     /*}}}  */
    /*}}}  */
    else
     /*{{{  did open lib*/
     {
      /*{{{  Get Port*/
      int loop= -1;
      char *tmp=_arexx->portname;

      /*{{{  Get Portname*/
      if (portname)
       {
        while ((++loop<16)&&(portname[loop]))
          *(tmp++)=toupper(portname[loop]);
        *tmp=0;
       }
      else
       {
        strcpy (_arexx->portname,"ORIGAMI");
        tmp+=7;
       }
      /*}}}  */
      Forbid();
      _arexx->port=(struct MsgPort *)1;
      for (loop=0;_arexx->port;loop++)
       {
        if (loop) stci_d(tmp,loop);
        _arexx->port=FindPort(_arexx->portname);
       }
      _arexx->port = CreatePort (_arexx->portname,0);
      Permit();
      /*}}}  */
      if (!_arexx->port)
       /*{{{  error*/
       {
        CloseLibrary (RexxSysBase);
        RexxSysBase=NULL;
        _arexx->signal=0;
        arexx=False;
       }
       /*}}}  */
      else
       {
        _arexx->signal = 1 << _arexx->port->mp_SigBit;
        strcpy (_arexx->errorname,_arexx->portname);
        strcat (_arexx->errorname,".LASTERROR");
       }
     }
     /*}}}  */
   }
   /*}}}  */
  /*}}}  */
  /*{{{  set some variables, if no arexx port is wanted*/
  else
   {
    _arexx->signal = 0;
    _arexx->port= NULL;
    RexxSysBase = NULL;
   }
  /*}}}  */
  _arexx->outstanding = 0;
  _arexx->tag =0;
  _arexx->command=NULL;
  _arexx->hist= -1;
  /*}}}  */
#  endif
  /*}}}  */
 }
/*}}}  */
/*{{{  init_amiga_post_rc*/
public void init_amiga_post_rc (void)
 {
  /*{{{  only MENU*/
#  ifdef MENU
  if (menu_root)
   /*{{{  initialize menu-datas*/
   {
    /*{{{  variables*/
    struct Menu *m=menu_root;
    struct MenuItem *i;
    int mx=10,my,mw;
    /*}}}  */

    while (m)
     /*{{{  handle one menu*/
     {
      m->LeftEdge = mx;
      m->TopEdge = 0;
      mx +=  (m->Width = strlen (m->MenuName)*off_y + 16) +5;
      m->Height = off_y + 2;
      m->Flags = MENUENABLED;
      i = m->FirstItem;
      my=mw=0;
      while (i)
       /*{{{  init all item structure data*/
       {
        struct IntuiText *t = (struct IntuiText *)i->ItemFill;
        t->FrontPen = 0;
        t->BackPen = 1;
        t->TopEdge = 2;
        t->DrawMode = JAM1;
        t->LeftEdge = 8;
        t->ITextFont = 0;
        t->NextText = 0;
        i->LeftEdge = -5;
        i->TopEdge = my * (2+off_y);
        mw = (((strlen (t->IText)+2) * off_y) > mw) ?
          ((strlen (t->IText)+2) * off_y) : mw;
        i->Height = 2+off_y;
        i->Flags = ITEMENABLED | ITEMTEXT | HIGHCOMP;
        i->MutualExclude = 0;
        i->SelectFill = 0;
        i->Command = 0;
        i->SubItem = 0;
        i->NextSelect = 0;
        my++;
        i=i->NextItem;
       }
       /*}}}  */
      i = m->FirstItem;
      while (i)
       /*{{{  set all width*/
       {
        i->Width = mw;
        i = i->NextItem;
       }
       /*}}}  */
      m = m->NextMenu;
     }
     /*}}}  */
    SetMenuStrip (wind,menu_root);
    menu_on = True;
   }
   /*}}}  */
#  endif
  /*}}}  */
  if (_Backstdout)
   /*{{{  close stderr filehandle*/
   {
    Close (_Backstdout);
    init_wind |=0x02;
   }
   /*}}}  */
 }
/*}}}  */
