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 41 20 70 6f 69 6e 74 65 72 20 74 6f 20 ** A pointer to
0510: 74 68 65 20 73 69 6e 67 6c 65 20 54 48 20 69 6e the single TH in
0520: 74 65 72 70 72 65 74 65 72 20 75 73 65 64 20 77 terpreter used w
0530: 69 74 68 69 6e 20 66 6f 73 73 69 6c 2e 0a 2a 2f ithin fossil..*/
0540: 0a 73 74 61 74 69 63 20 54 68 5f 49 6e 74 65 72 .static Th_Inter
0550: 70 20 2a 69 6e 74 65 72 70 20 3d 20 30 3b 0a 0a p *interp = 0;..
0560: 0a 2f 2a 0a 2a 2a 20 49 6d 70 6c 65 6d 65 6e 74 ./*.** Implement
0570: 61 74 69 6f 6e 73 20 6f 66 20 6d 61 6c 6c 6f 63 ations of malloc
0580: 28 29 20 61 6e 64 20 66 72 65 65 28 29 20 74 6f () and free() to
0590: 20 70 61 73 73 20 74 6f 20 74 68 65 20 69 6e 74 pass to the int
05a0: 65 72 70 72 65 74 65 72 2e 0a 2a 2f 0a 73 74 61 erpreter..*/.sta
05b0: 74 69 63 20 76 6f 69 64 20 2a 78 4d 61 6c 6c 6f tic void *xMallo
05c0: 63 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 6e c(unsigned int n
05d0: 29 7b 0a 20 20 76 6f 69 64 20 2a 70 20 3d 20 6d ){. void *p = m
05e0: 61 6c 6c 6f 63 28 6e 29 3b 0a 20 20 69 66 28 20 alloc(n);. if(
05f0: 70 20 29 7b 0a 20 20 20 20 6e 4f 75 74 73 74 61 p ){. nOutsta
0600: 6e 64 69 6e 67 4d 61 6c 6c 6f 63 2b 2b 3b 0a 20 ndingMalloc++;.
0610: 20 7d 0a 20 20 72 65 74 75 72 6e 20 70 3b 0a 7d }. return p;.}
0620: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 78 46 72 .static void xFr
0630: 65 65 28 76 6f 69 64 20 2a 70 29 7b 0a 20 20 69 ee(void *p){. i
0640: 66 28 20 70 20 29 7b 0a 20 20 20 20 6e 4f 75 74 f( p ){. nOut
0650: 73 74 61 6e 64 69 6e 67 4d 61 6c 6c 6f 63 2d 2d standingMalloc--
0660: 3b 0a 20 20 7d 0a 20 20 66 72 65 65 28 70 29 3b ;. }. free(p);
0670: 0a 7d 0a 73 74 61 74 69 63 20 54 68 5f 56 74 61 .}.static Th_Vta
0680: 62 20 76 74 61 62 20 3d 20 7b 20 78 4d 61 6c 6c b vtab = { xMall
0690: 6f 63 2c 20 78 46 72 65 65 20 7d 3b 0a 0a 0a 2f oc, xFree };.../
06a0: 2a 0a 2a 2a 20 54 72 75 65 20 69 66 20 6f 75 74 *.** True if out
06b0: 70 75 74 20 69 73 20 65 6e 61 62 6c 65 64 2e 20 put is enabled.
06c0: 20 46 61 6c 73 65 20 69 66 20 64 69 73 61 62 6c False if disabl
06d0: 65 64 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e ed..*/.static in
06e0: 74 20 65 6e 61 62 6c 65 4f 75 74 70 75 74 20 3d t enableOutput =
06f0: 20 31 3b 0a 0a 2f 2a 0a 2a 2a 20 54 48 20 63 6f 1;../*.** TH co
0700: 6d 6d 61 6e 64 3a 20 20 20 20 20 65 6e 61 62 6c mmand: enabl
0710: 65 5f 6f 75 74 70 75 74 20 42 4f 4f 4c 45 41 4e e_output BOOLEAN
0720: 0a 2a 2a 0a 2a 2a 20 45 6e 61 62 6c 65 20 6f 72 .**.** Enable or
0730: 20 64 69 73 61 62 6c 65 20 74 68 65 20 70 75 74 disable the put
0740: 73 20 61 6e 64 20 68 70 75 74 73 20 63 6f 6d 6d s and hputs comm
0750: 61 6e 64 73 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 ands..*/.static
0760: 69 6e 74 20 65 6e 61 62 6c 65 4f 75 74 70 75 74 int enableOutput
0770: 43 6d 64 28 0a 20 20 54 68 5f 49 6e 74 65 72 70 Cmd(. Th_Interp
0780: 20 2a 69 6e 74 65 72 70 2c 20 0a 20 20 76 6f 69 *interp, . voi
0790: 64 20 2a 70 2c 20 0a 20 20 69 6e 74 20 61 72 67 d *p, . int arg
07a0: 63 2c 20 0a 20 20 63 6f 6e 73 74 20 75 6e 73 69 c, . const unsi
07b0: 67 6e 65 64 20 63 68 61 72 20 2a 2a 61 72 67 76 gned char **argv
07c0: 2c 20 0a 20 20 69 6e 74 20 2a 61 72 67 6c 0a 29 , . int *argl.)
07d0: 7b 0a 20 20 69 66 28 20 61 72 67 63 21 3d 32 20 {. if( argc!=2
07e0: 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 20 54 68 ){. return Th
07f0: 5f 57 72 6f 6e 67 4e 75 6d 41 72 67 73 28 69 6e _WrongNumArgs(in
0800: 74 65 72 70 2c 20 22 65 6e 61 62 6c 65 5f 6f 75 terp, "enable_ou
0810: 74 70 75 74 20 42 4f 4f 4c 45 41 4e 22 29 3b 0a tput BOOLEAN");.
0820: 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 54 68 5f }. return Th_
0830: 54 6f 49 6e 74 28 69 6e 74 65 72 70 2c 20 61 72 ToInt(interp, ar
0840: 67 76 5b 31 5d 2c 20 61 72 67 6c 5b 31 5d 2c 20 gv[1], argl[1],
0850: 26 65 6e 61 62 6c 65 4f 75 74 70 75 74 29 3b 0a &enableOutput);.
0860: 7d 0a 0a 2f 2a 0a 2a 2a 20 53 65 6e 64 20 74 65 }../*.** Send te
0870: 78 74 20 74 6f 20 74 68 65 20 61 70 70 72 6f 70 xt to the approp
0880: 72 69 61 74 65 20 6f 75 74 70 75 74 3a 20 20 45 riate output: E
0890: 69 74 68 65 72 20 74 6f 20 74 68 65 20 63 6f 6e ither to the con
08a0: 73 6f 6c 65 0a 2a 2a 20 6f 72 20 74 6f 20 74 68 sole.** or to th
08b0: 65 20 43 47 49 20 72 65 70 6c 79 20 62 75 66 66 e CGI reply buff
08c0: 65 72 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f er..*/.static vo
08d0: 69 64 20 73 65 6e 64 54 65 78 74 28 63 6f 6e 73 id sendText(cons
08e0: 74 20 63 68 61 72 20 2a 7a 2c 20 69 6e 74 20 6e t char *z, int n
08f0: 29 7b 0a 20 20 69 66 28 20 65 6e 61 62 6c 65 4f ){. if( enableO
0900: 75 74 70 75 74 20 26 26 20 6e 20 29 7b 0a 20 20 utput && n ){.
0910: 20 20 69 66 28 20 6e 3c 30 20 29 20 6e 20 3d 20 if( n<0 ) n =
0920: 73 74 72 6c 65 6e 28 7a 29 3b 0a 20 20 20 20 69 strlen(z);. i
0930: 66 28 20 67 2e 63 67 69 50 61 6e 69 63 20 29 7b f( g.cgiPanic ){
0940: 0a 20 20 20 20 20 20 63 67 69 5f 61 70 70 65 6e . cgi_appen
0950: 64 5f 63 6f 6e 74 65 6e 74 28 7a 2c 20 6e 29 3b d_content(z, n);
0960: 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 . }else{.
0970: 20 20 66 77 72 69 74 65 28 7a 2c 20 31 2c 20 6e fwrite(z, 1, n
0980: 2c 20 73 74 64 6f 75 74 29 3b 0a 20 20 20 20 7d , stdout);. }
0990: 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 48 . }.}../*.** TH
09a0: 20 63 6f 6d 6d 61 6e 64 3a 20 20 20 20 20 70 75 command: pu
09b0: 74 73 20 53 54 52 49 4e 47 0a 2a 2a 20 54 48 20 ts STRING.** TH
09c0: 63 6f 6d 6d 61 6e 64 3a 20 20 20 20 20 68 74 6d command: htm
09d0: 6c 20 53 54 52 49 4e 47 0a 2a 2a 0a 2a 2a 20 4f l STRING.**.** O
09e0: 75 74 70 75 74 20 53 54 52 49 4e 47 20 61 73 20 utput STRING as
09f0: 48 54 4d 4c 20 28 68 74 6d 6c 29 20 6f 72 20 75 HTML (html) or u
0a00: 6e 63 68 61 6e 67 65 64 20 28 70 75 74 73 29 2e nchanged (puts).
0a10: 20 20 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 .*/.static int
0a20: 20 70 75 74 73 43 6d 64 28 0a 20 20 54 68 5f 49 putsCmd(. Th_I
0a30: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 0a nterp *interp, .
0a40: 20 20 76 6f 69 64 20 2a 70 43 6f 6e 76 65 72 74 void *pConvert
0a50: 2c 20 0a 20 20 69 6e 74 20 61 72 67 63 2c 20 0a , . int argc, .
0a60: 20 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 const unsigned
0a70: 20 63 68 61 72 20 2a 2a 61 72 67 76 2c 20 0a 20 char **argv, .
0a80: 20 69 6e 74 20 2a 61 72 67 6c 0a 29 7b 0a 20 20 int *argl.){.
0a90: 69 66 28 20 61 72 67 63 21 3d 32 20 29 7b 0a 20 if( argc!=2 ){.
0aa0: 20 20 20 72 65 74 75 72 6e 20 54 68 5f 57 72 6f return Th_Wro
0ab0: 6e 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70 ngNumArgs(interp
0ac0: 2c 20 22 70 75 74 73 20 53 54 52 49 4e 47 22 29 , "puts STRING")
0ad0: 3b 0a 20 20 7d 0a 20 20 69 66 28 20 65 6e 61 62 ;. }. if( enab
0ae0: 6c 65 4f 75 74 70 75 74 20 29 7b 0a 20 20 20 20 leOutput ){.
0af0: 69 6e 74 20 73 69 7a 65 3b 0a 20 20 20 20 63 68 int size;. ch
0b00: 61 72 20 2a 7a 4f 75 74 3b 0a 20 20 20 20 69 66 ar *zOut;. if
0b10: 28 20 70 43 6f 6e 76 65 72 74 20 29 7b 20 20 20 ( pConvert ){
0b20: 20 0a 20 20 20 20 20 20 7a 4f 75 74 20 3d 20 68 . zOut = h
0b30: 74 6d 6c 69 7a 65 28 28 63 68 61 72 2a 29 61 72 tmlize((char*)ar
0b40: 67 76 5b 31 5d 2c 20 61 72 67 6c 5b 31 5d 29 3b gv[1], argl[1]);
0b50: 0a 20 20 20 20 20 20 73 69 7a 65 20 3d 20 73 74 . size = st
0b60: 72 6c 65 6e 28 7a 4f 75 74 29 3b 0a 20 20 20 20 rlen(zOut);.
0b70: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 7a 4f 75 }else{. zOu
0b80: 74 20 3d 20 28 63 68 61 72 2a 29 61 72 67 76 5b t = (char*)argv[
0b90: 31 5d 3b 0a 20 20 20 20 20 20 73 69 7a 65 20 3d 1];. size =
0ba0: 20 61 72 67 6c 5b 31 5d 3b 0a 20 20 20 20 7d 0a argl[1];. }.
0bb0: 20 20 20 20 73 65 6e 64 54 65 78 74 28 7a 4f 75 sendText(zOu
0bc0: 74 2c 20 73 69 7a 65 29 3b 0a 20 20 20 20 69 66 t, size);. if
0bd0: 28 20 70 43 6f 6e 76 65 72 74 20 29 7b 0a 20 20 ( pConvert ){.
0be0: 20 20 20 20 66 72 65 65 28 7a 4f 75 74 29 3b 0a free(zOut);.
0bf0: 20 20 20 20 7d 0a 20 20 7d 0a 20 20 72 65 74 75 }. }. retu
0c00: 72 6e 20 54 48 5f 4f 4b 3b 0a 7d 0a 0a 2f 2a 0a rn TH_OK;.}../*.
0c10: 2a 2a 20 54 48 20 63 6f 6d 6d 61 6e 64 3a 20 20 ** TH command:
0c20: 20 20 20 20 77 69 6b 69 20 53 54 52 49 4e 47 0a wiki STRING.
0c30: 2a 2a 0a 2a 2a 20 52 65 6e 64 65 72 20 74 68 65 **.** Render the
0c40: 20 69 6e 70 75 74 20 73 74 72 69 6e 67 20 61 73 input string as
0c50: 20 77 69 6b 69 2e 0a 2a 2f 0a 73 74 61 74 69 63 wiki..*/.static
0c60: 20 69 6e 74 20 77 69 6b 69 43 6d 64 28 0a 20 20 int wikiCmd(.
0c70: 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 Th_Interp *inter
0c80: 70 2c 20 0a 20 20 76 6f 69 64 20 2a 70 2c 20 0a p, . void *p, .
0c90: 20 20 69 6e 74 20 61 72 67 63 2c 20 0a 20 20 63 int argc, . c
0ca0: 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68 onst unsigned ch
0cb0: 61 72 20 2a 2a 61 72 67 76 2c 20 0a 20 20 69 6e ar **argv, . in
0cc0: 74 20 2a 61 72 67 6c 0a 29 7b 0a 20 20 69 66 28 t *argl.){. if(
0cd0: 20 61 72 67 63 21 3d 32 20 29 7b 0a 20 20 20 20 argc!=2 ){.
0ce0: 72 65 74 75 72 6e 20 54 68 5f 57 72 6f 6e 67 4e return Th_WrongN
0cf0: 75 6d 41 72 67 73 28 69 6e 74 65 72 70 2c 20 22 umArgs(interp, "
0d00: 70 75 74 73 20 53 54 52 49 4e 47 22 29 3b 0a 20 puts STRING");.
0d10: 20 7d 0a 20 20 69 66 28 20 65 6e 61 62 6c 65 4f }. if( enableO
0d20: 75 74 70 75 74 20 29 7b 0a 20 20 20 20 42 6c 6f utput ){. Blo
0d30: 62 20 73 72 63 3b 0a 20 20 20 20 62 6c 6f 62 5f b src;. blob_
0d40: 69 6e 69 74 28 26 73 72 63 2c 20 28 63 68 61 72 init(&src, (char
0d50: 2a 29 61 72 67 76 5b 31 5d 2c 20 61 72 67 6c 5b *)argv[1], argl[
0d60: 31 5d 29 3b 0a 20 20 20 20 77 69 6b 69 5f 63 6f 1]);. wiki_co
0d70: 6e 76 65 72 74 28 26 73 72 63 2c 20 30 2c 20 57 nvert(&src, 0, W
0d80: 49 4b 49 5f 49 4e 4c 49 4e 45 29 3b 0a 20 20 20 IKI_INLINE);.
0d90: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 73 72 63 blob_reset(&src
0da0: 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 );. }. return
0db0: 54 48 5f 4f 4b 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 TH_OK;.}../*.**
0dc0: 4d 61 6b 65 20 73 75 72 65 20 74 68 65 20 69 6e Make sure the in
0dd0: 74 65 72 70 72 65 74 65 72 20 68 61 73 20 62 65 terpreter has be
0de0: 65 6e 20 69 6e 69 74 69 61 6c 69 7a 65 64 2e 0a en initialized..
0df0: 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 69 */.static void i
0e00: 6e 69 74 69 61 6c 69 7a 65 49 6e 74 65 72 70 28 nitializeInterp(
0e10: 76 6f 69 64 29 7b 0a 20 20 73 74 61 74 69 63 20 void){. static
0e20: 73 74 72 75 63 74 20 5f 43 6f 6d 6d 61 6e 64 20 struct _Command
0e30: 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 {. const char
0e40: 20 2a 7a 4e 61 6d 65 3b 0a 20 20 20 20 54 68 5f *zName;. Th_
0e50: 43 6f 6d 6d 61 6e 64 50 72 6f 63 20 78 50 72 6f CommandProc xPro
0e60: 63 3b 0a 20 20 20 20 76 6f 69 64 20 2a 70 43 6f c;. void *pCo
0e70: 6e 74 65 78 74 3b 0a 20 20 7d 20 61 43 6f 6d 6d ntext;. } aComm
0e80: 61 6e 64 5b 5d 20 3d 20 7b 0a 20 20 20 20 7b 22 and[] = {. {"
0e90: 65 6e 61 62 6c 65 5f 6f 75 74 70 75 74 22 2c 20 enable_output",
0ea0: 65 6e 61 62 6c 65 4f 75 74 70 75 74 43 6d 64 2c enableOutputCmd,
0eb0: 20 20 20 20 20 20 30 7d 2c 0a 20 20 20 20 7b 22 0},. {"
0ec0: 68 74 6d 6c 22 2c 20 20 20 20 20 20 20 20 20 20 html",
0ed0: 70 75 74 73 43 6d 64 2c 20 20 20 20 20 20 20 20 putsCmd,
0ee0: 20 20 20 20 20 20 30 7d 2c 0a 20 20 20 20 7b 22 0},. {"
0ef0: 70 75 74 73 22 2c 20 20 20 20 20 20 20 20 20 20 puts",
0f00: 70 75 74 73 43 6d 64 2c 20 20 20 20 20 20 20 28 putsCmd, (
0f10: 76 6f 69 64 2a 29 31 7d 2c 0a 20 20 20 20 7b 22 void*)1},. {"
0f20: 77 69 6b 69 22 2c 20 20 20 20 20 20 20 20 20 20 wiki",
0f30: 77 69 6b 69 43 6d 64 2c 20 20 20 20 20 20 20 20 wikiCmd,
0f40: 20 20 20 20 20 20 30 7d 2c 0a 20 20 7d 3b 0a 20 0},. };.
0f50: 20 69 66 28 20 69 6e 74 65 72 70 3d 3d 30 20 29 if( interp==0 )
0f60: 7b 0a 20 20 20 20 69 6e 74 20 69 3b 0a 20 20 20 {. int i;.
0f70: 20 69 6e 74 65 72 70 20 3d 20 54 68 5f 43 72 65 interp = Th_Cre
0f80: 61 74 65 49 6e 74 65 72 70 28 26 76 74 61 62 29 ateInterp(&vtab)
0f90: 3b 0a 20 20 20 20 74 68 5f 72 65 67 69 73 74 65 ;. th_registe
0fa0: 72 5f 6c 61 6e 67 75 61 67 65 28 69 6e 74 65 72 r_language(inter
0fb0: 70 29 3b 20 20 20 20 20 20 20 2f 2a 20 42 61 73 p); /* Bas
0fc0: 69 63 20 73 63 72 69 70 74 69 6e 67 20 63 6f 6d ic scripting com
0fd0: 6d 61 6e 64 73 2e 20 2a 2f 0a 20 20 20 20 66 6f mands. */. fo
0fe0: 72 28 69 3d 30 3b 20 69 3c 73 69 7a 65 6f 66 28 r(i=0; i<sizeof(
0ff0: 61 43 6f 6d 6d 61 6e 64 29 2f 73 69 7a 65 6f 66 aCommand)/sizeof
1000: 28 61 43 6f 6d 6d 61 6e 64 5b 30 5d 29 3b 20 69 (aCommand[0]); i
1010: 2b 2b 29 7b 0a 20 20 20 20 20 20 54 68 5f 43 72 ++){. Th_Cr
1020: 65 61 74 65 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 eateCommand(inte
1030: 72 70 2c 20 61 43 6f 6d 6d 61 6e 64 5b 69 5d 2e rp, aCommand[i].
1040: 7a 4e 61 6d 65 2c 20 61 43 6f 6d 6d 61 6e 64 5b zName, aCommand[
1050: 69 5d 2e 78 50 72 6f 63 2c 0a 20 20 20 20 20 20 i].xProc,.
1060: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1070: 20 61 43 6f 6d 6d 61 6e 64 5b 69 5d 2e 70 43 6f aCommand[i].pCo
1080: 6e 74 65 78 74 2c 20 30 29 3b 0a 20 20 20 20 7d ntext, 0);. }
1090: 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 49 6e . }.}../*.** In
10a0: 69 74 69 61 6c 69 7a 65 20 61 20 76 61 72 69 61 itialize a varia
10b0: 62 6c 65 20 69 6e 20 74 68 65 20 69 6e 74 65 72 ble in the inter
10c0: 70 72 65 74 65 72 2e 0a 2a 2f 0a 76 6f 69 64 20 preter..*/.void
10d0: 54 68 5f 49 6e 69 74 56 61 72 28 63 6f 6e 73 74 Th_InitVar(const
10e0: 20 63 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 63 6f char *zName, co
10f0: 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 nst char *zValue
1100: 29 7b 0a 20 20 69 6e 69 74 69 61 6c 69 7a 65 49 ){. initializeI
1110: 6e 74 65 72 70 28 29 3b 0a 20 20 54 68 5f 53 65 nterp();. Th_Se
1120: 74 56 61 72 28 69 6e 74 65 72 70 2c 20 7a 4e 61 tVar(interp, zNa
1130: 6d 65 2c 20 2d 31 2c 20 7a 56 61 6c 75 65 2c 20 me, -1, zValue,
1140: 73 74 72 6c 65 6e 28 7a 56 61 6c 75 65 29 29 3b strlen(zValue));
1150: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e .}../*.** Return
1160: 20 74 72 75 65 20 69 66 20 74 68 65 20 73 74 72 true if the str
1170: 69 6e 67 20 62 65 67 69 6e 73 20 77 69 74 68 20 ing begins with
1180: 74 68 65 20 54 48 31 20 62 65 67 69 6e 2d 73 63 the TH1 begin-sc
1190: 72 69 70 74 0a 2a 2a 20 74 61 67 3a 20 20 3c 74 ript.** tag: <t
11a0: 68 31 3e 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 h1>..*/.static i
11b0: 6e 74 20 69 73 42 65 67 69 6e 53 63 72 69 70 74 nt isBeginScript
11c0: 54 61 67 28 63 6f 6e 73 74 20 63 68 61 72 20 2a Tag(const char *
11d0: 7a 29 7b 0a 20 20 72 65 74 75 72 6e 20 7a 5b 30 z){. return z[0
11e0: 5d 3d 3d 27 3c 27 0a 20 20 20 20 20 20 26 26 20 ]=='<'. &&
11f0: 28 7a 5b 31 5d 3d 3d 27 74 27 20 7c 7c 20 7a 5b (z[1]=='t' || z[
1200: 31 5d 3d 3d 27 54 27 29 0a 20 20 20 20 20 20 26 1]=='T'). &
1210: 26 20 28 7a 5b 32 5d 3d 3d 27 68 27 20 7c 7c 20 & (z[2]=='h' ||
1220: 7a 5b 32 5d 3d 3d 27 48 27 29 0a 20 20 20 20 20 z[2]=='H').
1230: 20 26 26 20 7a 5b 33 5d 3d 3d 27 31 27 0a 20 20 && z[3]=='1'.
1240: 20 20 20 20 26 26 20 7a 5b 34 5d 3d 3d 27 3e 27 && z[4]=='>'
1250: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 ;.}../*.** Retur
1260: 6e 20 74 72 75 65 20 69 66 20 74 68 65 20 73 74 n true if the st
1270: 72 69 6e 67 20 62 65 67 69 6e 73 20 77 69 74 68 ring begins with
1280: 20 74 68 65 20 54 48 31 20 65 6e 64 2d 73 63 72 the TH1 end-scr
1290: 69 70 74 0a 2a 2a 20 74 61 67 3a 20 20 3c 2f 74 ipt.** tag: </t
12a0: 68 31 3e 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 h1>..*/.static i
12b0: 6e 74 20 69 73 45 6e 64 53 63 72 69 70 74 54 61 nt isEndScriptTa
12c0: 67 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 29 g(const char *z)
12d0: 7b 0a 20 20 72 65 74 75 72 6e 20 7a 5b 30 5d 3d {. return z[0]=
12e0: 3d 27 3c 27 0a 20 20 20 20 20 20 26 26 20 7a 5b ='<'. && z[
12f0: 31 5d 3d 3d 27 2f 27 0a 20 20 20 20 20 20 26 26 1]=='/'. &&
1300: 20 28 7a 5b 32 5d 3d 3d 27 74 27 20 7c 7c 20 7a (z[2]=='t' || z
1310: 5b 32 5d 3d 3d 27 54 27 29 0a 20 20 20 20 20 20 [2]=='T').
1320: 26 26 20 28 7a 5b 33 5d 3d 3d 27 68 27 20 7c 7c && (z[3]=='h' ||
1330: 20 7a 5b 33 5d 3d 3d 27 48 27 29 0a 20 20 20 20 z[3]=='H').
1340: 20 20 26 26 20 7a 5b 34 5d 3d 3d 27 31 27 0a 20 && z[4]=='1'.
1350: 20 20 20 20 20 26 26 20 7a 5b 35 5d 3d 3d 27 3e && z[5]=='>
1360: 27 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 73 ';.}../*.** If s
1370: 74 72 69 6e 67 20 7a 5b 30 2e 2e 2e 5d 20 63 6f tring z[0...] co
1380: 6e 74 61 69 6e 73 20 61 20 76 61 6c 69 64 20 76 ntains a valid v
1390: 61 72 69 61 62 6c 65 20 6e 61 6d 65 2c 20 72 65 ariable name, re
13a0: 74 75 72 6e 0a 2a 2a 20 74 68 65 20 6e 75 6d 62 turn.** the numb
13b0: 65 72 20 6f 66 20 63 68 61 72 61 63 74 65 72 73 er of characters
13c0: 20 69 6e 20 74 68 61 74 20 6e 61 6d 65 2e 20 20 in that name.
13d0: 4f 74 68 65 72 77 69 73 65 2c 20 72 65 74 75 72 Otherwise, retur
13e0: 6e 20 30 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 n 0..*/.static i
13f0: 6e 74 20 76 61 6c 69 64 56 61 72 4e 61 6d 65 28 nt validVarName(
1400: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 29 7b 0a const char *z){.
1410: 20 20 69 6e 74 20 69 20 3d 20 30 3b 0a 20 20 69 int i = 0;. i
1420: 66 28 20 7a 5b 30 5d 3d 3d 27 3a 27 20 26 26 20 f( z[0]==':' &&
1430: 7a 5b 31 5d 3d 3d 27 3a 27 20 26 26 20 69 73 61 z[1]==':' && isa
1440: 6c 70 68 61 28 7a 5b 32 5d 29 20 29 7b 0a 20 20 lpha(z[2]) ){.
1450: 20 20 7a 20 2b 3d 20 33 3b 0a 20 20 20 20 69 20 z += 3;. i
1460: 3d 20 33 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 = 3;. }else if(
1470: 20 69 73 61 6c 70 68 61 28 7a 5b 30 5d 29 20 29 isalpha(z[0]) )
1480: 7b 0a 20 20 20 20 7a 20 2b 2b 3b 0a 20 20 20 20 {. z ++;.
1490: 69 20 3d 20 31 3b 0a 20 20 7d 65 6c 73 65 7b 0a i = 1;. }else{.
14a0: 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a 20 20 return 0;.
14b0: 7d 0a 20 20 77 68 69 6c 65 28 20 69 73 61 6c 6e }. while( isaln
14c0: 75 6d 28 7a 5b 30 5d 29 20 7c 7c 20 7a 5b 30 5d um(z[0]) || z[0]
14d0: 3d 3d 27 5f 27 20 29 7b 0a 20 20 20 20 7a 2b 2b =='_' ){. z++
14e0: 3b 0a 20 20 20 20 69 2b 2b 3b 0a 20 20 7d 0a 20 ;. i++;. }.
14f0: 20 72 65 74 75 72 6e 20 69 3b 0a 7d 0a 0a 2f 2a return i;.}../*
1500: 0a 2a 2a 20 54 68 65 20 7a 5b 5d 20 69 6e 70 75 .** The z[] inpu
1510: 74 20 63 6f 6e 74 61 69 6e 73 20 74 65 78 74 20 t contains text
1520: 6d 69 78 65 64 20 77 69 74 68 20 54 48 31 20 73 mixed with TH1 s
1530: 63 72 69 70 74 73 2e 0a 2a 2a 20 54 68 65 20 54 cripts..** The T
1540: 48 31 20 73 63 72 69 70 74 73 20 61 72 65 20 63 H1 scripts are c
1550: 6f 6e 74 61 69 6e 65 64 20 77 69 74 68 69 6e 20 ontained within
1560: 3c 74 68 31 3e 2e 2e 2e 3c 2f 74 68 31 3e 2e 20 <th1>...</th1>.
1570: 20 54 68 69 73 20 72 6f 75 74 69 6e 65 0a 2a 2a This routine.**
1580: 20 70 72 6f 63 65 73 73 65 73 20 74 68 65 20 74 processes the t
1590: 65 6d 70 6c 61 74 65 20 61 6e 64 20 77 72 69 74 emplate and writ
15a0: 65 73 20 74 68 65 20 72 65 73 75 6c 74 73 20 6f es the results o
15b0: 6e 20 65 69 74 68 65 72 0a 2a 2a 20 73 74 64 6f n either.** stdo
15c0: 75 74 20 6f 72 20 69 6e 74 6f 20 43 47 49 2e 0a ut or into CGI..
15d0: 2a 2f 0a 69 6e 74 20 54 68 5f 52 65 6e 64 65 72 */.int Th_Render
15e0: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 29 7b (const char *z){
15f0: 0a 20 20 69 6e 74 20 69 20 3d 20 30 3b 0a 20 20 . int i = 0;.
1600: 69 6e 74 20 6e 3b 0a 20 20 69 6e 74 20 72 63 20 int n;. int rc
1610: 3d 20 54 48 5f 4f 4b 3b 0a 20 20 75 63 68 61 72 = TH_OK;. uchar
1620: 20 2a 7a 52 65 73 75 6c 74 3b 0a 20 20 69 6e 69 *zResult;. ini
1630: 74 69 61 6c 69 7a 65 49 6e 74 65 72 70 28 29 3b tializeInterp();
1640: 0a 20 20 77 68 69 6c 65 28 20 7a 5b 69 5d 20 29 . while( z[i] )
1650: 7b 0a 20 20 20 20 69 66 28 20 7a 5b 69 5d 3d 3d {. if( z[i]==
1660: 27 24 27 20 26 26 20 28 6e 20 3d 20 76 61 6c 69 '$' && (n = vali
1670: 64 56 61 72 4e 61 6d 65 28 26 7a 5b 69 2b 31 5d dVarName(&z[i+1]
1680: 29 29 3e 30 20 29 7b 0a 20 20 20 20 20 20 73 65 ))>0 ){. se
1690: 6e 64 54 65 78 74 28 7a 2c 20 69 29 3b 0a 20 20 ndText(z, i);.
16a0: 20 20 20 20 72 63 20 3d 20 54 68 5f 47 65 74 56 rc = Th_GetV
16b0: 61 72 28 69 6e 74 65 72 70 2c 20 26 7a 5b 69 2b ar(interp, &z[i+
16c0: 31 5d 2c 20 6e 29 3b 0a 20 20 20 20 20 20 7a 20 1], n);. z
16d0: 2b 3d 20 69 2b 31 2b 6e 3b 0a 20 20 20 20 20 20 += i+1+n;.
16e0: 69 20 3d 20 30 3b 0a 20 20 20 20 20 20 7a 52 65 i = 0;. zRe
16f0: 73 75 6c 74 20 3d 20 54 68 5f 47 65 74 52 65 73 sult = Th_GetRes
1700: 75 6c 74 28 69 6e 74 65 72 70 2c 20 26 6e 29 3b ult(interp, &n);
1710: 0a 20 20 20 20 20 20 73 65 6e 64 54 65 78 74 28 . sendText(
1720: 7a 52 65 73 75 6c 74 2c 20 6e 29 3b 0a 20 20 20 zResult, n);.
1730: 20 7d 65 6c 73 65 20 69 66 28 20 7a 5b 69 5d 3d }else if( z[i]=
1740: 3d 27 3c 27 20 26 26 20 69 73 42 65 67 69 6e 53 ='<' && isBeginS
1750: 63 72 69 70 74 54 61 67 28 26 7a 5b 69 5d 29 20 criptTag(&z[i])
1760: 29 7b 0a 20 20 20 20 20 20 73 65 6e 64 54 65 78 ){. sendTex
1770: 74 28 7a 2c 20 69 29 3b 0a 20 20 20 20 20 20 7a t(z, i);. z
1780: 20 2b 3d 20 69 2b 35 3b 0a 20 20 20 20 20 20 66 += i+5;. f
1790: 6f 72 28 69 3d 30 3b 20 7a 5b 69 5d 20 26 26 20 or(i=0; z[i] &&
17a0: 28 7a 5b 69 5d 21 3d 27 3c 27 20 7c 7c 20 21 69 (z[i]!='<' || !i
17b0: 73 45 6e 64 53 63 72 69 70 74 54 61 67 28 26 7a sEndScriptTag(&z
17c0: 5b 69 5d 29 29 3b 20 69 2b 2b 29 7b 7d 0a 20 20 [i])); i++){}.
17d0: 20 20 20 20 72 63 20 3d 20 54 68 5f 45 76 61 6c rc = Th_Eval
17e0: 28 69 6e 74 65 72 70 2c 20 30 2c 20 28 63 6f 6e (interp, 0, (con
17f0: 73 74 20 75 63 68 61 72 2a 29 7a 2c 20 69 29 3b st uchar*)z, i);
1800: 0a 20 20 20 20 20 20 69 66 28 20 72 63 21 3d 53 . if( rc!=S
1810: 42 53 5f 4f 4b 20 29 20 62 72 65 61 6b 3b 0a 20 BS_OK ) break;.
1820: 20 20 20 20 20 7a 20 2b 3d 20 69 3b 0a 20 20 20 z += i;.
1830: 20 20 20 69 66 28 20 7a 5b 30 5d 20 29 7b 20 7a if( z[0] ){ z
1840: 20 2b 3d 20 36 3b 20 7d 0a 20 20 20 20 20 20 69 += 6; }. i
1850: 20 3d 20 30 3b 0a 20 20 20 20 7d 65 6c 73 65 7b = 0;. }else{
1860: 0a 20 20 20 20 20 20 69 2b 2b 3b 0a 20 20 20 20 . i++;.
1870: 7d 0a 20 20 7d 0a 20 20 69 66 28 20 72 63 3d 3d }. }. if( rc==
1880: 54 48 5f 45 52 52 4f 52 20 29 7b 0a 20 20 20 20 TH_ERROR ){.
1890: 73 65 6e 64 54 65 78 74 28 22 3c 68 72 3e 3c 70 sendText("<hr><p
18a0: 3e 3c 66 6f 6e 74 20 63 6f 6c 6f 72 3d 5c 22 72 ><font color=\"r
18b0: 65 64 5c 22 3e 3c 62 3e 45 52 52 4f 52 3a 20 22 ed\"><b>ERROR: "
18c0: 2c 20 2d 31 29 3b 0a 20 20 20 20 7a 52 65 73 75 , -1);. zResu
18d0: 6c 74 20 3d 20 54 68 5f 47 65 74 52 65 73 75 6c lt = Th_GetResul
18e0: 74 28 69 6e 74 65 72 70 2c 20 26 6e 29 3b 0a 20 t(interp, &n);.
18f0: 20 20 20 73 65 6e 64 54 65 78 74 28 7a 52 65 73 sendText(zRes
1900: 75 6c 74 2c 20 6e 29 3b 0a 20 20 20 20 73 65 6e ult, n);. sen
1910: 64 54 65 78 74 28 22 3c 2f 62 3e 3c 2f 66 6f 6e dText("</b></fon
1920: 74 3e 3c 2f 70 3e 22 2c 20 2d 31 29 3b 0a 20 20 t></p>", -1);.
1930: 7d 65 6c 73 65 7b 0a 20 20 20 20 73 65 6e 64 54 }else{. sendT
1940: 65 78 74 28 7a 2c 20 69 29 3b 0a 20 20 7d 0a 20 ext(z, i);. }.
1950: 20 72 65 74 75 72 6e 20 72 63 3b 0a 7d 0a 0a 2f return rc;.}../
1960: 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 74 65 *.** COMMAND: te
1970: 73 74 2d 74 68 2d 72 65 6e 64 65 72 0a 2a 2f 0a st-th-render.*/.
1980: 76 6f 69 64 20 74 65 73 74 5f 74 68 5f 72 65 6e void test_th_ren
1990: 64 65 72 28 76 6f 69 64 29 7b 0a 20 20 42 6c 6f der(void){. Blo
19a0: 62 20 69 6e 3b 0a 20 20 69 66 28 20 67 2e 61 72 b in;. if( g.ar
19b0: 67 63 3c 33 20 29 7b 0a 20 20 20 20 75 73 61 67 gc<3 ){. usag
19c0: 65 28 22 46 49 4c 45 22 29 3b 0a 20 20 7d 0a 20 e("FILE");. }.
19d0: 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 69 6e 29 3b blob_zero(&in);
19e0: 0a 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66 72 6f . blob_read_fro
19f0: 6d 5f 66 69 6c 65 28 26 69 6e 2c 20 67 2e 61 72 m_file(&in, g.ar
1a00: 67 76 5b 32 5d 29 3b 0a 20 20 54 68 5f 52 65 6e gv[2]);. Th_Ren
1a10: 64 65 72 28 62 6c 6f 62 5f 73 74 72 28 26 69 6e der(blob_str(&in
1a20: 29 29 3b 0a 7d 0a ));.}.