/*  outer.h								*/
/*    Compile-time constants for outer_brev.  Constants can come	*/
/*    from user-defined .h file via -DOPTIONS compiliation switch for	*/
/*    outer.  Those constants supersede these.  Lots of other places	*/
/*    for constants to come from, too...				*/

#define OUTERH_VERSION "outer.h version 1.2 11 Nov 99"
/*  11 Nov 99.  WJS							*/
/*	QUERY_STRING_CHAR & QUERY_STRING_ITEM_SEPARATOR.		*/
/*	Remove OO_OUTER							*/
/*	#include stdlib for things like strtol				*/
/*	Default the -DOPTIONS quantities.  Values taken from synthesis'	*/
/*	  /users/jgofs/src/include/default.h, whose comment says	*/
/*	  "Values are those of 23 Jan 96 outerw"			*/
/*	[Begin 1.2]							*/
/*  20 Apr 99.  WJS							*/
/*	Include error_exit_defn.h					*/
/*  13 Mar 99.  WJS							*/
/*	Include errno.h							*/
/*	[Begin 1.1]							*/
/*  16 Dec 98.  WJS							*/
/*	Define PLOTLINK in terms of OTHEROPT if appropriate		*/
/*	[Begin 1.0a]							*/
/*   4 Dec 98.  WJS							*/
/*	Bug fix: OTHEROPT was supposed to be OTHEROPTS.  Meantime,	*/
/*	  OTHEROPTS was defined the old, unreconciled way, so the thing	*/
/*	  compiled!							*/
/*	[Begin 1.0]							*/

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#ifdef VMS
#include <ctype.h>
#else
#include <malloc.h>
#endif

#include "error_exit_defn.h"
#include "path_info_routines.h"

#include OPTIONS   /*  User-spec'd defns - must precede outer.h defns	*/
#ifndef ATTRSIZE
#define ATTRSIZE 40
#endif
#ifndef COMMENTLINE
#define COMMENTLINE 80
#endif
#ifndef DATUMSIZE
#define DATUMSIZE 80
#endif
#ifndef TOTATTRSIZE
#define TOTATTRSIZE 1024
#endif
#ifndef VARNAMESIZE
#define VARNAMESIZE 40
#endif


#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#if FALSE != (! TRUE)
#error "Conflicting TRUE/FALSE values"
#endif
  /*  Should probably test that TRUE & FALSE fit into char vars...	*/

#define UNSPECIFIED -1
#if (UNSPECIFIED == TRUE) || (UNSPECIFIED == FALSE)
#error "UNSPECIFIED conflicts with TRUE or FALSE"
#endif

  /*  Established defined values for compilation constants		*/
#ifndef BREVSTART
#define BREVSTART 1
#endif
#ifndef BREVCOUNT
#define BREVCOUNT 20
#endif
#ifndef QUOTENOLINK
#define QUOTENOLINK FALSE
#endif
#ifndef MYADDR
#define MYADDR "\0"
#endif
#ifndef MYPORT
#define MYPORT "\0"		/*  NB: string, not integer		*/
#endif
#ifndef BUTTONIMAGESDIR
#define BUTTONIMAGESDIR "\0"
#endif
#ifndef OPTIONSERVER
#define OPTIONSERVER "\0"
#endif
#ifndef DIRSERVER
#define DIRSERVER "\0"
#endif
#ifndef INFOSERVER
#define INFOSERVER "\0"
#endif
#ifndef JGOFS_DATA_CGI_SPEC
#define JGOFS_DATA_CGI_SPEC "/jg/serv"
#endif

/**********	Compile-time link control		*****************/

  /*  Reconcile TOPLINKS and NOTOPLINKS compile-time constants		*/
#if defined(TOPLINKS) && defined(NOTOPLINKS)
#if (TOPLINKS && NOTOPLINKS) || (!TOPLINKS && !NOTOPLINKS)
#error "Conflicting TOPLINKS definitions"
#endif
#endif

  /*  Provide a compile-time value from user params or default		*/
#ifndef TOPLINKS
#ifdef NOTOPLINKS
#define TOPLINKS !NOTOPLINKS
#else
#define TOPLINKS TRUE
#endif
#endif    

  /*  Reconcile DIRLINK and NODIRLINK compile-time constants		*/
