#include "mbconfig.h"
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include "parsinc.h"
#include "filename.h"
Go to the source code of this file.
static char* expand_environment |
( |
const char * |
in | ) |
|
|
static |
Definition at line 436 of file parsinc.cc.
References buf, c, DEBUGCOUT, MAXSUBST, and SAFENEWARR.
Referenced by resolve_filename().
448 DEBUGCOUT(
">> expand_environment: " << in << std::endl);
450 subst[cnt].start = 0;
452 subst[cnt].value = NULL;
453 subst[cnt].length = 0;
454 for (
c = 0; in[
c];
c++) {
457 silent_cerr(
"too many substitutions in \""
458 << in <<
"\"" << std::endl);
463 if (in[
c + 1] ==
'$') {
465 subst[cnt].start =
c;
466 subst[cnt].value =
"";
467 subst[cnt].length = 0;
472 unsigned namepos =
c;
474 const char *end = std::strchr(&in[
c],
'}');
477 silent_cerr(
"missing trailing \"}\" "
478 "in \"" << in <<
"\""
484 unsigned l = end - &in[namepos];
486 memcpy(buf, &in[namepos], l);
488 subst[cnt].value = getenv(buf);
489 if (subst[cnt].value == NULL) {
490 silent_cerr(
"unable to find "
498 c = end - &in[0] + 1;
501 if (in[
c] !=
'_' && !isalpha(in[
c])) {
502 silent_cerr(
"illegal leading char "
504 "variable name in \""
510 for (c++; in[
c]; c++) {
511 if (in[c] !=
'_' && !isalnum(in[c])) {
516 unsigned l = &in[
c] - &in[namepos];
518 memcpy(buf, &in[namepos], l);
521 subst[cnt].value = getenv(buf);
522 if (subst[cnt].value == NULL) {
523 silent_cerr(
"unable to find "
533 subst[cnt].length = strlen(subst[cnt].value);
536 subst[cnt].start =
c;
543 subst[cnt].value = NULL;
544 subst[cnt].length = 0;
547 for (c = 0; c < cnt; c++) {
548 len += (subst[
c].end - subst[
c].start) + subst[c].length;
550 len += subst[
c].end - subst[
c].start;
555 for (c = 0; c < cnt; c++) {
556 unsigned l = subst[
c].end - subst[
c].start;
558 memcpy(&out[p], &in[subst[c].start], l);
561 if (subst[c].length > 0) {
562 memcpy(&out[p], subst[c].value, subst[c].length);
563 p += subst[
c].length;
566 unsigned l = subst[
c].end - subst[
c].start;
568 memcpy(&out[p], &in[subst[c].start], l);
573 DEBUGCOUT(
"<< expand_environment: " << out << std::endl);
static std::stack< cleanup * > c
#define SAFENEWARR(pnt, item, sz)
static doublereal buf[BUFSIZE]
static void InitDescData |
( |
void |
| ) |
|
|
static |
static char* resolve_filename |
( |
const char * |
filename_in | ) |
|
|
static |
Definition at line 579 of file parsinc.cc.
References buf, DIR_SEP, expand_environment(), filename, SAFEDELETEARR, SAFENEWARR, and SAFESTRDUP.
Referenced by IncludeParser::GetFileName().
584 if (strchr(filename_in,
'$')) {
586 if (filename == NULL) {
590 filename = (
char *)filename_in;
593 if (filename[0] ==
'~') {
599 home = getenv(
"HOME");
608 ll = l + strlen(filename) + 1;
612 strcpy(s + l, filename);
617 #if defined(HAVE_PWD_H)
621 p = std::strchr(filename,
DIR_SEP);
629 memcpy(buf, filename, l);
641 l = strlen(pw->pw_dir);
642 int ll = l + strlen(p) + 1;
645 strncpy(s, pw->pw_dir, l);
655 if (filename != NULL) {
657 if (filename != filename_in) {
663 if (filename != filename_in) {
#define SAFEDELETEARR(pnt)
static char * expand_environment(const char *in)
#define SAFESTRDUP(pnt, src)
#define SAFENEWARR(pnt, item, sz)
static doublereal buf[BUFSIZE]