Fossil SCM
Enhancements to TH1 scripting in support of new ticket functionality.
Commit
74e3f90596ac555e2f421b0507fcb9495644588b
Parent
bf67db062dd3a20…
1 file changed
+50
-10
+50
-10
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -98,11 +98,12 @@ | ||
| 98 | 98 | return zRc; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /* |
| 102 | 102 | ** Send text to the appropriate output: Either to the console |
| 103 | -** or to the CGI reply buffer. | |
| 103 | +** or to the CGI reply buffer. Escape all characters with special | |
| 104 | +** meaning to HTML if the encode parameter is true. | |
| 104 | 105 | */ |
| 105 | 106 | static void sendText(const char *z, int n, int encode){ |
| 106 | 107 | if( enableOutput && n ){ |
| 107 | 108 | if( n<0 ) n = strlen(z); |
| 108 | 109 | if( encode ){ |
| @@ -130,11 +131,11 @@ | ||
| 130 | 131 | |
| 131 | 132 | /* |
| 132 | 133 | ** TH command: puts STRING |
| 133 | 134 | ** TH command: html STRING |
| 134 | 135 | ** |
| 135 | -** Output STRING as HTML (html) or unchanged (puts). | |
| 136 | +** Output STRING escaped for HTML (html) or unchanged (puts). | |
| 136 | 137 | */ |
| 137 | 138 | static int putsCmd( |
| 138 | 139 | Th_Interp *interp, |
| 139 | 140 | void *pConvert, |
| 140 | 141 | int argc, |
| @@ -142,11 +143,11 @@ | ||
| 142 | 143 | int *argl |
| 143 | 144 | ){ |
| 144 | 145 | if( argc!=2 ){ |
| 145 | 146 | return Th_WrongNumArgs(interp, "puts STRING"); |
| 146 | 147 | } |
| 147 | - sendText((char*)argv[1], argl[1], pConvert!=0); | |
| 148 | + sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert); | |
| 148 | 149 | return TH_OK; |
| 149 | 150 | } |
| 150 | 151 | |
| 151 | 152 | /* |
| 152 | 153 | ** TH command: wiki STRING |
| @@ -158,17 +159,18 @@ | ||
| 158 | 159 | void *p, |
| 159 | 160 | int argc, |
| 160 | 161 | const char **argv, |
| 161 | 162 | int *argl |
| 162 | 163 | ){ |
| 164 | + int flags = WIKI_INLINE | WIKI_NOBADLINKS | *(unsigned int*)p; | |
| 163 | 165 | if( argc!=2 ){ |
| 164 | 166 | return Th_WrongNumArgs(interp, "wiki STRING"); |
| 165 | 167 | } |
| 166 | 168 | if( enableOutput ){ |
| 167 | 169 | Blob src; |
| 168 | 170 | blob_init(&src, (char*)argv[1], argl[1]); |
| 169 | - wiki_convert(&src, 0, WIKI_INLINE|WIKI_NOBADLINKS); | |
| 171 | + wiki_convert(&src, 0, flags); | |
| 170 | 172 | blob_reset(&src); |
| 171 | 173 | } |
| 172 | 174 | return TH_OK; |
| 173 | 175 | } |
| 174 | 176 | |
| @@ -530,38 +532,76 @@ | ||
| 530 | 532 | sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x); |
| 531 | 533 | Th_SetResult(interp, zUTime, -1); |
| 532 | 534 | return TH_OK; |
| 533 | 535 | } |
| 534 | 536 | |
| 537 | + | |
| 538 | +/* | |
| 539 | +** TH1 command: randhex N | |
| 540 | +** | |
| 541 | +** Return N*2 random hexadecimal digits with N<50. If N is omitted, | |
| 542 | +** use a value of 10. | |
| 543 | +*/ | |
| 544 | +static int randhexCmd( | |
| 545 | + Th_Interp *interp, | |
| 546 | + void *p, | |
| 547 | + int argc, | |
| 548 | + const char **argv, | |
| 549 | + int *argl | |
| 550 | +){ | |
| 551 | + int n; | |
| 552 | + char aRand[50]; | |
| 553 | + char zOut[100]; | |
| 554 | + if( argc!=1 && argc!=2 ){ | |
| 555 | + return Th_WrongNumArgs(interp, "repository ?BOOLEAN?"); | |
| 556 | + } | |
| 557 | + if( argc==2 ){ | |
| 558 | + if( Th_ToInt(interp, argv[1], argl[1], &n) ){ | |
| 559 | + return TH_ERROR; | |
| 560 | + } | |
| 561 | + if( n<1 ) n = 1; | |
| 562 | + if( n>sizeof(aRand) ) n = sizeof(aRand); | |
| 563 | + }else{ | |
| 564 | + n = 10; | |
| 565 | + } | |
| 566 | + sqlite3_randomness(n, aRand); | |
| 567 | + encode16(aRand, zOut, n); | |
| 568 | + Th_SetResult(interp, zOut, -1); | |
| 569 | + return TH_OK; | |
| 570 | +} | |
| 571 | + | |
| 535 | 572 | |
| 536 | 573 | /* |
| 537 | 574 | ** Make sure the interpreter has been initialized. Initialize it if |
| 538 | 575 | ** it has not been already. |
| 539 | 576 | ** |
| 540 | 577 | ** The interpreter is stored in the g.interp global variable. |
| 541 | 578 | */ |
| 542 | 579 | void Th_FossilInit(int needConfig, int forceSetup){ |
| 543 | 580 | int wasInit = 0; |
| 581 | + static unsigned int aFlags[] = { 0, 1, WIKI_LINKSONLY }; | |
| 544 | 582 | static struct _Command { |
| 545 | 583 | const char *zName; |
| 546 | 584 | Th_CommandProc xProc; |
| 547 | 585 | void *pContext; |
| 548 | 586 | } aCommand[] = { |
| 549 | 587 | {"anycap", anycapCmd, 0}, |
| 550 | 588 | {"combobox", comboboxCmd, 0}, |
| 589 | + {"date", dateCmd, 0}, | |
| 590 | + {"decorate", wikiCmd, (void*)&aFlags[2]}, | |
| 551 | 591 | {"enable_output", enableOutputCmd, 0}, |
| 552 | - {"linecount", linecntCmd, 0}, | |
| 553 | 592 | {"hascap", hascapCmd, 0}, |
| 554 | 593 | {"hasfeature", hasfeatureCmd, 0}, |
| 594 | + {"html", putsCmd, (void*)&aFlags[0]}, | |
| 555 | 595 | {"htmlize", htmlizeCmd, 0}, |
| 556 | - {"date", dateCmd, 0}, | |
| 557 | - {"html", putsCmd, 0}, | |
| 558 | - {"puts", putsCmd, (void*)1}, | |
| 559 | - {"wiki", wikiCmd, 0}, | |
| 596 | + {"linecount", linecntCmd, 0}, | |
| 597 | + {"puts", putsCmd, (void*)&aFlags[1]}, | |
| 598 | + {"randhex", randhexCmd, 0}, | |
| 560 | 599 | {"repository", repositoryCmd, 0}, |
| 561 | - {"utime", utimeCmd, 0}, | |
| 562 | 600 | {"stime", stimeCmd, 0}, |
| 601 | + {"utime", utimeCmd, 0}, | |
| 602 | + {"wiki", wikiCmd, (void*)&aFlags[0]}, | |
| 563 | 603 | {0, 0, 0} |
| 564 | 604 | }; |
| 565 | 605 | if( needConfig ){ |
| 566 | 606 | /* |
| 567 | 607 | ** This function uses several settings which may be defined in the |
| 568 | 608 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -98,11 +98,12 @@ | |
| 98 | return zRc; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | ** Send text to the appropriate output: Either to the console |
| 103 | ** or to the CGI reply buffer. |
| 104 | */ |
| 105 | static void sendText(const char *z, int n, int encode){ |
| 106 | if( enableOutput && n ){ |
| 107 | if( n<0 ) n = strlen(z); |
| 108 | if( encode ){ |
| @@ -130,11 +131,11 @@ | |
| 130 | |
| 131 | /* |
| 132 | ** TH command: puts STRING |
| 133 | ** TH command: html STRING |
| 134 | ** |
| 135 | ** Output STRING as HTML (html) or unchanged (puts). |
| 136 | */ |
| 137 | static int putsCmd( |
| 138 | Th_Interp *interp, |
| 139 | void *pConvert, |
| 140 | int argc, |
| @@ -142,11 +143,11 @@ | |
| 142 | int *argl |
| 143 | ){ |
| 144 | if( argc!=2 ){ |
| 145 | return Th_WrongNumArgs(interp, "puts STRING"); |
| 146 | } |
| 147 | sendText((char*)argv[1], argl[1], pConvert!=0); |
| 148 | return TH_OK; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | ** TH command: wiki STRING |
| @@ -158,17 +159,18 @@ | |
| 158 | void *p, |
| 159 | int argc, |
| 160 | const char **argv, |
| 161 | int *argl |
| 162 | ){ |
| 163 | if( argc!=2 ){ |
| 164 | return Th_WrongNumArgs(interp, "wiki STRING"); |
| 165 | } |
| 166 | if( enableOutput ){ |
| 167 | Blob src; |
| 168 | blob_init(&src, (char*)argv[1], argl[1]); |
| 169 | wiki_convert(&src, 0, WIKI_INLINE|WIKI_NOBADLINKS); |
| 170 | blob_reset(&src); |
| 171 | } |
| 172 | return TH_OK; |
| 173 | } |
| 174 | |
| @@ -530,38 +532,76 @@ | |
| 530 | sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x); |
| 531 | Th_SetResult(interp, zUTime, -1); |
| 532 | return TH_OK; |
| 533 | } |
| 534 | |
| 535 | |
| 536 | /* |
| 537 | ** Make sure the interpreter has been initialized. Initialize it if |
| 538 | ** it has not been already. |
| 539 | ** |
| 540 | ** The interpreter is stored in the g.interp global variable. |
| 541 | */ |
| 542 | void Th_FossilInit(int needConfig, int forceSetup){ |
| 543 | int wasInit = 0; |
| 544 | static struct _Command { |
| 545 | const char *zName; |
| 546 | Th_CommandProc xProc; |
| 547 | void *pContext; |
| 548 | } aCommand[] = { |
| 549 | {"anycap", anycapCmd, 0}, |
| 550 | {"combobox", comboboxCmd, 0}, |
| 551 | {"enable_output", enableOutputCmd, 0}, |
| 552 | {"linecount", linecntCmd, 0}, |
| 553 | {"hascap", hascapCmd, 0}, |
| 554 | {"hasfeature", hasfeatureCmd, 0}, |
| 555 | {"htmlize", htmlizeCmd, 0}, |
| 556 | {"date", dateCmd, 0}, |
| 557 | {"html", putsCmd, 0}, |
| 558 | {"puts", putsCmd, (void*)1}, |
| 559 | {"wiki", wikiCmd, 0}, |
| 560 | {"repository", repositoryCmd, 0}, |
| 561 | {"utime", utimeCmd, 0}, |
| 562 | {"stime", stimeCmd, 0}, |
| 563 | {0, 0, 0} |
| 564 | }; |
| 565 | if( needConfig ){ |
| 566 | /* |
| 567 | ** This function uses several settings which may be defined in the |
| 568 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -98,11 +98,12 @@ | |
| 98 | return zRc; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | ** Send text to the appropriate output: Either to the console |
| 103 | ** or to the CGI reply buffer. Escape all characters with special |
| 104 | ** meaning to HTML if the encode parameter is true. |
| 105 | */ |
| 106 | static void sendText(const char *z, int n, int encode){ |
| 107 | if( enableOutput && n ){ |
| 108 | if( n<0 ) n = strlen(z); |
| 109 | if( encode ){ |
| @@ -130,11 +131,11 @@ | |
| 131 | |
| 132 | /* |
| 133 | ** TH command: puts STRING |
| 134 | ** TH command: html STRING |
| 135 | ** |
| 136 | ** Output STRING escaped for HTML (html) or unchanged (puts). |
| 137 | */ |
| 138 | static int putsCmd( |
| 139 | Th_Interp *interp, |
| 140 | void *pConvert, |
| 141 | int argc, |
| @@ -142,11 +143,11 @@ | |
| 143 | int *argl |
| 144 | ){ |
| 145 | if( argc!=2 ){ |
| 146 | return Th_WrongNumArgs(interp, "puts STRING"); |
| 147 | } |
| 148 | sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert); |
| 149 | return TH_OK; |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | ** TH command: wiki STRING |
| @@ -158,17 +159,18 @@ | |
| 159 | void *p, |
| 160 | int argc, |
| 161 | const char **argv, |
| 162 | int *argl |
| 163 | ){ |
| 164 | int flags = WIKI_INLINE | WIKI_NOBADLINKS | *(unsigned int*)p; |
| 165 | if( argc!=2 ){ |
| 166 | return Th_WrongNumArgs(interp, "wiki STRING"); |
| 167 | } |
| 168 | if( enableOutput ){ |
| 169 | Blob src; |
| 170 | blob_init(&src, (char*)argv[1], argl[1]); |
| 171 | wiki_convert(&src, 0, flags); |
| 172 | blob_reset(&src); |
| 173 | } |
| 174 | return TH_OK; |
| 175 | } |
| 176 | |
| @@ -530,38 +532,76 @@ | |
| 532 | sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x); |
| 533 | Th_SetResult(interp, zUTime, -1); |
| 534 | return TH_OK; |
| 535 | } |
| 536 | |
| 537 | |
| 538 | /* |
| 539 | ** TH1 command: randhex N |
| 540 | ** |
| 541 | ** Return N*2 random hexadecimal digits with N<50. If N is omitted, |
| 542 | ** use a value of 10. |
| 543 | */ |
| 544 | static int randhexCmd( |
| 545 | Th_Interp *interp, |
| 546 | void *p, |
| 547 | int argc, |
| 548 | const char **argv, |
| 549 | int *argl |
| 550 | ){ |
| 551 | int n; |
| 552 | char aRand[50]; |
| 553 | char zOut[100]; |
| 554 | if( argc!=1 && argc!=2 ){ |
| 555 | return Th_WrongNumArgs(interp, "repository ?BOOLEAN?"); |
| 556 | } |
| 557 | if( argc==2 ){ |
| 558 | if( Th_ToInt(interp, argv[1], argl[1], &n) ){ |
| 559 | return TH_ERROR; |
| 560 | } |
| 561 | if( n<1 ) n = 1; |
| 562 | if( n>sizeof(aRand) ) n = sizeof(aRand); |
| 563 | }else{ |
| 564 | n = 10; |
| 565 | } |
| 566 | sqlite3_randomness(n, aRand); |
| 567 | encode16(aRand, zOut, n); |
| 568 | Th_SetResult(interp, zOut, -1); |
| 569 | return TH_OK; |
| 570 | } |
| 571 | |
| 572 | |
| 573 | /* |
| 574 | ** Make sure the interpreter has been initialized. Initialize it if |
| 575 | ** it has not been already. |
| 576 | ** |
| 577 | ** The interpreter is stored in the g.interp global variable. |
| 578 | */ |
| 579 | void Th_FossilInit(int needConfig, int forceSetup){ |
| 580 | int wasInit = 0; |
| 581 | static unsigned int aFlags[] = { 0, 1, WIKI_LINKSONLY }; |
| 582 | static struct _Command { |
| 583 | const char *zName; |
| 584 | Th_CommandProc xProc; |
| 585 | void *pContext; |
| 586 | } aCommand[] = { |
| 587 | {"anycap", anycapCmd, 0}, |
| 588 | {"combobox", comboboxCmd, 0}, |
| 589 | {"date", dateCmd, 0}, |
| 590 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 591 | {"enable_output", enableOutputCmd, 0}, |
| 592 | {"hascap", hascapCmd, 0}, |
| 593 | {"hasfeature", hasfeatureCmd, 0}, |
| 594 | {"html", putsCmd, (void*)&aFlags[0]}, |
| 595 | {"htmlize", htmlizeCmd, 0}, |
| 596 | {"linecount", linecntCmd, 0}, |
| 597 | {"puts", putsCmd, (void*)&aFlags[1]}, |
| 598 | {"randhex", randhexCmd, 0}, |
| 599 | {"repository", repositoryCmd, 0}, |
| 600 | {"stime", stimeCmd, 0}, |
| 601 | {"utime", utimeCmd, 0}, |
| 602 | {"wiki", wikiCmd, (void*)&aFlags[0]}, |
| 603 | {0, 0, 0} |
| 604 | }; |
| 605 | if( needConfig ){ |
| 606 | /* |
| 607 | ** This function uses several settings which may be defined in the |
| 608 |