Fossil SCM

Add the 'redirect' command to TH1.

mistachkin 2016-01-30 21:40 trunk
Commit 71caba53bdc3d71fc08745341a9c52537c123a2c
2 files changed +22 +8
--- src/th_main.c
+++ src/th_main.c
@@ -430,10 +430,31 @@
430430
return Th_WrongNumArgs(interp, "puts STRING");
431431
}
432432
sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
433433
return TH_OK;
434434
}
435
+
436
+/*
437
+** TH1 command: redirect URL
438
+**
439
+** Issues an HTTP redirect (302) to the specified URL and then exits the
440
+** process.
441
+*/
442
+static int redirectCmd(
443
+ Th_Interp *interp,
444
+ void *p,
445
+ int argc,
446
+ const char **argv,
447
+ int *argl
448
+){
449
+ if( argc!=2 ){
450
+ return Th_WrongNumArgs(interp, "redirect URL");
451
+ }
452
+ cgi_redirect(argv[1]);
453
+ Th_SetResult(interp, argv[1], argl[1]); /* NOT REACHED */
454
+ return TH_OK;
455
+}
435456
436457
/*
437458
** TH1 command: markdown STRING
438459
**
439460
** Renders the input string as markdown. The result is a two-element list.
@@ -1772,10 +1793,11 @@
17721793
{"linecount", linecntCmd, 0},
17731794
{"markdown", markdownCmd, 0},
17741795
{"puts", putsCmd, (void*)&aFlags[1]},
17751796
{"query", queryCmd, 0},
17761797
{"randhex", randhexCmd, 0},
1798
+ {"redirect", redirectCmd, 0},
17771799
{"regexp", regexpCmd, 0},
17781800
{"reinitialize", reinitializeCmd, 0},
17791801
{"render", renderCmd, 0},
17801802
{"repository", repositoryCmd, 0},
17811803
{"searchable", searchableCmd, 0},
17821804
--- src/th_main.c
+++ src/th_main.c
@@ -430,10 +430,31 @@
430 return Th_WrongNumArgs(interp, "puts STRING");
431 }
432 sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
433 return TH_OK;
434 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
436 /*
437 ** TH1 command: markdown STRING
438 **
439 ** Renders the input string as markdown. The result is a two-element list.
@@ -1772,10 +1793,11 @@
1772 {"linecount", linecntCmd, 0},
1773 {"markdown", markdownCmd, 0},
1774 {"puts", putsCmd, (void*)&aFlags[1]},
1775 {"query", queryCmd, 0},
1776 {"randhex", randhexCmd, 0},
 
1777 {"regexp", regexpCmd, 0},
1778 {"reinitialize", reinitializeCmd, 0},
1779 {"render", renderCmd, 0},
1780 {"repository", repositoryCmd, 0},
1781 {"searchable", searchableCmd, 0},
1782
--- src/th_main.c
+++ src/th_main.c
@@ -430,10 +430,31 @@
430 return Th_WrongNumArgs(interp, "puts STRING");
431 }
432 sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
433 return TH_OK;
434 }
435
436 /*
437 ** TH1 command: redirect URL
438 **
439 ** Issues an HTTP redirect (302) to the specified URL and then exits the
440 ** process.
441 */
442 static int redirectCmd(
443 Th_Interp *interp,
444 void *p,
445 int argc,
446 const char **argv,
447 int *argl
448 ){
449 if( argc!=2 ){
450 return Th_WrongNumArgs(interp, "redirect URL");
451 }
452 cgi_redirect(argv[1]);
453 Th_SetResult(interp, argv[1], argl[1]); /* NOT REACHED */
454 return TH_OK;
455 }
456
457 /*
458 ** TH1 command: markdown STRING
459 **
460 ** Renders the input string as markdown. The result is a two-element list.
@@ -1772,10 +1793,11 @@
1793 {"linecount", linecntCmd, 0},
1794 {"markdown", markdownCmd, 0},
1795 {"puts", putsCmd, (void*)&aFlags[1]},
1796 {"query", queryCmd, 0},
1797 {"randhex", randhexCmd, 0},
1798 {"redirect", redirectCmd, 0},
1799 {"regexp", regexpCmd, 0},
1800 {"reinitialize", reinitializeCmd, 0},
1801 {"render", renderCmd, 0},
1802 {"repository", repositoryCmd, 0},
1803 {"searchable", searchableCmd, 0},
1804
+8
--- www/th1.md
+++ www/th1.md
@@ -422,10 +422,18 @@
422422
423423
* randhex N
424424
425425
Returns a string of N*2 random hexadecimal digits with N<50. If N is
426426
omitted, use a value of 10.
427
+
428
+<a name="redirect"></a>TH1 redirect Command
429
+-------------------------------------------
430
+
431
+ * redirect URL
432
+
433
+Issues an HTTP redirect (302) to the specified URL and then exits the
434
+process.
427435
428436
<a name="regexp"></a>TH1 regexp Command
429437
---------------------------------------
430438
431439
* regexp ?-nocase? ?--? exp string
432440
--- www/th1.md
+++ www/th1.md
@@ -422,10 +422,18 @@
422
423 * randhex N
424
425 Returns a string of N*2 random hexadecimal digits with N<50. If N is
426 omitted, use a value of 10.
 
 
 
 
 
 
 
 
427
428 <a name="regexp"></a>TH1 regexp Command
429 ---------------------------------------
430
431 * regexp ?-nocase? ?--? exp string
432
--- www/th1.md
+++ www/th1.md
@@ -422,10 +422,18 @@
422
423 * randhex N
424
425 Returns a string of N*2 random hexadecimal digits with N<50. If N is
426 omitted, use a value of 10.
427
428 <a name="redirect"></a>TH1 redirect Command
429 -------------------------------------------
430
431 * redirect URL
432
433 Issues an HTTP redirect (302) to the specified URL and then exits the
434 process.
435
436 <a name="regexp"></a>TH1 regexp Command
437 ---------------------------------------
438
439 * regexp ?-nocase? ?--? exp string
440

Keyboard Shortcuts

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