Check-in [7adbf773c2]
Not logged in
Overview

SHA1 Hash:7adbf773c2377e5289d22bf997314d23a71a6f56
Date: 2008-05-16 03:18:23
User: stephan
Comment:added optional FILE arg to wiki export
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/wiki.c from [fcc5e5e311] to [a15e177b1a].

@@ -665,14 +665,14 @@
 **
 ** 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.
 **
@@ -686,29 +686,23 @@
 **        Lists all wiki entries, one per line, ordered
 **        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
 **        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
 **        to the head version).
@@ -723,17 +717,18 @@
   if( n==0 ){
     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'"
       " ORDER BY x.mtime DESC LIMIT 1",
@@ -749,11 +744,28 @@
     }
     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 ){
     char *zPageName;