|
e6aab1a…
|
drh
|
1 |
/* |
|
e6aab1a…
|
drh
|
2 |
** Copyright (c) 2016 D. Richard Hipp |
|
e6aab1a…
|
drh
|
3 |
** |
|
e6aab1a…
|
drh
|
4 |
** This program is free software; you can redistribute it and/or |
|
e6aab1a…
|
drh
|
5 |
** modify it under the terms of the Simplified BSD License (also |
|
e6aab1a…
|
drh
|
6 |
** known as the "2-Clause License" or "FreeBSD License".) |
|
e6aab1a…
|
drh
|
7 |
** |
|
e6aab1a…
|
drh
|
8 |
** This program is distributed in the hope that it will be useful, |
|
e6aab1a…
|
drh
|
9 |
** but without any warranty; without even the implied warranty of |
|
e6aab1a…
|
drh
|
10 |
** merchantability or fitness for a particular purpose. |
|
e6aab1a…
|
drh
|
11 |
** |
|
e6aab1a…
|
drh
|
12 |
** Author contact information: |
|
e6aab1a…
|
drh
|
13 |
** [email protected] |
|
e6aab1a…
|
drh
|
14 |
** http://www.hwaci.com/drh/ |
|
e6aab1a…
|
drh
|
15 |
** |
|
e6aab1a…
|
drh
|
16 |
******************************************************************************* |
|
e6aab1a…
|
drh
|
17 |
** |
|
e6aab1a…
|
drh
|
18 |
** This file contains code used to map command names (ex: "help", "commit", |
|
e6aab1a…
|
drh
|
19 |
** "diff") or webpage names (ex: "/timeline", "/search") into the functions |
|
e6aab1a…
|
drh
|
20 |
** that implement those commands and web pages and their associated help |
|
e6aab1a…
|
drh
|
21 |
** text. |
|
e6aab1a…
|
drh
|
22 |
*/ |
|
e6aab1a…
|
drh
|
23 |
#include "config.h" |
|
e6aab1a…
|
drh
|
24 |
#include <assert.h> |
|
e6aab1a…
|
drh
|
25 |
#include "dispatch.h" |
|
e6aab1a…
|
drh
|
26 |
|
|
e6aab1a…
|
drh
|
27 |
#if INTERFACE |
|
e6aab1a…
|
drh
|
28 |
/* |
|
e6aab1a…
|
drh
|
29 |
** An instance of this object defines everything we need to know about an |
|
6eeb27a…
|
drh
|
30 |
** individual command, webpage, setting, or help topic. |
|
e6aab1a…
|
drh
|
31 |
*/ |
|
e6aab1a…
|
drh
|
32 |
struct CmdOrPage { |
|
49703de…
|
drh
|
33 |
const char *zName; /* Name. Webpages start with "/". Commands do not */ |
|
2b6a34c…
|
andygoth
|
34 |
void (*xFunc)(void); /* Implementation function, or NULL for settings */ |
|
e6aab1a…
|
drh
|
35 |
const char *zHelp; /* Raw help text */ |
|
db70849…
|
danield
|
36 |
int iHelp; /* Index of help variable */ |
|
3ca2bc1…
|
mistachkin
|
37 |
unsigned int eCmdFlags; /* Flags */ |
|
e6aab1a…
|
drh
|
38 |
}; |
|
e6aab1a…
|
drh
|
39 |
|
|
555ddfe…
|
drh
|
40 |
/*************************************************************************** |
|
555ddfe…
|
drh
|
41 |
** These macros must match similar macros in mkindex.c |
|
555ddfe…
|
drh
|
42 |
** Allowed values for CmdOrPage.eCmdFlags. |
|
555ddfe…
|
drh
|
43 |
*/ |
|
6eeb27a…
|
drh
|
44 |
#define CMDFLAG_1ST_TIER 0x000001 /* Most important commands */ |
|
6eeb27a…
|
drh
|
45 |
#define CMDFLAG_2ND_TIER 0x000002 /* Obscure and seldom used commands */ |
|
6eeb27a…
|
drh
|
46 |
#define CMDFLAG_TEST 0x000004 /* Commands for testing only */ |
|
6eeb27a…
|
drh
|
47 |
#define CMDFLAG_WEBPAGE 0x000008 /* Web pages */ |
|
6eeb27a…
|
drh
|
48 |
#define CMDFLAG_COMMAND 0x000010 /* A command */ |
|
6eeb27a…
|
drh
|
49 |
#define CMDFLAG_SETTING 0x000020 /* A setting */ |
|
6eeb27a…
|
drh
|
50 |
#define CMDFLAG_VERSIONABLE 0x000040 /* A versionable setting */ |
|
6eeb27a…
|
drh
|
51 |
#define CMDFLAG_BLOCKTEXT 0x000080 /* Multi-line text setting */ |
|
6eeb27a…
|
drh
|
52 |
#define CMDFLAG_BOOLEAN 0x000100 /* A boolean setting */ |
|
6eeb27a…
|
drh
|
53 |
#define CMDFLAG_RAWCONTENT 0x000200 /* Do not interpret POST content */ |
|
6eeb27a…
|
drh
|
54 |
/* NOTE: 0x000400 = CMDFLAG_SENSITIVE in mkindex.c! */ |
|
6eeb27a…
|
drh
|
55 |
#define CMDFLAG_HIDDEN 0x000800 /* Elide from most listings */ |
|
6eeb27a…
|
drh
|
56 |
#define CMDFLAG_LDAVG_EXEMPT 0x001000 /* Exempt from load_control() */ |
|
6eeb27a…
|
drh
|
57 |
#define CMDFLAG_ALIAS 0x002000 /* Command aliases */ |
|
6eeb27a…
|
drh
|
58 |
#define CMDFLAG_KEEPEMPTY 0x004000 /* Do not unset empty settings */ |
|
6eeb27a…
|
drh
|
59 |
#define CMDFLAG_ABBREVSUBCMD 0x008000 /* Help text abbreviates subcommands */ |
|
6eeb27a…
|
drh
|
60 |
#define CMDFLAG_TOPIC 0x010000 /* A help topic */ |
|
555ddfe…
|
drh
|
61 |
/**************************************************************************/ |
|
555ddfe…
|
drh
|
62 |
|
|
555ddfe…
|
drh
|
63 |
/* Values for the 2nd parameter to dispatch_name_search() */ |
|
6eeb27a…
|
drh
|
64 |
#define CMDFLAG_ANY 0x010038 /* Match anything */ |
|
6eeb27a…
|
drh
|
65 |
#define CMDFLAG_PREFIX 0x000200 /* Prefix match is OK */ |
|
e6aab1a…
|
drh
|
66 |
|
|
e6aab1a…
|
drh
|
67 |
#endif /* INTERFACE */ |
|
e6aab1a…
|
drh
|
68 |
|
|
e6aab1a…
|
drh
|
69 |
/* |
|
e6aab1a…
|
drh
|
70 |
** The page_index.h file contains the definition for aCommand[] - an array |
|
e6aab1a…
|
drh
|
71 |
** of CmdOrPage objects that defines all available commands and webpages |
|
e6aab1a…
|
drh
|
72 |
** known to Fossil. |
|
e6aab1a…
|
drh
|
73 |
** |
|
e6aab1a…
|
drh
|
74 |
** The entries in aCommand[] are in sorted order by name. Since webpage names |
|
e6aab1a…
|
drh
|
75 |
** always begin with "/", all webpage names occur first. The page_index.h file |
|
1763f28…
|
mistachkin
|
76 |
** also sets the FOSSIL_FIRST_CMD macro to be the *approximate* index |
|
49703de…
|
drh
|
77 |
** in aCommand[] of the first command entry. FOSSIL_FIRST_CMD might be |
|
49703de…
|
drh
|
78 |
** slightly too low, and so the range FOSSIL_FIRST_CMD...MX_COMMAND might |
|
49703de…
|
drh
|
79 |
** contain a few webpage entries at the beginning. |
|
e6aab1a…
|
drh
|
80 |
** |
|
e6aab1a…
|
drh
|
81 |
** The page_index.h file is generated by the mkindex program which scans all |
|
49703de…
|
drh
|
82 |
** source code files looking for header comments on the functions that |
|
49703de…
|
drh
|
83 |
** implement command and webpages. |
|
e6aab1a…
|
drh
|
84 |
*/ |
|
e6aab1a…
|
drh
|
85 |
#include "page_index.h" |
|
3cb9ba4…
|
andygoth
|
86 |
#define MX_COMMAND count(aCommand) |
|
db70849…
|
danield
|
87 |
#define MX_HELP_DUP 5 /* Upper bound estimate on help string duplication */ |
|
e6aab1a…
|
drh
|
88 |
|
|
e6aab1a…
|
drh
|
89 |
/* |
|
2b6a34c…
|
andygoth
|
90 |
** Given a command, webpage, or setting name in zName, find the corresponding |
|
2b6a34c…
|
andygoth
|
91 |
** CmdOrPage object and return a pointer to that object in *ppCmd. |
|
e6aab1a…
|
drh
|
92 |
** |
|
2b6a34c…
|
andygoth
|
93 |
** The eType field is CMDFLAG_COMMAND to look up commands, CMDFLAG_WEBPAGE to |
|
2b6a34c…
|
andygoth
|
94 |
** look up webpages, CMDFLAG_SETTING to look up settings, or CMDFLAG_ANY to look |
|
2b6a34c…
|
andygoth
|
95 |
** for any. If the CMDFLAG_PREFIX bit is set, then a prefix match is allowed. |
|
e6aab1a…
|
drh
|
96 |
** |
|
e6aab1a…
|
drh
|
97 |
** Return values: |
|
e6aab1a…
|
drh
|
98 |
** 0: Success. *ppCmd is set to the appropriate CmdOrPage |
|
e6aab1a…
|
drh
|
99 |
** 1: Not found. |
|
e6aab1a…
|
drh
|
100 |
** 2: Ambiguous. Two or more entries match. |
|
e6aab1a…
|
drh
|
101 |
*/ |
|
e6aab1a…
|
drh
|
102 |
int dispatch_name_search( |
|
49703de…
|
drh
|
103 |
const char *zName, /* Look for this name */ |
|
49703de…
|
drh
|
104 |
unsigned eType, /* CMDFLAGS_* bits */ |
|
49703de…
|
drh
|
105 |
const CmdOrPage **ppCmd /* Write the matching CmdOrPage object here */ |
|
e6aab1a…
|
drh
|
106 |
){ |
|
e6aab1a…
|
drh
|
107 |
int upr, lwr, mid; |
|
e6aab1a…
|
drh
|
108 |
int nName = strlen(zName); |
|
e6aab1a…
|
drh
|
109 |
lwr = 0; |
|
e6aab1a…
|
drh
|
110 |
upr = MX_COMMAND - 1; |
|
e6aab1a…
|
drh
|
111 |
while( lwr<=upr ){ |
|
e6aab1a…
|
drh
|
112 |
int c; |
|
e6aab1a…
|
drh
|
113 |
mid = (upr+lwr)/2; |
|
e6aab1a…
|
drh
|
114 |
c = strcmp(zName, aCommand[mid].zName); |
|
e6aab1a…
|
drh
|
115 |
if( c==0 ){ |
|
38df2a4…
|
drh
|
116 |
if( (aCommand[mid].eCmdFlags & eType)==0 ) return 1; |
|
e6aab1a…
|
drh
|
117 |
*ppCmd = &aCommand[mid]; |
|
e6aab1a…
|
drh
|
118 |
return 0; /* An exact match */ |
|
e6aab1a…
|
drh
|
119 |
}else if( c<0 ){ |
|
e6aab1a…
|
drh
|
120 |
upr = mid - 1; |
|
e6aab1a…
|
drh
|
121 |
}else{ |
|
e6aab1a…
|
drh
|
122 |
lwr = mid + 1; |
|
e6aab1a…
|
drh
|
123 |
} |
|
e6aab1a…
|
drh
|
124 |
} |
|
e6aab1a…
|
drh
|
125 |
if( (eType & CMDFLAG_PREFIX)!=0 |
|
e6aab1a…
|
drh
|
126 |
&& lwr<MX_COMMAND |
|
e6aab1a…
|
drh
|
127 |
&& strncmp(zName, aCommand[lwr].zName, nName)==0 |
|
e6aab1a…
|
drh
|
128 |
){ |
|
2b6a34c…
|
andygoth
|
129 |
/* An inexact prefix match was found. Scan the name table to try to find |
|
2b6a34c…
|
andygoth
|
130 |
* exactly one entry with this prefix and the requested type. */ |
|
2b6a34c…
|
andygoth
|
131 |
for( mid=-1; lwr<MX_COMMAND |
|
2b6a34c…
|
andygoth
|
132 |
&& strncmp(zName, aCommand[lwr].zName, nName)==0; ++lwr ){ |
|
2b6a34c…
|
andygoth
|
133 |
if( aCommand[lwr].eCmdFlags & eType ){ |
|
2b6a34c…
|
andygoth
|
134 |
if( mid<0 ){ |
|
2b6a34c…
|
andygoth
|
135 |
mid = lwr; /* Potential ambiguous prefix */ |
|
2b6a34c…
|
andygoth
|
136 |
}else{ |
|
512905e…
|
mgagnon
|
137 |
if( aCommand[lwr].xFunc != aCommand[mid].xFunc ){ |
|
512905e…
|
mgagnon
|
138 |
return 2; /* Confirmed ambiguous prefix */ |
|
512905e…
|
mgagnon
|
139 |
} |
|
2b6a34c…
|
andygoth
|
140 |
} |
|
2b6a34c…
|
andygoth
|
141 |
} |
|
2b6a34c…
|
andygoth
|
142 |
} |
|
2b6a34c…
|
andygoth
|
143 |
if( mid>=0 ){ |
|
2b6a34c…
|
andygoth
|
144 |
*ppCmd = &aCommand[mid]; |
|
e6aab1a…
|
drh
|
145 |
return 0; /* Prefix match */ |
|
e6aab1a…
|
drh
|
146 |
} |
|
e6aab1a…
|
drh
|
147 |
} |
|
e6aab1a…
|
drh
|
148 |
return 1; /* Not found */ |
|
e6aab1a…
|
drh
|
149 |
} |
|
e6aab1a…
|
drh
|
150 |
|
|
e6aab1a…
|
drh
|
151 |
/* |
|
8131f1c…
|
drh
|
152 |
** zName is the name of a webpage (eType==CMDFLAGS_WEBPAGE) that does not |
|
8131f1c…
|
drh
|
153 |
** exist in the dispatch table. Check to see if this webpage name exists |
|
8131f1c…
|
drh
|
154 |
** as an alias in the CONFIG table of the repository. If it is, then make |
|
8131f1c…
|
drh
|
155 |
** appropriate changes to the CGI environment and set *ppCmd to point to the |
|
b1191c1…
|
andygoth
|
156 |
** aliased command. |
|
8131f1c…
|
drh
|
157 |
** |
|
8131f1c…
|
drh
|
158 |
** Return 0 if the command is successfully aliased. Return 1 if there |
|
ce1bc4f…
|
jan.nijtmans
|
159 |
** is not alias for zName. Any kind of error in the alias value causes a |
|
8131f1c…
|
drh
|
160 |
** error to be thrown. |
|
8131f1c…
|
drh
|
161 |
** |
|
b1191c1…
|
andygoth
|
162 |
** Alias entries in the CONFIG table have a "name" value of "walias:NAME" |
|
8131f1c…
|
drh
|
163 |
** where NAME is the input page name. The value is a string of the form |
|
8131f1c…
|
drh
|
164 |
** "NEWNAME?QUERYPARAMS". The ?QUERYPARAMS is optional. If present (and it |
|
b1191c1…
|
andygoth
|
165 |
** usually is), then all query parameters are added to the CGI environment. |
|
8131f1c…
|
drh
|
166 |
** Except, query parameters of the form "X!" cause any CGI X variable to be |
|
8131f1c…
|
drh
|
167 |
** removed. |
|
8131f1c…
|
drh
|
168 |
*/ |
|
8131f1c…
|
drh
|
169 |
int dispatch_alias(const char *zName, const CmdOrPage **ppCmd){ |
|
8131f1c…
|
drh
|
170 |
char *z; |
|
8131f1c…
|
drh
|
171 |
char *zQ; |
|
4c666cc…
|
drh
|
172 |
int i; |
|
8131f1c…
|
drh
|
173 |
|
|
8131f1c…
|
drh
|
174 |
z = db_text(0, "SELECT value FROM config WHERE name='walias:%q'",zName); |
|
8131f1c…
|
drh
|
175 |
if( z==0 ) return 1; |
|
8131f1c…
|
drh
|
176 |
for(i=0; z[i] && z[i]!='?'; i++){} |
|
8131f1c…
|
drh
|
177 |
if( z[i]=='?' ){ |
|
8131f1c…
|
drh
|
178 |
z[i] = 0; |
|
8131f1c…
|
drh
|
179 |
zQ = &z[i+1]; |
|
8131f1c…
|
drh
|
180 |
}else{ |
|
8131f1c…
|
drh
|
181 |
zQ = &z[i]; |
|
8131f1c…
|
drh
|
182 |
} |
|
8131f1c…
|
drh
|
183 |
if( dispatch_name_search(z, CMDFLAG_WEBPAGE, ppCmd) ){ |
|
99fcc43…
|
drh
|
184 |
fossil_fatal("\"%s\" aliased to \"%s\" but \"%s\" does not exist", |
|
8131f1c…
|
drh
|
185 |
zName, z, z); |
|
8131f1c…
|
drh
|
186 |
} |
|
8131f1c…
|
drh
|
187 |
z = zQ; |
|
8131f1c…
|
drh
|
188 |
while( *z ){ |
|
8131f1c…
|
drh
|
189 |
char *zName = z; |
|
49b6f89…
|
drh
|
190 |
char *zValue = 0; |
|
8131f1c…
|
drh
|
191 |
while( *z && *z!='=' && *z!='&' && *z!='!' ){ z++; } |
|
8131f1c…
|
drh
|
192 |
if( *z=='=' ){ |
|
8131f1c…
|
drh
|
193 |
*z = 0; |
|
8131f1c…
|
drh
|
194 |
z++; |
|
8131f1c…
|
drh
|
195 |
zValue = z; |
|
8131f1c…
|
drh
|
196 |
while( *z && *z!='&' ){ z++; } |
|
8131f1c…
|
drh
|
197 |
if( *z ){ |
|
8131f1c…
|
drh
|
198 |
*z = 0; |
|
8131f1c…
|
drh
|
199 |
z++; |
|
8131f1c…
|
drh
|
200 |
} |
|
8131f1c…
|
drh
|
201 |
dehttpize(zValue); |
|
8131f1c…
|
drh
|
202 |
}else if( *z=='!' ){ |
|
8131f1c…
|
drh
|
203 |
*(z++) = 0; |
|
8131f1c…
|
drh
|
204 |
cgi_delete_query_parameter(zName); |
|
8131f1c…
|
drh
|
205 |
zName = ""; |
|
8131f1c…
|
drh
|
206 |
}else{ |
|
8131f1c…
|
drh
|
207 |
if( *z ){ *z++ = 0; } |
|
8131f1c…
|
drh
|
208 |
zValue = ""; |
|
8131f1c…
|
drh
|
209 |
} |
|
8131f1c…
|
drh
|
210 |
if( fossil_islower(zName[0]) ){ |
|
8131f1c…
|
drh
|
211 |
cgi_replace_query_parameter(zName, zValue); |
|
19bbd2c…
|
drh
|
212 |
}else if( fossil_isupper(zName[0]) ){ |
|
19bbd2c…
|
drh
|
213 |
cgi_replace_query_parameter_tolower(zName, zValue); |
|
8131f1c…
|
drh
|
214 |
} |
|
8131f1c…
|
drh
|
215 |
} |
|
8131f1c…
|
drh
|
216 |
return 0; |
|
8131f1c…
|
drh
|
217 |
} |
|
8131f1c…
|
drh
|
218 |
|
|
8131f1c…
|
drh
|
219 |
/* |
|
e6aab1a…
|
drh
|
220 |
** Fill Blob with a space-separated list of all command names that |
|
512905e…
|
mgagnon
|
221 |
** match the prefix zPrefix and the eType CMDFLAGS_ bits. |
|
e6aab1a…
|
drh
|
222 |
*/ |
|
512905e…
|
mgagnon
|
223 |
void dispatch_matching_names( |
|
512905e…
|
mgagnon
|
224 |
const char *zPrefix, /* name prefix */ |
|
512905e…
|
mgagnon
|
225 |
unsigned eType, /* CMDFLAG_ bits */ |
|
512905e…
|
mgagnon
|
226 |
Blob *pList /* space-separated list of command names */ |
|
512905e…
|
mgagnon
|
227 |
){ |
|
e6aab1a…
|
drh
|
228 |
int i; |
|
e6aab1a…
|
drh
|
229 |
int nPrefix = (int)strlen(zPrefix); |
|
e6aab1a…
|
drh
|
230 |
for(i=FOSSIL_FIRST_CMD; i<MX_COMMAND; i++){ |
|
512905e…
|
mgagnon
|
231 |
if( (aCommand[i].eCmdFlags & eType)==0 ) continue; |
|
e6aab1a…
|
drh
|
232 |
if( strncmp(zPrefix, aCommand[i].zName, nPrefix)==0 ){ |
|
e6aab1a…
|
drh
|
233 |
blob_appendf(pList, " %s", aCommand[i].zName); |
|
e58c76a…
|
drh
|
234 |
} |
|
e58c76a…
|
drh
|
235 |
} |
|
e58c76a…
|
drh
|
236 |
} |
|
e58c76a…
|
drh
|
237 |
|
|
e58c76a…
|
drh
|
238 |
/* |
|
e58c76a…
|
drh
|
239 |
** Return the index of the first non-space character that follows |
|
e58c76a…
|
drh
|
240 |
** a span of two or more spaces. Return 0 if there is not gap. |
|
e58c76a…
|
drh
|
241 |
*/ |
|
e58c76a…
|
drh
|
242 |
static int hasGap(const char *z, int n){ |
|
e58c76a…
|
drh
|
243 |
int i; |
|
e58c76a…
|
drh
|
244 |
for(i=3; i<n-1; i++){ |
|
e58c76a…
|
drh
|
245 |
if( z[i]==' ' && z[i+1]!=' ' && z[i-1]==' ' && z[i-2]!='.' ) return i+1; |
|
e58c76a…
|
drh
|
246 |
} |
|
e58c76a…
|
drh
|
247 |
return 0 ; |
|
e58c76a…
|
drh
|
248 |
} |
|
e58c76a…
|
drh
|
249 |
|
|
e58c76a…
|
drh
|
250 |
/* |
|
71992d0…
|
drh
|
251 |
** Input string zIn starts with '['. If the content is a hyperlink of the |
|
71992d0…
|
drh
|
252 |
** form [[...]] then return the index of the closing ']'. Otherwise return 0. |
|
71992d0…
|
drh
|
253 |
*/ |
|
71992d0…
|
drh
|
254 |
static int help_is_link(const char *z, int n){ |
|
71992d0…
|
drh
|
255 |
int i; |
|
71992d0…
|
drh
|
256 |
char c; |
|
71992d0…
|
drh
|
257 |
if( n<5 ) return 0; |
|
71992d0…
|
drh
|
258 |
if( z[1]!='[' ) return 0; |
|
71992d0…
|
drh
|
259 |
for(i=3; i<n && (c = z[i])!=0; i++){ |
|
71992d0…
|
drh
|
260 |
if( c==']' && z[i-1]==']' ) return i; |
|
71992d0…
|
drh
|
261 |
} |
|
71992d0…
|
drh
|
262 |
return 0; |
|
71992d0…
|
drh
|
263 |
} |
|
71992d0…
|
drh
|
264 |
|
|
71992d0…
|
drh
|
265 |
/* |
|
517223e…
|
drh
|
266 |
** Append text to pOut with changes: |
|
517223e…
|
drh
|
267 |
** |
|
517223e…
|
drh
|
268 |
** * Add hyperlink markup for [[...]] |
|
517223e…
|
drh
|
269 |
** * Escape HTML characters: < > & and " |
|
517223e…
|
drh
|
270 |
** * Change "%fossil" to just "fossil" |
|
71992d0…
|
drh
|
271 |
*/ |
|
71992d0…
|
drh
|
272 |
static void appendLinked(Blob *pOut, const char *z, int n){ |
|
71992d0…
|
drh
|
273 |
int i = 0; |
|
71992d0…
|
drh
|
274 |
int j; |
|
71992d0…
|
drh
|
275 |
while( i<n ){ |
|
517223e…
|
drh
|
276 |
char c = z[i]; |
|
517223e…
|
drh
|
277 |
if( c=='[' && (j = help_is_link(z+i, n-i))>0 ){ |
|
71992d0…
|
drh
|
278 |
if( i ) blob_append(pOut, z, i); |
|
71992d0…
|
drh
|
279 |
z += i+2; |
|
71992d0…
|
drh
|
280 |
n -= i+2; |
|
c64f28d…
|
drh
|
281 |
blob_appendf(pOut, "<a href='%R/help/%.*s'>%.*s</a>", |
|
71992d0…
|
drh
|
282 |
j-3, z, j-3, z); |
|
71992d0…
|
drh
|
283 |
z += j-1; |
|
71992d0…
|
drh
|
284 |
n -= j-1; |
|
517223e…
|
drh
|
285 |
i = 0; |
|
517223e…
|
drh
|
286 |
}else if( c=='%' && n-i>=7 && strncmp(z+i,"%fossil",7)==0 ){ |
|
517223e…
|
drh
|
287 |
if( i ) blob_append(pOut, z, i); |
|
517223e…
|
drh
|
288 |
z += i+7; |
|
517223e…
|
drh
|
289 |
n -= i+7; |
|
517223e…
|
drh
|
290 |
blob_append(pOut, "fossil", 6); |
|
517223e…
|
drh
|
291 |
i = 0; |
|
517223e…
|
drh
|
292 |
}else if( c=='<' ){ |
|
517223e…
|
drh
|
293 |
if( i ) blob_append(pOut, z, i); |
|
517223e…
|
drh
|
294 |
blob_append(pOut, "<", 4); |
|
517223e…
|
drh
|
295 |
z += i+1; |
|
517223e…
|
drh
|
296 |
n -= i+1; |
|
517223e…
|
drh
|
297 |
i = 0; |
|
517223e…
|
drh
|
298 |
}else if( c=='>' ){ |
|
517223e…
|
drh
|
299 |
if( i ) blob_append(pOut, z, i); |
|
517223e…
|
drh
|
300 |
blob_append(pOut, ">", 4); |
|
517223e…
|
drh
|
301 |
z += i+1; |
|
517223e…
|
drh
|
302 |
n -= i+1; |
|
517223e…
|
drh
|
303 |
i = 0; |
|
517223e…
|
drh
|
304 |
}else if( c=='&' ){ |
|
517223e…
|
drh
|
305 |
if( i ) blob_append(pOut, z, i); |
|
517223e…
|
drh
|
306 |
blob_append(pOut, "&", 5); |
|
517223e…
|
drh
|
307 |
z += i+1; |
|
517223e…
|
drh
|
308 |
n -= i+1; |
|
71992d0…
|
drh
|
309 |
i = 0; |
|
71992d0…
|
drh
|
310 |
}else{ |
|
71992d0…
|
drh
|
311 |
i++; |
|
71992d0…
|
drh
|
312 |
} |
|
71992d0…
|
drh
|
313 |
} |
|
71992d0…
|
drh
|
314 |
blob_append(pOut, z, i); |
|
517223e…
|
drh
|
315 |
} |
|
517223e…
|
drh
|
316 |
|
|
517223e…
|
drh
|
317 |
/* |
|
517223e…
|
drh
|
318 |
** Append text to pOut, adding formatting markup. Terms that |
|
517223e…
|
drh
|
319 |
** have all lower-case letters are within <tt>..</tt>. Terms |
|
6c84306…
|
drh
|
320 |
** that have all upper-case letters are within <i>..</i>. Except, |
|
6c84306…
|
drh
|
321 |
** if the entire string begins with % then put the whole thing |
|
6c84306…
|
drh
|
322 |
** inside of <tt>..</tt>. |
|
517223e…
|
drh
|
323 |
*/ |
|
517223e…
|
drh
|
324 |
static void appendMixedFont(Blob *pOut, const char *z, int n){ |
|
517223e…
|
drh
|
325 |
const char *zEnd = ""; |
|
517223e…
|
drh
|
326 |
int i = 0; |
|
517223e…
|
drh
|
327 |
int j; |
|
6c84306…
|
drh
|
328 |
if( n>0 && z[0]=='%' ){ |
|
6c84306…
|
drh
|
329 |
blob_append(pOut, "<tt>", 4); |
|
6c84306…
|
drh
|
330 |
blob_append(pOut, z, n); |
|
6c84306…
|
drh
|
331 |
blob_append(pOut, "</tt>", 5); |
|
6c84306…
|
drh
|
332 |
return; |
|
6c84306…
|
drh
|
333 |
} |
|
517223e…
|
drh
|
334 |
while( i<n ){ |
|
517223e…
|
drh
|
335 |
if( z[i]==' ' || z[i]=='=' ){ |
|
517223e…
|
drh
|
336 |
for(j=i+1; j<n && (z[j]==' ' || z[j]=='='); j++){} |
|
517223e…
|
drh
|
337 |
appendLinked(pOut, z+i, j-i); |
|
517223e…
|
drh
|
338 |
i = j; |
|
517223e…
|
drh
|
339 |
}else{ |
|
517223e…
|
drh
|
340 |
for(j=i; j<n && z[j]!=' ' && z[j]!='=' && !fossil_isalpha(z[j]); j++){} |
|
517223e…
|
drh
|
341 |
if( j>=n || z[j]==' ' || z[j]=='=' ){ |
|
517223e…
|
drh
|
342 |
zEnd = ""; |
|
517223e…
|
drh
|
343 |
}else{ |
|
517223e…
|
drh
|
344 |
if( fossil_isupper(z[j]) && z[i]!='-' ){ |
|
517223e…
|
drh
|
345 |
blob_append(pOut, "<i>",3); |
|
517223e…
|
drh
|
346 |
zEnd = "</i>"; |
|
517223e…
|
drh
|
347 |
}else{ |
|
517223e…
|
drh
|
348 |
blob_append(pOut, "<tt>", 4); |
|
517223e…
|
drh
|
349 |
zEnd = "</tt>"; |
|
517223e…
|
drh
|
350 |
} |
|
517223e…
|
drh
|
351 |
} |
|
517223e…
|
drh
|
352 |
while( j<n && z[j]!=' ' && z[j]!='=' ){ j++; } |
|
517223e…
|
drh
|
353 |
appendLinked(pOut, z+i, j-i); |
|
517223e…
|
drh
|
354 |
if( zEnd[0] ) blob_append(pOut, zEnd, -1); |
|
517223e…
|
drh
|
355 |
i = j; |
|
517223e…
|
drh
|
356 |
} |
|
517223e…
|
drh
|
357 |
} |
|
1763f28…
|
mistachkin
|
358 |
} |
|
1763f28…
|
mistachkin
|
359 |
|
|
1763f28…
|
mistachkin
|
360 |
/* |
|
1763f28…
|
mistachkin
|
361 |
** Attempt to reformat plain-text help into HTML for display on a webpage. |
|
1763f28…
|
mistachkin
|
362 |
** |
|
1763f28…
|
mistachkin
|
363 |
** The HTML output is appended to Blob pHtml, which should already be |
|
1763f28…
|
mistachkin
|
364 |
** initialized. |
|
e58c76a…
|
drh
|
365 |
** |
|
e58c76a…
|
drh
|
366 |
** Formatting rules: |
|
e58c76a…
|
drh
|
367 |
** |
|
e58c76a…
|
drh
|
368 |
** * Bullet lists are indented from the surrounding text by |
|
e58c76a…
|
drh
|
369 |
** at least one space. Each bullet begins with " * ". |
|
e58c76a…
|
drh
|
370 |
** |
|
e58c76a…
|
drh
|
371 |
** * Display lists are indented from the surrounding text. |
|
e58c76a…
|
drh
|
372 |
** Each tag begins with "-" or occur on a line that is |
|
e58c76a…
|
drh
|
373 |
** followed by two spaces and a non-space. <dd> elements can begin |
|
e58c76a…
|
drh
|
374 |
** on the same line as long as they are separated by at least |
|
e58c76a…
|
drh
|
375 |
** two spaces. |
|
e58c76a…
|
drh
|
376 |
** |
|
e58c76a…
|
drh
|
377 |
** * Indented text is show verbatim (<pre>...</pre>) |
|
e8ba89b…
|
drh
|
378 |
** |
|
e8ba89b…
|
drh
|
379 |
** * Lines that begin with "|" at the left margin are in <pre>...</pre> |
|
1763f28…
|
mistachkin
|
380 |
*/ |
|
1763f28…
|
mistachkin
|
381 |
static void help_to_html(const char *zHelp, Blob *pHtml){ |
|
e58c76a…
|
drh
|
382 |
int i; |
|
e58c76a…
|
drh
|
383 |
char c; |
|
e58c76a…
|
drh
|
384 |
int nIndent = 0; |
|
e58c76a…
|
drh
|
385 |
int wantP = 0; |
|
e58c76a…
|
drh
|
386 |
int wantBR = 0; |
|
e58c76a…
|
drh
|
387 |
int aIndent[10]; |
|
e58c76a…
|
drh
|
388 |
const char *azEnd[10]; |
|
e58c76a…
|
drh
|
389 |
int iLevel = 0; |
|
e58c76a…
|
drh
|
390 |
int isLI = 0; |
|
e58c76a…
|
drh
|
391 |
int isDT = 0; |
|
e8ba89b…
|
drh
|
392 |
int inPRE = 0; |
|
e58c76a…
|
drh
|
393 |
static const char *zEndDL = "</dl></blockquote>"; |
|
e58c76a…
|
drh
|
394 |
static const char *zEndPRE = "</pre></blockquote>"; |
|
e58c76a…
|
drh
|
395 |
static const char *zEndUL = "</ul>"; |
|
e58c76a…
|
drh
|
396 |
static const char *zEndDD = "</dd>"; |
|
e58c76a…
|
drh
|
397 |
|
|
e58c76a…
|
drh
|
398 |
aIndent[0] = 0; |
|
e58c76a…
|
drh
|
399 |
azEnd[0] = ""; |
|
e58c76a…
|
drh
|
400 |
while( zHelp[0] ){ |
|
e58c76a…
|
drh
|
401 |
i = 0; |
|
517223e…
|
drh
|
402 |
while( (c = zHelp[i])!=0 && c!='\n' ){ |
|
517223e…
|
drh
|
403 |
if( c=='%' && i>2 && zHelp[i-2]==':' && strncmp(zHelp+i,"%fossil",7)==0 ){ |
|
517223e…
|
drh
|
404 |
appendLinked(pHtml, zHelp, i); |
|
517223e…
|
drh
|
405 |
zHelp += i+1; |
|
517223e…
|
drh
|
406 |
i = 0; |
|
517223e…
|
drh
|
407 |
wantBR = 1; |
|
517223e…
|
drh
|
408 |
continue; |
|
517223e…
|
drh
|
409 |
} |
|
517223e…
|
drh
|
410 |
i++; |
|
517223e…
|
drh
|
411 |
} |
|
e8ba89b…
|
drh
|
412 |
if( i>2 && (zHelp[0]=='>' || zHelp[0]=='|') && zHelp[1]==' ' ){ |
|
e8ba89b…
|
drh
|
413 |
if( zHelp[0]=='>' ){ |
|
e8ba89b…
|
drh
|
414 |
isDT = 1; |
|
e8ba89b…
|
drh
|
415 |
for(nIndent=1; nIndent<i && zHelp[nIndent]==' '; nIndent++){} |
|
e8ba89b…
|
drh
|
416 |
}else{ |
|
e8ba89b…
|
drh
|
417 |
if( !inPRE ){ |
|
e8ba89b…
|
drh
|
418 |
blob_append(pHtml, "<pre>\n", -1); |
|
e8ba89b…
|
drh
|
419 |
inPRE = 1; |
|
e8ba89b…
|
drh
|
420 |
} |
|
e8ba89b…
|
drh
|
421 |
} |
|
e58c76a…
|
drh
|
422 |
}else{ |
|
e8ba89b…
|
drh
|
423 |
if( inPRE ){ |
|
e8ba89b…
|
drh
|
424 |
blob_append(pHtml, "</pre>\n", -1); |
|
e8ba89b…
|
drh
|
425 |
inPRE = 0; |
|
e8ba89b…
|
drh
|
426 |
} |
|
e58c76a…
|
drh
|
427 |
isDT = 0; |
|
e58c76a…
|
drh
|
428 |
for(nIndent=0; nIndent<i && zHelp[nIndent]==' '; nIndent++){} |
|
e8ba89b…
|
drh
|
429 |
} |
|
e8ba89b…
|
drh
|
430 |
if( inPRE ){ |
|
e8ba89b…
|
drh
|
431 |
blob_append(pHtml, zHelp+1, i); |
|
e8ba89b…
|
drh
|
432 |
zHelp += i + 1; |
|
e8ba89b…
|
drh
|
433 |
continue; |
|
517223e…
|
drh
|
434 |
} |
|
e58c76a…
|
drh
|
435 |
if( nIndent==i ){ |
|
e58c76a…
|
drh
|
436 |
if( c==0 ) break; |
|
517223e…
|
drh
|
437 |
if( iLevel && azEnd[iLevel]==zEndPRE ){ |
|
517223e…
|
drh
|
438 |
/* Skip the newline at the end of a <pre> */ |
|
517223e…
|
drh
|
439 |
}else{ |
|
517223e…
|
drh
|
440 |
blob_append_char(pHtml, '\n'); |
|
517223e…
|
drh
|
441 |
} |
|
e58c76a…
|
drh
|
442 |
wantP = 1; |
|
e58c76a…
|
drh
|
443 |
wantBR = 0; |
|
e58c76a…
|
drh
|
444 |
zHelp += i+1; |
|
e58c76a…
|
drh
|
445 |
continue; |
|
e58c76a…
|
drh
|
446 |
} |
|
e58c76a…
|
drh
|
447 |
if( nIndent+2<i && zHelp[nIndent]=='*' && zHelp[nIndent+1]==' ' ){ |
|
e58c76a…
|
drh
|
448 |
nIndent += 2; |
|
e58c76a…
|
drh
|
449 |
while( nIndent<i && zHelp[nIndent]==' '){ nIndent++; } |
|
e58c76a…
|
drh
|
450 |
isLI = 1; |
|
e58c76a…
|
drh
|
451 |
}else{ |
|
e58c76a…
|
drh
|
452 |
isLI = 0; |
|
e58c76a…
|
drh
|
453 |
} |
|
e58c76a…
|
drh
|
454 |
while( iLevel>0 && aIndent[iLevel]>nIndent ){ |
|
e58c76a…
|
drh
|
455 |
blob_append(pHtml, azEnd[iLevel--], -1); |
|
e58c76a…
|
drh
|
456 |
} |
|
e58c76a…
|
drh
|
457 |
if( nIndent>aIndent[iLevel] ){ |
|
e58c76a…
|
drh
|
458 |
assert( iLevel<ArraySize(aIndent)-2 ); |
|
e58c76a…
|
drh
|
459 |
if( isLI ){ |
|
e58c76a…
|
drh
|
460 |
iLevel++; |
|
e58c76a…
|
drh
|
461 |
aIndent[iLevel] = nIndent; |
|
e58c76a…
|
drh
|
462 |
azEnd[iLevel] = zEndUL; |
|
ccc780f…
|
drh
|
463 |
if( wantP ){ |
|
ccc780f…
|
drh
|
464 |
blob_append(pHtml,"<p>", 3); |
|
ccc780f…
|
drh
|
465 |
wantP = 0; |
|
ccc780f…
|
drh
|
466 |
} |
|
e58c76a…
|
drh
|
467 |
blob_append(pHtml, "<ul>\n", 5); |
|
275da70…
|
danield
|
468 |
}else if( isDT |
|
e58c76a…
|
drh
|
469 |
|| zHelp[nIndent]=='-' |
|
e58c76a…
|
drh
|
470 |
|| hasGap(zHelp+nIndent,i-nIndent) ){ |
|
e58c76a…
|
drh
|
471 |
iLevel++; |
|
e58c76a…
|
drh
|
472 |
aIndent[iLevel] = nIndent; |
|
e58c76a…
|
drh
|
473 |
azEnd[iLevel] = zEndDL; |
|
ccc780f…
|
drh
|
474 |
wantP = 0; |
|
ddd1c32…
|
drh
|
475 |
if( isDT ){ |
|
ddd1c32…
|
drh
|
476 |
blob_append(pHtml, "<blockquote><dl>\n", -1); |
|
ddd1c32…
|
drh
|
477 |
}else{ |
|
ddd1c32…
|
drh
|
478 |
blob_append(pHtml, "<blockquote><dl class=\"helpOptions\">\n", -1); |
|
ddd1c32…
|
drh
|
479 |
} |
|
e58c76a…
|
drh
|
480 |
}else if( azEnd[iLevel]==zEndDL ){ |
|
e58c76a…
|
drh
|
481 |
iLevel++; |
|
e58c76a…
|
drh
|
482 |
aIndent[iLevel] = nIndent; |
|
e58c76a…
|
drh
|
483 |
azEnd[iLevel] = zEndDD; |
|
ccc780f…
|
drh
|
484 |
if( wantP ){ |
|
ccc780f…
|
drh
|
485 |
blob_append(pHtml,"<p>", 3); |
|
ccc780f…
|
drh
|
486 |
wantP = 0; |
|
ccc780f…
|
drh
|
487 |
} |
|
e58c76a…
|
drh
|
488 |
blob_append(pHtml, "<dd>", 4); |
|
e58c76a…
|
drh
|
489 |
}else if( wantP ){ |
|
e58c76a…
|
drh
|
490 |
iLevel++; |
|
e58c76a…
|
drh
|
491 |
aIndent[iLevel] = nIndent; |
|
e58c76a…
|
drh
|
492 |
azEnd[iLevel] = zEndPRE; |
|
e58c76a…
|
drh
|
493 |
blob_append(pHtml, "<blockquote><pre>", -1); |
|
e58c76a…
|
drh
|
494 |
wantP = 0; |
|
e58c76a…
|
drh
|
495 |
} |
|
e58c76a…
|
drh
|
496 |
} |
|
e58c76a…
|
drh
|
497 |
if( isLI ){ |
|
e58c76a…
|
drh
|
498 |
blob_append(pHtml, "<li> ", 5); |
|
e58c76a…
|
drh
|
499 |
} |
|
e58c76a…
|
drh
|
500 |
if( wantP ){ |
|
689b7f6…
|
stephan
|
501 |
blob_append(pHtml, "<p> ", 4); |
|
e58c76a…
|
drh
|
502 |
wantP = 0; |
|
e58c76a…
|
drh
|
503 |
} |
|
e58c76a…
|
drh
|
504 |
if( azEnd[iLevel]==zEndDL ){ |
|
e58c76a…
|
drh
|
505 |
int iDD; |
|
e58c76a…
|
drh
|
506 |
blob_append(pHtml, "<dt> ", 5); |
|
e58c76a…
|
drh
|
507 |
iDD = hasGap(zHelp+nIndent, i-nIndent); |
|
e58c76a…
|
drh
|
508 |
if( iDD ){ |
|
e58c76a…
|
drh
|
509 |
int x; |
|
e58c76a…
|
drh
|
510 |
assert( iLevel<ArraySize(aIndent)-1 ); |
|
e58c76a…
|
drh
|
511 |
iLevel++; |
|
e58c76a…
|
drh
|
512 |
aIndent[iLevel] = x = nIndent+iDD; |
|
e58c76a…
|
drh
|
513 |
azEnd[iLevel] = zEndDD; |
|
e58c76a…
|
drh
|
514 |
appendMixedFont(pHtml, zHelp+nIndent, iDD-2); |
|
517223e…
|
drh
|
515 |
blob_append(pHtml, "</dt><dd>",9); |
|
517223e…
|
drh
|
516 |
appendLinked(pHtml, zHelp+x, i-x); |
|
e58c76a…
|
drh
|
517 |
}else{ |
|
e58c76a…
|
drh
|
518 |
appendMixedFont(pHtml, zHelp+nIndent, i-nIndent); |
|
e58c76a…
|
drh
|
519 |
} |
|
517223e…
|
drh
|
520 |
blob_append(pHtml, "</dt>\n", 6); |
|
e58c76a…
|
drh
|
521 |
}else if( wantBR ){ |
|
e58c76a…
|
drh
|
522 |
appendMixedFont(pHtml, zHelp+nIndent, i-nIndent); |
|
e58c76a…
|
drh
|
523 |
blob_append(pHtml, "<br>\n", 5); |
|
e58c76a…
|
drh
|
524 |
wantBR = 0; |
|
e58c76a…
|
drh
|
525 |
}else{ |
|
71992d0…
|
drh
|
526 |
appendLinked(pHtml, zHelp+nIndent, i-nIndent); |
|
71992d0…
|
drh
|
527 |
blob_append_char(pHtml, '\n'); |
|
e58c76a…
|
drh
|
528 |
} |
|
e58c76a…
|
drh
|
529 |
zHelp += i+1; |
|
e58c76a…
|
drh
|
530 |
i = 0; |
|
e58c76a…
|
drh
|
531 |
if( c==0 ) break; |
|
e58c76a…
|
drh
|
532 |
} |
|
e58c76a…
|
drh
|
533 |
while( iLevel>0 ){ |
|
e58c76a…
|
drh
|
534 |
blob_appendf(pHtml, "%s\n", azEnd[iLevel--]); |
|
e58c76a…
|
drh
|
535 |
} |
|
e58c76a…
|
drh
|
536 |
} |
|
e58c76a…
|
drh
|
537 |
|
|
e58c76a…
|
drh
|
538 |
/* |
|
e58c76a…
|
drh
|
539 |
** Format help text for TTY display. |
|
e58c76a…
|
drh
|
540 |
*/ |
|
62cb8ea…
|
drh
|
541 |
static void help_to_text(const char *zHelp, Blob *pText, int bUsage){ |
|
71992d0…
|
drh
|
542 |
int i, x; |
|
e58c76a…
|
drh
|
543 |
char c; |
|
b097e68…
|
drh
|
544 |
if( zHelp[0]=='>' ){ |
|
b097e68…
|
drh
|
545 |
if( !bUsage ){ |
|
b097e68…
|
drh
|
546 |
blob_appendf(pText, "Usage:"); |
|
b097e68…
|
drh
|
547 |
}else{ |
|
b097e68…
|
drh
|
548 |
blob_append_char(pText, ' '); |
|
b097e68…
|
drh
|
549 |
} |
|
baeffb9…
|
drh
|
550 |
zHelp++; |
|
baeffb9…
|
drh
|
551 |
} |
|
e58c76a…
|
drh
|
552 |
for(i=0; (c = zHelp[i])!=0; i++){ |
|
e58c76a…
|
drh
|
553 |
if( c=='%' && strncmp(zHelp+i,"%fossil",7)==0 ){ |
|
e58c76a…
|
drh
|
554 |
if( i>0 ) blob_append(pText, zHelp, i); |
|
e58c76a…
|
drh
|
555 |
blob_append(pText, "fossil", 6); |
|
e58c76a…
|
drh
|
556 |
zHelp += i+7; |
|
e58c76a…
|
drh
|
557 |
i = -1; |
|
e58c76a…
|
drh
|
558 |
continue; |
|
e58c76a…
|
drh
|
559 |
} |
|
e8ba89b…
|
drh
|
560 |
if( c=='\n' && (zHelp[i+1]=='>' || zHelp[i+1]=='|') && zHelp[i+2]==' ' ){ |
|
e58c76a…
|
drh
|
561 |
blob_append(pText, zHelp, i+1); |
|
e58c76a…
|
drh
|
562 |
blob_append(pText, " ", 1); |
|
e58c76a…
|
drh
|
563 |
zHelp += i+2; |
|
e58c76a…
|
drh
|
564 |
i = -1; |
|
e58c76a…
|
drh
|
565 |
continue; |
|
e58c76a…
|
drh
|
566 |
} |
|
71992d0…
|
drh
|
567 |
if( c=='[' && (x = help_is_link(zHelp+i, 100000))!=0 ){ |
|
71992d0…
|
drh
|
568 |
if( i>0 ) blob_append(pText, zHelp, i); |
|
71992d0…
|
drh
|
569 |
zHelp += i+2; |
|
71992d0…
|
drh
|
570 |
blob_append(pText, zHelp, x-3); |
|
71992d0…
|
drh
|
571 |
zHelp += x-1; |
|
71992d0…
|
drh
|
572 |
i = -1; |
|
71992d0…
|
drh
|
573 |
continue; |
|
275da70…
|
danield
|
574 |
} |
|
e58c76a…
|
drh
|
575 |
} |
|
e58c76a…
|
drh
|
576 |
if( i>0 ){ |
|
e58c76a…
|
drh
|
577 |
blob_append(pText, zHelp, i); |
|
275da70…
|
danield
|
578 |
} |
|
89e5ac1…
|
stephan
|
579 |
} |
|
89e5ac1…
|
stephan
|
580 |
|
|
89e5ac1…
|
stephan
|
581 |
/* |
|
89e5ac1…
|
stephan
|
582 |
** Display help for all commands based on provided flags. |
|
89e5ac1…
|
stephan
|
583 |
*/ |
|
89e5ac1…
|
stephan
|
584 |
static void display_all_help(int mask, int useHtml, int rawOut){ |
|
89e5ac1…
|
stephan
|
585 |
int i; |
|
db70849…
|
danield
|
586 |
unsigned char occHelp[FOSSIL_MX_CMDIDX] = {0}; /* Help string occurrences */ |
|
586967c…
|
mistachkin
|
587 |
int bktHelp[FOSSIL_MX_CMDIDX][MX_HELP_DUP] = {{0}};/* Help strings->commands*/ |
|
89e5ac1…
|
stephan
|
588 |
if( useHtml ) fossil_print("<!--\n"); |
|
89e5ac1…
|
stephan
|
589 |
fossil_print("Help text for:\n"); |
|
89e5ac1…
|
stephan
|
590 |
if( mask & CMDFLAG_1ST_TIER ) fossil_print(" * Commands\n"); |
|
89e5ac1…
|
stephan
|
591 |
if( mask & CMDFLAG_2ND_TIER ) fossil_print(" * Auxiliary commands\n"); |
|
db70849…
|
danield
|
592 |
if( mask & CMDFLAG_ALIAS ) fossil_print(" * Aliases\n"); |
|
89e5ac1…
|
stephan
|
593 |
if( mask & CMDFLAG_TEST ) fossil_print(" * Test commands\n"); |
|
89e5ac1…
|
stephan
|
594 |
if( mask & CMDFLAG_WEBPAGE ) fossil_print(" * Web pages\n"); |
|
89e5ac1…
|
stephan
|
595 |
if( mask & CMDFLAG_SETTING ) fossil_print(" * Settings\n"); |
|
6eeb27a…
|
drh
|
596 |
if( mask & CMDFLAG_TOPIC ) fossil_print(" * Help Topic\n"); |
|
89e5ac1…
|
stephan
|
597 |
if( useHtml ){ |
|
89e5ac1…
|
stephan
|
598 |
fossil_print("-->\n"); |
|
89e5ac1…
|
stephan
|
599 |
fossil_print("<!-- start_all_help -->\n"); |
|
89e5ac1…
|
stephan
|
600 |
}else{ |
|
89e5ac1…
|
stephan
|
601 |
fossil_print("---\n"); |
|
89e5ac1…
|
stephan
|
602 |
} |
|
db70849…
|
danield
|
603 |
/* Fill in help string buckets */ |
|
db70849…
|
danield
|
604 |
for(i=0; i<MX_COMMAND; i++){ |
|
db70849…
|
danield
|
605 |
if( (aCommand[i].eCmdFlags & mask)==0 ) continue; |
|
db70849…
|
danield
|
606 |
else if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue; |
|
db70849…
|
danield
|
607 |
bktHelp[aCommand[i].iHelp][occHelp[aCommand[i].iHelp]++] = i; |
|
db70849…
|
danield
|
608 |
} |
|
89e5ac1…
|
stephan
|
609 |
for(i=0; i<MX_COMMAND; i++){ |
|
89e5ac1…
|
stephan
|
610 |
if( (aCommand[i].eCmdFlags & mask)==0 ) continue; |
|
701c6dc…
|
stephan
|
611 |
else if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue; |
|
db70849…
|
danield
|
612 |
if( occHelp[aCommand[i].iHelp] > 0 ){ |
|
db70849…
|
danield
|
613 |
int j; |
|
db70849…
|
danield
|
614 |
if( useHtml ){ |
|
db70849…
|
danield
|
615 |
Blob html; |
|
db70849…
|
danield
|
616 |
blob_init(&html, 0, 0); |
|
db70849…
|
danield
|
617 |
help_to_html(aCommand[i].zHelp, &html); |
|
db70849…
|
danield
|
618 |
for(j=0; j<occHelp[aCommand[i].iHelp]; j++){ |
|
db70849…
|
danield
|
619 |
fossil_print("<h1>%h</h1>\n", |
|
db70849…
|
danield
|
620 |
aCommand[bktHelp[aCommand[i].iHelp][j]].zName); |
|
db70849…
|
danield
|
621 |
} |
|
db70849…
|
danield
|
622 |
fossil_print("%s\n<hr>\n", blob_str(&html)); |
|
db70849…
|
danield
|
623 |
blob_reset(&html); |
|
db70849…
|
danield
|
624 |
}else if( rawOut ){ |
|
db70849…
|
danield
|
625 |
for(j=0; j<occHelp[aCommand[i].iHelp]; j++) |
|
db70849…
|
danield
|
626 |
fossil_print("# %s\n", aCommand[bktHelp[aCommand[i].iHelp][j]].zName); |
|
db70849…
|
danield
|
627 |
fossil_print("%s\n\n", aCommand[i].zHelp); |
|
db70849…
|
danield
|
628 |
}else{ |
|
db70849…
|
danield
|
629 |
Blob txt; |
|
db70849…
|
danield
|
630 |
blob_init(&txt, 0, 0); |
|
62cb8ea…
|
drh
|
631 |
help_to_text(aCommand[i].zHelp, &txt, 0); |
|
db70849…
|
danield
|
632 |
for(j=0; j<occHelp[aCommand[i].iHelp]; j++){ |
|
db70849…
|
danield
|
633 |
fossil_print("# %s%s\n", |
|
db70849…
|
danield
|
634 |
aCommand[bktHelp[aCommand[i].iHelp][j]].zName, |
|
db70849…
|
danield
|
635 |
(aCommand[i].eCmdFlags & CMDFLAG_VERSIONABLE)!=0 ? |
|
db70849…
|
danield
|
636 |
" (versionable)" : ""); |
|
db70849…
|
danield
|
637 |
} |
|
db70849…
|
danield
|
638 |
fossil_print("%s\n\n", blob_str(&txt)); |
|
db70849…
|
danield
|
639 |
blob_reset(&txt); |
|
db70849…
|
danield
|
640 |
} |
|
db70849…
|
danield
|
641 |
occHelp[aCommand[i].iHelp] = 0; |
|
89e5ac1…
|
stephan
|
642 |
} |
|
89e5ac1…
|
stephan
|
643 |
} |
|
89e5ac1…
|
stephan
|
644 |
if( useHtml ){ |
|
89e5ac1…
|
stephan
|
645 |
fossil_print("<!-- end_all_help -->\n"); |
|
89e5ac1…
|
stephan
|
646 |
}else{ |
|
89e5ac1…
|
stephan
|
647 |
fossil_print("---\n"); |
|
89e5ac1…
|
stephan
|
648 |
} |
|
89e5ac1…
|
stephan
|
649 |
version_cmd(); |
|
1763f28…
|
mistachkin
|
650 |
} |
|
e6aab1a…
|
drh
|
651 |
|
|
e6aab1a…
|
drh
|
652 |
/* |
|
e6aab1a…
|
drh
|
653 |
** COMMAND: test-all-help |
|
e6aab1a…
|
drh
|
654 |
** |
|
e6aab1a…
|
drh
|
655 |
** Usage: %fossil test-all-help ?OPTIONS? |
|
e6aab1a…
|
drh
|
656 |
** |
|
e6aab1a…
|
drh
|
657 |
** Show help text for commands and pages. Useful for proof-reading. |
|
e6aab1a…
|
drh
|
658 |
** Defaults to just the CLI commands. Specify --www to see only the |
|
e6aab1a…
|
drh
|
659 |
** web pages, or --everything to see both commands and pages. |
|
e6aab1a…
|
drh
|
660 |
** |
|
e6aab1a…
|
drh
|
661 |
** Options: |
|
2512d2d…
|
km
|
662 |
** -a|--aliases Show aliases |
|
6eeb27a…
|
drh
|
663 |
** -c|--topics Show help topics |
|
275da70…
|
danield
|
664 |
** -e|--everything Show all commands and pages. Omit aliases to |
|
db70849…
|
danield
|
665 |
** avoid duplicates. |
|
2512d2d…
|
km
|
666 |
** -h|--html Transform output to HTML |
|
2512d2d…
|
km
|
667 |
** -o|--options Show global options |
|
2512d2d…
|
km
|
668 |
** -r|--raw No output formatting |
|
2512d2d…
|
km
|
669 |
** -s|--settings Show settings |
|
2512d2d…
|
km
|
670 |
** -t|--test Include test- commands |
|
2512d2d…
|
km
|
671 |
** -w|--www Show WWW pages |
|
e6aab1a…
|
drh
|
672 |
*/ |
|
e6aab1a…
|
drh
|
673 |
void test_all_help_cmd(void){ |
|
e6aab1a…
|
drh
|
674 |
int mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER; |
|
1763f28…
|
mistachkin
|
675 |
int useHtml = find_option("html","h",0)!=0; |
|
71992d0…
|
drh
|
676 |
int rawOut = find_option("raw","r",0)!=0; |
|
e6aab1a…
|
drh
|
677 |
|
|
e6aab1a…
|
drh
|
678 |
if( find_option("www","w",0) ){ |
|
e6aab1a…
|
drh
|
679 |
mask = CMDFLAG_WEBPAGE; |
|
e6aab1a…
|
drh
|
680 |
} |
|
e6aab1a…
|
drh
|
681 |
if( find_option("everything","e",0) ){ |
|
cb3a890…
|
drh
|
682 |
mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE | |
|
6eeb27a…
|
drh
|
683 |
CMDFLAG_ALIAS | CMDFLAG_SETTING | CMDFLAG_TEST | CMDFLAG_TOPIC; |
|
f74f701…
|
drh
|
684 |
} |
|
f74f701…
|
drh
|
685 |
if( find_option("settings","s",0) ){ |
|
f74f701…
|
drh
|
686 |
mask = CMDFLAG_SETTING; |
|
f74f701…
|
drh
|
687 |
} |
|
db70849…
|
danield
|
688 |
if( find_option("aliases","a",0) ){ |
|
db70849…
|
danield
|
689 |
mask = CMDFLAG_ALIAS; |
|
275da70…
|
danield
|
690 |
} |
|
e6aab1a…
|
drh
|
691 |
if( find_option("test","t",0) ){ |
|
e6aab1a…
|
drh
|
692 |
mask |= CMDFLAG_TEST; |
|
6eeb27a…
|
drh
|
693 |
} |
|
6eeb27a…
|
drh
|
694 |
if( find_option("topics","c",0) ){ |
|
6eeb27a…
|
drh
|
695 |
mask |= CMDFLAG_TOPIC; |
|
89e5ac1…
|
stephan
|
696 |
} |
|
89e5ac1…
|
stephan
|
697 |
display_all_help(mask, useHtml, rawOut); |
|
c7bb647…
|
drh
|
698 |
} |
|
c7bb647…
|
drh
|
699 |
|
|
c7bb647…
|
drh
|
700 |
/* |
|
c7bb647…
|
drh
|
701 |
** Count the number of entries in the aCommand[] table that match |
|
c7bb647…
|
drh
|
702 |
** the given flag. |
|
c7bb647…
|
drh
|
703 |
*/ |
|
c7bb647…
|
drh
|
704 |
static int countCmds(unsigned int eFlg){ |
|
c7bb647…
|
drh
|
705 |
int n = 0; |
|
c7bb647…
|
drh
|
706 |
int i; |
|
e6aab1a…
|
drh
|
707 |
for(i=0; i<MX_COMMAND; i++){ |
|
c7bb647…
|
drh
|
708 |
if( (aCommand[i].eCmdFlags & eFlg)!=0 ) n++; |
|
c7bb647…
|
drh
|
709 |
} |
|
c7bb647…
|
drh
|
710 |
return n; |
|
c7bb647…
|
drh
|
711 |
} |
|
c7bb647…
|
drh
|
712 |
|
|
c7bb647…
|
drh
|
713 |
/* |
|
c7bb647…
|
drh
|
714 |
** COMMAND: test-command-stats |
|
c7bb647…
|
drh
|
715 |
** |
|
c7bb647…
|
drh
|
716 |
** Print statistics about the built-in command dispatch table. |
|
c7bb647…
|
drh
|
717 |
*/ |
|
c7bb647…
|
drh
|
718 |
void test_command_stats_cmd(void){ |
|
c7bb647…
|
drh
|
719 |
fossil_print("commands: %4d\n", |
|
c7bb647…
|
drh
|
720 |
countCmds( CMDFLAG_COMMAND )); |
|
c7bb647…
|
drh
|
721 |
fossil_print(" 1st tier %4d\n", |
|
c7bb647…
|
drh
|
722 |
countCmds( CMDFLAG_1ST_TIER )); |
|
c7bb647…
|
drh
|
723 |
fossil_print(" 2nd tier %4d\n", |
|
c7bb647…
|
drh
|
724 |
countCmds( CMDFLAG_2ND_TIER )); |
|
db70849…
|
danield
|
725 |
fossil_print(" alias %4d\n", |
|
db70849…
|
danield
|
726 |
countCmds( CMDFLAG_ALIAS )); |
|
c7bb647…
|
drh
|
727 |
fossil_print(" test %4d\n", |
|
c7bb647…
|
drh
|
728 |
countCmds( CMDFLAG_TEST )); |
|
c7bb647…
|
drh
|
729 |
fossil_print("web-pages: %4d\n", |
|
c7bb647…
|
drh
|
730 |
countCmds( CMDFLAG_WEBPAGE )); |
|
c7bb647…
|
drh
|
731 |
fossil_print("settings: %4d\n", |
|
c7bb647…
|
drh
|
732 |
countCmds( CMDFLAG_SETTING )); |
|
6eeb27a…
|
drh
|
733 |
fossil_print("help-topics: %4d\n", |
|
6eeb27a…
|
drh
|
734 |
countCmds( CMDFLAG_TOPIC )); |
|
c7bb647…
|
drh
|
735 |
fossil_print("total entries: %4d\n", MX_COMMAND); |
|
c7bb647…
|
drh
|
736 |
} |
|
c7bb647…
|
drh
|
737 |
|
|
c7bb647…
|
drh
|
738 |
/* |
|
a99d917…
|
drh
|
739 |
** Compute an estimate of the edit-distance between to input strings. |
|
a99d917…
|
drh
|
740 |
** |
|
a99d917…
|
drh
|
741 |
** The first string is the input. The second is the pattern. Only the |
|
a99d917…
|
drh
|
742 |
** first 100 characters of the pattern are considered. |
|
a99d917…
|
drh
|
743 |
*/ |
|
a99d917…
|
drh
|
744 |
static int edit_distance(const char *zA, const char *zB){ |
|
a99d917…
|
drh
|
745 |
int nA = (int)strlen(zA); |
|
a99d917…
|
drh
|
746 |
int nB = (int)strlen(zB); |
|
a99d917…
|
drh
|
747 |
int i, j, m; |
|
a99d917…
|
drh
|
748 |
int p0, p1, c0; |
|
3783a24…
|
stephan
|
749 |
int a[100] = {0}; |
|
a99d917…
|
drh
|
750 |
static const int incr = 4; |
|
a99d917…
|
drh
|
751 |
|
|
a99d917…
|
drh
|
752 |
for(j=0; j<nB; j++) a[j] = 1; |
|
a99d917…
|
drh
|
753 |
for(i=0; i<nA; i++){ |
|
a99d917…
|
drh
|
754 |
p0 = i==0 ? 0 : i*incr-1; |
|
a99d917…
|
drh
|
755 |
c0 = i*incr; |
|
a99d917…
|
drh
|
756 |
for(j=0; j<nB; j++){ |
|
a99d917…
|
drh
|
757 |
int m = 999; |
|
a99d917…
|
drh
|
758 |
p1 = a[j]; |
|
a99d917…
|
drh
|
759 |
if( zA[i]==zB[j] ){ |
|
a99d917…
|
drh
|
760 |
m = p0; |
|
a99d917…
|
drh
|
761 |
}else{ |
|
a99d917…
|
drh
|
762 |
m = c0+2; |
|
a99d917…
|
drh
|
763 |
if( m>p1+2 ) m = p1+2; |
|
a99d917…
|
drh
|
764 |
if( m>p0+3 ) m = p0+3; |
|
a99d917…
|
drh
|
765 |
} |
|
a99d917…
|
drh
|
766 |
c0 = a[j]; |
|
a99d917…
|
drh
|
767 |
a[j] = m; |
|
a99d917…
|
drh
|
768 |
p0 = p1; |
|
a99d917…
|
drh
|
769 |
} |
|
a99d917…
|
drh
|
770 |
} |
|
a99d917…
|
drh
|
771 |
m = a[nB-1]; |
|
a99d917…
|
drh
|
772 |
for(j=0; j<nB-1; j++){ |
|
a99d917…
|
drh
|
773 |
if( a[j]+1<m ) m = a[j]+1; |
|
a99d917…
|
drh
|
774 |
} |
|
a99d917…
|
drh
|
775 |
return m; |
|
a99d917…
|
drh
|
776 |
} |
|
a99d917…
|
drh
|
777 |
|
|
a99d917…
|
drh
|
778 |
/* |
|
a99d917…
|
drh
|
779 |
** Fill the pointer array with names of commands that approximately |
|
a99d917…
|
drh
|
780 |
** match the input. Return the number of approximate matches. |
|
a99d917…
|
drh
|
781 |
** |
|
a99d917…
|
drh
|
782 |
** Closest matches appear first. |
|
a99d917…
|
drh
|
783 |
*/ |
|
a99d917…
|
drh
|
784 |
int dispatch_approx_match(const char *zIn, int nArray, const char **azArray){ |
|
a99d917…
|
drh
|
785 |
int i; |
|
a99d917…
|
drh
|
786 |
int bestScore; |
|
a99d917…
|
drh
|
787 |
int m; |
|
a99d917…
|
drh
|
788 |
int n = 0; |
|
a99d917…
|
drh
|
789 |
int mnScore = 0; |
|
a99d917…
|
drh
|
790 |
int mxScore = 99999; |
|
a99d917…
|
drh
|
791 |
int iFirst, iLast; |
|
a99d917…
|
drh
|
792 |
|
|
a99d917…
|
drh
|
793 |
if( zIn[0]=='/' ){ |
|
a99d917…
|
drh
|
794 |
iFirst = 0; |
|
a99d917…
|
drh
|
795 |
iLast = FOSSIL_FIRST_CMD-1; |
|
a99d917…
|
drh
|
796 |
}else{ |
|
a99d917…
|
drh
|
797 |
iFirst = FOSSIL_FIRST_CMD; |
|
a99d917…
|
drh
|
798 |
iLast = MX_COMMAND-1; |
|
a99d917…
|
drh
|
799 |
} |
|
a99d917…
|
drh
|
800 |
|
|
a99d917…
|
drh
|
801 |
while( n<nArray ){ |
|
275da70…
|
danield
|
802 |
bestScore = mxScore; |
|
a99d917…
|
drh
|
803 |
for(i=iFirst; i<=iLast; i++){ |
|
a99d917…
|
drh
|
804 |
m = edit_distance(zIn, aCommand[i].zName); |
|
a99d917…
|
drh
|
805 |
if( m<mnScore ) continue; |
|
a99d917…
|
drh
|
806 |
if( m==mnScore ){ |
|
a99d917…
|
drh
|
807 |
azArray[n++] = aCommand[i].zName; |
|
a99d917…
|
drh
|
808 |
if( n>=nArray ) return n; |
|
a99d917…
|
drh
|
809 |
}else if( m<bestScore ){ |
|
a99d917…
|
drh
|
810 |
bestScore = m; |
|
a99d917…
|
drh
|
811 |
} |
|
a99d917…
|
drh
|
812 |
} |
|
a99d917…
|
drh
|
813 |
if( bestScore>=mxScore ) break; |
|
a99d917…
|
drh
|
814 |
mnScore = bestScore; |
|
a99d917…
|
drh
|
815 |
} |
|
a99d917…
|
drh
|
816 |
return n; |
|
a99d917…
|
drh
|
817 |
} |
|
a99d917…
|
drh
|
818 |
|
|
a99d917…
|
drh
|
819 |
/* |
|
a99d917…
|
drh
|
820 |
** COMMAND: test-approx-match |
|
a99d917…
|
drh
|
821 |
** |
|
a99d917…
|
drh
|
822 |
** Test the approximate match algorithm |
|
a99d917…
|
drh
|
823 |
*/ |
|
a99d917…
|
drh
|
824 |
void test_approx_match_command(void){ |
|
a99d917…
|
drh
|
825 |
int i, j, n; |
|
a99d917…
|
drh
|
826 |
const char *az[20]; |
|
a99d917…
|
drh
|
827 |
for(i=2; i<g.argc; i++){ |
|
a99d917…
|
drh
|
828 |
fossil_print("%s:\n", g.argv[i]); |
|
a99d917…
|
drh
|
829 |
n = dispatch_approx_match(g.argv[i], 20, az); |
|
a99d917…
|
drh
|
830 |
for(j=0; j<n; j++){ |
|
a99d917…
|
drh
|
831 |
fossil_print(" %s\n", az[j]); |
|
a99d917…
|
drh
|
832 |
} |
|
a99d917…
|
drh
|
833 |
} |
|
a99d917…
|
drh
|
834 |
} |
|
a99d917…
|
drh
|
835 |
|
|
e5ace41…
|
stephan
|
836 |
|
|
e5ace41…
|
stephan
|
837 |
/* |
|
e5ace41…
|
stephan
|
838 |
** Returns 1 if the command or page name zName is known to be a |
|
e5ace41…
|
stephan
|
839 |
** command/page which is only available in certain builds/platforms, |
|
e5ace41…
|
stephan
|
840 |
** else returns 0. |
|
e5ace41…
|
stephan
|
841 |
*/ |
|
e5ace41…
|
stephan
|
842 |
static int help_is_platform_command(const char *zName){ |
|
e5ace41…
|
stephan
|
843 |
const char *aList[] = { |
|
e5ace41…
|
stephan
|
844 |
/* List of commands/pages which are known to only be available in |
|
e5ace41…
|
stephan
|
845 |
** certain builds/platforms. */ |
|
e5ace41…
|
stephan
|
846 |
"winsrv", |
|
e5ace41…
|
stephan
|
847 |
"json", "/json", |
|
e5ace41…
|
stephan
|
848 |
NULL /* end-of-list sentinel */ |
|
e5ace41…
|
stephan
|
849 |
}; |
|
e5ace41…
|
stephan
|
850 |
int i = 0; |
|
e5ace41…
|
stephan
|
851 |
const char *z; |
|
e5ace41…
|
stephan
|
852 |
for( z = aList[0]; z ; z = aList[++i] ){ |
|
e5ace41…
|
stephan
|
853 |
if( 0==fossil_strcmp(zName, z) ) return 1; |
|
e5ace41…
|
stephan
|
854 |
} |
|
e5ace41…
|
stephan
|
855 |
return 0; |
|
e5ace41…
|
stephan
|
856 |
} |
|
e5ace41…
|
stephan
|
857 |
|
|
a99d917…
|
drh
|
858 |
/* |
|
e6aab1a…
|
drh
|
859 |
** WEBPAGE: help |
|
c64f28d…
|
drh
|
860 |
** URL: /help/CMD or /help/www/PAGE |
|
8530666…
|
drh
|
861 |
** |
|
c64f28d…
|
drh
|
862 |
** Show the built-in help text for CMD or PAGE. CMD can be a command-line |
|
c64f28d…
|
drh
|
863 |
** interface command or a setting name. PAGE is the name of a |
|
c64f28d…
|
drh
|
864 |
** web interface. /help//PAGE also works if the double-/ makes it through |
|
c64f28d…
|
drh
|
865 |
** the main web server. |
|
c64f28d…
|
drh
|
866 |
** |
|
8530666…
|
drh
|
867 |
** Query parameters: |
|
8530666…
|
drh
|
868 |
** |
|
8530666…
|
drh
|
869 |
** name=CMD Show help for CMD where CMD is a command name or |
|
c64f28d…
|
drh
|
870 |
** or setting name. If CMD beings with "/" it is |
|
c64f28d…
|
drh
|
871 |
** interpreted as a PAGE name. |
|
c64f28d…
|
drh
|
872 |
** |
|
c64f28d…
|
drh
|
873 |
** name=www/PAGE Show help for web page PAGE. |
|
c64f28d…
|
drh
|
874 |
** |
|
8af6864…
|
wyoung
|
875 |
** name=/PAGE The initial "www/" on web-page help can be abbreviated as |
|
c64f28d…
|
drh
|
876 |
** just "/" |
|
8530666…
|
drh
|
877 |
** |
|
8530666…
|
drh
|
878 |
** plaintext Show the help within <pre>...</pre>, as if it were |
|
8530666…
|
drh
|
879 |
** displayed using the "fossil help" command. |
|
e6aab1a…
|
drh
|
880 |
** |
|
8530666…
|
drh
|
881 |
** raw Show the raw help text without any formatting. |
|
8530666…
|
drh
|
882 |
** (Used for debugging.) |
|
e6aab1a…
|
drh
|
883 |
*/ |
|
e6aab1a…
|
drh
|
884 |
void help_page(void){ |
|
e6aab1a…
|
drh
|
885 |
const char *zCmd = P("cmd"); |
|
e6aab1a…
|
drh
|
886 |
|
|
e6aab1a…
|
drh
|
887 |
if( zCmd==0 ) zCmd = P("name"); |
|
57f1e87…
|
drh
|
888 |
cgi_check_for_malice(); |
|
e237cea…
|
andygoth
|
889 |
if( zCmd && *zCmd ){ |
|
e6aab1a…
|
drh
|
890 |
int rc; |
|
e6aab1a…
|
drh
|
891 |
const CmdOrPage *pCmd = 0; |
|
e6aab1a…
|
drh
|
892 |
|
|
57f1e87…
|
drh
|
893 |
style_set_current_feature("tkt"); |
|
e28cc73…
|
drh
|
894 |
style_submenu_element("Topic-List", "%R/help"); |
|
2e9e369…
|
drh
|
895 |
if( search_restrict(SRCH_HELP)!=0 ){ |
|
6d9f0f5…
|
drh
|
896 |
style_submenu_element("Search","%R/search?y=h"); |
|
6d9f0f5…
|
drh
|
897 |
} |
|
c64f28d…
|
drh
|
898 |
if( strncmp(zCmd,"www/",4)==0 && zCmd[4]!=0 ){ |
|
c64f28d…
|
drh
|
899 |
/* Use https://domain/fossil/help/www/timeline or similar with the "www" |
|
8af6864…
|
wyoung
|
900 |
** intermediate tag to view web-page documentation. */ |
|
c64f28d…
|
drh
|
901 |
zCmd += 3; |
|
c64f28d…
|
drh
|
902 |
} |
|
f2f419e…
|
drh
|
903 |
rc = dispatch_name_search(zCmd, CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd); |
|
e28cc73…
|
drh
|
904 |
if( pCmd ){ |
|
e28cc73…
|
drh
|
905 |
style_header("Help: %s", pCmd->zName); |
|
e28cc73…
|
drh
|
906 |
}else{ |
|
e28cc73…
|
drh
|
907 |
style_header("Help"); |
|
e28cc73…
|
drh
|
908 |
} |
|
e28cc73…
|
drh
|
909 |
if( pCmd==0 ){ |
|
e28cc73…
|
drh
|
910 |
/* No <h1> line in this case */ |
|
e28cc73…
|
drh
|
911 |
}else if( *zCmd=='/' ){ |
|
e6aab1a…
|
drh
|
912 |
/* Some of the webpages require query parameters in order to work. |
|
e6aab1a…
|
drh
|
913 |
** @ <h1>The "<a href='%R%s(zCmd)'>%s(zCmd)</a>" page:</h1> */ |
|
e28cc73…
|
drh
|
914 |
@ <h1>The "%h(pCmd->zName)" page:</h1> |
|
f74f701…
|
drh
|
915 |
}else if( rc==0 && (pCmd->eCmdFlags & CMDFLAG_SETTING)!=0 ){ |
|
f74f701…
|
drh
|
916 |
@ <h1>The "%h(pCmd->zName)" setting:</h1> |
|
6eeb27a…
|
drh
|
917 |
}else if( rc==0 && (pCmd->eCmdFlags & CMDFLAG_TOPIC)!=0 ){ |
|
6eeb27a…
|
drh
|
918 |
@ <h1>The "%h(pCmd->zName)" help topic:</h1> |
|
7a69e5d…
|
drh
|
919 |
}else{ |
|
e28cc73…
|
drh
|
920 |
@ <h1>The "%h(pCmd->zName)" command:</h1> |
|
7a69e5d…
|
drh
|
921 |
} |
|
e28cc73…
|
drh
|
922 |
if( rc==1 || (rc==2 && zCmd[0]=='/') ){ |
|
e5ace41…
|
stephan
|
923 |
if( zCmd && help_is_platform_command(zCmd) ){ |
|
e5ace41…
|
stephan
|
924 |
@ Not available in this build: "%h(zCmd)" |
|
e5ace41…
|
stephan
|
925 |
}else{ |
|
e5ace41…
|
stephan
|
926 |
@ Unknown topic: "%h(zCmd)" |
|
e5ace41…
|
stephan
|
927 |
} |
|
7a69e5d…
|
drh
|
928 |
}else if( rc==2 ){ |
|
e28cc73…
|
drh
|
929 |
@ Ambiguous prefix: "%h(zCmd)" |
|
7a69e5d…
|
drh
|
930 |
}else{ |
|
7a69e5d…
|
drh
|
931 |
if( pCmd->zHelp[0]==0 ){ |
|
f74f701…
|
drh
|
932 |
@ No help available for "%h(pCmd->zName)" |
|
8530666…
|
drh
|
933 |
}else if( P("plaintext") ){ |
|
8530666…
|
drh
|
934 |
Blob txt; |
|
8530666…
|
drh
|
935 |
blob_init(&txt, 0, 0); |
|
62cb8ea…
|
drh
|
936 |
help_to_text(pCmd->zHelp, &txt, 0); |
|
8530666…
|
drh
|
937 |
@ <pre class="helpPage"> |
|
8530666…
|
drh
|
938 |
@ %h(blob_str(&txt)) |
|
8530666…
|
drh
|
939 |
@ </pre> |
|
8530666…
|
drh
|
940 |
blob_reset(&txt); |
|
8530666…
|
drh
|
941 |
}else if( P("raw") ){ |
|
8530666…
|
drh
|
942 |
@ <pre class="helpPage"> |
|
8530666…
|
drh
|
943 |
@ %h(pCmd->zHelp) |
|
8530666…
|
drh
|
944 |
@ </pre> |
|
37e8c17…
|
andygoth
|
945 |
}else{ |
|
e58c76a…
|
drh
|
946 |
@ <div class="helpPage"> |
|
37e8c17…
|
andygoth
|
947 |
help_to_html(pCmd->zHelp, cgi_output_blob()); |
|
e58c76a…
|
drh
|
948 |
@ </div> |
|
37e8c17…
|
andygoth
|
949 |
} |
|
37e8c17…
|
andygoth
|
950 |
} |
|
37e8c17…
|
andygoth
|
951 |
}else{ |
|
1d495e8…
|
drh
|
952 |
int i; |
|
b919738…
|
drh
|
953 |
const char *zWidth = "28ex"; |
|
db70849…
|
danield
|
954 |
unsigned char occHelp[FOSSIL_MX_CMDIDX] = {0}; /* Help str occurrences */ |
|
586967c…
|
mistachkin
|
955 |
int bktHelp[FOSSIL_MX_CMDIDX][MX_HELP_DUP] = {{0}};/* Help str->commands */ |
|
37e8c17…
|
andygoth
|
956 |
style_header("Help"); |
|
6d9f0f5…
|
drh
|
957 |
search_screen(SRCH_HELP, 0x02); |
|
266a311…
|
drh
|
958 |
|
|
266a311…
|
drh
|
959 |
@ <a name='commands'></a> |
|
6eeb27a…
|
drh
|
960 |
@ <h1>Commands:</h1> |
|
b919738…
|
drh
|
961 |
@ <div class="columns" style="column-width: %s(zWidth);"> |
|
1d495e8…
|
drh
|
962 |
@ <ul> |
|
db70849…
|
danield
|
963 |
/* Fill in help string buckets */ |
|
db70849…
|
danield
|
964 |
for(i=0; i<MX_COMMAND; i++){ |
|
db70849…
|
danield
|
965 |
if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue; |
|
db70849…
|
danield
|
966 |
bktHelp[aCommand[i].iHelp][occHelp[aCommand[i].iHelp]++] = i; |
|
db70849…
|
danield
|
967 |
} |
|
1d495e8…
|
drh
|
968 |
for(i=0; i<MX_COMMAND; i++){ |
|
37e8c17…
|
andygoth
|
969 |
const char *z = aCommand[i].zName; |
|
37e8c17…
|
andygoth
|
970 |
const char *zBoldOn = aCommand[i].eCmdFlags&CMDFLAG_1ST_TIER?"<b>" :""; |
|
37e8c17…
|
andygoth
|
971 |
const char *zBoldOff = aCommand[i].eCmdFlags&CMDFLAG_1ST_TIER?"</b>":""; |
|
37e8c17…
|
andygoth
|
972 |
if( '/'==*z || strncmp(z,"test",4)==0 ) continue; |
|
6eeb27a…
|
drh
|
973 |
if( (aCommand[i].eCmdFlags & (CMDFLAG_SETTING|CMDFLAG_TOPIC))!=0 ){ |
|
6eeb27a…
|
drh
|
974 |
continue; |
|
6eeb27a…
|
drh
|
975 |
} |
|
701c6dc…
|
stephan
|
976 |
else if( (aCommand[i].eCmdFlags & CMDFLAG_HIDDEN)!=0 ) continue; |
|
db70849…
|
danield
|
977 |
else if( (aCommand[i].eCmdFlags & CMDFLAG_ALIAS)!=0 ) continue; |
|
c64f28d…
|
drh
|
978 |
@ <li><a href="%R/help/%s(z)">%s(zBoldOn)%s(z)%s(zBoldOff)</a> |
|
db70849…
|
danield
|
979 |
/* Output aliases */ |
|
db70849…
|
danield
|
980 |
if( occHelp[aCommand[i].iHelp] > 1 ){ |
|
db70849…
|
danield
|
981 |
int j; |
|
db70849…
|
danield
|
982 |
int aliases[MX_HELP_DUP], nAliases=0; |
|
db70849…
|
danield
|
983 |
for(j=0; j<occHelp[aCommand[i].iHelp]; j++){ |
|
db70849…
|
danield
|
984 |
if( bktHelp[aCommand[i].iHelp][j] != i ){ |
|
275da70…
|
danield
|
985 |
if( aCommand[bktHelp[aCommand[i].iHelp][j]].eCmdFlags |
|
275da70…
|
danield
|
986 |
& CMDFLAG_ALIAS ){ |
|
db70849…
|
danield
|
987 |
aliases[nAliases++] = bktHelp[aCommand[i].iHelp][j]; |
|
db70849…
|
danield
|
988 |
} |
|
db70849…
|
danield
|
989 |
} |
|
db70849…
|
danield
|
990 |
} |
|
db70849…
|
danield
|
991 |
if( nAliases>0 ){ |
|
db70849…
|
danield
|
992 |
int k; |
|
db70849…
|
danield
|
993 |
@(\ |
|
db70849…
|
danield
|
994 |
for(k=0; k<nAliases; k++){ |
|
c64f28d…
|
drh
|
995 |
@<a href="%R/help/%s(aCommand[aliases[k]].zName)">\ |
|
db70849…
|
danield
|
996 |
@%s(aCommand[aliases[k]].zName)</a>%s((k<nAliases-1)?", ":"")\ |
|
db70849…
|
danield
|
997 |
} |
|
db70849…
|
danield
|
998 |
@)\ |
|
db70849…
|
danield
|
999 |
} |
|
db70849…
|
danield
|
1000 |
} |
|
db70849…
|
danield
|
1001 |
@ </li> |
|
1d495e8…
|
drh
|
1002 |
} |
|
db70849…
|
danield
|
1003 |
|
|
1f4a9eb…
|
wyoung
|
1004 |
@ </ul></div> |
|
266a311…
|
drh
|
1005 |
|
|
266a311…
|
drh
|
1006 |
@ <a name='webpages'></a> |
|
6eeb27a…
|
drh
|
1007 |
@ <h1>Web pages:</h1> |
|
b919738…
|
drh
|
1008 |
@ <div class="columns" style="column-width: %s(zWidth);"> |
|
1d495e8…
|
drh
|
1009 |
@ <ul> |
|
1d495e8…
|
drh
|
1010 |
for(i=0; i<MX_COMMAND; i++){ |
|
1d495e8…
|
drh
|
1011 |
const char *z = aCommand[i].zName; |
|
1d495e8…
|
drh
|
1012 |
if( '/'!=*z ) continue; |
|
701c6dc…
|
stephan
|
1013 |
else if( (aCommand[i].eCmdFlags & CMDFLAG_HIDDEN)!=0 ) continue; |
|
1d495e8…
|
drh
|
1014 |
if( aCommand[i].zHelp[0] ){ |
|
c64f28d…
|
drh
|
1015 |
@ <li><a href="%R/help/www%s(z)">%s(z+1)</a></li> |
|
e6aab1a…
|
drh
|
1016 |
}else{ |
|
e6aab1a…
|
drh
|
1017 |
@ <li>%s(z+1)</li> |
|
e6aab1a…
|
drh
|
1018 |
} |
|
1d495e8…
|
drh
|
1019 |
} |
|
1d495e8…
|
drh
|
1020 |
@ </ul></div> |
|
1d495e8…
|
drh
|
1021 |
|
|
6eeb27a…
|
drh
|
1022 |
@ <a name='settings'></a> |
|
6eeb27a…
|
drh
|
1023 |
@ <h1>Settings:</h1> |
|
b919738…
|
drh
|
1024 |
@ <div class="columns" style="column-width: %s(zWidth);"> |
|
b919738…
|
drh
|
1025 |
@ <ul> |
|
b919738…
|
drh
|
1026 |
for(i=0; i<MX_COMMAND; i++){ |
|
b919738…
|
drh
|
1027 |
const char *z = aCommand[i].zName; |
|
6eeb27a…
|
drh
|
1028 |
if( (aCommand[i].eCmdFlags & CMDFLAG_SETTING)==0 ) continue; |
|
b919738…
|
drh
|
1029 |
else if( (aCommand[i].eCmdFlags & CMDFLAG_HIDDEN)!=0 ) continue; |
|
b919738…
|
drh
|
1030 |
if( aCommand[i].zHelp[0] ){ |
|
c64f28d…
|
drh
|
1031 |
@ <li><a href="%R/help/%s(z)">%s(z)</a></li> |
|
c64f28d…
|
drh
|
1032 |
}else{ |
|
c64f28d…
|
drh
|
1033 |
@ <li>%s(z)</li> |
|
c64f28d…
|
drh
|
1034 |
} |
|
c64f28d…
|
drh
|
1035 |
} |
|
c64f28d…
|
drh
|
1036 |
@ </ul></div> |
|
c64f28d…
|
drh
|
1037 |
|
|
6eeb27a…
|
drh
|
1038 |
@ <a name='topics'></a> |
|
6eeb27a…
|
drh
|
1039 |
@ <h1>Other Miscellaneous Help Topics:</h1> |
|
6eeb27a…
|
drh
|
1040 |
@ <div class="columns" style="column-width: %s(zWidth);"> |
|
6eeb27a…
|
drh
|
1041 |
@ <ul> |
|
6eeb27a…
|
drh
|
1042 |
for(i=0; i<MX_COMMAND; i++){ |
|
6eeb27a…
|
drh
|
1043 |
const char *z = aCommand[i].zName; |
|
6eeb27a…
|
drh
|
1044 |
if( (aCommand[i].eCmdFlags & CMDFLAG_TOPIC)==0 ) continue; |
|
6eeb27a…
|
drh
|
1045 |
if( aCommand[i].zHelp[0] ){ |
|
6eeb27a…
|
drh
|
1046 |
@ <li><a href="%R/help/%s(z)">%s(z)</a></li> |
|
6eeb27a…
|
drh
|
1047 |
}else{ |
|
6eeb27a…
|
drh
|
1048 |
@ <li>%s(z)</li> |
|
6eeb27a…
|
drh
|
1049 |
} |
|
6eeb27a…
|
drh
|
1050 |
} |
|
6eeb27a…
|
drh
|
1051 |
@ </ul></div> |
|
6eeb27a…
|
drh
|
1052 |
|
|
6eeb27a…
|
drh
|
1053 |
@ <a name='unsupported'></a> |
|
6eeb27a…
|
drh
|
1054 |
@ <h1>Unsupported and Testing Commands:</h1> |
|
c64f28d…
|
drh
|
1055 |
@ <div class="columns" style="column-width: %s(zWidth);"> |
|
c64f28d…
|
drh
|
1056 |
@ <ul> |
|
c64f28d…
|
drh
|
1057 |
for(i=0; i<MX_COMMAND; i++){ |
|
c64f28d…
|
drh
|
1058 |
const char *z = aCommand[i].zName; |
|
6eeb27a…
|
drh
|
1059 |
if( strncmp(z,"test",4)!=0 ) continue; |
|
c64f28d…
|
drh
|
1060 |
else if( (aCommand[i].eCmdFlags & CMDFLAG_HIDDEN)!=0 ) continue; |
|
c64f28d…
|
drh
|
1061 |
if( aCommand[i].zHelp[0] ){ |
|
c64f28d…
|
drh
|
1062 |
@ <li><a href="%R/help/%s(z)">%s(z)</a></li> |
|
1d495e8…
|
drh
|
1063 |
}else{ |
|
1d495e8…
|
drh
|
1064 |
@ <li>%s(z)</li> |
|
1d495e8…
|
drh
|
1065 |
} |
|
1d495e8…
|
drh
|
1066 |
} |
|
1d495e8…
|
drh
|
1067 |
@ </ul></div> |
|
1d495e8…
|
drh
|
1068 |
|
|
1d495e8…
|
drh
|
1069 |
} |
|
112c713…
|
drh
|
1070 |
style_finish_page(); |
|
e6aab1a…
|
drh
|
1071 |
} |
|
e6aab1a…
|
drh
|
1072 |
|
|
e6aab1a…
|
drh
|
1073 |
/* |
|
e6aab1a…
|
drh
|
1074 |
** WEBPAGE: test-all-help |
|
e6aab1a…
|
drh
|
1075 |
** |
|
e6aab1a…
|
drh
|
1076 |
** Show all help text on a single page. Useful for proof-reading. |
|
e6aab1a…
|
drh
|
1077 |
*/ |
|
e6aab1a…
|
drh
|
1078 |
void test_all_help_page(void){ |
|
e6aab1a…
|
drh
|
1079 |
int i; |
|
db70849…
|
danield
|
1080 |
unsigned char occHelp[FOSSIL_MX_CMDIDX] = {0}; /* Help string occurrences */ |
|
586967c…
|
mistachkin
|
1081 |
int bktHelp[FOSSIL_MX_CMDIDX][MX_HELP_DUP] = {{0}};/* Help strings->commands*/ |
|
9e40834…
|
drh
|
1082 |
Blob buf; |
|
9e40834…
|
drh
|
1083 |
blob_init(&buf,0,0); |
|
112c713…
|
drh
|
1084 |
style_set_current_feature("test"); |
|
d8506df…
|
andygoth
|
1085 |
style_header("All Help Text"); |
|
9e40834…
|
drh
|
1086 |
@ <dl> |
|
db70849…
|
danield
|
1087 |
/* Fill in help string buckets */ |
|
db70849…
|
danield
|
1088 |
for(i=0; i<MX_COMMAND; i++){ |
|
db70849…
|
danield
|
1089 |
if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue; |
|
db70849…
|
danield
|
1090 |
bktHelp[aCommand[i].iHelp][occHelp[aCommand[i].iHelp]++] = i; |
|
275da70…
|
danield
|
1091 |
} |
|
e6aab1a…
|
drh
|
1092 |
for(i=0; i<MX_COMMAND; i++){ |
|
9e40834…
|
drh
|
1093 |
const char *zDesc; |
|
9e40834…
|
drh
|
1094 |
unsigned int e = aCommand[i].eCmdFlags; |
|
9e40834…
|
drh
|
1095 |
if( e & CMDFLAG_1ST_TIER ){ |
|
9e40834…
|
drh
|
1096 |
zDesc = "1st tier command"; |
|
9e40834…
|
drh
|
1097 |
}else if( e & CMDFLAG_2ND_TIER ){ |
|
9e40834…
|
drh
|
1098 |
zDesc = "2nd tier command"; |
|
db70849…
|
danield
|
1099 |
}else if( e & CMDFLAG_ALIAS ){ |
|
db70849…
|
danield
|
1100 |
zDesc = "alias"; |
|
9e40834…
|
drh
|
1101 |
}else if( e & CMDFLAG_TEST ){ |
|
9e40834…
|
drh
|
1102 |
zDesc = "test command"; |
|
6eeb27a…
|
drh
|
1103 |
}else if( e & CMDFLAG_TOPIC ){ |
|
6eeb27a…
|
drh
|
1104 |
zDesc = "help-topic"; |
|
9e40834…
|
drh
|
1105 |
}else if( e & CMDFLAG_WEBPAGE ){ |
|
9e40834…
|
drh
|
1106 |
if( e & CMDFLAG_RAWCONTENT ){ |
|
9e40834…
|
drh
|
1107 |
zDesc = "raw-content web page"; |
|
9e40834…
|
drh
|
1108 |
}else{ |
|
9e40834…
|
drh
|
1109 |
zDesc = "web page"; |
|
9e40834…
|
drh
|
1110 |
} |
|
9e40834…
|
drh
|
1111 |
}else{ |
|
9e40834…
|
drh
|
1112 |
blob_reset(&buf); |
|
9e40834…
|
drh
|
1113 |
if( e & CMDFLAG_VERSIONABLE ){ |
|
9e40834…
|
drh
|
1114 |
blob_appendf(&buf, "versionable "); |
|
9e40834…
|
drh
|
1115 |
} |
|
9e40834…
|
drh
|
1116 |
if( e & CMDFLAG_BLOCKTEXT ){ |
|
9e40834…
|
drh
|
1117 |
blob_appendf(&buf, "block-text "); |
|
9e40834…
|
drh
|
1118 |
} |
|
9e40834…
|
drh
|
1119 |
if( e & CMDFLAG_BOOLEAN ){ |
|
9e40834…
|
drh
|
1120 |
blob_appendf(&buf, "boolean "); |
|
9e40834…
|
drh
|
1121 |
} |
|
9e40834…
|
drh
|
1122 |
blob_appendf(&buf,"setting"); |
|
9e40834…
|
drh
|
1123 |
zDesc = blob_str(&buf); |
|
9e40834…
|
drh
|
1124 |
} |
|
e6aab1a…
|
drh
|
1125 |
if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue; |
|
db70849…
|
danield
|
1126 |
if( occHelp[aCommand[i].iHelp] > 0 ){ |
|
db70849…
|
danield
|
1127 |
int j; |
|
db70849…
|
danield
|
1128 |
for(j=0; j<occHelp[aCommand[i].iHelp]; j++){ |
|
db70849…
|
danield
|
1129 |
unsigned int e = aCommand[bktHelp[aCommand[i].iHelp][j]].eCmdFlags; |
|
db70849…
|
danield
|
1130 |
if( e & CMDFLAG_1ST_TIER ){ |
|
db70849…
|
danield
|
1131 |
zDesc = "1st tier command"; |
|
db70849…
|
danield
|
1132 |
}else if( e & CMDFLAG_2ND_TIER ){ |
|
db70849…
|
danield
|
1133 |
zDesc = "2nd tier command"; |
|
db70849…
|
danield
|
1134 |
}else if( e & CMDFLAG_ALIAS ){ |
|
db70849…
|
danield
|
1135 |
zDesc = "alias"; |
|
db70849…
|
danield
|
1136 |
}else if( e & CMDFLAG_TEST ){ |
|
db70849…
|
danield
|
1137 |
zDesc = "test command"; |
|
db70849…
|
danield
|
1138 |
}else if( e & CMDFLAG_WEBPAGE ){ |
|
db70849…
|
danield
|
1139 |
if( e & CMDFLAG_RAWCONTENT ){ |
|
db70849…
|
danield
|
1140 |
zDesc = "raw-content web page"; |
|
db70849…
|
danield
|
1141 |
}else{ |
|
db70849…
|
danield
|
1142 |
zDesc = "web page"; |
|
db70849…
|
danield
|
1143 |
} |
|
db70849…
|
danield
|
1144 |
} |
|
275da70…
|
danield
|
1145 |
|
|
db70849…
|
danield
|
1146 |
@ <dt><big><b>%s(aCommand[bktHelp[aCommand[i].iHelp][j]].zName)</b> |
|
db70849…
|
danield
|
1147 |
@</big> (%s(zDesc))</dt> |
|
db70849…
|
danield
|
1148 |
} |
|
ccc780f…
|
drh
|
1149 |
@ <p><dd> |
|
db70849…
|
danield
|
1150 |
help_to_html(aCommand[i].zHelp, cgi_output_blob()); |
|
ccc780f…
|
drh
|
1151 |
@ </dd><p> |
|
db70849…
|
danield
|
1152 |
occHelp[aCommand[i].iHelp] = 0; |
|
db70849…
|
danield
|
1153 |
} |
|
9e40834…
|
drh
|
1154 |
} |
|
9e40834…
|
drh
|
1155 |
@ </dl> |
|
9e40834…
|
drh
|
1156 |
blob_reset(&buf); |
|
112c713…
|
drh
|
1157 |
style_finish_page(); |
|
112c713…
|
drh
|
1158 |
} |
|
baeffb9…
|
drh
|
1159 |
|
|
baeffb9…
|
drh
|
1160 |
/* |
|
b097e68…
|
drh
|
1161 |
** Analyze p and return one of three values: |
|
b097e68…
|
drh
|
1162 |
** |
|
b097e68…
|
drh
|
1163 |
** 0 p is the continuation of a prior subcommand. |
|
b097e68…
|
drh
|
1164 |
** |
|
b097e68…
|
drh
|
1165 |
** 1 p is text past the end of a prior subcommand. |
|
b097e68…
|
drh
|
1166 |
** |
|
b097e68…
|
drh
|
1167 |
** 2 p is the start of a new subcommand. |
|
62cb8ea…
|
drh
|
1168 |
*/ |
|
b097e68…
|
drh
|
1169 |
static int is_subcommand(Blob *p, int bAbbrevSubcmd){ |
|
b097e68…
|
drh
|
1170 |
int i, sz; |
|
b097e68…
|
drh
|
1171 |
const unsigned char *z = (const unsigned char*)blob_buffer(p); |
|
b097e68…
|
drh
|
1172 |
sz = blob_size(p); |
|
b097e68…
|
drh
|
1173 |
if( sz>6 ) sz = 6; |
|
b097e68…
|
drh
|
1174 |
for(i=0; i<sz && fossil_isspace(z[i]); i++){} |
|
b097e68…
|
drh
|
1175 |
if( i>=sz ) return 0; |
|
b097e68…
|
drh
|
1176 |
|
|
b097e68…
|
drh
|
1177 |
if( bAbbrevSubcmd==0 ){ |
|
b097e68…
|
drh
|
1178 |
if( i>1 ) return 0; |
|
b097e68…
|
drh
|
1179 |
return z[0]=='>' ? 2 : 1; |
|
62cb8ea…
|
drh
|
1180 |
}else{ |
|
b097e68…
|
drh
|
1181 |
return (i==3 && fossil_isalpha(z[3])) ? 2 : 1; |
|
62cb8ea…
|
drh
|
1182 |
} |
|
62cb8ea…
|
drh
|
1183 |
} |
|
62cb8ea…
|
drh
|
1184 |
|
|
62cb8ea…
|
drh
|
1185 |
/* |
|
baeffb9…
|
drh
|
1186 |
** Input z[] is help text for zTopic. If zTopic has sub-command zSub, |
|
baeffb9…
|
drh
|
1187 |
** then cut out all portions of the original help text that do not |
|
baeffb9…
|
drh
|
1188 |
** directly pertain to zSub and write the zSub-relevant parts into |
|
baeffb9…
|
drh
|
1189 |
** pOut. |
|
baeffb9…
|
drh
|
1190 |
** |
|
baeffb9…
|
drh
|
1191 |
** Return the number of lines of z[] written into pOut. A return of |
|
baeffb9…
|
drh
|
1192 |
** zero means no simplification occurred. |
|
baeffb9…
|
drh
|
1193 |
*/ |
|
baeffb9…
|
drh
|
1194 |
static int simplify_to_subtopic( |
|
baeffb9…
|
drh
|
1195 |
const char *z, /* Full original help text */ |
|
baeffb9…
|
drh
|
1196 |
Blob *pOut, /* Write simplified help text here */ |
|
baeffb9…
|
drh
|
1197 |
const char *zTopic, /* TOPIC */ |
|
62cb8ea…
|
drh
|
1198 |
const char *zSubtopic, /* SUBTOPIC */ |
|
62cb8ea…
|
drh
|
1199 |
int bAbbrevSubcmd /* True if z[] contains abbreviated subcommands */ |
|
90e564f…
|
drh
|
1200 |
){ |
|
e2bdc10…
|
danield
|
1201 |
Blob in, line;/*, subsection;*/ |
|
90e564f…
|
drh
|
1202 |
int n = 0; |
|
90e564f…
|
drh
|
1203 |
char *zQTop = re_quote(zTopic); |
|
90e564f…
|
drh
|
1204 |
char *zQSub = re_quote(zSubtopic); |
|
62cb8ea…
|
drh
|
1205 |
char *zPattern; |
|
90e564f…
|
drh
|
1206 |
ReCompiled *pRe = 0; |
|
90e564f…
|
drh
|
1207 |
|
|
62cb8ea…
|
drh
|
1208 |
if( bAbbrevSubcmd ){ |
|
62cb8ea…
|
drh
|
1209 |
zPattern = mprintf(" ([a-z]+ ?\\| ?)*%s\\b", zQSub); |
|
62cb8ea…
|
drh
|
1210 |
}else{ |
|
b097e68…
|
drh
|
1211 |
zPattern = mprintf("> ?fossil [-a-z]+ .*\\b%s\\b", zQSub); |
|
62cb8ea…
|
drh
|
1212 |
} |
|
90e564f…
|
drh
|
1213 |
fossil_free(zQTop); |
|
90e564f…
|
drh
|
1214 |
fossil_free(zQSub); |
|
82888a0…
|
drh
|
1215 |
fossil_re_compile(&pRe, zPattern, 0); |
|
90e564f…
|
drh
|
1216 |
fossil_free(zPattern); |
|
90e564f…
|
drh
|
1217 |
blob_init(&in, z, -1); |
|
90e564f…
|
drh
|
1218 |
while( blob_line(&in, &line) ){ |
|
b097e68…
|
drh
|
1219 |
if( re_match(pRe, (unsigned char*)blob_buffer(&line), blob_size(&line)) ){ |
|
b097e68…
|
drh
|
1220 |
int atStart = 1; |
|
90e564f…
|
drh
|
1221 |
blob_appendb(pOut, &line); |
|
90e564f…
|
drh
|
1222 |
n++; |
|
b097e68…
|
drh
|
1223 |
while( blob_line(&in, &line) ){ |
|
b097e68…
|
drh
|
1224 |
if( re_match(pRe,(unsigned char*)blob_buffer(&line),blob_size(&line)) ){ |
|
b097e68…
|
drh
|
1225 |
blob_appendb(pOut, &line); |
|
b097e68…
|
drh
|
1226 |
n++; |
|
b097e68…
|
drh
|
1227 |
atStart = 1; |
|
b097e68…
|
drh
|
1228 |
}else{ |
|
b097e68…
|
drh
|
1229 |
int x = is_subcommand(&line,bAbbrevSubcmd); |
|
b097e68…
|
drh
|
1230 |
if( x==2 ){ |
|
b097e68…
|
drh
|
1231 |
if( atStart ){ |
|
b097e68…
|
drh
|
1232 |
blob_appendb(pOut, &line); |
|
b097e68…
|
drh
|
1233 |
n++; |
|
b097e68…
|
drh
|
1234 |
}else{ |
|
b097e68…
|
drh
|
1235 |
break; |
|
b097e68…
|
drh
|
1236 |
} |
|
b097e68…
|
drh
|
1237 |
}else if( x==1 ){ |
|
b097e68…
|
drh
|
1238 |
break; |
|
b097e68…
|
drh
|
1239 |
}else{ |
|
b097e68…
|
drh
|
1240 |
blob_appendb(pOut, &line); |
|
b097e68…
|
drh
|
1241 |
n++; |
|
b097e68…
|
drh
|
1242 |
atStart = 0; |
|
b097e68…
|
drh
|
1243 |
} |
|
b097e68…
|
drh
|
1244 |
} |
|
90e564f…
|
drh
|
1245 |
} |
|
90e564f…
|
drh
|
1246 |
} |
|
90e564f…
|
drh
|
1247 |
} |
|
90e564f…
|
drh
|
1248 |
blob_reset(&line); |
|
90e564f…
|
drh
|
1249 |
re_free(pRe); |
|
90e564f…
|
drh
|
1250 |
if( n ){ |
|
90e564f…
|
drh
|
1251 |
blob_trim(pOut); |
|
90e564f…
|
drh
|
1252 |
blob_reset(&in); |
|
aff179d…
|
drh
|
1253 |
} |
|
aff179d…
|
drh
|
1254 |
return n; |
|
62cb8ea…
|
drh
|
1255 |
} |
|
62cb8ea…
|
drh
|
1256 |
|
|
62cb8ea…
|
drh
|
1257 |
/* |
|
62cb8ea…
|
drh
|
1258 |
** Input p is a "Usage:" line or a subcommand line. Simplify this line |
|
62cb8ea…
|
drh
|
1259 |
** for the --usage option and write it into pOut. |
|
62cb8ea…
|
drh
|
1260 |
*/ |
|
62cb8ea…
|
drh
|
1261 |
static void simplify_usage_line( |
|
62cb8ea…
|
drh
|
1262 |
Blob *p, |
|
62cb8ea…
|
drh
|
1263 |
Blob *pOut, |
|
62cb8ea…
|
drh
|
1264 |
int bAbbrevSubcmd, |
|
62cb8ea…
|
drh
|
1265 |
const char *zCmd |
|
62cb8ea…
|
drh
|
1266 |
){ |
|
62cb8ea…
|
drh
|
1267 |
const char *z = blob_buffer(p); |
|
62cb8ea…
|
drh
|
1268 |
int sz = blob_size(p); |
|
62cb8ea…
|
drh
|
1269 |
int i = 0; |
|
62cb8ea…
|
drh
|
1270 |
if( sz>6 && z[0]=='U' ){ |
|
62cb8ea…
|
drh
|
1271 |
for(i=1; i<sz && !fossil_isspace(z[i]); i++){} |
|
62cb8ea…
|
drh
|
1272 |
}else if( sz>0 && z[0]=='>' ){ |
|
62cb8ea…
|
drh
|
1273 |
i = 1; |
|
62cb8ea…
|
drh
|
1274 |
}else if( sz>4 && bAbbrevSubcmd |
|
62cb8ea…
|
drh
|
1275 |
&& memcmp(z," ",3)==0 && !fossil_isspace(z[3]) ){ |
|
62cb8ea…
|
drh
|
1276 |
int j; |
|
62cb8ea…
|
drh
|
1277 |
for(j=3; j<sz-1 && (z[j]!=' ' || z[j+1]!=' '); j++){} |
|
62cb8ea…
|
drh
|
1278 |
blob_appendf(pOut, "fossil %s %.*s\n", zCmd, j-3, &z[3]); |
|
62cb8ea…
|
drh
|
1279 |
return; |
|
62cb8ea…
|
drh
|
1280 |
}else{ |
|
62cb8ea…
|
drh
|
1281 |
while( i<sz && fossil_isspace(z[i]) ) i++; |
|
62cb8ea…
|
drh
|
1282 |
if( i+2<sz && (z[i]=='o' || z[i]=='O') && z[i+1]=='r' ){ |
|
62cb8ea…
|
drh
|
1283 |
while( i<sz && !fossil_isspace(z[i]) ) i++; |
|
62cb8ea…
|
drh
|
1284 |
} |
|
62cb8ea…
|
drh
|
1285 |
} |
|
62cb8ea…
|
drh
|
1286 |
while( i<sz && fossil_isspace(z[i]) ) i++; |
|
62cb8ea…
|
drh
|
1287 |
blob_append(pOut, &z[i], sz-i); |
|
baeffb9…
|
drh
|
1288 |
} |
|
baeffb9…
|
drh
|
1289 |
|
|
baeffb9…
|
drh
|
1290 |
/* |
|
baeffb9…
|
drh
|
1291 |
** Input z[] is help text for a command zTopic. Write into pOut all lines of |
|
baeffb9…
|
drh
|
1292 |
** z[] that show the command-line syntax for that command. Lines written |
|
baeffb9…
|
drh
|
1293 |
** to pOut are lines that begin with out of: |
|
baeffb9…
|
drh
|
1294 |
** |
|
baeffb9…
|
drh
|
1295 |
** Usage: |
|
baeffb9…
|
drh
|
1296 |
** or: |
|
baeffb9…
|
drh
|
1297 |
** > fossil TOPIC |
|
baeffb9…
|
drh
|
1298 |
** |
|
baeffb9…
|
drh
|
1299 |
** Return the number of lines written into pOut. |
|
baeffb9…
|
drh
|
1300 |
*/ |
|
baeffb9…
|
drh
|
1301 |
static int simplify_to_usage( |
|
baeffb9…
|
drh
|
1302 |
const char *z, /* Full original help text */ |
|
baeffb9…
|
drh
|
1303 |
Blob *pOut, /* Write simplified help text here */ |
|
62cb8ea…
|
drh
|
1304 |
const char *zTopic, /* The command for which z[] is full help text */ |
|
62cb8ea…
|
drh
|
1305 |
int bAbbrevSubcmd /* z[] uses abbreviated subcommands */ |
|
baeffb9…
|
drh
|
1306 |
){ |
|
baeffb9…
|
drh
|
1307 |
ReCompiled *pRe = 0; |
|
baeffb9…
|
drh
|
1308 |
Blob in, line; |
|
baeffb9…
|
drh
|
1309 |
int n = 0; |
|
baeffb9…
|
drh
|
1310 |
|
|
62cb8ea…
|
drh
|
1311 |
if( bAbbrevSubcmd ){ |
|
82888a0…
|
drh
|
1312 |
fossil_re_compile(&pRe, "^(Usage: | [a-z][-a-z|]+ .*)", 0); |
|
62cb8ea…
|
drh
|
1313 |
}else{ |
|
82888a0…
|
drh
|
1314 |
fossil_re_compile(&pRe, "^(Usage: | *[Oo]r: +%fossi |> ?fossil )", 0); |
|
62cb8ea…
|
drh
|
1315 |
} |
|
baeffb9…
|
drh
|
1316 |
blob_init(&in, z, -1); |
|
baeffb9…
|
drh
|
1317 |
while( blob_line(&in, &line) ){ |
|
90e564f…
|
drh
|
1318 |
if( re_match(pRe, (unsigned char*)blob_buffer(&line), blob_strlen(&line)) ){ |
|
62cb8ea…
|
drh
|
1319 |
simplify_usage_line(&line, pOut, bAbbrevSubcmd, zTopic); |
|
baeffb9…
|
drh
|
1320 |
n++; |
|
baeffb9…
|
drh
|
1321 |
} |
|
baeffb9…
|
drh
|
1322 |
} |
|
baeffb9…
|
drh
|
1323 |
re_free(pRe); |
|
baeffb9…
|
drh
|
1324 |
if( n ) blob_trim(pOut); |
|
baeffb9…
|
drh
|
1325 |
return n; |
|
baeffb9…
|
drh
|
1326 |
} |
|
692a283…
|
drh
|
1327 |
|
|
692a283…
|
drh
|
1328 |
/* |
|
692a283…
|
drh
|
1329 |
** Input z[] is help text. Write into pOut all lines of z[] that show |
|
692a283…
|
drh
|
1330 |
** command-line options. Return the number of lines written. |
|
692a283…
|
drh
|
1331 |
*/ |
|
692a283…
|
drh
|
1332 |
static int simplify_to_options( |
|
692a283…
|
drh
|
1333 |
const char *z, /* Full original help text */ |
|
62cb8ea…
|
drh
|
1334 |
Blob *pOut, /* Write simplified help text here */ |
|
62cb8ea…
|
drh
|
1335 |
int bAbbrevSubcmd, /* z[] uses abbreviated subcommands */ |
|
62cb8ea…
|
drh
|
1336 |
const char *zCmd /* Name of the command that z[] describes */ |
|
692a283…
|
drh
|
1337 |
){ |
|
692a283…
|
drh
|
1338 |
ReCompiled *pRe = 0; |
|
692a283…
|
drh
|
1339 |
Blob txt, line, subsection; |
|
692a283…
|
drh
|
1340 |
int n = 0; |
|
62cb8ea…
|
drh
|
1341 |
int bSubsectionSeen = 0; |
|
692a283…
|
drh
|
1342 |
|
|
692a283…
|
drh
|
1343 |
blob_init(&txt, z, -1); |
|
692a283…
|
drh
|
1344 |
blob_init(&subsection, 0, 0); |
|
82888a0…
|
drh
|
1345 |
fossil_re_compile(&pRe, "^ +-.* ", 0); |
|
692a283…
|
drh
|
1346 |
while( blob_line(&txt, &line) ){ |
|
62cb8ea…
|
drh
|
1347 |
int len = blob_size(&line); |
|
62cb8ea…
|
drh
|
1348 |
unsigned char *zLine = (unsigned char *)blob_buffer(&line); |
|
62cb8ea…
|
drh
|
1349 |
if( re_match(pRe, zLine, len) ){ |
|
62cb8ea…
|
drh
|
1350 |
if( blob_size(&subsection) ){ |
|
62cb8ea…
|
drh
|
1351 |
simplify_usage_line(&subsection, pOut, bAbbrevSubcmd, zCmd); |
|
692a283…
|
drh
|
1352 |
blob_reset(&subsection); |
|
692a283…
|
drh
|
1353 |
} |
|
692a283…
|
drh
|
1354 |
blob_appendb(pOut, &line); |
|
62cb8ea…
|
drh
|
1355 |
}else if( len>7 && !fossil_isspace(zLine[0]) && bSubsectionSeen |
|
62cb8ea…
|
drh
|
1356 |
&& sqlite3_strlike("%options:%",blob_str(&line),0)==0 ){ |
|
62cb8ea…
|
drh
|
1357 |
subsection = line; |
|
62cb8ea…
|
drh
|
1358 |
}else if( !bAbbrevSubcmd && len>9 |
|
b097e68…
|
drh
|
1359 |
&& (memcmp(zLine,"> fossil ",9)==0 |
|
b097e68…
|
drh
|
1360 |
|| memcmp(zLine,"> fossil",9)==0) ){ |
|
62cb8ea…
|
drh
|
1361 |
subsection = line; |
|
62cb8ea…
|
drh
|
1362 |
bSubsectionSeen = 1; |
|
62cb8ea…
|
drh
|
1363 |
}else if( bAbbrevSubcmd && len>5 && memcmp(zLine," ",3)==0 |
|
62cb8ea…
|
drh
|
1364 |
&& fossil_isalpha(zLine[3]) ){ |
|
692a283…
|
drh
|
1365 |
subsection = line; |
|
62cb8ea…
|
drh
|
1366 |
bSubsectionSeen = 1; |
|
62cb8ea…
|
drh
|
1367 |
}else if( len>1 && !fossil_isspace(zLine[0]) && bSubsectionSeen ){ |
|
62cb8ea…
|
drh
|
1368 |
blob_reset(&subsection); |
|
692a283…
|
drh
|
1369 |
} |
|
692a283…
|
drh
|
1370 |
} |
|
692a283…
|
drh
|
1371 |
re_free(pRe); |
|
692a283…
|
drh
|
1372 |
blob_trim(pOut); |
|
692a283…
|
drh
|
1373 |
blob_reset(&subsection); |
|
692a283…
|
drh
|
1374 |
return n; |
|
692a283…
|
drh
|
1375 |
} |
|
692a283…
|
drh
|
1376 |
|
|
692a283…
|
drh
|
1377 |
|
|
e6aab1a…
|
drh
|
1378 |
|
|
e6aab1a…
|
drh
|
1379 |
static void multi_column_list(const char **azWord, int nWord){ |
|
e6aab1a…
|
drh
|
1380 |
int i, j, len; |
|
e6aab1a…
|
drh
|
1381 |
int mxLen = 0; |
|
e6aab1a…
|
drh
|
1382 |
int nCol; |
|
e6aab1a…
|
drh
|
1383 |
int nRow; |
|
e6aab1a…
|
drh
|
1384 |
for(i=0; i<nWord; i++){ |
|
e6aab1a…
|
drh
|
1385 |
len = strlen(azWord[i]); |
|
e6aab1a…
|
drh
|
1386 |
if( len>mxLen ) mxLen = len; |
|
e6aab1a…
|
drh
|
1387 |
} |
|
e6aab1a…
|
drh
|
1388 |
nCol = 80/(mxLen+2); |
|
e6aab1a…
|
drh
|
1389 |
if( nCol==0 ) nCol = 1; |
|
e6aab1a…
|
drh
|
1390 |
nRow = (nWord + nCol - 1)/nCol; |
|
e6aab1a…
|
drh
|
1391 |
for(i=0; i<nRow; i++){ |
|
e6aab1a…
|
drh
|
1392 |
const char *zSpacer = ""; |
|
e6aab1a…
|
drh
|
1393 |
for(j=i; j<nWord; j+=nRow){ |
|
e6aab1a…
|
drh
|
1394 |
fossil_print("%s%-*s", zSpacer, mxLen, azWord[j]); |
|
e6aab1a…
|
drh
|
1395 |
zSpacer = " "; |
|
e6aab1a…
|
drh
|
1396 |
} |
|
e6aab1a…
|
drh
|
1397 |
fossil_print("\n"); |
|
e6aab1a…
|
drh
|
1398 |
} |
|
e6aab1a…
|
drh
|
1399 |
} |
|
e6aab1a…
|
drh
|
1400 |
|
|
e6aab1a…
|
drh
|
1401 |
/* |
|
e6aab1a…
|
drh
|
1402 |
** COMMAND: test-list-webpage |
|
e6aab1a…
|
drh
|
1403 |
** |
|
e6aab1a…
|
drh
|
1404 |
** List all web pages. |
|
e6aab1a…
|
drh
|
1405 |
*/ |
|
e6aab1a…
|
drh
|
1406 |
void cmd_test_webpage_list(void){ |
|
e6aab1a…
|
drh
|
1407 |
int i, nCmd; |
|
e6aab1a…
|
drh
|
1408 |
const char *aCmd[MX_COMMAND]; |
|
e6aab1a…
|
drh
|
1409 |
for(i=nCmd=0; i<MX_COMMAND; i++){ |
|
dfa23f5…
|
andygoth
|
1410 |
if(CMDFLAG_WEBPAGE & aCommand[i].eCmdFlags){ |
|
e6aab1a…
|
drh
|
1411 |
aCmd[nCmd++] = aCommand[i].zName; |
|
e6aab1a…
|
drh
|
1412 |
} |
|
e6aab1a…
|
drh
|
1413 |
} |
|
e6aab1a…
|
drh
|
1414 |
assert(nCmd && "page list is empty?"); |
|
e6aab1a…
|
drh
|
1415 |
multi_column_list(aCmd, nCmd); |
|
e6aab1a…
|
drh
|
1416 |
} |
|
e6aab1a…
|
drh
|
1417 |
|
|
e6aab1a…
|
drh
|
1418 |
|
|
e6aab1a…
|
drh
|
1419 |
/* |
|
e6aab1a…
|
drh
|
1420 |
** List of commands starting with zPrefix, or all commands if zPrefix is NULL. |
|
e6aab1a…
|
drh
|
1421 |
*/ |
|
8a231a7…
|
drh
|
1422 |
static void command_list(int cmdMask, int verboseFlag, int useHtml){ |
|
8a231a7…
|
drh
|
1423 |
if( verboseFlag ){ |
|
8a231a7…
|
drh
|
1424 |
display_all_help(cmdMask, useHtml, 0); |
|
8a231a7…
|
drh
|
1425 |
}else{ |
|
8a231a7…
|
drh
|
1426 |
int i, nCmd; |
|
8a231a7…
|
drh
|
1427 |
const char *aCmd[MX_COMMAND]; |
|
8a231a7…
|
drh
|
1428 |
for(i=nCmd=0; i<MX_COMMAND; i++){ |
|
8a231a7…
|
drh
|
1429 |
if( (aCommand[i].eCmdFlags & cmdMask)==0 ) continue; |
|
701c6dc…
|
stephan
|
1430 |
else if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue; |
|
8a231a7…
|
drh
|
1431 |
aCmd[nCmd++] = aCommand[i].zName; |
|
8a231a7…
|
drh
|
1432 |
} |
|
8a231a7…
|
drh
|
1433 |
multi_column_list(aCmd, nCmd); |
|
8a231a7…
|
drh
|
1434 |
} |
|
50eb6bd…
|
drh
|
1435 |
} |
|
50eb6bd…
|
drh
|
1436 |
|
|
50eb6bd…
|
drh
|
1437 |
/* |
|
6eeb27a…
|
drh
|
1438 |
** TOPIC: options |
|
6eeb27a…
|
drh
|
1439 |
** |
|
6eeb27a…
|
drh
|
1440 |
** Command-line options common to all commands: |
|
6eeb27a…
|
drh
|
1441 |
** |
|
6eeb27a…
|
drh
|
1442 |
** --args FILENAME Read additional arguments and options from FILENAME |
|
6eeb27a…
|
drh
|
1443 |
** --case-sensitive BOOL Set case sensitivity for file names |
|
6eeb27a…
|
drh
|
1444 |
** --cgitrace Active CGI tracing |
|
6eeb27a…
|
drh
|
1445 |
** --chdir PATH Change to PATH before performing any operations |
|
6eeb27a…
|
drh
|
1446 |
** --errorlog FILENAME Log errors to FILENAME |
|
6eeb27a…
|
drh
|
1447 |
** -?|--help Show help on the command rather than running it |
|
6eeb27a…
|
drh
|
1448 |
** --httptrace Trace outbound HTTP requests |
|
6eeb27a…
|
drh
|
1449 |
** --localtime Display times using the local timezone |
|
6eeb27a…
|
drh
|
1450 |
** --nocgi Do not act as CGI |
|
6eeb27a…
|
drh
|
1451 |
** --no-th-hook Do not run TH1 hooks |
|
74d5ce3…
|
florian
|
1452 |
** -q|--quiet Reduce the amount of output |
|
6eeb27a…
|
drh
|
1453 |
** --sqlstats Show SQL usage statistics when done |
|
6eeb27a…
|
drh
|
1454 |
** --sqltrace Trace all SQL commands |
|
6eeb27a…
|
drh
|
1455 |
** --sshtrace Trace SSH activity |
|
6eeb27a…
|
drh
|
1456 |
** --ssl-identity NAME Set the SSL identity to NAME |
|
6eeb27a…
|
drh
|
1457 |
** --systemtrace Trace calls to system() |
|
6eeb27a…
|
drh
|
1458 |
** -U|--user USER Make the default user be USER |
|
6eeb27a…
|
drh
|
1459 |
** --utc Display times using UTC |
|
6eeb27a…
|
drh
|
1460 |
** --vfs NAME Cause SQLite to use the NAME VFS |
|
6eeb27a…
|
drh
|
1461 |
** |
|
6eeb27a…
|
drh
|
1462 |
** Additional options available on most commands that use network I/O: |
|
6eeb27a…
|
drh
|
1463 |
** |
|
6eeb27a…
|
drh
|
1464 |
** --accept-any-cert Disable server SSL cdert validation. Accept any SSL |
|
6eeb27a…
|
drh
|
1465 |
** cert that the server provides. WARNING: Unsafe! |
|
6eeb27a…
|
drh
|
1466 |
** Testing and debugging use only! |
|
6eeb27a…
|
drh
|
1467 |
** --ipv4 Use only IPv4. Disable IPv6 support. |
|
6eeb27a…
|
drh
|
1468 |
** --ipv6 Use only IPv6. Disable IPv4 support. |
|
6eeb27a…
|
drh
|
1469 |
** --nosync Disable autosync for the current command. |
|
6eeb27a…
|
drh
|
1470 |
** --proxy URL Specify the HTTP proxy to use. URL can be "off". |
|
b097e68…
|
drh
|
1471 |
*/ |
|
e6aab1a…
|
drh
|
1472 |
|
|
e6aab1a…
|
drh
|
1473 |
/* |
|
e6aab1a…
|
drh
|
1474 |
** COMMAND: help |
|
e6aab1a…
|
drh
|
1475 |
** |
|
aff179d…
|
drh
|
1476 |
** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND] |
|
2b6a34c…
|
andygoth
|
1477 |
** |
|
2b6a34c…
|
andygoth
|
1478 |
** Display information on how to use TOPIC, which may be a command, webpage, or |
|
e58c76a…
|
drh
|
1479 |
** setting. Webpage names begin with "/". If TOPIC is omitted, a list of |
|
aff179d…
|
drh
|
1480 |
** topics is returned. If there is an extra argument after TOPIC, it is |
|
4ee254e…
|
drh
|
1481 |
** the name of a subcommand, in which case only the help text for that one |
|
aff179d…
|
drh
|
1482 |
** subcommand is shown. |
|
e58c76a…
|
drh
|
1483 |
** |
|
e58c76a…
|
drh
|
1484 |
** The following options can be used when TOPIC is omitted: |
|
e58c76a…
|
drh
|
1485 |
** |
|
84f697e…
|
drh
|
1486 |
** -a|--all List both common and auxiliary commands |
|
baeffb9…
|
drh
|
1487 |
** -e|--everything List all help on all topics |
|
baeffb9…
|
drh
|
1488 |
** -f|--full List full set of commands (including auxiliary |
|
baeffb9…
|
drh
|
1489 |
** and unsupported "test" commands), options, |
|
baeffb9…
|
drh
|
1490 |
** settings, and web pages |
|
8a231a7…
|
drh
|
1491 |
** -o|--options List command-line options common to all commands |
|
8a231a7…
|
drh
|
1492 |
** -s|--setting List setting names |
|
8a231a7…
|
drh
|
1493 |
** -t|--test List unsupported "test" commands |
|
8a231a7…
|
drh
|
1494 |
** -v|--verbose List both names and help text |
|
8a231a7…
|
drh
|
1495 |
** -x|--aux List only auxiliary commands |
|
8a231a7…
|
drh
|
1496 |
** -w|--www List all web pages |
|
e58c76a…
|
drh
|
1497 |
** |
|
e58c76a…
|
drh
|
1498 |
** These options can be used when TOPIC is present: |
|
e58c76a…
|
drh
|
1499 |
** |
|
3091605…
|
drh
|
1500 |
** -c|--commands Restrict TOPIC search to commands |
|
baeffb9…
|
drh
|
1501 |
** -h|--html Format output as HTML rather than plain text |
|
692a283…
|
drh
|
1502 |
** -o|--options Show command-line options for TOPIC |
|
baeffb9…
|
drh
|
1503 |
** --raw Output raw, unformatted help text |
|
baeffb9…
|
drh
|
1504 |
** -u|--usage Show a succinct usage summary, not full help text |
|
aff179d…
|
drh
|
1505 |
** |
|
aff179d…
|
drh
|
1506 |
** See also: [[usage]], [[options]], [[search]] with the -h option |
|
e6aab1a…
|
drh
|
1507 |
*/ |
|
e6aab1a…
|
drh
|
1508 |
void help_cmd(void){ |
|
e6aab1a…
|
drh
|
1509 |
int rc; |
|
baeffb9…
|
drh
|
1510 |
int mask = CMDFLAG_ANY; /* Mask of help topic types */ |
|
baeffb9…
|
drh
|
1511 |
int isPage = 0; /* True if TOPIC is a page */ |
|
baeffb9…
|
drh
|
1512 |
int verboseFlag = 0; /* -v option */ |
|
baeffb9…
|
drh
|
1513 |
int commandsFlag = 0; /* -c option */ |
|
baeffb9…
|
drh
|
1514 |
const char *z; /* Original, untranslated help text */ |
|
baeffb9…
|
drh
|
1515 |
const char *zCmdOrPage; /* "command" or "page" or "setting" */ |
|
baeffb9…
|
drh
|
1516 |
const CmdOrPage *pCmd = 0; /* ptr to aCommand[] entry for TOPIC */ |
|
baeffb9…
|
drh
|
1517 |
int useHtml = 0; /* -h option */ |
|
692a283…
|
drh
|
1518 |
int bUsage; /* --usage */ |
|
baeffb9…
|
drh
|
1519 |
int bRaw; /* --raw option */ |
|
692a283…
|
drh
|
1520 |
int bOptions; /* --options */ |
|
baeffb9…
|
drh
|
1521 |
const char *zTopic; /* TOPIC argument */ |
|
baeffb9…
|
drh
|
1522 |
const char *zSubtopic = 0; /* SUBTOPIC argument */ |
|
692a283…
|
drh
|
1523 |
Blob subtext1, subtext2, s3; /* Subsets of z[] containing subtopic/usage */ |
|
baeffb9…
|
drh
|
1524 |
Blob txt; /* Text after rendering */ |
|
62cb8ea…
|
drh
|
1525 |
int bAbbrevSubcmd = 0; /* Help text uses abbreviated subcommands */ |
|
baeffb9…
|
drh
|
1526 |
|
|
65f59be…
|
andybradford
|
1527 |
verboseFlag = find_option("verbose","v",0)!=0; |
|
8a231a7…
|
drh
|
1528 |
commandsFlag = find_option("commands","c",0)!=0; |
|
8a231a7…
|
drh
|
1529 |
useHtml = find_option("html","h",0)!=0; |
|
baeffb9…
|
drh
|
1530 |
bRaw = find_option("raw",0,0)!=0; |
|
692a283…
|
drh
|
1531 |
bOptions = find_option("options","o",0)!=0; |
|
692a283…
|
drh
|
1532 |
bUsage = find_option("usage","u",0)!=0; |
|
692a283…
|
drh
|
1533 |
if( find_option("all","a",0) ){ |
|
8a231a7…
|
drh
|
1534 |
command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
|
e6aab1a…
|
drh
|
1535 |
return; |
|
e6aab1a…
|
drh
|
1536 |
} |
|
e6aab1a…
|
drh
|
1537 |
else if( find_option("www","w",0) ){ |
|
8a231a7…
|
drh
|
1538 |
command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml); |
|
e6aab1a…
|
drh
|
1539 |
return; |
|
e6aab1a…
|
drh
|
1540 |
} |
|
e6aab1a…
|
drh
|
1541 |
else if( find_option("aux","x",0) ){ |
|
8a231a7…
|
drh
|
1542 |
command_list(CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
|
e6aab1a…
|
drh
|
1543 |
return; |
|
e6aab1a…
|
drh
|
1544 |
} |
|
e6aab1a…
|
drh
|
1545 |
else if( find_option("test","t",0) ){ |
|
8a231a7…
|
drh
|
1546 |
command_list(CMDFLAG_TEST, verboseFlag, useHtml); |
|
f74f701…
|
drh
|
1547 |
return; |
|
f74f701…
|
drh
|
1548 |
} |
|
f74f701…
|
drh
|
1549 |
else if( find_option("setting","s",0) ){ |
|
8a231a7…
|
drh
|
1550 |
command_list(CMDFLAG_SETTING, verboseFlag, useHtml); |
|
8a231a7…
|
drh
|
1551 |
return; |
|
8a231a7…
|
drh
|
1552 |
} |
|
6eeb27a…
|
drh
|
1553 |
else if( find_option("topic","c",0) ){ |
|
6eeb27a…
|
drh
|
1554 |
command_list(CMDFLAG_TOPIC, verboseFlag, useHtml); |
|
6eeb27a…
|
drh
|
1555 |
return; |
|
6eeb27a…
|
drh
|
1556 |
} |
|
89e5ac1…
|
stephan
|
1557 |
else if( find_option("full","f",0) ){ |
|
89e5ac1…
|
stephan
|
1558 |
fossil_print("fossil commands:\n\n"); |
|
8a231a7…
|
drh
|
1559 |
command_list(CMDFLAG_1ST_TIER, verboseFlag, useHtml); |
|
89e5ac1…
|
stephan
|
1560 |
fossil_print("\nfossil auxiliary commands:\n\n"); |
|
8a231a7…
|
drh
|
1561 |
command_list(CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
|
89e5ac1…
|
stephan
|
1562 |
fossil_print("\nfossil settings:\n\n"); |
|
8a231a7…
|
drh
|
1563 |
command_list(CMDFLAG_SETTING, verboseFlag, useHtml); |
|
89e5ac1…
|
stephan
|
1564 |
fossil_print("\nfossil web pages:\n\n"); |
|
8a231a7…
|
drh
|
1565 |
command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml); |
|
6eeb27a…
|
drh
|
1566 |
fossil_print("\nfossil miscellaneous help topics:\n\n"); |
|
6eeb27a…
|
drh
|
1567 |
command_list(CMDFLAG_TOPIC, verboseFlag, useHtml); |
|
89e5ac1…
|
stephan
|
1568 |
fossil_print("\nfossil test commands (unsupported):\n\n"); |
|
8a231a7…
|
drh
|
1569 |
command_list(CMDFLAG_TEST, verboseFlag, useHtml); |
|
1ce93cb…
|
brickviking
|
1570 |
if ( !verboseFlag ) { |
|
1ce93cb…
|
brickviking
|
1571 |
fossil_print("\n"); |
|
1ce93cb…
|
brickviking
|
1572 |
version_cmd(); |
|
1ce93cb…
|
brickviking
|
1573 |
} |
|
89e5ac1…
|
stephan
|
1574 |
return; |
|
89e5ac1…
|
stephan
|
1575 |
} |
|
89e5ac1…
|
stephan
|
1576 |
else if( find_option("everything","e",0) ){ |
|
89e5ac1…
|
stephan
|
1577 |
display_all_help(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE | |
|
6eeb27a…
|
drh
|
1578 |
CMDFLAG_SETTING | CMDFLAG_TEST | CMDFLAG_TOPIC, |
|
6eeb27a…
|
drh
|
1579 |
useHtml, 0); |
|
8a231a7…
|
drh
|
1580 |
return; |
|
8a231a7…
|
drh
|
1581 |
} |
|
8a231a7…
|
drh
|
1582 |
verify_all_options(); |
|
c91fd40…
|
drh
|
1583 |
zCmdOrPage = "help topic"; |
|
8a231a7…
|
drh
|
1584 |
if( g.argc<3 ){ |
|
692a283…
|
drh
|
1585 |
if( bOptions ){ |
|
6eeb27a…
|
drh
|
1586 |
zTopic = "options"; |
|
6eeb27a…
|
drh
|
1587 |
zSubtopic = 0; |
|
6eeb27a…
|
drh
|
1588 |
mask = CMDFLAG_TOPIC; |
|
6eeb27a…
|
drh
|
1589 |
bOptions = 0; |
|
6eeb27a…
|
drh
|
1590 |
goto find_and_show_help; |
|
692a283…
|
drh
|
1591 |
} |
|
8a231a7…
|
drh
|
1592 |
z = g.argv[0]; |
|
8a231a7…
|
drh
|
1593 |
fossil_print( |
|
8a231a7…
|
drh
|
1594 |
"Usage: %s help TOPIC\n" |
|
90e564f…
|
drh
|
1595 |
"Things to try:\n\n" |
|
90e564f…
|
drh
|
1596 |
" %s help help\n" |
|
b097e68…
|
drh
|
1597 |
" %s help -o\n" |
|
90e564f…
|
drh
|
1598 |
" %s help -a\n" |
|
638c98d…
|
drh
|
1599 |
" %s search -h TOPIC\n\n" |
|
90e564f…
|
drh
|
1600 |
"Other common values for TOPIC:\n\n", |
|
90e564f…
|
drh
|
1601 |
z, z, z, z, z); |
|
8a231a7…
|
drh
|
1602 |
command_list(CMDFLAG_1ST_TIER,verboseFlag,useHtml); |
|
8a231a7…
|
drh
|
1603 |
if( !verboseFlag ) version_cmd(); |
|
a99d917…
|
drh
|
1604 |
return; |
|
a99d917…
|
drh
|
1605 |
} |
|
8a231a7…
|
drh
|
1606 |
zTopic = g.argv[2]; |
|
baeffb9…
|
drh
|
1607 |
zSubtopic = g.argc>=4 ? g.argv[3] : 0; |
|
8a231a7…
|
drh
|
1608 |
isPage = ('/' == zTopic[0]) ? 1 : 0; |
|
90e564f…
|
drh
|
1609 |
if( isPage ){ |
|
a99d917…
|
drh
|
1610 |
zCmdOrPage = "page"; |
|
8a231a7…
|
drh
|
1611 |
}else if( commandsFlag ){ |
|
c91fd40…
|
drh
|
1612 |
mask = CMDFLAG_COMMAND; |
|
3091605…
|
drh
|
1613 |
zCmdOrPage = "command"; |
|
aff179d…
|
drh
|
1614 |
} |
|
6eeb27a…
|
drh
|
1615 |
find_and_show_help: |
|
6eeb27a…
|
drh
|
1616 |
rc = dispatch_name_search(zTopic, mask|CMDFLAG_PREFIX, &pCmd); |
|
aff179d…
|
drh
|
1617 |
if( rc ){ |
|
aff179d…
|
drh
|
1618 |
int i, n; |
|
aff179d…
|
drh
|
1619 |
const char *az[5]; |
|
aff179d…
|
drh
|
1620 |
if( rc==1 ){ |
|
e5ace41…
|
stephan
|
1621 |
if( help_is_platform_command(g.argv[2]) ){ |
|
7919a44…
|
stephan
|
1622 |
fossil_print("Not available in this build: %s\n", g.argv[2]); |
|
e5ace41…
|
stephan
|
1623 |
return; |
|
e5ace41…
|
stephan
|
1624 |
} |
|
aff179d…
|
drh
|
1625 |
fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); |
|
aff179d…
|
drh
|
1626 |
}else{ |
|
aff179d…
|
drh
|
1627 |
fossil_print("ambiguous %s prefix: %s\n", |
|
aff179d…
|
drh
|
1628 |
zCmdOrPage, g.argv[2]); |
|
aff179d…
|
drh
|
1629 |
} |
|
aff179d…
|
drh
|
1630 |
fossil_print("Did you mean one of these TOPICs:\n"); |
|
aff179d…
|
drh
|
1631 |
n = dispatch_approx_match(g.argv[2], 5, az); |
|
aff179d…
|
drh
|
1632 |
for(i=0; i<n; i++){ |
|
aff179d…
|
drh
|
1633 |
fossil_print(" * %s\n", az[i]); |
|
aff179d…
|
drh
|
1634 |
} |
|
aff179d…
|
drh
|
1635 |
fossil_print("Other commands to try:\n"); |
|
aff179d…
|
drh
|
1636 |
fossil_print(" fossil search -h PATTERN ;# search all help text\n"); |
|
aff179d…
|
drh
|
1637 |
fossil_print(" fossil help -a ;# show all commands\n"); |
|
aff179d…
|
drh
|
1638 |
fossil_print(" fossil help -w ;# show all web-pages\n"); |
|
aff179d…
|
drh
|
1639 |
fossil_print(" fossil help -s ;# show all settings\n"); |
|
aff179d…
|
drh
|
1640 |
fossil_print(" fossil help -o ;# show global options\n"); |
|
aff179d…
|
drh
|
1641 |
return; |
|
aff179d…
|
drh
|
1642 |
} |
|
62cb8ea…
|
drh
|
1643 |
bAbbrevSubcmd = (pCmd->eCmdFlags & CMDFLAG_ABBREVSUBCMD)!=0; |
|
aff179d…
|
drh
|
1644 |
z = pCmd->zHelp; |
|
aff179d…
|
drh
|
1645 |
if( z==0 ){ |
|
aff179d…
|
drh
|
1646 |
fossil_fatal("no help available for the %s %s", |
|
aff179d…
|
drh
|
1647 |
pCmd->zName, zCmdOrPage); |
|
e6aab1a…
|
drh
|
1648 |
} |
|
90e564f…
|
drh
|
1649 |
blob_init(&subtext1, 0, 0); |
|
90e564f…
|
drh
|
1650 |
blob_init(&subtext2, 0, 0); |
|
692a283…
|
drh
|
1651 |
blob_init(&s3, 0, 0); |
|
baeffb9…
|
drh
|
1652 |
if( zSubtopic!=0 ){ |
|
62cb8ea…
|
drh
|
1653 |
if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic, bAbbrevSubcmd) ){ |
|
baeffb9…
|
drh
|
1654 |
z = blob_str(&subtext1); |
|
baeffb9…
|
drh
|
1655 |
}else{ |
|
b097e68…
|
drh
|
1656 |
fossil_print("No subtopic \"%s\" for \"%s\".\n", zSubtopic, zTopic); |
|
b097e68…
|
drh
|
1657 |
bUsage = 1; |
|
b097e68…
|
drh
|
1658 |
zSubtopic = 0; |
|
62cb8ea…
|
drh
|
1659 |
} |
|
62cb8ea…
|
drh
|
1660 |
} |
|
62cb8ea…
|
drh
|
1661 |
if( bUsage ){ |
|
62cb8ea…
|
drh
|
1662 |
if( simplify_to_usage(z, &subtext2, zTopic, bAbbrevSubcmd) ){ |
|
62cb8ea…
|
drh
|
1663 |
z = blob_str(&subtext2); |
|
62cb8ea…
|
drh
|
1664 |
}else{ |
|
62cb8ea…
|
drh
|
1665 |
bUsage = 0; |
|
baeffb9…
|
drh
|
1666 |
} |
|
baeffb9…
|
drh
|
1667 |
} |
|
692a283…
|
drh
|
1668 |
if( bOptions ){ |
|
62cb8ea…
|
drh
|
1669 |
simplify_to_options(z, &s3, bAbbrevSubcmd, zTopic); |
|
692a283…
|
drh
|
1670 |
z = blob_str(&s3); |
|
baeffb9…
|
drh
|
1671 |
} |
|
90e564f…
|
drh
|
1672 |
if( pCmd && pCmd->eCmdFlags & CMDFLAG_SETTING ){ |
|
1e1a319…
|
mark
|
1673 |
const Setting *pSetting = db_find_setting(pCmd->zName, 0); |
|
1e1a319…
|
mark
|
1674 |
char *zDflt = 0; |
|
1e1a319…
|
mark
|
1675 |
if( pSetting!=0 && pSetting->def!=0 && *pSetting->def!=0 ){ |
|
1e1a319…
|
mark
|
1676 |
zDflt = mprintf(" (default: %s)", pSetting->def); |
|
1e1a319…
|
mark
|
1677 |
} |
|
1e1a319…
|
mark
|
1678 |
fossil_print("Setting: \"%s\"%s%s\n\n", |
|
1e1a319…
|
mark
|
1679 |
pCmd->zName, zDflt!=0 ? zDflt : "", |
|
f74f701…
|
drh
|
1680 |
(pCmd->eCmdFlags & CMDFLAG_VERSIONABLE)!=0 ? " (versionable)" : "" |
|
f74f701…
|
drh
|
1681 |
); |
|
1e1a319…
|
mark
|
1682 |
fossil_free(zDflt); |
|
e58c76a…
|
drh
|
1683 |
} |
|
e58c76a…
|
drh
|
1684 |
blob_init(&txt, 0, 0); |
|
baeffb9…
|
drh
|
1685 |
if( bRaw ){ |
|
baeffb9…
|
drh
|
1686 |
blob_append(&txt, z, -1); |
|
baeffb9…
|
drh
|
1687 |
}else if( useHtml ){ |
|
e58c76a…
|
drh
|
1688 |
help_to_html(z, &txt); |
|
e58c76a…
|
drh
|
1689 |
}else{ |
|
b097e68…
|
drh
|
1690 |
help_to_text(z, &txt, bUsage || zSubtopic!=0); |
|
e58c76a…
|
drh
|
1691 |
} |
|
62cb8ea…
|
drh
|
1692 |
if( blob_strlen(&txt)>0 ) fossil_print("%s\n", blob_str(&txt)); |
|
e58c76a…
|
drh
|
1693 |
blob_reset(&txt); |
|
baeffb9…
|
drh
|
1694 |
blob_reset(&subtext1); |
|
baeffb9…
|
drh
|
1695 |
blob_reset(&subtext2); |
|
f74f701…
|
drh
|
1696 |
} |
|
f74f701…
|
drh
|
1697 |
|
|
f74f701…
|
drh
|
1698 |
/* |
|
f74f701…
|
drh
|
1699 |
** Return a pointer to the setting information array. |
|
f74f701…
|
drh
|
1700 |
** |
|
f646537…
|
drh
|
1701 |
** This routine provides access to the aSetting[] array which is created |
|
f74f701…
|
drh
|
1702 |
** by the mkindex utility program and included with <page_index.h>. |
|
f74f701…
|
drh
|
1703 |
*/ |
|
f74f701…
|
drh
|
1704 |
const Setting *setting_info(int *pnCount){ |
|
df654bd…
|
drh
|
1705 |
if( pnCount ) *pnCount = (int)(sizeof(aSetting)/sizeof(aSetting[0])) - 1; |
|
f74f701…
|
drh
|
1706 |
return aSetting; |
|
f646537…
|
drh
|
1707 |
} |
|
f646537…
|
drh
|
1708 |
|
|
f646537…
|
drh
|
1709 |
/* |
|
f646537…
|
drh
|
1710 |
** Return a pointer to a specific Setting entry for the setting named |
|
f646537…
|
drh
|
1711 |
** in the argument. Or return NULL if no such setting exists. |
|
f646537…
|
drh
|
1712 |
** |
|
f646537…
|
drh
|
1713 |
** The pointer returned points into the middle of the global aSetting[] |
|
f646537…
|
drh
|
1714 |
** array that is generated by mkindex. Use setting_info() to fetch the |
|
f646537…
|
drh
|
1715 |
** whole array. Use this routine to fetch a specific entry. |
|
f646537…
|
drh
|
1716 |
*/ |
|
f646537…
|
drh
|
1717 |
const Setting *setting_find(const char *zName){ |
|
f646537…
|
drh
|
1718 |
int iFirst = 0; |
|
f646537…
|
drh
|
1719 |
int iLast = ArraySize(aSetting)-1; |
|
f646537…
|
drh
|
1720 |
while( iFirst<=iLast ){ |
|
f646537…
|
drh
|
1721 |
int iCur = (iFirst+iLast)/2; |
|
f646537…
|
drh
|
1722 |
int c = strcmp(aSetting[iCur].name, zName); |
|
f646537…
|
drh
|
1723 |
if( c<0 ){ |
|
f646537…
|
drh
|
1724 |
iFirst = iCur+1; |
|
f646537…
|
drh
|
1725 |
}else if( c>0 ){ |
|
f646537…
|
drh
|
1726 |
iLast = iCur-1; |
|
f646537…
|
drh
|
1727 |
}else{ |
|
f646537…
|
drh
|
1728 |
return &aSetting[iCur]; |
|
f646537…
|
drh
|
1729 |
} |
|
f646537…
|
drh
|
1730 |
} |
|
f646537…
|
drh
|
1731 |
return 0; |
|
b2dacfc…
|
drh
|
1732 |
} |
|
b2dacfc…
|
drh
|
1733 |
|
|
b2dacfc…
|
drh
|
1734 |
/***************************************************************************** |
|
b2dacfc…
|
drh
|
1735 |
** A virtual table for accessing the information in aCommand[], and |
|
b2dacfc…
|
drh
|
1736 |
** especially the help-text |
|
b2dacfc…
|
drh
|
1737 |
*/ |
|
b2dacfc…
|
drh
|
1738 |
|
|
b2dacfc…
|
drh
|
1739 |
/* helptextVtab_vtab is a subclass of sqlite3_vtab which is |
|
b2dacfc…
|
drh
|
1740 |
** underlying representation of the virtual table |
|
b2dacfc…
|
drh
|
1741 |
*/ |
|
b2dacfc…
|
drh
|
1742 |
typedef struct helptextVtab_vtab helptextVtab_vtab; |
|
b2dacfc…
|
drh
|
1743 |
struct helptextVtab_vtab { |
|
b2dacfc…
|
drh
|
1744 |
sqlite3_vtab base; /* Base class - must be first */ |
|
b2dacfc…
|
drh
|
1745 |
/* Add new fields here, as necessary */ |
|
b2dacfc…
|
drh
|
1746 |
}; |
|
b2dacfc…
|
drh
|
1747 |
|
|
b2dacfc…
|
drh
|
1748 |
/* helptextVtab_cursor is a subclass of sqlite3_vtab_cursor which will |
|
b2dacfc…
|
drh
|
1749 |
** serve as the underlying representation of a cursor that scans |
|
b2dacfc…
|
drh
|
1750 |
** over rows of the result |
|
b2dacfc…
|
drh
|
1751 |
*/ |
|
b2dacfc…
|
drh
|
1752 |
typedef struct helptextVtab_cursor helptextVtab_cursor; |
|
b2dacfc…
|
drh
|
1753 |
struct helptextVtab_cursor { |
|
b2dacfc…
|
drh
|
1754 |
sqlite3_vtab_cursor base; /* Base class - must be first */ |
|
b2dacfc…
|
drh
|
1755 |
/* Insert new fields here. For this helptextVtab we only keep track |
|
b2dacfc…
|
drh
|
1756 |
** of the rowid */ |
|
b2dacfc…
|
drh
|
1757 |
sqlite3_int64 iRowid; /* The rowid */ |
|
b2dacfc…
|
drh
|
1758 |
}; |
|
b2dacfc…
|
drh
|
1759 |
|
|
b2dacfc…
|
drh
|
1760 |
/* |
|
b2dacfc…
|
drh
|
1761 |
** The helptextVtabConnect() method is invoked to create a new |
|
b2dacfc…
|
drh
|
1762 |
** helptext virtual table. |
|
b2dacfc…
|
drh
|
1763 |
** |
|
b2dacfc…
|
drh
|
1764 |
** Think of this routine as the constructor for helptextVtab_vtab objects. |
|
b2dacfc…
|
drh
|
1765 |
** |
|
b2dacfc…
|
drh
|
1766 |
** All this routine needs to do is: |
|
b2dacfc…
|
drh
|
1767 |
** |
|
b2dacfc…
|
drh
|
1768 |
** (1) Allocate the helptextVtab_vtab object and initialize all fields. |
|
b2dacfc…
|
drh
|
1769 |
** |
|
b2dacfc…
|
drh
|
1770 |
** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the |
|
b2dacfc…
|
drh
|
1771 |
** result set of queries against the virtual table will look like. |
|
b2dacfc…
|
drh
|
1772 |
*/ |
|
b2dacfc…
|
drh
|
1773 |
static int helptextVtabConnect( |
|
b2dacfc…
|
drh
|
1774 |
sqlite3 *db, |
|
b2dacfc…
|
drh
|
1775 |
void *pAux, |
|
b2dacfc…
|
drh
|
1776 |
int argc, const char *const*argv, |
|
b2dacfc…
|
drh
|
1777 |
sqlite3_vtab **ppVtab, |
|
b2dacfc…
|
drh
|
1778 |
char **pzErr |
|
b2dacfc…
|
drh
|
1779 |
){ |
|
b2dacfc…
|
drh
|
1780 |
helptextVtab_vtab *pNew; |
|
b2dacfc…
|
drh
|
1781 |
int rc; |
|
b2dacfc…
|
drh
|
1782 |
|
|
b2dacfc…
|
drh
|
1783 |
rc = sqlite3_declare_vtab(db, |
|
53adb7d…
|
drh
|
1784 |
"CREATE TABLE x(name,type,flags,helptext,formatted,html)" |
|
b2dacfc…
|
drh
|
1785 |
); |
|
b2dacfc…
|
drh
|
1786 |
if( rc==SQLITE_OK ){ |
|
b2dacfc…
|
drh
|
1787 |
pNew = sqlite3_malloc( sizeof(*pNew) ); |
|
b2dacfc…
|
drh
|
1788 |
*ppVtab = (sqlite3_vtab*)pNew; |
|
b2dacfc…
|
drh
|
1789 |
if( pNew==0 ) return SQLITE_NOMEM; |
|
b2dacfc…
|
drh
|
1790 |
memset(pNew, 0, sizeof(*pNew)); |
|
b2dacfc…
|
drh
|
1791 |
} |
|
b2dacfc…
|
drh
|
1792 |
return rc; |
|
b2dacfc…
|
drh
|
1793 |
} |
|
b2dacfc…
|
drh
|
1794 |
|
|
b2dacfc…
|
drh
|
1795 |
/* |
|
b2dacfc…
|
drh
|
1796 |
** This method is the destructor for helptextVtab_vtab objects. |
|
b2dacfc…
|
drh
|
1797 |
*/ |
|
b2dacfc…
|
drh
|
1798 |
static int helptextVtabDisconnect(sqlite3_vtab *pVtab){ |
|
b2dacfc…
|
drh
|
1799 |
helptextVtab_vtab *p = (helptextVtab_vtab*)pVtab; |
|
b2dacfc…
|
drh
|
1800 |
sqlite3_free(p); |
|
b2dacfc…
|
drh
|
1801 |
return SQLITE_OK; |
|
b2dacfc…
|
drh
|
1802 |
} |
|
b2dacfc…
|
drh
|
1803 |
|
|
b2dacfc…
|
drh
|
1804 |
/* |
|
b2dacfc…
|
drh
|
1805 |
** Constructor for a new helptextVtab_cursor object. |
|
b2dacfc…
|
drh
|
1806 |
*/ |
|
b2dacfc…
|
drh
|
1807 |
static int helptextVtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ |
|
b2dacfc…
|
drh
|
1808 |
helptextVtab_cursor *pCur; |
|
b2dacfc…
|
drh
|
1809 |
pCur = sqlite3_malloc( sizeof(*pCur) ); |
|
b2dacfc…
|
drh
|
1810 |
if( pCur==0 ) return SQLITE_NOMEM; |
|
b2dacfc…
|
drh
|
1811 |
memset(pCur, 0, sizeof(*pCur)); |
|
b2dacfc…
|
drh
|
1812 |
*ppCursor = &pCur->base; |
|
b2dacfc…
|
drh
|
1813 |
return SQLITE_OK; |
|
b2dacfc…
|
drh
|
1814 |
} |
|
b2dacfc…
|
drh
|
1815 |
|
|
b2dacfc…
|
drh
|
1816 |
/* |
|
b2dacfc…
|
drh
|
1817 |
** Destructor for a helptextVtab_cursor. |
|
b2dacfc…
|
drh
|
1818 |
*/ |
|
b2dacfc…
|
drh
|
1819 |
static int helptextVtabClose(sqlite3_vtab_cursor *cur){ |
|
b2dacfc…
|
drh
|
1820 |
helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; |
|
b2dacfc…
|
drh
|
1821 |
sqlite3_free(pCur); |
|
b2dacfc…
|
drh
|
1822 |
return SQLITE_OK; |
|
b2dacfc…
|
drh
|
1823 |
} |
|
b2dacfc…
|
drh
|
1824 |
|
|
b2dacfc…
|
drh
|
1825 |
|
|
b2dacfc…
|
drh
|
1826 |
/* |
|
b2dacfc…
|
drh
|
1827 |
** Advance a helptextVtab_cursor to its next row of output. |
|
b2dacfc…
|
drh
|
1828 |
*/ |
|
b2dacfc…
|
drh
|
1829 |
static int helptextVtabNext(sqlite3_vtab_cursor *cur){ |
|
b2dacfc…
|
drh
|
1830 |
helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; |
|
b2dacfc…
|
drh
|
1831 |
pCur->iRowid++; |
|
b2dacfc…
|
drh
|
1832 |
return SQLITE_OK; |
|
b2dacfc…
|
drh
|
1833 |
} |
|
b2dacfc…
|
drh
|
1834 |
|
|
b2dacfc…
|
drh
|
1835 |
/* |
|
b2dacfc…
|
drh
|
1836 |
** Return values of columns for the row at which the helptextVtab_cursor |
|
b2dacfc…
|
drh
|
1837 |
** is currently pointing. |
|
b2dacfc…
|
drh
|
1838 |
*/ |
|
b2dacfc…
|
drh
|
1839 |
static int helptextVtabColumn( |
|
b2dacfc…
|
drh
|
1840 |
sqlite3_vtab_cursor *cur, /* The cursor */ |
|
b2dacfc…
|
drh
|
1841 |
sqlite3_context *ctx, /* First argument to sqlite3_result_...() */ |
|
b2dacfc…
|
drh
|
1842 |
int i /* Which column to return */ |
|
b2dacfc…
|
drh
|
1843 |
){ |
|
b2dacfc…
|
drh
|
1844 |
helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; |
|
b2dacfc…
|
drh
|
1845 |
const CmdOrPage *pPage = aCommand + pCur->iRowid; |
|
b2dacfc…
|
drh
|
1846 |
switch( i ){ |
|
b2dacfc…
|
drh
|
1847 |
case 0: /* name */ |
|
b2dacfc…
|
drh
|
1848 |
sqlite3_result_text(ctx, pPage->zName, -1, SQLITE_STATIC); |
|
b2dacfc…
|
drh
|
1849 |
break; |
|
b2dacfc…
|
drh
|
1850 |
case 1: { /* type */ |
|
b2dacfc…
|
drh
|
1851 |
const char *zType = 0; |
|
b2dacfc…
|
drh
|
1852 |
if( pPage->eCmdFlags & CMDFLAG_COMMAND ){ |
|
b2dacfc…
|
drh
|
1853 |
zType = "command"; |
|
b2dacfc…
|
drh
|
1854 |
}else if( pPage->eCmdFlags & CMDFLAG_WEBPAGE ){ |
|
b2dacfc…
|
drh
|
1855 |
zType = "webpage"; |
|
b2dacfc…
|
drh
|
1856 |
}else if( pPage->eCmdFlags & CMDFLAG_SETTING ){ |
|
b2dacfc…
|
drh
|
1857 |
zType = "setting"; |
|
6eeb27a…
|
drh
|
1858 |
}else if( pPage->eCmdFlags & CMDFLAG_TOPIC ){ |
|
6eeb27a…
|
drh
|
1859 |
zType = "help-topic"; |
|
b2dacfc…
|
drh
|
1860 |
} |
|
b2dacfc…
|
drh
|
1861 |
sqlite3_result_text(ctx, zType, -1, SQLITE_STATIC); |
|
b2dacfc…
|
drh
|
1862 |
break; |
|
b2dacfc…
|
drh
|
1863 |
} |
|
b2dacfc…
|
drh
|
1864 |
case 2: /* flags */ |
|
b2dacfc…
|
drh
|
1865 |
sqlite3_result_int(ctx, pPage->eCmdFlags); |
|
b2dacfc…
|
drh
|
1866 |
break; |
|
b2dacfc…
|
drh
|
1867 |
case 3: /* helptext */ |
|
b2dacfc…
|
drh
|
1868 |
sqlite3_result_text(ctx, pPage->zHelp, -1, SQLITE_STATIC); |
|
b2dacfc…
|
drh
|
1869 |
break; |
|
53adb7d…
|
drh
|
1870 |
case 4: { /* formatted */ |
|
53adb7d…
|
drh
|
1871 |
Blob txt; |
|
53adb7d…
|
drh
|
1872 |
blob_init(&txt, 0, 0); |
|
62cb8ea…
|
drh
|
1873 |
help_to_text(pPage->zHelp, &txt, 0); |
|
53adb7d…
|
drh
|
1874 |
sqlite3_result_text(ctx, blob_str(&txt), -1, fossil_free); |
|
53adb7d…
|
drh
|
1875 |
break; |
|
53adb7d…
|
drh
|
1876 |
} |
|
53adb7d…
|
drh
|
1877 |
case 5: { /* formatted */ |
|
53adb7d…
|
drh
|
1878 |
Blob txt; |
|
53adb7d…
|
drh
|
1879 |
blob_init(&txt, 0, 0); |
|
53adb7d…
|
drh
|
1880 |
help_to_html(pPage->zHelp, &txt); |
|
53adb7d…
|
drh
|
1881 |
sqlite3_result_text(ctx, blob_str(&txt), -1, fossil_free); |
|
53adb7d…
|
drh
|
1882 |
break; |
|
53adb7d…
|
drh
|
1883 |
} |
|
b2dacfc…
|
drh
|
1884 |
} |
|
b2dacfc…
|
drh
|
1885 |
return SQLITE_OK; |
|
b2dacfc…
|
drh
|
1886 |
} |
|
b2dacfc…
|
drh
|
1887 |
|
|
b2dacfc…
|
drh
|
1888 |
/* |
|
b2dacfc…
|
drh
|
1889 |
** Return the rowid for the current row. In this implementation, the |
|
b2dacfc…
|
drh
|
1890 |
** rowid is the same as the output value. |
|
b2dacfc…
|
drh
|
1891 |
*/ |
|
b2dacfc…
|
drh
|
1892 |
static int helptextVtabRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){ |
|
b2dacfc…
|
drh
|
1893 |
helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; |
|
b2dacfc…
|
drh
|
1894 |
*pRowid = pCur->iRowid; |
|
b2dacfc…
|
drh
|
1895 |
return SQLITE_OK; |
|
b2dacfc…
|
drh
|
1896 |
} |
|
b2dacfc…
|
drh
|
1897 |
|
|
b2dacfc…
|
drh
|
1898 |
/* |
|
b2dacfc…
|
drh
|
1899 |
** Return TRUE if the cursor has been moved off of the last |
|
b2dacfc…
|
drh
|
1900 |
** row of output. |
|
b2dacfc…
|
drh
|
1901 |
*/ |
|
b2dacfc…
|
drh
|
1902 |
static int helptextVtabEof(sqlite3_vtab_cursor *cur){ |
|
b2dacfc…
|
drh
|
1903 |
helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; |
|
b2dacfc…
|
drh
|
1904 |
return pCur->iRowid>=MX_COMMAND; |
|
b2dacfc…
|
drh
|
1905 |
} |
|
b2dacfc…
|
drh
|
1906 |
|
|
b2dacfc…
|
drh
|
1907 |
/* |
|
b2dacfc…
|
drh
|
1908 |
** This method is called to "rewind" the helptextVtab_cursor object back |
|
b2dacfc…
|
drh
|
1909 |
** to the first row of output. This method is always called at least |
|
275da70…
|
danield
|
1910 |
** once prior to any call to helptextVtabColumn() or helptextVtabRowid() or |
|
b2dacfc…
|
drh
|
1911 |
** helptextVtabEof(). |
|
b2dacfc…
|
drh
|
1912 |
*/ |
|
b2dacfc…
|
drh
|
1913 |
static int helptextVtabFilter( |
|
275da70…
|
danield
|
1914 |
sqlite3_vtab_cursor *pVtabCursor, |
|
b2dacfc…
|
drh
|
1915 |
int idxNum, const char *idxStr, |
|
b2dacfc…
|
drh
|
1916 |
int argc, sqlite3_value **argv |
|
b2dacfc…
|
drh
|
1917 |
){ |
|
b2dacfc…
|
drh
|
1918 |
helptextVtab_cursor *pCur = (helptextVtab_cursor *)pVtabCursor; |
|
b2dacfc…
|
drh
|
1919 |
pCur->iRowid = 1; |
|
b2dacfc…
|
drh
|
1920 |
return SQLITE_OK; |
|
b2dacfc…
|
drh
|
1921 |
} |
|
b2dacfc…
|
drh
|
1922 |
|
|
b2dacfc…
|
drh
|
1923 |
/* |
|
b2dacfc…
|
drh
|
1924 |
** SQLite will invoke this method one or more times while planning a query |
|
b2dacfc…
|
drh
|
1925 |
** that uses the virtual table. This routine needs to create |
|
b2dacfc…
|
drh
|
1926 |
** a query plan for each invocation and compute an estimated cost for that |
|
b2dacfc…
|
drh
|
1927 |
** plan. |
|
b2dacfc…
|
drh
|
1928 |
*/ |
|
b2dacfc…
|
drh
|
1929 |
static int helptextVtabBestIndex( |
|
b2dacfc…
|
drh
|
1930 |
sqlite3_vtab *tab, |
|
b2dacfc…
|
drh
|
1931 |
sqlite3_index_info *pIdxInfo |
|
b2dacfc…
|
drh
|
1932 |
){ |
|
b2dacfc…
|
drh
|
1933 |
pIdxInfo->estimatedCost = (double)MX_COMMAND; |
|
b2dacfc…
|
drh
|
1934 |
pIdxInfo->estimatedRows = MX_COMMAND; |
|
b2dacfc…
|
drh
|
1935 |
return SQLITE_OK; |
|
b2dacfc…
|
drh
|
1936 |
} |
|
b2dacfc…
|
drh
|
1937 |
|
|
b2dacfc…
|
drh
|
1938 |
/* |
|
275da70…
|
danield
|
1939 |
** This following structure defines all the methods for the |
|
b2dacfc…
|
drh
|
1940 |
** virtual table. |
|
b2dacfc…
|
drh
|
1941 |
*/ |
|
b2dacfc…
|
drh
|
1942 |
static sqlite3_module helptextVtabModule = { |
|
b2dacfc…
|
drh
|
1943 |
/* iVersion */ 0, |
|
b2dacfc…
|
drh
|
1944 |
/* xCreate */ 0, /* Helptext is eponymous and read-only */ |
|
b2dacfc…
|
drh
|
1945 |
/* xConnect */ helptextVtabConnect, |
|
b2dacfc…
|
drh
|
1946 |
/* xBestIndex */ helptextVtabBestIndex, |
|
b2dacfc…
|
drh
|
1947 |
/* xDisconnect */ helptextVtabDisconnect, |
|
b2dacfc…
|
drh
|
1948 |
/* xDestroy */ 0, |
|
b2dacfc…
|
drh
|
1949 |
/* xOpen */ helptextVtabOpen, |
|
b2dacfc…
|
drh
|
1950 |
/* xClose */ helptextVtabClose, |
|
b2dacfc…
|
drh
|
1951 |
/* xFilter */ helptextVtabFilter, |
|
b2dacfc…
|
drh
|
1952 |
/* xNext */ helptextVtabNext, |
|
b2dacfc…
|
drh
|
1953 |
/* xEof */ helptextVtabEof, |
|
b2dacfc…
|
drh
|
1954 |
/* xColumn */ helptextVtabColumn, |
|
b2dacfc…
|
drh
|
1955 |
/* xRowid */ helptextVtabRowid, |
|
b2dacfc…
|
drh
|
1956 |
/* xUpdate */ 0, |
|
b2dacfc…
|
drh
|
1957 |
/* xBegin */ 0, |
|
b2dacfc…
|
drh
|
1958 |
/* xSync */ 0, |
|
b2dacfc…
|
drh
|
1959 |
/* xCommit */ 0, |
|
b2dacfc…
|
drh
|
1960 |
/* xRollback */ 0, |
|
b2dacfc…
|
drh
|
1961 |
/* xFindMethod */ 0, |
|
b2dacfc…
|
drh
|
1962 |
/* xRename */ 0, |
|
b2dacfc…
|
drh
|
1963 |
/* xSavepoint */ 0, |
|
b2dacfc…
|
drh
|
1964 |
/* xRelease */ 0, |
|
b2dacfc…
|
drh
|
1965 |
/* xRollbackTo */ 0, |
|
ab05475…
|
danield
|
1966 |
/* xShadowName */ 0, |
|
ab05475…
|
danield
|
1967 |
/* xIntegrity */ 0 |
|
b2dacfc…
|
drh
|
1968 |
}; |
|
b2dacfc…
|
drh
|
1969 |
|
|
b2dacfc…
|
drh
|
1970 |
|
|
b2dacfc…
|
drh
|
1971 |
/* |
|
b2dacfc…
|
drh
|
1972 |
** Register the helptext virtual table |
|
b2dacfc…
|
drh
|
1973 |
*/ |
|
b2dacfc…
|
drh
|
1974 |
int helptext_vtab_register(sqlite3 *db){ |
|
b2dacfc…
|
drh
|
1975 |
int rc = sqlite3_create_module(db, "helptext", &helptextVtabModule, 0); |
|
b2dacfc…
|
drh
|
1976 |
return rc; |
|
b2dacfc…
|
drh
|
1977 |
} |
|
b2dacfc…
|
drh
|
1978 |
/* End of the helptext virtual table |
|
b2dacfc…
|
drh
|
1979 |
******************************************************************************/ |