Fossil SCM

Add the 'checkout', 'render', 'styleHeader', 'styleFooter', and 'trace' TH1 commands.

mistachkin 2014-06-10 19:59 UTC trunk
Commit c18ff5d0051370d059c09d73d00814622d2a9e7f
2 files changed +125 +82
+125
--- src/th_main.c
+++ src/th_main.c
@@ -572,10 +572,130 @@
572572
if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
573573
}
574574
Th_SetResult(interp, g.zRepositoryName, -1);
575575
return TH_OK;
576576
}
577
+
578
+/*
579
+** TH1 command: checkout ?BOOLEAN?
580
+**
581
+** Return the fully qualified directory name of the current checkout or an
582
+** empty string if it is not available.
583
+*/
584
+static int checkoutCmd(
585
+ Th_Interp *interp,
586
+ void *p,
587
+ int argc,
588
+ const char **argv,
589
+ int *argl
590
+){
591
+ if( argc!=1 && argc!=2 ){
592
+ return Th_WrongNumArgs(interp, "checkout ?BOOLEAN?");
593
+ }
594
+ if( argc==2 ){
595
+ int openRepository = 0;
596
+ if( Th_ToInt(interp, argv[1], argl[1], &openRepository) ){
597
+ return TH_ERROR;
598
+ }
599
+ if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
600
+ }
601
+ Th_SetResult(interp, g.zLocalRoot, -1);
602
+ return TH_OK;
603
+}
604
+
605
+/*
606
+** TH1 command: trace STRING
607
+**
608
+** Generate a TH1 trace message if debugging is enabled.
609
+*/
610
+static int traceCmd(
611
+ Th_Interp *interp,
612
+ void *p,
613
+ int argc,
614
+ const char **argv,
615
+ int *argl
616
+){
617
+ if( argc!=2 ){
618
+ return Th_WrongNumArgs(interp, "trace STRING");
619
+ }
620
+ if( g.thTrace ){
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.
631
+*/
632
+static int renderCmd(
633
+ Th_Interp *interp,
634
+ void *p,
635
+ int argc,
636
+ const char **argv,
637
+ int *argl
638
+){
639
+ int rc;
640
+ if( argc!=2 ){
641
+ return Th_WrongNumArgs(interp, "render STRING");
642
+ }
643
+ rc = Th_Render(argv[1]);
644
+ Th_SetResult(interp, 0, 0);
645
+ return rc;
646
+}
647
+
648
+/*
649
+** TH1 command: styleHeader TITLE
650
+**
651
+** Render the configured style header.
652
+*/
653
+static int styleHeaderCmd(
654
+ Th_Interp *interp,
655
+ void *p,
656
+ int argc,
657
+ const char **argv,
658
+ int *argl
659
+){
660
+ if( argc!=2 ){
661
+ return Th_WrongNumArgs(interp, "styleHeader TITLE");
662
+ }
663
+ if( g.zConfigDbName ){
664
+ style_header("%s", argv[1]);
665
+ Th_SetResult(interp, 0, 0);
666
+ return TH_OK;
667
+ }else{
668
+ Th_SetResult(interp, "configuration unavailable", -1);
669
+ return TH_ERROR;
670
+ }
671
+}
672
+
673
+/*
674
+** TH1 command: styleFooter
675
+**
676
+** Render the configured style footer.
677
+*/
678
+static int styleFooterCmd(
679
+ Th_Interp *interp,
680
+ void *p,
681
+ int argc,
682
+ const char **argv,
683
+ int *argl
684
+){
685
+ if( argc!=1 ){
686
+ return Th_WrongNumArgs(interp, "styleFooter");
687
+ }
688
+ if( g.zConfigDbName ){
689
+ style_footer();
690
+ Th_SetResult(interp, 0, 0);
691
+ return TH_OK;
692
+ }else{
693
+ Th_SetResult(interp, "configuration unavailable", -1);
694
+ return TH_ERROR;
695
+ }
696
+}
577697
578698
#ifdef _WIN32
579699
# include <windows.h>
580700
#else
581701
# include <sys/time.h>
@@ -991,10 +1111,11 @@
9911111
const char *zName;
9921112
Th_CommandProc xProc;
9931113
void *pContext;
9941114
} aCommand[] = {
9951115
{"anycap", anycapCmd, 0},
1116
+ {"checkout", checkoutCmd, 0},
9961117
{"combobox", comboboxCmd, 0},
9971118
{"date", dateCmd, 0},
9981119
{"decorate", wikiCmd, (void*)&aFlags[2]},
9991120
{"enable_output", enableOutputCmd, 0},
10001121
{"httpize", httpizeCmd, 0},
@@ -1006,13 +1127,17 @@
10061127
{"linecount", linecntCmd, 0},
10071128
{"puts", putsCmd, (void*)&aFlags[1]},
10081129
{"query", queryCmd, 0},
10091130
{"randhex", randhexCmd, 0},
10101131
{"regexp", regexpCmd, 0},
1132
+ {"render", renderCmd, 0},
10111133
{"repository", repositoryCmd, 0},
10121134
{"setting", settingCmd, 0},
1135
+ {"styleHeader", styleHeaderCmd, 0},
1136
+ {"styleFooter", styleFooterCmd, 0},
10131137
{"tclReady", tclReadyCmd, 0},
1138
+ {"trace", traceCmd, 0},
10141139
{"stime", stimeCmd, 0},
10151140
{"utime", utimeCmd, 0},
10161141
{"wiki", wikiCmd, (void*)&aFlags[0]},
10171142
{0, 0, 0}
10181143
};
10191144
--- src/th_main.c
+++ src/th_main.c
@@ -572,10 +572,130 @@
572 if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
573 }
574 Th_SetResult(interp, g.zRepositoryName, -1);
575 return TH_OK;
576 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
578 #ifdef _WIN32
579 # include <windows.h>
580 #else
581 # include <sys/time.h>
@@ -991,10 +1111,11 @@
991 const char *zName;
992 Th_CommandProc xProc;
993 void *pContext;
994 } aCommand[] = {
995 {"anycap", anycapCmd, 0},
 
996 {"combobox", comboboxCmd, 0},
997 {"date", dateCmd, 0},
998 {"decorate", wikiCmd, (void*)&aFlags[2]},
999 {"enable_output", enableOutputCmd, 0},
1000 {"httpize", httpizeCmd, 0},
@@ -1006,13 +1127,17 @@
1006 {"linecount", linecntCmd, 0},
1007 {"puts", putsCmd, (void*)&aFlags[1]},
1008 {"query", queryCmd, 0},
1009 {"randhex", randhexCmd, 0},
1010 {"regexp", regexpCmd, 0},
 
1011 {"repository", repositoryCmd, 0},
1012 {"setting", settingCmd, 0},
 
 
1013 {"tclReady", tclReadyCmd, 0},
 
1014 {"stime", stimeCmd, 0},
1015 {"utime", utimeCmd, 0},
1016 {"wiki", wikiCmd, (void*)&aFlags[0]},
1017 {0, 0, 0}
1018 };
1019
--- src/th_main.c
+++ src/th_main.c
@@ -572,10 +572,130 @@
572 if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
573 }
574 Th_SetResult(interp, g.zRepositoryName, -1);
575 return TH_OK;
576 }
577
578 /*
579 ** TH1 command: checkout ?BOOLEAN?
580 **
581 ** Return the fully qualified directory name of the current checkout or an
582 ** empty string if it is not available.
583 */
584 static int checkoutCmd(
585 Th_Interp *interp,
586 void *p,
587 int argc,
588 const char **argv,
589 int *argl
590 ){
591 if( argc!=1 && argc!=2 ){
592 return Th_WrongNumArgs(interp, "checkout ?BOOLEAN?");
593 }
594 if( argc==2 ){
595 int openRepository = 0;
596 if( Th_ToInt(interp, argv[1], argl[1], &openRepository) ){
597 return TH_ERROR;
598 }
599 if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
600 }
601 Th_SetResult(interp, g.zLocalRoot, -1);
602 return TH_OK;
603 }
604
605 /*
606 ** TH1 command: trace STRING
607 **
608 ** Generate a TH1 trace message if debugging is enabled.
609 */
610 static int traceCmd(
611 Th_Interp *interp,
612 void *p,
613 int argc,
614 const char **argv,
615 int *argl
616 ){
617 if( argc!=2 ){
618 return Th_WrongNumArgs(interp, "trace STRING");
619 }
620 if( g.thTrace ){
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.
631 */
632 static int renderCmd(
633 Th_Interp *interp,
634 void *p,
635 int argc,
636 const char **argv,
637 int *argl
638 ){
639 int rc;
640 if( argc!=2 ){
641 return Th_WrongNumArgs(interp, "render STRING");
642 }
643 rc = Th_Render(argv[1]);
644 Th_SetResult(interp, 0, 0);
645 return rc;
646 }
647
648 /*
649 ** TH1 command: styleHeader TITLE
650 **
651 ** Render the configured style header.
652 */
653 static int styleHeaderCmd(
654 Th_Interp *interp,
655 void *p,
656 int argc,
657 const char **argv,
658 int *argl
659 ){
660 if( argc!=2 ){
661 return Th_WrongNumArgs(interp, "styleHeader TITLE");
662 }
663 if( g.zConfigDbName ){
664 style_header("%s", argv[1]);
665 Th_SetResult(interp, 0, 0);
666 return TH_OK;
667 }else{
668 Th_SetResult(interp, "configuration unavailable", -1);
669 return TH_ERROR;
670 }
671 }
672
673 /*
674 ** TH1 command: styleFooter
675 **
676 ** Render the configured style footer.
677 */
678 static int styleFooterCmd(
679 Th_Interp *interp,
680 void *p,
681 int argc,
682 const char **argv,
683 int *argl
684 ){
685 if( argc!=1 ){
686 return Th_WrongNumArgs(interp, "styleFooter");
687 }
688 if( g.zConfigDbName ){
689 style_footer();
690 Th_SetResult(interp, 0, 0);
691 return TH_OK;
692 }else{
693 Th_SetResult(interp, "configuration unavailable", -1);
694 return TH_ERROR;
695 }
696 }
697
698 #ifdef _WIN32
699 # include <windows.h>
700 #else
701 # include <sys/time.h>
@@ -991,10 +1111,11 @@
1111 const char *zName;
1112 Th_CommandProc xProc;
1113 void *pContext;
1114 } aCommand[] = {
1115 {"anycap", anycapCmd, 0},
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},
@@ -1006,13 +1127,17 @@
1127 {"linecount", linecntCmd, 0},
1128 {"puts", putsCmd, (void*)&aFlags[1]},
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 {"stime", stimeCmd, 0},
1140 {"utime", utimeCmd, 0},
1141 {"wiki", wikiCmd, (void*)&aFlags[0]},
1142 {0, 0, 0}
1143 };
1144
--- test/th1.test
+++ test/th1.test
@@ -472,5 +472,87 @@
472472
473473
###############################################################################
474474
475475
fossil test-th-eval "expr 0+0b"
476476
test th1-expr-35 {$RESULT eq {TH_ERROR: expected number, got: "0b"}}
477
+
478
+###############################################################################
479
+
480
+fossil test-th-eval "checkout 1"
481
+test th1-checkout-1 {[string length $RESULT] > 0}
482
+
483
+###############################################################################
484
+
485
+fossil test-th-eval "checkout"
486
+test th1-checkout-2 {[string length $RESULT] == 0}
487
+
488
+###############################################################################
489
+
490
+set savedPwd [pwd]; cd /
491
+fossil test-th-eval "checkout 1"
492
+cd $savedPwd; unset savedPwd
493
+test th1-checkout-3 {[string length $RESULT] == 0}
494
+
495
+###############################################################################
496
+
497
+set savedPwd [pwd]; cd /
498
+fossil test-th-eval "checkout"
499
+cd $savedPwd; unset savedPwd
500
+test th1-checkout-4 {[string length $RESULT] == 0}
501
+
502
+###############################################################################
503
+
504
+fossil test-th-eval "render {}"
505
+test th1-render-1 {$RESULT eq {}}
506
+
507
+###############################################################################
508
+
509
+fossil test-th-eval "render {$<x> before <th1>set x 123</th1> after $<x> }"
510
+test th1-render-2 {$RESULT eq {no such variable: x before after 123 }}
511
+
512
+###############################################################################
513
+
514
+fossil test-th-eval "trace {}"
515
+test th1-trace-1 {$RESULT eq {}}
516
+
517
+###############################################################################
518
+
519
+fossil test-th-eval --th-trace "trace {}"
520
+test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
521
+{------------------ BEGIN TRACE LOG ------------------
522
+th1-setup {} => TH_OK<br />
523
+
524
+------------------- END TRACE LOG -------------------}}
525
+
526
+###############################################################################
527
+
528
+fossil test-th-eval "trace {this is a trace message.}"
529
+test th1-trace-3 {$RESULT eq {}}
530
+
531
+###############################################################################
532
+
533
+fossil test-th-eval --th-trace "trace {this is a trace message.}"
534
+test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
535
+{------------------ BEGIN TRACE LOG ------------------
536
+th1-setup {} => TH_OK<br />
537
+this is a trace message.
538
+------------------- END TRACE LOG -------------------}}
539
+
540
+###############################################################################
541
+
542
+fossil test-th-eval "styleHeader {Page Title Here}"
543
+test th1-header-1 {$RESULT eq {TH_ERROR: configuration unavailable}}
544
+
545
+###############################################################################
546
+
547
+fossil test-th-eval --th-open-config "styleHeader {Page Title Here}"
548
+test th1-header-2 {[regexp -- {<title>Fossil: Page Title Here</title>} $RESULT]}
549
+
550
+###############################################################################
551
+
552
+fossil test-th-eval "styleFooter"
553
+test th1-footer-1 {$RESULT eq {TH_ERROR: configuration unavailable}}
554
+
555
+###############################################################################
556
+
557
+fossil test-th-eval --th-open-config "styleFooter"
558
+test th1-footer-2 {$RESULT eq {}}
477559
--- test/th1.test
+++ test/th1.test
@@ -472,5 +472,87 @@
472
473 ###############################################################################
474
475 fossil test-th-eval "expr 0+0b"
476 test th1-expr-35 {$RESULT eq {TH_ERROR: expected number, got: "0b"}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
--- test/th1.test
+++ test/th1.test
@@ -472,5 +472,87 @@
472
473 ###############################################################################
474
475 fossil test-th-eval "expr 0+0b"
476 test th1-expr-35 {$RESULT eq {TH_ERROR: expected number, got: "0b"}}
477
478 ###############################################################################
479
480 fossil test-th-eval "checkout 1"
481 test th1-checkout-1 {[string length $RESULT] > 0}
482
483 ###############################################################################
484
485 fossil test-th-eval "checkout"
486 test th1-checkout-2 {[string length $RESULT] == 0}
487
488 ###############################################################################
489
490 set savedPwd [pwd]; cd /
491 fossil test-th-eval "checkout 1"
492 cd $savedPwd; unset savedPwd
493 test th1-checkout-3 {[string length $RESULT] == 0}
494
495 ###############################################################################
496
497 set savedPwd [pwd]; cd /
498 fossil test-th-eval "checkout"
499 cd $savedPwd; unset savedPwd
500 test th1-checkout-4 {[string length $RESULT] == 0}
501
502 ###############################################################################
503
504 fossil test-th-eval "render {}"
505 test th1-render-1 {$RESULT eq {}}
506
507 ###############################################################################
508
509 fossil test-th-eval "render {$<x> before <th1>set x 123</th1> after $<x> }"
510 test th1-render-2 {$RESULT eq {no such variable: x before after 123 }}
511
512 ###############################################################################
513
514 fossil test-th-eval "trace {}"
515 test th1-trace-1 {$RESULT eq {}}
516
517 ###############################################################################
518
519 fossil test-th-eval --th-trace "trace {}"
520 test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
521 {------------------ BEGIN TRACE LOG ------------------
522 th1-setup {} => TH_OK<br />
523
524 ------------------- END TRACE LOG -------------------}}
525
526 ###############################################################################
527
528 fossil test-th-eval "trace {this is a trace message.}"
529 test th1-trace-3 {$RESULT eq {}}
530
531 ###############################################################################
532
533 fossil test-th-eval --th-trace "trace {this is a trace message.}"
534 test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
535 {------------------ BEGIN TRACE LOG ------------------
536 th1-setup {} => TH_OK<br />
537 this is a trace message.
538 ------------------- END TRACE LOG -------------------}}
539
540 ###############################################################################
541
542 fossil test-th-eval "styleHeader {Page Title Here}"
543 test th1-header-1 {$RESULT eq {TH_ERROR: configuration unavailable}}
544
545 ###############################################################################
546
547 fossil test-th-eval --th-open-config "styleHeader {Page Title Here}"
548 test th1-header-2 {[regexp -- {<title>Fossil: Page Title Here</title>} $RESULT]}
549
550 ###############################################################################
551
552 fossil test-th-eval "styleFooter"
553 test th1-footer-1 {$RESULT eq {TH_ERROR: configuration unavailable}}
554
555 ###############################################################################
556
557 fossil test-th-eval --th-open-config "styleFooter"
558 test th1-footer-2 {$RESULT eq {}}
559

Keyboard Shortcuts

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