Fossil SCM

Add 'reinitialize' command to TH1. Add 'flags' to the globalState TH1 command.

mistachkin 2014-09-09 19:45 trunk merge
Commit 3355835fdc5f4583a5dd2165b8389ca9390e4ee2
2 files changed +43 -1 +19
+43 -1
--- src/th_main.c
+++ src/th_main.c
@@ -31,12 +31,17 @@
3131
#define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */
3232
#define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */
3333
#define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */
3434
#define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */
3535
#define TH_INIT_MASK ((u32)0x0000000F) /* All possible init flags. */
36
-#define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */
36
+
37
+/*
38
+** Useful and/or "well-known" combinations of flag values.
39
+*/
40
+#define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */
3741
#define TH_INIT_HOOK (TH_INIT_NEED_CONFIG | TH_INIT_FORCE_SETUP)
42
+#define TH_INIT_FORBID_MASK (TH_INIT_FORCE_TCL) /* Illegal from a script. */
3843
#endif
3944
4045
/*
4146
** Flags set by functions in this file to keep track of integration state
4247
** information. These flags should not be used outside of this file.
@@ -682,10 +687,11 @@
682687
**
683688
** "checkout" = The active local checkout directory, if any.
684689
** "configuration" = The active configuration database file name,
685690
** if any.
686691
** "executable" = The fully qualified executable file name.
692
+** "flags" = The TH1 initialization flags.
687693
** "log" = The error log file name, if any.
688694
** "repository" = The active local repository file name, if
689695
** any.
690696
** "top" = The base path for the active server instance,
691697
** if applicable.
@@ -718,10 +724,13 @@
718724
}else if( fossil_strnicmp(argv[1], "configuration\0", 14)==0 ){
719725
Th_SetResult(interp, g.zConfigDbName ? g.zConfigDbName : zDefault, -1);
720726
return TH_OK;
721727
}else if( fossil_strnicmp(argv[1], "executable\0", 11)==0 ){
722728
Th_SetResult(interp, g.nameOfExe ? g.nameOfExe : zDefault, -1);
729
+ return TH_OK;
730
+ }else if( fossil_strnicmp(argv[1], "flags\0", 6)==0 ){
731
+ Th_SetResultInt(interp, g.th1Flags);
723732
return TH_OK;
724733
}else if( fossil_strnicmp(argv[1], "log\0", 4)==0 ){
725734
Th_SetResult(interp, g.zErrlog ? g.zErrlog : zDefault, -1);
726735
return TH_OK;
727736
}else if( fossil_strnicmp(argv[1], "repository\0", 11)==0 ){
@@ -782,10 +791,39 @@
782791
return Th_WrongNumArgs(interp, "setParameter NAME VALUE");
783792
}
784793
cgi_replace_parameter(mprintf("%s", argv[1]), mprintf("%s", argv[2]));
785794
return TH_OK;
786795
}
796
+
797
+/*
798
+** TH1 command: reinitialize ?FLAGS?
799
+**
800
+** Reinitializes the TH1 interpreter using the specified flags.
801
+*/
802
+static int reinitializeCmd(
803
+ Th_Interp *interp,
804
+ void *p,
805
+ int argc,
806
+ const char **argv,
807
+ int *argl
808
+){
809
+ u32 flags = TH_INIT_DEFAULT;
810
+ if( argc!=1 && argc!=2 ){
811
+ return Th_WrongNumArgs(interp, "reinitialize ?FLAGS?");
812
+ }
813
+ if( argc==2 ){
814
+ int iFlags;
815
+ if( Th_ToInt(interp, argv[1], argl[1], &iFlags) ){
816
+ return TH_ERROR;
817
+ }else{
818
+ flags = (u32)iFlags;
819
+ }
820
+ }
821
+ Th_FossilInit(flags & ~TH_INIT_FORBID_MASK);
822
+ Th_SetResult(interp, 0, 0);
823
+ return TH_OK;
824
+}
787825
788826
/*
789827
** TH1 command: render STRING
790828
**
791829
** Renders the template and writes the results.
@@ -1372,10 +1410,11 @@
13721410
{"linecount", linecntCmd, 0},
13731411
{"puts", putsCmd, (void*)&aFlags[1]},
13741412
{"query", queryCmd, 0},
13751413
{"randhex", randhexCmd, 0},
13761414
{"regexp", regexpCmd, 0},
1415
+ {"reinitialize", reinitializeCmd, 0},
13771416
{"render", renderCmd, 0},
13781417
{"repository", repositoryCmd, 0},
13791418
{"setParameter", setParameterCmd, 0},
13801419
{"setting", settingCmd, 0},
13811420
{"styleHeader", styleHeaderCmd, 0},
@@ -1385,10 +1424,13 @@
13851424
{"stime", stimeCmd, 0},
13861425
{"utime", utimeCmd, 0},
13871426
{"wiki", wikiCmd, (void*)&aFlags[0]},
13881427
{0, 0, 0}
13891428
};
1429
+ if( g.thTrace ){
1430
+ Th_Trace("th1-init 0x%x => 0x%x<br />\n", g.th1Flags, flags);
1431
+ }
13901432
if( needConfig ){
13911433
/*
13921434
** This function uses several settings which may be defined in the
13931435
** repository and/or the global configuration. Since the caller
13941436
** passed a non-zero value for the needConfig parameter, make sure
13951437
--- src/th_main.c
+++ src/th_main.c
@@ -31,12 +31,17 @@
31 #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */
32 #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */
33 #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */
34 #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */
35 #define TH_INIT_MASK ((u32)0x0000000F) /* All possible init flags. */
36 #define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */
 
 
 
 
37 #define TH_INIT_HOOK (TH_INIT_NEED_CONFIG | TH_INIT_FORCE_SETUP)
 
