corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject [65/92] [abbrv] incubator-corinthia git commit: Provide get, put, and create commands in dfutil
Date Wed, 17 Dec 2014 13:29:15 GMT
Provide get, put, and create commands in dfutil

Replace the default action of dfutil from determining which type of
conversion should take place based on file extensions/existence, and
require the user to explicitly specify the action to be performed. These
are:

dfutil get concrete.docx abstract.html

    Create a new HTML file from a Word document. The HTML file must not
    already exist.

dfutil put concrete.docx abstract.html

    Update an existing Word document based on a modified HTML file. The
    Word document must already exist, and must be same document from
    which the HTML file was originally generated.

    The put operation cannot be executed twice on the same Word
    document, because after the first time, the fact that the document
    is modified will mean that the ids become out of sync with the HTML
    file.  If you want to update a document multiple times, you must
    create a copy of the .docx file each time, and update that.

dfutil create concrete.docx abstract.html

    Create a new Word document from a HTML file. The Word document must
    not already exist.


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/4f74168c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/4f74168c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/4f74168c

Branch: refs/heads/stable
Commit: 4f74168c13353be3fa0197075eb7c10d3794a7a9
Parents: 192c879
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Fri Dec 5 23:24:45 2014 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Fri Dec 5 23:32:35 2014 +0700

----------------------------------------------------------------------
 consumers/dfutil/src/Commands.c | 55 ------------------------------------
 consumers/dfutil/src/Commands.h |  1 -
 consumers/dfutil/src/main.c     | 35 +++++++++++++++++++++--
 3 files changed, 32 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/4f74168c/consumers/dfutil/src/Commands.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Commands.c b/consumers/dfutil/src/Commands.c
index 82f332d..f0c2895 100644
--- a/consumers/dfutil/src/Commands.c
+++ b/consumers/dfutil/src/Commands.c
@@ -232,61 +232,6 @@ int normalizeFile(const char *filename, DFError **error)
     return 1;
 }
 
-static int convertHTMLToLaTeX(const char *inFilename, const char *outFilename, DFError **error)
-{
-    DFDocument *htmlDoc = DFParseHTMLFile(inFilename,0,error);
-    if (htmlDoc == NULL) {
-        DFErrorFormat(error,"%s: %s",inFilename,DFErrorMessage(error));
-        return 0;
-    }
-
-    HTML_normalizeDocument(htmlDoc);
-    char *latex = HTMLToLaTeX(htmlDoc);
-
-
-    if (!DFStringWriteToFile(latex,outFilename,error)) {
-        DFErrorFormat(error,"%s: %s",inFilename,DFErrorMessage(error));
-        free(latex);
-        DFDocumentRelease(htmlDoc);
-        return 0;
-    }
-
-    free(latex);
-    DFDocumentRelease(htmlDoc);
-    return 1;
-}
-
-int convertFile(const char *inFilename, const char *outFilename, DFError **error)
-{
-    char *inExt = DFPathExtension(inFilename);
-    char *outExt = DFPathExtension(outFilename);
-    int result = 0;
-
-    if (DFStringEqualsCI(inExt,"docx") && DFStringEqualsCI(outExt,"html")) {
-        // Generate new HTML file from .docx
-        result = DFGetFile(inFilename,outFilename,error);
-    }
-    else if (DFStringEqualsCI(inExt,"html") && DFStringEqualsCI(outExt,"docx")) {
-        // Update existing .docx file from HTML
-        if (DFFileExists(inFilename))
-            result = DFPutFile(outFilename,inFilename,error);
-        else
-            result = DFCreateFile(outFilename,inFilename,error);
-    }
-    else if (DFStringEqualsCI(inExt,"html") && DFStringEqualsCI(outExt,"tex")) {
-        // Create new .tex file from HTML
-        result = convertHTMLToLaTeX(inFilename,outFilename,error);
-    }
-    else {
-        DFErrorFormat(error,"Unknown conversion type");
-        result = 0;
-    }
-
-    free(inExt);
-    free(outExt);
-    return result;
-}
-
 int testCSS(const char *filename, DFError **error)
 {
     char *input = DFStringReadFromFile(filename,error);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/4f74168c/consumers/dfutil/src/Commands.h
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Commands.h b/consumers/dfutil/src/Commands.h
index 88f75be..4add6c9 100644
--- a/consumers/dfutil/src/Commands.h
+++ b/consumers/dfutil/src/Commands.h
@@ -21,7 +21,6 @@
 int prettyPrintFile(const char *filename, DFError **error);
 int fromPlain(const char *inFilename, const char *outFilename, DFError **error);
 int normalizeFile(const char *filename, DFError **error);
-int convertFile(const char *inFilename, const char *outFilename, DFError **error);
 int testCSS(const char *filename, DFError **error);
 int parseHTMLFile(const char *filename, DFError **error);
 int textPackageList(const char *filename, DFError **error);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/4f74168c/consumers/dfutil/src/main.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/main.c b/consumers/dfutil/src/main.c
index c7e52cf..16bb2a7 100644
--- a/consumers/dfutil/src/main.c
+++ b/consumers/dfutil/src/main.c
@@ -20,6 +20,7 @@
 #include "StringTests.h"
 #include "DFZipFile.h"
 #include "DFCommon.h"
+#include <DocFormats/DocFormats.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -103,13 +104,41 @@ static int runCommand(int argc, const char **argv, DFError **dferr)
         DFPackageRelease(package);
         return r;
     }
-    else if (argc == 3) {
-        return convertFile(argv[1],argv[2],dferr);
+    else if ((argc == 4) && !strcmp(argv[1],"get")) {
+        return DFGetFile(argv[2],argv[3],dferr);
+    }
+    else if ((argc == 4) && !strcmp(argv[1],"put")) {
+        return DFPutFile(argv[2],argv[3],dferr);
+    }
+    else if ((argc == 4) && !strcmp(argv[1],"create")) {
+        return DFCreateFile(argv[2],argv[3],dferr);
     }
     else {
                ////////////////////////////////////////////////////////////////////////////////
         printf("Usage:\n"
-              "\n"
+               "\n"
+               "dfutil get concrete.docx abstract.html\n"
+               "\n"
+               "    Create a new HTML file from a Word document. The HTML file must not\n"
+               "    already exist.\n"
+               "\n"
+               "dfutil put concrete.docx abstract.html\n"
+               "\n"
+               "    Update an existing Word document based on a modified HTML file. The\n"
+               "    Word document must already exist, and must be same document from\n"
+               "    which the HTML file was originally generated.\n"
+               "\n"
+               "    The put operation cannot be executed twice on the same Word\n"
+               "    document, because after the first time, the fact that the document\n"
+               "    is modified will mean that the ids become out of sync with the HTML\n"
+               "    file.  If you want to update a document multiple times, you must\n"
+               "    create a copy of the .docx file each time, and update that.\n"
+               "\n"
+               "dfutil create concrete.docx abstract.html\n"
+               "\n"
+               "    Create a new Word document from a HTML file. The Word document must\n"
+               "    not already exist.\n"
+               "\n"
               "dfutil -pp filename\n"
               "    Print a plain text version of a .docx or .odt file to standard output\n"
               "\n"


Mime
View raw message