Back to index

tetex-bin  3.0
Classes | Defines | Typedefs | Functions | Variables
gsftopk.c File Reference
#include "version.h"
#include "config.h"
#include <stdio.h>
#include <ctype.h>
#include <memory.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <setjmp.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <varargs.h>

Go to the source code of this file.

Classes

struct  option
struct  p_list
struct  spacenode

Defines

#define strchr   index
#define strrchr   rindex
#define memcpy(d, s, n)   bcopy((s), (d), (n))
#define memmove(d, s, n)   bcopy((s), (d), (n))
#define memcmp(s1, s2, n)   bcmp((s1), (s2), (n))
#define dirent   direct
#define NAMLEN(dirent)   (dirent)->d_namlen
#define WIFSTOPPED(stat_val)   (((stat_val) & 0377) == 0177)
#define WIFSIGNALED(stat_val)   (((stat_val) & 0377) != 0)
#define WTERMSIG(stat_val)   ((stat_val) & 0177)
#define WEXITSTATUS(stat_val)   ((unsigned)(stat_val) >> 8)
#define SIGCHLD   SIGCLD
#define FOPEN_R_MODE   "r"
#define FOPEN_RBIN_MODE   "r"
#define FOPEN_WBIN_MODE   "w"
#define AA(args)   ()
#define P1H(p1)   ()
#define P1C(t1, n1)   (n1) t1 n1;
#define P2C(t1, n1, t2, n2)   (n1,n2) t1 n1; t2 n2;
#define P3C(t1, n1, t2, n2, t3, n3)   (n1,n2,n3) t1 n1; t2 n2; t3 n3;
#define P4C(t1, n1, t2, n2, t3, n3, t4, n4)
#define P5C(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5)
#define P6C(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6)
#define P7C(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6, t7, n7)
#define const   /* nothing */
#define NUMBER(x)   (sizeof (x) / sizeof *(x))
#define GS_PATH   "gs"
#define NORETURN   /* nothing */
#define NeedVarargsPrototypes   0
#define True   1
#define False   0
#define NeedWidePrototypes   0
#define MAXPATHLEN   256
#define PK_PRE   (char) 247
#define PK_ID   (char) 89
#define PK_SPC   (char) 240
#define PK_POST   (char) 245
#define PK_NOP   (char) 246
#define OPT_DBG   0x101
#define BUFSIZE   512
#define lh   tfm_lengths[1]
#define bc   tfm_lengths[2]
#define ec   tfm_lengths[3]
#define nw   tfm_lengths[4]
#define gs_is_done   (gs_pid == 0)
#define ISSET(a, b)   FD_ISSET(a, b)
#define data_getc()   (data_out < data_end ? *data_out++ : data_fgetc())
#define HUNKSIZE   (MAXPATHLEN + 2)

Typedefs

typedef char Boolean
typedef Boolean wide_bool
typedef unsigned char byte
typedef int gsf_wait_t

Functions

char * strchr ()
char * strrchr ()
double atof ()
char * getenv ()
NORETURN void exit_toto_too P1H (void)
NORETURN void oops (va_alist)
NORETURN void opt_oops (va_alist)
static void *xmalloc P1C (unsigned, size)
static void *xrealloc P2C (char *, oldp, unsigned, size)
char *get_one_arg P1C (const char *, src)
static RETSIGTYPE handle_sigchild P1C (int, signo)
static void data_ungetc P1C (byte, c)
static int data_read P2C (byte *, buf, int, n)
static const char *find_dbl_slash P2C (const char *, sp_bgn, const char *, sp_end)
static void main_search_proc P7C (char *, matpos, const char *, sp_pos, const char *, sp_slash, const char *, sp_end, wide_bool, skip_subdirs, struct spacenode *, space, char *, spacenext)
static FILE *search P3C (const char *, path, const char *, path_var, const char *, name)
Boolean fgets_long P1C (FILE *, f)
void addtodls P1C (const char *, s)
void expect P1C (const char *, waitingfor)
static void tallyup P1C (int, n)
static void putshort P1C (short, w)
static void putmed P1C (long, w)
static void putglyph P1C (int, cc)
static void putspecl P2C (const char *, str1, const char *, str2)
int main P2C (int, argc, char **, argv)

Variables

static char copyright [] = "@(#) Copyright (c) 1993-1998 Paul Vojta.\n"
int errno
char progname [] = "gsftopk "
char version [] = VERSION
Boolean test = False
char * fontname
int fontlen
char * mapline = NULL
const char * mapfile = NULL
const char * gspath = GS_PATH
Boolean dosnames = False
Boolean quiet = False
static struct option []
FILEpk_file = NULL
char * xfilename
int col = 0
const char * specinfo = ""
pid_t gs_pid = 0
const char * config_file_header_path = HEADERPATH
struct p_listp_head = &psfonts_map
struct p_list ** p_tail = &psfonts_map.next
Boolean data_eof = False
int data_fd
byte buffer [BUFSIZE]
bytedata_out = buffer
bytedata_end = buffer
int tfm_lengths [12]
long checksum
long design
byte width_index [256]
long tfm_widths [256]
bytebitmap
int width
int skip
int height
int hoff
int voff
int bytes_wide
unsigned int bm_size
bytebitmap_end
int pk_len
static Boolean got_sigchld = False
static char searchpath [MAXPATHLEN+1]
struct spacenode firstnode
static jmp_buf found_env
static FILEsearchfile
static const char * searchname
static int searchnamelen
char * long_line = NULL
int long_line_len = 82
char * dlstring = NULL
unsigned int dls_len = 0
unsigned int dls_max = 0
char line [82]
static byte masks [] = {0, 1, 3, 7, 017, 037, 077, 0177, 0377}
byte flag
int pk_dyn_f
int pk_dyn_g
int base
int deltas [13]
static Boolean odd = False
static byte part

Class Documentation

struct option

Definition at line 420 of file gsftopk.c.

Class Members
void * addr
int * flag
int has_arg
Boolean has_arg
const char * longname
char * name
const char * name
short shortname
int val
int value
struct p_list

Definition at line 457 of file gsftopk.c.

Collaboration diagram for p_list:
Class Members
struct p_list * next
const char * value
struct spacenode

Definition at line 1141 of file gsftopk.c.

Collaboration diagram for spacenode:
Class Members
struct spacenode * next
char sp
char * sp_end

Define Documentation

#define AA (   args)    ()

Definition at line 200 of file gsftopk.c.

#define bc   tfm_lengths[2]

Definition at line 501 of file gsftopk.c.

#define BUFSIZE   512

Definition at line 477 of file gsftopk.c.

#define const   /* nothing */

Definition at line 216 of file gsftopk.c.

#define data_getc ( )    (data_out < data_end ? *data_out++ : data_fgetc())

Definition at line 1060 of file gsftopk.c.

#define dirent   direct

Definition at line 92 of file gsftopk.c.

#define ec   tfm_lengths[3]

Definition at line 502 of file gsftopk.c.

#define False   0

Definition at line 371 of file gsftopk.c.

#define FOPEN_R_MODE   "r"

Definition at line 148 of file gsftopk.c.

#define FOPEN_RBIN_MODE   "r"

Definition at line 158 of file gsftopk.c.

