You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by pm...@apache.org on 2015/08/07 19:13:49 UTC
incubator-corinthia git commit: Replace dfutil with dfconvert
Repository: incubator-corinthia
Updated Branches:
refs/heads/Release_0.1 bf6274ceb -> 3afe8f659
Replace dfutil with dfconvert
The file conversion commands used to be in dfutil, but were moved to
dfconvert a while back. The latter is relevant for the release; dfutil
is now just a mixed bag of commands that aren't useful other than for a
small number of testing purposes.
Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/3afe8f65
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/3afe8f65
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/3afe8f65
Branch: refs/heads/Release_0.1
Commit: 3afe8f659b430f5c9605490298839d68a02fdad7
Parents: bf6274c
Author: Peter Kelly <pe...@uxproductivity.com>
Authored: Sat Aug 8 00:12:28 2015 +0700
Committer: Peter Kelly <pe...@uxproductivity.com>
Committed: Sat Aug 8 00:12:28 2015 +0700
----------------------------------------------------------------------
CMakeLists.txt | 2 +-
consumers/dfconvert/src/CMakeLists.txt | 49 ++++
consumers/dfconvert/src/main.c | 76 +++++
consumers/dfutil/src/CMakeLists.txt | 75 -----
consumers/dfutil/src/Commands.c | 438 ----------------------------
consumers/dfutil/src/Commands.h | 36 ---
consumers/dfutil/src/FunctionTests.h | 24 --
consumers/dfutil/src/FunctionTests.m | 155 ----------
consumers/dfutil/src/StringTests.h | 30 --
consumers/dfutil/src/StringTests.m | 193 ------------
consumers/dfutil/src/main.c | 161 ----------
11 files changed, 126 insertions(+), 1113 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 964adf3..5a24667 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -60,4 +60,4 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
###
add_subdirectory(DocFormats)
add_subdirectory(consumers/dftest/src)
-add_subdirectory(consumers/dfutil/src)
+add_subdirectory(consumers/dfconvert/src)
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfconvert/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/consumers/dfconvert/src/CMakeLists.txt b/consumers/dfconvert/src/CMakeLists.txt
new file mode 100644
index 0000000..595fe21
--- /dev/null
+++ b/consumers/dfconvert/src/CMakeLists.txt
@@ -0,0 +1,49 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+
+###
+## global definitions
+###
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+
+
+
+###
+## group source objects
+###
+set(SOURCES
+ main.c)
+
+
+
+###
+# Common include for all platform files
+###
+include_directories()
+include_directories(SYSTEM ${INCLUDE_DIRS})
+include_directories(SYSTEM ../../../DocFormats/api/headers)
+include_directories(SYSTEM ../../../DocFormats/headers)
+include_directories(.)
+link_directories(${LIB_DIRS})
+
+
+
+###
+# executable (release artifact)
+###
+add_executable(dfconvert ${SOURCES})
+target_link_libraries(dfconvert DocFormats ${LIBS})
+source_group(src FILES ${SOURCES})
+set_property(TARGET dfconvert PROPERTY FOLDER consumers)
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfconvert/src/main.c
----------------------------------------------------------------------
diff --git a/consumers/dfconvert/src/main.c b/consumers/dfconvert/src/main.c
new file mode 100644
index 0000000..7295691
--- /dev/null
+++ b/consumers/dfconvert/src/main.c
@@ -0,0 +1,76 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "DFPlatform.h"
+#include <DocFormats/DocFormats.h>
+#include <stdio.h>
+#include <string.h>
+
+void usage(void)
+{
+ printf("Usage:\n"
+ "\n"
+ "dfconvert 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"
+ "dfconvert 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"
+ "dfconvert 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"
+ "dfconvert does not yet convert odf or latex files.\n"
+ "\n");
+}
+
+int main(int argc, const char **argv)
+{
+ DFError *error = NULL;
+ if ((argc == 4) && !strcmp(argv[1],"get")) {
+ if (DFGetFile(argv[2],argv[3],&error))
+ return 0;
+ }
+ else if ((argc == 4) && !strcmp(argv[1],"put")) {
+ if (DFPutFile(argv[2],argv[3],&error))
+ return 0;
+ }
+ else if ((argc == 4) && !strcmp(argv[1],"create")) {
+ if (DFCreateFile(argv[2],argv[3],&error))
+ return 0;
+ }
+ else {
+ usage();
+ return 0;
+ }
+
+ fprintf(stderr,"Error: %s\n",DFErrorMessage(&error));
+ DFErrorRelease(error);
+ return 1;
+}
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfutil/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/CMakeLists.txt b/consumers/dfutil/src/CMakeLists.txt
deleted file mode 100644
index 0ed75db..0000000
--- a/consumers/dfutil/src/CMakeLists.txt
+++ /dev/null
@@ -1,75 +0,0 @@
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-
-###
-## global definitions
-###
-set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-
-
-
-###
-## group source objects
-###
-set(SOURCES
- Commands.c
- Commands.h
- FunctionTests.h
- StringTests.h
- main.c
-)
-
-
-
-###
-# Common include for all platform files
-###
-include_directories()
-include_directories(SYSTEM ${INCLUDE_DIRS})
-include_directories(SYSTEM ../../../DocFormats/api/headers)
-include_directories(.)
-include_directories(../../../DocFormats/headers)
-include_directories(../../../DocFormats/unittest)
-include_directories(../../../DocFormats/core/src/common)
-include_directories(../../../DocFormats/core/src/css)
-include_directories(../../../DocFormats/core/src/html)
-include_directories(../../../DocFormats/core/src/lib)
-include_directories(../../../DocFormats/core/src/names)
-include_directories(../../../DocFormats/core/src/xml)
-include_directories(../../../DocFormats/core/tests/html)
-include_directories(../../../DocFormats/core/tests/common)
-include_directories(../../../DocFormats/filters/latex/src)
-include_directories(../../../DocFormats/filters/odf/src)
-include_directories(../../../DocFormats/filters/ooxml/src/common)
-include_directories(../../../DocFormats/filters/ooxml/src/word)
-include_directories(../../../DocFormats/filters/ooxml/src/word/formatting)
-include_directories(../../../DocFormats/filters/ooxml/src/word/lenses)
-include_directories(../../../DocFormats/filters/ooxml/tests/word)
-include_directories(/usr/include/libxml2)
-link_directories(${LIB_DIRS})
-
-if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
- set(SOURCES ${SOURCES} FunctionTests.m StringTests.m)
-endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
-
-
-
-###
-# executable (release artifact)
-###
-add_executable(dfutil ${SOURCES})
-target_link_libraries(dfutil DocFormats ${LIBS})
-source_group(src FILES ${SOURCES})
-set_property(TARGET dfutil PROPERTY FOLDER consumers)
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfutil/src/Commands.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Commands.c b/consumers/dfutil/src/Commands.c
deleted file mode 100644
index e012e99..0000000
--- a/consumers/dfutil/src/Commands.c
+++ /dev/null
@@ -1,438 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "DFPlatform.h"
-#include "Commands.h"
-#include "BDTTests.h"
-#include "WordPlain.h"
-#include "HTMLPlain.h"
-#include "TextPackage.h"
-#include "StringTests.h"
-#include "DFChanges.h"
-#include "WordConverter.h"
-#include "DFHTML.h"
-#include "DFXML.h"
-#include "DFString.h"
-#include "DFFilesystem.h"
-#include "DFHTMLNormalization.h"
-#include "CSS.h"
-//not in release 0.1 #include "HTMLToLaTeX.h"
-#include "DFCommon.h"
-#include "DFZipFile.h"
-#include <DocFormats/DocFormats.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-static DFBuffer *readData(const char *filename, DFError **error)
-{
- if ((filename == NULL) || !strcmp(filename,"-"))
- filename = "/dev/stdin";;
- DFBuffer *buffer = DFBufferReadFromFile(filename,error);
- if (buffer == NULL) {
- DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
- return NULL;
- }
- return buffer;
-}
-
-static char *readString(const char *filename, DFError **error)
-{
- DFBuffer *buffer = readData(filename,error);
- if (buffer == NULL)
- return NULL;
- char *result = xstrdup(buffer->data);
- DFBufferRelease(buffer);
- return result;
-}
-
-static int writeData(DFBuffer *buf, const char *filename, DFError **error)
-{
- if ((filename == NULL) || !strcmp(filename,"-")) {
- fwrite(buf->data,buf->len,1,stdout);
- return 1;
- }
- else if (!DFBufferWriteToFile(buf,filename,error)) {
- DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
- return 0;
- }
- else {
- return 1;
- }
-}
-
-static int writeString(const char *str, const char *filename, DFError **error)
-{
- DFBuffer *buf = DFBufferNew();
- DFBufferAppendString(buf,str);
- int ok = writeData(buf,filename,error);
- DFBufferRelease(buf);
- return ok;
-}
-
-static int prettyPrintXMLFile(const char *filename, int html, DFError **error)
-{
- DFError *err = NULL;
- DFDocument *doc;
- if (html)
- doc = DFParseHTMLFile(filename,0,&err);
- else
- doc = DFParseXMLFile(filename,&err);
- if (doc == NULL)
- return 0;
-
- char *str = DFSerializeXMLString(doc,0,1);
- printf("%s",str);
- free(str);
- DFDocumentRelease(doc);
- return 1;
-}
-
-static int prettyPrintWordFile(const char *filename, DFError **error)
-{
- int ok = 0;
- char *plain = NULL;
- DFStorage *storage = NULL;
-
- storage = DFStorageOpenZip(filename,error);
- if (storage == NULL) {
- DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
- goto end;
- }
-
- plain = Word_toPlain(storage,NULL);
- printf("%s",plain);
-
- ok = 1;
-
-end:
- free(plain);
- DFStorageRelease(storage);
- return ok;
-}
-
-static int prettyPrintODFFile(const char *filename, DFError **error)
-{
- int ok = 0;
- char *odf = NULL;
- DFStorage *storage = NULL;
-
- storage = DFStorageOpenZip(filename,error);
-
- if (storage == NULL) {
- DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
- goto end;
- }
- /*
- odf = ODF_toPlain(storage,NULL);
- printf("%s",odt);
- */
- printf("ODF file support has not been implemented yet.\n");
- ok = 1;
-
-end:
- free(odf);
- DFStorageRelease(storage);
- return ok;
-
-}
-
-
-
-int prettyPrintFile(const char *filename, DFError **error)
-{
- int ok;
- char *extension = DFPathExtension(filename);
- if (DFStringEqualsCI(extension,"xml"))
- ok = prettyPrintXMLFile(filename,0,error);
- else if (DFStringEqualsCI(extension,"html") || DFStringEqualsCI(extension,"htm"))
- ok = prettyPrintXMLFile(filename,1,error);
- else if (DFStringEqualsCI(extension,"docx"))
- ok = prettyPrintWordFile(filename,error);
- else if (DFStringEqualsCI(extension,"odt"))
- ok = prettyPrintODFFile(filename,error);
- else {
- DFErrorFormat(error,"Unknown file type");
- ok = 0;
- }
- free(extension);
- return ok;
-}
-
-static int fromPlain2(const char *inStr, const char *inPath, const char *outFilename, DFError **error)
-{
- char *outExtension = DFPathExtension(outFilename);
- int isDocx = DFStringEqualsCI(outExtension,"docx");
- int ok = 0;
-
- if (!isDocx) {
- DFErrorFormat(error,"%s: Unknown extension",outFilename);
- goto end;
- }
-
- DFStorage *storage = NULL;
-
- storage = Word_fromPlain(inStr,inPath,error);
- if (storage == NULL)
- goto end;
-
- ok = DFZip(outFilename,storage,error);
- DFStorageRelease(storage);
-
- return ok;
-end:
- free(outExtension);
- return ok;
-}
-
-int fromPlain(const char *inFilename, const char *outFilename, DFError **error)
-{
- int fromStdin = !strcmp(inFilename,"-");
- char *inStr = readString(inFilename,error);
- if (inStr == NULL)
- return 0;
-
- char *inPath = fromStdin ? xstrdup(".") : DFPathDirName(inFilename);
- int ok = fromPlain2(inStr,inPath,outFilename,error);
- free(inPath);
- free(inStr);
- return ok;
-}
-
-int normalizeFile(const char *filename, DFError **error)
-{
- DFDocument *doc = DFParseHTMLFile(filename,0,error);
- if (doc == NULL) {
- DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
- return 0;
- }
-
- HTML_normalizeDocument(doc);
- HTML_safeIndent(doc->docNode,0);
- char *str = DFSerializeXMLString(doc,0,0);
- printf("%s",str);
- free(str);
- DFDocumentRelease(doc);
- return 1;
-}
-
-int testCSS(const char *filename, DFError **error)
-{
- char *input = DFStringReadFromFile(filename,error);
- if (input == NULL) {
- DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
- return 0;
- }
-
- CSSSheet *styleSheet = CSSSheetNew();
- CSSSheetUpdateFromCSSText(styleSheet,input);
- char *text = CSSSheetCopyText(styleSheet);
- printf("%s",text);
- free(text);
- printf("================================================================================\n");
- char *cssText = CSSSheetCopyCSSText(styleSheet);
- printf("%s",cssText);
- free(cssText);
- CSSSheetRelease(styleSheet);
- free(input);
-
- return 1;
-}
-
-int parseHTMLFile(const char *filename, DFError **error)
-{
- DFDocument *doc = DFParseHTMLFile(filename,0,error);
- if (doc == NULL)
- return 0;
- char *result = DFSerializeXMLString(doc,0,0);
- printf("%s",result);
- free(result);
- DFDocumentRelease(doc);
- return 1;
-}
-
-static int textPackageListRecursive(const char *input, const char *filePath, DFError **error, int indent)
-{
- TextPackage *package = TextPackageNewWithString(input,filePath,error);
- if (package == NULL)
- return 0;
- if (package->nkeys == 1) {
- TextPackageRelease(package);
- return 1;
- }
- for (size_t ki = 0; ki < package->nkeys; ki++) {
- const char *key = package->keys[ki];
- if (strlen(key) == 0)
- continue;
- for (int i = 0; i < indent; i++)
- printf(" ");
- printf("%s\n",key);
- const char *value = DFHashTableLookup(package->items,key);
- if (!textPackageListRecursive(value,filePath,error,indent+1)) {
- TextPackageRelease(package);
- return 0;
- }
- }
- TextPackageRelease(package);
- return 1;
-}
-
-int textPackageList(const char *filename, DFError **error)
-{
- char *filePath = DFPathDirName(filename);
- char *value = DFStringReadFromFile(filename,error);
- int result = 0;
- if (value == NULL)
- DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
- else if (!textPackageListRecursive(value,filePath,error,0))
- DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
- else
- result = 1;
-
- free(filePath);
- free(value);
- return result;
-}
-
-int textPackageGet(const char *filename, const char *itemPath, DFError **error)
-{
- char *value = DFStringReadFromFile(filename,error);
- if (value == NULL) {
- DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
- return 0;
- }
-
- const char **components = DFStringSplit(itemPath,"/",0);
- for (size_t i = 0; components[i]; i++) {
- const char *name = components[i];
- char *filePath = DFPathDirName(filename);
- TextPackage *package = TextPackageNewWithString(value,filePath,error);
- free(filePath);
- if (package == NULL) {
- free(value);
- free(components);
- return 0;
- }
- free(value);
- value = xstrdup(DFHashTableLookup(package->items,name));
- if (value == NULL) {
- DFErrorFormat(error,"%s: Item %s not found",filename,itemPath);
- TextPackageRelease(package);
- free(value);
- free(components);
- return 0;
- }
- TextPackageRelease(package);
- }
- free(components);
-
- printf("%s",value);
- free(value);
- return 1;
-}
-
-int diffFiles(const char *filename1, const char *filename2, DFError **error)
-{
- DFDocument *doc1 = DFParseHTMLFile(filename1,0,error);
- if (doc1 == NULL) {
- DFErrorFormat(error,"%s: %s",filename1,DFErrorMessage(error));
- return 0;
- }
-
- DFDocument *doc2 = DFParseHTMLFile(filename1,0,error);
- if (doc2 == NULL) {
- DFErrorFormat(error,"%s: %s",filename2,DFErrorMessage(error));
- DFDocumentRelease(doc1);
- return 0;
- }
-
- DFComputeChanges(doc1->root,doc2->root,HTML_ID);
- char *changesStr = DFChangesToString(doc1->root);
- printf("%s",changesStr);
- free(changesStr);
-
- DFDocumentRelease(doc1);
- DFDocumentRelease(doc2);
- return 1;
-}
-
-void parseContent(const char *content)
-{
- DFArray *parts = CSSParseContent(content);
- printf("parts.count = %zu\n",DFArrayCount(parts));
- for (size_t i = 0; i < DFArrayCount(parts); i++) {
- ContentPart *part = DFArrayItemAt(parts,i);
- char *quotedValue = DFQuote(part->value);
- printf("%s %s\n",ContentPartTypeString(part->type),quotedValue);
- free(quotedValue);
- }
- DFArrayRelease(parts);
-}
-
-int btosFile(const char *inFilename, const char *outFilename, DFError **error)
-{
- DFBuffer *data = readData(inFilename,error);
- if (data == NULL)
- return 0;
- char *str = binaryToString(data);
- int ok = writeString(str,outFilename,error);
- free(str);
- DFBufferRelease(data);
- return ok;
-}
-
-int stobFile(const char *inFilename, const char *outFilename, DFError **error)
-{
- char *str = readString(inFilename,error);
- if (str == NULL)
- return 0;;
- DFBuffer *bin = stringToBinary(str);
- int ok = writeData(bin,outFilename,error);
- DFBufferRelease(bin);
- free(str);
- return ok;
-}
-
-int escapeCSSIdent(const char *filename, DFError **error)
-{
- char *input = readString(filename,error);
- if (input == NULL)
- return 0;
- char *unescaped = DFStringTrimWhitespace(input);
- char *escaped = CSSEscapeIdent(unescaped);
- printf("%s\n",escaped);
- free(escaped);
- free(unescaped);
- free(input);
- return 1;
-}
-
-int unescapeCSSIdent(const char *filename, DFError **error)
-{
- char *input = readString(filename,error);
- if (input == NULL)
- return 0;
- char *escaped = DFStringTrimWhitespace(input);
- char *unescaped = CSSUnescapeIdent(escaped);
- printf("%s\n",unescaped);
- free(unescaped);
- free(escaped);
- free(input);
- return 1;
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfutil/src/Commands.h
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Commands.h b/consumers/dfutil/src/Commands.h
deleted file mode 100644
index 44fbcc1..0000000
--- a/consumers/dfutil/src/Commands.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-#include <DocFormats/DFError.h>
-#include "DFBuffer.h"
-
-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 testCSS(const char *filename, DFError **error);
-int parseHTMLFile(const char *filename, DFError **error);
-int textPackageList(const char *filename, DFError **error);
-int textPackageGet(const char *filename, const char *itemPath, DFError **error);
-int printTree(const char *filename, DFError **error);
-int diffFiles(const char *filename1, const char *filename2, DFError **error);
-void parseContent(const char *content);
-int btosFile(const char *inFilename, const char *outFilename, DFError **error);
-int stobFile(const char *inFilename, const char *outFilename, DFError **error);
-int escapeCSSIdent(const char *filename, DFError **error);
-int unescapeCSSIdent(const char *filename, DFError **error);
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfutil/src/FunctionTests.h
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/FunctionTests.h b/consumers/dfutil/src/FunctionTests.h
deleted file mode 100644
index 2e611d8..0000000
--- a/consumers/dfutil/src/FunctionTests.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-#ifdef __APPLE__
-
-void testPathFunctions(void);
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfutil/src/FunctionTests.m
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/FunctionTests.m b/consumers/dfutil/src/FunctionTests.m
deleted file mode 100644
index 037ac45..0000000
--- a/consumers/dfutil/src/FunctionTests.m
+++ /dev/null
@@ -1,155 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#import <Foundation/Foundation.h>
-#include "DFPlatform.h"
-#include "FunctionTests.h"
-#include "DFString.h"
-#include "DFFilesystem.h"
-
-static NSString *NSStringFromC(const char *cstr)
-{
- if (cstr == NULL)
- return NULL;
- else
- return [NSString stringWithUTF8String: cstr];
-}
-
-static void printResult(const char *input, const char *expected, const char *actual)
-{
- char *quotedInput = DFQuote(input);
- char *quotedExpected = DFQuote(expected);
- char *quotedActual = DFQuote(actual);
- char *resultStr = !strcmp(expected,actual) ? "PASS": "FAIL";
-
- printf("%-30s %-30s %-30s %s\n",quotedInput,quotedExpected,quotedActual,resultStr);
-
- free(quotedInput);
- free(quotedExpected);
- free(quotedActual);
-}
-
-static void testDirName(const char *input)
-{
- const char *expected = NSStringFromC(input).stringByDeletingLastPathComponent.UTF8String;
- char *actual = DFPathDirName(input);
- printResult(input,expected,actual);
- free(actual);
-}
-
-static void testBaseName(const char *input)
-{
- const char *expected = NSStringFromC(input).lastPathComponent.UTF8String;
- char *actual = DFPathBaseName(input);
- printResult(input,expected,actual);
- free(actual);
-}
-
-static void testPathExtension(const char *input)
-{
- const char *expected = NSStringFromC(input).pathExtension.UTF8String;
- char *actual = DFPathExtension(input);
- printResult(input,expected,actual);
- free(actual);
-}
-
-static void testPathWithoutExtension(const char *input)
-{
- const char *expected = NSStringFromC(input).stringByDeletingPathExtension.UTF8String;
- char *actual = DFPathWithoutExtension(input);
- printResult(input,expected,actual);
- free(actual);
-}
-
-static const char *dirTests[] = {
- "/one/two/three",
- "/one/two/three/",
- "one/two/three",
- "one/two/three/",
- "something",
- "something/",
- "/something/",
- "/something",
- NULL,
-};
-
-static const char *extensionTests[] = {
- "filename.ext",
- "filename",
- "one/two/filename.ext",
- "one/two/filename",
- "/one/two/filename.ext",
- "/one/two/filename",
- "/one/two/three.ext/",
- "/one/two.ext/three/",
- "/one/two.ext/three",
- "/",
- "",
- NULL,
-};
-
-static struct { const char *path1; const char *path2; } appendTests[] = {
- { "one", "two" },
- { "one/", "two" },
- { "one", "/two" },
- { "one/", "/two" },
- { "one/two", "three" },
- { "one//two", "three" },
- { "one", "two/three" },
- { "one", "two//three" },
- { "/", "one" },
- { "/", "/one" },
- { "", "one" },
- { "", "/one" },
- { "one", "" },
- { "one", "/" },
- { "one", "two/" },
- { "one", "two//" },
- { NULL, NULL },
-};
-
-static void testAppendPathComponent(const char *input1, const char *input2)
-{
- const char *expected = ([NSStringFromC(input1) stringByAppendingPathComponent: NSStringFromC(input2)]).UTF8String;
- char *actual = DFAppendPathComponent(input1,input2);
- char *quoteInput = DFFormatString("'%s' '%s'",input1,input2);
- printResult(quoteInput,expected,actual);
- free(actual);
- free(quoteInput);
-}
-
-void testPathFunctions(void)
-{
- printf("DFDirName\n\n");
- for (int i = 0; 0 < dirTests[i]; i++)
- testDirName(dirTests[i]);
-
- printf("\nDFBaseName\n\n");
- for (int i = 0; 0 < dirTests[i]; i++)
- testBaseName(dirTests[i]);
-
- printf("\nDFPathExtension\n\n");
- for (int i = 0; extensionTests[i]; i++)
- testPathExtension(extensionTests[i]);
-
- printf("\nDFPathWithoutExtension\n\n");
- for (int i = 0; extensionTests[i]; i++)
- testPathWithoutExtension(extensionTests[i]);
-
- for (int i = 0; appendTests[i].path1; i++)
- testAppendPathComponent(appendTests[i].path1,appendTests[i].path2);
-}
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfutil/src/StringTests.h
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/StringTests.h b/consumers/dfutil/src/StringTests.h
deleted file mode 100644
index bd8eb53..0000000
--- a/consumers/dfutil/src/StringTests.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-#include <stdint.h>
-
-#ifdef __APPLE__
-
-int testDFNextChar(const uint32_t *input32, size_t len32);
-int testDFPrevChar(const uint32_t *input32, size_t len32);
-uint32_t *genTestUTF32String(size_t len32);
-int testUnicode(void);
-int testStrings(void);
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfutil/src/StringTests.m
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/StringTests.m b/consumers/dfutil/src/StringTests.m
deleted file mode 100644
index aca2524..0000000
--- a/consumers/dfutil/src/StringTests.m
+++ /dev/null
@@ -1,193 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#import <Foundation/Foundation.h>
-#include "DFPlatform.h"
-#include "StringTests.h"
-#include "DFString.h"
-
-int testDFNextChar(const uint32_t *input32, size_t len32)
-{
- printf("Testing DFNextChar\n");
- NSString *ns = [[NSString alloc] initWithBytes: input32 length: len32*sizeof(uint32_t)
- encoding: NSUTF32LittleEndianStringEncoding];
- assert(ns != nil);
-
- int widthHistogram[5];
- bzero(widthHistogram,5*sizeof(int));
-
- const char *eight = ns.UTF8String;
- size_t pos8 = 0;
- size_t pos32 = 0;
- int errors = 0;
- for (;;) {
- size_t oldpos8 = pos8;
- uint32_t ch = DFNextChar(eight,&pos8);
- ssize_t nbytes = pos8 - oldpos8;
- assert((pos32 == len32) || (nbytes > 0));
- if (pos32 < len32) {
- assert(nbytes >= 1);
- assert(nbytes <= 4);
- widthHistogram[nbytes]++;
- }
- if (ch != input32[pos32])
- errors++;
- if (pos32 == len32)
- break;
- pos32++;
- }
-
- for (int i = 1; i <= 4; i++) {
- printf(" Characters requiring %d bytes: %d\n",i,widthHistogram[i]);
- }
- printf(" Total characters: %lu\n",len32);
- printf(" Total bytes: %lu\n",strlen(eight));
- printf(" Errors: %d\n",errors);
- return errors;
-}
-
-int testDFPrevChar(const uint32_t *input32, size_t len32)
-{
- printf("Testing DFPrevChar\n");
- assert(len32 > 0);
- NSString *ns = [[NSString alloc] initWithBytes: input32 length: len32*sizeof(uint32_t)
- encoding: NSUTF32LittleEndianStringEncoding];
- assert(ns != nil);
-
- int widthHistogram[5];
- bzero(widthHistogram,5*sizeof(int));
-
- const char *eight = ns.UTF8String;
- assert(strlen(eight) > 0);
- size_t pos8 = strlen(eight) - 1;
- size_t pos32 = len32-1;
- int errors = 0;
- for (;;) {
- size_t oldpos8 = pos8;
- uint32_t ch = DFPrevChar(eight,&pos8);
- ssize_t nbytes = oldpos8 - pos8;
- assert((pos32 == len32) || (nbytes > 0));
- if (pos32 < len32) {
- assert(nbytes >= 1);
- assert(nbytes <= 4);
- widthHistogram[nbytes]++;
- }
- if (ch != input32[pos32])
- errors++;
- if (pos32 == 0)
- break;
- pos32--;
- }
-
- for (int i = 1; i <= 4; i++) {
- printf(" Characters requiring %d bytes: %d\n",i,widthHistogram[i]);
- }
- printf(" Total characters: %lu\n",len32);
- printf(" Total bytes: %lu\n",strlen(eight));
- printf(" Errors: %d\n",errors);
- return errors;
-}
-
-uint32_t *genTestUTF32String(size_t len32)
-{
- uint32_t *str32 = (uint32_t *)malloc((len32+1)*sizeof(uint32_t));
- for (size_t i = 0; i < len32; i++) {
- do {
- uint32_t min = 0;
- uint32_t max = 0;
-
- int nbytes = 1 + (rand()%4);
- switch (nbytes) {
- case 1:
- min = 0;
- max = 0x7F;
- break;
- case 2:
- min = 0x80;
- max = 0x7FF;
- break;
- case 3:
- min = 0x800;
- max = 0xFFFF;
- break;
- case 4:
- min = 0x10000;
- max = 0x10FFFF;
- break;
- default:
- assert(0);
- break;
- }
-
- assert(max > 0);
-
- str32[i] = min + rand()%(max - min);
-
- assert(str32[i] < 0x10FFFF);
- } while ((str32[i] == 0) || ((str32[i] >= 0xD800) && (str32[i] <= 0xDFFF)));
- }
- str32[len32] = 0;
- return str32;
-}
-
-int testUnicode(void)
-{
- int pass = 1;
- uint32_t value;
- uint32_t array[2];
- for (value = 1; value <= 0x10FFFF; value++) {
-
- if ((value >= 0xD800) && (value <= 0xDFFF))
- continue;
-
- @autoreleasepool {
- array[0] = value;
- array[1] = 0;
-
- NSString *str = [[NSString alloc] initWithBytes: &value length: 4 encoding: NSUTF32LittleEndianStringEncoding];
- const char *nsutf8 = str.UTF8String;
- char *myutf8 = DFUTF32to8(array);
- if (strcmp(nsutf8,myutf8)) {
- printf("value = 0x%X FAIL 32 to 8\n",value);
- pass = 0;
- }
- else {
- uint32_t *myutf32 = DFUTF8To32(myutf8);
- int mylen = 0;
- while (myutf32[mylen] != 0)
- mylen++;
- if ((mylen != 1) || (myutf32[0] != value)) {
- printf("value = 0x%X FAIL 8 to 32\n",value);
- pass = 0;
- }
- else {
- printf("value = 0x%X PASS\n",value);
- }
- }
- }
- }
- return pass;
-}
-
-int testStrings(void)
-{
- size_t len32 = 1024*1024;
- uint32_t *str32 = genTestUTF32String(len32);
- testDFNextChar(str32,len32);
- testDFPrevChar(str32,len32);
- return 1;
-}
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3afe8f65/consumers/dfutil/src/main.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/main.c b/consumers/dfutil/src/main.c
deleted file mode 100644
index c3b1ba5..0000000
--- a/consumers/dfutil/src/main.c
+++ /dev/null
@@ -1,161 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "DFPlatform.h"
-#include "Commands.h"
-#include "BDTTests.h"
-#include "WordPlain.h"
-#include "HTMLPlain.h"
-#include "FunctionTests.h"
-#include "StringTests.h"
-#include "DFZipFile.h"
-#include "DFCommon.h"
-#include "DFFilesystem.h"
-#include <DocFormats/DocFormats.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-static int runCommand(int argc, const char **argv, DFError **dferr)
-{
- if ((argc == 3) && !strcmp(argv[1],"-pp")) {
- return prettyPrintFile(argv[2],dferr);
- }
- else if ((argc == 4) && !strcmp(argv[1],"-fp")) {
- return fromPlain(argv[2],argv[3],dferr);
- }
- else if ((argc == 3) && !strcmp(argv[1],"-normalize")) {
- return normalizeFile(argv[2],dferr);
- }
- else if ((argc >= 2) && !strcmp(argv[1],"-bdt")) {
- BDT_Test(argc-2,&argv[2]);
- return 1;
- }
- else if ((argc == 3) && !strcmp(argv[1],"-css")) {
- return testCSS(argv[2],dferr);
- }
- else if ((argc == 3) && !strcmp(argv[1],"-parsehtml")) {
- return parseHTMLFile(argv[2],dferr);
- }
- else if ((argc == 3) && !strcmp(argv[1],"-tplist")) {
- return textPackageList(argv[2],dferr);
- }
- else if ((argc == 4) && !strcmp(argv[1],"-tpget")) {
- return textPackageGet(argv[2],argv[3],dferr);
- }
- else if ((argc == 4) && !strcmp(argv[1],"-diff")) {
- return diffFiles(argv[2],argv[3],dferr);
- }
- else if ((argc == 3) && !strcmp(argv[1],"-parsecontent")) {
- parseContent(argv[2]);
- return 1;
- }
- else if ((argc >= 2) && !strcmp(argv[1],"-btos")) {
- const char *inFilename = (argc >= 3) ? argv[2] : NULL;
- const char *outFilename = (argc >= 4) ? argv[3] : NULL;
- return btosFile(inFilename,outFilename,dferr);
- }
- else if ((argc >= 2) && !strcmp(argv[1],"-stob")) {
- const char *inFilename = (argc >= 3) ? argv[2] : NULL;
- const char *outFilename = (argc >= 4) ? argv[3] : NULL;
- return stobFile(inFilename,outFilename,dferr);
- }
- else if ((argc == 3) && (!strcmp(argv[1],"-css-escape"))) {
- return escapeCSSIdent(argv[2],dferr);
- }
- else if ((argc == 3) && (!strcmp(argv[1],"-css-unescape"))) {
- return unescapeCSSIdent(argv[2],dferr);
- }
-#ifdef __APPLE__
- else if ((argc == 2) && (!strcmp(argv[1],"-test-unicode"))) {
- return testUnicode();
- }
- else if ((argc == 2) && (!strcmp(argv[1],"-test-strings"))) {
- return testStrings();
- }
- else if ((argc == 2) && (!strcmp(argv[1],"-test-path"))) {
- testPathFunctions();
- return 1;
- }
-#endif
- else if ((argc == 4) && !strcmp(argv[1],"-zip")) {
- DFStorage *storage = DFStorageNewFilesystem(argv[3],DFFileFormatUnknown);
- int r = DFZip(argv[2],storage,dferr);
- DFStorageRelease(storage);
- return r;
- }
- else if ((argc == 4) && !strcmp(argv[1],"-unzip")) {
- DFStorage *storage = DFStorageNewFilesystem(argv[3],DFFileFormatUnknown);
- int r = DFUnzip(argv[2],storage,dferr);
- DFStorageRelease(storage);
- return r;
- }
- else {
- ////////////////////////////////////////////////////////////////////////////////
- printf("Usage:\n"
- "\n"
- "dfutil -pp filename\n"
- " Print a plain text version of a .docx or .odt file to standard output\n"
- "\n"
- "dfutil -fp infilename outfilename\n"
- " Create a .docx or .odt file based on a plain text representation. If\n"
- " infilename is -, read from standard input.\n"
- "\n"
- "dfutil -normalize filename\n"
- " Normalize a HTML file\n"
- "\n"
- "dfutil -parsecontent string\n"
- " Parse a value as if it were given as a CSS 'content' property, and print parts\n"
- "\n"
- "dfutil -btos [infilename] [outfilename]\n"
- " Convert binary data to string\n"
- "\n"
- "dfutil -stob [infilename] [outfilename]\n"
- " Convert string to binary data\n"
- "\n"
- "dfutil -css-escape [infilename]\n"
- " Escape CSS class name\n"
- "\n"
- "dfutil -css-unescape [infilename]\n"
- " Unescape CSS class name\n"
- "\n"
- "dfutil -zip zipFilename sourceDir\n"
- " Create a zip file\n"
- "\n"
- "dfutil -unzip zipFilename destDir\n"
- " Extract a zip file\n"
- "\n"
- "dfutil input.html output.docx\n"
- "dfutil input.html output.odt\n"
- "dfutil input.docx output.html\n"
- "dfutil input.docx output.html\n"
- " Convert to/from .docx or .odt and .html\n");
- return 1;
- }
-}
-
-int main(int argc, const char * argv[])
-{
- int r = 0;
- DFError *dferr = NULL;
- if (!runCommand(argc,argv,&dferr)) {
- fprintf(stderr,"%s\n",DFErrorMessage(&dferr));
- DFErrorRelease(dferr);
- r = 1;
- }
- return r;
-}