mkpragmatab.tcl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. #!/usr/bin/tclsh
  2. #
  3. # Run this script to generate the pragma name lookup table C code.
  4. #
  5. # To add new pragmas, first add the name and other relevant attributes
  6. # of the pragma to the "pragma_def" object below. Then run this script
  7. # to generate the ../src/pragma.h header file that contains macros and
  8. # the lookup table needed for pragma name lookup in the pragma.c module.
  9. # Then add the extra "case PragTyp_XXXXX:" and subsequent code for the
  10. # new pragma in ../src/pragma.c.
  11. #
  12. # The results are normally written into the ../src/pragma.h file. However,
  13. # if an alternative output file name is provided as an argument, then
  14. # results are written into the alternative. For example:
  15. #
  16. # tclsh tool/mkpragmatab.tcl ;# <--- Results to src/pragma.h
  17. #
  18. # tclsh tool/mkpragmatab.tcl /dev/tty ;# <-- results to terminal
  19. #
  20. # Flag meanings:
  21. set flagMeaning(NeedSchema) {Force schema load before running}
  22. set flagMeaning(ReadOnly) {Read-only HEADER_VALUE}
  23. set flagMeaning(Result0) {Acts as query when no argument}
  24. set flagMeaning(Result1) {Acts as query when has one argument}
  25. set flagMeaning(SchemaReq) {Schema required - "main" is default}
  26. set flagMeaning(SchemaOpt) {Schema restricts name search if present}
  27. set flagMeaning(NoColumns) {OP_ResultRow called with zero columns}
  28. set flagMeaning(NoColumns1) {zero columns if RHS argument is present}
  29. set pragma_def {
  30. NAME: full_column_names
  31. TYPE: FLAG
  32. ARG: SQLITE_FullColNames
  33. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  34. NAME: short_column_names
  35. TYPE: FLAG
  36. ARG: SQLITE_ShortColNames
  37. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  38. NAME: count_changes
  39. TYPE: FLAG
  40. ARG: SQLITE_CountRows
  41. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  42. NAME: empty_result_callbacks
  43. TYPE: FLAG
  44. ARG: SQLITE_NullCallback
  45. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  46. NAME: fullfsync
  47. TYPE: FLAG
  48. ARG: SQLITE_FullFSync
  49. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  50. NAME: checkpoint_fullfsync
  51. TYPE: FLAG
  52. ARG: SQLITE_CkptFullFSync
  53. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  54. NAME: cache_spill
  55. FLAG: Result0 SchemaReq NoColumns1
  56. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  57. NAME: reverse_unordered_selects
  58. TYPE: FLAG
  59. ARG: SQLITE_ReverseOrder
  60. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  61. NAME: query_only
  62. TYPE: FLAG
  63. ARG: SQLITE_QueryOnly
  64. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  65. NAME: automatic_index
  66. TYPE: FLAG
  67. ARG: SQLITE_AutoIndex
  68. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  69. IF: !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
  70. NAME: sql_trace
  71. TYPE: FLAG
  72. ARG: SQLITE_SqlTrace
  73. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  74. IF: defined(SQLITE_DEBUG)
  75. NAME: vdbe_listing
  76. TYPE: FLAG
  77. ARG: SQLITE_VdbeListing
  78. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  79. IF: defined(SQLITE_DEBUG)
  80. NAME: vdbe_trace
  81. TYPE: FLAG
  82. ARG: SQLITE_VdbeTrace
  83. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  84. IF: defined(SQLITE_DEBUG)
  85. NAME: vdbe_addoptrace
  86. TYPE: FLAG
  87. ARG: SQLITE_VdbeAddopTrace
  88. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  89. IF: defined(SQLITE_DEBUG)
  90. NAME: vdbe_debug
  91. TYPE: FLAG
  92. ARG: SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace
  93. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  94. IF: defined(SQLITE_DEBUG)
  95. NAME: vdbe_eqp
  96. TYPE: FLAG
  97. ARG: SQLITE_VdbeEQP
  98. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  99. IF: defined(SQLITE_DEBUG)
  100. NAME: ignore_check_constraints
  101. TYPE: FLAG
  102. ARG: SQLITE_IgnoreChecks
  103. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  104. IF: !defined(SQLITE_OMIT_CHECK)
  105. NAME: writable_schema
  106. TYPE: FLAG
  107. ARG: SQLITE_WriteSchema|SQLITE_NoSchemaError
  108. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  109. NAME: read_uncommitted
  110. TYPE: FLAG
  111. ARG: SQLITE_ReadUncommit
  112. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  113. NAME: recursive_triggers
  114. TYPE: FLAG
  115. ARG: SQLITE_RecTriggers
  116. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  117. NAME: trusted_schema
  118. TYPE: FLAG
  119. ARG: SQLITE_TrustedSchema
  120. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  121. NAME: foreign_keys
  122. TYPE: FLAG
  123. ARG: SQLITE_ForeignKeys
  124. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  125. IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
  126. NAME: defer_foreign_keys
  127. TYPE: FLAG
  128. ARG: SQLITE_DeferFKs
  129. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  130. IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
  131. NAME: cell_size_check
  132. TYPE: FLAG
  133. ARG: SQLITE_CellSizeCk
  134. NAME: default_cache_size
  135. FLAG: NeedSchema Result0 SchemaReq NoColumns1
  136. COLS: cache_size
  137. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
  138. NAME: page_size
  139. FLAG: Result0 SchemaReq NoColumns1
  140. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  141. NAME: secure_delete
  142. FLAG: Result0
  143. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  144. NAME: page_count
  145. FLAG: NeedSchema Result0 SchemaReq
  146. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  147. NAME: max_page_count
  148. TYPE: PAGE_COUNT
  149. FLAG: NeedSchema Result0 SchemaReq
  150. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  151. NAME: locking_mode
  152. FLAG: Result0 SchemaReq
  153. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  154. NAME: journal_mode
  155. FLAG: NeedSchema Result0 SchemaReq
  156. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  157. NAME: journal_size_limit
  158. FLAG: Result0 SchemaReq
  159. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  160. NAME: cache_size
  161. FLAG: NeedSchema Result0 SchemaReq NoColumns1
  162. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  163. NAME: mmap_size
  164. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  165. NAME: auto_vacuum
  166. FLAG: NeedSchema Result0 SchemaReq NoColumns1
  167. IF: !defined(SQLITE_OMIT_AUTOVACUUM)
  168. NAME: incremental_vacuum
  169. FLAG: NeedSchema NoColumns
  170. IF: !defined(SQLITE_OMIT_AUTOVACUUM)
  171. NAME: temp_store
  172. FLAG: Result0 NoColumns1
  173. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  174. NAME: temp_store_directory
  175. FLAG: NoColumns1
  176. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  177. NAME: data_store_directory
  178. FLAG: NoColumns1
  179. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
  180. NAME: lock_proxy_file
  181. FLAG: NoColumns1
  182. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
  183. NAME: synchronous
  184. FLAG: NeedSchema Result0 SchemaReq NoColumns1
  185. IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
  186. NAME: table_info
  187. FLAG: NeedSchema Result1 SchemaOpt
  188. ARG: 0
  189. COLS: cid name type notnull dflt_value pk
  190. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  191. NAME: table_xinfo
  192. TYPE: TABLE_INFO
  193. FLAG: NeedSchema Result1 SchemaOpt
  194. ARG: 1
  195. COLS: cid name type notnull dflt_value pk hidden
  196. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  197. NAME: table_list
  198. TYPE: TABLE_LIST
  199. FLAG: NeedSchema Result1
  200. COLS: schema name type ncol wr strict
  201. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  202. NAME: stats
  203. FLAG: NeedSchema Result0 SchemaReq
  204. COLS: tbl idx wdth hght flgs
  205. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
  206. NAME: index_info
  207. TYPE: INDEX_INFO
  208. ARG: 0
  209. FLAG: NeedSchema Result1 SchemaOpt
  210. COLS: seqno cid name
  211. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  212. NAME: index_xinfo
  213. TYPE: INDEX_INFO
  214. ARG: 1
  215. FLAG: NeedSchema Result1 SchemaOpt
  216. COLS: seqno cid name desc coll key
  217. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  218. NAME: index_list
  219. FLAG: NeedSchema Result1 SchemaOpt
  220. COLS: seq name unique origin partial
  221. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  222. NAME: database_list
  223. FLAG: Result0
  224. COLS: seq name file
  225. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  226. NAME: function_list
  227. FLAG: Result0
  228. COLS: name builtin type enc narg flags
  229. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  230. IF: !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
  231. NAME: module_list
  232. FLAG: Result0
  233. COLS: name
  234. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  235. IF: !defined(SQLITE_OMIT_VIRTUALTABLE)
  236. IF: !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
  237. NAME: pragma_list
  238. FLAG: Result0
  239. COLS: name
  240. IF: !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
  241. NAME: collation_list
  242. FLAG: Result0
  243. COLS: seq name
  244. IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
  245. NAME: foreign_key_list
  246. FLAG: NeedSchema Result1 SchemaOpt
  247. COLS: id seq table from to on_update on_delete match
  248. IF: !defined(SQLITE_OMIT_FOREIGN_KEY)
  249. NAME: foreign_key_check
  250. FLAG: NeedSchema Result0 Result1 SchemaOpt
  251. COLS: table rowid parent fkid
  252. IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
  253. NAME: parser_trace
  254. TYPE: FLAG
  255. ARG: SQLITE_ParserTrace
  256. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  257. IF: defined(SQLITE_DEBUG)
  258. NAME: case_sensitive_like
  259. FLAG: NoColumns
  260. IF: !defined(SQLITE_OMIT_CASE_SENSITIVE_LIKE_PRAGMA)
  261. NAME: integrity_check
  262. FLAG: NeedSchema Result0 Result1 SchemaOpt
  263. IF: !defined(SQLITE_OMIT_INTEGRITY_CHECK)
  264. NAME: quick_check
  265. TYPE: INTEGRITY_CHECK
  266. FLAG: NeedSchema Result0 Result1 SchemaOpt
  267. IF: !defined(SQLITE_OMIT_INTEGRITY_CHECK)
  268. NAME: encoding
  269. FLAG: Result0 NoColumns1
  270. IF: !defined(SQLITE_OMIT_UTF16)
  271. NAME: schema_version
  272. TYPE: HEADER_VALUE
  273. ARG: BTREE_SCHEMA_VERSION
  274. FLAG: NoColumns1 Result0
  275. IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
  276. NAME: user_version
  277. TYPE: HEADER_VALUE
  278. ARG: BTREE_USER_VERSION
  279. FLAG: NoColumns1 Result0
  280. IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
  281. NAME: data_version
  282. TYPE: HEADER_VALUE
  283. ARG: BTREE_DATA_VERSION
  284. FLAG: ReadOnly Result0
  285. IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
  286. NAME: freelist_count
  287. TYPE: HEADER_VALUE
  288. ARG: BTREE_FREE_PAGE_COUNT
  289. FLAG: ReadOnly Result0
  290. IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
  291. NAME: application_id
  292. TYPE: HEADER_VALUE
  293. ARG: BTREE_APPLICATION_ID
  294. FLAG: NoColumns1 Result0
  295. IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
  296. NAME: compile_options
  297. FLAG: Result0
  298. IF: !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
  299. NAME: wal_checkpoint
  300. FLAG: NeedSchema
  301. COLS: busy log checkpointed
  302. IF: !defined(SQLITE_OMIT_WAL)
  303. NAME: wal_autocheckpoint
  304. IF: !defined(SQLITE_OMIT_WAL)
  305. NAME: shrink_memory
  306. FLAG: NoColumns
  307. NAME: busy_timeout
  308. FLAG: Result0
  309. COLS: timeout
  310. NAME: lock_status
  311. FLAG: Result0
  312. COLS: database status
  313. IF: defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  314. NAME: activate_extensions
  315. IF: defined(SQLITE_ENABLE_CEROD)
  316. NAME: soft_heap_limit
  317. FLAG: Result0
  318. NAME: hard_heap_limit
  319. FLAG: Result0
  320. NAME: threads
  321. FLAG: Result0
  322. NAME: analysis_limit
  323. FLAG: Result0
  324. NAME: optimize
  325. FLAG: Result1 NeedSchema
  326. NAME: legacy_alter_table
  327. TYPE: FLAG
  328. ARG: SQLITE_LegacyAlter
  329. IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
  330. }
  331. # Open the output file
  332. #
  333. if {$argc>0} {
  334. set destfile [lindex $argv 0]
  335. } else {
  336. set destfile "[file dir [file dir [file normal $argv0]]]/src/pragma.h"
  337. puts "Overwriting $destfile with new pragma table..."
  338. }
  339. set fd [open $destfile wb]
  340. puts $fd {/* DO NOT EDIT!
  341. ** This file is automatically generated by the script at
  342. ** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit
  343. ** that script and rerun it.
  344. */}
  345. # Parse the PRAGMA table above.
  346. #
  347. set name {}
  348. set type {}
  349. set if {}
  350. set flags {}
  351. set cols {}
  352. set cols_list {}
  353. set arg 0
  354. proc record_one {} {
  355. global name type if arg allbyname typebyif flags cols all_cols
  356. global cols_list colUsedBy
  357. if {$name==""} return
  358. if {$cols!=""} {
  359. if {![info exists all_cols($cols)]} {
  360. set all_cols($cols) 1
  361. lappend cols_list $cols
  362. }
  363. set cx $cols
  364. lappend colUsedBy($cols) $name
  365. } else {
  366. set cx 0
  367. }
  368. set allbyname($name) [list $type $arg $if $flags $cols]
  369. set name {}
  370. set type {}
  371. set if {}
  372. set flags {}
  373. set cols {}
  374. set arg 0
  375. }
  376. foreach line [split $pragma_def \n] {
  377. set line [string trim $line]
  378. if {$line==""} continue
  379. foreach {id val} [split $line :] break
  380. set val [string trim $val]
  381. if {$id=="NAME"} {
  382. record_one
  383. set name $val
  384. set type [string toupper $val]
  385. } elseif {$id=="TYPE"} {
  386. set type $val
  387. if {$type=="FLAG"} {
  388. lappend flags Result0 NoColumns1
  389. }
  390. } elseif {$id=="ARG"} {
  391. set arg $val
  392. } elseif {$id=="COLS"} {
  393. set cols $val
  394. } elseif {$id=="IF"} {
  395. lappend if $val
  396. } elseif {$id=="FLAG"} {
  397. foreach term [split $val] {
  398. lappend flags $term
  399. set allflags($term) 1
  400. }
  401. } else {
  402. error "bad pragma_def line: $line"
  403. }
  404. }
  405. record_one
  406. set allnames [lsort [array names allbyname]]
  407. # Generate #defines for all pragma type names. Group the pragmas that are
  408. # omit in default builds (ex: defined(SQLITE_DEBUG))
  409. # at the end.
  410. #
  411. puts $fd "\n/* The various pragma types */"
  412. set pnum 0
  413. foreach name $allnames {
  414. set type [lindex $allbyname($name) 0]
  415. if {[info exists seentype($type)]} continue
  416. set if [lindex $allbyname($name) 2]
  417. if {[regexp SQLITE_DEBUG $if] || [regexp SQLITE_HAS_CODEC $if]} continue
  418. set seentype($type) 1
  419. puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
  420. incr pnum
  421. }
  422. foreach name $allnames {
  423. set type [lindex $allbyname($name) 0]
  424. if {[info exists seentype($type)]} continue
  425. set if [lindex $allbyname($name) 2]
  426. if {[regexp SQLITE_DEBUG $if]} continue
  427. set seentype($type) 1
  428. puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
  429. incr pnum
  430. }
  431. foreach name $allnames {
  432. set type [lindex $allbyname($name) 0]
  433. if {[info exists seentype($type)]} continue
  434. set seentype($type) 1
  435. puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
  436. incr pnum
  437. }
  438. # Generate #defines for flags
  439. #
  440. puts $fd "\n/* Property flags associated with various pragma. */"
  441. set fv 1
  442. foreach f [lsort [array names allflags]] {
  443. puts $fd [format {#define PragFlg_%-10s 0x%02x /* %s */} \
  444. $f $fv $flagMeaning($f)]
  445. set fv [expr {$fv*2}]
  446. }
  447. # Sort the column lists so that longer column lists occur first
  448. #
  449. proc colscmp {a b} {
  450. return [expr {[llength $b] - [llength $a]}]
  451. }
  452. set cols_list [lsort -command colscmp $cols_list]
  453. # Generate the array of column names used by pragmas that act like
  454. # queries.
  455. #
  456. puts $fd "\n/* Names of columns for pragmas that return multi-column result"
  457. puts $fd "** or that return single-column results where the name of the"
  458. puts $fd "** result column is different from the name of the pragma\n*/"
  459. puts $fd "static const char *const pragCName\[\] = {"
  460. set offset 0
  461. set allcollist {}
  462. foreach cols $cols_list {
  463. set n [llength $cols]
  464. set limit [expr {[llength $allcollist] - $n}]
  465. for {set i 0} {$i<$limit} {incr i} {
  466. set sublist [lrange $allcollist $i [expr {$i+$n-1}]]
  467. if {$sublist==$cols} {
  468. puts $fd [format "%27s/* $colUsedBy($cols) reuses $i */" ""]
  469. set cols_offset($cols) $i
  470. break
  471. }
  472. }
  473. if {$i<$limit} continue
  474. set cols_offset($cols) $offset
  475. set ub " /* Used by: $colUsedBy($cols) */"
  476. foreach c $cols {
  477. lappend allcollist $c
  478. puts $fd [format " /* %3d */ %-14s%s" $offset \"$c\", $ub]
  479. set ub ""
  480. incr offset
  481. }
  482. }
  483. puts $fd "\175;"
  484. # Generate the lookup table
  485. #
  486. puts $fd "\n/* Definitions of all built-in pragmas */"
  487. puts $fd "typedef struct PragmaName \173"
  488. puts $fd " const char *const zName; /* Name of pragma */"
  489. puts $fd " u8 ePragTyp; /* PragTyp_XXX value */"
  490. puts $fd " u8 mPragFlg; /* Zero or more PragFlg_XXX values */"
  491. puts $fd { u8 iPragCName; /* Start of column names in pragCName[] */}
  492. puts $fd " u8 nPragCName; \
  493. /* Num of col names. 0 means use pragma name */"
  494. puts $fd " u64 iArg; /* Extra argument */"
  495. puts $fd "\175 PragmaName;"
  496. puts $fd "static const PragmaName aPragmaName\[\] = \173"
  497. set current_if {}
  498. set spacer [format { %26s } {}]
  499. foreach name $allnames {
  500. foreach {type arg if flag cx} $allbyname($name) break
  501. if {$cx==0 || $cx==""} {
  502. set cy 0
  503. set nx 0
  504. } else {
  505. set cy $cols_offset($cx)
  506. set nx [llength $cx]
  507. }
  508. if {$if!=$current_if} {
  509. if {$current_if!=""} {
  510. foreach this_if $current_if {
  511. puts $fd "#endif"
  512. }
  513. }
  514. set current_if $if
  515. if {$current_if!=""} {
  516. foreach this_if $current_if {
  517. puts $fd "#if $this_if"
  518. }
  519. }
  520. }
  521. set typex [format PragTyp_%-23s $type,]
  522. if {$flag==""} {
  523. set flagx "0"
  524. } else {
  525. set flagx PragFlg_[join $flag {|PragFlg_}]
  526. }
  527. puts $fd " \173/* zName: */ \"$name\","
  528. puts $fd " /* ePragTyp: */ PragTyp_$type,"
  529. puts $fd " /* ePragFlg: */ $flagx,"
  530. puts $fd " /* ColNames: */ $cy, $nx,"
  531. puts $fd " /* iArg: */ $arg \175,"
  532. }
  533. if {$current_if!=""} {
  534. foreach this_if $current_if {
  535. puts $fd "#endif"
  536. }
  537. }
  538. puts $fd "\175;"
  539. # count the number of pragmas, for information purposes
  540. #
  541. set allcnt 0
  542. set dfltcnt 0
  543. foreach name $allnames {
  544. incr allcnt
  545. set if [lindex $allbyname($name) 2]
  546. if {[regexp {^defined} $if] || [regexp {[^!]defined} $if]} continue
  547. incr dfltcnt
  548. }
  549. puts $fd "/* Number of pragmas: $dfltcnt on by default, $allcnt total. */"