Fossil SCM

Add the 'getParameter' and 'setParameter' TH1 commands.

mistachkin 2014-06-10 23:12 UTC th1Cmds
Commit 40c11955383fcc0914e750d0f3d2b5d52597b8b6
2 files changed +45 +37
--- src/th_main.c
+++ src/th_main.c
@@ -621,10 +621,53 @@
621621
Th_Trace("%s", argv[1]);
622622
}
623623
Th_SetResult(interp, 0, 0);
624624
return TH_OK;
625625
}
626
+
627
+/*
628
+** TH1 command: getParameter NAME ?DEFAULT?
629
+**
630
+** Return the value of the specified query parameter or the specified default
631
+** value when there is no matching query parameter.
632
+*/
633
+static int getParameterCmd(
634
+ Th_Interp *interp,
635
+ void *p,
636
+ int argc,
637
+ const char **argv,
638
+ int *argl
639
+){
640
+ const char *zDefault = 0;
641
+ if( argc!=2 && argc!=3 ){
642
+ return Th_WrongNumArgs(interp, "getParameter NAME ?DEFAULT?");
643
+ }
644
+ if( argc==3 ){
645
+ zDefault = argv[2];
646
+ }
647
+ Th_SetResult(interp, cgi_parameter(argv[1], zDefault), -1);
648
+ return TH_OK;
649
+}
650
+
651
+/*
652
+** TH1 command: setParameter NAME VALUE
653
+**
654
+** Sets the value of the specified query parameter.
655
+*/
656
+static int setParameterCmd(
657
+ Th_Interp *interp,
658
+ void *p,
659
+ int argc,
660
+ const char **argv,
661
+ int *argl
662
+){
663
+ if( argc!=3 ){
664
+ return Th_WrongNumArgs(interp, "setParameter NAME VALUE");
665
+ }
666
+ cgi_set_parameter(argv[1], argv[2]);
667
+ return TH_OK;
668
+}
626669
627670
/*
628671
** TH1 command: render STRING
629672
**
630673
** Renders the template and writes the results.
@@ -1116,10 +1159,11 @@
11161159
{"checkout", checkoutCmd, 0},
11171160
{"combobox", comboboxCmd, 0},
11181161
{"date", dateCmd, 0},
11191162
{"decorate", wikiCmd, (void*)&aFlags[2]},
11201163
{"enable_output", enableOutputCmd, 0},
1164
+ {"getParameter", getParameterCmd, 0},
11211165
{"httpize", httpizeCmd, 0},
11221166
{"hascap", hascapCmd, 0},
11231167
{"hasfeature", hasfeatureCmd, 0},
11241168
{"html", putsCmd, (void*)&aFlags[0]},
11251169
{"htmlize", htmlizeCmd, 0},
@@ -1129,10 +1173,11 @@
11291173
{"query", queryCmd, 0},
11301174
{"randhex", randhexCmd, 0},
11311175
{"regexp", regexpCmd, 0},
11321176
{"render", renderCmd, 0},
11331177
{"repository", repositoryCmd, 0},
1178
+ {"setParameter", setParameterCmd, 0},
11341179
{"setting", settingCmd, 0},
11351180
{"styleHeader", styleHeaderCmd, 0},
11361181
{"styleFooter", styleFooterCmd, 0},
11371182
{"tclReady", tclReadyCmd, 0},
11381183
{"trace", traceCmd, 0},
11391184
--- src/th_main.c
+++ src/th_main.c
@@ -621,10 +621,53 @@
621 Th_Trace("%s", argv[1]);
622 }
623 Th_SetResult(interp, 0, 0);
624 return TH_OK;
625 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
626
627 /*
628 ** TH1 command: render STRING
629 **
630 ** Renders the template and writes the results.
@@ -1116,10 +1159,11 @@
1116 {"checkout", checkoutCmd, 0},
1117 {"combobox", comboboxCmd, 0},
1118 {"date", dateCmd, 0},
1119 {"decorate", wikiCmd, (void*)&aFlags[2]},
1120 {"enable_output", enableOutputCmd, 0},
 
1121 {"httpize", httpizeCmd, 0},
1122 {"hascap", hascapCmd, 0},
1123 {"hasfeature", hasfeatureCmd, 0},
1124 {"html", putsCmd, (void*)&aFlags[0]},
1125 {"htmlize", htmlizeCmd, 0},
@@ -1129,10 +1173,11 @@
1129 {"query", queryCmd, 0},
1130 {"randhex", randhexCmd, 0},
1131 {"regexp", regexpCmd, 0},
1132 {"render", renderCmd, 0},
1133 {"repository", repositoryCmd, 0},
 
1134 {"setting", settingCmd, 0},
1135 {"styleHeader", styleHeaderCmd, 0},
1136 {"styleFooter", styleFooterCmd, 0},
1137 {"tclReady", tclReadyCmd, 0},
1138 {"trace", traceCmd, 0},
1139
--- src/th_main.c
+++ src/th_main.c
@@ -621,10 +621,53 @@
621 Th_Trace("%s", argv[1]);
622 }
623 Th_SetResult(interp, 0, 0);
624 return TH_OK;
625 }
626
627 /*
628 ** TH1 command: getParameter NAME ?DEFAULT?
629 **
630 ** Return the value of the specified query parameter or the specified default
631 ** value when there is no matching query parameter.
632 */
633 static int getParameterCmd(
634 Th_Interp *interp,
635 void *p,
636 int argc,
637 const char **argv,
638 int *argl
639 ){
640 const char *zDefault = 0;
641 if( argc!=2 && argc!=3 ){
642 return Th_WrongNumArgs(interp, "getParameter NAME ?DEFAULT?");
643 }
644 if( argc==3 ){
645 zDefault = argv[2];
646 }
647 Th_SetResult(interp, cgi_parameter(argv[1], zDefault), -1);
648 return TH_OK;
649 }
650
651 /*
652 ** TH1 command: setParameter NAME VALUE
653 **
654 ** Sets the value of the specified query parameter.
655 */
656 static int setParameterCmd(
657 Th_Interp *interp,
658 void *p,
659 int argc,
660 const char **argv,
661 int *argl
662 ){
663 if( argc!=3 ){
664 return Th_WrongNumArgs(interp, "setParameter NAME VALUE");
665 }
666 cgi_set_parameter(argv[1], argv[2]);
667 return TH_OK;
668 }
669
670 /*
671 ** TH1 command: render STRING
672 **
673 ** Renders the template and writes the results.
@@ -1116,10 +1159,11 @@
1159 {"checkout", checkoutCmd, 0},
1160 {"combobox", comboboxCmd, 0},
1161 {"date", dateCmd, 0},
1162 {"decorate", wikiCmd, (void*)&aFlags[2]},
1163 {"enable_output", enableOutputCmd, 0},
1164 {"getParameter", getParameterCmd, 0},
1165 {"httpize", httpizeCmd, 0},
1166 {"hascap", hascapCmd, 0},
1167 {"hasfeature", hasfeatureCmd, 0},
1168 {"html", putsCmd, (void*)&aFlags[0]},
1169 {"htmlize", htmlizeCmd, 0},
@@ -1129,10 +1173,11 @@
1173 {"query", queryCmd, 0},
1174 {"randhex", randhexCmd, 0},
1175 {"regexp", regexpCmd, 0},
1176 {"render", renderCmd, 0},
1177 {"repository", repositoryCmd, 0},
1178 {"setParameter", setParameterCmd, 0},
1179 {"setting", settingCmd, 0},
1180 {"styleHeader", styleHeaderCmd, 0},
1181 {"styleFooter", styleFooterCmd, 0},
1182 {"tclReady", tclReadyCmd, 0},
1183 {"trace", traceCmd, 0},
1184
--- test/th1.test
+++ test/th1.test
@@ -554,5 +554,42 @@
554554
555555
###############################################################################
556556
557557
fossil test-th-eval --th-open-config "styleFooter"
558558
test th1-footer-2 {$RESULT eq {}}
559
+
560
+###############################################################################
561
+
562
+fossil test-th-eval "getParameter"
563
+test th1-get-parameter-1 {$RESULT eq \
564
+ {TH_ERROR: wrong # args: should be "getParameter NAME ?DEFAULT?"}}
565
+
566
+###############################################################################
567
+
568
+fossil test-th-eval "getParameter test1"
569
+test th1-get-parameter-2 {$RESULT eq {}}
570
+
571
+###############################################################################
572
+
573
+fossil test-th-eval "getParameter test1 defValue1"
574
+test th1-get-parameter-3 {$RESULT eq {defValue1}}
575
+
576
+###############################################################################
577
+
578
+fossil test-th-eval "setParameter"
579
+test th1-set-parameter-1 {$RESULT eq \
580
+ {TH_ERROR: wrong # args: should be "setParameter NAME VALUE"}}
581
+
582
+###############################################################################
583
+
584
+fossil test-th-eval "setParameter test1 value1; getParameter test1"
585
+test th1-set-parameter-2 {$RESULT eq {value1}}
586
+
587
+###############################################################################
588
+
589
+fossil test-th-eval "setParameter test2 value2; getParameter test1"
590
+test th1-set-parameter-3 {$RESULT eq {}}
591
+
592
+###############################################################################
593
+
594
+fossil test-th-eval "setParameter test3 value3; getParameter test3 defValue3"
595
+test th1-set-parameter-4 {$RESULT eq {value3}}
559596
--- test/th1.test
+++ test/th1.test
@@ -554,5 +554,42 @@
554
555 ###############################################################################
556
557 fossil test-th-eval --th-open-config "styleFooter"
558 test th1-footer-2 {$RESULT eq {}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
559
--- test/th1.test
+++ test/th1.test
@@ -554,5 +554,42 @@
554
555 ###############################################################################
556
557 fossil test-th-eval --th-open-config "styleFooter"
558 test th1-footer-2 {$RESULT eq {}}
559
560 ###############################################################################
561
562 fossil test-th-eval "getParameter"
563 test th1-get-parameter-1 {$RESULT eq \
564 {TH_ERROR: wrong # args: should be "getParameter NAME ?DEFAULT?"}}
565
566 ###############################################################################
567
568 fossil test-th-eval "getParameter test1"
569 test th1-get-parameter-2 {$RESULT eq {}}
570
571 ###############################################################################
572
573 fossil test-th-eval "getParameter test1 defValue1"
574 test th1-get-parameter-3 {$RESULT eq {defValue1}}
575
576 ###############################################################################
577
578 fossil test-th-eval "setParameter"
579 test th1-set-parameter-1 {$RESULT eq \
580 {TH_ERROR: wrong # args: should be "setParameter NAME VALUE"}}
581
582 ###############################################################################
583
584 fossil test-th-eval "setParameter test1 value1; getParameter test1"
585 test th1-set-parameter-2 {$RESULT eq {value1}}
586
587 ###############################################################################
588
589 fossil test-th-eval "setParameter test2 value2; getParameter test1"
590 test th1-set-parameter-3 {$RESULT eq {}}
591
592 ###############################################################################
593
594 fossil test-th-eval "setParameter test3 value3; getParameter test3 defValue3"
595 test th1-set-parameter-4 {$RESULT eq {value3}}
596

Keyboard Shortcuts

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