Hex Artifact Content
Not logged in

Artifact 7258c955ba097b1b1819f8b53963fe33a7bf5a9b:

File src/th_main.c part of check-in [3122fc4c7e] - Continuing work on tickets (still not working right.) Improvements to the web pages. by drh on 2008-02-14 02:49:41. Also file src/th_main.c part of check-in [588bb7cd73] - Merged to ed26056bb5. by aku on 2008-02-24 18:50:35.

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 38 20 44 2e 20 52 69 63 68  (c) 2008 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 61 6e 20 69 6e 74   contains an int
0380: 65 72 66 61 63 65 20 62 65 74 77 65 65 6e 20 74  erface between t
0390: 68 65 20 54 48 20 73 63 72 69 70 74 69 6e 67 20  he TH scripting 
03a0: 6c 61 6e 67 75 61 67 65 0a 2a 2a 20 28 61 6e 20  language.** (an 
03b0: 69 6e 64 65 70 65 6e 64 65 6e 74 20 70 72 6f 6a  independent proj
03c0: 65 63 74 29 20 61 6e 64 20 66 6f 73 73 69 6c 2e  ect) and fossil.
03d0: 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f  .*/.#include "co
03e0: 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64 65  nfig.h".#include
03f0: 20 22 74 68 5f 6d 61 69 6e 2e 68 22 0a 0a 2f 2a   "th_main.h"../*
0400: 0a 2a 2a 20 47 6c 6f 62 61 6c 20 76 61 72 69 61  .** Global varia
0410: 62 6c 65 20 63 6f 75 6e 74 69 6e 67 20 74 68 65  ble counting the
0420: 20 6e 75 6d 62 65 72 20 6f 66 20 6f 75 74 73 74   number of outst
0430: 61 6e 64 69 6e 67 20 63 61 6c 6c 73 20 74 6f 20  anding calls to 
0440: 6d 61 6c 6c 6f 63 28 29 0a 2a 2a 20 6d 61 64 65  malloc().** made
0450: 20 62 79 20 74 68 65 20 74 68 31 20 69 6d 70 6c   by the th1 impl
0460: 65 6d 65 6e 74 61 74 69 6f 6e 2e 20 54 68 69 73  ementation. This
0470: 20 69 73 20 75 73 65 64 20 74 6f 20 63 61 74 63   is used to catc
0480: 68 20 6d 65 6d 6f 72 79 20 6c 65 61 6b 73 0a 2a  h memory leaks.*
0490: 2a 20 69 6e 20 74 68 65 20 69 6e 74 65 72 70 72  * in the interpr
04a0: 65 74 65 72 2e 20 4f 62 76 69 6f 75 73 6c 79 2c  eter. Obviously,
04b0: 20 69 74 20 61 6c 73 6f 20 6d 65 61 6e 73 20 74   it also means t
04c0: 68 31 20 69 73 20 6e 6f 74 20 74 68 72 65 61 64  h1 is not thread
04d0: 73 61 66 65 2e 0a 2a 2f 0a 73 74 61 74 69 63 20  safe..*/.static 
04e0: 69 6e 74 20 6e 4f 75 74 73 74 61 6e 64 69 6e 67  int nOutstanding
04f0: 4d 61 6c 6c 6f 63 20 3d 20 30 3b 0a 0a 2f 2a 0a  Malloc = 0;../*.
0500: 2a 2a 20 49 6d 70 6c 65 6d 65 6e 74 61 74 69 6f  ** Implementatio
0510: 6e 73 20 6f 66 20 6d 61 6c 6c 6f 63 28 29 20 61  ns of malloc() a
0520: 6e 64 20 66 72 65 65 28 29 20 74 6f 20 70 61 73  nd free() to pas
0530: 73 20 74 6f 20 74 68 65 20 69 6e 74 65 72 70 72  s to the interpr
0540: 65 74 65 72 2e 0a 2a 2f 0a 73 74 61 74 69 63 20  eter..*/.static 
0550: 76 6f 69 64 20 2a 78 4d 61 6c 6c 6f 63 28 75 6e  void *xMalloc(un
0560: 73 69 67 6e 65 64 20 69 6e 74 20 6e 29 7b 0a 20  signed int n){. 
0570: 20 76 6f 69 64 20 2a 70 20 3d 20 6d 61 6c 6c 6f   void *p = mallo
0580: 63 28 6e 29 3b 0a 20 20 69 66 28 20 70 20 29 7b  c(n);.  if( p ){
0590: 0a 20 20 20 20 6e 4f 75 74 73 74 61 6e 64 69 6e  .    nOutstandin
05a0: 67 4d 61 6c 6c 6f 63 2b 2b 3b 0a 20 20 7d 0a 20  gMalloc++;.  }. 
05b0: 20 72 65 74 75 72 6e 20 70 3b 0a 7d 0a 73 74 61   return p;.}.sta
05c0: 74 69 63 20 76 6f 69 64 20 78 46 72 65 65 28 76  tic void xFree(v
05d0: 6f 69 64 20 2a 70 29 7b 0a 20 20 69 66 28 20 70  oid *p){.  if( p
05e0: 20 29 7b 0a 20 20 20 20 6e 4f 75 74 73 74 61 6e   ){.    nOutstan
05f0: 64 69 6e 67 4d 61 6c 6c 6f 63 2d 2d 3b 0a 20 20  dingMalloc--;.  
0600: 7d 0a 20 20 66 72 65 65 28 70 29 3b 0a 7d 0a 73  }.  free(p);.}.s
0610: 74 61 74 69 63 20 54 68 5f 56 74 61 62 20 76 74  tatic Th_Vtab vt
0620: 61 62 20 3d 20 7b 20 78 4d 61 6c 6c 6f 63 2c 20  ab = { xMalloc, 
0630: 78 46 72 65 65 20 7d 3b 0a 0a 0a 2f 2a 0a 2a 2a  xFree };.../*.**
0640: 20 54 72 75 65 20 69 66 20 6f 75 74 70 75 74 20   True if output 
0650: 69 73 20 65 6e 61 62 6c 65 64 2e 20 20 46 61 6c  is enabled.  Fal
0660: 73 65 20 69 66 20 64 69 73 61 62 6c 65 64 2e 0a  se if disabled..
0670: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 65 6e  */.static int en
0680: 61 62 6c 65 4f 75 74 70 75 74 20 3d 20 31 3b 0a  ableOutput = 1;.
0690: 0a 2f 2a 0a 2a 2a 20 54 48 20 63 6f 6d 6d 61 6e  ./*.** TH comman
06a0: 64 3a 20 20 20 20 20 65 6e 61 62 6c 65 5f 6f 75  d:     enable_ou
06b0: 74 70 75 74 20 42 4f 4f 4c 45 41 4e 0a 2a 2a 0a  tput BOOLEAN.**.
06c0: 2a 2a 20 45 6e 61 62 6c 65 20 6f 72 20 64 69 73  ** Enable or dis
06d0: 61 62 6c 65 20 74 68 65 20 70 75 74 73 20 61 6e  able the puts an
06e0: 64 20 68 70 75 74 73 20 63 6f 6d 6d 61 6e 64 73  d hputs commands
06f0: 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20  ..*/.static int 
0700: 65 6e 61 62 6c 65 4f 75 74 70 75 74 43 6d 64 28  enableOutputCmd(
0710: 0a 20 20 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e  .  Th_Interp *in
0720: 74 65 72 70 2c 20 0a 20 20 76 6f 69 64 20 2a 70  terp, .  void *p
0730: 2c 20 0a 20 20 69 6e 74 20 61 72 67 63 2c 20 0a  , .  int argc, .
0740: 20 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64    const unsigned
0750: 20 63 68 61 72 20 2a 2a 61 72 67 76 2c 20 0a 20   char **argv, . 
0760: 20 69 6e 74 20 2a 61 72 67 6c 0a 29 7b 0a 20 20   int *argl.){.  
0770: 69 66 28 20 61 72 67 63 21 3d 32 20 29 7b 0a 20  if( argc!=2 ){. 
0780: 20 20 20 72 65 74 75 72 6e 20 54 68 5f 57 72 6f     return Th_Wro
0790: 6e 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70  ngNumArgs(interp
07a0: 2c 20 22 65 6e 61 62 6c 65 5f 6f 75 74 70 75 74  , "enable_output
07b0: 20 42 4f 4f 4c 45 41 4e 22 29 3b 0a 20 20 7d 0a   BOOLEAN");.  }.
07c0: 20 20 72 65 74 75 72 6e 20 54 68 5f 54 6f 49 6e    return Th_ToIn
07d0: 74 28 69 6e 74 65 72 70 2c 20 61 72 67 76 5b 31  t(interp, argv[1
07e0: 5d 2c 20 61 72 67 6c 5b 31 5d 2c 20 26 65 6e 61  ], argl[1], &ena
07f0: 62 6c 65 4f 75 74 70 75 74 29 3b 0a 7d 0a 0a 2f  bleOutput);.}../
0800: 2a 0a 2a 2a 20 53 65 6e 64 20 74 65 78 74 20 74  *.** Send text t
0810: 6f 20 74 68 65 20 61 70 70 72 6f 70 72 69 61 74  o the appropriat
0820: 65 20 6f 75 74 70 75 74 3a 20 20 45 69 74 68 65  e output:  Eithe
0830: 72 20 74 6f 20 74 68 65 20 63 6f 6e 73 6f 6c 65  r to the console
0840: 0a 2a 2a 20 6f 72 20 74 6f 20 74 68 65 20 43 47  .** or to the CG
0850: 49 20 72 65 70 6c 79 20 62 75 66 66 65 72 2e 0a  I reply buffer..
0860: 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 73  */.static void s
0870: 65 6e 64 54 65 78 74 28 63 6f 6e 73 74 20 63 68  endText(const ch
0880: 61 72 20 2a 7a 2c 20 69 6e 74 20 6e 2c 20 69 6e  ar *z, int n, in
0890: 74 20 65 6e 63 6f 64 65 29 7b 0a 20 20 69 66 28  t encode){.  if(
08a0: 20 65 6e 61 62 6c 65 4f 75 74 70 75 74 20 26 26   enableOutput &&
08b0: 20 6e 20 29 7b 0a 20 20 20 20 69 66 28 20 6e 3c   n ){.    if( n<
08c0: 30 20 29 20 6e 20 3d 20 73 74 72 6c 65 6e 28 7a  0 ) n = strlen(z
08d0: 29 3b 0a 20 20 20 20 69 66 28 20 65 6e 63 6f 64  );.    if( encod
08e0: 65 20 29 7b 0a 20 20 20 20 20 20 7a 20 3d 20 68  e ){.      z = h
08f0: 74 6d 6c 69 7a 65 28 7a 2c 20 6e 29 3b 0a 20 20  tmlize(z, n);.  
0900: 20 20 20 20 6e 20 3d 20 73 74 72 6c 65 6e 28 7a      n = strlen(z
0910: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28  );.    }.    if(
0920: 20 67 2e 63 67 69 50 61 6e 69 63 20 29 7b 0a 20   g.cgiPanic ){. 
0930: 20 20 20 20 20 63 67 69 5f 61 70 70 65 6e 64 5f       cgi_append_
0940: 63 6f 6e 74 65 6e 74 28 7a 2c 20 6e 29 3b 0a 20  content(z, n);. 
0950: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
0960: 66 77 72 69 74 65 28 7a 2c 20 31 2c 20 6e 2c 20  fwrite(z, 1, n, 
0970: 73 74 64 6f 75 74 29 3b 0a 20 20 20 20 7d 0a 20  stdout);.    }. 
0980: 20 20 20 69 66 28 20 65 6e 63 6f 64 65 20 29 20     if( encode ) 
0990: 66 72 65 65 28 28 63 68 61 72 2a 29 7a 29 3b 0a  free((char*)z);.
09a0: 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 48 20    }.}../*.** TH 
09b0: 63 6f 6d 6d 61 6e 64 3a 20 20 20 20 20 70 75 74  command:     put
09c0: 73 20 53 54 52 49 4e 47 0a 2a 2a 20 54 48 20 63  s STRING.** TH c
09d0: 6f 6d 6d 61 6e 64 3a 20 20 20 20 20 68 74 6d 6c  ommand:     html
09e0: 20 53 54 52 49 4e 47 0a 2a 2a 0a 2a 2a 20 4f 75   STRING.**.** Ou
09f0: 74 70 75 74 20 53 54 52 49 4e 47 20 61 73 20 48  tput STRING as H
0a00: 54 4d 4c 20 28 68 74 6d 6c 29 20 6f 72 20 75 6e  TML (html) or un
0a10: 63 68 61 6e 67 65 64 20 28 70 75 74 73 29 2e 20  changed (puts). 
0a20: 20 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20   .*/.static int 
0a30: 70 75 74 73 43 6d 64 28 0a 20 20 54 68 5f 49 6e  putsCmd(.  Th_In
0a40: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 0a 20  terp *interp, . 
0a50: 20 76 6f 69 64 20 2a 70 43 6f 6e 76 65 72 74 2c   void *pConvert,
0a60: 20 0a 20 20 69 6e 74 20 61 72 67 63 2c 20 0a 20   .  int argc, . 
0a70: 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20   const unsigned 
0a80: 63 68 61 72 20 2a 2a 61 72 67 76 2c 20 0a 20 20  char **argv, .  
0a90: 69 6e 74 20 2a 61 72 67 6c 0a 29 7b 0a 20 20 69  int *argl.){.  i
0aa0: 66 28 20 61 72 67 63 21 3d 32 20 29 7b 0a 20 20  f( argc!=2 ){.  
0ab0: 20 20 72 65 74 75 72 6e 20 54 68 5f 57 72 6f 6e    return Th_Wron
0ac0: 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70 2c  gNumArgs(interp,
0ad0: 20 22 70 75 74 73 20 53 54 52 49 4e 47 22 29 3b   "puts STRING");
0ae0: 0a 20 20 7d 0a 20 20 73 65 6e 64 54 65 78 74 28  .  }.  sendText(
0af0: 28 63 68 61 72 2a 29 61 72 67 76 5b 31 5d 2c 20  (char*)argv[1], 
0b00: 61 72 67 6c 5b 31 5d 2c 20 70 43 6f 6e 76 65 72  argl[1], pConver
0b10: 74 21 3d 30 29 3b 0a 20 20 72 65 74 75 72 6e 20  t!=0);.  return 
0b20: 54 48 5f 4f 4b 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  TH_OK;.}../*.** 
0b30: 54 48 20 63 6f 6d 6d 61 6e 64 3a 20 20 20 20 20  TH command:     
0b40: 20 77 69 6b 69 20 53 54 52 49 4e 47 0a 2a 2a 0a   wiki STRING.**.
0b50: 2a 2a 20 52 65 6e 64 65 72 20 74 68 65 20 69 6e  ** Render the in
0b60: 70 75 74 20 73 74 72 69 6e 67 20 61 73 20 77 69  put string as wi
0b70: 6b 69 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e  ki..*/.static in
0b80: 74 20 77 69 6b 69 43 6d 64 28 0a 20 20 54 68 5f  t wikiCmd(.  Th_
0b90: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20  Interp *interp, 
0ba0: 0a 20 20 76 6f 69 64 20 2a 70 2c 20 0a 20 20 69  .  void *p, .  i
0bb0: 6e 74 20 61 72 67 63 2c 20 0a 20 20 63 6f 6e 73  nt argc, .  cons
0bc0: 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20  t unsigned char 
0bd0: 2a 2a 61 72 67 76 2c 20 0a 20 20 69 6e 74 20 2a  **argv, .  int *
0be0: 61 72 67 6c 0a 29 7b 0a 20 20 69 66 28 20 61 72  argl.){.  if( ar
0bf0: 67 63 21 3d 32 20 29 7b 0a 20 20 20 20 72 65 74  gc!=2 ){.    ret
0c00: 75 72 6e 20 54 68 5f 57 72 6f 6e 67 4e 75 6d 41  urn Th_WrongNumA
0c10: 72 67 73 28 69 6e 74 65 72 70 2c 20 22 77 69 6b  rgs(interp, "wik
0c20: 69 20 53 54 52 49 4e 47 22 29 3b 0a 20 20 7d 0a  i STRING");.  }.
0c30: 20 20 69 66 28 20 65 6e 61 62 6c 65 4f 75 74 70    if( enableOutp
0c40: 75 74 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 73  ut ){.    Blob s
0c50: 72 63 3b 0a 20 20 20 20 62 6c 6f 62 5f 69 6e 69  rc;.    blob_ini
0c60: 74 28 26 73 72 63 2c 20 28 63 68 61 72 2a 29 61  t(&src, (char*)a
0c70: 72 67 76 5b 31 5d 2c 20 61 72 67 6c 5b 31 5d 29  rgv[1], argl[1])
0c80: 3b 0a 20 20 20 20 77 69 6b 69 5f 63 6f 6e 76 65  ;.    wiki_conve
0c90: 72 74 28 26 73 72 63 2c 20 30 2c 20 57 49 4b 49  rt(&src, 0, WIKI
0ca0: 5f 49 4e 4c 49 4e 45 29 3b 0a 20 20 20 20 62 6c  _INLINE);.    bl
0cb0: 6f 62 5f 72 65 73 65 74 28 26 73 72 63 29 3b 0a  ob_reset(&src);.
0cc0: 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 54 48 5f    }.  return TH_
0cd0: 4f 4b 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 48 20  OK;.}../*.** TH 
0ce0: 63 6f 6d 6d 61 6e 64 3a 20 20 20 20 20 68 61 73  command:     has
0cf0: 63 61 70 20 53 54 52 49 4e 47 0a 2a 2a 0a 2a 2a  cap STRING.**.**
0d00: 20 52 65 74 75 72 6e 20 74 72 75 65 20 69 66 20   Return true if 
0d10: 74 68 65 20 75 73 65 72 20 68 61 73 20 61 6c 6c  the user has all
0d20: 20 6f 66 20 74 68 65 20 63 61 70 61 62 69 6c 69   of the capabili
0d30: 74 69 65 73 20 6c 69 73 74 65 64 20 69 6e 20 53  ties listed in S
0d40: 54 52 49 4e 47 2e 0a 2a 2f 0a 73 74 61 74 69 63  TRING..*/.static
0d50: 20 69 6e 74 20 68 61 73 63 61 70 43 6d 64 28 0a   int hascapCmd(.
0d60: 20 20 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74    Th_Interp *int
0d70: 65 72 70 2c 20 0a 20 20 76 6f 69 64 20 2a 70 2c  erp, .  void *p,
0d80: 20 0a 20 20 69 6e 74 20 61 72 67 63 2c 20 0a 20   .  int argc, . 
0d90: 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20   const unsigned 
0da0: 63 68 61 72 20 2a 2a 61 72 67 76 2c 20 0a 20 20  char **argv, .  
0db0: 69 6e 74 20 2a 61 72 67 6c 0a 29 7b 0a 20 20 69  int *argl.){.  i
0dc0: 66 28 20 61 72 67 63 21 3d 32 20 29 7b 0a 20 20  f( argc!=2 ){.  
0dd0: 20 20 72 65 74 75 72 6e 20 54 68 5f 57 72 6f 6e    return Th_Wron
0de0: 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70 2c  gNumArgs(interp,
0df0: 20 22 68 61 73 63 61 70 20 53 54 52 49 4e 47 22   "hascap STRING"
0e00: 29 3b 0a 20 20 7d 0a 20 20 54 68 5f 53 65 74 52  );.  }.  Th_SetR
0e10: 65 73 75 6c 74 49 6e 74 28 69 6e 74 65 72 70 2c  esultInt(interp,
0e20: 20 6c 6f 67 69 6e 5f 68 61 73 5f 63 61 70 61 62   login_has_capab
0e30: 69 6c 69 74 79 28 28 63 68 61 72 2a 29 61 72 67  ility((char*)arg
0e40: 76 5b 31 5d 2c 61 72 67 6c 5b 31 5d 29 29 3b 0a  v[1],argl[1]));.
0e50: 20 20 72 65 74 75 72 6e 20 54 48 5f 4f 4b 3b 0a    return TH_OK;.
0e60: 7d 0a 0a 2f 2a 0a 2a 2a 20 54 48 31 20 63 6f 6d  }../*.** TH1 com
0e70: 6d 61 6e 64 3a 20 20 63 6f 6d 62 6f 62 6f 78 20  mand:  combobox 
0e80: 4e 41 4d 45 20 54 45 58 54 2d 4c 49 53 54 20 4e  NAME TEXT-LIST N
0e90: 55 4d 4c 49 4e 45 53 0a 2a 2a 0a 2a 2a 20 47 65  UMLINES.**.** Ge
0ea0: 6e 65 72 61 74 65 20 61 6e 20 48 54 4d 4c 20 63  nerate an HTML c
0eb0: 6f 6d 62 6f 62 6f 78 2e 20 20 4e 41 4d 45 20 69  ombobox.  NAME i
0ec0: 73 20 62 6f 74 68 20 74 68 65 20 6e 61 6d 65 20  s both the name 
0ed0: 6f 66 20 74 68 65 0a 2a 2a 20 43 47 49 20 70 61  of the.** CGI pa
0ee0: 72 61 6d 65 74 65 72 20 61 6e 64 20 74 68 65 20  rameter and the 
0ef0: 6e 61 6d 65 20 6f 66 20 61 20 76 61 72 69 61 62  name of a variab
0f00: 6c 65 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73  le that contains
0f10: 20 74 68 65 0a 2a 2a 20 63 75 72 72 65 6e 74 6c   the.** currentl
0f20: 79 20 73 65 6c 65 63 74 65 64 20 76 61 6c 75 65  y selected value
0f30: 2e 20 20 54 45 58 54 2d 4c 49 53 54 20 69 73 20  .  TEXT-LIST is 
0f40: 61 20 6c 69 73 74 20 6f 66 20 70 6f 73 73 69 62  a list of possib
0f50: 6c 65 0a 2a 2a 20 76 61 6c 75 65 73 20 66 6f 72  le.** values for
0f60: 20 74 68 65 20 63 6f 6d 62 6f 62 6f 78 2e 20 20   the combobox.  
0f70: 4e 55 4d 4c 49 4e 45 53 20 69 73 20 31 20 66 6f  NUMLINES is 1 fo
0f80: 72 20 61 20 74 72 75 65 20 63 6f 6d 62 6f 62 6f  r a true combobo
0f90: 78 2e 0a 2a 2a 20 49 66 20 4e 55 4d 4c 49 4e 45  x..** If NUMLINE
0fa0: 53 20 69 73 20 67 72 65 61 74 65 72 20 74 68 61  S is greater tha
0fb0: 6e 20 6f 6e 65 20 74 68 65 6e 20 74 68 65 20 64  n one then the d
0fc0: 69 73 70 6c 61 79 20 69 73 20 61 20 6c 69 73 74  isplay is a list
0fd0: 62 6f 78 0a 2a 2a 20 77 69 74 68 20 74 68 65 20  box.** with the 
0fe0: 6e 75 6d 62 65 72 20 6f 66 20 6c 69 6e 65 73 20  number of lines 
0ff0: 67 69 76 65 6e 2e 0a 2a 2f 0a 73 74 61 74 69 63  given..*/.static
1000: 20 69 6e 74 20 63 6f 6d 62 6f 62 6f 78 43 6d 64   int comboboxCmd
1010: 28 0a 20 20 54 68 5f 49 6e 74 65 72 70 20 2a 69  (.  Th_Interp *i
1020: 6e 74 65 72 70 2c 0a 20 20 76 6f 69 64 20 2a 70  nterp,.  void *p
1030: 2c 20 0a 20 20 69 6e 74 20 61 72 67 63 2c 20 0a  , .  int argc, .
1040: 20 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64    const unsigned
1050: 20 63 68 61 72 20 2a 2a 61 72 67 76 2c 20 0a 20   char **argv, . 
1060: 20 69 6e 74 20 2a 61 72 67 6c 0a 29 7b 0a 20 20   int *argl.){.  
1070: 69 66 28 20 61 72 67 63 21 3d 34 20 29 7b 0a 20  if( argc!=4 ){. 
1080: 20 20 20 72 65 74 75 72 6e 20 54 68 5f 57 72 6f     return Th_Wro
1090: 6e 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70  ngNumArgs(interp
10a0: 2c 20 22 63 6f 6d 62 6f 62 6f 78 20 4e 41 4d 45  , "combobox NAME
10b0: 20 54 45 58 54 2d 4c 49 53 54 20 4e 55 4d 4c 49   TEXT-LIST NUMLI
10c0: 4e 45 53 22 29 3b 0a 20 20 7d 0a 20 20 69 66 28  NES");.  }.  if(
10d0: 20 65 6e 61 62 6c 65 4f 75 74 70 75 74 20 29 7b   enableOutput ){
10e0: 0a 20 20 20 20 69 6e 74 20 68 65 69 67 68 74 3b  .    int height;
10f0: 0a 20 20 20 20 42 6c 6f 62 20 6c 69 73 74 2c 20  .    Blob list, 
1100: 65 6c 65 6d 2c 20 6e 61 6d 65 3b 0a 20 20 20 20  elem, name;.    
1110: 69 6e 74 20 6e 56 61 6c 75 65 3b 0a 20 20 20 20  int nValue;.    
1120: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c  const char *zVal
1130: 75 65 3b 0a 20 20 20 20 63 68 61 72 20 2a 7a 2c  ue;.    char *z,
1140: 20 2a 7a 48 3b 0a 0a 20 20 20 20 69 66 28 20 54   *zH;..    if( T
1150: 68 5f 54 6f 49 6e 74 28 69 6e 74 65 72 70 2c 20  h_ToInt(interp, 
1160: 61 72 67 76 5b 33 5d 2c 20 61 72 67 6c 5b 33 5d  argv[3], argl[3]
1170: 2c 20 26 68 65 69 67 68 74 29 20 29 20 72 65 74  , &height) ) ret
1180: 75 72 6e 20 54 48 5f 45 52 52 4f 52 3b 0a 20 20  urn TH_ERROR;.  
1190: 20 20 62 6c 6f 62 5f 69 6e 69 74 28 26 6c 69 73    blob_init(&lis
11a0: 74 2c 20 28 63 68 61 72 2a 29 61 72 67 76 5b 32  t, (char*)argv[2
11b0: 5d 2c 20 61 72 67 6c 5b 32 5d 29 3b 0a 20 20 20  ], argl[2]);.   
11c0: 20 62 6c 6f 62 5f 69 6e 69 74 28 26 6e 61 6d 65   blob_init(&name
11d0: 2c 20 28 63 68 61 72 2a 29 61 72 67 76 5b 31 5d  , (char*)argv[1]
11e0: 2c 20 61 72 67 6c 5b 31 5d 29 3b 0a 20 20 20 20  , argl[1]);.    
11f0: 7a 56 61 6c 75 65 20 3d 20 54 68 5f 46 65 74 63  zValue = Th_Fetc
1200: 68 28 62 6c 6f 62 5f 73 74 72 28 26 6e 61 6d 65  h(blob_str(&name
1210: 29 2c 20 26 6e 56 61 6c 75 65 29 3b 0a 20 20 20  ), &nValue);.   
1220: 20 7a 20 3d 20 6d 70 72 69 6e 74 66 28 22 3c 73   z = mprintf("<s
1230: 65 6c 65 63 74 20 6e 61 6d 65 3d 5c 22 25 7a 5c  elect name=\"%z\
1240: 22 20 73 69 7a 65 3d 5c 22 25 64 5c 22 3e 22 2c  " size=\"%d\">",
1250: 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20   .              
1260: 20 20 20 68 74 6d 6c 69 7a 65 28 62 6c 6f 62 5f     htmlize(blob_
1270: 62 75 66 66 65 72 28 26 6e 61 6d 65 29 2c 20 62  buffer(&name), b
1280: 6c 6f 62 5f 73 69 7a 65 28 26 6e 61 6d 65 29 29  lob_size(&name))
1290: 2c 20 68 65 69 67 68 74 29 3b 0a 20 20 20 20 73  , height);.    s
12a0: 65 6e 64 54 65 78 74 28 7a 2c 20 2d 31 2c 20 30  endText(z, -1, 0
12b0: 29 3b 0a 20 20 20 20 66 72 65 65 28 7a 29 3b 0a  );.    free(z);.
12c0: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26      blob_reset(&
12d0: 6e 61 6d 65 29 3b 0a 20 20 20 20 77 68 69 6c 65  name);.    while
12e0: 28 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69  ( blob_token(&li
12f0: 73 74 2c 20 26 65 6c 65 6d 29 20 29 7b 0a 20 20  st, &elem) ){.  
1300: 20 20 20 20 7a 48 20 3d 20 68 74 6d 6c 69 7a 65      zH = htmlize
1310: 28 62 6c 6f 62 5f 62 75 66 66 65 72 28 26 65 6c  (blob_buffer(&el
1320: 65 6d 29 2c 20 62 6c 6f 62 5f 73 69 7a 65 28 26  em), blob_size(&
1330: 65 6c 65 6d 29 29 3b 0a 20 20 20 20 20 20 69 66  elem));.      if
1340: 28 20 7a 56 61 6c 75 65 20 26 26 20 62 6c 6f 62  ( zValue && blob
1350: 5f 73 69 7a 65 28 26 65 6c 65 6d 29 3d 3d 6e 56  _size(&elem)==nV
1360: 61 6c 75 65 20 0a 20 20 20 20 20 20 20 20 20 20  alue .          
1370: 20 20 20 26 26 20 6d 65 6d 63 6d 70 28 7a 56 61     && memcmp(zVa
1380: 6c 75 65 2c 20 62 6c 6f 62 5f 62 75 66 66 65 72  lue, blob_buffer
1390: 28 26 65 6c 65 6d 29 2c 20 6e 56 61 6c 75 65 29  (&elem), nValue)
13a0: 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 20 7a  ==0 ){.        z
13b0: 20 3d 20 6d 70 72 69 6e 74 66 28 22 3c 6f 70 74   = mprintf("<opt
13c0: 69 6f 6e 20 76 61 6c 75 65 3d 5c 22 25 73 5c 22  ion value=\"%s\"
13d0: 20 73 65 6c 65 63 74 65 64 3e 25 73 3c 2f 6f 70   selected>%s</op
13e0: 74 69 6f 6e 3e 22 2c 20 7a 48 2c 20 7a 48 29 3b  tion>", zH, zH);
13f0: 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20  .      }else{.  
1400: 20 20 20 20 20 20 7a 20 3d 20 6d 70 72 69 6e 74        z = mprint
1410: 66 28 22 3c 6f 70 74 69 6f 6e 20 76 61 6c 75 65  f("<option value
1420: 3d 5c 22 25 73 5c 22 3e 25 73 3c 2f 6f 70 74 69  =\"%s\">%s</opti
1430: 6f 6e 3e 22 2c 20 7a 48 2c 20 7a 48 29 3b 0a 20  on>", zH, zH);. 
1440: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 66 72 65       }.      fre
1450: 65 28 7a 48 29 3b 0a 20 20 20 20 20 20 73 65 6e  e(zH);.      sen
1460: 64 54 65 78 74 28 7a 2c 20 2d 31 2c 20 30 29 3b  dText(z, -1, 0);
1470: 0a 20 20 20 20 20 20 66 72 65 65 28 7a 29 3b 0a  .      free(z);.
1480: 20 20 20 20 7d 0a 20 20 20 20 73 65 6e 64 54 65      }.    sendTe
1490: 78 74 28 22 3c 2f 73 65 6c 65 63 74 3e 22 2c 20  xt("</select>", 
14a0: 2d 31 2c 20 30 29 3b 0a 20 20 20 20 62 6c 6f 62  -1, 0);.    blob
14b0: 5f 72 65 73 65 74 28 26 6c 69 73 74 29 3b 0a 20  _reset(&list);. 
14c0: 20 7d 0a 20 20 72 65 74 75 72 6e 20 54 48 5f 4f   }.  return TH_O
14d0: 4b 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 48 31 20  K;.}../*.** TH1 
14e0: 63 6f 6d 6d 61 6e 64 3a 20 20 20 20 20 6c 69 6e  command:     lin
14f0: 65 63 6f 75 6e 74 20 53 54 52 49 4e 47 20 4d 41  ecount STRING MA
1500: 58 20 4d 49 4e 0a 2a 2a 0a 2a 2a 20 52 65 74 75  X MIN.**.** Retu
1510: 72 6e 20 6f 6e 65 20 6d 6f 72 65 20 74 68 61 6e  rn one more than
1520: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 5c   the number of \
1530: 6e 20 63 68 61 72 61 63 74 65 72 73 20 69 6e 20  n characters in 
1540: 53 54 52 49 4e 47 2e 20 20 42 75 74 0a 2a 2a 20  STRING.  But.** 
1550: 6e 65 76 65 72 20 72 65 74 75 72 6e 20 6c 65 73  never return les
1560: 73 20 74 68 61 6e 20 4d 49 4e 20 6f 72 20 6d 6f  s than MIN or mo
1570: 72 65 20 74 68 61 6e 20 4d 41 58 2e 0a 2a 2f 0a  re than MAX..*/.
1580: 73 74 61 74 69 63 20 69 6e 74 20 6c 69 6e 65 63  static int linec
1590: 6e 74 43 6d 64 28 0a 20 20 54 68 5f 49 6e 74 65  ntCmd(.  Th_Inte
15a0: 72 70 20 2a 69 6e 74 65 72 70 2c 0a 20 20 76 6f  rp *interp,.  vo
15b0: 69 64 20 2a 70 2c 20 0a 20 20 69 6e 74 20 61 72  id *p, .  int ar
15c0: 67 63 2c 20 0a 20 20 63 6f 6e 73 74 20 75 6e 73  gc, .  const uns
15d0: 69 67 6e 65 64 20 63 68 61 72 20 2a 2a 61 72 67  igned char **arg
15e0: 76 2c 20 0a 20 20 69 6e 74 20 2a 61 72 67 6c 0a  v, .  int *argl.
15f0: 29 7b 0a 20 20 63 6f 6e 73 74 20 75 63 68 61 72  ){.  const uchar
1600: 20 2a 7a 3b 0a 20 20 69 6e 74 20 73 69 7a 65 2c   *z;.  int size,
1610: 20 6e 2c 20 69 3b 0a 20 20 69 6e 74 20 69 4d 69   n, i;.  int iMi
1620: 6e 2c 20 69 4d 61 78 3b 0a 20 20 69 66 28 20 61  n, iMax;.  if( a
1630: 72 67 63 21 3d 34 20 29 7b 0a 20 20 20 20 72 65  rgc!=4 ){.    re
1640: 74 75 72 6e 20 54 68 5f 57 72 6f 6e 67 4e 75 6d  turn Th_WrongNum
1650: 41 72 67 73 28 69 6e 74 65 72 70 2c 20 22 6c 69  Args(interp, "li
1660: 6e 65 63 6f 75 6e 74 20 53 54 52 49 4e 47 20 4d  necount STRING M
1670: 41 58 20 4d 49 4e 22 29 3b 0a 20 20 7d 0a 20 20  AX MIN");.  }.  
1680: 69 66 28 20 54 68 5f 54 6f 49 6e 74 28 69 6e 74  if( Th_ToInt(int
1690: 65 72 70 2c 20 61 72 67 76 5b 32 5d 2c 20 61 72  erp, argv[2], ar
16a0: 67 6c 5b 32 5d 2c 20 26 69 4d 61 78 29 20 29 20  gl[2], &iMax) ) 
16b0: 72 65 74 75 72 6e 20 54 48 5f 45 52 52 4f 52 3b  return TH_ERROR;
16c0: 0a 20 20 69 66 28 20 54 68 5f 54 6f 49 6e 74 28  .  if( Th_ToInt(
16d0: 69 6e 74 65 72 70 2c 20 61 72 67 76 5b 33 5d 2c  interp, argv[3],
16e0: 20 61 72 67 6c 5b 33 5d 2c 20 26 69 4d 69 6e 29   argl[3], &iMin)
16f0: 20 29 20 72 65 74 75 72 6e 20 54 48 5f 45 52 52   ) return TH_ERR
1700: 4f 52 3b 0a 20 20 7a 20 3d 20 61 72 67 76 5b 31  OR;.  z = argv[1
1710: 5d 3b 0a 20 20 73 69 7a 65 20 3d 20 61 72 67 6c  ];.  size = argl
1720: 5b 31 5d 3b 0a 20 20 66 6f 72 28 6e 3d 31 2c 20  [1];.  for(n=1, 
1730: 69 3d 30 3b 20 69 3c 73 69 7a 65 3b 20 69 2b 2b  i=0; i<size; i++
1740: 29 7b 0a 20 20 20 20 69 66 28 20 7a 5b 69 5d 3d  ){.    if( z[i]=
1750: 3d 27 5c 6e 27 20 29 7b 0a 20 20 20 20 20 20 6e  ='\n' ){.      n
1760: 2b 2b 3b 0a 20 20 20 20 20 20 69 66 28 20 6e 3e  ++;.      if( n>
1770: 3d 69 4d 61 78 20 29 20 62 72 65 61 6b 3b 0a 20  =iMax ) break;. 
1780: 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20 6e     }.  }.  if( n
1790: 3c 69 4d 69 6e 20 29 20 6e 20 3d 20 69 4d 69 6e  <iMin ) n = iMin
17a0: 3b 0a 20 20 69 66 28 20 6e 3e 69 4d 61 78 20 29  ;.  if( n>iMax )
17b0: 20 6e 20 3d 20 69 4d 61 78 3b 0a 20 20 54 68 5f   n = iMax;.  Th_
17c0: 53 65 74 52 65 73 75 6c 74 49 6e 74 28 69 6e 74  SetResultInt(int
17d0: 65 72 70 2c 20 6e 29 3b 0a 20 20 72 65 74 75 72  erp, n);.  retur
17e0: 6e 20 54 48 5f 4f 4b 3b 0a 7d 0a 0a 2f 2a 0a 2a  n TH_OK;.}../*.*
17f0: 2a 20 4d 61 6b 65 20 73 75 72 65 20 74 68 65 20  * Make sure the 
1800: 69 6e 74 65 72 70 72 65 74 65 72 20 68 61 73 20  interpreter has 
1810: 62 65 65 6e 20 69 6e 69 74 69 61 6c 69 7a 65 64  been initialized
1820: 2e 0a 2a 2f 0a 76 6f 69 64 20 54 68 5f 46 6f 73  ..*/.void Th_Fos
1830: 73 69 6c 49 6e 69 74 28 76 6f 69 64 29 7b 0a 20  silInit(void){. 
1840: 20 73 74 61 74 69 63 20 73 74 72 75 63 74 20 5f   static struct _
1850: 43 6f 6d 6d 61 6e 64 20 7b 0a 20 20 20 20 63 6f  Command {.    co
1860: 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b  nst char *zName;
1870: 0a 20 20 20 20 54 68 5f 43 6f 6d 6d 61 6e 64 50  .    Th_CommandP
1880: 72 6f 63 20 78 50 72 6f 63 3b 0a 20 20 20 20 76  roc xProc;.    v
1890: 6f 69 64 20 2a 70 43 6f 6e 74 65 78 74 3b 0a 20  oid *pContext;. 
18a0: 20 7d 20 61 43 6f 6d 6d 61 6e 64 5b 5d 20 3d 20   } aCommand[] = 
18b0: 7b 0a 20 20 20 20 7b 22 63 6f 6d 62 6f 62 6f 78  {.    {"combobox
18c0: 22 2c 20 20 20 20 20 20 63 6f 6d 62 6f 62 6f 78  ",      combobox
18d0: 43 6d 64 2c 20 20 20 20 20 20 20 20 20 20 30 7d  Cmd,          0}
18e0: 2c 0a 20 20 20 20 7b 22 65 6e 61 62 6c 65 5f 6f  ,.    {"enable_o
18f0: 75 74 70 75 74 22 2c 20 65 6e 61 62 6c 65 4f 75  utput", enableOu
1900: 74 70 75 74 43 6d 64 2c 20 20 20 20 20 20 30 7d  tputCmd,      0}
1910: 2c 0a 20 20 20 20 7b 22 6c 69 6e 65 63 6f 75 6e  ,.    {"linecoun
1920: 74 22 2c 20 20 20 20 20 6c 69 6e 65 63 6e 74 43  t",     linecntC
1930: 6d 64 2c 20 20 20 20 20 20 20 20 20 20 20 30 7d  md,           0}
1940: 2c 0a 20 20 20 20 7b 22 68 61 73 63 61 70 22 2c  ,.    {"hascap",
1950: 20 20 20 20 20 20 20 20 68 61 73 63 61 70 43 6d          hascapCm
1960: 64 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 7d  d,            0}
1970: 2c 0a 20 20 20 20 7b 22 68 74 6d 6c 22 2c 20 20  ,.    {"html",  
1980: 20 20 20 20 20 20 20 20 70 75 74 73 43 6d 64 2c          putsCmd,
1990: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 7d                0}
19a0: 2c 0a 20 20 20 20 7b 22 70 75 74 73 22 2c 20 20  ,.    {"puts",  
19b0: 20 20 20 20 20 20 20 20 70 75 74 73 43 6d 64 2c          putsCmd,
19c0: 20 20 20 20 20 20 20 28 76 6f 69 64 2a 29 31 7d         (void*)1}
19d0: 2c 0a 20 20 20 20 7b 22 77 69 6b 69 22 2c 20 20  ,.    {"wiki",  
19e0: 20 20 20 20 20 20 20 20 77 69 6b 69 43 6d 64 2c          wikiCmd,
19f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 7d                0}
1a00: 2c 0a 20 20 7d 3b 0a 20 20 69 66 28 20 67 2e 69  ,.  };.  if( g.i
1a10: 6e 74 65 72 70 3d 3d 30 20 29 7b 0a 20 20 20 20  nterp==0 ){.    
1a20: 69 6e 74 20 69 3b 0a 20 20 20 20 67 2e 69 6e 74  int i;.    g.int
1a30: 65 72 70 20 3d 20 54 68 5f 43 72 65 61 74 65 49  erp = Th_CreateI
1a40: 6e 74 65 72 70 28 26 76 74 61 62 29 3b 0a 20 20  nterp(&vtab);.  
1a50: 20 20 74 68 5f 72 65 67 69 73 74 65 72 5f 6c 61    th_register_la
1a60: 6e 67 75 61 67 65 28 67 2e 69 6e 74 65 72 70 29  nguage(g.interp)
1a70: 3b 20 20 20 20 20 20 20 2f 2a 20 42 61 73 69 63  ;       /* Basic
1a80: 20 73 63 72 69 70 74 69 6e 67 20 63 6f 6d 6d 61   scripting comma
1a90: 6e 64 73 2e 20 2a 2f 0a 20 20 20 20 66 6f 72 28  nds. */.    for(
1aa0: 69 3d 30 3b 20 69 3c 73 69 7a 65 6f 66 28 61 43  i=0; i<sizeof(aC
1ab0: 6f 6d 6d 61 6e 64 29 2f 73 69 7a 65 6f 66 28 61  ommand)/sizeof(a
1ac0: 43 6f 6d 6d 61 6e 64 5b 30 5d 29 3b 20 69 2b 2b  Command[0]); i++
1ad0: 29 7b 0a 20 20 20 20 20 20 54 68 5f 43 72 65 61  ){.      Th_Crea
1ae0: 74 65 43 6f 6d 6d 61 6e 64 28 67 2e 69 6e 74 65  teCommand(g.inte
1af0: 72 70 2c 20 61 43 6f 6d 6d 61 6e 64 5b 69 5d 2e  rp, aCommand[i].
1b00: 7a 4e 61 6d 65 2c 20 61 43 6f 6d 6d 61 6e 64 5b  zName, aCommand[
1b10: 69 5d 2e 78 50 72 6f 63 2c 0a 20 20 20 20 20 20  i].xProc,.      
1b20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1b30: 20 61 43 6f 6d 6d 61 6e 64 5b 69 5d 2e 70 43 6f   aCommand[i].pCo
1b40: 6e 74 65 78 74 2c 20 30 29 3b 0a 20 20 20 20 7d  ntext, 0);.    }
1b50: 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 74  .  }.}../*.** St
1b60: 6f 72 65 20 61 20 73 74 72 69 6e 67 20 76 61 6c  ore a string val
1b70: 75 65 20 69 6e 20 61 20 76 61 72 69 61 62 6c 65  ue in a variable
1b80: 20 69 6e 20 74 68 65 20 69 6e 74 65 72 70 72 65   in the interpre
1b90: 74 65 72 2e 0a 2a 2f 0a 76 6f 69 64 20 54 68 5f  ter..*/.void Th_
1ba0: 53 74 6f 72 65 28 63 6f 6e 73 74 20 63 68 61 72  Store(const char
1bb0: 20 2a 7a 4e 61 6d 65 2c 20 63 6f 6e 73 74 20 63   *zName, const c
1bc0: 68 61 72 20 2a 7a 56 61 6c 75 65 29 7b 0a 20 20  har *zValue){.  
1bd0: 54 68 5f 46 6f 73 73 69 6c 49 6e 69 74 28 29 3b  Th_FossilInit();
1be0: 0a 20 20 54 68 5f 53 65 74 56 61 72 28 67 2e 69  .  Th_SetVar(g.i
1bf0: 6e 74 65 72 70 2c 20 28 75 63 68 61 72 2a 29 7a  nterp, (uchar*)z
1c00: 4e 61 6d 65 2c 20 2d 31 2c 20 28 75 63 68 61 72  Name, -1, (uchar
1c10: 2a 29 7a 56 61 6c 75 65 2c 20 73 74 72 6c 65 6e  *)zValue, strlen
1c20: 28 7a 56 61 6c 75 65 29 29 3b 0a 7d 0a 0a 2f 2a  (zValue));.}../*
1c30: 0a 2a 2a 20 52 65 74 72 69 65 76 65 20 61 20 73  .** Retrieve a s
1c40: 74 72 69 6e 67 20 76 61 6c 75 65 20 66 72 6f 6d  tring value from
1c50: 20 74 68 65 20 69 6e 74 65 72 70 72 65 74 65 72   the interpreter
1c60: 2e 20 20 49 66 20 6e 6f 20 73 75 63 68 0a 2a 2a  .  If no such.**
1c70: 20 76 61 72 69 61 62 6c 65 20 65 78 69 73 74 73   variable exists
1c80: 2c 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 0a 2a  , return NULL..*
1c90: 2f 0a 63 68 61 72 20 2a 54 68 5f 46 65 74 63 68  /.char *Th_Fetch
1ca0: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61  (const char *zNa
1cb0: 6d 65 2c 20 69 6e 74 20 2a 70 53 69 7a 65 29 7b  me, int *pSize){
1cc0: 0a 20 20 69 6e 74 20 72 63 3b 0a 20 20 54 68 5f  .  int rc;.  Th_
1cd0: 46 6f 73 73 69 6c 49 6e 69 74 28 29 3b 0a 20 20  FossilInit();.  
1ce0: 72 63 20 3d 20 54 68 5f 47 65 74 56 61 72 28 67  rc = Th_GetVar(g
1cf0: 2e 69 6e 74 65 72 70 2c 20 28 75 63 68 61 72 2a  .interp, (uchar*
1d00: 29 7a 4e 61 6d 65 2c 20 2d 31 29 3b 0a 20 20 69  )zName, -1);.  i
1d10: 66 28 20 72 63 3d 3d 54 48 5f 4f 4b 20 29 7b 0a  f( rc==TH_OK ){.
1d20: 20 20 20 20 72 65 74 75 72 6e 20 28 63 68 61 72      return (char
1d30: 2a 29 54 68 5f 47 65 74 52 65 73 75 6c 74 28 67  *)Th_GetResult(g
1d40: 2e 69 6e 74 65 72 70 2c 20 70 53 69 7a 65 29 3b  .interp, pSize);
1d50: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 72 65  .  }else{.    re
1d60: 74 75 72 6e 20 30 3b 0a 20 20 7d 0a 7d 0a 0a 2f  turn 0;.  }.}../
1d70: 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65  *.** Return true
1d80: 20 69 66 20 74 68 65 20 73 74 72 69 6e 67 20 62   if the string b
1d90: 65 67 69 6e 73 20 77 69 74 68 20 74 68 65 20 54  egins with the T
1da0: 48 31 20 62 65 67 69 6e 2d 73 63 72 69 70 74 0a  H1 begin-script.
1db0: 2a 2a 20 74 61 67 3a 20 20 3c 74 68 31 3e 2e 0a  ** tag:  <th1>..
1dc0: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 69 73  */.static int is
1dd0: 42 65 67 69 6e 53 63 72 69 70 74 54 61 67 28 63  BeginScriptTag(c
1de0: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 29 7b 0a 20  onst char *z){. 
1df0: 20 72 65 74 75 72 6e 20 7a 5b 30 5d 3d 3d 27 3c   return z[0]=='<
1e00: 27 0a 20 20 20 20 20 20 26 26 20 28 7a 5b 31 5d  '.      && (z[1]
1e10: 3d 3d 27 74 27 20 7c 7c 20 7a 5b 31 5d 3d 3d 27  =='t' || z[1]=='
1e20: 54 27 29 0a 20 20 20 20 20 20 26 26 20 28 7a 5b  T').      && (z[
1e30: 32 5d 3d 3d 27 68 27 20 7c 7c 20 7a 5b 32 5d 3d  2]=='h' || z[2]=
1e40: 3d 27 48 27 29 0a 20 20 20 20 20 20 26 26 20 7a  ='H').      && z
1e50: 5b 33 5d 3d 3d 27 31 27 0a 20 20 20 20 20 20 26  [3]=='1'.      &
1e60: 26 20 7a 5b 34 5d 3d 3d 27 3e 27 3b 0a 7d 0a 0a  & z[4]=='>';.}..
1e70: 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 75  /*.** Return tru
1e80: 65 20 69 66 20 74 68 65 20 73 74 72 69 6e 67 20  e if the string 
1e90: 62 65 67 69 6e 73 20 77 69 74 68 20 74 68 65 20  begins with the 
1ea0: 54 48 31 20 65 6e 64 2d 73 63 72 69 70 74 0a 2a  TH1 end-script.*
1eb0: 2a 20 74 61 67 3a 20 20 3c 2f 74 68 31 3e 2e 0a  * tag:  </th1>..
1ec0: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 69 73  */.static int is
1ed0: 45 6e 64 53 63 72 69 70 74 54 61 67 28 63 6f 6e  EndScriptTag(con
1ee0: 73 74 20 63 68 61 72 20 2a 7a 29 7b 0a 20 20 72  st char *z){.  r
1ef0: 65 74 75 72 6e 20 7a 5b 30 5d 3d 3d 27 3c 27 0a  eturn z[0]=='<'.
1f00: 20 20 20 20 20 20 26 26 20 7a 5b 31 5d 3d 3d 27        && z[1]=='
1f10: 2f 27 0a 20 20 20 20 20 20 26 26 20 28 7a 5b 32  /'.      && (z[2
1f20: 5d 3d 3d 27 74 27 20 7c 7c 20 7a 5b 32 5d 3d 3d  ]=='t' || z[2]==
1f30: 27 54 27 29 0a 20 20 20 20 20 20 26 26 20 28 7a  'T').      && (z
1f40: 5b 33 5d 3d 3d 27 68 27 20 7c 7c 20 7a 5b 33 5d  [3]=='h' || z[3]
1f50: 3d 3d 27 48 27 29 0a 20 20 20 20 20 20 26 26 20  =='H').      && 
1f60: 7a 5b 34 5d 3d 3d 27 31 27 0a 20 20 20 20 20 20  z[4]=='1'.      
1f70: 26 26 20 7a 5b 35 5d 3d 3d 27 3e 27 3b 0a 7d 0a  && z[5]=='>';.}.
1f80: 0a 2f 2a 0a 2a 2a 20 49 66 20 73 74 72 69 6e 67  ./*.** If string
1f90: 20 7a 5b 30 2e 2e 2e 5d 20 63 6f 6e 74 61 69 6e   z[0...] contain
1fa0: 73 20 61 20 76 61 6c 69 64 20 76 61 72 69 61 62  s a valid variab
1fb0: 6c 65 20 6e 61 6d 65 2c 20 72 65 74 75 72 6e 0a  le name, return.
1fc0: 2a 2a 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66  ** the number of
1fd0: 20 63 68 61 72 61 63 74 65 72 73 20 69 6e 20 74   characters in t
1fe0: 68 61 74 20 6e 61 6d 65 2e 20 20 4f 74 68 65 72  hat name.  Other
1ff0: 77 69 73 65 2c 20 72 65 74 75 72 6e 20 30 2e 0a  wise, return 0..
2000: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 76 61  */.static int va
2010: 6c 69 64 56 61 72 4e 61 6d 65 28 63 6f 6e 73 74  lidVarName(const
2020: 20 63 68 61 72 20 2a 7a 29 7b 0a 20 20 69 6e 74   char *z){.  int
2030: 20 69 20 3d 20 30 3b 0a 20 20 69 6e 74 20 69 6e   i = 0;.  int in
2040: 42 72 61 63 6b 65 74 20 3d 20 30 3b 0a 20 20 69  Bracket = 0;.  i
2050: 66 28 20 7a 5b 30 5d 3d 3d 27 3c 27 20 29 7b 0a  f( z[0]=='<' ){.
2060: 20 20 20 20 69 6e 42 72 61 63 6b 65 74 20 3d 20      inBracket = 
2070: 31 3b 0a 20 20 20 20 7a 2b 2b 3b 0a 20 20 7d 0a  1;.    z++;.  }.
2080: 20 20 69 66 28 20 7a 5b 30 5d 3d 3d 27 3a 27 20    if( z[0]==':' 
2090: 26 26 20 7a 5b 31 5d 3d 3d 27 3a 27 20 26 26 20  && z[1]==':' && 
20a0: 69 73 61 6c 70 68 61 28 7a 5b 32 5d 29 20 29 7b  isalpha(z[2]) ){
20b0: 0a 20 20 20 20 7a 20 2b 3d 20 33 3b 0a 20 20 20  .    z += 3;.   
20c0: 20 69 20 2b 3d 20 33 3b 0a 20 20 7d 65 6c 73 65   i += 3;.  }else
20d0: 20 69 66 28 20 69 73 61 6c 70 68 61 28 7a 5b 30   if( isalpha(z[0
20e0: 5d 29 20 29 7b 0a 20 20 20 20 7a 20 2b 2b 3b 0a  ]) ){.    z ++;.
20f0: 20 20 20 20 69 20 2b 3d 20 31 3b 0a 20 20 7d 65      i += 1;.  }e
2100: 6c 73 65 7b 0a 20 20 20 20 72 65 74 75 72 6e 20  lse{.    return 
2110: 30 3b 0a 20 20 7d 0a 20 20 77 68 69 6c 65 28 20  0;.  }.  while( 
2120: 69 73 61 6c 6e 75 6d 28 7a 5b 30 5d 29 20 7c 7c  isalnum(z[0]) ||
2130: 20 7a 5b 30 5d 3d 3d 27 5f 27 20 29 7b 0a 20 20   z[0]=='_' ){.  
2140: 20 20 7a 2b 2b 3b 0a 20 20 20 20 69 2b 2b 3b 0a    z++;.    i++;.
2150: 20 20 7d 0a 20 20 69 66 28 20 69 6e 42 72 61 63    }.  if( inBrac
2160: 6b 65 74 20 29 7b 0a 20 20 20 20 69 66 28 20 7a  ket ){.    if( z
2170: 5b 30 5d 21 3d 27 3e 27 20 29 20 72 65 74 75 72  [0]!='>' ) retur
2180: 6e 20 30 3b 0a 20 20 20 20 69 20 2b 3d 20 32 3b  n 0;.    i += 2;
2190: 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 69 3b  .  }.  return i;
21a0: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 7a 5b  .}../*.** The z[
21b0: 5d 20 69 6e 70 75 74 20 63 6f 6e 74 61 69 6e 73  ] input contains
21c0: 20 74 65 78 74 20 6d 69 78 65 64 20 77 69 74 68   text mixed with
21d0: 20 54 48 31 20 73 63 72 69 70 74 73 2e 0a 2a 2a   TH1 scripts..**
21e0: 20 54 68 65 20 54 48 31 20 73 63 72 69 70 74 73   The TH1 scripts
21f0: 20 61 72 65 20 63 6f 6e 74 61 69 6e 65 64 20 77   are contained w
2200: 69 74 68 69 6e 20 3c 74 68 31 3e 2e 2e 2e 3c 2f  ithin <th1>...</
2210: 74 68 31 3e 2e 20 0a 2a 2a 20 54 48 31 20 76 61  th1>. .** TH1 va
2220: 72 69 61 62 6c 65 73 20 61 72 65 20 24 61 61 61  riables are $aaa
2230: 20 6f 72 20 24 3c 61 61 61 3e 2e 20 20 54 68 65   or $<aaa>.  The
2240: 20 66 69 72 73 74 20 66 6f 72 6d 20 6f 66 0a 2a   first form of.*
2250: 2a 20 76 61 72 69 61 62 6c 65 20 69 73 20 6c 69  * variable is li
2260: 74 65 72 61 6c 2e 20 20 54 68 65 20 73 65 63 6f  teral.  The seco
2270: 6e 64 20 69 73 20 72 75 6e 20 74 68 72 6f 75 67  nd is run throug
2280: 68 20 68 74 6d 6c 69 7a 65 0a 2a 2a 20 62 65 66  h htmlize.** bef
2290: 6f 72 65 20 62 65 69 6e 67 20 69 6e 73 65 72 74  ore being insert
22a0: 65 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 72  ed..**.** This r
22b0: 6f 75 74 69 6e 65 20 70 72 6f 63 65 73 73 65 73  outine processes
22c0: 20 74 68 65 20 74 65 6d 70 6c 61 74 65 20 61 6e   the template an
22d0: 64 20 77 72 69 74 65 73 20 74 68 65 20 72 65 73  d writes the res
22e0: 75 6c 74 73 0a 2a 2a 20 6f 6e 20 65 69 74 68 65  ults.** on eithe
22f0: 72 20 73 74 64 6f 75 74 20 6f 72 20 69 6e 74 6f  r stdout or into
2300: 20 43 47 49 2e 0a 2a 2f 0a 69 6e 74 20 54 68 5f   CGI..*/.int Th_
2310: 52 65 6e 64 65 72 28 63 6f 6e 73 74 20 63 68 61  Render(const cha
2320: 72 20 2a 7a 29 7b 0a 20 20 69 6e 74 20 69 20 3d  r *z){.  int i =
2330: 20 30 3b 0a 20 20 69 6e 74 20 6e 3b 0a 20 20 69   0;.  int n;.  i
2340: 6e 74 20 72 63 20 3d 20 54 48 5f 4f 4b 3b 0a 20  nt rc = TH_OK;. 
2350: 20 75 63 68 61 72 20 2a 7a 52 65 73 75 6c 74 3b   uchar *zResult;
2360: 0a 20 20 54 68 5f 46 6f 73 73 69 6c 49 6e 69 74  .  Th_FossilInit
2370: 28 29 3b 0a 20 20 77 68 69 6c 65 28 20 7a 5b 69  ();.  while( z[i
2380: 5d 20 29 7b 0a 20 20 20 20 69 66 28 20 7a 5b 69  ] ){.    if( z[i
2390: 5d 3d 3d 27 24 27 20 26 26 20 28 6e 20 3d 20 76  ]=='$' && (n = v
23a0: 61 6c 69 64 56 61 72 4e 61 6d 65 28 26 7a 5b 69  alidVarName(&z[i
23b0: 2b 31 5d 29 29 3e 30 20 29 7b 0a 20 20 20 20 20  +1]))>0 ){.     
23c0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 61   const char *zVa
23d0: 72 3b 0a 20 20 20 20 20 20 69 6e 74 20 6e 56 61  r;.      int nVa
23e0: 72 3b 0a 20 20 20 20 20 20 73 65 6e 64 54 65 78  r;.      sendTex
23f0: 74 28 7a 2c 20 69 2c 20 30 29 3b 0a 20 20 20 20  t(z, i, 0);.    
2400: 20 20 69 66 28 20 7a 5b 69 2b 31 5d 3d 3d 27 3c    if( z[i+1]=='<
2410: 27 20 29 7b 0a 20 20 20 20 20 20 20 20 2f 2a 20  ' ){.        /* 
2420: 56 61 72 69 61 62 6c 65 73 20 6f 66 20 74 68 65  Variables of the
2430: 20 66 6f 72 6d 20 24 3c 61 61 61 3e 20 2a 2f 0a   form $<aaa> */.
2440: 20 20 20 20 20 20 20 20 7a 56 61 72 20 3d 20 26          zVar = &
2450: 7a 5b 69 2b 32 5d 3b 0a 20 20 20 20 20 20 20 20  z[i+2];.        
2460: 6e 56 61 72 20 3d 20 6e 2d 32 3b 0a 20 20 20 20  nVar = n-2;.    
2470: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20    }else{.       
2480: 20 2f 2a 20 56 61 72 69 61 62 6c 65 73 20 6f 66   /* Variables of
2490: 20 74 68 65 20 66 6f 72 6d 20 24 61 61 61 20 2a   the form $aaa *
24a0: 2f 0a 20 20 20 20 20 20 20 20 7a 56 61 72 20 3d  /.        zVar =
24b0: 20 26 7a 5b 69 2b 31 5d 3b 0a 20 20 20 20 20 20   &z[i+1];.      
24c0: 20 20 6e 56 61 72 20 3d 20 6e 3b 0a 20 20 20 20    nVar = n;.    
24d0: 20 20 7d 0a 20 20 20 20 20 20 72 63 20 3d 20 54    }.      rc = T
24e0: 68 5f 47 65 74 56 61 72 28 67 2e 69 6e 74 65 72  h_GetVar(g.inter
24f0: 70 2c 20 28 75 63 68 61 72 2a 29 7a 56 61 72 2c  p, (uchar*)zVar,
2500: 20 6e 56 61 72 29 3b 0a 20 20 20 20 20 20 7a 20   nVar);.      z 
2510: 2b 3d 20 69 2b 31 2b 6e 3b 0a 20 20 20 20 20 20  += i+1+n;.      
2520: 69 20 3d 20 30 3b 0a 20 20 20 20 20 20 7a 52 65  i = 0;.      zRe
2530: 73 75 6c 74 20 3d 20 28 75 63 68 61 72 2a 29 54  sult = (uchar*)T
2540: 68 5f 47 65 74 52 65 73 75 6c 74 28 67 2e 69 6e  h_GetResult(g.in
2550: 74 65 72 70 2c 20 26 6e 29 3b 0a 20 20 20 20 20  terp, &n);.     
2560: 20 73 65 6e 64 54 65 78 74 28 28 63 68 61 72 2a   sendText((char*
2570: 29 7a 52 65 73 75 6c 74 2c 20 6e 2c 20 6e 3e 6e  )zResult, n, n>n
2580: 56 61 72 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20  Var);.    }else 
2590: 69 66 28 20 7a 5b 69 5d 3d 3d 27 3c 27 20 26 26  if( z[i]=='<' &&
25a0: 20 69 73 42 65 67 69 6e 53 63 72 69 70 74 54 61   isBeginScriptTa
25b0: 67 28 26 7a 5b 69 5d 29 20 29 7b 0a 20 20 20 20  g(&z[i]) ){.    
25c0: 20 20 73 65 6e 64 54 65 78 74 28 7a 2c 20 69 2c    sendText(z, i,
25d0: 20 30 29 3b 0a 20 20 20 20 20 20 7a 20 2b 3d 20   0);.      z += 
25e0: 69 2b 35 3b 0a 20 20 20 20 20 20 66 6f 72 28 69  i+5;.      for(i
25f0: 3d 30 3b 20 7a 5b 69 5d 20 26 26 20 28 7a 5b 69  =0; z[i] && (z[i
2600: 5d 21 3d 27 3c 27 20 7c 7c 20 21 69 73 45 6e 64  ]!='<' || !isEnd
2610: 53 63 72 69 70 74 54 61 67 28 26 7a 5b 69 5d 29  ScriptTag(&z[i])
2620: 29 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 20  ); i++){}.      
2630: 72 63 20 3d 20 54 68 5f 45 76 61 6c 28 67 2e 69  rc = Th_Eval(g.i
2640: 6e 74 65 72 70 2c 20 30 2c 20 28 63 6f 6e 73 74  nterp, 0, (const
2650: 20 75 63 68 61 72 2a 29 7a 2c 20 69 29 3b 0a 20   uchar*)z, i);. 
2660: 20 20 20 20 20 69 66 28 20 72 63 21 3d 54 48 5f       if( rc!=TH_
2670: 4f 4b 20 29 20 62 72 65 61 6b 3b 0a 20 20 20 20  OK ) break;.    
2680: 20 20 7a 20 2b 3d 20 69 3b 0a 20 20 20 20 20 20    z += i;.      
2690: 69 66 28 20 7a 5b 30 5d 20 29 7b 20 7a 20 2b 3d  if( z[0] ){ z +=
26a0: 20 36 3b 20 7d 0a 20 20 20 20 20 20 69 20 3d 20   6; }.      i = 
26b0: 30 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20  0;.    }else{.  
26c0: 20 20 20 20 69 2b 2b 3b 0a 20 20 20 20 7d 0a 20      i++;.    }. 
26d0: 20 7d 0a 20 20 69 66 28 20 72 63 3d 3d 54 48 5f   }.  if( rc==TH_
26e0: 45 52 52 4f 52 20 29 7b 0a 20 20 20 20 73 65 6e  ERROR ){.    sen
26f0: 64 54 65 78 74 28 22 3c 68 72 3e 3c 70 3e 3c 66  dText("<hr><p><f
2700: 6f 6e 74 20 63 6f 6c 6f 72 3d 5c 22 72 65 64 5c  ont color=\"red\
2710: 22 3e 3c 62 3e 45 52 52 4f 52 3a 20 22 2c 20 2d  "><b>ERROR: ", -
2720: 31 2c 20 30 29 3b 0a 20 20 20 20 7a 52 65 73 75  1, 0);.    zResu
2730: 6c 74 20 3d 20 28 75 63 68 61 72 2a 29 54 68 5f  lt = (uchar*)Th_
2740: 47 65 74 52 65 73 75 6c 74 28 67 2e 69 6e 74 65  GetResult(g.inte
2750: 72 70 2c 20 26 6e 29 3b 0a 20 20 20 20 73 65 6e  rp, &n);.    sen
2760: 64 54 65 78 74 28 28 63 68 61 72 2a 29 7a 52 65  dText((char*)zRe
2770: 73 75 6c 74 2c 20 6e 2c 20 31 29 3b 0a 20 20 20  sult, n, 1);.   
2780: 20 73 65 6e 64 54 65 78 74 28 22 3c 2f 62 3e 3c   sendText("</b><
2790: 2f 66 6f 6e 74 3e 3c 2f 70 3e 22 2c 20 2d 31 2c  /font></p>", -1,
27a0: 20 30 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20   0);.  }else{.  
27b0: 20 20 73 65 6e 64 54 65 78 74 28 7a 2c 20 69 2c    sendText(z, i,
27c0: 20 30 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72   0);.  }.  retur
27d0: 6e 20 72 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43  n rc;.}../*.** C
27e0: 4f 4d 4d 41 4e 44 3a 20 74 65 73 74 2d 74 68 2d  OMMAND: test-th-
27f0: 72 65 6e 64 65 72 0a 2a 2f 0a 76 6f 69 64 20 74  render.*/.void t
2800: 65 73 74 5f 74 68 5f 72 65 6e 64 65 72 28 76 6f  est_th_render(vo
2810: 69 64 29 7b 0a 20 20 42 6c 6f 62 20 69 6e 3b 0a  id){.  Blob in;.
2820: 20 20 69 66 28 20 67 2e 61 72 67 63 3c 33 20 29    if( g.argc<3 )
2830: 7b 0a 20 20 20 20 75 73 61 67 65 28 22 46 49 4c  {.    usage("FIL
2840: 45 22 29 3b 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f  E");.  }.  blob_
2850: 7a 65 72 6f 28 26 69 6e 29 3b 0a 20 20 62 6c 6f  zero(&in);.  blo
2860: 62 5f 72 65 61 64 5f 66 72 6f 6d 5f 66 69 6c 65  b_read_from_file
2870: 28 26 69 6e 2c 20 67 2e 61 72 67 76 5b 32 5d 29  (&in, g.argv[2])
2880: 3b 0a 20 20 54 68 5f 52 65 6e 64 65 72 28 62 6c  ;.  Th_Render(bl
2890: 6f 62 5f 73 74 72 28 26 69 6e 29 29 3b 0a 7d 0a  ob_str(&in));.}.