Fossil SCM

Enhancements to TH1 scripting in support of new ticket functionality.

drh 2012-11-21 21:02 trunk
Commit 74e3f90596ac555e2f421b0507fcb9495644588b
1 file changed +50 -10
+50 -10
--- src/th_main.c
+++ src/th_main.c
@@ -98,11 +98,12 @@
9898
return zRc;
9999
}
100100
101101
/*
102102
** 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.
104105
*/
105106
static void sendText(const char *z, int n, int encode){
106107
if( enableOutput && n ){
107108
if( n<0 ) n = strlen(z);
108109
if( encode ){
@@ -130,11 +131,11 @@
130131
131132
/*
132133
** TH command: puts STRING
133134
** TH command: html STRING
134135
**
135
-** Output STRING as HTML (html) or unchanged (puts).
136
+** Output STRING escaped for HTML (html) or unchanged (puts).
136137
*/
137138
static int putsCmd(
138139
Th_Interp *interp,
139140
void *pConvert,
140141
int argc,
@@ -142,11 +143,11 @@
142143
int *argl
143144
){
144145
if( argc!=2 ){
145146
return Th_WrongNumArgs(interp, "puts STRING");
146147
}
147
- sendText((char*)argv[1], argl[1], pConvert!=0);
148
+ sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
148149
return TH_OK;
149150
}
150151
151152
/*
152153
** TH command: wiki STRING
@@ -158,17 +159,18 @@
158159
void *p,
159160
int argc,
160161
const char **argv,
161162
int *argl
162163
){
164
+ int flags = WIKI_INLINE | WIKI_NOBADLINKS | *(unsigned int*)p;
163165
if( argc!=2 ){
164166
return Th_WrongNumArgs(interp, "wiki STRING");
165167
}
166168
if( enableOutput ){
167169
Blob src;
168170
blob_init(&src, (char*)argv[1], argl[1]);
169
- wiki_convert(&src, 0, WIKI_INLINE|WIKI_NOBADLINKS);
171
+ wiki_convert(&src, 0, flags);
170172
blob_reset(&src);
171173
}
172174
return TH_OK;
173175
}
174176
@@ -530,38 +532,76 @@
530532
sqlite3_snprintf(sizeof(zUTime), zUTime, "%llu", x);
531533
Th_SetResult(interp, zUTime, -1);
532534
return TH_OK;
533535
}
534536
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
+
535572
536573
/*
537574
** Make sure the interpreter has been initialized. Initialize it if
538575
** it has not been already.
539576
**
540577
** The interpreter is stored in the g.interp global variable.
541578
*/
542579
void Th_FossilInit(int needConfig, int forceSetup){
543580
int wasInit = 0;
581
+ static unsigned int aFlags[] = { 0, 1, WIKI_LINKSONLY };
544582
static struct _Command {
545583
const char *zName;
546584
Th_CommandProc xProc;
547585
void *pContext;
548586
} aCommand[] = {
549587
{"anycap", anycapCmd, 0},
550588
{"combobox", comboboxCmd, 0},
589
+ {"date", dateCmd, 0},
590
+ {"decorate", wikiCmd, (void*)&aFlags[2]},
551591
{"enable_output", enableOutputCmd, 0},
552
- {"linecount", linecntCmd, 0},
553592
{"hascap", hascapCmd, 0},
554593
{"hasfeature", hasfeatureCmd, 0},
594
+ {"html", putsCmd, (void*)&aFlags[0]},
555595
{"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},
560599
{"repository", repositoryCmd, 0},
561
- {"utime", utimeCmd, 0},
562600
{"stime", stimeCmd, 0},
601
+ {"utime", utimeCmd, 0},
602
+ {"wiki", wikiCmd, (void*)&aFlags[0]},
563603
{0, 0, 0}
564604
};
565605
if( needConfig ){
566606
/*
567607
** This function uses several settings which may be defined in the
568608
--- 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

Keyboard Shortcuts

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