//************************************
//
// Name : App.c
//
//************************************


//**** Header files

//** OS Include files

//** OS function prototypes
#include <clib/exec_protos.h>
#include <clib/wb_protos.h>

//** OS function inline calls
#include <pragmas/exec_pragmas.h>
#include <pragmas/wb_pragmas.h>

//** ANSI C includes

//** application include

#include "Librarian.h"
#include "Node.h"
#include "App.h"
#include "TDEBUG.H"


//**** Local data structures

struct MsgPort *AppMenu=NULL;


//**** Aux functions

int BindMenus(void) {
  struct ProgNode *pn;
  if (IsListEmpty(List)) return 0;
  if (AppMenu=CreateMsgPort()) {
    for (pn = (struct ProgNode *)List->lh_Head ; pn->pn_Node.ln_Succ ; pn = (struct ProgNode *)pn->pn_Node.ln_Succ) {
      if (pn->pn_Type==PNT_APPMENU) {
	pn->pn_appmenu=AddAppMenuItemA(0L,(ULONG)pn,pn->pn_Node.ln_Name,AppMenu,NULL);
	if (NULL==pn->pn_appmenu) {
	  FreeMenus();
	  return 0;
	} // if created OK?
      } // if NULL
    }; // for
  } else {
    DPRINT("BindMenus: CreateMsgPort() failed\n",0);
  } // if create port
  return 1;
} // BindMenus


int FreeMenus(void) {
  struct ProgNode *pn;
  if (IsListEmpty(List)) return 1;
  if (NULL==AppMenu) return 0;
  for (pn = (struct ProgNode *)List->lh_Head ; pn->pn_Node.ln_Succ ; pn = (struct ProgNode *)pn->pn_Node.ln_Succ) {
    if (pn->pn_Type==PNT_APPMENU) {
      RemoveAppMenuItem(pn->pn_appmenu);
      pn->pn_appmenu=NULL;
    } // if
  };
  DeleteMsgPort(AppMenu);
  AppMenu=NULL;
  return 1;
} // FreeMenus

//**** End of file