#define FOPEN_WBIN_MODE   "w"

Definition at line 171 of file gsftopk.c.

#define gs_is_done   (gs_pid == 0)

Definition at line 763 of file gsftopk.c.

#define GS_PATH   "gs"

Definition at line 352 of file gsftopk.c.

#define HUNKSIZE   (MAXPATHLEN + 2)

Definition at line 1139 of file gsftopk.c.

#define ISSET (   a,
  b 
)    FD_ISSET(a, b)

Definition at line 973 of file gsftopk.c.

#define lh   tfm_lengths[1]

Definition at line 500 of file gsftopk.c.

#define MAXPATHLEN   256

Definition at line 388 of file gsftopk.c.

#define memcmp (   s1,
  s2,
  n 
)    bcmp((s1), (s2), (n))

Definition at line 66 of file gsftopk.c.

#define memcpy (   d,
  s,
  n 
)    bcopy((s), (d), (n))

Definition at line 64 of file gsftopk.c.

#define memmove (   d,
  s,
  n 
)    bcopy((s), (d), (n))

Definition at line 65 of file gsftopk.c.

#define NAMLEN (   dirent)    (dirent)->d_namlen

Definition at line 93 of file gsftopk.c.

#define NeedVarargsPrototypes   0

Definition at line 365 of file gsftopk.c.

#define NeedWidePrototypes   0

Definition at line 377 of file gsftopk.c.

#define NORETURN   /* nothing */

Definition at line 358 of file gsftopk.c.

#define NUMBER (   x)    (sizeof (x) / sizeof *(x))

Definition at line 338 of file gsftopk.c.

#define nw   tfm_lengths[4]

Definition at line 503 of file gsftopk.c.

#define OPT_DBG   0x101

Definition at line 409 of file gsftopk.c.

#define P1C (   t1,
  n1 
)    (n1) t1 n1;

Definition at line 204 of file gsftopk.c.

#define P1H (   p1)    ()

Definition at line 202 of file gsftopk.c.

#define P2C (   t1,
  n1,
  t2,
  n2 
)    (n1,n2) t1 n1; t2 n2;

Definition at line 205 of file gsftopk.c.

#define P3C (   t1,
  n1,
  t2,
  n2,
  t3,
  n3 
)    (n1,n2,n3) t1 n1; t2 n2; t3 n3;

Definition at line 206 of file gsftopk.c.

#define P4C (   t1,
  n1,
  t2,
  n2,
  t3,
  n3,
  t4,
  n4 
)
Value:
(n1,n2,n3,n4) \
  t1 n1; t2 n2; t3 n3; t4 n4;

Definition at line 207 of file gsftopk.c.

#define P5C (   t1,
  n1,
  t2,
  n2,
  t3,
  n3,
  t4,
  n4,
  t5,
  n5 
)
Value:
(n1,n2,n3,n4,n5) \
  t1 n1; t2 n2; t3 n3; t4 n4; t5 n5;

Definition at line 209 of file gsftopk.c.

#define P6C (   t1,
  n1,
  t2,
  n2,
  t3,
  n3,
  t4,
  n4,
  t5,
  n5,
  t6,
  n6 
)
Value:
(n1,n2,n3,n4,n5,n6) \
  t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; t6 n6;

Definition at line 211 of file gsftopk.c.

#define P7C (   t1,
  n1,
  t2,
  n2,
  t3,
  n3,
  t4,
  n4,
  t5,
  n5,
  t6,
  n6,
  t7,
  n7 
)
Value:
(n1,n2,n3,n4,n5,n6,n7) \
  t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; t6 n6; t7 n7;

Definition at line 213 of file gsftopk.c.

#define PK_ID   (char) 89

Definition at line 392 of file gsftopk.c.

#define PK_NOP   (char) 246

Definition at line 395 of file gsftopk.c.

#define PK_POST   (char) 245

Definition at line 394 of file gsftopk.c.

#define PK_PRE   (char) 247

Definition at line 391 of file gsftopk.c.

#define PK_SPC   (char) 240

Definition at line 393 of file gsftopk.c.

#define SIGCHLD   SIGCLD

Definition at line 143 of file gsftopk.c.

#define strchr   index

Definition at line 59 of file gsftopk.c.

#define strrchr   rindex

Definition at line 60 of file gsftopk.c.

#define True   1

Definition at line 370 of file gsftopk.c.

#define WEXITSTATUS (   stat_val)    ((unsigned)(stat_val) >> 8)

Definition at line 139 of file gsftopk.c.

#define WIFSIGNALED (   stat_val)    (((stat_val) & 0377) != 0)

Definition at line 131 of file gsftopk.c.

#define WIFSTOPPED (   stat_val)    (((stat_val) & 0377) == 0177)

Definition at line 127 of file gsftopk.c.

#define WTERMSIG (   stat_val)    ((stat_val) & 0177)

Definition at line 135 of file gsftopk.c.


Typedef Documentation

typedef char Boolean

Definition at line 369 of file gsftopk.c.

typedef unsigned char byte

Definition at line 479 of file gsftopk.c.

typedef int gsf_wait_t

Definition at line 765 of file gsftopk.c.

typedef Boolean wide_bool

Definition at line 384 of file gsftopk.c.


Function Documentation

double atof ( )
char* getenv ( )

Definition at line 596 of file gsftopk.c.

{
#if !NeedVarargsPrototypes
       const char *message;
#endif
       va_list       args;

#if NeedVarargsPrototypes
       va_start(args, message);
#else
       va_start(args);
       message = va_arg(args, const char *);
#endif
       if (col != 0) putchar('\n');
       vfprintf(stderr, message, args);
       va_end(args);
       putc('\n', stderr);
       exit_toto_too();
}

Here is the caller graph for this function:

Definition at line 628 of file gsftopk.c.