#if defined(DIRLINK) && defined(NODIRLINK)
#if (DIRLINK && NODIRLINK) || (!DIRLINK && !NODIRLINK)
#error "Conflicting DIRLINK definitions"
#endif
#endif

  /*  Provide a compile-time value from user params or default		*/
#ifndef DIRLINK
#ifdef NODIRLINK
#define DIRLINK !NODIRLINK
#else
#define DIRLINK UNSPECIFIED
#endif
#endif    

  /*  Reconcile DOCLINK and NODOCLINK compile-time constants		*/
#if defined(DOCLINK) && defined(NODOCLINK)
#if (DOCLINK && NODOCLINK) || (!DOCLINK && !NODOCLINK)
#error "Conflicting DOCLINK definitions"
#endif
#endif

  /*  Provide a compile-time value from user params or default		*/
#ifndef DOCLINK
#ifdef NODOCLINK
#define DOCLINK !NODOCLINK
#else
#define DOCLINK UNSPECIFIED
#endif
#endif    

  /*  Reconcile PLOTLINK and NOPLOTLINK compile-time constants		*/
#if defined(PLOTLINK) && defined(NOPLOTLINK)
#if (PLOTLINK && NOPLOTLINK) || (!PLOTLINK && !NOPLOTLINK)
#error "Conflicting PLOTLINK definitions"
#endif
#endif

  /*  Provide a compile-time value from user params or default		*/
#ifndef PLOTLINK
#ifdef NOPLOTLINK
#define PLOTLINK !NOPLOTLINK
#else
#define PLOTLINK UNSPECIFIED
#endif
#endif    

  /*  Reconcile LEV0LINK and NOLEV0LINK compile-time constants		*/
#if defined(LEV0LINK) && defined(NOLEV0LINK)
#if (LEV0LINK && NOLEV0LINK) || (!LEV0LINK && !NOLEV0LINK)
#error "Conflicting LEV0LINK definitions"
#endif
#endif

  /*  Provide a compile-time value from user params or default		*/
#ifndef LEV0LINK
#ifdef NOLEV0LINK
#define LEV0LINK !NOLEV0LINK
#else
#define LEV0LINK UNSPECIFIED
#endif
#endif    

  /*  Reconcile LEVNLINK and NOLEVNLINK compile-time constants		*/
#if defined(LEVNLINK) && defined(NOLEVNLINK)
#if (LEVNLINK && NOLEVNLINK) || (!LEVNLINK && !NOLEVNLINK)
#error "Conflicting LEVNLINK definitions"
#endif
#endif

  /*  Provide a compile-time value from user params or default		*/
#ifndef LEVNLINK
#ifdef NOLEVNLINK
#define LEVNLINK !NOLEVNLINK
#else
#define LEVNLINK UNSPECIFIED
#endif
#endif    

  /*  Reconcile FLATLINK and NOFLATLINK compile-time constants		*/
#if defined(FLATLINK) && defined(NOFLATLINK)
#if (FLATLINK && NOFLATLINK) || (!FLATLINK && !NOFLATLINK)
#error "Conflicting FLATLINK definitions"
#endif
#endif

  /*  Provide a compile-time value from user params or default		*/
#ifndef FLATLINK
#ifdef NOFLATLINK
#define FLATLINK !NOFLATLINK
#else
#define FLATLINK UNSPECIFIED
#endif
#endif    

  /*  Reconcile OTHEROPTS and NOOTHEROPTS compile-time constants	*/
#if defined(OTHEROPTS) && defined(NOOTHEROPTS)
#if (OTHEROPTS && NOOTHEROPTS) || (!OTHEROPTS && !NOOTHEROPTS)
#error "Conflicting OTHEROPTS definitions"
#endif
#endif

  /*  Provide a compile-time value from user params or default		*/
#ifndef OTHEROPTS
#ifdef NOOTHEROPTS
#define OTHEROPTS !NOOTHEROPTS
#else
#define OTHEROPTS UNSPECIFIED
#endif
#endif    

  /*  OTHEROPTS & PLOTLINK are supposed to be synonymous, so reconcile	*/
  /*  them, too								*/
