Egbert Eich wrote:
Juliusz, Kean, please check below and tell me if it does what you expect.
Mostly, except for the -x stuff. Can you and Juliusz apply and try the attached patch? This doesnt include the X11.tmpl cleanup portion of my original patch, but ti does clean up some missing prototypes and unused variables in mkfontscale, as well as changing the old -x to -a, and making -x be the exclusion suffix.

Kean
Index: xc/programs/mkfontscale/hash.c
===================================================================
RCS file: /cvs/xc/programs/mkfontscale/hash.c,v
retrieving revision 1.1
diff -u -r1.1 hash.c
--- xc/programs/mkfontscale/hash.c      2003/06/20 15:49:52     1.1
+++ xc/programs/mkfontscale/hash.c      2003/07/03 03:16:40
@@ -179,18 +179,18 @@
 }
 
 static int
-key_first_cmp(void *v1, void *v2)
+key_first_cmp(const void *v1, const void *v2)
 {
-    HashBucketPtr *b1 = v1, *b2 = v2;
+    const HashBucketPtr *b1 = v1, *b2 = v2;
     int c1 = strcmp_lwr((*b1)->key, (*b2)->key);
     if(c1 != 0) return c1;
     return strcmp((*b1)->value, (*b2)->value);
 }
 
 static int
