Diff
Not logged in

Differences From:

File src/wiki.c part of check-in [e03d1be55b] - Added new "wiki create" command. Cleaned up the "wiki commit" code and added an option filename argument to both "wiki commit" and "wiki create". by drh on 2008-05-16 01:43:55. [view]

To:

File src/wiki.c part of check-in [7adbf773c2] - added optional FILE arg to wiki export by stephan on 2008-05-16 03:18:23. [view]

@@ -666,12 +666,12 @@
 ** Usage: %fossil wiki (export|commit|list) WikiName
 **
 ** Run various subcommands to fetch wiki entries.
 **
-**     %fossil wiki export PAGENAME
+**     %fossil wiki export PAGENAME ?FILE?
 **
 **        Sends the latest version of the PAGENAME wiki
-**        entry to stdout.
+**        entry to the given file or standard output.
 **
 **     %fossil wiki commit PAGENAME ?FILE?
 **
 **        Commit changes to a wiki page from FILE or from standard.
@@ -687,11 +687,11 @@
 **        case-insentively by name.
 **
 ** TODOs:
 **
-**     %fossil wiki export ?UUID? ?-f outfile[=stdout]? WikiName
+**     %fossil wiki export ?-u UUID? WikiName ?FILE?
 **
-**        Outputs the selected version of WikiName to the selected file.
+**        Outputs the selected version of WikiName.
 **
 **     %fossil wiki delete ?-m MESSAGE? WikiName
 **
 **        The same as deleting a file entry, but i don't know if fossil
@@ -698,16 +698,10 @@
 **        supports a commit message for Wiki entries.
 **
 **     %fossil wiki ?-u? ?-d? ?-s=[|]? list
 **
-**        Lists the UUID and/or Date of last change for each entry, delimited
-**        by the -s char.
-**
-**     %fossil wiki commit ?-f infile[=stdin]? WikiName
-**
-**        Commit changes to a wiki page from a file or standard input.
-**        It creats a new entry if needed (or is that philosophically
-**        wrong?).
+**        Lists the UUID and/or Date of last change along with each entry
+**        name, delimited by the -s char.
 **
 **     %fossil wiki diff ?UUID? ?-f infile[=stdin]? EntryName
 **
 **        Diffs the local copy of a page with a given version (defaulting
@@ -724,15 +718,16 @@
     goto wiki_cmd_usage;
   }
 
   if( strncmp(g.argv[2],"export",n)==0 ){
-    char const *zPageName;            /* Name of the wiki page to export */
+    char const *zPageName;        /* Name of the wiki page to export */
+    char const *zFile;            /* Name of the output file (0=stdout) */
     int rid;                /* Artifact ID of the wiki page */
     int i;                  /* Loop counter */
     char *zBody = 0;        /* Wiki page content */
     Manifest m;             /* Parsed wiki page content */
-    if( g.argc!=4 ){
-      usage("export PAGENAME");
+    if( (g.argc!=4) && (g.argc!=5) ){
+      usage("export PAGENAME ?FILE?");
     }
     zPageName = g.argv[3];
     rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
       " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
@@ -750,9 +745,26 @@
     if( zBody==0 ){
       fossil_fatal("wiki page [%s] not found",zPageName);
     }
     for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
-    printf("%.*s\n", i, zBody);
+    zFile  = (g.argc==4) ? 0 : g.argv[4];
+    if( zFile ){
+      FILE * zF;
+      short doClose = 0;
+      if( (1 == strlen(zFile)) && ('-'==zFile[0]) ){
+        zF = stdout;
+      }else{
+        zF = fopen( zFile, "w" );
+        doClose = zF ? 1 : 0;
+      }
+      if( ! zF ){
+        fossil_fatal("wiki export could not open output file for writing.");
+      }
+      fprintf(zF,"%.*s\n", i, zBody);
+      if( doClose ) fclose(zF);
+    }else{
+	printf("%.*s\n", i, zBody);
+    }
     return;
   }else
   if( strncmp(g.argv[2],"commit",n)==0
       || strncmp(g.argv[2],"create",n)==0 ){