Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Add script to compile/install/distribute antiword
Browse files Browse the repository at this point in the history
This days Git on Windows is used not only for code, but more and more
for managing documentation workflow. And on Windows a lot of people use
*.doc as document format.

So the idea is to provide textconv diff & blame support for *.doc out of
the box, for which we'll need default textconv driver.

Personally I've been using antiword on Linux for such porpose for quite
some time already, and while not perfect, antiword works ok -- I can see
what's changed in git, and `git gui blame` docs, which is great to me.

NOTE: antiword needs to access files with encoding mapping tables, and since we
are going to add antiword to distribution (next patch) for this I had to patch
it to determine installation prefix at runtime, just like git does.

Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru>
  • Loading branch information
Kirill Smelkov authored and navytux committed Dec 20, 2010
1 parent e4b7f18 commit dff9bb0
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/antiword/.gitignore
@@ -0,0 +1 @@
/antiword-git/
23 changes: 23 additions & 0 deletions src/antiword/patches/0001-Add-.gititgnore.patch
@@ -0,0 +1,23 @@
From 6e97f006d17627866155bbe27344b18df11a3c96 Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@mns.spb.ru>
Date: Wed, 24 Nov 2010 21:24:41 +0300
Subject: [PATCH 1/4] Add .gititgnore

Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru>
---
.gitignore | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
create mode 100644 .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..28febf5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.o
+*.exe
+tags
--
1.7.3.2.245.g03276

@@ -0,0 +1,50 @@
From c1b802eeb0307db3e90bd2fca702256652331758 Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@mns.spb.ru>
Date: Wed, 10 Nov 2010 20:02:19 +0300
Subject: [PATCH 2/4] antiword: Tweak Makefile.Linux for msysGit

It is easier to start from Makefile.Linux because even if there is
Makefile.cygming as we'll see in later patches, it does not serve our purposes
well - we'll still need to change installed location and runtime path for
resources...

Also we don't need kantiword, and /usr/local/bin/ -> /usr/bin/

Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru>
---
Makefile.Linux | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Makefile.Linux b/Makefile.Linux
index eeb2d15..65af1df 100644
--- a/Makefile.Linux
+++ b/Makefile.Linux
@@ -30,13 +30,13 @@ OBJS =\
wordlib.o wordmac.o wordole.o wordwin.o xmalloc.o xml.o

PROGS =\
- antiword\
- kantiword
+ antiword.exe
+# kantiword

LOCAL_INSTALL_DIR = $(HOME)/bin
LOCAL_RESOURCES_DIR = $(HOME)/.antiword

-GLOBAL_INSTALL_DIR = /usr/local/bin
+GLOBAL_INSTALL_DIR = /usr/bin
GLOBAL_RESOURCES_DIR = /usr/share/antiword

all: $(PROGS)
@@ -71,7 +71,7 @@ clean:
rm -f $(OBJS)
rm -f $(PROGS)

-antiword: $(OBJS)
+antiword.exe: $(OBJS)
@rm -f $@
$(LD) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
@chmod 750 $@
--
1.7.3.2.245.g03276

@@ -0,0 +1,46 @@
From 5985c61e19256d51f281d87e6610760663854b30 Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@mns.spb.ru>
Date: Wed, 24 Nov 2010 21:27:58 +0300
Subject: [PATCH 3/4] Tech szBasename about '/' and '\\' path separators (win32 only)

Previously it was using '/' on linux and '\' on mingw. Since on windows
path separator can be on of those two, teach szBasename about it.

Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru>
---
misc.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/misc.c b/misc.c
index 609a2f0..63d1c91 100644
--- a/misc.c
+++ b/misc.c
@@ -519,7 +519,7 @@ unilen(const UCHAR *s)
const char *
szBasename(const char *szFilename)
{
- const char *szTmp;
+ const char *tail;

fail(szFilename == NULL);

@@ -527,11 +527,12 @@ szBasename(const char *szFilename)
return "null";
}

- szTmp = strrchr(szFilename, FILE_SEPARATOR[0]);
- if (szTmp == NULL) {
- return szFilename;
+ /* check for both '/' and '\\' */
+ for (tail = szFilename+strlen(szFilename)-1; tail >= szFilename; --tail) {
+ if (*tail == '/' || *tail == '\\')
+ return tail+1;
}
- return ++szTmp;
+ return szFilename;
} /* end of szBasename */

/*
--
1.7.3.2.245.g03276

140 changes: 140 additions & 0 deletions src/antiword/patches/0004-Implement-runtime-prefix-detection.patch
@@ -0,0 +1,140 @@
From 9860d61871f53e94d0780061fcab4e5951e10215 Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@mns.spb.ru>
Date: Wed, 24 Nov 2010 21:29:41 +0300
Subject: [PATCH 4/4] Implement runtime prefix detection

Antiword needs prefix to know where to look for encoding map tables.
Don't hardcode this prefix, and instead do, what Git does - determine it
at runtime.

Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru>
---
antiword.h | 2 ++
fonts_u.c | 6 ++++--
misc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
options.c | 8 ++++----
4 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/antiword.h b/antiword.h
index 3f4aad5..1e4a384 100644
--- a/antiword.h
+++ b/antiword.h
@@ -430,6 +430,8 @@ extern USHORT usGetListValue(int, int, const style_block_type *);
#if !defined(__riscos)
extern const char *szGetHomeDirectory(void);
extern const char *szGetAntiwordDirectory(void);
+extern const char *szGetAntiwordRuntimePrefix(void);
+extern const char *szGetAntiwordRuntimeDir(void);
#endif /* !__riscos */
extern long lGetFilesize(const char *);
#if defined(DEBUG)
diff --git a/fonts_u.c b/fonts_u.c
index a99f7d2..812830e 100644
--- a/fonts_u.c
+++ b/fonts_u.c
@@ -27,7 +27,8 @@ FILE *
pOpenFontTableFile(void)
{
FILE *pFile;
- const char *szHome, *szAntiword, *szGlobalFile;
+ const char *szHome, *szAntiword;
+ char szGlobalFile[PATH_MAX+1];
char szEnvironmentFile[PATH_MAX+1];
char szLocalFile[PATH_MAX+1];

@@ -75,7 +76,8 @@ pOpenFontTableFile(void)
}