-value_first_cmp(void *v1, void *v2)
+value_first_cmp(const void *v1, const void *v2)
 {
-    HashBucketPtr *b1 = v1, *b2 = v2;
+    const HashBucketPtr *b1 = v1, *b2 = v2;
     int c1 = strcmp((*b1)->value, (*b2)->value);
     if(c1 != 0) return c1;
     return strcmp_lwr((*b1)->key, (*b2)->key);
Index: xc/programs/mkfontscale/hash.h
===================================================================
RCS file: /cvs/xc/programs/mkfontscale/hash.h,v
retrieving revision 1.1
diff -u -r1.1 hash.h
--- xc/programs/mkfontscale/hash.h      2003/06/20 15:49:52     1.1
+++ xc/programs/mkfontscale/hash.h      2003/07/03 03:16:40
@@ -35,3 +35,4 @@
 int putHash(HashTablePtr table, char *key, char *value, int prio);
 int hashElements(HashTablePtr table);
 HashBucketPtr *hashArray(HashTablePtr table, int value_first);
+void destroyHashArray(HashBucketPtr *array);
Index: xc/programs/mkfontscale/ident.c
===================================================================
RCS file: /cvs/xc/programs/mkfontscale/ident.c,v
retrieving revision 1.1
diff -u -r1.1 ident.c
--- xc/programs/mkfontscale/ident.c     2003/06/20 15:49:52     1.1
+++ xc/programs/mkfontscale/ident.c     2003/07/03 03:16:41
@@ -121,9 +121,8 @@
 {
     int prop_position;
     PropPtr props = NULL;
-    int version, format, count, prop_size, nprops, i, string_size, rc;
+    int format, count, prop_size, nprops, i, string_size, rc;
     char *strings = NULL, *s;
-    char buf[4];
 
     count = getLSB32(f);
     if(count <= 0)
Index: xc/programs/mkfontscale/list.c
===================================================================
RCS file: /cvs/xc/programs/mkfontscale/list.c,v
retrieving revision 1.4
diff -u -r1.4 list.c
--- xc/programs/mkfontscale/list.c      2003/06/20 15:49:52     1.4
+++ xc/programs/mkfontscale/list.c      2003/07/03 03:16:41
@@ -57,8 +57,6 @@
 ListPtr
 listAdjoin(char *car, ListPtr cdr)
 {
-    ListPtr lcar;
-
     if(listMember(car, cdr)) {
         free(car);
         return cdr;
Index: xc/programs/mkfontscale/mkfontscale.c
===================================================================
RCS file: /cvs/xc/programs/mkfontscale/mkfontscale.c,v
retrieving revision 1.9
diff -u -r1.9 mkfontscale.c
--- xc/programs/mkfontscale/mkfontscale.c       2003/07/01 13:05:34     1.9
+++ xc/programs/mkfontscale/mkfontscale.c       2003/07/03 03:16:44
@@ -74,32 +74,36 @@
 
 #define countof(_a) (sizeof(_a)/sizeof((_a)[0]))
 
-int doDirectory(char*, int, ListPtr);
+static int doDirectory(char*, int, ListPtr);
 static int checkEncoding(FT_Face face, char *encoding_name);
 static int checkExtraEncoding(FT_Face face, char *encoding_name, int found);
 static int find_cmap(int type, int pid, int eid, FT_Face face);
 static char* notice_foundry(char *notice);
 static char* vendor_foundry(signed char *vendor);
-int readFontScale(HashTablePtr entries, char *dirname);
+static int readFontScale(HashTablePtr entries, char *dirname);
 ListPtr makeXLFD(char *filename, FT_Face face, int);
+static int readEncodings(ListPtr encodings, char *dirname);
 
 static FT_Library ft_library;
 static float bigEncodingFuzz = 0.02;
 
+static int relative;
 static int doScalable;
 static int doBitmaps;
-static int doEncodings;
+static int onlyEncodings;
+static int onlyEncodings;
 static ListPtr encodingsToDo;
 static int reencodeLegacy;
-char *encodingPrefix = NULL;
+static char *encodingPrefix;
+static char *exclusionSuffix;
 
 static void
 usage(void)
 {
     fprintf(stderr, 
-            "mkfontscale [ -b ] [ -s ] [ -o filename ] \n"
-            "            [ -x encoding ] [ -f fuzz ] [ -l ] "
-            "[ -e directory ] [ -p prefix ]\n"
+            "mkfontscale [ -b ] [ -s ] [ -o filename ] [-x suffix ]\n"
+            "            [ -a encoding ] [ -f fuzz ] [ -l ] "
+            "            [ -e directory ] [ -p prefix ] [ -n ] [ -r ] \n"
             "            [ directory ]...\n");
 }
 
@@ -108,15 +112,19 @@
 {
     int argn;
     FT_Error ftrc;
-    int rc;
+    int rc, ll = 0;
     char prefix[NPREFIX];
 
+    encodingPrefix = NULL;
+    exclusionSuffix = NULL;
+
     if(getcwd(prefix, NPREFIX - 1) == NULL) {
         perror("Couldn't get cwd");
         exit(1);
     }
     if(prefix[strlen(prefix) - 1] != '/')
         strcat(prefix, "/");
+    encodingPrefix = dsprintf("%s", prefix);
 
     outfilename = NULL;
 
@@ -127,8 +135,9 @@
                                NULL, 0);
     doBitmaps = 0;
     doScalable = 1;
+    onlyEncodings = 0;
+    relative = 0;
     reencodeLegacy = 1;
-    doEncodings = 0;
     encodingsToDo = NULL;
 
     argn = 1;
@@ -138,7 +147,14 @@
         if(argv[argn][1] == '-') {
             argn++;
             break;
-        } else if(strcmp(argv[argn], "-x") == 0) {
+        } else if (strcmp(argv[argn], "-x") == 0) {
+            if(argn >= argc - 1) {
+                usage();
+                exit(1);
+            }
+            exclusionSuffix = argv[argn + 1];
+            argn += 2;
+        } else if(strcmp(argv[argn], "-a") == 0) {
             if(argn >= argc - 1) {
                 usage();
                 exit(1);
@@ -154,14 +170,14 @@
                 usage();
                 exit(1);
             }
-            strcpy(prefix, argv[argn + 1]);
+            free(encodingPrefix);
+            encodingPrefix = dsprintf("%s", argv[argn + 1]);
             argn += 2;
         } else if(strcmp(argv[argn], "-e") == 0) {
             if(argn >= argc - 1) {
                 usage();
                 exit(1);
             }
-            doEncodings = 1;
             rc = readEncodings(encodingsToDo, argv[argn + 1]);
             if(rc < 0)
                 exit(1);
@@ -172,6 +188,12 @@
         } else if(strcmp(argv[argn], "-s") == 0) {
             doScalable = 0;
             argn++;
+        } else if(strcmp(argv[argn], "-n") == 0) {
+            onlyEncodings = 1;
+            argn++;
+        } else if(strcmp(argv[argn], "-r") == 0) {
+            relative = 1;
+            argn++;
         } else if(strcmp(argv[argn], "-l") == 0) {
             reencodeLegacy = !reencodeLegacy;
             argn++;
@@ -199,8 +221,6 @@
         }
     }
 
-    encodingPrefix = dsprintf("%s", prefix);
-
     if(outfilename == NULL) {
         if(doBitmaps)
             outfilename = "fonts.dir";
@@ -213,13 +233,14 @@
         fprintf(stderr, "Could not initialise FreeType library: %d\n", ftrc);
         exit(1);
     }
-        
 
+    ll = listLength(encodingsToDo);
+
     if (argn == argc)
-        doDirectory(".", doEncodings, encodingsToDo);
+        doDirectory(".", ll, encodingsToDo);
     else
         while(argn < argc) {
-            doDirectory(argv[argn], doEncodings, encodingsToDo);
+            doDirectory(argv[argn], ll, encodingsToDo);
             argn++;
         }
     return 0;
@@ -629,7 +650,7 @@
     return xlfd;
 }
 
-int
+static int
 readFontScale(HashTablePtr entries, char *dirname)
 {
     int n = strlen(dirname);
@@ -695,11 +716,11 @@
     return 0;
 }
 
-int
-doDirectory(char *dirname_given, int doEncodings, ListPtr encodingsToDo)
+static int
+doDirectory(char *dirname_given, int numEncodings, ListPtr encodingsToDo)
 {
-    char *dirname, *fontscale_name, *filename;
-    FILE *fontscale;
+    char *dirname, *fontscale_name, *filename, *encdir;
+    FILE *fontscale, *encfile;
     DIR *dirp;
     struct dirent *entry;
     FT_Error ftrc;
@@ -708,7 +729,10 @@
     HashTablePtr entries;
     HashBucketPtr *array;
     int i, n, found, rc;
-    int isBitmap;
+    int isBitmap=0,xl=0;
+
+    if (exclusionSuffix)
+        xl = strlen (exclusionSuffix);
 
     i = strlen(dirname_given);
     if(i == 0)
@@ -723,27 +747,9 @@
         exit(1);
     }
 
-    if(doEncodings) {
-        char *e = dsprintf("%s%s", dirname, "encodings.dir");
-        FILE *out;
-        ListPtr l;
-
-        if(e == NULL) {
-            perror("encodings");
-            exit(1);
-        }
-        unlink(e);
-        out = fopen(e, "w");
-        if(out == NULL) {
-            perror("open(encodings.dir)");
-            exit(1);
-        }
-        fprintf(out, "%d\n", listLength(encodingsToDo));
-        for(l = encodingsToDo; l; l = l->next) {
-            fprintf(out, "%s\n", l->value);
-        }
-    }
-
+    if (onlyEncodings) 
+       goto encodings;
+    
     entries = makeHashTable();
     if(doBitmaps && !doScalable) {
         readFontScale(entries, dirname);
@@ -784,6 +790,13 @@
         int have_face = 0;
         char *xlfd_name = NULL;
         xlfd = NULL;
+
+       if (xl) {
+           int dl = strlen (entry->d_name);
+           if (strcmp (entry->d_name + dl - xl, exclusionSuffix) == 0)
+               continue;
+       }
+
         filename = dsprintf("%s%s", dirname, entry->d_name);
 
         if(doBitmaps)
@@ -915,6 +928,29 @@
         fclose(fontscale);
         free(fontscale_name);
     }
+
+ encodings:
+    encdir = dsprintf("%s%s", dirname, "encodings.dir");
+
+    if(encdir == NULL) {
+       perror("encodings");
+       exit(1);
+    }
+    unlink(encdir);
+
+    if (numEncodings) {
+       encfile = fopen(encdir, "w");
+       if(encfile == NULL) {
+           perror("open(encodings.dir)");
+           exit(1);
+       }
+        fprintf(encfile, "%d\n", numEncodings);
+        for(lp = encodingsToDo; lp; lp = lp->next) {
+            fprintf(encfile, "%s\n", lp->value);
+        }
+       fclose (encfile);
+    }
+
     free(dirname);
     return 1;
 }
@@ -1172,11 +1208,10 @@
     return NULL;
 }
 
