Fossil SCM
Add the 'getParameter' and 'setParameter' TH1 commands.
Commit
40c11955383fcc0914e750d0f3d2b5d52597b8b6
Parent
c18ff5d0051370d…
2 files changed
+45
+37
+45
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -621,10 +621,53 @@ | ||
| 621 | 621 | Th_Trace("%s", argv[1]); |
| 622 | 622 | } |
| 623 | 623 | Th_SetResult(interp, 0, 0); |
| 624 | 624 | return TH_OK; |
| 625 | 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 | +} | |
| 626 | 669 | |
| 627 | 670 | /* |
| 628 | 671 | ** TH1 command: render STRING |
| 629 | 672 | ** |
| 630 | 673 | ** Renders the template and writes the results. |
| @@ -1116,10 +1159,11 @@ | ||
| 1116 | 1159 | {"checkout", checkoutCmd, 0}, |
| 1117 | 1160 | {"combobox", comboboxCmd, 0}, |
| 1118 | 1161 | {"date", dateCmd, 0}, |
| 1119 | 1162 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 1120 | 1163 | {"enable_output", enableOutputCmd, 0}, |
| 1164 | + {"getParameter", getParameterCmd, 0}, | |
| 1121 | 1165 | {"httpize", httpizeCmd, 0}, |
| 1122 | 1166 | {"hascap", hascapCmd, 0}, |
| 1123 | 1167 | {"hasfeature", hasfeatureCmd, 0}, |
| 1124 | 1168 | {"html", putsCmd, (void*)&aFlags[0]}, |
| 1125 | 1169 | {"htmlize", htmlizeCmd, 0}, |
| @@ -1129,10 +1173,11 @@ | ||
| 1129 | 1173 | {"query", queryCmd, 0}, |
| 1130 | 1174 | {"randhex", randhexCmd, 0}, |
| 1131 | 1175 | {"regexp", regexpCmd, 0}, |
| 1132 | 1176 | {"render", renderCmd, 0}, |
| 1133 | 1177 | {"repository", repositoryCmd, 0}, |
| 1178 | + {"setParameter", setParameterCmd, 0}, | |
| 1134 | 1179 | {"setting", settingCmd, 0}, |
| 1135 | 1180 | {"styleHeader", styleHeaderCmd, 0}, |
| 1136 | 1181 | {"styleFooter", styleFooterCmd, 0}, |
| 1137 | 1182 | {"tclReady", tclReadyCmd, 0}, |
| 1138 | 1183 | {"trace", traceCmd, 0}, |
| 1139 | 1184 |
| --- 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 |
+37
| --- test/th1.test | ||
| +++ test/th1.test | ||
| @@ -554,5 +554,42 @@ | ||
| 554 | 554 | |
| 555 | 555 | ############################################################################### |
| 556 | 556 | |
| 557 | 557 | fossil test-th-eval --th-open-config "styleFooter" |
| 558 | 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}} | |
| 559 | 596 |
| --- 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 |