{
#if !NeedVarargsPrototypes
       const char *message;
#endif
       va_list       args;

#if NeedVarargsPrototypes
       va_start(args, message);
#else
       va_start(args);
       message = va_arg(args, const char *);
#endif
       fputs("gsftopk: ", stderr);
       vfprintf(stderr, message, args);
       va_end(args);
       fputs("\nTry `gsftopk --help' for more information.\n", stderr);
       exit(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void* xmalloc P1C ( unsigned  ,
size   
) [static]

Definition at line 658 of file gsftopk.c.

{
       void *mem = (void *) malloc(size);

       if (mem == NULL)
           oops("gsftopk: Cannot allocate %u bytes.\n", size);
       return mem;
}

Here is the call graph for this function:

char* get_one_arg P1C ( const char *  ,
src   
)

Definition at line 692 of file gsftopk.c.

{
       char          *dest;
       const char    *p;
       unsigned int  len;

       len = strlen(src);
       p = memchr(src, ' ', len);
       if (p != NULL) len = p - src;
       p = memchr(src, '\t', len);
       if (p != NULL) len = p - src;

       dest = xmalloc(len + 1);
       memcpy(dest, src, len);
       dest[len] = '\0';

       return dest;
}

Here is the call graph for this function:

static RETSIGTYPE handle_sigterm P1C ( int  ,
signo   
) [static]

Definition at line 749 of file gsftopk.c.

static void data_ungetc P1C ( byte  ,
c   
) [static]

Definition at line 1063 of file gsftopk.c.

{
       if (data_out <= buffer)
           oops("Too many calls to data_ungetc()");

       *--data_out = c;
}

Here is the call graph for this function:

Boolean fgets_long P1C ( FILE ,
f   
)

Definition at line 1311 of file gsftopk.c.

{
       int    len;

       if (fgets(long_line, long_line_len, f) == NULL)
           return False;

       len = 0;
       for (;;) {
           len += strlen(long_line + len);
           if (len > 0 && long_line[len - 1] == '\n') {
              long_line[--len] = '\0';
              break;
           }
           if (len < long_line_len - 1)
              break;
           long_line_len += 80;
           long_line = xrealloc(long_line, long_line_len);
           fgets(long_line + len, long_line_len - len, f);
       }

       return True;
}

Here is the call graph for this function:

void addtodls P1C ( const char *  ,
s   
)

Definition at line 1416 of file gsftopk.c.

{
       int    len    = strlen(s);

       if (dls_len + len >= dls_max) {
           unsigned int newsize = dls_max + 80;

           if (newsize <= dls_len + len) newsize = dls_len + len + 1;
           dlstring = xrealloc(dlstring, dls_max = newsize);
       }
       strcpy(dlstring + dls_len, s);
       dls_len += len;
}

Here is the call graph for this function:

void expect P1C ( const char *  ,
waitingfor   
)

Definition at line 1448 of file gsftopk.c.

{
       for (;;) {
#if !_AMIGA
           data_gets((byte *) line, sizeof(line));
#else
           if (fgets(line, sizeof(line), data_file) == NULL)
              oops("Premature end of file");
#endif
           if (memcmp(line, waitingfor, strlen(waitingfor)) == 0) return;
           fputs("gs: ", stdout);
           for (;;) {
              fputs(line, stdout);
              if (*line == '\0' || line[strlen(line) - 1] == '\n') break;
#if !_AMIGA
              data_gets((byte *) line, sizeof(line));
#else
              if (fgets(line, sizeof(line), data_file) == NULL)
                  oops("Premature end of file");
#endif
           }
       }
}

Here is the call graph for this function:

static void tallyup P1C ( int  ,
n   
) [static]

Definition at line 1517 of file gsftopk.c.

{
       int    m;

       if (n > 208) {
           ++base;
           n -= 192;
           for (m = 0x100; m != 0 && m < n; m <<= 4) base += 2;
           if (m != 0 && (m = (m - n) / 15) < 13) deltas[m] += 2;
       }
       else if (n > 13) ++deltas[(208 - n) / 15];
       else --deltas[n - 1];
}
static void putshort P1C ( short  ,
w   
) [static]

Definition at line 1911 of file gsftopk.c.

{
       putc(w >> 8, pk_file);
       putc(w, pk_file);
}
static void putlong P1C ( long  ,
w   
) [static]

Definition at line 1918 of file gsftopk.c.

{
       putc(w >> 16, pk_file);
       putc(w >> 8, pk_file);
       putc(w, pk_file);
}
static void putglyph P1C ( int  ,
cc   
) [static]

Definition at line 1935 of file gsftopk.c.

{
       static Boolean       have_first_line = False;
       static int    llx, lly, urx, ury;
       static float  char_width;
       static byte   *area1 = NULL;
       static unsigned int size1 = 0;
       static int    i;
       long   dm;
       long   tfm_wid;
       byte   *p;

       if (!quiet) {
           int wid;
           static const char *s = "";

           wid = (cc >= 100) + (cc >= 10) + 4;
           if (col + wid > 80) {
              s = "\n";
              col = 0;
           }
           printf("%s[%d", s, cc);
           fflush(stdout);
           col += wid;
           s = " ";
       }
       if (!have_first_line) {
           expect("#^");
           if (sscanf(line, "#^ %d %d %d %d %d %f\n", &i,
                  &llx, &lly, &urx, &ury, &char_width) != 6)
              oops("Cannot scanf first line");
       }
       if (i < cc) oops("Character %d received, %d expected", i, cc);
       if (i > cc) {
           fprintf(stderr, "Character %d is missing.\n", cc);
           have_first_line = True;
           return;
       }
       have_first_line = False;
       hoff = -llx + 2;
       voff = ury + 2 - 1;
       expect("P4\n");
       whitespace();
       width = getint();
       whitespace();
       height = getint();
       (void) data_getc();
       if (width != urx - llx + 4 || height != ury - lly + 4)
           oops("Dimensions do not match:  %d %d %d %d %d %d",
              llx, lly, urx, ury, width, height);
       bytes_wide = (width + 7) / 8;
       bm_size = bytes_wide * height;
       if (size1 < bm_size) {
           if (area1 != NULL) free(area1);
           area1 = xmalloc(bm_size);
           size1 = bm_size;
       }
       for (p = area1 + (height - 1) * bytes_wide; p >= area1; p -= bytes_wide)
           if (data_read(p, bytes_wide) != bytes_wide)
              oops("Cannot read bitmap of size %u", bm_size);
       bitmap = area1;
       bitmap_end = bitmap + bm_size;
       trim_bitmap();
       if (height == 0 || !pk_rll_cvt()) pk_bm_cvt();
       tfm_wid = tfm_widths[width_index[cc]];
       dm = (long) (char_width + 0.5) - (char_width < -0.5);
       if (pk_len + 8 < 4 * 256 && tfm_wid < (1<<24) &&
              dm >= 0 && dm < 256 && width < 256 && height < 256 &&
              hoff >= -128 && hoff < 128 && voff >= -128 && voff < 128) {
           putc(flag | ((pk_len + 8) >> 8), pk_file);
           putc(pk_len + 8, pk_file);
           putc(cc, pk_file);
           putmed(tfm_wid);
           putc(dm, pk_file);
           putc(width, pk_file);
           putc(height, pk_file);
           putc(hoff, pk_file);
           putc(voff, pk_file);
       } else
       if (pk_len + 13 < 3 * 65536L && tfm_wid < (1<<24) &&
              dm >= 0 && dm < 65536L && width < 65536L && height < 65536L &&
              hoff >= -65536L && hoff < 65536L &&
              voff >= -65536L && voff < 65536L) {
           putc(flag | 4 | ((pk_len + 13) >> 16), pk_file);
           putshort(pk_len + 13);
           putc(cc, pk_file);
           putmed(tfm_wid);
           putshort(dm);
           putshort(width);
           putshort(height);
           putshort(hoff);
           putshort(voff);
       }
       else {
           putc(flag | 7, pk_file);
           putlong(pk_len + 28);
           putlong(cc);
           putlong(tfm_wid);
           putlong((long) (char_width * 65536.0 + 0.5) - (char_width < -0.5));
           putlong(0);
           putlong(width);
           putlong(height);
           putlong(hoff);
           putlong(voff);
       }
       fwrite(bitmap, 1, pk_len, pk_file);
       if (!quiet) {
           putchar(']');
           fflush(stdout);
       }
}

Here is the call graph for this function:

NORETURN void exit_toto_too P1H ( void  ) [read]

Definition at line 533 of file gsftopk.c.

{
#if !WIN32
       if (gs_pid != 0)
           kill(gs_pid, SIGKILL);
#else
       if (hGsThread) {
         switch (WaitForSingleObject(hGsThread, 2000)) {
         case WAIT_OBJECT_0:
           CloseHandle(hGsThread);
           hGsThread = NULL;
           break;
         case WAIT_TIMEOUT:
           fprintf(stderr, "Timeout waiting for Gs thread.\n");
           break;
         case WAIT_FAILED:
           fprintf(stderr, "WaitForSingleObject failed on Gs thread (Error code %d).\n",
                  GetLastError());
           break;
         default:
           break;
         }

         if (hGsThread) {
           if (TerminateThread(hGsThread, 1) == 0) {
             fprintf(stderr, "... couldn't terminate gs thread\n");
           }
           CloseHandle(hGsThread);
           /* FIXME : is it right to call this ? */
           gs_dll_release();
         }      
       }

       if (hGsDataIn)
         CloseHandle(hGsDataIn);
       if (hGsDataOut)
         CloseHandle(hGsDataOut);

#endif
       if (pk_file != NULL) {
           fclose(pk_file);
           if (unlink(xfilename) != 0) perror("unlink");
       }

       _exit(1);
}

Here is the call graph for this function:

static void* xrealloc P2C ( char *  ,
oldp  ,
unsigned  ,
size   
) [static]

Definition at line 673 of file gsftopk.c.

{
       void   *mem;

       mem = oldp == NULL ? (void *) malloc(size)
           : (void *) realloc(oldp, size);
       if (mem == NULL)
           oops("gsftopk: Cannot reallocate %u bytes.\n", size);
       return mem;
}

Here is the call graph for this function:

static void data_gets P2C ( byte ,
buf  ,
int  ,
n   
) [static]

Definition at line 1072 of file gsftopk.c.

{
       byte   *buf1  = buf;
       byte   *buf_end = buf + n;
       int    n1;

       if (buf1 >= buf_end)
           return 0;

       while (!data_eof) {
           n1 = buf_end - buf1;
           if (n1 > data_end - data_out)
              n1 = data_end - data_out;
           memcpy(buf1, data_out, n1);
           buf1 += n1;
           data_out += n1;
           if (buf1 >= buf_end) break;
           data_fillbuf();
       }

       return buf1 - buf;
}
static const char* find_dbl_slash P2C ( const char *  ,
sp_bgn  ,
const char *  ,
sp_end   
) [static]

Definition at line 1156 of file gsftopk.c.

{
       const char    *p;

       for (;;) {
           p = memchr(sp_bgn, '/', sp_end - sp_bgn);
           if (p == NULL) return sp_end;
           if (p[1] == '/') return p;
           sp_bgn = p + 1;
       }
}

Here is the call graph for this function:

static void putspecl P2C ( const char *  ,
str1  ,
const char *  ,
str2   
) [static]

Definition at line 2048 of file gsftopk.c.

{
       int    len1   = strlen(str1);
       int    len2   = 0;

       if (str2 != NULL) len2 = strlen(str2);
       if (len1 + len2 > 255) return;
       putc(PK_SPC, pk_file);
       putc(len1 + len2, pk_file);
       fwrite(str1, 1, len1, pk_file);
       if (len2 != 0) fwrite(str2, 1, len2, pk_file);
}

Here is the call graph for this function:

int main P2C ( int  ,
argc  ,
char **  ,
argv   
)

Definition at line 2062 of file gsftopk.c.

{
       FILE          *config_file;
       FILE          *render_ps;
       FILE          *tfm_file;
       char          **argp;
       float         dpi;
       const char    *dvipsrc;
       char          *p;
       char          *PSname              = NULL;
       char          *specinf      = NULL;
       char          *specp        = NULL;       /* NULL pacifies lint */
       char          charlist[10*2 + 90*3 + 156*4 + 1];
       char          designstr[20];
       char          dpistr[20];
#if HAVE_SIGACTION
       struct sigaction sigact;
#endif
#if _AMIGA
       char          fngs[50];
       char          fngsf[50];
       char          tfm_path[256];
       BPTR          in, out;
#else
       char          *substarg;
#endif
#if WIN32
       DWORD idGsThread;
#else /* not WIN32 */
#if !_AMIGA
       int           std_out[2];
#endif
       int           std_in[2];
#endif /* not WIN32 */
       int           cc;
       int           ppp;
       int           i;

       argp = argv;
       while (++argp < argv + argc && (*argp)[0] == '-') {
           const struct option *opt_ptr;
           const struct option *opt;
           char *arg = *argp + 1;

           if (*arg == '\0') --arg;       /* this will flag an error later */
           if (*arg != '-') {             /* if short argument */
              opt = options;
              for (;;) {
                  if (*arg == opt->shortname)
                     break;
                  if (++opt >= options + NUMBER(options))
                     opt_oops("invalid option -- %c", *arg);
              }
              if (opt->has_arg) {
                  ++arg;
                  if (*arg == '\0') {
                     if (++argp >= argv + argc)
                         opt_oops("option requires an argument -- %c",
                           arg[-1]);
                     arg = *argp;
                  }
              }
              else {
                  if (arg[1] != '\0')
                     opt_oops("invalid number of bytes in option `%s'",
                       arg - 1);
              }
           }
           else {                  /* long argument */
              int    len;
              char   *arg1;

              ++arg;
              if (*arg == '\0') {  /* if -- */
                  ++argp;
                  break;
              }
              len = strlen(arg);
              arg1 = memchr(arg, '=', len);
              if (arg1 != NULL) {
                  len = arg1 - arg;
                  ++arg1;
              }
              opt = NULL;
              for (opt_ptr = options; opt_ptr < options + NUMBER(options);
                ++opt_ptr)
                  if (memcmp(arg, opt_ptr->longname, len) == 0) {
                     if (opt != NULL)
                         opt_oops("option `%s' is ambiguous.", arg - 2);
                     opt = opt_ptr;
                  }
              if (opt == NULL)
                  opt_oops("unrecognized option `%s'", arg - 2);
              if (opt->has_arg) {
                  if (arg1 == NULL) {
                     if (++argp >= argv + argc)
                         opt_oops("option `--%s' requires an argument.",
                           opt->longname);
                     arg1 = *argp;
                  }
              }
              else {
                  if (arg1 != NULL)
                     opt_oops("option `--%s' doesn't allow an argument.",
                       opt->longname);
              }
              arg = arg1;
           }         /* end long argument */

           if (opt->addr != NULL)
              if (opt->has_arg)
                  *((char **) opt->addr) = arg;
              else
                  *((Boolean *) opt->addr) = opt->value;

           switch (opt->shortname) {
#ifdef KPATHSEA
           case OPT_DBG:
              kpathsea_debug |= atoi(arg);
              break;
#endif
           case 'h':
#ifndef KPATHSEA
              puts("\
Usage:  gsftopk [OPTION] FONT DPI\n\
Translate the PostScript Type 1 font FONT to PK bitmap format at DPI dpi.\n\
\n\
  -t, --test         check for presence of font in .map file.\n\
  --mapline=LINE     use LINE as the line from the .map file.\n\
  --mapfile=FILE     use FILE as a .map file; default psfonts.map.\n\
  -i GS, --interpreter=GS  use GS as Ghostscript interpreter.\n\
  --dosnames         short pk filename (cmr10.pk instead of cmr10.600pk).\n\
  -q, --quiet        don't print progress information to standard output.\n\
  -h, --help         print this message and exit.\n\
  -v, --version             print version number and exit.\n");
#else
              puts("\
Usage:  gsftopk [OPTION] FONT DPI\n\
Translate the PostScript Type 1 font FONT to PK bitmap format at DPI dpi.\n\
\n\
  -t, --test         check for presence of font in .map file.\n\
  --mapline=LINE     use LINE as the line from the .map file.\n\
  --mapfile=FILE     use FILE as a .map file; default psfonts.map.\n\
  -i GS, --interpreter=GS  use GS as Ghostscript interpreter.\n\
  --dosnames         short pk filename (cmr10.pk instead of cmr10.600pk).\n\
  -q, --quiet        don't print progress information to standard output.\n\
  --debug=NUM        set debugging flags.\n\
  -h, --help         print this message and exit.\n\
  -v, --version             print version number and exit.\n");
#endif
              return 0;
           case 'v':
#ifndef KPATHSEA
              printf("gsftopk %s\n", version);
#else
              {
                  extern KPSEDLL char *kpathsea_version_string;

                  printf("gsftopk(k) %s\n", version);
                  puts(kpathsea_version_string);
                  puts("Copyright (C) 1993-1998 Paul Vojta.\n\
There is NO warranty.  You may redistribute this software\n\
under the terms of the GNU General Public License\n\
and the standard X consortium copyright notice.\n\
For more information about these matters, see the files\n\
named COPYING and gsftopk.c.\n\
Author of gsftopk: Paul Vojta.");
              }
#endif
              return 0;
           }
       }

       if (mapfile != NULL && mapline != NULL)
           opt_oops("cannot specify both `--mapline' and `--mapfile'");

       if (argp >= argv + argc)
           opt_oops(test ? "must provide a font name"
             : "must provide a font name and resolution");

       fontname = *argp++;
       fontlen = strlen(fontname);

       if (argp >= argv + argc) {
           if (!test)
              opt_oops("must provide rendering resolution");
           dpi = 0.0;
       }
       else {
           dpi = atof(*argp++);
           if (dpi <= 0.0)
              opt_oops("DPI argument `%s' must be a positive number", *argp);
       }

       if (argp < argv + argc)
           opt_oops("no more than two arguments are allowed");

#ifdef KPATHSEA
       kpse_set_progname(argv[0]);
       kpse_init_prog("GSFTOPK", (int) (dpi + 0.5), NULL, "cmr10");
       if (!test)
           xputenv_int("KPATHSEA_DPI", (int) (dpi + 0.5));
#endif

#if _AMIGA
       /* [CL] 21-Jun-97
          This is quite silly but it really helps things when determining the
          font supplier and family.
       */
       putenv("GSFTOPKTFM=");
#endif

       /*
        * Read the dvips-style config file(s).
        */

       long_line = xmalloc(long_line_len);       /* initialize fgets_long */

#ifndef KPATHSEA
       config_file = search(CONFIGPATH, "TEXCONFIG", "config.ps");
       if (config_file != NULL)
           getdefaults(config_file);

       dvipsrc = getenv("DVIPSRC");
       if (dvipsrc == NULL) {
           dvipsrc = getenv("HOME");
           if (dvipsrc != NULL) {
              i = strlen(dvipsrc);
              p = xmalloc(i + 10);
              memcpy(p, dvipsrc, i);
              memcpy(p + i, "/.dvipsrc", 10);
           }
       }
       if (dvipsrc != NULL) {
           config_file = fopen(dvipsrc, "r");
           if (config_file != NULL)
              getdefaults(config_file);
       }

       config_file = search(CONFIGPATH, "TEXCONFIG", "config.gsftopk");
       if (config_file != NULL)
           getdefaults(config_file);
#else
       getdefaults("config.ps");

       dvipsrc = kpse_var_value("DVIPSRC");
       getdefaults(dvipsrc != NULL ? dvipsrc : "$HOME/.dvipsrc");

       getdefaults("config.gsftopk");

       /* Set HEADERPATH from config file.  */

       if (config_file_header_path != NULL)
           kpse_format_info[kpse_tex_ps_header_format].client_path
             = config_file_header_path;
#endif

       /*
        * Get the map line.
        */

       if (mapline != NULL) {
           if (memcmp(mapline, fontname, fontlen) != 0
             || (mapline[fontlen] != '\0' && !isspace(mapline[fontlen])))
              oops("font name does not match --mapline argument");
       }
       else {
           Boolean font_found;

           if (mapfile != NULL) {
#ifndef KPATHSEA
              config_file = search(CONFIGPATH, "TEXCONFIG",
                                 mapfile);
#else
              config_file = kpse_open_file(mapfile,
                                        kpse_fontmap_format);
#endif

              if (config_file == NULL) {
                  perror(mapfile);
                  exit(1);
              }
              font_found = scan_map_file(config_file);
           }
           else {
              struct p_list *p_node;

              font_found = False;
              *p_tail = NULL;
              for (p_node = p_head; p_node != NULL; p_node = p_node->next) {
#ifndef KPATHSEA
                  config_file = search(CONFIGPATH, "TEXCONFIG",
                    p_node->value);
#else
                  config_file = kpse_open_file(p_node->value,
                    kpse_fontmap_format);
#endif
                  if (config_file != NULL)
                     if (scan_map_file(config_file)) {
                         font_found = True;
                         break;
                     }
              }
           }

           if (!font_found)
              if (test)
                  exit(1);
              else
                  oops("Cannot find font %s in map file(s).", fontname);

           mapline = long_line;
       }

       if (test)
           exit(0);

       if (!quiet) {
           printf("%sversion %s", progname, version);
           fflush(stdout);
           col = 1;  /* any nonzero value will do */
       }

       /*
        * Parse the line from the map file.
        */
       for (p = mapline + fontlen; *p != '\0'; ++p) {
           if (isspace(*p)) continue;
           if (*p == '<') {
              char   *q;
              char   endc;
              char   c;
              FILE   *f;

              ++p;
              /* There may be two '<'s in front of the filename. */
              if (*p == '<') ++p;
              /* ... and maybe a '[' */
              if (*p == '[') ++p;
              q = p;
              while (*p != '\0' && !isspace(*p)) ++p;
              endc = *p;
              *p = '\0';
#ifdef KPATHSEA
              searchpath = kpse_find_file(q, kpse_tex_ps_header_format,true);
#ifdef WIN32
              /* Be safe for Ghostscript's sake */
              dostounix_filename(searchpath);
#endif /* WIN32 */
              f = searchpath ? fopen(searchpath, FOPEN_R_MODE) : NULL;
#else
              f = search(config_file_header_path, "DVIPSHEADERS", q);
#endif
              if (f == NULL) oops("Cannot find font file %s", q);
              /* search() also sets searchpath */
              addtodls(" (");
              addtodls(searchpath);
              c = getc(f);
              addtodls(c == '\0' ? ") ttload"
                : c == '\200' ? ") brun"
                : ") run");
              fclose(f);
              if (endc == '\0') break;
              continue;
           }
           else if (*p == '"') {
              char   *q;

              if (specinf != NULL)
                  *specp++ = ' ';
              else
                  specinf = specp = xmalloc(strlen(p));
              ++p;
              q = strchr(p, '"');
              if (q == NULL) q = p + strlen(p);
              memcpy(specp, p, q - p);
              specp += q - p;
              p = q;
              if (*p == '\0') break;
              else continue;
           }
           else {
              PSname = p;
              while (*p != '\0' && !isspace(*p)) ++p;
              if (*p == '\0') break;
           }
           *p = '\0';
       }

#if OLD_DVIPS
       /* Parse lines like `Symbol-Slanted "/Symbol .167 SlantFont"'. */
       if (*(p = specinf) == '/') {
           PSname = ++p;
           while (*p && !isspace(*p)) ++p;
           if (*p) *p++ = '\0';
           specinf = p;
       }
#endif /* OLD_DVIPS */

       if (specinf != NULL) {
           *specp = '\0';
           specinfo = specinf;
       }

       if (PSname == NULL)
           PSname = fontname;

       /*
        *     Start up Ghostscript.
        */

#ifdef KPATHSEA
       searchpath = kpse_find_file("render.ps", kpse_tex_ps_header_format,
                                true);
       render_ps = searchpath ? fopen (searchpath, FOPEN_R_MODE) : NULL;
#else
       render_ps = search(config_file_header_path, "DVIPSHEADERS",
           "render.ps");
#endif
       if (render_ps == NULL)
           oops("Cannot find PS driver file \"render.ps\".");
       fclose(render_ps);

#if !_AMIGA
       substarg = xmalloc(strlen(PSname) + 13);
       sprintf(substarg, "-sSUBSTFONT=%s", PSname);
#endif

       sprintf(dpistr, "%f", dpi);

#if _AMIGA

       mktemp(tmpname);

       sprintf(fngs, "fifo:%s/rweK", tmpname);
       sprintf(fngsf, "fifo:%s/rweKm", tmpname);

       std_in[1] = open(fngsf, O_WRONLY|O_TRUNC|O_CREAT, 511);

       if (std_in[1] == -1) {
           perror("pipe");
           return 1;
       }

       in = Open(fngs, MODE_OLDFILE);
       out = Open(fngs, MODE_NEWFILE);

       if (in && out) {
           int error;
           char *cmd;
           char formatstr[] = "%s -dNODISPLAY -dNOGC -sSUBSTFONT=\"%s\" -q -- \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"";
           unsigned int len;

           len = sizeof formatstr + strlen(gspath) + strlen(searchpath)
             + 2 * strlen(PSname) + (dlstring != NULL ? strlen(dlstring) : 0)
             + strlen(specinfo) + strlen(dpistr);

           cmd = xmalloc(len);

           sprintf(cmd, formatstr, PSname, gspath, searchpath, PSname,
             dlstring != NULL ? dlstring : "", specinfo, dpistr);

           error = SystemTags(cmd, SYS_Input, in,
                               SYS_Output, out,
                               SYS_Asynch, TRUE,
                               /* NP_StackSize, 50000, */
                               TAG_DONE, TAG_DONE);
           free(cmd);

           if (error == -1) {
              Close(in);
              Close(out);
              PrintFault(error, "System(gs)");
              exit(1);
           }
       }
       else {
           perror("pipes");
           if (in) Close(in);
           if (out) Close(out);
           exit(1);
       }

#elif WIN32

       /* (later) */

#else /* neither _AMIGA nor WIN32 */

       if (pipe(std_in) != 0 || pipe(std_out) != 0) {
           perror("pipe");
           return 1;
       }

       /* Catch the signal for death of the child process. */

#if HAVE_SIGACTION
       sigact.sa_handler = handle_sigchild;
       (void) sigemptyset(&sigact.sa_mask);
       sigact.sa_flags = SA_NOCLDSTOP;
       (void) sigaction(SIGCHLD, &sigact, (struct sigaction *) NULL);
#else
       (void) signal(SIGCHLD, handle_sigchild);
#endif

       /*
        * Also catch various termination signals, so that we can kill the
        * gs process before terminating.
        */

       (void) signal(SIGHUP, handle_sigterm);
       (void) signal(SIGINT, handle_sigterm);
       (void) signal(SIGQUIT, handle_sigterm);
       (void) signal(SIGTERM, handle_sigterm);

       fflush(stderr);             /* to avoid double flushing */
       gs_pid = vfork();
       if (gs_pid == 0) {
           close(std_in[1]);
           dup2(std_in[0], 0);
           close(std_in[0]);
           close(std_out[0]);
           dup2(std_out[1], 1);
           close(std_out[1]);
           execlp(gspath, "gs", "-dNODISPLAY", "-dNOGC", substarg, "-q", "--",
              /* render.ps */ searchpath,
              PSname,
              dlstring != NULL ? dlstring : "", specinfo, dpistr, NULL);
           if (col != 0) {
              putc('\n', stderr);
              col = 0;
           }
           perror(gspath);
           exit(1);
       }
       if (gs_pid == -1) {
           perror("fork");
           exit(1);
       }

#endif /* neither _AMIGA nor WIN32 */

       /*
        *     Open and read the tfm file.  If this takes a while, at least
        *     it can overlap with the startup of Ghostscript.
        */

       xfilename = xmalloc(fontlen + 10);
       strcpy(xfilename, fontname);
#ifdef KPATHSEA
#if _AMIGA
       strcpy(tfm_path, kpse_find_file(xfilename, kpse_tfm_format, true));
       tfm_file = fopen(tfm_path, "r");
#else
       tfm_file = kpse_open_file(xfilename, kpse_tfm_format);
#endif /* _AMIGA */
#else /* not KPATHSEA */
       strcpy(xfilename + fontlen, ".tfm");
       tfm_file = search(TFMPATH, "TEXFONTS", xfilename);
#endif /* not KPATHSEA */
       if (tfm_file == NULL) oops("Cannot find tfm file.");

       for (i = 0; i < 12; ++i) {
           int j;

           j = (int) ((byte) getc(tfm_file)) << 8;
           tfm_lengths[i] = j | (int) ((byte) getc(tfm_file));
       }
       checksum = getlong(tfm_file);
       design = getlong(tfm_file);
       fseek(tfm_file, 4 * (lh + 6), 0);
       p = charlist;
       for (cc = bc; cc <= ec; ++cc) {
           width_index[cc] = (byte) getc(tfm_file);
           if (width_index[cc] != 0) {
              sprintf(p, "%d ", cc);
              p += strlen(p);
           }
           (void) getc(tfm_file);
           (void) getc(tfm_file);
           (void) getc(tfm_file);
       }
       for (i = 0; i < nw; ++i) tfm_widths[i] = getlong(tfm_file);
       fclose(tfm_file);
       p[-1] = '\n';

       sprintf(designstr, "%f\n", (float) design / (1 << 20));

#if !WIN32

       /* write the design size and character list to the file */
       write(std_in[1], designstr, strlen(designstr));
       write(std_in[1], charlist, p - charlist);

       close(std_in[1]);

#else /* WIN32 */

       if (gs_locate() == NULL) {
         fprintf(stderr, "\nCan't locate Ghostscript ! Exiting ...\n");
         return EXIT_FAILURE;
       }

       SetConsoleCtrlHandler(handle_sigterm, TRUE);

       hGsDataIn = CreateEvent(NULL, FALSE, FALSE, "gsDataIn");
       hGsDataOut = CreateEvent(NULL, FALSE, FALSE, "gsDataOut");

       gs_argv[3] = substarg;
       gs_argv[6] = searchpath;
       gs_argv[7] = PSname;
       gs_argv[8] = dlstring != NULL ? dlstring : "";
       gs_argv[9] = specinfo;
       gs_argv[10] = dpistr;

       buffer_stdin = concat(designstr, charlist);

       if ((hGsThread = CreateThread(NULL,            /* security attributes */
                                  0,               /* default stack size */
                                  Win32GsSendData, /* start address of thread */
                                  0,               /* parameter */
                                  0,               /* creation flags */
                                  &idGsThread      /* thread id */
                                  )) == NULL)
         Win32Error("CreateThread");

#endif /* WIN32 */

/*
 *     Read the output from Ghostscript.
 */

#if _AMIGA

       if ((data_file = fopen(fngsf, "r")) == NULL) {
           perror("GS_out");
           exit(1);
       }

#elif WIN32

       /* Nothing */

#else /* neither _AMIGA nor WIN32 */

       data_fd = std_out[0];

       /* Set data_fd for non-blocking I/O */
       if (fcntl(data_fd, F_SETFL, fcntl(data_fd, F_GETFL, 0) | O_NONBLOCK)
         == -1)
           perror("fcntl");

#endif /* neither _AMIGA nor WIN32 */

/*
 *     Create pk file and write preamble.
 */

       if (dosnames)
           strcpy(xfilename + fontlen, ".pk");
       else
           sprintf(xfilename + fontlen, ".%dpk", (int) (dpi + 0.5));

       if ((pk_file = fopen(xfilename, FOPEN_WBIN_MODE)) == NULL) {
           perror(xfilename);
           exit_toto_too();
       }
       putc(PK_PRE, pk_file);
       putc(PK_ID, pk_file);
       expect("V");  /* get GS version */
       i = strlen(line) - 2;
       if (i < 0 || i > 10) i = 0;
       line[1] = '/';
       if (!quiet) {
           if (i > 0) fwrite(line + 1, 1, i, stdout);
           putchar('\n');
           col = 0;
       }
       putc(sizeof(progname) + sizeof(version) + i - 2, pk_file);
       fwrite(progname, 1, sizeof(progname) - 1, pk_file);
       fwrite(version, 1, sizeof(version) - 1, pk_file);
       if (i >= 0) {
           fwrite(line + 1, 1, i, pk_file);
       }
       putlong(design);
       putlong(checksum);
       ppp = dpi / 72.27 * 65536.0 + 0.5;
       putlong(ppp); /* hppp */
       putlong(ppp); /* vppp */

/*
 *     Write the actual characters.
 */

       for (cc = bc; cc <= ec; ++cc)
           if (width_index[cc] != 0)
              putglyph(cc);

#if _AMIGA

       fclose(data_file);

#elif WIN32

       /* Release data buffer, enable thread to terminate */
       SetEvent(hGsDataOut);

#ifdef DEBUG
       fprintf(stderr, "Waiting for thread ... \n");
#endif
       if (hGsThread) {
         switch (WaitForSingleObject(hGsThread, 2000)) {
         case WAIT_OBJECT_0:
           CloseHandle(hGsThread);
           hGsThread = NULL;
           break;
         case WAIT_TIMEOUT:
           fprintf(stderr, "Timeout waiting for Gs thread.\n");
           break;
         case WAIT_FAILED:
           fprintf(stderr, "WaitForSingleObject failed on Gs thread (Error code %d).\n",
                  GetLastError());
           break;
         default:
           break;
         }
       }

       if (hGsThread) {
         if (TerminateThread(hGsThread, 1) == 0) {
           fprintf(stderr, "... couldn't terminate gs thread\n");
         }
         CloseHandle(hGsThread);
         /* FIXME : is it right to call this ? */
         gs_dll_release();
       }
       if (hGsDataIn)
         CloseHandle(hGsDataIn);
       if (hGsDataOut)
         CloseHandle(hGsDataOut);

#else /* neither _AMIGA nor WIN32 */

       close(data_fd);
       if (!gs_is_done)
           wait_for_gs();

#endif /* neither _AMIGA nor WIN32 */

/*
 *     Write out identifying specials:
 *            jobname=(font)
 *            mag=1
 *            mode=modeless
 *            pixels_per_inch=(dpi)
 */

       putspecl("jobname=", fontname);
       putspecl("mag=1", NULL);
       putspecl("mode=modeless", NULL);
       sprintf(dpistr, "%d", (int) dpi);
       putspecl("pixels_per_inch=", dpistr);

/*
 *     Postamble
 */

       putc(PK_POST, pk_file);
       while (ftell(pk_file) % 4 != 0) putc(PK_NOP, pk_file);
       fclose(pk_file);
       if (!quiet) putchar('\n');
       col = 0;

#if _AMIGA
       /* [CL] 21-Jun-97
          The same silly thing to indicate the path of the tfm file
       */
       {
           char tmpstr[80];

           sprintf(tmpstr, "GSFTOPKTFM=%s", tfm_path);
           putenv(tmpstr);
       }
#endif

       return 0;
}

Here is the call graph for this function:

static FILE* search P3C ( const char *  ,
path  ,
const char *  ,
path_var  ,
const char *  ,
name   
) [static]

Definition at line 1260 of file gsftopk.c.

{
       const char    *env_path     = NULL;
       FILE          *f;

       if (path_var != NULL) {
           if (*name == '/') {
              strcpy(searchpath, name);
              return fopen(searchpath, "r");
           }
           env_path = getenv(path_var);
       }
       if (env_path == NULL) {
           env_path = path;
           path = NULL;
       }
       searchname = name;
       searchnamelen = strlen(name);
       for (;;) {
           const char *p;

           p = strchr(env_path, ':');
           if (p == NULL) p = env_path + strlen(env_path);
           if (p == env_path) {
              if (path != NULL) {
                  f = search(path, (char *) NULL, name);
                  if (f != NULL) return f;
              }
           }
           else {
              if (setjmp(found_env))
                  return searchfile;
              main_search_proc(searchpath,
                  env_path, find_dbl_slash(env_path, p), p,
                  True, &firstnode, firstnode.sp);
           }
           if (*p == '\0') return NULL;
           env_path = p + 1;
       }
}

Here is the call graph for this function:

static void main_search_proc P7C ( char *  ,
matpos  ,
const char *  ,
sp_pos  ,
const char *  ,
sp_slash  ,
const char *  ,
sp_end  ,
wide_bool  ,
skip_subdirs  ,
struct spacenode ,
space  ,
char *  ,
spacenext   
) [static]

Definition at line 1169 of file gsftopk.c.

{
       char          *mp;
       struct stat   statbuf;
       DIR           *dir;
       struct dirent *entry;
       int           lenleft;
       int           len;
       struct spacenode *space1;
       char          *spacenext1;

       mp = matpos + (sp_slash - sp_pos);
       /* check length */
       if (mp + searchnamelen >= searchpath + sizeof(searchpath) - 2) return;
       memcpy(matpos, sp_pos, sp_slash - sp_pos);
       if (sp_slash == sp_end) {   /* try for a file */
           *mp = '/';
           strcpy(mp + (mp == searchpath || mp[-1] != '/'), searchname);
           searchfile = fopen(searchpath, "r");
           if (searchfile != NULL) longjmp(found_env, True);
       }
       else {/* try for a subdirectory */
           *mp = '\0';
           if (stat(searchpath, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) {
              *mp++ = '/';
              main_search_proc(mp, sp_slash + 2,
                  find_dbl_slash(sp_slash + 2, sp_end), sp_end,
                  statbuf.st_nlink <= 2, space, spacenext);
           }
       }
       if (skip_subdirs) return;
       *matpos = '\0';
       dir = opendir(searchpath);
       if (dir == NULL) return;
       lenleft = searchpath + sizeof(searchpath) - matpos;
       space1 = space;
       spacenext1 = spacenext;
       for (;;) {
           entry = readdir(dir);
           if (entry == NULL) break;
           len = NAMLEN(entry) + 1;
           if (len > lenleft) continue;   /* too long */
           strcpy(matpos, entry->d_name);
           if (*matpos == '.' && (matpos[1] == '\0' || (matpos[1] == '.'
                  && matpos[2] == '\0')))
              continue;            /* ignore . and .. */
           if (stat(searchpath, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))
              continue;            /* if not a directory */
           if (statbuf.st_nlink > 2) ++len;
           if (spacenext1 + len > space1->sp + HUNKSIZE) {
              space1->sp_end = spacenext1;
              if (space1->next == NULL) {
                  space1->next = xmalloc(sizeof(struct spacenode));
                  space1->next->next = NULL;
              }
              space1 = space1->next;
              spacenext1 = space1->sp;
           }
           if (statbuf.st_nlink > 2) {
              *spacenext1++ = '/';
              --len;
           }
           memcpy(spacenext1, entry->d_name, len - 1);
           spacenext1[len - 1] = '\0';
           spacenext1 += len;
       }
       closedir(dir);
       for (;;) {
           space1->sp_end = spacenext1;
           if (spacenext == space->sp_end) {
              if (space == space1) break;
              space = space->next;
              spacenext = space->sp;
           }
           skip_subdirs = True;
           if (*spacenext == '/') {
              ++spacenext;
              skip_subdirs = False;
           }
           len = strlen(spacenext);
           memcpy(matpos, spacenext, len);
           matpos[len] = '/';
           main_search_proc(matpos + len + 1, sp_pos, sp_slash, sp_end,
              skip_subdirs, space1, spacenext1);
           spacenext += len + 1;
       }
}

Here is the call graph for this function:

char* strchr ( )
char * strrchr ( )

Here is the caller graph for this function:


Variable Documentation

Definition at line 1509 of file gsftopk.c.

Definition at line 514 of file gsftopk.c.

Definition at line 522 of file gsftopk.c.

unsigned int bm_size

Definition at line 521 of file gsftopk.c.

Definition at line 482 of file gsftopk.c.

Definition at line 520 of file gsftopk.c.

Definition at line 505 of file gsftopk.c.

int col = 0

Definition at line 443 of file gsftopk.c.

Definition at line 452 of file gsftopk.c.

char copyright[] = "@(#) Copyright (c) 1993-1998 Paul Vojta.\n" [static]

Definition at line 25 of file gsftopk.c.

Definition at line 484 of file gsftopk.c.

Definition at line 473 of file gsftopk.c.

Definition at line 481 of file gsftopk.c.

Definition at line 483 of file gsftopk.c.

int deltas[13]

Definition at line 1510 of file gsftopk.c.

long design

Definition at line 506 of file gsftopk.c.

unsigned int dls_len = 0

Definition at line 1412 of file gsftopk.c.

unsigned int dls_max = 0

Definition at line 1413 of file gsftopk.c.

char* dlstring = NULL

Definition at line 1411 of file gsftopk.c.

Definition at line 417 of file gsftopk.c.

Definition at line 1506 of file gsftopk.c.

Definition at line 413 of file gsftopk.c.

char* fontname

Definition at line 412 of file gsftopk.c.

jmp_buf found_env [static]

Definition at line 1150 of file gsftopk.c.

Definition at line 717 of file gsftopk.c.

Definition at line 445 of file gsftopk.c.

const char* gspath = GS_PATH

Definition at line 416 of file gsftopk.c.

Definition at line 517 of file gsftopk.c.

Definition at line 518 of file gsftopk.c.

char line[82]

Definition at line 1445 of file gsftopk.c.

char* long_line = NULL

Definition at line 1307 of file gsftopk.c.

Definition at line 1308 of file gsftopk.c.

const char* mapfile = NULL

Definition at line 415 of file gsftopk.c.

char* mapline = NULL

Definition at line 414 of file gsftopk.c.

byte masks[] = {0, 1, 3, 7, 017, 037, 077, 0177, 0377} [static]

Definition at line 1504 of file gsftopk.c.

Boolean odd = False [static]

Definition at line 1535 of file gsftopk.c.

struct option[] [static]
Initial value:
 {
              {"test",      't',   False, &test, True},
              {"mapline",   0,     True,  &mapline, 0},
              {"mapfile",   0,     True,  &mapfile, 0},
              {"interpreter",      'i',   True,  &gspath, 0},
              {"dosnames",  0,     False, &dosnames, True},
              {"quiet",     'q',   False, &quiet,       True},



              {"version",   'v',   False, NULL,  0},
              {"help",      'h',   False, NULL,  0}}

Definition at line 428 of file gsftopk.c.

struct p_list* p_head = &psfonts_map

Definition at line 466 of file gsftopk.c.

struct p_list** p_tail = &psfonts_map.next

Definition at line 467 of file gsftopk.c.

byte part [static]

Definition at line 1536 of file gsftopk.c.

Definition at line 1507 of file gsftopk.c.

Definition at line 1508 of file gsftopk.c.

Definition at line 441 of file gsftopk.c.

Definition at line 523 of file gsftopk.c.

char progname[] = "gsftopk "

Definition at line 398 of file gsftopk.c.

Definition at line 418 of file gsftopk.c.

FILE* searchfile [static]

Definition at line 1151 of file gsftopk.c.

const char* searchname [static]

Definition at line 1152 of file gsftopk.c.

int searchnamelen [static]

Definition at line 1153 of file gsftopk.c.

char searchpath[MAXPATHLEN+1] [static]

Definition at line 1134 of file gsftopk.c.

Definition at line 516 of file gsftopk.c.

const char* specinfo = ""

Definition at line 444 of file gsftopk.c.

Definition at line 411 of file gsftopk.c.

Definition at line 499 of file gsftopk.c.

long tfm_widths[256]

Definition at line 508 of file gsftopk.c.

char version[] = VERSION

Definition at line 403 of file gsftopk.c.

Definition at line 519 of file gsftopk.c.

Definition at line 515 of file gsftopk.c.

Definition at line 507 of file gsftopk.c.

char* xfilename

Definition at line 442 of file gsftopk.c.