#ifndef BASICLIB_H
#define BASICLIB_H

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

/*  
**  $Filename: basic.h
**  $Release:  39.0
**  
**  Include file for BASIC.library
**  
**  (C) Copyright 2001 Dietmar Eilert
**      All Rights Reserved
*/ 

#define BASIC_VERSION  39
#define BASIC_REVISION 0
#define BASIC_MAGIC    0x44426553

/* varargs tags (see autodoc/basiclib.doc) */

enum
{
    BASIC_COMMANDLINE = (int)TAG_USER,               /* command line with arguments (UBYTE *) */
    BASIC_PRIORITY,                                  /* interpreter priority (WORD) */
    BASIC_HOST,                                      /* name of host's message port (UBYTE *) */
    BASIC_FILENAME,                                  /* program to load (UBYTE *) */
    BASIC_METACODE,                                  /* program to load (void  *) */
    BASIC_ADDRESS,                                   /* program to load (UBYTE *) */
    BASIC_SIZE,                                      /* program size (ULONG) */
    BASIC_CONSOLE,                                   /* console (UBYTE *) */
    BASIC_HOOK,                                      /* hook function implementing extensions (basic_hook) */
    BASIC_INTERACTIVE,                               /* enable interactive mode ? (BOOL) */
    BASIC_EDITOR,                                    /* default editor (UBYTE *) */
    BASIC_SIGNALS                                    /* signals raised when interpreter exits (ULONG) */
};

/* Prototype of hook function (BASIK_HOOK) adding new commands and variables to BASIC */

typedef LONG (*basic_hook)(void *context, UWORD method, UBYTE *argument, struct basic_value *value);

/* methods for hook functions */

enum
{
    BASIC_COMMAND,                                   /* argument is the command line to be parsed */
    BASIC_SET,                                       /* argument is the variable name */
    BASIC_GET                                        /* argument is the variable name */
};

/* possible return codes of a hook function (basic_hook) installed with BASIC_HOOK */

enum
{
    BASIC_DEFER,                                     /* defer processing to interpreter */
    BASIC_ACCEPT,                                    /* defer processing to hook */
    BASIC_STOP                                       /* stop execution */
};

/* flags for basic_run() */

#define BASIC_SHARED (0)                             /* share variables */
#define BASIC_CLEAR  (1L<<0)                         /* clear variables */

/* BASIC error codes */

enum
{
    BASIC_OK,
    BASIC_ERROR_ARGUMENTMISSING,
    BASIC_ERROR_FILENOTFOUND,
    BASIC_ERROR_RUNTIME,
    BASIC_ERROR_IO,
    BASIC_ERROR_LOAD,
    BASIC_ERROR_CONSOLE,
    BASIC_ERROR_SYNTAX,
    BASIC_ERROR_END,
    BASIC_ERROR_INTERNAL,

    /* number of errors */

    BASIC_ERRORS
};

/* BASIC strings are 0-terminated but may also contain '\0' inside the string */

struct basic_string
{
    ULONG  length;                                   /* length */
    UBYTE *buffer;                                   /* string content */
};

/* definition of a BASIC value which can be numeric or textual */

struct basic_value
{
    UWORD type;                                      /* type qualifier */

    union
    {
        struct basic_string *string;                 /* value if type is textual */
        LONG                 number;                 /* value if type is numeric */
    };
};

/* possible types of BASIC values (basic_value->type) */

enum
{
    BASIC_NUMERIC,                                   /* integer */
    BASIC_STRING                                     /* string  */
};

#endif
