Hex Artifact Content
Not logged in

Artifact ab705d6d8d7add0c74599e236b33fc72c06c7e55:

File src/th.h part of check-in [0c99a1554a] - Modify the TH1 script interperter to use native characters rather than unsigned characters. Fix a bug in the combobox extension command of TH1. by drh on 2008-10-24 16:36:34.

0000: 0a 2f 2a 20 54 68 69 73 20 68 65 61 64 65 72 20  ./* This header 
0010: 66 69 6c 65 20 64 65 66 69 6e 65 73 20 74 68 65  file defines the
0020: 20 65 78 74 65 72 6e 61 6c 20 69 6e 74 65 72 66   external interf
0030: 61 63 65 20 74 6f 20 74 68 65 20 63 75 73 74 6f  ace to the custo
0040: 6d 20 53 63 72 69 70 74 69 6e 67 0a 2a 2a 20 4c  m Scripting.** L
0050: 61 6e 67 75 61 67 65 20 28 54 48 29 20 69 6e 74  anguage (TH) int
0060: 65 72 70 72 65 74 65 72 2e 20 20 54 48 20 69 73  erpreter.  TH is
0070: 20 76 65 72 79 20 73 69 6d 69 6c 61 72 20 74 6f   very similar to
0080: 20 54 43 4c 20 62 75 74 20 69 73 20 6e 6f 74 20   TCL but is not 
0090: 61 6e 0a 2a 2a 20 65 78 61 63 74 20 63 6c 6f 6e  an.** exact clon
00a0: 65 2e 0a 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 42 65 66  e..*/../*.** Bef
00b0: 6f 72 65 20 63 72 65 61 74 69 6e 67 20 61 6e 20  ore creating an 
00c0: 69 6e 74 65 72 70 72 65 74 65 72 2c 20 74 68 65  interpreter, the
00d0: 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 6d 75 73   application mus
00e0: 74 20 61 6c 6c 6f 63 61 74 65 20 61 6e 64 0a 2a  t allocate and.*
00f0: 2a 20 70 6f 70 75 6c 61 74 65 20 61 6e 20 69 6e  * populate an in
0100: 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f  stance of the fo
0110: 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72  llowing structur
0120: 65 2e 20 49 74 20 6d 75 73 74 20 72 65 6d 61 69  e. It must remai
0130: 6e 20 76 61 6c 69 64 0a 2a 2a 20 66 6f 72 20 74  n valid.** for t
0140: 68 65 20 6c 69 66 65 74 69 6d 65 20 6f 66 20 74  he lifetime of t
0150: 68 65 20 69 6e 74 65 72 70 72 65 74 65 72 2e 0a  he interpreter..
0160: 2a 2f 0a 73 74 72 75 63 74 20 54 68 5f 56 74 61  */.struct Th_Vta
0170: 62 20 7b 0a 20 20 76 6f 69 64 20 2a 28 2a 78 4d  b {.  void *(*xM
0180: 61 6c 6c 6f 63 29 28 75 6e 73 69 67 6e 65 64 20  alloc)(unsigned 
0190: 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 28 2a 78  int);.  void (*x
01a0: 46 72 65 65 29 28 76 6f 69 64 20 2a 29 3b 0a 7d  Free)(void *);.}
01b0: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74  ;.typedef struct
01c0: 20 54 68 5f 56 74 61 62 20 54 68 5f 56 74 61 62   Th_Vtab Th_Vtab
01d0: 3b 0a 0a 2f 2a 0a 2a 2a 20 4f 70 61 71 75 65 20  ;../*.** Opaque 
01e0: 68 61 6e 64 6c 65 20 66 6f 72 20 69 6e 74 65 72  handle for inter
01f0: 70 65 74 65 72 2e 0a 2a 2f 0a 74 79 70 65 64 65  peter..*/.typede
0200: 66 20 73 74 72 75 63 74 20 54 68 5f 49 6e 74 65  f struct Th_Inte
0210: 72 70 20 54 68 5f 49 6e 74 65 72 70 3b 0a 0a 2f  rp Th_Interp;../
0220: 2a 20 0a 2a 2a 20 43 72 65 61 74 65 20 61 6e 64  * .** Create and
0230: 20 64 65 6c 65 74 65 20 69 6e 74 65 72 70 72 65   delete interpre
0240: 74 65 72 73 2e 20 0a 2a 2f 0a 54 68 5f 49 6e 74  ters. .*/.Th_Int
0250: 65 72 70 20 2a 20 54 68 5f 43 72 65 61 74 65 49  erp * Th_CreateI
0260: 6e 74 65 72 70 28 54 68 5f 56 74 61 62 20 2a 70  nterp(Th_Vtab *p
0270: 56 74 61 62 29 3b 0a 76 6f 69 64 20 54 68 5f 44  Vtab);.void Th_D
0280: 65 6c 65 74 65 49 6e 74 65 72 70 28 54 68 5f 49  eleteInterp(Th_I
0290: 6e 74 65 72 70 20 2a 29 3b 0a 0a 2f 2a 20 0a 2a  nterp *);../* .*
02a0: 2a 20 45 76 61 6c 75 61 74 65 20 61 6e 20 54 48  * Evaluate an TH
02b0: 20 70 72 6f 67 72 61 6d 20 69 6e 20 74 68 65 20   program in the 
02c0: 73 74 61 63 6b 20 66 72 61 6d 65 20 69 64 65 6e  stack frame iden
02d0: 74 69 66 69 65 64 20 62 79 20 70 61 72 61 6d 65  tified by parame
02e0: 74 65 72 0a 2a 2a 20 69 46 72 61 6d 65 2c 20 61  ter.** iFrame, a
02f0: 63 63 6f 72 64 69 6e 67 20 74 6f 20 74 68 65 20  ccording to the 
0300: 66 6f 6c 6c 6f 77 69 6e 67 20 72 75 6c 65 73 3a  following rules:
0310: 0a 2a 2a 0a 2a 2a 20 20 20 2a 20 49 66 20 69 46  .**.**   * If iF
0320: 72 61 6d 65 20 69 73 20 30 2c 20 74 68 69 73 20  rame is 0, this 
0330: 6d 65 61 6e 73 20 74 68 65 20 63 75 72 72 65 6e  means the curren
0340: 74 20 66 72 61 6d 65 2e 0a 2a 2a 0a 2a 2a 20 20  t frame..**.**  
0350: 20 2a 20 49 66 20 69 46 72 61 6d 65 20 69 73 20   * If iFrame is 
0360: 6e 65 67 61 74 69 76 65 2c 20 74 68 65 6e 20 74  negative, then t
0370: 68 65 20 6e 74 68 20 66 72 61 6d 65 20 75 70 20  he nth frame up 
0380: 74 68 65 20 73 74 61 63 6b 2c 20 77 68 65 72 65  the stack, where
0390: 20 6e 20 69 73 20 0a 2a 2a 20 20 20 20 20 74 68   n is .**     th
03a0: 65 20 61 62 73 6f 6c 75 74 65 20 76 61 6c 75 65  e absolute value
03b0: 20 6f 66 20 69 46 72 61 6d 65 2e 20 41 20 76 61   of iFrame. A va
03c0: 6c 75 65 20 6f 66 20 2d 31 20 6d 65 61 6e 73 20  lue of -1 means 
03d0: 74 68 65 20 63 61 6c 6c 69 6e 67 0a 2a 2a 20 20  the calling.**  
03e0: 20 20 20 70 72 6f 63 65 64 75 72 65 2e 0a 2a 2a     procedure..**
03f0: 0a 2a 2a 20 20 20 2a 20 49 66 20 69 46 72 61 6d  .**   * If iFram
0400: 65 20 69 73 20 2b 76 65 2c 20 74 68 65 6e 20 74  e is +ve, then t
0410: 68 65 20 6e 74 68 20 66 72 61 6d 65 20 66 72 6f  he nth frame fro
0420: 6d 20 74 68 65 20 62 6f 74 74 6f 6d 20 6f 66 20  m the bottom of 
0430: 74 68 65 20 73 74 61 63 6b 2e 0a 2a 2a 20 20 20  the stack..**   
0440: 20 20 41 6e 20 69 46 72 61 6d 65 20 76 61 6c 75    An iFrame valu
0450: 65 20 6f 66 20 31 20 6d 65 61 6e 73 20 74 68 65  e of 1 means the
0460: 20 74 6f 70 6c 65 76 65 6c 20 28 67 6c 6f 62 61   toplevel (globa
0470: 6c 29 20 66 72 61 6d 65 2e 0a 2a 2f 0a 69 6e 74  l) frame..*/.int
0480: 20 54 68 5f 45 76 61 6c 28 54 68 5f 49 6e 74 65   Th_Eval(Th_Inte
0490: 72 70 20 2a 69 6e 74 65 72 70 2c 20 69 6e 74 20  rp *interp, int 
04a0: 69 46 72 61 6d 65 2c 20 63 6f 6e 73 74 20 63 68  iFrame, const ch
04b0: 61 72 20 2a 7a 50 72 6f 67 2c 20 69 6e 74 20 6e  ar *zProg, int n
04c0: 50 72 6f 67 29 3b 0a 0a 2f 2a 0a 2a 2a 20 45 76  Prog);../*.** Ev
04d0: 61 6c 75 61 74 65 20 61 20 54 48 20 65 78 70 72  aluate a TH expr
04e0: 65 73 73 69 6f 6e 2e 20 54 68 65 20 72 65 73 75  ession. The resu
04f0: 6c 74 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20  lt is stored in 
0500: 74 68 65 20 0a 2a 2a 20 69 6e 74 65 72 70 72 65  the .** interpre
0510: 74 65 72 20 72 65 73 75 6c 74 2e 0a 2a 2f 0a 69  ter result..*/.i
0520: 6e 74 20 54 68 5f 45 78 70 72 28 54 68 5f 49 6e  nt Th_Expr(Th_In
0530: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 63 6f  terp *interp, co
0540: 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 29  nst char *, int)
0550: 3b 0a 0a 2f 2a 20 0a 2a 2a 20 41 63 63 65 73 73  ;../* .** Access
0560: 20 54 48 20 76 61 72 69 61 62 6c 65 73 20 69 6e   TH variables in
0570: 20 74 68 65 20 63 75 72 72 65 6e 74 20 73 74 61   the current sta
0580: 63 6b 20 66 72 61 6d 65 2e 20 49 66 20 74 68 65  ck frame. If the
0590: 20 76 61 72 69 61 62 6c 65 20 6e 61 6d 65 0a 2a   variable name.*
05a0: 2a 20 62 65 67 69 6e 73 20 77 69 74 68 20 22 3a  * begins with ":
05b0: 3a 22 2c 20 74 68 65 20 6c 6f 6f 6b 75 70 20 69  :", the lookup i
05c0: 73 20 69 6e 20 74 68 65 20 74 6f 70 20 6c 65 76  s in the top lev
05d0: 65 6c 20 28 67 6c 6f 62 61 6c 29 20 66 72 61 6d  el (global) fram
05e0: 65 2e 20 0a 2a 2f 0a 69 6e 74 20 54 68 5f 47 65  e. .*/.int Th_Ge
05f0: 74 56 61 72 28 54 68 5f 49 6e 74 65 72 70 20 2a  tVar(Th_Interp *
0600: 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20  , const char *, 
0610: 69 6e 74 29 3b 0a 69 6e 74 20 54 68 5f 53 65 74  int);.int Th_Set
0620: 56 61 72 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c  Var(Th_Interp *,
0630: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69   const char *, i
0640: 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  nt, const char *
0650: 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 54 68 5f 4c  , int);.int Th_L
0660: 69 6e 6b 56 61 72 28 54 68 5f 49 6e 74 65 72 70  inkVar(Th_Interp
0670: 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a   *, const char *
0680: 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 63 6f 6e 73  , int, int, cons
0690: 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b 0a  t char *, int);.
06a0: 69 6e 74 20 54 68 5f 55 6e 73 65 74 56 61 72 28  int Th_UnsetVar(
06b0: 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20 63 6f 6e  Th_Interp *, con
06c0: 73 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b  st char *, int);
06d0: 0a 0a 74 79 70 65 64 65 66 20 69 6e 74 20 28 2a  ..typedef int (*
06e0: 54 68 5f 43 6f 6d 6d 61 6e 64 50 72 6f 63 29 28  Th_CommandProc)(
06f0: 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20 76 6f 69  Th_Interp *, voi
0700: 64 20 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20  d *, int, const 
0710: 63 68 61 72 20 2a 2a 2c 20 69 6e 74 20 2a 29 3b  char **, int *);
0720: 0a 0a 2f 2a 20 0a 2a 2a 20 52 65 67 69 73 74 65  ../* .** Registe
0730: 72 20 6e 65 77 20 63 6f 6d 6d 61 6e 64 73 2e 20  r new commands. 
0740: 0a 2a 2f 0a 69 6e 74 20 54 68 5f 43 72 65 61 74  .*/.int Th_Creat
0750: 65 43 6f 6d 6d 61 6e 64 28 0a 20 20 54 68 5f 49  eCommand(.  Th_I
0760: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 0a  nterp *interp, .
0770: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e    const char *zN
0780: 61 6d 65 2c 20 0a 20 20 2f 2a 20 69 6e 74 20 28  ame, .  /* int (
0790: 2a 78 50 72 6f 63 29 28 54 68 5f 49 6e 74 65 72  *xProc)(Th_Inter
07a0: 70 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 69 6e 74  p *, void *, int
07b0: 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2a 2c  , const char **,
07c0: 20 69 6e 74 20 2a 29 2c 20 2a 2f 0a 20 20 54 68   int *), */.  Th
07d0: 5f 43 6f 6d 6d 61 6e 64 50 72 6f 63 20 78 50 72  _CommandProc xPr
07e0: 6f 63 2c 0a 20 20 76 6f 69 64 20 2a 70 43 6f 6e  oc,.  void *pCon
07f0: 74 65 78 74 2c 0a 20 20 76 6f 69 64 20 28 2a 78  text,.  void (*x
0800: 44 65 6c 29 28 54 68 5f 49 6e 74 65 72 70 20 2a  Del)(Th_Interp *
0810: 2c 20 76 6f 69 64 20 2a 29 0a 29 3b 0a 0a 2f 2a  , void *).);../*
0820: 20 0a 2a 2a 20 44 65 6c 65 74 65 20 6f 72 20 72   .** Delete or r
0830: 65 6e 61 6d 65 20 63 6f 6d 6d 61 6e 64 73 2e 0a  ename commands..
0840: 2a 2f 0a 69 6e 74 20 54 68 5f 52 65 6e 61 6d 65  */.int Th_Rename
0850: 43 6f 6d 6d 61 6e 64 28 54 68 5f 49 6e 74 65 72  Command(Th_Inter
0860: 70 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20  p *, const char 
0870: 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68  *, int, const ch
0880: 61 72 20 2a 2c 20 69 6e 74 29 3b 0a 0a 2f 2a 20  ar *, int);../* 
0890: 0a 2a 2a 20 50 75 73 68 20 61 20 6e 65 77 20 73  .** Push a new s
08a0: 74 61 63 6b 20 66 72 61 6d 65 20 28 6c 6f 63 61  tack frame (loca
08b0: 6c 20 76 61 72 69 61 62 6c 65 20 63 6f 6e 74 65  l variable conte
08c0: 78 74 29 20 6f 6e 74 6f 20 74 68 65 20 69 6e 74  xt) onto the int
08d0: 65 72 70 72 65 74 65 72 20 0a 2a 2a 20 73 74 61  erpreter .** sta
08e0: 63 6b 2c 20 63 61 6c 6c 20 74 68 65 20 66 75 6e  ck, call the fun
08f0: 63 74 69 6f 6e 20 73 75 70 70 6c 69 65 64 20 61  ction supplied a
0900: 73 20 70 61 72 61 6d 65 74 65 72 20 78 43 61 6c  s parameter xCal
0910: 6c 20 77 69 74 68 20 74 68 65 20 74 77 6f 20 0a  l with the two .
0920: 2a 2a 20 63 6f 6e 74 65 78 74 20 61 72 67 75 6d  ** context argum
0930: 65 6e 74 73 2c 20 0a 2a 2a 0a 2a 2a 20 20 20 78  ents, .**.**   x
0940: 43 61 6c 6c 28 69 6e 74 65 72 70 2c 20 70 43 6f  Call(interp, pCo
0950: 6e 74 65 78 74 31 2c 20 70 43 6f 6e 74 65 78 74  ntext1, pContext
0960: 32 29 0a 2a 2a 0a 2a 2a 20 2c 20 74 68 65 6e 20  2).**.** , then 
0970: 70 6f 70 20 74 68 65 20 66 72 61 6d 65 20 6f 66  pop the frame of
0980: 66 20 6f 66 20 74 68 65 20 69 6e 74 65 72 70 72  f of the interpr
0990: 65 74 65 72 20 73 74 61 63 6b 2e 20 54 68 65 20  eter stack. The 
09a0: 76 61 6c 75 65 20 72 65 74 75 72 6e 65 64 0a 2a  value returned.*
09b0: 2a 20 62 79 20 74 68 65 20 78 43 61 6c 6c 28 29  * by the xCall()
09c0: 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 72 65 74   function is ret
09d0: 75 72 6e 65 64 20 61 73 20 74 68 65 20 72 65 73  urned as the res
09e0: 75 6c 74 20 6f 66 20 74 68 69 73 20 66 75 6e 63  ult of this func
09f0: 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73  tion..**.** This
0a00: 20 69 73 20 69 6e 74 65 6e 64 65 64 20 66 6f 72   is intended for
0a10: 20 75 73 65 20 62 79 20 74 68 65 20 69 6d 70 6c   use by the impl
0a20: 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 63 6f  ementation of co
0a30: 6d 6d 61 6e 64 73 20 73 75 63 68 20 61 73 0a 2a  mmands such as.*
0a40: 2a 20 74 68 6f 73 65 20 63 72 65 61 74 65 64 20  * those created 
0a50: 62 79 20 5b 70 72 6f 63 5d 2e 0a 2a 2f 0a 69 6e  by [proc]..*/.in
0a60: 74 20 54 68 5f 49 6e 46 72 61 6d 65 28 54 68 5f  t Th_InFrame(Th_
0a70: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 0a  Interp *interp,.
0a80: 20 20 69 6e 74 20 28 2a 78 43 61 6c 6c 29 28 54    int (*xCall)(T
0a90: 68 5f 49 6e 74 65 72 70 20 2a 2c 20 76 6f 69 64  h_Interp *, void
0aa0: 20 2a 70 43 6f 6e 74 65 78 74 31 2c 20 76 6f 69   *pContext1, voi
0ab0: 64 20 2a 70 43 6f 6e 74 65 78 74 32 29 2c 0a 20  d *pContext2),. 
0ac0: 20 76 6f 69 64 20 2a 70 43 6f 6e 74 65 78 74 31   void *pContext1
0ad0: 2c 0a 20 20 76 6f 69 64 20 2a 70 43 6f 6e 74 65  ,.  void *pConte
0ae0: 78 74 32 0a 29 3b 0a 0a 2f 2a 20 0a 2a 2a 20 56  xt2.);../* .** V
0af0: 61 6c 69 64 20 72 65 74 75 72 6e 20 63 6f 64 65  alid return code
0b00: 73 20 66 6f 72 20 78 50 72 6f 63 20 63 61 6c 6c  s for xProc call
0b10: 62 61 63 6b 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e  backs..*/.#defin
0b20: 65 20 54 48 5f 4f 4b 20 20 20 20 20 20 20 30 0a  e TH_OK       0.
0b30: 23 64 65 66 69 6e 65 20 54 48 5f 45 52 52 4f 52  #define TH_ERROR
0b40: 20 20 20 20 31 0a 23 64 65 66 69 6e 65 20 54 48      1.#define TH
0b50: 5f 42 52 45 41 4b 20 20 20 20 32 0a 23 64 65 66  _BREAK    2.#def
0b60: 69 6e 65 20 54 48 5f 52 45 54 55 52 4e 20 20 20  ine TH_RETURN   
0b70: 33 0a 23 64 65 66 69 6e 65 20 54 48 5f 43 4f 4e  3.#define TH_CON
0b80: 54 49 4e 55 45 20 34 0a 0a 2f 2a 20 0a 2a 2a 20  TINUE 4../* .** 
0b90: 53 65 74 20 61 6e 64 20 67 65 74 20 74 68 65 20  Set and get the 
0ba0: 69 6e 74 65 72 70 72 65 74 65 72 20 72 65 73 75  interpreter resu
0bb0: 6c 74 2e 20 0a 2a 2f 0a 69 6e 74 20 54 68 5f 53  lt. .*/.int Th_S
0bc0: 65 74 52 65 73 75 6c 74 28 54 68 5f 49 6e 74 65  etResult(Th_Inte
0bd0: 72 70 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72  rp *, const char
0be0: 20 2a 2c 20 69 6e 74 29 3b 0a 63 6f 6e 73 74 20   *, int);.const 
0bf0: 63 68 61 72 20 2a 54 68 5f 47 65 74 52 65 73 75  char *Th_GetResu
0c00: 6c 74 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20  lt(Th_Interp *, 
0c10: 69 6e 74 20 2a 29 3b 0a 63 68 61 72 20 2a 54 68  int *);.char *Th
0c20: 5f 54 61 6b 65 52 65 73 75 6c 74 28 54 68 5f 49  _TakeResult(Th_I
0c30: 6e 74 65 72 70 20 2a 2c 20 69 6e 74 20 2a 29 3b  nterp *, int *);
0c40: 0a 0a 2f 2a 0a 2a 2a 20 53 65 74 20 61 6e 20 65  ../*.** Set an e
0c50: 72 72 6f 72 20 6d 65 73 73 61 67 65 20 61 73 20  rror message as 
0c60: 74 68 65 20 69 6e 74 65 72 70 72 65 74 65 72 20  the interpreter 
0c70: 72 65 73 75 6c 74 2e 20 54 68 69 73 20 61 6c 73  result. This als
0c80: 6f 0a 2a 2a 20 73 65 74 73 20 74 68 65 20 67 6c  o.** sets the gl
0c90: 6f 62 61 6c 20 73 74 61 63 6b 2d 74 72 61 63 65  obal stack-trace
0ca0: 20 76 61 72 69 61 62 6c 65 20 24 3a 3a 74 68 5f   variable $::th_
0cb0: 73 74 61 63 6b 5f 74 72 61 63 65 2e 0a 2a 2f 0a  stack_trace..*/.
0cc0: 69 6e 74 20 54 68 5f 45 72 72 6f 72 4d 65 73 73  int Th_ErrorMess
0cd0: 61 67 65 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c  age(Th_Interp *,
0ce0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 63   const char *, c
0cf0: 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e 74  onst char *, int
0d00: 29 3b 0a 0a 2f 2a 20 0a 2a 2a 20 41 63 63 65 73  );../* .** Acces
0d10: 73 20 74 68 65 20 6d 65 6d 6f 72 79 20 6d 61 6e  s the memory man
0d20: 61 67 65 6d 65 6e 74 20 66 75 6e 63 74 69 6f 6e  agement function
0d30: 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74  s associated wit
0d40: 68 20 74 68 65 20 73 70 65 63 69 66 69 65 64 0a  h the specified.
0d50: 2a 2a 20 69 6e 74 65 72 70 72 65 74 65 72 2e 0a  ** interpreter..
0d60: 2a 2f 0a 76 6f 69 64 20 2a 54 68 5f 4d 61 6c 6c  */.void *Th_Mall
0d70: 6f 63 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20  oc(Th_Interp *, 
0d80: 69 6e 74 29 3b 0a 76 6f 69 64 20 54 68 5f 46 72  int);.void Th_Fr
0d90: 65 65 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20  ee(Th_Interp *, 
0da0: 76 6f 69 64 20 2a 29 3b 0a 0a 2f 2a 20 0a 2a 2a  void *);../* .**
0db0: 20 46 75 6e 63 74 69 6f 6e 73 20 66 6f 72 20 68   Functions for h
0dc0: 61 6e 64 6c 69 6e 67 20 54 48 20 6c 69 73 74 73  andling TH lists
0dd0: 2e 0a 2a 2f 0a 69 6e 74 20 54 68 5f 4c 69 73 74  ..*/.int Th_List
0de0: 41 70 70 65 6e 64 28 54 68 5f 49 6e 74 65 72 70  Append(Th_Interp
0df0: 20 2a 2c 20 63 68 61 72 20 2a 2a 2c 20 69 6e 74   *, char **, int
0e00: 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a   *, const char *
0e10: 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 54 68 5f 53  , int);.int Th_S
0e20: 70 6c 69 74 4c 69 73 74 28 54 68 5f 49 6e 74 65  plitList(Th_Inte
0e30: 72 70 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72  rp *, const char
0e40: 20 2a 2c 20 69 6e 74 2c 20 63 68 61 72 20 2a 2a   *, int, char **
0e50: 2a 2c 20 69 6e 74 20 2a 2a 2c 20 69 6e 74 20 2a  *, int **, int *
0e60: 29 3b 0a 0a 69 6e 74 20 54 68 5f 53 74 72 69 6e  );..int Th_Strin
0e70: 67 41 70 70 65 6e 64 28 54 68 5f 49 6e 74 65 72  gAppend(Th_Inter
0e80: 70 20 2a 2c 20 63 68 61 72 20 2a 2a 2c 20 69 6e  p *, char **, in
0e90: 74 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20  t *, const char 
0ea0: 2a 2c 20 69 6e 74 29 3b 0a 0a 2f 2a 20 0a 2a 2a  *, int);../* .**
0eb0: 20 46 75 6e 63 74 69 6f 6e 73 20 66 6f 72 20 68   Functions for h
0ec0: 61 6e 64 6c 69 6e 67 20 6e 75 6d 62 65 72 73 20  andling numbers 
0ed0: 61 6e 64 20 70 6f 69 6e 74 65 72 73 2e 0a 2a 2f  and pointers..*/
0ee0: 0a 69 6e 74 20 54 68 5f 54 6f 49 6e 74 28 54 68  .int Th_ToInt(Th
0ef0: 5f 49 6e 74 65 72 70 20 2a 2c 20 63 6f 6e 73 74  _Interp *, const
0f00: 20 63 68 61 72 20 2a 2c 20 69 6e 74 2c 20 69 6e   char *, int, in
0f10: 74 20 2a 29 3b 0a 69 6e 74 20 54 68 5f 54 6f 44  t *);.int Th_ToD
0f20: 6f 75 62 6c 65 28 54 68 5f 49 6e 74 65 72 70 20  ouble(Th_Interp 
0f30: 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c  *, const char *,
0f40: 20 69 6e 74 2c 20 64 6f 75 62 6c 65 20 2a 29 3b   int, double *);
0f50: 0a 69 6e 74 20 54 68 5f 53 65 74 52 65 73 75 6c  .int Th_SetResul
0f60: 74 49 6e 74 28 54 68 5f 49 6e 74 65 72 70 20 2a  tInt(Th_Interp *
0f70: 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 54 68 5f 53  , int);.int Th_S
0f80: 65 74 52 65 73 75 6c 74 44 6f 75 62 6c 65 28 54  etResultDouble(T
0f90: 68 5f 49 6e 74 65 72 70 20 2a 2c 20 64 6f 75 62  h_Interp *, doub
0fa0: 6c 65 29 3b 0a 0a 2f 2a 0a 2a 2a 20 44 72 6f 70  le);../*.** Drop
0fb0: 20 69 6e 20 72 65 70 6c 61 63 65 6d 65 6e 74 73   in replacements
0fc0: 20 66 6f 72 20 74 68 65 20 63 6f 72 72 65 73 70   for the corresp
0fd0: 6f 6e 64 69 6e 67 20 73 74 61 6e 64 61 72 64 20  onding standard 
0fe0: 6c 69 62 72 61 72 79 20 66 75 6e 63 74 69 6f 6e  library function
0ff0: 73 2e 0a 2a 2f 0a 69 6e 74 20 74 68 5f 73 74 72  s..*/.int th_str
1000: 6c 65 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a  len(const char *
1010: 29 3b 0a 69 6e 74 20 74 68 5f 69 73 64 69 67 69  );.int th_isdigi
1020: 74 28 63 68 61 72 29 3b 0a 69 6e 74 20 74 68 5f  t(char);.int th_
1030: 69 73 73 70 61 63 65 28 63 68 61 72 29 3b 0a 69  isspace(char);.i
1040: 6e 74 20 74 68 5f 69 73 61 6c 6e 75 6d 28 63 68  nt th_isalnum(ch
1050: 61 72 29 3b 0a 69 6e 74 20 74 68 5f 69 73 73 70  ar);.int th_issp
1060: 65 63 69 61 6c 28 63 68 61 72 29 3b 0a 63 68 61  ecial(char);.cha
1070: 72 20 2a 74 68 5f 73 74 72 64 75 70 28 54 68 5f  r *th_strdup(Th_
1080: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20  Interp *interp, 
1090: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 2c 20 69  const char *z, i
10a0: 6e 74 20 6e 29 3b 0a 0a 2f 2a 0a 2a 2a 20 49 6e  nt n);../*.** In
10b0: 74 65 72 66 61 63 65 73 20 74 6f 20 72 65 67 69  terfaces to regi
10c0: 73 74 65 72 20 74 68 65 20 6c 61 6e 67 75 61 67  ster the languag
10d0: 65 20 65 78 74 65 6e 73 69 6f 6e 73 2e 0a 2a 2f  e extensions..*/
10e0: 0a 69 6e 74 20 74 68 5f 72 65 67 69 73 74 65 72  .int th_register
10f0: 5f 6c 61 6e 67 75 61 67 65 28 54 68 5f 49 6e 74  _language(Th_Int
1100: 65 72 70 20 2a 69 6e 74 65 72 70 29 3b 20 20 20  erp *interp);   
1110: 20 20 20 20 20 20 20 20 20 2f 2a 20 74 68 5f 6c           /* th_l
1120: 61 6e 67 2e 63 20 2a 2f 0a 69 6e 74 20 74 68 5f  ang.c */.int th_
1130: 72 65 67 69 73 74 65 72 5f 73 71 6c 69 74 65 28  register_sqlite(
1140: 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  Th_Interp *inter
1150: 70 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 20  p);             
1160: 20 2f 2a 20 74 68 5f 73 71 6c 69 74 65 2e 63 20   /* th_sqlite.c 
1170: 2a 2f 0a 69 6e 74 20 74 68 5f 72 65 67 69 73 74  */.int th_regist
1180: 65 72 5f 76 66 73 28 54 68 5f 49 6e 74 65 72 70  er_vfs(Th_Interp
1190: 20 2a 69 6e 74 65 72 70 29 3b 20 20 20 20 20 20   *interp);      
11a0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 74 68             /* th
11b0: 5f 76 66 73 2e 63 20 2a 2f 0a 69 6e 74 20 74 68  _vfs.c */.int th
11c0: 5f 72 65 67 69 73 74 65 72 5f 74 65 73 74 76 66  _register_testvf
11d0: 73 28 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74  s(Th_Interp *int
11e0: 65 72 70 29 3b 20 20 20 20 20 20 20 20 20 20 20  erp);           
11f0: 20 20 2f 2a 20 74 68 5f 74 65 73 74 76 66 73 2e    /* th_testvfs.
1200: 63 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 47 65 6e 65  c */../*.** Gene
1210: 72 61 6c 20 70 75 72 70 6f 73 65 20 68 61 73 68  ral purpose hash
1220: 20 74 61 62 6c 65 20 66 72 6f 6d 20 74 68 5f 6c   table from th_l
1230: 61 6e 67 2e 63 2e 0a 2a 2f 0a 74 79 70 65 64 65  ang.c..*/.typede
1240: 66 20 73 74 72 75 63 74 20 54 68 5f 48 61 73 68  f struct Th_Hash
1250: 20 20 20 20 20 20 54 68 5f 48 61 73 68 3b 0a 74        Th_Hash;.t
1260: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 68  ypedef struct Th
1270: 5f 48 61 73 68 45 6e 74 72 79 20 54 68 5f 48 61  _HashEntry Th_Ha
1280: 73 68 45 6e 74 72 79 3b 0a 73 74 72 75 63 74 20  shEntry;.struct 
1290: 54 68 5f 48 61 73 68 45 6e 74 72 79 20 7b 0a 20  Th_HashEntry {. 
12a0: 20 76 6f 69 64 20 2a 70 44 61 74 61 3b 0a 20 20   void *pData;.  
12b0: 63 68 61 72 20 2a 7a 4b 65 79 3b 0a 20 20 69 6e  char *zKey;.  in
12c0: 74 20 6e 4b 65 79 3b 0a 20 20 54 68 5f 48 61 73  t nKey;.  Th_Has
12d0: 68 45 6e 74 72 79 20 2a 70 4e 65 78 74 3b 20 20  hEntry *pNext;  
12e0: 20 20 20 2f 2a 20 49 6e 74 65 72 6e 61 6c 20 75     /* Internal u
12f0: 73 65 20 6f 6e 6c 79 20 2a 2f 0a 7d 3b 0a 54 68  se only */.};.Th
1300: 5f 48 61 73 68 20 2a 54 68 5f 48 61 73 68 4e 65  _Hash *Th_HashNe
1310: 77 28 54 68 5f 49 6e 74 65 72 70 20 2a 29 3b 0a  w(Th_Interp *);.
1320: 76 6f 69 64 20 54 68 5f 48 61 73 68 44 65 6c 65  void Th_HashDele
1330: 74 65 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20  te(Th_Interp *, 
1340: 54 68 5f 48 61 73 68 20 2a 29 3b 0a 76 6f 69 64  Th_Hash *);.void
1350: 20 54 68 5f 48 61 73 68 49 74 65 72 61 74 65 28   Th_HashIterate(
1360: 54 68 5f 49 6e 74 65 72 70 2a 2c 54 68 5f 48 61  Th_Interp*,Th_Ha
1370: 73 68 2a 2c 76 6f 69 64 20 28 2a 78 29 28 54 68  sh*,void (*x)(Th
1380: 5f 48 61 73 68 45 6e 74 72 79 2a 2c 20 76 6f 69  _HashEntry*, voi
1390: 64 2a 29 2c 76 6f 69 64 2a 29 3b 0a 54 68 5f 48  d*),void*);.Th_H
13a0: 61 73 68 45 6e 74 72 79 20 2a 54 68 5f 48 61 73  ashEntry *Th_Has
13b0: 68 46 69 6e 64 28 54 68 5f 49 6e 74 65 72 70 2a  hFind(Th_Interp*
13c0: 2c 20 54 68 5f 48 61 73 68 2a 2c 20 63 6f 6e 73  , Th_Hash*, cons
13d0: 74 20 63 68 61 72 2a 2c 20 69 6e 74 2c 20 69 6e  t char*, int, in
13e0: 74 29 3b 0a 0a 2f 2a 0a 2a 2a 20 55 73 65 66 75  t);../*.** Usefu
13f0: 6c 20 66 75 6e 63 74 69 6f 6e 73 20 66 72 6f 6d  l functions from
1400: 20 74 68 5f 6c 61 6e 67 2e 63 2e 0a 2a 2f 0a 69   th_lang.c..*/.i
1410: 6e 74 20 54 68 5f 57 72 6f 6e 67 4e 75 6d 41 72  nt Th_WrongNumAr
1420: 67 73 28 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e  gs(Th_Interp *in
1430: 74 65 72 70 2c 20 63 6f 6e 73 74 20 63 68 61 72  terp, const char
1440: 20 2a 7a 4d 73 67 29 3b 0a 0a 74 79 70 65 64 65   *zMsg);..typede
1450: 66 20 73 74 72 75 63 74 20 54 68 5f 53 75 62 43  f struct Th_SubC
1460: 6f 6d 6d 61 6e 64 20 7b 63 68 61 72 20 2a 7a 4e  ommand {char *zN
1470: 61 6d 65 3b 20 54 68 5f 43 6f 6d 6d 61 6e 64 50  ame; Th_CommandP
1480: 72 6f 63 20 78 50 72 6f 63 3b 7d 20 54 68 5f 53  roc xProc;} Th_S
1490: 75 62 43 6f 6d 6d 61 6e 64 3b 0a 69 6e 74 20 54  ubCommand;.int T
14a0: 68 5f 43 61 6c 6c 53 75 62 43 6f 6d 6d 61 6e 64  h_CallSubCommand
14b0: 28 54 68 5f 49 6e 74 65 72 70 2a 2c 76 6f 69 64  (Th_Interp*,void
14c0: 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72  *,int,const char
14d0: 2a 2a 2c 69 6e 74 2a 2c 54 68 5f 53 75 62 43 6f  **,int*,Th_SubCo
14e0: 6d 6d 61 6e 64 2a 29 3b 0a                       mmand*);.