36 _G(
"Houston, we have a problem"),
37 _G(
"3.. 2.. 1.. BOOM!"),
42 #define NMSGS (sizeof(messages) / sizeof(char *))
51 static void vputlog(
int level,
const char *head,
const char *format, va_list ap)
64 if(filename && (f = fopen(filename,
"w")) == NULL)
96 void __debug(
int mask,
const char *format, ...)
100 va_start(ap, format);
103 fprintf(stderr,
"Debug: ");
104 vfprintf(stderr, format, ap);
110 va_start(ap, format);
122 va_start(ap, format);
125 vfprintf(stderr, format, ap);
128 va_start(ap, format);
139 va_start(ap, format);
140 fprintf(stderr,
"%s: %s: ",
143 vfprintf(stderr, format, ap);
147 va_start(ap, format);
158 va_start(ap, format);
160 vfprintf(stderr, format, ap);
164 va_start(ap, format);
174 va_start(ap, format);
176 vfprintf(stderr, format, ap);
180 va_start(ap, format);
190 va_start(ap, format);
192 vfprintf(stderr, format, ap);
196 va_start(ap, format);
209 void *ptr = malloc(nelems);
212 mdvi_fatal(
_(
"out of memory allocating %u bytes\n"),
222 mdvi_crash(
_(
"attempted to reallocate with zero size\n"));
223 ptr = realloc(data, newsize);
225 mdvi_fatal(
_(
"failed to reallocate %u bytes\n"), (
unsigned)newsize);
234 mdvi_crash(
_(
"attempted to callocate 0 members\n"));
236 mdvi_crash(
_(
"attempted to callocate %u members with size 0\n"),
238 ptr = calloc(nmemb, size);
241 (
unsigned)nmemb, (
unsigned)size);
257 length = strlen(
string) + 1;
259 memcpy(ptr,
string, length);
266 strncpy(to, from, length);
288 memcpy(ptr, data, length);
299 needle_len = strlen (needle);
300 haystack_len = strlen (haystack);
305 if (haystack_len < needle_len)
306 return (
char *)haystack;
308 p = haystack + haystack_len - needle_len;
309 while (p >= haystack) {
310 for (i = 0; i < needle_len; i++)
311 if (p[i] != needle[i])
327 size_t buf_size = 512;
331 if ((ptr = getcwd (buf, buf_size)) == NULL && errno == ERANGE) {
339 buf =
mdvi_realloc (buf, strlen (buf) + strlen (path) + 2);
341 strncat (buf, path, strlen (path));
351 static const char *units =
"incmmmmtptpcddccspbpftydcs";
355 for(p = spec; *p >=
'0' && *p <=
'9'; p++)
356 val = 10.0 * val + (
double)(*p -
'0');
360 while(*p && *p >=
'0' && *p <=
'9') {
361 val += (*p++ -
'0') * factor;
362 factor = factor * 0.1;
366 for(q = units; *q; q += 2) {
367 if(p[0] == q[0] && p[1] == q[1])
370 switch((
int)(q - units)) {
371 case 0: factor = 1.0;
break;
372 case 2: factor = 1.0 / 2.54;
break;
373 case 4: factor = 1.0 / 25.4;
break;
374 case 6: factor = 1.0 / 0.0254;
break;
375 case 8: factor = 1.0 / 72.27;
break;
376 case 10: factor = 12.0 / 72.27;
break;
377 case 12: factor = (1238.0 / 1157.0) / 72.27;
break;
378 case 14: factor = 12 * (1238.0 / 1157.0) / 72.27;
break;
379 case 16: factor = 1.0 / (72.27 * 65536);
break;
380 case 18: factor = 1.0 / 72.0;
break;
381 case 20: factor = 12.0;
break;
382 case 22: factor = 36.0;
break;
383 case 24: factor = 1.0 / 72000.0;
break;
384 default: factor = 1.0;
393 return (
int)(factor * dpi + 0.5);
400 if(fstat(fd, &st) == 0)
401 return (
Ulong)st.st_mtime;
405 char *
xstradd(
char *dest,
size_t *size,
size_t n,
const char *src,
size_t m)
418 char *
getword(
char *
string,
const char *delim,
char **end)
424 for(ptr =
string; *ptr &&
strchr(delim, *ptr); ptr++);
430 while(*ptr && !
strchr(delim, *ptr))
436 char *
getstring(
char *
string,
const char *delim,
char **end)
443 for(ptr =
string; *ptr &&
strchr(delim, *ptr); ptr++);
447 quoted = (*ptr ==
'"');
449 for(word = ++ptr; *ptr && *ptr !=
'"'; ptr++);
451 for(word = ptr; *ptr && !
strchr(delim, *ptr); ptr++);
475 len = strlen(
string);
484 }
else if(dstr->
size == 0) {
498 len = strlen(
string);
500 if(pos + len >= dstr->
length) {
515 len = strlen(
string);
534 len = strlen(
string);