38 #endif
39
40 /*
41 ** Flags set by functions in this file to keep track of integration state
42 ** information. These flags should not be used outside of this file.
@@ -682,10 +687,11 @@
682 **
683 ** "checkout" = The active local checkout directory, if any.
684 ** "configuration" = The active configuration database file name,
685 ** if any.
686 ** "executable" = The fully qualified executable file name.
 
687 ** "log" = The error log file name, if any.
688 ** "repository" = The active local repository file name, if
689 ** any.
690 ** "top" = The base path for the active server instance,
691 ** if applicable.
@@ -718,10 +724,13 @@
718 }else if( fossil_strnicmp(argv[1], "configuration\0", 14)==0 ){
719 Th_SetResult(interp, g.zConfigDbName ? g.zConfigDbName : zDefault, -1);
720 return TH_OK;
721 }else if( fossil_strnicmp(argv[1], "executable\0", 11)==0 ){
722 Th_SetResult(interp, g.nameOfExe ? g.nameOfExe : zDefault, -1);
 
 
 
723 return TH_OK;
724 }else if( fossil_strnicmp(argv[1], "log\0", 4)==0 ){
725 Th_SetResult(interp, g.zErrlog ? g.zErrlog : zDefault, -1);
726 return TH_OK;
727 }else if( fossil_strnicmp(argv[1], "repository\0", 11)==0 ){
@@ -782,10 +791,39 @@
782 return Th_WrongNumArgs(interp, "setParameter NAME VALUE");
783 }
784 cgi_replace_parameter(mprintf("%s", argv[1]), mprintf("%s", argv[2]));
785 return TH_OK;
786 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787
788 /*
789 ** TH1 command: render STRING
790 **
791 ** Renders the template and writes the results.
@@ -1372,10 +1410,11 @@
1372 {"linecount", linecntCmd, 0},
1373 {"puts", putsCmd, (void*)&aFlags[1]},
1374 {"query", queryCmd, 0},
1375 {"randhex", randhexCmd, 0},
1376 {"regexp", regexpCmd, 0},
 
1377 {"render", renderCmd, 0},
1378 {"repository", repositoryCmd, 0},
1379 {"setParameter", setParameterCmd, 0},
1380 {"setting", settingCmd, 0},
1381 {"styleHeader", styleHeaderCmd, 0},
@@ -1385,10 +1424,13 @@
1385 {"stime", stimeCmd, 0},
1386 {"utime", utimeCmd, 0},
1387 {"wiki", wikiCmd, (void*)&aFlags[0]},
1388 {0, 0, 0}
1389 };
 
 
 
1390 if( needConfig ){
1391 /*
1392 ** This function uses several settings which may be defined in the
1393 ** repository and/or the global configuration. Since the caller
1394 ** passed a non-zero value for the needConfig parameter, make sure
1395
--- src/th_main.c
+++ src/th_main.c
@@ -31,12 +31,17 @@
31 #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */
32 #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */
33 #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */
34 #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */
35 #define TH_INIT_MASK ((u32)0x0000000F) /* All possible init flags. */
36
37 /*
38 ** Useful and/or "well-known" combinations of flag values.
39 */
40 #define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */
41 #define TH_INIT_HOOK (TH_INIT_NEED_CONFIG | TH_INIT_FORCE_SETUP)
42 #define TH_INIT_FORBID_MASK (TH_INIT_FORCE_TCL) /* Illegal from a script. */
43 #endif
44
45 /*
46 ** Flags set by functions in this file to keep track of integration state
47 ** information. These flags should not be used outside of this file.
@@ -682,10 +687,11 @@
687 **
688 ** "checkout" = The active local checkout directory, if any.
689 ** "configuration" = The active configuration database file name,
690 ** if any.
691 ** "executable" = The fully qualified executable file name.
692 ** "flags" = The TH1 initialization flags.
693 ** "log" = The error log file name, if any.
694 ** "repository" = The active local repository file name, if
695 ** any.
696 ** "top" = The base path for the active server instance,
697 ** if applicable.
@@ -718,10 +724,13 @@
724 }else if( fossil_strnicmp(argv[1], "configuration\0", 14)==0 ){
725 Th_SetResult(interp, g.zConfigDbName ? g.zConfigDbName : zDefault, -1);
726 return TH_OK;
727 }else if( fossil_strnicmp(argv[1], "executable\0", 11)==0 ){
728 Th_SetResult(interp, g.nameOfExe ? g.nameOfExe : zDefault, -1);
729 return TH_OK;
730 }else if( fossil_strnicmp(argv[1], "flags\0", 6)==0 ){
731 Th_SetResultInt(interp, g.th1Flags);
732 return TH_OK;
733 }else if( fossil_strnicmp(argv[1], "log\0", 4)==0 ){
734 Th_SetResult(interp, g.zErrlog ? g.zErrlog : zDefault, -1);
735 return TH_OK;
736 }else if( fossil_strnicmp(argv[1], "repository\0", 11)==0 ){
@@ -782,10 +791,39 @@
791 return Th_WrongNumArgs(interp, "setParameter NAME VALUE");
792 }
793 cgi_replace_parameter(mprintf("%s", argv[1]), mprintf("%s", argv[2]));
794 return TH_OK;
795 }
796
797 /*
798 ** TH1 command: reinitialize ?FLAGS?
799 **
800 ** Reinitializes the TH1 interpreter using the specified flags.
801 */
802 static int reinitializeCmd(
803 Th_Interp *interp,
804 void *p,
805 int argc,
806 const char **argv,
807 int *argl
808 ){
809 u32 flags = TH_INIT_DEFAULT;
810 if( argc!=1 && argc!=2 ){
811 return Th_WrongNumArgs(interp, "reinitialize ?FLAGS?");
812 }
813 if( argc==2 ){
814 int iFlags;
815 if( Th_ToInt(interp, argv[1], argl[1], &iFlags) ){
816 return TH_ERROR;
817 }else{
818 flags = (u32)iFlags;
819 }
820 }
821 Th_FossilInit(flags & ~TH_INIT_FORBID_MASK);
822 Th_SetResult(interp, 0, 0);
823 return TH_OK;
824 }
825
826 /*
827 ** TH1 command: render STRING
828 **
829 ** Renders the template and writes the results.
@@ -1372,10 +1410,11 @@
1410 {"linecount", linecntCmd, 0},
1411 {"puts", putsCmd, (void*)&aFlags[1]},
1412 {"query", queryCmd, 0},
1413 {"randhex", randhexCmd, 0},
1414 {"regexp", regexpCmd, 0},
1415 {"reinitialize", reinitializeCmd, 0},
1416 {"render", renderCmd, 0},
1417 {"repository", repositoryCmd, 0},
1418 {"setParameter", setParameterCmd, 0},
1419 {"setting", settingCmd, 0},
1420 {"styleHeader", styleHeaderCmd, 0},
@@ -1385,10 +1424,13 @@
1424 {"stime", stimeCmd, 0},
1425 {"utime", utimeCmd, 0},
1426 {"wiki", wikiCmd, (void*)&aFlags[0]},
1427 {0, 0, 0}
1428 };
1429 if( g.thTrace ){
1430 Th_Trace("th1-init 0x%x => 0x%x<br />\n", g.th1Flags, flags);
1431 }
1432 if( needConfig ){
1433 /*
1434 ** This function uses several settings which may be defined in the
1435 ** repository and/or the global configuration. Since the caller
1436 ** passed a non-zero value for the needConfig parameter, make sure
1437
--- test/th1.test
+++ test/th1.test
@@ -553,15 +553,17 @@
553553
554554
fossil test-th-eval --th-trace "trace {}"
555555
if {$th1Hooks} {
556556
test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
557557
{------------------ BEGIN TRACE LOG ------------------
558
+th1-init 0x0 => 0x0<br />
558559
559560
------------------- END TRACE LOG -------------------}}
560561
} else {
561562
test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
562563
{------------------ BEGIN TRACE LOG ------------------
564
+th1-init 0x0 => 0x0<br />
563565
th1-setup {} => TH_OK<br />
564566
565567
------------------- END TRACE LOG -------------------}}
566568
}
567569
@@ -574,15 +576,17 @@
574576
575577
fossil test-th-eval --th-trace "trace {this is a trace message.}"
576578
if {$th1Hooks} {
577579
test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
578580
{------------------ BEGIN TRACE LOG ------------------
581
+th1-init 0x0 => 0x0<br />
579582
this is a trace message.
580583
------------------- END TRACE LOG -------------------}}
581584
} else {
582585
test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
583586
{------------------ BEGIN TRACE LOG ------------------
587
+th1-init 0x0 => 0x0<br />
584588
th1-setup {} => TH_OK<br />
585589
this is a trace message.
586590
------------------- END TRACE LOG -------------------}}
587591
}
588592
@@ -789,5 +793,20 @@
789793
790794
###############################################################################
791795
792796
fossil test-th-eval --vfs $altVfs "globalState vfs"
793797
test th1-globalState-15 {$RESULT eq $altVfs}
798
+
799
+###############################################################################
800
+
801
+fossil test-th-eval "globalState flags"
802
+test th1-globalState-16 {$RESULT eq "0"}
803
+
804
+###############################################################################
805
+
806
+fossil test-th-eval "reinitialize; globalState configuration"
807
+test th1-reinitialize-1 {$RESULT eq ""}
808
+
809
+###############################################################################
810
+
811
+fossil test-th-eval "reinitialize 1; globalState configuration"
812
+test th1-reinitialize-2 {$RESULT ne ""}
794813
--- test/th1.test
+++ test/th1.test
@@ -553,15 +553,17 @@
553
554 fossil test-th-eval --th-trace "trace {}"
555 if {$th1Hooks} {
556 test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
557 {------------------ BEGIN TRACE LOG ------------------
 
558
559 ------------------- END TRACE LOG -------------------}}
560 } else {
561 test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
562 {------------------ BEGIN TRACE LOG ------------------
 
563 th1-setup {} => TH_OK<br />
564
565 ------------------- END TRACE LOG -------------------}}
566 }
567
@@ -574,15 +576,17 @@
574
575 fossil test-th-eval --th-trace "trace {this is a trace message.}"
576 if {$th1Hooks} {
577 test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
578 {------------------ BEGIN TRACE LOG ------------------
 
579 this is a trace message.
580 ------------------- END TRACE LOG -------------------}}
581 } else {
582 test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
583 {------------------ BEGIN TRACE LOG ------------------
 
584 th1-setup {} => TH_OK<br />
585 this is a trace message.
586 ------------------- END TRACE LOG -------------------}}
587 }
588
@@ -789,5 +793,20 @@
789
790 ###############################################################################
791
792 fossil test-th-eval --vfs $altVfs "globalState vfs"
793 test th1-globalState-15 {$RESULT eq $altVfs}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
794
--- test/th1.test
+++ test/th1.test
@@ -553,15 +553,17 @@
553
554 fossil test-th-eval --th-trace "trace {}"
555 if {$th1Hooks} {
556 test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
557 {------------------ BEGIN TRACE LOG ------------------
558 th1-init 0x0 => 0x0<br />
559
560 ------------------- END TRACE LOG -------------------}}
561 } else {
562 test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
563 {------------------ BEGIN TRACE LOG ------------------
564 th1-init 0x0 => 0x0<br />
565 th1-setup {} => TH_OK<br />
566
567 ------------------- END TRACE LOG -------------------}}
568 }
569
@@ -574,15 +576,17 @@
576
577 fossil test-th-eval --th-trace "trace {this is a trace message.}"
578 if {$th1Hooks} {
579 test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
580 {------------------ BEGIN TRACE LOG ------------------
581 th1-init 0x0 => 0x0<br />
582 this is a trace message.
583 ------------------- END TRACE LOG -------------------}}
584 } else {
585 test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
586 {------------------ BEGIN TRACE LOG ------------------
587 th1-init 0x0 => 0x0<br />
588 th1-setup {} => TH_OK<br />
589 this is a trace message.
590 ------------------- END TRACE LOG -------------------}}
591 }
592
@@ -789,5 +793,20 @@
793
794 ###############################################################################
795
796 fossil test-th-eval --vfs $altVfs "globalState vfs"
797 test th1-globalState-15 {$RESULT eq $altVfs}
798
799 ###############################################################################
800
801 fossil test-th-eval "globalState flags"
802 test th1-globalState-16 {$RESULT eq "0"}
803
804 ###############################################################################
805
806 fossil test-th-eval "reinitialize; globalState configuration"
807 test th1-reinitialize-1 {$RESULT eq ""}
808
809 ###############################################################################
810
811 fossil test-th-eval "reinitialize 1; globalState configuration"
812 test th1-reinitialize-2 {$RESULT ne ""}
813

Keyboard Shortcuts

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