diff -Naur ttmkfdir-3.0.9.orig/Makefile ttmkfdir-3.0.9/Makefile
--- ttmkfdir-3.0.9.orig/Makefile	2005-06-03 13:05:36.000000000 +0000
+++ ttmkfdir-3.0.9/Makefile	2005-06-03 13:06:27.000000000 +0000
@@ -28,7 +28,7 @@
 DEBUG=-ggdb
 CXX=g++
 CXXFLAGS=-Wall -pedantic $(FREETYPE_INCL) $(DEBUG) $(OPTFLAGS)
-LDFLAGS=$(FREETYPE_LIB) $(DEBUG)
+LDFLAGS=$(FREETYPE_LIB) $(DEBUG) -lz
 
 DESTDIR=
 PREFIX=/usr
diff -Naur ttmkfdir-3.0.9.orig/builtin.cpp ttmkfdir-3.0.9/builtin.cpp
--- ttmkfdir-3.0.9.orig/builtin.cpp	2005-06-03 13:05:36.000000000 +0000
+++ ttmkfdir-3.0.9/builtin.cpp	2005-06-03 13:06:46.000000000 +0000
@@ -600,7 +600,7 @@
 	0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
     };
 
-};
+}
 
 Encoding::BuiltinEncoding_t Encoding::builtin_encodings[] = {
     {256,191,32,{TT_PLATFORM_MICROSOFT,TT_MS_ID_UNICODE_CS,iso8859_1},{"iso8859-1",}},
diff -Naur ttmkfdir-3.0.9.orig/directory.cpp ttmkfdir-3.0.9/directory.cpp
--- ttmkfdir-3.0.9.orig/directory.cpp	2005-06-03 13:05:36.000000000 +0000
+++ ttmkfdir-3.0.9/directory.cpp	2005-06-03 13:07:08.000000000 +0000
@@ -1,7 +1,9 @@
 #include <cctype>
 #include <dirent.h>
+#include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include "directory.h"
 
@@ -37,19 +39,24 @@
 bool
 ttfdirectory::select (const char *name) const
 {
-    int len;
+    int fd;
+    unsigned int n;
     struct stat buf;
+    char sigdata[8];
+    char TTsig[] = "\000\001\000\000\000", OTsig[] = "OTTO";
 
     /* must be a regular file */
     if (::stat (name, &buf) || !(S_ISREG (buf.st_mode))) {
 	return false;
     }
-    
-    /* we make the decision by the extension of the file name */
-    return (((len = strlen (name)) > 4) &&
-	    (name[len - 4] == '.') &&
-	    (std::toupper(name[len - 3]) == 'T') &&
-	    (std::toupper(name[len - 2]) == 'T') &&
-	    ((std::toupper(name[len - 1]) == 'F') ||
-	     (std::toupper(name[len - 1]) == 'C')));
+
+    fd = ::open(name, O_RDONLY);
+    if (fd < 0) return false;
+    n = read(fd, sigdata, sizeof(sigdata));
+    close(fd);
+    if (n < sizeof(sigdata))
+	return false;
+
+    return (!memcmp(sigdata, TTsig, 5)
+	    || !memcmp(sigdata, OTsig, 4));
 }
diff -Naur ttmkfdir-3.0.9.orig/encoding.cpp ttmkfdir-3.0.9/encoding.cpp
--- ttmkfdir-3.0.9.orig/encoding.cpp	2005-06-03 13:05:36.000000000 +0000
+++ ttmkfdir-3.0.9/encoding.cpp	2005-06-03 13:07:08.000000000 +0000
@@ -2,7 +2,8 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
-#include "freetype/freetype.h"
+#include <unistd.h>
+#include <zlib.h>
 
 #include "ttmkfdir.h"
 #include "encoding.h"
@@ -32,9 +33,16 @@
     NextFile (FILE *f, char *name)
     {
 	char file_name [1024];
-	char command[1024];
+	char line_buf [1024];
+	char tmp_file_name[] = "/tmp/ttmkfdir_XXXXXX";
+	char inbuf[300000];
+	FILE *od;
+	gzFile fd;
+	int rvalue, tmpfd;
 
-	if (fscanf (f, "%*s %[^\n]\n", file_name) == 1) {
+	if (fgets (line_buf, sizeof(line_buf), f) != NULL) {
+
+	    sscanf (line_buf, "%*s %[^\n]\n", file_name);
 
 	    if (file_name[0] == '/') {
 		name[0] = 0;
@@ -44,9 +52,25 @@
 	
 	    strcat (name, file_name);
 
-	    sprintf (command, "exec %s < %s", (toupper(name[strlen (name) - 1]) == 'Z')
-		     ? "gzip -d" : "cat", name);
-	    return popen (command, "r");
+	    bzero(inbuf, sizeof(inbuf));
+
+	    fd = gzopen (name,"rb");
+	    rvalue = gzread (fd, inbuf, sizeof(inbuf));
+
+	    tmpfd = mkstemp (tmp_file_name);
+	    if (tmpfd == -1) {
+		return 0;
+	    }
+
+	    od = fdopen (tmpfd,"w");
+	    fputs (inbuf, od);
+	    fflush (od);
+	    fclose (od);
+
+	    od = fopen (tmp_file_name,"r");
+	    unlink (tmp_file_name);
+	    return od;
+
 	}
 
 	return 0;
@@ -75,7 +99,7 @@
 	yyrestart (input);
 	yylex (name, *this);
 
-	pclose (input);
+	fclose (input);
     }
 
     fclose (f);
@@ -97,7 +121,7 @@
 
     NumericMapping *m = new NumericMapping (size, b->mapdata.platform, b->mapdata.encoding);
 
-    for (int i = 0; i < size; i++)
+    for (unsigned int i = 0; i < size; i++)
 	(*m)[i] = b->mapdata.mappingtable[i];
 
     AddMapping (m);
diff -Naur ttmkfdir-3.0.9.orig/encoding.h ttmkfdir-3.0.9/encoding.h
--- ttmkfdir-3.0.9.orig/encoding.h	2005-06-03 13:05:36.000000000 +0000
+++ ttmkfdir-3.0.9/encoding.h	2005-06-03 13:06:36.000000000 +0000
@@ -6,7 +6,8 @@
 #include <map>
 #include <string>
 
-#include "freetype/freetype.h"
+#include <ft2build.h>
+#include FT_FREETYPE_H
 
 #include "util.h"
 
diff -Naur ttmkfdir-3.0.9.orig/encoding.l ttmkfdir-3.0.9/encoding.l
--- ttmkfdir-3.0.9.orig/encoding.l	2005-06-03 13:05:36.000000000 +0000
+++ ttmkfdir-3.0.9/encoding.l	2005-06-03 13:07:08.000000000 +0000
@@ -8,7 +8,7 @@
 #include "ttmkfdir.h"    
 #include "encoding.h"    
 
-#define DEFAULT_SIZE 0x100 /* 8 bit encoding */
+#define DEFAULT_SIZE 0xFFFF;
 #define YY_DECL int yylex (char *current_file, Encodings_t &dest)
 
 static unsigned int line_number = 1;
@@ -43,6 +43,7 @@
 STARTENCODING{WHITESPACES}{STRING} {
     cur_enc = new Encoding;
     cur_enc->names.push_back (strip_first (yytext));
+    cur_enc->size = DEFAULT_SIZE;
     BEGIN(INSIDE_ENC_BLOCK);
 }
 
@@ -97,6 +98,7 @@
 <INSIDE_MAP_BLOCK>UNDEFINE{WHITESPACES}{NUMBER}({WHITESPACES}{NUMBER})? {
     char *startptr = strip_first (yytext);
     char *endptr;
+    long msize = cur_map->size();
 
     int i1 = std::strtol (startptr, &endptr, 0);
     startptr = endptr;
@@ -106,15 +108,16 @@
     if (startptr == endptr) {
 	i2 = i1;
     }
-    
+
     /* now mark all the unassigned codes */
-    for (long i = i1; i <= i2; i++) {
+    for (long i = i1; i <= i2 && i < msize; i++) {
 	(*cur_map)[i] = -1;
     }
 }
 
 <INSIDE_MAP_BLOCK>{NUMBER}({WHITESPACES}{NUMBER}){0,2} {
-    int numbers[3], i = 0, start_range, end_range, target, res;
+    int numbers[3], target, res;
+    unsigned int i = 0, start_range, end_range;
     char *startptr;
     char *endptr = yytext;
 
diff -Naur ttmkfdir-3.0.9.orig/ttf.cpp ttmkfdir-3.0.9/ttf.cpp
--- ttmkfdir-3.0.9.orig/ttf.cpp	2005-06-03 13:05:36.000000000 +0000
+++ ttmkfdir-3.0.9/ttf.cpp	2005-06-03 13:07:08.000000000 +0000
@@ -51,20 +51,26 @@
 bool
 Face::MappingPresent (int cmapidx, NumericMapping *m, int enc_size, int start_code, bool enc_comp)
 {
-    int idx, missing = 0;
+    int idx; 
+    unsigned int missing = 0, bail_at, msize;
+
     FT_Set_Charmap (face, face->charmaps[cmapidx]);
 
-    for (unsigned int i = start_code; i < m->size (); i++) {
+    msize = m->size();
+    if (enc_size <= 256) {
+	bail_at = int (cmdline::instance()->option ("max-missing"));
+    } else {
+	bail_at = ((int (cmdline::instance()->option ("max-missing-percentage")) & enc_comp)*enc_size)/100;
+    }
+
+    for (unsigned int i = start_code; i < msize && missing < bail_at; i++) {
 	if ((*m)[i] < 0) 
 	    continue;
 	if ((idx = FT_Get_Char_Index (face, (*m)[i])) == 0)
 	    missing++;
     }
-    if (enc_size <= 256) {
-        return (missing <= int (cmdline::instance()->option ("max-missing")));
-    } else {
-        return ((100 * missing/enc_size) <= int (cmdline::instance()->option ("max-missing-percentage")) & enc_comp);
-    }
+
+    return missing < bail_at;
 }
 
 Face::Face (const std::string &filename)
@@ -239,7 +245,7 @@
 	for (i = 0; i < n; i++) {
 	    if ((fterror = FT_Get_Sfnt_Name (face, i, &NamePtr)) != FT_Err_Ok) {
                     std::cout << "Warning: Can't SFNT name : " << FileName << "(" << fterror << ")" << std::endl;
-	            return;
+	            return NULL;
             };
             platform = NamePtr.platform_id;
             encoding = NamePtr.encoding_id;
diff -Naur ttmkfdir-3.0.9.orig/ttf.h ttmkfdir-3.0.9/ttf.h
--- ttmkfdir-3.0.9.orig/ttf.h	2005-06-03 13:05:36.000000000 +0000
+++ ttmkfdir-3.0.9/ttf.h	2005-06-03 13:06:46.000000000 +0000
@@ -3,12 +3,13 @@
 #define TTF_H__
 
 #include <string>
-#include "freetype/freetype.h"
-#include "freetype/tttables.h"
-#include "freetype/ftsnames.h"
-#include "freetype/ttnameid.h"
-#include "freetype/fterrors.h"
-#include "freetype/ftmodule.h"
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_SFNT_NAMES_H
+#include FT_TRUETYPE_TABLES_H
+#include FT_TRUETYPE_IDS_H
+#include FT_ERRORS_H
+#include FT_MODULE_H
 
 #include "util.h"
 #include "encoding.h"
@@ -49,7 +50,7 @@
 	TT_Postscript	    *post;
 	std::string	    FileName;
     };
-};
+}
 
 #endif /* TTF_H__ */
 
diff -Naur ttmkfdir-3.0.9.orig/util.h ttmkfdir-3.0.9/util.h
--- ttmkfdir-3.0.9.orig/util.h	2005-06-03 13:05:36.000000000 +0000
+++ ttmkfdir-3.0.9/util.h	2005-06-03 13:06:46.000000000 +0000
@@ -17,6 +17,6 @@
 	Singleton (void) {};
 	~Singleton (void) {};
     };
-}; 
+}
 
 #endif // TTMKFDIRUTIL_H__
