File: vflmklib.c

package info (click to toggle)
vflib3 3.6.14.dfsg-3+nmu3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 11,536 kB
  • ctags: 3,710
  • sloc: ansic: 35,811; sh: 10,357; asm: 3,290; makefile: 962; lisp: 123; perl: 109; awk: 43
file content (210 lines) | stat: -rw-r--r-- 4,625 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* 
 * vflmklib.c 
 * - commn functions used in vflmkXXX.c
 *
 *
 * by Hirotsugu Kakugawa
 *
 *  10 May 2001
 *  22 Jul 2005  Enhanced file search.
 */
/*
 * Copyright (C) 2001-2005  Hirotsugu Kakugawa. 
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
 */


#include "config.h"
#include "with.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/time.h>

#ifdef WITH_KPATHSEA
# include  "kpathsea/kpathsea.h"
#endif

#include  "VFlib-3_6.h"
#include  "VFsys.h"
#include  "vflibcap.h"
#include  "fsearch.h"



char*
copy_cmdline(int xargc, char **xargv)
{
  int   i, t;
  char  *s, *p;

  t = 1;
  for (i = 0; i < xargc; i++)
    t = t + strlen(xargv[i]) + 1;
  if ((s = malloc(t)) == NULL){
    fprintf(stderr, "no memory.\n");
    exit(1);
  }
  
  p = s;
  for (i = 0; i < xargc; i++){
    strcpy(p, xargv[i]);
    p += strlen(xargv[i]);
    *(p++) = ' ';
  }
  p[t-1] = '\0';

  return s;
}


void 
banner(char *name, char *prog, char *cline)
{
  char  host[256], ts[256], *p;
  time_t   t;

  if (gethostname(host, sizeof(host)) < 0)
    strcpy(host, "???");
  t = time(NULL);

  strcpy(ts, asctime(localtime(&t)));
  if ((p = strchr(ts, '\n')) != NULL)
    *p = '\0';

  printf(";; -------------------------------------------------------\n");
  printf(";; *** %s ***\n", name);
  printf(";; Generated by %s\n", prog);
  printf(";; at %s on %s\n", ts, host);
  printf(";; Commandline: %s\n", cline);
  printf("\n");
}

char*
x_strdup(char *s)
{
  char  *p;

  if (s == NULL){
    fprintf(stderr, "internal error.");
    exit(1);
  }

  p = malloc(strlen(s) + 1);
  if (p == NULL){
    fprintf(stderr, "no memory.");
    exit(1);
  }
  
  strcpy(p, s);
  return p;
}

char*
check_font_exist(char *file, char **dirs, int ndirs, int kptype, char **ext)
{
  int  i, l, j, y;
  char  path[MAXPATHLEN], *p, **e;
  char *e0[] = { "", NULL };

  if (ndirs == 0)
    return 0;  /* may or may not exist */

  e = ext;
  if (e == NULL)
    e = e0;

  for (i = 0; i < ndirs; i++){
    if ((strcmp(dirs[i], "TEXMF") == 0)
	|| (strcmp(dirs[i], "KPATHSEA") == 0)
	|| (strcmp(dirs[i], "texmf") == 0)
	|| (strcmp(dirs[i], "kpathsea") == 0)){
      p = kpse_find_file(file, kptype, 0);
      if ((p != NULL) && (access(p, R_OK) >= 0)){
	return  x_strdup(file);    /* exist */
      } else { 
	for (j = 0; e[j] != NULL; j++){
	  sprintf(path, "%s%s", file, e[j]);
	  /* check as it is */
	  p = kpse_find_file(path, kptype, 0);
	  if ((p != NULL) && (access(p, R_OK) >= 0))
	    return  x_strdup(path);    /* exist */
	  /* check lower case */
	  for (y = 0; path[y] != '\0'; y++)
	    path[y] = tolower(path[y]);
	  p = kpse_find_file(path, kptype, 0);
	  if ((p != NULL) && (access(p, R_OK) >= 0))
	    return  x_strdup(path);    /* exist */
	  /* check upper case */
	  for (y = 0; path[y] != '\0'; y++)
	    path[y] = toupper(path[y]);
	  p = kpse_find_file(path, kptype, 0);
	  if ((p != NULL) && (access(p, R_OK) >= 0))
	    return  x_strdup(path);    /* exist */
	}
      }
      return NULL;
    } else {
      for (j = 0; e[j] != NULL; j++){
	sprintf(path, "%s", dirs[i]);
	l = strlen(dirs[i]);
	if ((l >= 2) && (dirs[i][l-2] == '/') && (dirs[i][l-1] == '/')){
	  sprintf(&path[l-2], "/%s", file);
	} else if ((l >= 2) && (dirs[i][l-2] != '/') && (dirs[i][l-1] == '/')){
	  sprintf(&path[l-1], "/%s", file);
	} else {
	  sprintf(&path[l], "/%s", file);
	}
	strcat(path, e[j]);
	if (access(path, R_OK) >= 0)
	  return  x_strdup(path);    /* exist */
      }
    }
  }
  
  return NULL;  /* not exist */
}


void
check_argc(int argc)
{
  if (argc == 0){
    fprintf(stderr,"Illegal command line argument\n");
    fprintf(stderr,"Use '--help' option for help\n");
    exit(1);
  }
}


int
map_need_tfm(char *fontclass)
{
  int  i;
  static char *db[] = {
    "type1", 
    "vf", 
    NULL};
  
  for (i = 0; db[i] != NULL; i++){
    if (strcmp(fontclass, db[i]) == 0)
      return 1;
  }
  return 0;  
}