#if OTHEROPTS != PLOTLINK
#if PLOTLINK == UNSPECIFIED
#undef PLOTLINK
#define PLOTLINK OTHEROPTS
#elif OTHEROPTS != UNSPECIFIED
#error "Conflicting PLOTLINK/OTHEROPTS definitions"
#endif
#endif

#ifdef OO_OUTER
#error "OO_OUTER no longer used"
#endif

/**********	End compile-time link control		*****************/


#ifndef GENERATE_ALPHA_SELECTIONS
#define GENERATE_ALPHA_SELECTIONS TRUE
#endif

#ifndef USE_DOUBLE
#define USE_DOUBLE FALSE
#endif

#define QUERY_STRING_CHAR '?'		/*  http defn			*/
#define QUERY_STRING_ITEM_SEPARATOR ',' /*  our convention		*/
  /*  Next character must be non-special to http.  Also must not be	*/
  /*  legal character of jgofs variable name				*/
#define TRIGRAM_KEY '%'

  /*  Reconcile TEST_GIFS and NOTEST_GIFS compile-time constants	*/
#if defined(TEST_GIFS) && defined(NOTEST_GIFS)
#if (TEST_GIFS && NOTEST_GIFS) || (!TEST_GIFS && !NOTEST_GIFS)
#error "Conflicting TEST_GIFS definitions"
#endif
#endif
#ifndef TEST_GIFS
#ifdef NOTEST_GIFS
#define TEST_GIFS !NOTEST_GIFS
#else
#define TEST_GIFS FALSE
#endif
#endif    
#define DIR_GIF 0
#define DOC_GIF 1
#define PLOT_GIF 2
#define LEVEL0_GIF 3
#define NOLEVEL0_GIF 4
#define LEVELN_GIF 5
#define NOLEVELN_GIF 6
#define FLAT_GIF 7
#define NGIFS 8		/*	Keep = to count if gifs added		*/

  /*  Convert string sizes into their respective buffer sizes		*/
  /*  unless outer uses string size, too (eg, TOKEN)			*/
  /*  Parens important if constant is used in arithmetic, since macro	*/
  /*  does string substitution, not numeric.  Consider n*VARNAMEBUFSIZE	*/
  /*  - we want result of macro to be n*(VARNAMESIZE + 1).  W/o parens,	*/
  /*  trouble.  Guess how we found out...				*/
#define VARNAMEBUFSIZE (VARNAMESIZE + 1)
#define COMMENTLINEBUF (COMMENTLINE + 1)	/* Note defn of		*/
					    /* COMMENTLINE includes \n.	*/
#define ATTRBUFSIZE (ATTRSIZE+1)
#define DATUMBUFSIZE (DATUMSIZE+1)

  /*  OUTVARBUF holds variables, then attributes; use max		*/
#if COMMENTLINEBUF > (ATTRSIZE + VARNAMESIZE + 1)
#define CALC_OUTVARSIZE COMMENTLINEBUF
#else
#define CALC_OUTVARSIZE (ATTRSIZE + VARNAMESIZE + 1)
#endif
  /*  If user gave us bigger buffer (typically spec'd in default.h) use it */
  /*  Logic is a bit backwards - don't do anything if user buffer is	*/
  /*    bigger; redefine if supplied but smaller; define if unsupplied	*/
#ifdef OUTVARBUFSIZE
#if CALC_OUTVARSIZE > OUTVARBUFSIZE
#undef OUTVARBUFSIZE
#define OUTVARBUFSIZE CALC_OUTVARSIZE
#endif
#else
#define OUTVARBUFSIZE CALC_OUTVARSIZE
#endif

  /*  OUTBUF holds comment lines, then data; use max			*/
#if COMMENTLINEBUF > DATUMBUFSIZE
#define CALC_OUTSIZE COMMENTLINEBUF
#else
#define CALC_OUTSIZE DATUMBUFSIZE
#endif
  /*  If user gave us bigger buffer (typically spec'd in default.h) use it */
  /*  Logic is a bit backwards - don't do anything if user buffer is	*/
  /*    bigger; redefine if supplied but smaller; define if unsupplied	*/
#ifdef OUTBUFSIZE
#if CALC_OUTSIZE > OUTBUFSIZE
#undef OUTBUFSIZE
#define OUTBUFSIZE CALC_OUTSIZE
#endif
#else
#define OUTBUFSIZE CALC_OUTSIZE
#endif
