#!/usr/bin/tclsh
#
# Run this script to generate the pragma name lookup table C code.
#
# To add new pragmas, first add the name and other relevant attributes
# of the pragma to the "pragma_def" object below. Then run this script
# to generate the ../src/pragma.h header file that contains macros and
# the lookup table needed for pragma name lookup in the pragma.c module.
# Then add the extra "case PragTyp_XXXXX:" and subsequent code for the
# new pragma in ../src/pragma.c.
#
# Flag meanings:
set flagMeaning(NeedSchema)
set flagMeaning(ReadOnly)
set flagMeaning(Result0)
set flagMeaning(Result1)
set flagMeaning(SchemaReq)
set flagMeaning(SchemaOpt)
set flagMeaning(NoColumns)
set flagMeaning(NoColumns1)
set pragma_def
# Open the output file
#
set destfile "/src/pragma.h"
puts "Overwriting $destfile with new pragma table..."
set fd
puts $fd
# Parse the PRAGMA table above.
#
set name
set type
set if
set flags
set cols
set cols_list
set arg 0
foreach line
record_one
set allnames
# Generate #defines for all pragma type names. Group the pragmas that are
# omit in default builds (ex: defined(SQLITE_DEBUG))
# at the end.
#
puts $fd "\n/* The various pragma types */"
set pnum 0
foreach name $allnames
foreach name $allnames
foreach name $allnames
# Generate #defines for flags
#
puts $fd "\n/* Property flags associated with various pragma. */"
set fv 1
foreach f
# Sort the column lists so that longer column lists occur first
#
set cols_list
# Generate the array of column names used by pragmas that act like
# queries.
#
puts $fd "\n/* Names of columns for pragmas that return multi-column result"
puts $fd "** or that return single-column results where the name of the"
puts $fd "** result column is different from the name of the pragma\n*/"
puts $fd "static const char *const pragCName\[\] = {"
set offset 0
set allcollist
foreach cols $cols_list
puts $fd "\175;"
# Generate the lookup table
#
puts $fd "\n/* Definitions of all built-in pragmas */"
puts $fd "typedef struct PragmaName \173"
puts $fd " const char *const zName; /* Name of pragma */"
puts $fd " u8 ePragTyp; /* PragTyp_XXX value */"
puts $fd " u8 mPragFlg; /* Zero or more PragFlg_XXX values */"
puts $fd
puts $fd " u8 nPragCName; \
/* Num of col names. 0 means use pragma name */"
puts $fd " u64 iArg; /* Extra argument */"
puts $fd "\175 PragmaName;"
puts $fd "static const PragmaName aPragmaName\[\] = \173"
set current_if
set spacer
foreach name $allnames
if
puts $fd "\175;"
# count the number of pragmas, for information purposes
#
set allcnt 0
set dfltcnt 0
foreach name $allnames
puts $fd "/* Number of pragmas: $dfltcnt on by default, $allcnt total. */"