/*************************************************************************
 * Copyright 1984-1995 United States Data Corporation. All Rights Reserved.
 *************************************************************************
 *                                - NOTICE -
 *
 * The information contained herein is confidential information of United
 * States Data Corporation, a Delaware corporation, and is protected by
 * United States copyright and trade secret law and international treaties.
 * This information is not to be disclosed, used or copied by or transferred
 * to any individual, corporation, company or other person without the
 * express written permission of United States Data Corporation.
 *************************************************************************
 *
 * Module:  FLNTAG.H
 *
 *	Header file for FactoryLink tag name API.  These functions
 *	manage the translations of references to their components.
 *
 * History:
 *
 *	bjc 03/25/95	Created. 
 */

#ifndef _FLNTAG_INCLUDED
#define _FLNTAG_INCLUDED

#include <stdio.h>
#include <stdlib.h>
#include <flib.h>
#include <objct.h>


/*
 ************************************************************************
 *                            Constants                                 *       
 ************************************************************************
 */

#define FLNTAG_MAGIC      0x9999   /* Handle integrity value */

#define FLNTAG_NODEMKR    ':'
#define FLNTAG_DIMMKR     '['
#define FLNTAG_MBRMKR     '.'

/* NTAG structure maximums */
#define FLNTAG_MAX_NODE   8
#define FLNTAG_MAX_NAME   MAX_TAG_NAME
#define FLNTAG_MAX_DIM    MAX_DIM_LENGTH
#define FLNTAG_MAX_MBR    16

/* NTAG structure flags */
#define FLNTAG_S_NODE     0x0001
#define FLNTAG_S_NAME     0x0002
#define FLNTAG_S_DIMEN    0x0004
#define FLNTAG_S_MEMBER   0x0008

/* Error codes */
#define FLNTAG_E_GOOD     (GOOD)   /* No error - assume GOOD >= 0 */
#define FLNTAG_E_GENERAL  (-1)     /* General - assume ERROR == -1 */
#define FLNTAG_E_HANDLE   (-2)     /* Invalid NTAG handle */
#define FLNTAG_E_INVARG   (-3)     /* Invalid argument */
#define FLNTAG_E_NOMEM    (-4)     /* Memory allocation failure */
#define FLNTAG_E_REFSYN   (-5)     /* Invalid reference syntax */
#define FLNTAG_E_INVCHR   (-6)     /* Invalid reference character */
#define FLNTAG_E_LENGTH   (-7)     /* Invalid length specified */
#define FLNTAG_E_DIMSYN   (-8)     /* Invalid dimension syntax */
#define FLNTAG_E_DIMLEN   (-9)     /* Length of dimension length */
#define FLNTAG_E_DIMNUM   (-10)    /* Mismatch in the number of dims */
#define FLNTAG_E_DIMRNG   (-11)    /* Dimension reference beyond max */
#define FLNTAG_E_MBRREF   (-12)    /* Syntax for a reference to a member */


/*
 ************************************************************************
 *                        Structures and Types                          *
 ************************************************************************
 */

/*
 *  Structure for normalized tag names
 */
typedef struct _flntag
{
	u16   magic;                      /* structure integrity marker */
	char  node[FLNTAG_MAX_NODE+1];    /* ref's node */
	char  name[FLNTAG_MAX_NAME+1];    /* ref's name */
	char  dimens[FLNTAG_MAX_DIM+1];   /* ref's dimension */
	char  member[FLNTAG_MAX_MBR+1];   /* ref's member */
} FLNTAG;

/*
 *  Dimension size type
 */ 
typedef u16 fldimsz;

/*
 ************************************************************************
 *                              Macros                                  * 
 ************************************************************************
 */

#define flntag_get_brktdims(ntag)((ntag)->dimens)
#define flntag_get_dimen(ntag)   ((ntag)->dimens)
#define flntag_get_member(ntag)  ((ntag)->member)
#define flntag_get_name(ntag)    ((ntag)->name)
#define flntag_get_node(ntag)    ((ntag)->node)

#define flntag_open_objct(flapp, objct)  ct_open_tag(objct, flapp)
#define flntag_close_objct(objct)        ct_close(objct)

#define flntag_gen_objname(ntag, outstr, maxlen) \
        flntag_gen_str(ntag, 0xFFFF & ~FLNTAG_S_DIMEN, outstr, maxlen)

#define flntag_gen_ref(ntag, tagref, maxlen) \
        flntag_gen_str(ntag, 0xFFFF, tagref, maxlen)

#define flntag_gen_parent(ntag, tagref, maxlen) \
        flntag_gen_str(ntag, FLNTAG_S_NODE | FLNTAG_S_NAME, tagref, maxlen)

#define flntag_set_dimens flntag_set_dimen

/*
 ************************************************************************
 *                         Function Prototypes                          * 
 ************************************************************************
 */

#ifdef __cplusplus
extern "C" {
#endif

/*
 *  Protected FLNTAG Interface:
 */
extern void flntag_init(FLNTAG *ntag);

/*
 *  Public FLNTAG Interface:
 */
extern FLNTAG* flntag_create(void);
extern void    flntag_destroy(FLNTAG *ntag);

extern int flntag_parse_parent_ref(FLNTAG *ntag, char *tagref);
extern int flntag_parse_ref(FLNTAG *ntag, char *tagref);
extern int flntag_gen_str(FLNTAG *ntag, u16 incl, char *outstr, int maxlen);

extern i16 flntag_parse_brkt4dims(char *dimstr, fldimsz *dims, u16 dimslen);
extern i16 flntag_parse_comma4dims(char *dimstr, fldimsz *dims, u16 dimslen);

#ifndef NOCT
extern int flntag_find_def(FLNTAG *ntag, CT *objct, FLOBJREC *def);
extern int flntag_find_tag(FLNTAG *ntag, CT *objct, TAG *tag);
#endif

extern int flntag_calc_base(FLNTAG *ntag, TAG *tag, char *def_dims, TAG *base);
extern int flntag_calc_tag(FLNTAG *ntag, TAG *base, char *def_dims, TAG *tag);

extern int flntag_set_dimen(FLNTAG *ntag, char *dimens);
extern int flntag_set_member(FLNTAG *ntag, char *member);
extern int flntag_set_name(FLNTAG *ntag, char *name);
extern int flntag_set_node(FLNTAG *ntag, char *node);

#ifdef __cplusplus
}
#endif

#endif