/* Try the global version of the fontnames file */
- szGlobalFile = GLOBAL_ANTIWORD_DIR FILE_SEPARATOR FONTNAMES_FILE;
+ snprintf(szGlobalFile, sizeof(szGlobalFile),
+ "%s" FILE_SEPARATOR FONTNAMES_FILE, szGetAntiwordRuntimeDir());
DBG_MSG(szGlobalFile);

pFile = fopen(szGlobalFile, "r");
diff --git a/misc.c b/misc.c
index 63d1c91..893faa9 100644
--- a/misc.c
+++ b/misc.c
@@ -71,6 +71,50 @@ szGetAntiwordDirectory(void)
#endif /* !__riscos */

/*
+ * szGetAntiwordRuntimePrefix
+ * (win32 only)
+ */
+const char *
+szGetAntiwordRuntimePrefix(void)
+{
+ static char prefix[PATH_MAX+1];
+ char *tail;
+ int ncut;
+
+ strncpy(prefix, __argv[0], sizeof(prefix));
+
+ /* do dirname() twice prefix/bin/antiword.exe -> prefix */
+ for (ncut=0, tail = prefix+strlen(prefix)-1; ncut < 2 && tail >= prefix; --tail) {
+ if (*tail == '/' || *tail == '\\') {
+ *tail = '\0';
+ ++ncut;
+ }
+ }
+
+ if (ncut != 2)
+ werr(1, "E: Cannot determine runtime prefix from \'%s\'", __argv[0]);
+
+ return prefix;
+}
+
+/*
+ * szGetAntiwordRuntimeDir
+ * (win32 only)
+ */
+const char *
+szGetAntiwordRuntimeDir(void)
+{
+ static char dir[PATH_MAX+1];
+ const char *prefix = szGetAntiwordRuntimePrefix();
+
+ strncpy(dir, prefix, sizeof(dir));
+ strncat(dir, FILE_SEPARATOR "share" FILE_SEPARATOR "antiword", sizeof(dir)-strlen(dir));
+
+ return dir;
+}
+
+
+/*
* Get the size of the specified file.
* Returns -1 if the file does not exist or is not a proper file.
*/
diff --git a/options.c b/options.c
index 8379fef..9bcc88a 100644
--- a/options.c
+++ b/options.c
@@ -238,11 +238,11 @@ pOpenCharacterMappingFile(const char *szLeafname)
/* Try the global version of the mapping file */
if (tFilenameLen <
sizeof(szMappingFile) -
- sizeof(GLOBAL_ANTIWORD_DIR) -
+ strlen(szGetAntiwordRuntimeDir()) -
sizeof(FILE_SEPARATOR)) {
sprintf(szMappingFile,
- GLOBAL_ANTIWORD_DIR FILE_SEPARATOR "%s%s",
- szLeafname, szSuffix);
+ "%s" FILE_SEPARATOR "%s%s",
+ szGetAntiwordRuntimeDir(), szLeafname, szSuffix);
DBG_MSG(szMappingFile);
pFile = fopen(szMappingFile, "r");
if (pFile != NULL) {
@@ -253,7 +253,7 @@ pOpenCharacterMappingFile(const char *szLeafname)
}
werr(0, "I can't open your mapping file (%s%s)\n"
"It is not in '%s" FILE_SEPARATOR ANTIWORD_DIR "' nor in '"
- GLOBAL_ANTIWORD_DIR "'.", szLeafname, szSuffix, szHome);
+ "%s" "'.", szLeafname, szSuffix, szHome, szGetAntiwordRuntimeDir());
return NULL;
#endif /* __riscos */
} /* end of pOpenCharacterMappingFile */
--
1.7.3.2.245.g03276

26 changes: 26 additions & 0 deletions src/antiword/release.sh
@@ -0,0 +1,26 @@
#!/bin/sh

cd "$(dirname "$0")"

REPO=git://repo.or.cz/antiword.git
DIR=antiword-git
HEAD=0680e7ee62e430e0905085e5b4cfb01d31db5936 # antiword 0.37

die () {
echo "$*" >&2
exit 1
}

test -d $DIR ||
( git clone -n $REPO $DIR && cd $DIR && git checkout $HEAD ) ||
die "Could not clone $REPO"

(cd $DIR && git am ../patches/*) ||
die "Could not apply patches"

(cd $DIR &&
make -f Makefile.Linux antiword.exe &&
index=$(/share/msysGit/pre-install.sh) &&
make -f Makefile.Linux global_install &&
/share/msysGit/post-install.sh $index "Install antiword (Git $HEAD)"
) || die "Could not install antiword"

0 comments on commit dff9bb0

Please sign in to comment.