/* Copyright (c) 1993 by Sanjay Ghemawat */
#ifndef _CAL_TCL_H
#define _CAL_TCL_H

/*
 * TCL Interface to calendar.
 */

#include "object.h"
#include "arrays.h"

class Calendar;
class CalFile;
class Item;
class Item_Tcl;

declareArray(FileList,CalFile*)

class Calendar_Tcl : public Object {
  public:
    Calendar_Tcl(Tcl_Interp*, char const* handle, char const* file);
    virtual ~Calendar_Tcl();

    int error();		/* Used to detect initialization error */
    char const* error_msg();	/* Error description */

    virtual int method(int, char*[]);

    /*
     * effects	Returns name of calendar file that contains item.
     *		Returns 0 if no such file.
     */
    char const* container(Item_Tcl*);

    CalFile*  main;		/* Main calendar */
    FileList* includes;		/* Included calendars */
    void add_item_handles(Calendar*);
    void remove_item_handles(Calendar*);

     /*
      * effects	Returns calendar file with specified name.
      *		If name is nil, returns main calendar file.
      *		If no calendar file matches name, returns nil.
      */
    CalFile* find_calendar(char const* name);

    /*
     * modifies	includes/items/error_message.
     * effects	Uses string names in main calendar to fixup include list.
     *		Appends errors to error_message.
     */
    void fix_includes();

    void clear_error();
    void add_error(char const* title, char const* text);
  private:
    int had_error;
    charArray* msg;		/* Always kept null terminated */
};

extern Calendar_Tcl* calendar_instance;

inline int Calendar_Tcl::error() {
    return had_error;
}

inline char const* Calendar_Tcl::error_msg() {
    return msg->as_pointer();
}

#endif /* _CAL_TCL_H */
