0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20 /*.** Copyright
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68 (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54 ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66 his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75 u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20 te it and/or.**
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20 modify it under
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65 the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62 GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76 lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65 ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 tributed in the
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20 l be useful,.**
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20 but WITHOUT ANY
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75 WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54 * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52 Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55 A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20 RPOSE. See the
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50 GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20 d have received
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72 g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69 ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65 te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20 ation, Inc., 59
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53 Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73 uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31 ton, MA 02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20 307, USA..**.**
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 nformation:.**
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 * http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65 .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75 contains code u
0380: 73 65 64 20 74 6f 20 70 61 72 73 65 72 20 74 69 sed to parser ti
0390: 63 6b 65 74 20 63 6f 6e 66 69 67 75 72 61 74 69 cket configurati
03a0: 6f 6e 0a 2a 2a 20 61 72 74 69 66 69 63 61 74 65 on.** artificate
03b0: 73 2e 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 s..*/.#include "
03c0: 63 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75 config.h".#inclu
03d0: 64 65 20 22 74 6b 74 63 6f 6e 66 2e 68 22 0a 23 de "tktconf.h".#
03e0: 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e include <assert.
03f0: 68 3e 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e h>../*.** Return
0400: 20 54 52 55 45 20 69 66 20 74 68 65 20 67 69 76 TRUE if the giv
0410: 65 6e 20 74 6f 6b 65 6e 20 69 73 20 61 20 76 61 en token is a va
0420: 6c 69 64 20 66 69 65 6c 64 20 6e 61 6d 65 20 66 lid field name f
0430: 6f 72 0a 2a 2a 20 74 68 65 20 74 69 63 6b 65 74 or.** the ticket
0440: 20 74 61 62 6c 65 2e 20 20 54 68 65 20 6e 61 6d table. The nam
0450: 65 20 6d 75 73 74 20 62 65 20 61 6c 6c 20 6c 65 e must be all le
0460: 74 74 65 72 73 2c 20 64 69 67 69 74 73 2c 20 0a tters, digits, .
0470: 2a 2a 20 61 6e 64 20 75 6e 64 65 72 73 63 6f 72 ** and underscor
0480: 65 73 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e es..*/.static in
0490: 74 20 69 73 5f 76 61 6c 69 64 5f 6e 61 6d 65 28 t is_valid_name(
04a0: 42 6c 6f 62 20 2a 70 29 7b 0a 20 20 63 6f 6e 73 Blob *p){. cons
04b0: 74 20 63 68 61 72 20 2a 7a 20 3d 20 62 6c 6f 62 t char *z = blob
04c0: 5f 62 75 66 66 65 72 28 70 29 3b 0a 20 20 69 6e _buffer(p);. in
04d0: 74 20 6e 20 3d 20 62 6c 6f 62 5f 73 69 7a 65 28 t n = blob_size(
04e0: 70 29 3b 0a 20 20 69 6e 74 20 69 3b 0a 0a 20 20 p);. int i;..
04f0: 66 6f 72 28 69 3d 30 3b 20 69 3c 6e 3b 20 69 2b for(i=0; i<n; i+
0500: 2b 29 7b 0a 20 20 20 20 69 66 28 20 21 69 73 61 +){. if( !isa
0510: 6c 6e 75 6d 28 7a 5b 69 5d 29 20 26 26 20 7a 5b lnum(z[i]) && z[
0520: 69 5d 21 3d 27 5f 27 20 29 7b 0a 20 20 20 20 20 i]!='_' ){.
0530: 20 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 20 7d return 0;. }
0540: 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 31 3b . }. return 1;
0550: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e .}../*.** Return
0560: 20 54 52 55 45 20 69 66 20 74 68 65 20 67 69 76 TRUE if the giv
0570: 65 6e 20 74 6f 6b 65 6e 20 69 73 20 61 20 76 61 en token is a va
0580: 6c 69 64 20 65 6e 75 6d 65 72 61 74 69 6f 6e 20 lid enumeration
0590: 76 61 6c 75 65 2e 0a 2a 2a 20 54 68 65 20 74 6f value..** The to
05a0: 6b 65 6e 20 6d 75 73 74 20 63 6f 6e 73 69 73 74 ken must consist
05b0: 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
05c0: 67 20 63 68 61 72 61 63 74 65 72 73 3a 0a 2a 2a g characters:.**
05d0: 0a 2a 2a 20 61 2d 7a 41 2d 5a 30 2d 39 5f 25 2f .** a-zA-Z0-9_%/
05e0: 2e 2d 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 .-.*/.static int
05f0: 20 69 73 5f 76 61 6c 69 64 5f 65 6e 75 6d 28 42 is_valid_enum(B
0600: 6c 6f 62 20 2a 70 29 7b 0a 20 20 63 6f 6e 73 74 lob *p){. const
0610: 20 63 68 61 72 20 2a 7a 20 3d 20 62 6c 6f 62 5f char *z = blob_
0620: 62 75 66 66 65 72 28 70 29 3b 0a 20 20 69 6e 74 buffer(p);. int
0630: 20 6e 20 3d 20 62 6c 6f 62 5f 73 69 7a 65 28 70 n = blob_size(p
0640: 29 3b 0a 20 20 69 6e 74 20 69 3b 0a 0a 20 20 66 );. int i;.. f
0650: 6f 72 28 69 3d 30 3b 20 69 3c 6e 3b 20 69 2b 2b or(i=0; i<n; i++
0660: 29 7b 0a 20 20 20 20 69 6e 74 20 63 20 3d 20 7a ){. int c = z
0670: 5b 69 5d 3b 0a 20 20 20 20 69 66 28 20 21 69 73 [i];. if( !is
0680: 61 6c 6e 75 6d 28 63 29 20 26 26 20 63 21 3d 27 alnum(c) && c!='
0690: 5f 27 20 26 26 20 63 21 3d 27 25 27 20 26 26 20 _' && c!='%' &&
06a0: 63 21 3d 27 2f 27 20 26 26 20 63 21 3d 27 2e 27 c!='/' && c!='.'
06b0: 20 26 26 20 63 21 3d 27 2d 27 20 29 7b 0a 20 20 && c!='-' ){.
06c0: 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a 20 20 return 0;.
06d0: 20 20 7d 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e }. }. return
06e0: 20 31 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 41 20 1;.}.../*.** A
06f0: 74 69 63 6b 65 74 20 63 6f 6e 66 69 67 75 72 61 ticket configura
0700: 74 69 6f 6e 20 72 65 63 6f 72 64 20 69 73 20 61 tion record is a
0710: 20 73 69 6e 67 6c 65 20 61 72 74 69 66 61 63 74 single artifact
0720: 20 74 68 61 74 20 64 65 66 69 6e 65 73 0a 2a 2a that defines.**
0730: 20 74 68 65 20 74 69 63 6b 65 74 20 63 6f 6e 66 the ticket conf
0740: 69 67 75 72 61 74 69 6f 6e 20 66 6f 72 20 61 20 iguration for a
0750: 73 65 72 76 65 72 2e 20 20 54 68 65 20 66 69 6c server. The fil
0760: 65 20 66 6f 72 6d 61 74 20 69 73 20 61 73 0a 2a e format is as.*
0770: 2a 20 66 6f 6c 6c 6f 77 73 3a 0a 2a 2a 0a 2a 2a * follows:.**.**
0780: 20 20 20 20 20 74 69 63 6b 65 74 2d 63 6f 6e 66 ticket-conf
0790: 69 67 75 72 61 74 69 6f 6e 0a 2a 2a 20 20 20 20 iguration.**
07a0: 20 66 69 65 6c 64 20 3c 66 69 65 6c 64 6e 61 6d field <fieldnam
07b0: 65 3e 20 3c 66 69 65 6c 64 74 79 70 65 3e 20 3c e> <fieldtype> <
07c0: 77 69 64 74 68 3e 20 3c 70 61 72 61 6d 3e 20 2e width> <param> .
07d0: 2e 2e 0a 2a 2a 20 20 20 20 20 74 65 6d 70 6c 61 ...** templa
07e0: 74 65 20 3c 74 79 70 65 3e 20 3c 64 65 6c 69 6d te <type> <delim
07f0: 69 74 65 72 3e 0a 2a 2a 20 20 20 20 20 3c 74 65 iter>.** <te
0800: 78 74 3e 0a 2a 2a 0a 2a 2a 20 41 6c 6c 20 6c 69 xt>.**.** All li
0810: 6e 65 73 20 61 72 65 20 73 65 70 61 72 61 74 65 nes are separate
0820: 64 20 62 79 20 5c 6e 2e 20 20 54 72 61 69 6c 69 d by \n. Traili
0830: 6e 67 20 77 68 69 74 65 73 70 61 63 65 20 69 73 ng whitespace is
0840: 0a 2a 2a 20 69 67 6e 6f 72 65 64 2e 20 20 54 68 .** ignored. Th
0850: 65 20 66 69 72 73 74 20 6c 69 6e 65 20 6d 75 73 e first line mus
0860: 74 20 62 65 20 22 74 69 63 6b 65 74 2d 63 6f 6e t be "ticket-con
0870: 66 69 67 75 72 61 74 69 6f 6e 22 2e 0a 2a 2a 20 figuration"..**
0880: 53 75 62 73 65 71 75 65 6e 74 20 6c 69 6e 65 73 Subsequent lines
0890: 20 61 72 65 20 65 69 74 68 65 72 20 22 66 69 65 are either "fie
08a0: 6c 64 22 20 6f 72 20 22 74 65 6d 70 6c 61 74 65 ld" or "template
08b0: 22 20 6c 69 6e 65 73 2e 0a 2a 2a 20 54 68 65 72 " lines..** Ther
08c0: 65 20 6d 75 73 74 20 62 65 20 65 78 61 63 74 6c e must be exactl
08d0: 79 20 74 68 72 65 65 20 74 65 6d 70 6c 61 74 65 y three template
08e0: 20 6c 69 6e 65 73 20 61 6e 64 20 6f 6e 65 20 6f lines and one o
08f0: 72 20 6d 6f 72 65 0a 2a 2a 20 66 69 65 6c 64 20 r more.** field
0900: 6c 69 6e 65 73 20 28 75 73 75 61 6c 6c 79 20 6d lines (usually m
0910: 6f 72 65 29 2e 0a 2a 2a 0a 2a 2a 20 46 69 65 6c ore)..**.** Fiel
0920: 64 20 6c 69 6e 65 73 20 64 65 66 69 6e 65 20 74 d lines define t
0930: 68 65 20 66 69 65 6c 64 73 20 6f 66 20 74 68 65 he fields of the
0940: 20 22 74 69 63 6b 65 74 22 20 74 61 62 6c 65 20 "ticket" table
0950: 69 6e 20 74 68 65 0a 2a 2a 20 64 61 74 61 62 61 in the.** databa
0960: 73 65 2e 20 20 54 68 65 20 66 69 65 6c 64 73 20 se. The fields
0970: 61 70 70 65 61 72 20 69 6e 20 74 68 65 20 74 61 appear in the ta
0980: 62 6c 65 20 69 6e 20 74 68 65 20 6f 72 64 65 72 ble in the order
0990: 20 69 6e 20 0a 2a 2a 20 77 68 69 63 68 20 74 68 in .** which th
09a0: 65 79 20 61 70 70 65 61 72 20 69 6e 20 74 68 65 ey appear in the
09b0: 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 61 configuration a
09c0: 72 74 69 66 61 63 74 2e 20 20 54 68 65 20 3c 66 rtifact. The <f
09d0: 69 65 6c 64 6e 61 6d 65 3e 0a 2a 2a 20 6d 75 73 ieldname>.** mus
09e0: 74 20 63 6f 6e 73 69 73 74 20 6f 66 20 61 6c 70 t consist of alp
09f0: 68 61 6e 75 6d 65 72 69 63 73 20 61 6e 64 20 75 hanumerics and u
0a00: 6e 64 65 72 73 63 6f 72 65 73 2e 20 20 3c 66 69 nderscores. <fi
0a10: 65 6c 64 74 79 70 65 3e 0a 2a 2a 20 69 73 20 6f eldtype>.** is o
0a20: 6e 65 20 6f 66 3a 20 20 74 65 78 74 2c 20 63 74 ne of: text, ct
0a30: 65 78 74 2c 20 65 6e 75 6d 2c 20 64 61 74 65 2c ext, enum, date,
0a40: 20 75 75 69 64 2c 20 62 61 73 65 6c 69 6e 65 2e uuid, baseline.
0a50: 20 20 41 6c 6c 0a 2a 2a 20 74 79 70 65 73 20 68 All.** types h
0a60: 61 76 65 20 61 74 20 6c 65 61 73 74 20 61 20 3c ave at least a <
0a70: 77 69 64 74 68 3e 20 70 61 72 61 6d 65 74 65 72 width> parameter
0a80: 2e 20 20 54 65 78 74 20 61 6e 64 20 43 74 65 78 . Text and Ctex
0a90: 74 20 74 79 70 65 73 0a 2a 2a 20 68 61 76 65 20 t types.** have
0aa0: 61 20 68 65 69 67 68 74 20 70 61 72 61 6d 65 74 a height paramet
0ab0: 65 72 2e 20 20 45 6e 75 6d 20 68 61 73 20 61 20 er. Enum has a
0ac0: 6c 69 73 74 20 6f 66 20 61 6c 6c 6f 77 65 64 20 list of allowed
0ad0: 76 61 6c 75 65 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 values..**.** Th
0ae0: 65 20 3c 74 79 70 65 3e 20 6f 66 20 61 20 74 65 e <type> of a te
0af0: 6d 70 6c 61 74 65 20 69 73 20 6f 6e 65 20 6f 66 mplate is one of
0b00: 3a 20 6e 65 77 2c 20 76 69 65 77 2c 20 65 64 69 : new, view, edi
0b10: 74 2e 20 20 54 68 65 72 65 20 6d 75 73 74 0a 2a t. There must.*
0b20: 2a 20 62 65 20 6f 6e 65 20 74 65 6d 70 6c 61 74 * be one templat
0b30: 65 20 6f 66 20 65 61 63 68 20 74 79 70 65 2e 20 e of each type.
0b40: 20 3c 64 65 6c 69 6d 69 74 65 72 3e 20 69 73 20 <delimiter> is
0b50: 61 6e 20 61 72 62 69 74 72 61 72 79 20 73 74 72 an arbitrary str
0b60: 69 6e 67 0a 2a 2a 20 74 68 61 74 20 74 65 72 6d ing.** that term
0b70: 69 6e 61 74 65 73 20 74 68 65 20 74 65 6d 70 6c inates the templ
0b80: 61 74 65 2e 20 20 54 68 65 20 62 6f 64 79 20 6f ate. The body o
0b90: 66 20 74 68 65 20 74 65 6d 70 6c 61 74 65 20 69 f the template i
0ba0: 73 20 73 75 62 73 65 71 75 65 6e 74 0a 2a 2a 20 s subsequent.**
0bb0: 6c 69 6e 65 73 20 6f 66 20 74 65 78 74 20 75 70 lines of text up
0bc0: 20 74 6f 20 62 75 74 20 6e 6f 74 20 69 6e 63 6c to but not incl
0bd0: 75 64 69 6e 67 20 74 68 65 20 3c 64 65 6c 69 6d uding the <delim
0be0: 69 74 65 72 3e 2e 20 20 54 72 61 69 6c 69 6e 67 iter>. Trailing
0bf0: 0a 2a 2a 20 77 68 69 74 65 73 70 61 63 65 20 6f .** whitespace o
0c00: 6e 20 74 68 65 20 64 65 6c 69 6d 69 74 65 72 20 n the delimiter
0c10: 69 73 20 69 67 6e 6f 72 65 64 2e 0a 2a 2a 0a 2a is ignored..**.*
0c20: 2a 20 54 68 65 20 70 43 6f 6e 66 69 67 20 70 61 * The pConfig pa
0c30: 72 61 6d 65 74 65 72 20 69 73 20 74 68 65 20 63 rameter is the c
0c40: 6f 6d 70 6c 65 74 65 20 74 65 78 74 20 6f 66 20 omplete text of
0c50: 74 68 65 20 63 6f 6e 66 69 67 75 72 61 74 69 6f the configuratio
0c60: 6e 0a 2a 2a 20 66 69 6c 65 20 74 6f 20 62 65 20 n.** file to be
0c70: 70 61 72 73 65 64 2e 20 20 74 65 73 74 46 6c 61 parsed. testFla
0c80: 67 20 69 73 20 31 20 74 6f 20 63 61 75 73 65 20 g is 1 to cause
0c90: 74 68 65 20 72 65 73 75 6c 74 73 20 74 6f 20 62 the results to b
0ca0: 65 20 70 72 69 6e 74 65 64 0a 2a 2a 20 6f 6e 20 e printed.** on
0cb0: 73 74 64 6f 75 74 20 6f 72 20 30 20 74 6f 20 63 stdout or 0 to c
0cc0: 61 75 73 65 20 72 65 73 75 6c 74 73 20 74 6f 20 ause results to
0cd0: 75 70 64 61 74 65 20 74 68 65 20 64 61 74 61 62 update the datab
0ce0: 61 73 65 2e 0a 2a 2a 0a 2a 2a 20 52 65 74 75 72 ase..**.** Retur
0cf0: 6e 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 n the number of
0d00: 65 72 72 6f 72 73 2e 20 20 49 66 20 74 68 65 72 errors. If ther
0d10: 65 20 69 73 20 61 6e 20 65 72 72 6f 72 20 61 6e e is an error an
0d20: 64 20 70 45 72 72 21 3d 4e 55 4c 4c 0a 2a 2a 20 d pErr!=NULL.**
0d30: 74 68 65 6e 20 6c 65 61 76 65 20 61 6e 20 65 72 then leave an er
0d40: 72 6f 72 20 6d 65 73 73 61 67 65 20 69 6e 20 70 ror message in p
0d50: 45 72 72 2e 20 20 57 65 20 61 73 73 75 6d 65 20 Err. We assume
0d60: 74 68 61 74 20 70 45 72 72 20 68 61 73 20 61 6c that pErr has al
0d70: 72 65 61 64 79 0a 2a 2a 20 62 65 65 6e 20 69 6e ready.** been in
0d80: 69 74 69 61 6c 69 7a 65 64 2e 0a 2a 2f 0a 69 6e itialized..*/.in
0d90: 74 20 74 69 63 6b 65 74 5f 63 6f 6e 66 69 67 5f t ticket_config_
0da0: 70 61 72 73 65 28 42 6c 6f 62 20 2a 70 43 6f 6e parse(Blob *pCon
0db0: 66 69 67 2c 20 69 6e 74 20 74 65 73 74 46 6c 61 fig, int testFla
0dc0: 67 2c 20 42 6c 6f 62 20 2a 70 45 72 72 29 7b 0a g, Blob *pErr){.
0dd0: 20 20 69 6e 74 20 72 63 20 3d 20 31 3b 0a 20 20 int rc = 1;.
0de0: 42 6c 6f 62 20 6c 69 6e 65 3b 0a 20 20 42 6c 6f Blob line;. Blo
0df0: 62 20 74 6f 6b 65 6e 3b 0a 20 20 42 6c 6f 62 20 b token;. Blob
0e00: 6e 61 6d 65 3b 0a 20 20 42 6c 6f 62 20 74 79 70 name;. Blob typ
0e10: 65 3b 0a 20 20 42 6c 6f 62 20 61 72 67 3b 0a 20 e;. Blob arg;.
0e20: 20 42 6c 6f 62 20 73 71 6c 3b 0a 20 20 42 6c 6f Blob sql;. Blo
0e30: 62 20 74 62 6c 64 65 66 3b 0a 20 20 42 6c 6f 62 b tbldef;. Blob
0e40: 20 65 72 72 3b 0a 20 20 69 6e 74 20 73 65 65 6e err;. int seen
0e50: 5f 74 65 6d 70 6c 61 74 65 20 3d 20 30 3b 0a 20 _template = 0;.
0e60: 20 69 6e 74 20 6c 69 6e 65 6e 6f 20 3d 20 30 3b int lineno = 0;
0e70: 0a 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 73 .. blob_zero(&s
0e80: 71 6c 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f ql);. blob_zero
0e90: 28 26 74 62 6c 64 65 66 29 3b 0a 20 20 62 6c 6f (&tbldef);. blo
0ea0: 62 5f 7a 65 72 6f 28 26 74 6f 6b 65 6e 29 3b 0a b_zero(&token);.
0eb0: 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 6e 61 6d blob_zero(&nam
0ec0: 65 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 e);. blob_zero(
0ed0: 26 74 79 70 65 29 3b 0a 20 20 62 6c 6f 62 5f 7a &type);. blob_z
0ee0: 65 72 6f 28 26 61 72 67 29 3b 0a 20 20 62 6c 6f ero(&arg);. blo
0ef0: 62 5f 7a 65 72 6f 28 26 65 72 72 29 3b 0a 0a 20 b_zero(&err);..
0f00: 20 2f 2a 20 54 68 65 20 63 6f 6e 66 69 67 75 72 /* The configur
0f10: 61 74 69 6f 6e 20 66 69 6c 65 20 6d 75 73 74 20 ation file must
0f20: 62 65 67 69 6e 20 77 69 74 68 20 61 20 6c 69 6e begin with a lin
0f30: 65 20 74 68 61 74 0a 20 20 2a 2a 20 73 61 79 73 e that. ** says
0f40: 20 22 74 69 63 6b 65 74 2d 63 6f 6e 66 69 67 75 "ticket-configu
0f50: 72 61 74 69 6f 6e 22 0a 20 20 2a 2f 0a 20 20 62 ration". */. b
0f60: 6c 6f 62 5f 6c 69 6e 65 28 70 43 6f 6e 66 69 67 lob_line(pConfig
0f70: 2c 20 26 6c 69 6e 65 29 3b 0a 20 20 62 6c 6f 62 , &line);. blob
0f80: 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20 26 74 _token(&line, &t
0f90: 6f 6b 65 6e 29 3b 0a 20 20 69 66 28 20 21 62 6c oken);. if( !bl
0fa0: 6f 62 5f 65 71 28 26 74 6f 6b 65 6e 2c 20 22 74 ob_eq(&token, "t
0fb0: 69 63 6b 65 74 2d 63 6f 6e 66 69 67 75 72 61 74 icket-configurat
0fc0: 69 6f 6e 22 29 20 29 7b 0a 20 20 20 20 62 6c 6f ion") ){. blo
0fd0: 62 5f 61 70 70 65 6e 64 66 28 26 65 72 72 2c 20 b_appendf(&err,
0fe0: 22 6d 69 73 73 69 6e 67 20 69 6e 69 74 69 61 6c "missing initial
0ff0: 69 7a 61 74 69 6f 6e 20 6b 65 79 77 6f 72 64 22 ization keyword"
1000: 29 3b 0a 20 20 20 20 67 6f 74 6f 20 62 61 64 5f );. goto bad_
1010: 63 6f 6e 66 69 67 5f 66 69 6c 65 3b 0a 20 20 7d config_file;. }
1020: 0a 20 20 6c 69 6e 65 6e 6f 2b 2b 3b 0a 0a 20 20 . lineno++;..
1030: 2f 2a 20 42 65 67 69 6e 20 61 63 63 75 6d 75 6c /* Begin accumul
1040: 61 74 69 6e 67 20 53 51 4c 20 74 65 78 74 20 74 ating SQL text t
1050: 68 61 74 20 77 69 6c 6c 20 69 6d 70 6c 65 6d 65 hat will impleme
1060: 6e 74 20 74 68 65 20 0a 20 20 2a 2a 20 74 69 63 nt the . ** tic
1070: 6b 65 74 20 63 6f 6e 66 69 67 75 72 61 74 69 6f ket configuratio
1080: 6e 2e 20 20 74 62 6c 64 65 66 20 77 69 6c 6c 20 n. tbldef will
1090: 68 6f 6c 64 20 74 68 65 20 74 69 63 6b 65 74 20 hold the ticket
10a0: 74 61 62 6c 65 0a 20 20 2a 2a 20 64 65 66 69 6e table. ** defin
10b0: 69 74 69 6f 6e 2e 20 20 73 71 6c 20 77 69 6c 6c ition. sql will
10c0: 20 68 6f 6c 64 20 74 65 78 74 20 74 6f 20 69 6e hold text to in
10d0: 69 74 69 61 6c 69 7a 65 20 61 6e 64 20 64 65 66 itialize and def
10e0: 69 6e 65 0a 20 20 2a 2a 20 74 68 65 20 74 6b 74 ine. ** the tkt
10f0: 66 69 65 6c 64 20 74 61 62 6c 65 20 61 6e 64 20 field table and
1100: 74 6f 20 69 6e 73 65 72 74 20 74 65 6d 70 6c 61 to insert templa
1110: 74 65 20 74 65 78 74 20 69 6e 74 6f 20 74 68 65 te text into the
1120: 0a 20 20 2a 2a 20 63 6f 6e 66 69 67 20 74 61 62 . ** config tab
1130: 6c 65 0a 20 20 2a 2f 0a 20 20 62 6c 6f 62 5f 61 le. */. blob_a
1140: 70 70 65 6e 64 66 28 26 74 62 6c 64 65 66 2c 20 ppendf(&tbldef,
1150: 0a 20 20 20 20 20 22 44 52 4f 50 20 54 41 42 4c . "DROP TABL
1160: 45 20 49 46 20 45 58 49 53 54 53 20 74 69 63 6b E IF EXISTS tick
1170: 65 74 3b 5c 6e 22 0a 20 20 20 20 20 22 43 52 45 et;\n". "CRE
1180: 41 54 45 20 54 41 42 4c 45 20 74 69 63 6b 65 74 ATE TABLE ticket
1190: 28 5c 6e 22 0a 20 20 20 20 20 22 20 20 74 6b 74 (\n". " tkt
11a0: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 id INTEGER PRIMA
11b0: 52 59 20 4b 45 59 2c 5c 6e 22 0a 20 20 20 20 20 RY KEY,\n".
11c0: 22 20 20 74 6b 74 75 75 69 64 20 54 45 58 54 20 " tktuuid TEXT
11d0: 55 4e 49 51 55 45 2c 5c 6e 22 0a 20 20 20 20 20 UNIQUE,\n".
11e0: 22 20 20 73 74 61 72 74 74 69 6d 65 20 44 41 54 " starttime DAT
11f0: 45 54 49 4d 45 2c 5c 6e 22 0a 20 20 20 20 20 22 ETIME,\n". "
1200: 20 20 6c 61 73 74 6d 6f 64 20 44 41 54 45 54 49 lastmod DATETI
1210: 4d 45 22 0a 20 20 29 3b 0a 20 20 62 6c 6f 62 5f ME". );. blob_
1220: 61 70 70 65 6e 64 66 28 26 73 71 6c 2c 0a 20 20 appendf(&sql,.
1230: 20 20 20 22 44 52 4f 50 20 54 41 42 4c 45 20 49 "DROP TABLE I
1240: 46 20 45 58 49 53 54 53 20 74 6b 74 66 69 65 6c F EXISTS tktfiel
1250: 64 3b 5c 6e 22 0a 20 20 20 20 20 22 43 52 45 41 d;\n". "CREA
1260: 54 45 20 54 41 42 4c 45 20 74 6b 74 66 69 65 6c TE TABLE tktfiel
1270: 64 28 5c 6e 22 0a 20 20 20 20 20 22 20 20 66 69 d(\n". " fi
1280: 64 78 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 dx INTEGER PRIMA
1290: 52 59 20 4b 45 59 2c 5c 6e 22 0a 20 20 20 20 20 RY KEY,\n".
12a0: 22 20 20 6e 61 6d 65 20 54 45 58 54 20 55 4e 49 " name TEXT UNI
12b0: 51 55 45 2c 5c 6e 22 0a 20 20 20 20 20 22 20 20 QUE,\n". "
12c0: 74 79 70 65 20 54 45 58 54 2c 5c 6e 22 0a 20 20 type TEXT,\n".
12d0: 20 20 20 22 20 20 77 69 64 74 68 20 49 4e 54 45 " width INTE
12e0: 47 45 52 2c 5c 6e 22 0a 20 20 20 20 20 22 20 20 GER,\n". "
12f0: 61 72 67 5c 6e 22 0a 20 20 20 20 20 22 29 3b 5c arg\n". ");\
1300: 6e 22 0a 20 20 29 3b 0a 0a 20 20 2f 2a 20 50 72 n". );.. /* Pr
1310: 6f 63 65 73 73 20 74 68 65 20 72 65 6d 61 69 6e ocess the remain
1320: 64 65 72 20 6f 66 20 74 68 65 20 63 6f 6e 66 69 der of the confi
1330: 67 75 72 61 74 69 6f 6e 20 66 69 6c 65 20 28 74 guration file (t
1340: 68 65 20 70 61 72 74 20 74 68 61 74 0a 20 20 2a he part that. *
1350: 2a 20 63 6f 6d 65 73 20 61 66 74 65 72 20 74 68 * comes after th
1360: 65 20 22 74 69 63 6b 65 74 2d 63 6f 6e 66 69 67 e "ticket-config
1370: 75 72 61 74 69 6f 6e 22 20 68 65 61 64 65 72 29 uration" header)
1380: 20 6c 69 6e 65 20 62 79 20 6c 69 6e 65 0a 20 20 line by line.
1390: 2a 2f 0a 20 20 77 68 69 6c 65 28 20 62 6c 6f 62 */. while( blob
13a0: 5f 6c 69 6e 65 28 70 43 6f 6e 66 69 67 2c 20 26 _line(pConfig, &
13b0: 6c 69 6e 65 29 20 29 7b 0a 20 20 20 20 63 68 61 line) ){. cha
13c0: 72 20 2a 7a 3b 0a 20 20 20 20 6c 69 6e 65 6e 6f r *z;. lineno
13d0: 2b 2b 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 ++;. if( blob
13e0: 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20 26 74 _token(&line, &t
13f0: 6f 6b 65 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20 oken)==0 ){.
1400: 20 20 2f 2a 20 49 67 6e 6f 72 65 20 62 6c 61 6e /* Ignore blan
1410: 6b 20 6c 69 6e 65 73 20 2a 2f 0a 20 20 20 20 20 k lines */.
1420: 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7d continue;. }
1430: 0a 20 20 20 20 7a 20 3d 20 62 6c 6f 62 5f 62 75 . z = blob_bu
1440: 66 66 65 72 28 26 74 6f 6b 65 6e 29 3b 0a 20 20 ffer(&token);.
1450: 20 20 69 66 28 20 7a 5b 30 5d 3d 3d 27 23 27 20 if( z[0]=='#'
1460: 29 7b 0a 20 20 20 20 20 20 2f 2a 20 49 67 6e 6f ){. /* Igno
1470: 72 65 20 63 6f 6d 6d 65 6e 74 20 6c 69 6e 65 73 re comment lines
1480: 20 2a 2f 0a 20 20 20 20 20 20 63 6f 6e 74 69 6e */. contin
1490: 75 65 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f ue;. }.. /
14a0: 2a 0a 20 20 20 20 2a 2a 20 20 20 20 66 69 65 6c *. ** fiel
14b0: 64 20 3c 6e 61 6d 65 3e 20 3c 74 79 70 65 3e 20 d <name> <type>
14c0: 3c 77 69 64 74 68 3e 20 3c 61 72 67 73 2e 2e 2e <width> <args...
14d0: 3e 0a 20 20 20 20 2a 2f 0a 20 20 20 20 69 66 28 >. */. if(
14e0: 20 62 6c 6f 62 5f 65 71 28 26 74 6f 6b 65 6e 2c blob_eq(&token,
14f0: 20 22 66 69 65 6c 64 22 29 0a 20 20 20 20 20 26 "field"). &
1500: 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 & blob_token(&li
1510: 6e 65 2c 26 6e 61 6d 65 29 0a 20 20 20 20 20 26 ne,&name). &
1520: 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 & blob_token(&li
1530: 6e 65 2c 26 74 79 70 65 29 0a 20 20 20 20 20 26 ne,&type). &
1540: 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 & blob_token(&li
1550: 6e 65 2c 26 61 72 67 29 0a 20 20 20 20 29 7b 0a ne,&arg). ){.
1560: 20 20 20 20 20 20 69 6e 74 20 77 69 64 74 68 3b int width;
1570: 0a 0a 20 20 20 20 20 20 69 66 28 20 21 69 73 5f .. if( !is_
1580: 76 61 6c 69 64 5f 6e 61 6d 65 28 26 6e 61 6d 65 valid_name(&name
1590: 29 20 29 7b 0a 20 20 20 20 20 20 20 20 62 6c 6f ) ){. blo
15a0: 62 5f 61 70 70 65 6e 64 66 28 26 65 72 72 2c 20 b_appendf(&err,
15b0: 22 69 6e 76 61 6c 69 64 20 66 69 65 6c 64 20 6e "invalid field n
15c0: 61 6d 65 3a 20 25 62 22 2c 20 26 6e 61 6d 65 29 ame: %b", &name)
15d0: 3b 0a 20 20 20 20 20 20 20 20 67 6f 74 6f 20 62 ;. goto b
15e0: 61 64 5f 63 6f 6e 66 69 67 5f 66 69 6c 65 3b 0a ad_config_file;.
15f0: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66 }. if
1600: 28 20 21 62 6c 6f 62 5f 69 73 5f 69 6e 74 28 26 ( !blob_is_int(&
1610: 61 72 67 2c 20 26 77 69 64 74 68 29 20 29 7b 0a arg, &width) ){.
1620: 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 blob_app
1630: 65 6e 64 66 28 26 65 72 72 2c 20 22 69 6e 76 61 endf(&err, "inva
1640: 6c 69 64 20 66 69 65 6c 64 20 77 69 64 74 68 3a lid field width:
1650: 20 25 62 22 2c 20 26 61 72 67 29 3b 0a 20 20 20 %b", &arg);.
1660: 20 20 20 20 20 67 6f 74 6f 20 62 61 64 5f 63 6f goto bad_co
1670: 6e 66 69 67 5f 66 69 6c 65 3b 0a 20 20 20 20 20 nfig_file;.
1680: 20 7d 0a 20 20 20 20 20 20 69 66 28 20 77 69 64 }. if( wid
1690: 74 68 3c 31 20 7c 7c 20 77 69 64 74 68 3e 32 30 th<1 || width>20
16a0: 30 20 29 7b 0a 20 20 20 20 20 20 20 20 62 6c 6f 0 ){. blo
16b0: 62 5f 61 70 70 65 6e 64 66 28 26 65 72 72 2c 20 b_appendf(&err,
16c0: 22 77 69 64 74 68 20 6c 65 73 73 20 74 68 61 6e "width less than
16d0: 20 31 20 6f 72 20 67 72 65 61 74 65 72 20 74 68 1 or greater th
16e0: 61 6e 20 32 30 30 22 29 3b 0a 20 20 20 20 20 20 an 200");.
16f0: 20 20 67 6f 74 6f 20 62 61 64 5f 63 6f 6e 66 69 goto bad_confi
1700: 67 5f 66 69 6c 65 3b 0a 20 20 20 20 20 20 7d 0a g_file;. }.
1710: 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e blob_appen
1720: 64 66 28 26 74 62 6c 64 65 66 2c 20 22 2c 5c 6e df(&tbldef, ",\n
1730: 20 20 74 6b 74 5f 25 62 22 2c 20 26 6e 61 6d 65 tkt_%b", &name
1740: 29 3b 0a 20 20 20 20 20 20 69 66 28 20 62 6c 6f );. if( blo
1750: 62 5f 65 71 28 26 74 79 70 65 2c 22 74 65 78 74 b_eq(&type,"text
1760: 22 29 20 7c 7c 20 62 6c 6f 62 5f 65 71 28 26 74 ") || blob_eq(&t
1770: 79 70 65 2c 22 63 74 65 78 74 22 29 20 29 7b 0a ype,"ctext") ){.
1780: 20 20 20 20 20 20 20 20 69 6e 74 20 68 65 69 67 int heig
1790: 68 74 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 ht;. if(
17a0: 21 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e !blob_token(&lin
17b0: 65 2c 20 26 61 72 67 29 20 7c 7c 20 21 62 6c 6f e, &arg) || !blo
17c0: 62 5f 69 73 5f 69 6e 74 28 26 61 72 67 2c 20 26 b_is_int(&arg, &
17d0: 68 65 69 67 68 74 29 20 29 7b 0a 20 20 20 20 20 height) ){.
17e0: 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 blob_append
17f0: 66 28 26 65 72 72 2c 20 22 69 6e 76 61 6c 69 64 f(&err, "invalid
1800: 20 68 65 69 67 68 74 3a 20 25 62 22 2c 20 26 61 height: %b", &a
1810: 72 67 29 3b 0a 20 20 20 20 20 20 20 20 20 20 67 rg);. g
1820: 6f 74 6f 20 62 61 64 5f 63 6f 6e 66 69 67 5f 66 oto bad_config_f
1830: 69 6c 65 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 ile;. }.
1840: 20 20 20 20 20 20 20 69 66 28 20 68 65 69 67 68 if( heigh
1850: 74 3c 31 20 7c 7c 20 68 65 69 67 68 74 3e 31 30 t<1 || height>10
1860: 30 30 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 00 ){.
1870: 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 65 72 blob_appendf(&er
1880: 72 2c 20 22 68 65 69 67 68 74 20 6c 65 73 73 20 r, "height less
1890: 74 68 61 6e 20 31 20 6f 72 20 67 72 65 61 74 65 than 1 or greate
18a0: 72 20 74 68 61 6e 20 31 30 30 30 22 29 3b 0a 20 r than 1000");.
18b0: 20 20 20 20 20 20 20 20 20 67 6f 74 6f 20 62 61 goto ba
18c0: 64 5f 63 6f 6e 66 69 67 5f 66 69 6c 65 3b 0a 20 d_config_file;.
18d0: 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 }.
18e0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73 blob_appendf(&s
18f0: 71 6c 2c 0a 20 20 20 20 20 20 20 20 20 20 22 49 ql,. "I
1900: 4e 53 45 52 54 20 49 4e 54 4f 20 74 6b 74 66 69 NSERT INTO tktfi
1910: 65 6c 64 28 6e 61 6d 65 2c 74 79 70 65 2c 77 69 eld(name,type,wi
1920: 64 74 68 2c 61 72 67 29 22 0a 20 20 20 20 20 20 dth,arg)".
1930: 20 20 20 20 22 56 41 4c 55 45 53 28 27 25 62 27 "VALUES('%b'
1940: 2c 27 25 62 27 2c 25 64 2c 25 64 29 3b 5c 6e 22 ,'%b',%d,%d);\n"
1950: 2c 0a 20 20 20 20 20 20 20 20 20 20 26 6e 61 6d ,. &nam
1960: 65 2c 20 26 74 79 70 65 2c 20 77 69 64 74 68 2c e, &type, width,
1970: 20 68 65 69 67 68 74 0a 20 20 20 20 20 20 20 20 height.
1980: 29 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 20 69 );. }else i
1990: 66 28 20 62 6c 6f 62 5f 65 71 28 26 74 79 70 65 f( blob_eq(&type
19a0: 2c 22 65 6e 75 6d 22 29 20 29 7b 0a 20 20 20 20 ,"enum") ){.
19b0: 20 20 20 20 69 6e 74 20 63 6e 74 20 3d 20 30 3b int cnt = 0;
19c0: 0a 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 . const c
19d0: 68 61 72 20 2a 7a 44 65 6c 69 6d 20 3d 20 22 27 har *zDelim = "'
19e0: 22 3b 0a 20 20 20 20 20 20 20 20 62 6c 6f 62 5f ";. blob_
19f0: 61 70 70 65 6e 64 66 28 26 73 71 6c 2c 0a 20 20 appendf(&sql,.
1a00: 20 20 20 20 20 20 20 20 22 49 4e 53 45 52 54 20 "INSERT
1a10: 49 4e 54 4f 20 74 6b 74 66 69 65 6c 64 28 6e 61 INTO tktfield(na
1a20: 6d 65 2c 74 79 70 65 2c 77 69 64 74 68 2c 61 72 me,type,width,ar
1a30: 67 29 22 0a 20 20 20 20 20 20 20 20 20 20 22 56 g)". "V
1a40: 41 4c 55 45 53 28 27 25 62 27 2c 27 25 62 27 2c ALUES('%b','%b',
1a50: 25 64 2c 22 2c 0a 20 20 20 20 20 20 20 20 20 20 %d,",.
1a60: 26 6e 61 6d 65 2c 20 26 74 79 70 65 2c 20 77 69 &name, &type, wi
1a70: 64 74 68 0a 20 20 20 20 20 20 20 20 29 3b 0a 20 dth. );.
1a80: 20 20 20 20 20 20 20 77 68 69 6c 65 28 20 62 6c while( bl
1a90: 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20 ob_token(&line,
1aa0: 26 61 72 67 29 20 29 7b 0a 20 20 20 20 20 20 20 &arg) ){.
1ab0: 20 20 20 69 66 28 20 21 69 73 5f 76 61 6c 69 64 if( !is_valid
1ac0: 5f 65 6e 75 6d 28 26 61 72 67 29 20 29 7b 0a 20 _enum(&arg) ){.
1ad0: 20 20 20 20 20 20 20 20 20 20 20 62 6c 6f 62 5f blob_
1ae0: 61 70 70 65 6e 64 66 28 26 65 72 72 2c 20 22 69 appendf(&err, "i
1af0: 6e 76 61 6c 69 64 20 65 6e 75 6d 65 72 61 74 69 nvalid enumerati
1b00: 6f 6e 20 76 61 6c 75 65 3a 20 25 62 22 2c 20 26 on value: %b", &
1b10: 61 72 67 29 3b 0a 20 20 20 20 20 20 20 20 20 20 arg);.
1b20: 20 20 67 6f 74 6f 20 62 61 64 5f 63 6f 6e 66 69 goto bad_confi
1b30: 67 5f 66 69 6c 65 3b 0a 20 20 20 20 20 20 20 20 g_file;.
1b40: 20 20 7d 0a 20 20 20 20 20 20 20 20 20 20 63 6e }. cn
1b50: 74 2b 2b 3b 0a 20 20 20 20 20 20 20 20 20 20 62 t++;. b
1b60: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73 71 6c lob_appendf(&sql
1b70: 2c 20 22 25 73 25 62 22 2c 20 7a 44 65 6c 69 6d , "%s%b", zDelim
1b80: 2c 20 26 61 72 67 29 3b 0a 20 20 20 20 20 20 20 , &arg);.
1b90: 20 20 20 7a 44 65 6c 69 6d 20 3d 20 22 20 22 3b zDelim = " ";
1ba0: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 . }.
1bb0: 20 20 20 69 66 28 20 63 6e 74 3c 32 20 29 7b 0a if( cnt<2 ){.
1bc0: 20 20 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 61 blob_a
1bd0: 70 70 65 6e 64 66 28 26 65 72 72 2c 20 22 6c 65 ppendf(&err, "le
1be0: 73 73 20 74 68 61 6e 20 32 20 65 6e 75 6d 65 72 ss than 2 enumer
1bf0: 61 74 69 6f 6e 20 76 61 6c 75 65 73 22 29 3b 0a ation values");.
1c00: 20 20 20 20 20 20 20 20 20 20 67 6f 74 6f 20 62 goto b
1c10: 61 64 5f 63 6f 6e 66 69 67 5f 66 69 6c 65 3b 0a ad_config_file;.
1c20: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 }.
1c30: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 blob_appendf(&
1c40: 73 71 6c 2c 22 27 29 3b 5c 6e 22 29 3b 0a 20 20 sql,"');\n");.
1c50: 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 62 6c }else if( bl
1c60: 6f 62 5f 65 71 28 26 74 79 70 65 2c 22 75 75 69 ob_eq(&type,"uui
1c70: 64 22 29 20 7c 7c 20 62 6c 6f 62 5f 65 71 28 26 d") || blob_eq(&
1c80: 74 79 70 65 2c 22 62 61 73 65 6c 69 6e 65 22 29 type,"baseline")
1c90: 20 7c 7c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ||.
1ca0: 20 20 20 20 62 6c 6f 62 5f 65 71 28 26 74 79 70 blob_eq(&typ
1cb0: 65 2c 22 64 61 74 65 22 29 20 29 7b 0a 20 20 20 e,"date") ){.
1cc0: 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 blob_append
1cd0: 66 28 26 73 71 6c 2c 0a 20 20 20 20 20 20 20 20 f(&sql,.
1ce0: 20 20 22 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 "INSERT INTO t
1cf0: 6b 74 66 69 65 6c 64 28 6e 61 6d 65 2c 74 79 70 ktfield(name,typ
1d00: 65 2c 77 69 64 74 68 29 22 0a 20 20 20 20 20 20 e,width)".
1d10: 20 20 20 20 22 56 41 4c 55 45 53 28 27 25 62 27 "VALUES('%b'
1d20: 2c 27 25 62 27 2c 25 64 29 3b 5c 6e 22 2c 0a 20 ,'%b',%d);\n",.
1d30: 20 20 20 20 20 20 20 20 20 26 6e 61 6d 65 2c 20 &name,
1d40: 26 74 79 70 65 2c 20 77 69 64 74 68 0a 20 20 20 &type, width.
1d50: 20 20 20 20 20 29 3b 0a 20 20 20 20 20 20 7d 65 );. }e
1d60: 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 62 6c 6f lse{. blo
1d70: 62 5f 61 70 70 65 6e 64 66 28 26 65 72 72 2c 20 b_appendf(&err,
1d80: 22 75 6e 6b 6e 6f 77 6e 20 66 69 65 6c 64 20 74 "unknown field t
1d90: 79 70 65 3a 20 25 62 22 2c 20 26 74 79 70 65 29 ype: %b", &type)
1da0: 3b 0a 20 20 20 20 20 20 20 20 67 6f 74 6f 20 62 ;. goto b
1db0: 61 64 5f 63 6f 6e 66 69 67 5f 66 69 6c 65 3b 0a ad_config_file;.
1dc0: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 0a 20 }. .
1dd0: 20 20 20 2f 2a 0a 20 20 20 20 2a 2a 20 20 74 65 /*. ** te
1de0: 6d 70 6c 61 74 65 20 3c 74 79 70 65 3e 20 3c 64 mplate <type> <d
1df0: 65 6c 69 6d 69 74 65 72 3e 0a 20 20 20 20 2a 2a elimiter>. **
1e00: 20 20 3c 74 65 78 74 3e 0a 20 20 20 20 2a 2f 20 <text>. */
1e10: 20 20 20 20 20 0a 20 20 20 20 7d 65 6c 73 65 20 . }else
1e20: 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 74 6f 6b if( blob_eq(&tok
1e30: 65 6e 2c 20 22 74 65 6d 70 6c 61 74 65 22 29 0a en, "template").
1e40: 20 20 20 20 20 20 20 20 20 20 20 26 26 20 62 6c && bl
1e50: 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20 ob_token(&line,
1e60: 26 74 79 70 65 29 0a 20 20 20 20 20 20 20 20 20 &type).
1e70: 20 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 && blob_token(
1e80: 26 6c 69 6e 65 2c 20 26 61 72 67 29 0a 20 20 20 &line, &arg).
1e90: 20 29 7b 0a 20 20 20 20 20 20 69 6e 74 20 69 64 ){. int id
1ea0: 78 3b 0a 20 20 20 20 20 20 42 6c 6f 62 20 63 6f x;. Blob co
1eb0: 6e 74 65 6e 74 3b 0a 20 20 20 20 20 20 69 6e 74 ntent;. int
1ec0: 20 73 74 61 72 74 3b 0a 20 20 20 20 20 20 69 6e start;. in
1ed0: 74 20 65 6e 64 3b 0a 0a 20 20 20 20 20 20 69 66 t end;.. if
1ee0: 28 20 62 6c 6f 62 5f 65 71 28 26 74 79 70 65 2c ( blob_eq(&type,
1ef0: 22 6e 65 77 22 29 20 29 7b 0a 20 20 20 20 20 20 "new") ){.
1f00: 20 20 69 64 78 20 3d 20 30 3b 0a 20 20 20 20 20 idx = 0;.
1f10: 20 7d 65 6c 73 65 20 69 66 28 20 62 6c 6f 62 5f }else if( blob_
1f20: 65 71 28 26 74 79 70 65 2c 20 22 76 69 65 77 22 eq(&type, "view"
1f30: 29 20 29 7b 0a 20 20 20 20 20 20 20 20 69 64 78 ) ){. idx
1f40: 20 3d 20 31 3b 0a 20 20 20 20 20 20 7d 65 6c 73 = 1;. }els
1f50: 65 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 74 e if( blob_eq(&t
1f60: 79 70 65 2c 20 22 65 64 69 74 22 29 20 29 7b 0a ype, "edit") ){.
1f70: 20 20 20 20 20 20 20 20 69 64 78 20 3d 20 32 3b idx = 2;
1f80: 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 . }else{.
1f90: 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e blob_appen
1fa0: 64 66 28 26 65 72 72 2c 20 22 75 6e 6b 6e 6f 77 df(&err, "unknow
1fb0: 6e 20 74 65 6d 70 6c 61 74 65 20 74 79 70 65 3a n template type:
1fc0: 20 25 62 22 2c 20 26 74 79 70 65 29 3b 0a 20 20 %b", &type);.
1fd0: 20 20 20 20 20 20 67 6f 74 6f 20 62 61 64 5f 63 goto bad_c
1fe0: 6f 6e 66 69 67 5f 66 69 6c 65 3b 0a 20 20 20 20 onfig_file;.
1ff0: 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 28 73 }. if( (s
2000: 65 65 6e 5f 74 65 6d 70 6c 61 74 65 20 26 20 28 een_template & (
2010: 31 3c 3c 69 64 78 29 29 21 3d 30 20 29 7b 0a 20 1<<idx))!=0 ){.
2020: 20 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 blob_appe
2030: 6e 64 66 28 26 65 72 72 2c 20 22 6d 6f 72 65 20 ndf(&err, "more
2040: 74 68 61 6e 20 6f 6e 65 20 25 62 20 74 65 6d 70 than one %b temp
2050: 6c 61 74 65 22 2c 20 26 74 79 70 65 29 3b 0a 20 late", &type);.
2060: 20 20 20 20 20 20 20 67 6f 74 6f 20 62 61 64 5f goto bad_
2070: 63 6f 6e 66 69 67 5f 66 69 6c 65 3b 0a 20 20 20 config_file;.
2080: 20 20 20 7d 0a 20 20 20 20 20 20 73 65 65 6e 5f }. seen_
2090: 74 65 6d 70 6c 61 74 65 20 7c 3d 20 31 3c 3c 69 template |= 1<<i
20a0: 64 78 3b 0a 20 20 20 20 20 20 73 74 61 72 74 20 dx;. start
20b0: 3d 20 65 6e 64 20 3d 20 62 6c 6f 62 5f 74 65 6c = end = blob_tel
20c0: 6c 28 70 43 6f 6e 66 69 67 29 3b 0a 20 20 20 20 l(pConfig);.
20d0: 20 20 77 68 69 6c 65 28 20 62 6c 6f 62 5f 6c 69 while( blob_li
20e0: 6e 65 28 70 43 6f 6e 66 69 67 2c 20 26 6c 69 6e ne(pConfig, &lin
20f0: 65 29 20 29 7b 0a 20 20 20 20 20 20 20 20 20 62 e) ){. b
2100: 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c lob_token(&line,
2110: 20 26 74 6f 6b 65 6e 29 3b 0a 20 20 20 20 20 20 &token);.
2120: 20 20 20 69 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 if( blob_comp
2130: 61 72 65 28 26 74 6f 6b 65 6e 2c 20 26 61 72 67 are(&token, &arg
2140: 29 3d 3d 30 20 29 20 62 72 65 61 6b 3b 0a 20 20 )==0 ) break;.
2150: 20 20 20 20 20 20 20 65 6e 64 20 3d 20 62 6c 6f end = blo
2160: 62 5f 74 65 6c 6c 28 70 43 6f 6e 66 69 67 29 3b b_tell(pConfig);
2170: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 62 . }. b
2180: 6c 6f 62 5f 69 6e 69 74 28 26 63 6f 6e 74 65 6e lob_init(&conten
2190: 74 2c 20 26 62 6c 6f 62 5f 62 75 66 66 65 72 28 t, &blob_buffer(
21a0: 70 43 6f 6e 66 69 67 29 5b 73 74 61 72 74 5d 2c pConfig)[start],
21b0: 20 65 6e 64 20 2d 20 73 74 61 72 74 29 3b 0a 20 end - start);.
21c0: 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 blob_append
21d0: 66 28 26 73 71 6c 2c 20 0a 20 20 20 20 20 20 20 f(&sql, .
21e0: 20 22 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 63 "REPLACE INTO c
21f0: 6f 6e 66 69 67 28 6e 61 6d 65 2c 20 76 61 6c 75 onfig(name, valu
2200: 65 29 20 56 41 4c 55 45 53 28 27 74 6b 74 2d 25 e) VALUES('tkt-%
2210: 62 2d 74 65 6d 70 6c 61 74 65 27 2c 25 42 29 3b b-template',%B);
2220: 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20 26 74 79 \n",. &ty
2230: 70 65 2c 20 26 63 6f 6e 74 65 6e 74 0a 20 20 20 pe, &content.
2240: 20 20 20 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 );. blob
2250: 5f 72 65 73 65 74 28 26 63 6f 6e 74 65 6e 74 29 _reset(&content)
2260: 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 ;. }else{.
2270: 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 blob_appendf(
2280: 26 65 72 72 2c 20 22 75 6e 6b 6e 6f 77 6e 20 63 &err, "unknown c
2290: 6f 6d 6d 61 6e 64 3a 20 25 62 22 2c 20 26 74 6f ommand: %b", &to
22a0: 6b 65 6e 29 3b 0a 20 20 20 20 20 20 67 6f 74 6f ken);. goto
22b0: 20 62 61 64 5f 63 6f 6e 66 69 67 5f 66 69 6c 65 bad_config_file
22c0: 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 ;. }. }. if
22d0: 28 20 73 65 65 6e 5f 74 65 6d 70 6c 61 74 65 20 ( seen_template
22e0: 21 3d 20 30 78 37 20 29 7b 0a 20 20 20 20 62 6c != 0x7 ){. bl
22f0: 6f 62 5f 61 70 70 65 6e 64 66 28 26 65 72 72 2c ob_appendf(&err,
2300: 20 22 6d 69 73 73 69 6e 67 20 74 65 6d 70 6c 61 "missing templa
2310: 74 65 73 22 29 3b 0a 20 20 20 20 67 6f 74 6f 20 tes");. goto
2320: 62 61 64 5f 63 6f 6e 66 69 67 5f 66 69 6c 65 3b bad_config_file;
2330: 0a 20 20 7d 0a 0a 20 20 2f 2a 20 49 66 20 77 65 . }.. /* If we
2340: 20 72 65 61 63 68 20 74 68 69 73 20 70 6f 69 6e reach this poin
2350: 74 20 69 74 20 6d 65 61 6e 73 20 74 68 65 20 70 t it means the p
2360: 61 72 73 65 20 77 61 73 20 73 75 63 63 65 73 73 arse was success
2370: 66 75 6c 0a 20 20 2a 2f 0a 20 20 72 63 20 3d 20 ful. */. rc =
2380: 30 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 0;. blob_append
2390: 66 28 26 74 62 6c 64 65 66 2c 20 22 5c 6e 29 3b f(&tbldef, "\n);
23a0: 5c 6e 22 29 3b 0a 20 20 69 66 28 20 74 65 73 74 \n");. if( test
23b0: 46 6c 61 67 20 29 7b 0a 20 20 20 20 62 6c 6f 62 Flag ){. blob
23c0: 5f 77 72 69 74 65 5f 74 6f 5f 66 69 6c 65 28 26 _write_to_file(&
23d0: 74 62 6c 64 65 66 2c 20 22 2d 22 29 3b 0a 20 20 tbldef, "-");.
23e0: 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f blob_write_to_
23f0: 66 69 6c 65 28 26 73 71 6c 2c 20 22 2d 22 29 3b file(&sql, "-");
2400: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 64 62 . }else{. db
2410: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 25 62 22 _multi_exec("%b"
2420: 2c 20 26 74 62 6c 64 65 66 29 3b 0a 20 20 20 20 , &tbldef);.
2430: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 25 db_multi_exec("%
2440: 62 22 2c 20 26 73 71 6c 29 3b 0a 20 20 7d 0a 0a b", &sql);. }..
2450: 62 61 64 5f 63 6f 6e 66 69 67 5f 66 69 6c 65 3a bad_config_file:
2460: 0a 20 20 69 66 28 20 72 63 20 26 26 20 70 45 72 . if( rc && pEr
2470: 72 20 29 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 r ){. blob_ap
2480: 70 65 6e 64 66 28 70 45 72 72 2c 20 22 6c 69 6e pendf(pErr, "lin
2490: 65 20 25 64 3a 20 25 62 22 2c 20 6c 69 6e 65 6e e %d: %b", linen
24a0: 6f 2c 20 26 65 72 72 29 3b 0a 20 20 7d 0a 20 20 o, &err);. }.
24b0: 62 6c 6f 62 5f 72 65 73 65 74 28 26 74 6f 6b 65 blob_reset(&toke
24c0: 6e 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 n);. blob_reset
24d0: 28 26 6c 69 6e 65 29 3b 0a 20 20 62 6c 6f 62 5f (&line);. blob_
24e0: 72 65 73 65 74 28 26 6e 61 6d 65 29 3b 0a 20 20 reset(&name);.
24f0: 62 6c 6f 62 5f 72 65 73 65 74 28 26 74 79 70 65 blob_reset(&type
2500: 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 );. blob_reset(
2510: 26 61 72 67 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 &arg);. blob_re
2520: 73 65 74 28 26 73 71 6c 29 3b 0a 20 20 62 6c 6f set(&sql);. blo
2530: 62 5f 72 65 73 65 74 28 26 74 62 6c 64 65 66 29 b_reset(&tbldef)
2540: 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 ;. blob_reset(&
2550: 65 72 72 29 3b 0a 20 20 72 65 74 75 72 6e 20 72 err);. return r
2560: 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d c;.}../*.** COMM
2570: 41 4e 44 3a 20 74 65 73 74 2d 74 6b 74 63 6f 6e AND: test-tktcon
2580: 66 69 67 2d 70 61 72 73 65 0a 2a 2f 0a 76 6f 69 fig-parse.*/.voi
2590: 64 20 74 65 73 74 5f 74 6b 74 63 6f 6e 66 69 67 d test_tktconfig
25a0: 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 42 6c _cmd(void){. Bl
25b0: 6f 62 20 63 6f 6e 66 69 67 2c 20 65 72 72 3b 0a ob config, err;.
25c0: 20 20 69 66 28 20 67 2e 61 72 67 63 21 3d 33 20 if( g.argc!=3
25d0: 29 7b 0a 20 20 20 20 75 73 61 67 65 28 22 46 49 ){. usage("FI
25e0: 4c 45 4e 41 4d 45 22 29 3b 0a 20 20 7d 0a 20 20 LENAME");. }.
25f0: 62 6c 6f 62 5f 72 65 61 64 5f 66 72 6f 6d 5f 66 blob_read_from_f
2600: 69 6c 65 28 26 63 6f 6e 66 69 67 2c 20 67 2e 61 ile(&config, g.a
2610: 72 67 76 5b 32 5d 29 3b 0a 20 20 62 6c 6f 62 5f rgv[2]);. blob_
2620: 7a 65 72 6f 28 26 65 72 72 29 3b 0a 20 20 74 69 zero(&err);. ti
2630: 63 6b 65 74 5f 63 6f 6e 66 69 67 5f 70 61 72 73 cket_config_pars
2640: 65 28 26 63 6f 6e 66 69 67 2c 20 31 2c 20 26 65 e(&config, 1, &e
2650: 72 72 29 3b 0a 20 20 69 66 28 20 62 6c 6f 62 5f rr);. if( blob_
2660: 73 69 7a 65 28 26 65 72 72 29 20 29 7b 0a 20 20 size(&err) ){.
2670: 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f blob_write_to_
2680: 66 69 6c 65 28 26 65 72 72 2c 20 22 2d 22 29 3b file(&err, "-");
2690: 0a 20 20 7d 0a 7d 0a . }.}.