Fossil SCM

added optional FILE arg to wiki export

stephan 2008-05-16 03:18 trunk
Commit 7adbf773c2377e5289d22bf997314d23a71a6f56
1 file changed +28 -16
+28 -16
--- src/wiki.c
+++ src/wiki.c
@@ -665,14 +665,14 @@
665665
**
666666
** Usage: %fossil wiki (export|commit|list) WikiName
667667
**
668668
** Run various subcommands to fetch wiki entries.
669669
**
670
-** %fossil wiki export PAGENAME
670
+** %fossil wiki export PAGENAME ?FILE?
671671
**
672672
** Sends the latest version of the PAGENAME wiki
673
-** entry to stdout.
673
+** entry to the given file or standard output.
674674
**
675675
** %fossil wiki commit PAGENAME ?FILE?
676676
**
677677
** Commit changes to a wiki page from FILE or from standard.
678678
**
@@ -686,29 +686,23 @@
686686
** Lists all wiki entries, one per line, ordered
687687
** case-insentively by name.
688688
**
689689
** TODOs:
690690
**
691
-** %fossil wiki export ?UUID? ?-f outfile[=stdout]? WikiName
691
+** %fossil wiki export ?-u UUID? WikiName ?FILE?
692692
**
693
-** Outputs the selected version of WikiName to the selected file.
693
+** Outputs the selected version of WikiName.
694694
**
695695
** %fossil wiki delete ?-m MESSAGE? WikiName
696696
**
697697
** The same as deleting a file entry, but i don't know if fossil
698698
** supports a commit message for Wiki entries.
699699
**
700700
** %fossil wiki ?-u? ?-d? ?-s=[|]? list
701701
**
702
-** Lists the UUID and/or Date of last change for each entry, delimited
703
-** by the -s char.
704
-**
705
-** %fossil wiki commit ?-f infile[=stdin]? WikiName
706
-**
707
-** Commit changes to a wiki page from a file or standard input.
708
-** It creats a new entry if needed (or is that philosophically
709
-** wrong?).
702
+** Lists the UUID and/or Date of last change along with each entry
703
+** name, delimited by the -s char.
710704
**
711705
** %fossil wiki diff ?UUID? ?-f infile[=stdin]? EntryName
712706
**
713707
** Diffs the local copy of a page with a given version (defaulting
714708
** to the head version).
@@ -723,17 +717,18 @@
723717
if( n==0 ){
724718
goto wiki_cmd_usage;
725719
}
726720
727721
if( strncmp(g.argv[2],"export",n)==0 ){
728
- char const *zPageName; /* Name of the wiki page to export */
722
+ char const *zPageName; /* Name of the wiki page to export */
723
+ char const *zFile; /* Name of the output file (0=stdout) */
729724
int rid; /* Artifact ID of the wiki page */
730725
int i; /* Loop counter */
731726
char *zBody = 0; /* Wiki page content */
732727
Manifest m; /* Parsed wiki page content */
733
- if( g.argc!=4 ){
734
- usage("export PAGENAME");
728
+ if( (g.argc!=4) && (g.argc!=5) ){
729
+ usage("export PAGENAME ?FILE?");
735730
}
736731
zPageName = g.argv[3];
737732
rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
738733
" WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
739734
" ORDER BY x.mtime DESC LIMIT 1",
@@ -749,11 +744,28 @@
749744
}
750745
if( zBody==0 ){
751746
fossil_fatal("wiki page [%s] not found",zPageName);
752747
}
753748
for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
754
- printf("%.*s\n", i, zBody);
749
+ zFile = (g.argc==4) ? 0 : g.argv[4];
750
+ if( zFile ){
751
+ FILE * zF;
752
+ short doClose = 0;
753
+ if( (1 == strlen(zFile)) && ('-'==zFile[0]) ){
754
+ zF = stdout;
755
+ }else{
756
+ zF = fopen( zFile, "w" );
757
+ doClose = zF ? 1 : 0;
758
+ }
759
+ if( ! zF ){
760
+ fossil_fatal("wiki export could not open output file for writing.");
761
+ }
762
+ fprintf(zF,"%.*s\n", i, zBody);
763
+ if( doClose ) fclose(zF);
764
+ }else{
765
+ printf("%.*s\n", i, zBody);
766
+ }
755767
return;
756768
}else
757769
if( strncmp(g.argv[2],"commit",n)==0
758770
|| strncmp(g.argv[2],"create",n)==0 ){
759771
char *zPageName;
760772
--- src/wiki.c
+++ src/wiki.c
@@ -665,14 +665,14 @@
665 **
666 ** Usage: %fossil wiki (export|commit|list) WikiName
667 **
668 ** Run various subcommands to fetch wiki entries.
669 **
670 ** %fossil wiki export PAGENAME
671 **
672 ** Sends the latest version of the PAGENAME wiki
673 ** entry to stdout.
674 **
675 ** %fossil wiki commit PAGENAME ?FILE?
676 **
677 ** Commit changes to a wiki page from FILE or from standard.
678 **
@@ -686,29 +686,23 @@
686 ** Lists all wiki entries, one per line, ordered
687 ** case-insentively by name.
688 **
689 ** TODOs:
690 **
691 ** %fossil wiki export ?UUID? ?-f outfile[=stdout]? WikiName
692 **
693 ** Outputs the selected version of WikiName to the selected file.
694 **
695 ** %fossil wiki delete ?-m MESSAGE? WikiName
696 **
697 ** The same as deleting a file entry, but i don't know if fossil
698 ** supports a commit message for Wiki entries.
699 **
700 ** %fossil wiki ?-u? ?-d? ?-s=[|]? list
701 **
702 ** Lists the UUID and/or Date of last change for each entry, delimited
703 ** by the -s char.
704 **
705 ** %fossil wiki commit ?-f infile[=stdin]? WikiName
706 **
707 ** Commit changes to a wiki page from a file or standard input.
708 ** It creats a new entry if needed (or is that philosophically
709 ** wrong?).
710 **
711 ** %fossil wiki diff ?UUID? ?-f infile[=stdin]? EntryName
712 **
713 ** Diffs the local copy of a page with a given version (defaulting
714 ** to the head version).
@@ -723,17 +717,18 @@
723 if( n==0 ){
724 goto wiki_cmd_usage;
725 }
726
727 if( strncmp(g.argv[2],"export",n)==0 ){
728 char const *zPageName; /* Name of the wiki page to export */
 
729 int rid; /* Artifact ID of the wiki page */
730 int i; /* Loop counter */
731 char *zBody = 0; /* Wiki page content */
732 Manifest m; /* Parsed wiki page content */
733 if( g.argc!=4 ){
734 usage("export PAGENAME");
735 }
736 zPageName = g.argv[3];
737 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
738 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
739 " ORDER BY x.mtime DESC LIMIT 1",
@@ -749,11 +744,28 @@
749 }
750 if( zBody==0 ){
751 fossil_fatal("wiki page [%s] not found",zPageName);
752 }
753 for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
754 printf("%.*s\n", i, zBody);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755 return;
756 }else
757 if( strncmp(g.argv[2],"commit",n)==0
758 || strncmp(g.argv[2],"create",n)==0 ){
759 char *zPageName;
760
--- src/wiki.c
+++ src/wiki.c
@@ -665,14 +665,14 @@
665 **
666 ** Usage: %fossil wiki (export|commit|list) WikiName
667 **
668 ** Run various subcommands to fetch wiki entries.
669 **
670 ** %fossil wiki export PAGENAME ?FILE?
671 **
672 ** Sends the latest version of the PAGENAME wiki
673 ** entry to the given file or standard output.
674 **
675 ** %fossil wiki commit PAGENAME ?FILE?
676 **
677 ** Commit changes to a wiki page from FILE or from standard.
678 **
@@ -686,29 +686,23 @@
686 ** Lists all wiki entries, one per line, ordered
687 ** case-insentively by name.
688 **
689 ** TODOs:
690 **
691 ** %fossil wiki export ?-u UUID? WikiName ?FILE?
692 **
693 ** Outputs the selected version of WikiName.
694 **
695 ** %fossil wiki delete ?-m MESSAGE? WikiName
696 **
697 ** The same as deleting a file entry, but i don't know if fossil
698 ** supports a commit message for Wiki entries.
699 **
700 ** %fossil wiki ?-u? ?-d? ?-s=[|]? list
701 **
702 ** Lists the UUID and/or Date of last change along with each entry
703 ** name, delimited by the -s char.
 
 
 
 
 
 
704 **
705 ** %fossil wiki diff ?UUID? ?-f infile[=stdin]? EntryName
706 **
707 ** Diffs the local copy of a page with a given version (defaulting
708 ** to the head version).
@@ -723,17 +717,18 @@
717 if( n==0 ){
718 goto wiki_cmd_usage;
719 }
720
721 if( strncmp(g.argv[2],"export",n)==0 ){
722 char const *zPageName; /* Name of the wiki page to export */
723 char const *zFile; /* Name of the output file (0=stdout) */
724 int rid; /* Artifact ID of the wiki page */
725 int i; /* Loop counter */
726 char *zBody = 0; /* Wiki page content */
727 Manifest m; /* Parsed wiki page content */
728 if( (g.argc!=4) && (g.argc!=5) ){
729 usage("export PAGENAME ?FILE?");
730 }
731 zPageName = g.argv[3];
732 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
733 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
734 " ORDER BY x.mtime DESC LIMIT 1",
@@ -749,11 +744,28 @@
744 }
745 if( zBody==0 ){
746 fossil_fatal("wiki page [%s] not found",zPageName);
747 }
748 for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
749 zFile = (g.argc==4) ? 0 : g.argv[4];
750 if( zFile ){
751 FILE * zF;
752 short doClose = 0;
753 if( (1 == strlen(zFile)) && ('-'==zFile[0]) ){
754 zF = stdout;
755 }else{
756 zF = fopen( zFile, "w" );
757 doClose = zF ? 1 : 0;
758 }
759 if( ! zF ){
760 fossil_fatal("wiki export could not open output file for writing.");
761 }
762 fprintf(zF,"%.*s\n", i, zBody);
763 if( doClose ) fclose(zF);
764 }else{
765 printf("%.*s\n", i, zBody);
766 }
767 return;
768 }else
769 if( strncmp(g.argv[2],"commit",n)==0
770 || strncmp(g.argv[2],"create",n)==0 ){
771 char *zPageName;
772

Keyboard Shortcuts

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