Fossil SCM

New TH1 command: wikicontent Placed in its own branch for posterity.

bcsmith 2010-10-10 19:07 trunk
Commit 6916054dc87d1fca89cfd8183af9e3f4f9ebbd13
1 file changed +43
--- src/th_main.c
+++ src/th_main.c
@@ -141,10 +141,52 @@
141141
wiki_convert(&src, 0, WIKI_INLINE);
142142
blob_reset(&src);
143143
}
144144
return TH_OK;
145145
}
146
+
147
+/*
148
+** TH command: wikicontent WIKIPAGE_NAME FALLBACK_TEXT
149
+**
150
+** Output the contents of the wiki page named by the input string.
151
+** If WIKIPAGE_NAME does not exist, then FALLBACK_TEXT is used, instead.
152
+*/
153
+static int wikiContentCmd(
154
+ Th_Interp *interp,
155
+ void *p,
156
+ int argc,
157
+ const char **argv,
158
+ int *argl
159
+){
160
+ if( argc!=3 ){
161
+ return Th_WrongNumArgs(interp, "wikicontent WIKIPAGE_NAME FALLBACK_TEXT");
162
+ }
163
+ if( enableOutput ){
164
+ int rid;
165
+ Blob content;
166
+ Manifest m;
167
+ rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
168
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
169
+ " ORDER BY x.mtime DESC LIMIT 1",
170
+ argv[1]
171
+ );
172
+ if( content_get(rid, &content) ){
173
+ manifest_parse(&m, &content);
174
+ if( m.type == CFTYPE_WIKI ){
175
+ Th_SetResult(interp, m.zWiki, -1);
176
+ manifest_clear(&m);
177
+ }
178
+ else {
179
+ return TH_ERROR;
180
+ }
181
+ }
182
+ else {
183
+ Th_SetResult(interp, (char*)argv[2], argl[2]);
184
+ }
185
+ }
186
+ return TH_OK;
187
+}
146188
147189
/*
148190
** TH command: htmlize STRING
149191
**
150192
** Escape all characters of STRING which have special meaning in HTML.
@@ -350,10 +392,11 @@
350392
{"htmlize", htmlizeCmd, 0},
351393
{"date", dateCmd, 0},
352394
{"html", putsCmd, 0},
353395
{"puts", putsCmd, (void*)1},
354396
{"wiki", wikiCmd, 0},
397
+ {"wikicontent", wikiContentCmd, 0},
355398
};
356399
if( g.interp==0 ){
357400
int i;
358401
g.interp = Th_CreateInterp(&vtab);
359402
th_register_language(g.interp); /* Basic scripting commands. */
360403
--- src/th_main.c
+++ src/th_main.c
@@ -141,10 +141,52 @@
141 wiki_convert(&src, 0, WIKI_INLINE);
142 blob_reset(&src);
143 }
144 return TH_OK;
145 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
147 /*
148 ** TH command: htmlize STRING
149 **
150 ** Escape all characters of STRING which have special meaning in HTML.
@@ -350,10 +392,11 @@
350 {"htmlize", htmlizeCmd, 0},
351 {"date", dateCmd, 0},
352 {"html", putsCmd, 0},
353 {"puts", putsCmd, (void*)1},
354 {"wiki", wikiCmd, 0},
 
355 };
356 if( g.interp==0 ){
357 int i;
358 g.interp = Th_CreateInterp(&vtab);
359 th_register_language(g.interp); /* Basic scripting commands. */
360
--- src/th_main.c
+++ src/th_main.c
@@ -141,10 +141,52 @@
141 wiki_convert(&src, 0, WIKI_INLINE);
142 blob_reset(&src);
143 }
144 return TH_OK;
145 }
146
147 /*
148 ** TH command: wikicontent WIKIPAGE_NAME FALLBACK_TEXT
149 **
150 ** Output the contents of the wiki page named by the input string.
151 ** If WIKIPAGE_NAME does not exist, then FALLBACK_TEXT is used, instead.
152 */
153 static int wikiContentCmd(
154 Th_Interp *interp,
155 void *p,
156 int argc,
157 const char **argv,
158 int *argl
159 ){
160 if( argc!=3 ){
161 return Th_WrongNumArgs(interp, "wikicontent WIKIPAGE_NAME FALLBACK_TEXT");
162 }
163 if( enableOutput ){
164 int rid;
165 Blob content;
166 Manifest m;
167 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
168 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
169 " ORDER BY x.mtime DESC LIMIT 1",
170 argv[1]
171 );
172 if( content_get(rid, &content) ){
173 manifest_parse(&m, &content);
174 if( m.type == CFTYPE_WIKI ){
175 Th_SetResult(interp, m.zWiki, -1);
176 manifest_clear(&m);
177 }
178 else {
179 return TH_ERROR;
180 }
181 }
182 else {
183 Th_SetResult(interp, (char*)argv[2], argl[2]);
184 }
185 }
186 return TH_OK;
187 }
188
189 /*
190 ** TH command: htmlize STRING
191 **
192 ** Escape all characters of STRING which have special meaning in HTML.
@@ -350,10 +392,11 @@
392 {"htmlize", htmlizeCmd, 0},
393 {"date", dateCmd, 0},
394 {"html", putsCmd, 0},
395 {"puts", putsCmd, (void*)1},
396 {"wiki", wikiCmd, 0},
397 {"wikicontent", wikiContentCmd, 0},
398 };
399 if( g.interp==0 ){
400 int i;
401 g.interp = Th_CreateInterp(&vtab);
402 th_register_language(g.interp); /* Basic scripting commands. */
403

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button