/*
** A TCLSH that reads itself as its initialization script.  This is
** intended for use as CGI.  The CGI script should look like:
**
**      #/usr/bin/cgitclsh
**      #
**      proc w3-default {} {
**        w3 "<h1>Hello, World!</h1>\n"
**      }
**      w3-default -cgi
**
*/
#define SQLITE_THREADSAFE 0
#undef SQLITE_ENABLE_COLUMN_METADATA
#define SQLITE_OMIT_DECLTYPE 1
#define SQLITE_OMIT_DEPRECATED 1
#define SQLITE_OMIT_PROGRESS_CALLBACK 1
#define SQLITE_OMIT_SHARED_CACHE 1
#define SQLITE_DEFAULT_MEMSTATUS 0
#define SQLITE_MAX_EXPR_DEPTH 0
#define SQLITE_OMIT_LOAD_EXTENSION 1
#define SQLITE_ENABLE_FTS4 1
#define SQLITE_ENABLE_FTS5 1
#define SQLITE_ENABLE_RTREE 1
#define SQLITE_ENABLE_JSON1 1
#define TCLSH_INIT_PROC w3tclsh_init_proc
INCLUDE tclsqlite3.c

/* The w3.tcl script contains the useful web-application interface
** procedures.  After loading this script, "package require w3" becomes
** a no-op
*/
static const char zW3[] = 
BEGIN_STRING
INCLUDE $ROOT/w3.tcl
END_STRING
;

/* This script runs to figure out what the main script should be.  It
** loads the main script into a TCL variable named "main_script".  Or,
** if an interactive shell is desired, "main_script" is unset.
*/
static const char zW3TclshInit[] = 
BEGIN_STRING
INCLUDE $ROOT/w3tclsh.tcl
END_STRING
;

/*
** Return the text of the script to run.  Or, return NULL to run an
** interactive shell.
*/
const char *w3tclsh_init_proc(Tcl_Interp *interp){
  Tcl_GlobalEval(interp, zW3);  /* Load the w3.tcl extension */
  Tcl_GlobalEval(interp, zW3TclshInit); /* Load the main loop script */
  return Tcl_GetVar(interp, "main_script", TCL_GLOBAL_ONLY);
}