-int
+static int
 readEncodings(ListPtr encodings, char *dirname)
 {
     char *fullname;
-    int slash;
     DIR *dirp;
     struct dirent *file;
     char **names, **name;
@@ -1203,7 +1238,7 @@
             continue;
 
         for(name = names; *name; name++) {
-            if(fullname[0] != '/') {
+            if(fullname[0] != '/' && !relative) {
                 char *n;
                 n = dsprintf("%s%s", encodingPrefix, fullname);
                 if(n == NULL) {
@@ -1211,10 +1246,12 @@
                     closedir(dirp);
                     return -1;
                 }
-                free(fullname);
-                fullname = n;
+                encodingsToDo = listConsF(encodingsToDo, "%s %s", *name, n);
+                free(n);
+            } else {
+                encodingsToDo = 
+                    listConsF(encodingsToDo, "%s %s", *name, fullname);
             }
-            encodingsToDo = listConsF(encodingsToDo, "%s %s", *name ,fullname);
             if(encodingsToDo == NULL) {
                 fprintf(stderr, "Couldn't allocate encodings\n");
                 closedir(dirp);
Index: xc/programs/mkfontscale/mkfontscale.man
===================================================================
RCS file: /cvs/xc/programs/mkfontscale/mkfontscale.man,v
retrieving revision 1.4
diff -u -r1.4 mkfontscale.man
--- xc/programs/mkfontscale/mkfontscale.man     2003/06/20 15:49:52     1.4
+++ xc/programs/mkfontscale/mkfontscale.man     2003/07/03 03:16:44
@@ -14,6 +14,9 @@
 .I filename
 ] [
 .B \-x
+.I suffix
+] [
+.B \-a
 .I encoding
 ] \|.\|.\|. [
 .B \-f 
@@ -27,6 +30,12 @@
 .B \-p
 .I prefix
 ] [
+.B \-r
+.I prefix
+] [
+.B \-n
+.I prefix
+] [
 .B \-\-
 ] [
 .I directory
@@ -70,8 +79,12 @@
 the special value 
 .BR \- ,
 output is written to standard output.
+.TP
+.BI \-x " suffix"
+exclude all files with the specified
+.I suffix
 .TP
-.BI \-x " encoding"
+.BI \-a " encoding"
 add
 .I encoding
 to the list of encodings searched for.
@@ -98,6 +111,17 @@
 when they are written to the "encodings.dir" file.  The prefix is
 prepended litterally: if a `/' is required between the prefix and the path
 names, it must be supplied explicitly as part of the prefix.
+.TP
+.B \-r
+Keep non-absolute encoding directories in their relative form when
+writing the "encodings.dir" file.  The default is to convert relative
+encoding directories to absolute directories by prepending the current
+directory.  The positioning of this options is significant, as this
+option only applies to subsequent
+.TP
+.B \-n
+do not scan for fonts, do not write font directory files.  This option
+is useful when generating encoding directories only.
 .TP
 .B \-\- 
 end of options.

Reply via email to