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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
|
/* $Id: indep.c,v 1.38 2007/05/23 15:06:05 inu Exp $ */
#include "fm.h"
#include <stdio.h>
#ifndef __MINGW32_VERSION
#include <pwd.h>
#endif /* __MINGW32_VERSION */
#include <sys/param.h>
#include <sys/types.h>
#include <stdlib.h>
#include "indep.h"
#include "Str.h"
#include <gc.h>
#include "myctype.h"
#include "entity.h"
unsigned char QUOTE_MAP[0x100] = {
/* NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI */
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
/* DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US */
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
/* SPC ! " # $ % & ' ( ) * + , - . / */
24, 72, 76, 40, 8, 40, 41, 77, 72, 72, 72, 40, 72, 8, 0, 64,
/* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 72, 74, 72, 75, 40,
/* @ A B C D E F G H I J K L M N O */
72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* P Q R S T U V W X Y Z [ \ ] ^ _ */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 72, 72, 72, 72, 0,
/* ` a b c d e f g h i j k l m n o */
72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* p q r s t u v w x y z { | } ~ DEL */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 72, 72, 72, 72, 24,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
};
char *HTML_QUOTE_MAP[] = {
NULL,
"&",
"<",
">",
""",
"'",
NULL,
NULL,
};
clen_t
strtoclen(const char *s)
{
#ifdef HAVE_STRTOLL
return strtoll(s, NULL, 10);
#elif defined(HAVE_STRTOQ)
return strtoq(s, NULL, 10);
#elif defined(HAVE_ATOLL)
return atoll(s);
#elif defined(HAVE_ATOQ)
return atoq(s);
#else
return atoi(s);
#endif
}
#ifndef HAVE_BCOPY
void
bcopy(const void *src, void *dest, int len)
{
int i;
if (src == dest)
return;
if (src < dest) {
for (i = len - 1; i >= 0; i--)
((char *)dest)[i] = ((const char *)src)[i];
}
else { /* src > dest */
for (i = 0; i < len; i++)
((char *)dest)[i] = ((const char *)src)[i];
}
}
void
bzero(void *ptr, int len)
{
int i;
char *p = ptr;
for (i = 0; i < len; i++)
*(p++) = 0;
}
#endif /* not HAVE_BCOPY */
char *
allocStr(const char *s, int len)
{
char *ptr;
if (s == NULL)
return NULL;
if (len < 0)
len = strlen(s);
if (len < 0 || len >= STR_SIZE_MAX)
len = STR_SIZE_MAX - 1;
ptr = NewAtom_N(char, len + 1);
if (ptr == NULL) {
fprintf(stderr, "fm: Can't allocate string. Give me more memory!\n");
exit(-1);
}
bcopy(s, ptr, len);
ptr[len] = '\0';
return ptr;
}
int
strCmp(const void *s1, const void *s2)
{
return strcmp(*(const char **)s1, *(const char **)s2);
}
char *
currentdir()
{
char *path;
#ifdef HAVE_GETCWD
#ifdef MAXPATHLEN
path = NewAtom_N(char, MAXPATHLEN);
getcwd(path, MAXPATHLEN);
#else
path = getcwd(NULL, 0);
#endif
#else /* not HAVE_GETCWD */
#ifdef HAVE_GETWD
path = NewAtom_N(char, 1024);
getwd(path);
#else /* not HAVE_GETWD */
FILE *f;
char *p;
path = NewAtom_N(char, 1024);
f = popen("pwd", "r");
fgets(path, 1024, f);
pclose(f);
for (p = path; *p; p++)
if (*p == '\n') {
*p = '\0';
break;
}
#endif /* not HAVE_GETWD */
#endif /* not HAVE_GETCWD */
return path;
}
char *
cleanupName(char *name)
{
char *buf, *p, *q;
buf = allocStr(name, -1);
p = buf;
q = name;
while (*q != '\0') {
if (strncmp(p, "/../", 4) == 0) { /* foo/bar/../FOO */
if (p - 2 == buf && strncmp(p - 2, "..", 2) == 0) {
/* ../../ */
p += 3;
q += 3;
}
else if (p - 3 >= buf && strncmp(p - 3, "/..", 3) == 0) {
/* ../../../ */
p += 3;
q += 3;
}
else {
while (p != buf && *--p != '/') ; /* ->foo/FOO */
*p = '\0';
q += 3;
strcat(buf, q);
}
}
else if (strcmp(p, "/..") == 0) { /* foo/bar/.. */
if (p - 2 == buf && strncmp(p - 2, "..", 2) == 0) {
/* ../.. */
}
else if (p - 3 >= buf && strncmp(p - 3, "/..", 3) == 0) {
/* ../../.. */
}
else {
while (p != buf && *--p != '/') ; /* ->foo/ */
*++p = '\0';
}
break;
}
else if (strncmp(p, "/./", 3) == 0) { /* foo/./bar */
*p = '\0'; /* -> foo/bar */
q += 2;
strcat(buf, q);
}
else if (strcmp(p, "/.") == 0) { /* foo/. */
*++p = '\0'; /* -> foo/ */
break;
}
else if (strncmp(p, "//", 2) == 0) { /* foo//bar */
/* -> foo/bar */
*p = '\0';
q++;
strcat(buf, q);
}
else {
p++;
q++;
}
}
return buf;
}
char *
expandPath(char *name)
{
char *p;
struct passwd *passent, *getpwnam(const char *);
Str extpath = NULL;
if (name == NULL)
return NULL;
p = name;
if (*p == '~') {
p++;
#ifndef __MINGW32_VERSION
if (IS_ALPHA(*p)) {
char *q = strchr(p, '/');
if (q) { /* ~user/dir... */
passent = getpwnam(allocStr(p, q - p));
p = q;
}
else { /* ~user */
passent = getpwnam(p);
p = "";
}
if (!passent)
goto rest;
extpath = Strnew_charp(passent->pw_dir);
} else
#endif /* __MINGW32_VERSION */
if (*p == '/' || *p == '\0') { /* ~/dir... or ~ */
extpath = Strnew_charp(getenv("HOME"));
}
else
goto rest;
if (Strcmp_charp(extpath, "/") == 0 && *p == '/')
p++;
Strcat_charp(extpath, p);
return extpath->ptr;
}
rest:
return name;
}
#ifndef HAVE_STRCHR
char *
strchr(const char *s, int c)
{
while (*s) {
if ((unsigned char)*s == c)
return (char *)s;
s++;
}
return NULL;
}
#endif /* not HAVE_STRCHR */
#ifndef HAVE_STRCASECMP
int
strcasecmp(const char *s1, const char *s2)
{
int x;
while (*s1) {
x = TOLOWER(*s1) - TOLOWER(*s2);
if (x != 0)
return x;
s1++;
s2++;
}
return -TOLOWER(*s2);
}
int
strncasecmp(const char *s1, const char *s2, size_t n)
{
int x;
while (*s1 && n) {
x = TOLOWER(*s1) - TOLOWER(*s2);
if (x != 0)
return x;
s1++;
s2++;
n--;
}
return n ? -TOLOWER(*s2) : 0;
}
#endif /* not HAVE_STRCASECMP */
#ifndef HAVE_STRCASESTR
/* string search using the simplest algorithm */
char *
strcasestr(const char *s1, const char *s2)
{
int len1, len2;
if (s2 == NULL)
return (char *)s1;
if (*s2 == '\0')
return (char *)s1;
len1 = strlen(s1);
len2 = strlen(s2);
while (*s1 && len1 >= len2) {
if (strncasecmp(s1, s2, len2) == 0)
return (char *)s1;
s1++;
len1--;
}
return 0;
}
#endif
static int
strcasematch(char *s1, char *s2)
{
int x;
while (*s1) {
if (*s2 == '\0')
return 1;
x = TOLOWER(*s1) - TOLOWER(*s2);
if (x != 0)
break;
s1++;
s2++;
}
return (*s2 == '\0');
}
/* search multiple strings */
int
strcasemstr(char *str, char *srch[], char **ret_ptr)
{
int i;
while (*str) {
for (i = 0; srch[i]; i++) {
if (strcasematch(str, srch[i])) {
if (ret_ptr)
*ret_ptr = str;
return i;
}
}
str++;
}
return -1;
}
int
strmatchlen(const char *s1, const char *s2, int maxlen)
{
int i;
/* To allow the maxlen to be negatie (infinity),
* compare by "!=" instead of "<=". */
for (i = 0; i != maxlen; ++i) {
if (!s1[i] || !s2[i] || s1[i] != s2[i])
break;
}
return i;
}
char *
remove_space(char *str)
{
char *p, *q;
for (p = str; *p && IS_SPACE(*p); p++) ;
for (q = p; *q; q++) ;
for (; q > p && IS_SPACE(*(q - 1)); q--) ;
if (*q != '\0')
return Strnew_charp_n(p, q - p)->ptr;
return p;
}
int
non_null(char *s)
{
if (s == NULL)
return FALSE;
while (*s) {
if (!IS_SPACE(*s))
return TRUE;
s++;
}
return FALSE;
}
void
cleanup_line(Str s, int mode)
{
if (s->length >= 2 &&
s->ptr[s->length - 2] == '\r' && s->ptr[s->length - 1] == '\n') {
Strshrink(s, 2);
Strcat_char(s, '\n');
}
else if (Strlastchar(s) == '\r')
s->ptr[s->length - 1] = '\n';
else if (Strlastchar(s) != '\n')
Strcat_char(s, '\n');
if (mode != PAGER_MODE) {
int i;
for (i = 0; i < s->length; i++) {
if (s->ptr[i] == '\0')
s->ptr[i] = ' ';
}
}
}
int
getescapechar(char **str)
{
int dummy = -1;
char *p = *str, *q;
int strict_entity = TRUE;
if (*p == '&')
p++;
if (*p == '#') {
p++;
if (*p == 'x' || *p == 'X') {
p++;
if (!IS_XDIGIT(*p)) {
*str = p;
return -1;
}
for (dummy = GET_MYCDIGIT(*p), p++; IS_XDIGIT(*p); p++)
dummy = dummy * 0x10 + GET_MYCDIGIT(*p);
if (*p == ';')
p++;
*str = p;
return dummy;
}
else {
if (!IS_DIGIT(*p)) {
*str = p;
return -1;
}
for (dummy = GET_MYCDIGIT(*p), p++; IS_DIGIT(*p); p++)
dummy = dummy * 10 + GET_MYCDIGIT(*p);
if (*p == ';')
p++;
*str = p;
return dummy;
}
}
if (!IS_ALPHA(*p)) {
*str = p;
return -1;
}
q = p;
for (p++; IS_ALNUM(*p); p++) ;
q = allocStr(q, p - q);
if (strcasestr("lt gt amp quot apos nbsp", q) && *p != '=') {
/* a character entity MUST be terminated with ";". However,
* there's MANY web pages which uses < , > or something
* like them as <, >, etc. Therefore, we treat the most
* popular character entities (including &#xxxx;) without
* the last ";" as character entities. If the trailing character
* is "=", it must be a part of query in an URL. So <=, >=, etc.
* are not regarded as character entities.
*/
strict_entity = FALSE;
}
if (*p == ';')
p++;
else if (strict_entity) {
*str = p;
return -1;
}
*str = p;
return getHash_si(&entity, q, -1);
}
char *
getescapecmd(char **s)
{
char *save = *s;
Str tmp;
int ch = getescapechar(s);
if (ch >= 0)
return conv_entity(ch);
if (*save != '&')
tmp = Strnew_charp("&");
else
tmp = Strnew();
Strcat_charp_n(tmp, save, *s - save);
return tmp->ptr;
}
char *
html_quote(char *str)
{
Str tmp = NULL;
char *p, *q;
for (p = str; *p; p++) {
q = html_quote_char(*p);
if (q) {
if (tmp == NULL)
tmp = Strnew_charp_n(str, (int)(p - str));
Strcat_charp(tmp, q);
}
else {
if (tmp)
Strcat_char(tmp, *p);
}
}
if (tmp)
return tmp->ptr;
return str;
}
char *
html_unquote(char *str)
{
Str tmp = NULL;
char *p, *q;
for (p = str; *p;) {
if (*p == '&') {
if (tmp == NULL)
tmp = Strnew_charp_n(str, (int)(p - str));
q = getescapecmd(&p);
Strcat_charp(tmp, q);
}
else {
if (tmp)
Strcat_char(tmp, *p);
p++;
}
}
if (tmp)
return tmp->ptr;
return str;
}
static char xdigit[0x10] = "0123456789ABCDEF";
#define url_unquote_char(pstr) \
((IS_XDIGIT((*(pstr))[1]) && IS_XDIGIT((*(pstr))[2])) ? \
(*(pstr) += 3, (GET_MYCDIGIT((*(pstr))[-2]) << 4) | GET_MYCDIGIT((*(pstr))[-1])) : \
-1)
char *
url_quote(char *str)
{
Str tmp = NULL;
char *p;
for (p = str; *p; p++) {
if (is_url_quote(*p)) {
if (tmp == NULL)
tmp = Strnew_charp_n(str, (int)(p - str));
Strcat_char(tmp, '%');
Strcat_char(tmp, xdigit[((unsigned char)*p >> 4) & 0xF]);
Strcat_char(tmp, xdigit[(unsigned char)*p & 0xF]);
}
else {
if (tmp)
Strcat_char(tmp, *p);
}
}
if (tmp)
return tmp->ptr;
return str;
}
char *
file_quote(char *str)
{
Str tmp = NULL;
char *p;
char buf[4];
for (p = str; *p; p++) {
if (is_file_quote(*p)) {
if (tmp == NULL)
tmp = Strnew_charp_n(str, (int)(p - str));
sprintf(buf, "%%%02X", (unsigned char)*p);
Strcat_charp(tmp, buf);
}
else {
if (tmp)
Strcat_char(tmp, *p);
}
}
if (tmp)
return tmp->ptr;
return str;
}
char *
file_unquote(char *str)
{
Str tmp = NULL;
char *p, *q;
int c;
for (p = str; *p;) {
if (*p == '%') {
q = p;
c = url_unquote_char(&q);
if (c >= 0) {
if (tmp == NULL)
tmp = Strnew_charp_n(str, (int)(p - str));
if (c != '\0' && c != '\n' && c != '\r')
Strcat_char(tmp, (char)c);
p = q;
continue;
}
}
if (tmp)
Strcat_char(tmp, *p);
p++;
}
if (tmp)
return tmp->ptr;
return str;
}
Str
Str_form_quote(Str x)
{
Str tmp = NULL;
char *p = x->ptr, *ep = x->ptr + x->length;
char buf[4];
for (; p < ep; p++) {
if (*p == ' ') {
if (tmp == NULL)
tmp = Strnew_charp_n(x->ptr, (int)(p - x->ptr));
Strcat_char(tmp, '+');
}
else if (is_url_unsafe(*p)) {
if (tmp == NULL)
tmp = Strnew_charp_n(x->ptr, (int)(p - x->ptr));
sprintf(buf, "%%%02X", (unsigned char)*p);
Strcat_charp(tmp, buf);
}
else {
if (tmp)
Strcat_char(tmp, *p);
}
}
if (tmp)
return tmp;
return x;
}
Str
Str_url_unquote(Str x, int is_form, int safe)
{
Str tmp = NULL;
char *p = x->ptr, *ep = x->ptr + x->length, *q;
int c;
for (; p < ep;) {
if (is_form && *p == '+') {
if (tmp == NULL)
tmp = Strnew_charp_n(x->ptr, (int)(p - x->ptr));
Strcat_char(tmp, ' ');
p++;
continue;
}
else if (*p == '%') {
q = p;
c = url_unquote_char(&q);
if (c >= 0 && (!safe || !IS_ASCII(c) || !is_file_quote(c))) {
if (tmp == NULL)
tmp = Strnew_charp_n(x->ptr, (int)(p - x->ptr));
Strcat_char(tmp, (char)c);
p = q;
continue;
}
}
if (tmp)
Strcat_char(tmp, *p);
p++;
}
if (tmp)
return tmp;
return x;
}
char *
shell_quote(char *str)
{
Str tmp = NULL;
char *p;
for (p = str; *p; p++) {
if (is_shell_unsafe(*p)) {
if (tmp == NULL)
tmp = Strnew_charp_n(str, (int)(p - str));
Strcat_char(tmp, '\\');
Strcat_char(tmp, *p);
}
else {
if (tmp)
Strcat_char(tmp, *p);
}
}
if (tmp)
return tmp->ptr;
return str;
}
void *
xrealloc(void *ptr, size_t size)
{
void *newptr = realloc(ptr, size);
if (newptr == NULL) {
fprintf(stderr, "Out of memory\n");
exit(-1);
}
return newptr;
}
/* Define this as a separate function in case the free() has
* an incompatible prototype. */
void
xfree(void *ptr)
{
free(ptr);
}
void *
w3m_GC_realloc_atomic(void *ptr, size_t size)
{
return ptr ? GC_REALLOC(ptr, size) : GC_MALLOC_ATOMIC(size);
}
void
w3m_GC_free(void *ptr)
{
GC_FREE(ptr);
}
void
growbuf_init(struct growbuf *gb)
{
gb->ptr = NULL;
gb->length = 0;
gb->area_size = 0;
gb->realloc_proc = &w3m_GC_realloc_atomic;
gb->free_proc = &w3m_GC_free;
}
void
growbuf_init_without_GC(struct growbuf *gb)
{
gb->ptr = NULL;
gb->length = 0;
gb->area_size = 0;
gb->realloc_proc = &xrealloc;
gb->free_proc = &xfree;
}
void
growbuf_clear(struct growbuf *gb)
{
(*gb->free_proc) (gb->ptr);
gb->ptr = NULL;
gb->length = 0;
gb->area_size = 0;
}
Str
growbuf_to_Str(struct growbuf *gb)
{
Str s;
if (gb->free_proc == &w3m_GC_free) {
growbuf_reserve(gb, gb->length + 1);
gb->ptr[gb->length] = '\0';
s = New(struct _Str);
s->ptr = gb->ptr;
s->length = gb->length;
s->area_size = gb->area_size;
} else {
s = Strnew_charp_n(gb->ptr, gb->length);
(*gb->free_proc) (gb->ptr);
}
gb->ptr = NULL;
gb->length = 0;
gb->area_size = 0;
return s;
}
void
growbuf_reserve(struct growbuf *gb, int leastarea)
{
int newarea;
if (gb->area_size < leastarea) {
newarea = gb->area_size * 3 / 2;
if (newarea < leastarea)
newarea = leastarea;
newarea += 16;
gb->ptr = (*gb->realloc_proc) (gb->ptr, newarea);
gb->area_size = newarea;
}
}
void
growbuf_append(struct growbuf *gb, const unsigned char *src, int len)
{
growbuf_reserve(gb, gb->length + len);
memcpy(&gb->ptr[gb->length], src, len);
gb->length += len;
}
static char *
w3m_dir(const char *name, char *dft)
{
#ifdef USE_PATH_ENVVAR
char *value = getenv(name);
return value ? value : dft;
#else
return dft;
#endif
}
char *
w3m_auxbin_dir(void)
{
return w3m_dir("W3M_AUXBIN_DIR", AUXBIN_DIR);
}
char *
w3m_lib_dir(void)
{
/* FIXME: use W3M_CGIBIN_DIR? */
return w3m_dir("W3M_LIB_DIR", CGIBIN_DIR);
}
char *
w3m_etc_dir(void)
{
return w3m_dir("W3M_ETC_DIR", ETC_DIR);
}
char *
w3m_conf_dir(void)
{
return w3m_dir("W3M_CONF_DIR", CONF_DIR);
}
char *
w3m_help_dir(void)
{
return w3m_dir("W3M_HELP_DIR", HELP_DIR);
}
/* Local Variables: */
/* c-basic-offset: 4 */
/* tab-width: 8 */
/* End: */
|