Panda3D
configPageManager.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file configPageManager.cxx
10  * @author drose
11  * @date 2004-10-15
12  */
13 
14 #include "configPageManager.h"
15 #include "configDeclaration.h"
16 #include "configVariableBool.h"
17 #include "configVariableString.h"
18 #include "configPage.h"
19 #include "prcKeyRegistry.h"
20 #include "dSearchPath.h"
21 #include "executionEnvironment.h"
22 #include "config_prc.h"
23 #include "pfstream.h"
24 #include "pandaSystem.h"
25 #include "textEncoder.h"
26 #include "stringDecoder.h"
27 
28 // This file is generated by ppremake.
29 #include "prc_parameters.h"
30 
31 #include <set>
32 
33 // Pick up the public key definitions.
34 #ifdef PRC_PUBLIC_KEYS_INCLUDE
35 #include PRC_PUBLIC_KEYS_INCLUDE
36 #endif
37 
38 #include <algorithm>
39 #include <ctype.h>
40 
41 #ifndef _MSC_VER
42 #include <dlfcn.h>
43 #endif
44 
45 using std::string;
46 
47 ConfigPageManager *ConfigPageManager::_global_ptr = nullptr;
48 
49 /**
50  * The constructor is private (actually, just protected, but only to avoid a
51  * gcc compiler warning) because it should not be explicitly constructed.
52  * There is only one ConfigPageManager, and it constructs itself.
53  */
54 ConfigPageManager::
55 ConfigPageManager() {
56  _next_page_seq = 1;
57  _loaded_implicit = false;
58  _currently_loading = false;
59  _pages_sorted = true;
60 
61 #ifdef PRC_PUBLIC_KEYS_INCLUDE
62  // Record the public keys in the registry at startup time.
63  PrcKeyRegistry::get_global_ptr()->record_keys(prc_pubkeys, num_prc_pubkeys);
64 #endif // PRC_PUBLIC_KEYS_INCLUDE
65 }
66 
67 /**
68  * The ConfigPageManager destructor should never be called, because this is a
69  * global object that is never freed.
70  */
71 ConfigPageManager::
72 ~ConfigPageManager() {
73  prc_cat->error()
74  << "Internal error--ConfigPageManager destructor called!\n";
75 }
76 
77 /**
78  * Searches the PRC_DIR and/or PRC_PATH directories for *.prc files and loads
79  * them in as pages.
80  *
81  * This may be called after startup, to force the system to re-read all of the
82  * implicit prc files.
83  */
86  if (_currently_loading) {
87  // This is a recursion protector. We can get recursion feedback between
88  // config and notify, as each tries to use the other at construction.
89  return;
90  }
91  _currently_loading = true;
92 
93  // First, remove all the previously-loaded pages.
94  Pages::iterator pi;
95  for (pi = _implicit_pages.begin(); pi != _implicit_pages.end(); ++pi) {
96  delete (*pi);
97  }
98  _implicit_pages.clear();
99 
100  // If we are running inside a deployed application, see if it exposes
101  // information about how the PRC data should be initialized.
102  struct BlobInfo {
103  uint64_t blob_offset;
104  uint64_t blob_size;
105  uint16_t version;
106  uint16_t num_pointers;
107  uint16_t codepage;
108  uint16_t flags;
109  uint64_t reserved;
110  const void *module_table;
111  const char *prc_data;
112  const char *default_prc_dir;
113  const char *prc_dir_envvars;
114  const char *prc_path_envvars;
115  const char *prc_patterns;
116  const char *prc_encrypted_patterns;
117  const char *prc_encryption_key;
118  const char *prc_executable_patterns;
119  const char *prc_executable_args_envvar;
120  const char *main_dir;
121  const char *log_filename;
122  };
123 #ifdef _MSC_VER
124  const BlobInfo *blobinfo = (const BlobInfo *)GetProcAddress(GetModuleHandle(NULL), "blobinfo");
125 #elif defined(RTLD_MAIN_ONLY)
126  const BlobInfo *blobinfo = (const BlobInfo *)dlsym(RTLD_MAIN_ONLY, "blobinfo");
127 //#elif defined(RTLD_SELF)
128 // const BlobInfo *blobinfo = (const BlobInfo *)dlsym(RTLD_SELF, "blobinfo");
129 #else
130  const BlobInfo *blobinfo = (const BlobInfo *)dlsym(dlopen(NULL, RTLD_NOW), "blobinfo");
131 #endif
132  if (blobinfo != nullptr && (blobinfo->version == 0 || blobinfo->num_pointers < 10)) {
133  blobinfo = nullptr;
134  }
135 
136  if (blobinfo != nullptr) {
137  if (blobinfo->num_pointers >= 11 && blobinfo->main_dir != nullptr) {
138  ExecutionEnvironment::set_environment_variable("MAIN_DIR", blobinfo->main_dir);
139  } else {
140  // Make sure that py_panda.cxx won't override MAIN_DIR.
143  }
144  }
145 
146  // PRC_PATTERNS lists one or more filename templates separated by spaces.
147  // Pull them out and store them in _prc_patterns.
148  _prc_patterns.clear();
149 
150  string prc_patterns = PRC_PATTERNS;
151  if (blobinfo != nullptr && blobinfo->prc_patterns != nullptr) {
152  prc_patterns = blobinfo->prc_patterns;
153  }
154  if (!prc_patterns.empty()) {
155  vector_string pat_list;
156  ConfigDeclaration::extract_words(prc_patterns, pat_list);
157  _prc_patterns.reserve(pat_list.size());
158  for (size_t i = 0; i < pat_list.size(); ++i) {
159  GlobPattern glob(pat_list[i]);
160 #ifdef WIN32
161  // On windows, the file system is case-insensitive, so the pattern
162  // should be too.
163  glob.set_case_sensitive(false);
164 #endif // WIN32
165  _prc_patterns.push_back(glob);
166  }
167  }
168 
169  // Similarly for PRC_ENCRYPTED_PATTERNS.
170  _prc_encrypted_patterns.clear();
171 
172  string prc_encrypted_patterns = PRC_ENCRYPTED_PATTERNS;
173  if (blobinfo != nullptr && blobinfo->prc_encrypted_patterns != nullptr) {
174  prc_encrypted_patterns = blobinfo->prc_encrypted_patterns;
175  }
176  if (!prc_encrypted_patterns.empty()) {
177  vector_string pat_list;
178  ConfigDeclaration::extract_words(prc_encrypted_patterns, pat_list);
179  _prc_encrypted_patterns.reserve(pat_list.size());
180  for (size_t i = 0; i < pat_list.size(); ++i) {
181  GlobPattern glob(pat_list[i]);
182 #ifdef WIN32
183  glob.set_case_sensitive(false);
184 #endif // WIN32
185  _prc_encrypted_patterns.push_back(glob);
186  }
187  }
188 
189  // And again for PRC_EXECUTABLE_PATTERNS.
190  _prc_executable_patterns.clear();
191 
192  string prc_executable_patterns = PRC_EXECUTABLE_PATTERNS;
193  if (blobinfo != nullptr && blobinfo->prc_executable_patterns != nullptr) {
194  prc_executable_patterns = blobinfo->prc_executable_patterns;
195  }
196  if (!prc_executable_patterns.empty()) {
197  vector_string pat_list;
198  ConfigDeclaration::extract_words(prc_executable_patterns, pat_list);
199  _prc_executable_patterns.reserve(pat_list.size());
200  for (size_t i = 0; i < pat_list.size(); ++i) {
201  GlobPattern glob(pat_list[i]);
202 #ifdef WIN32
203  glob.set_case_sensitive(false);
204 #endif // WIN32
205  _prc_executable_patterns.push_back(glob);
206  }
207  }
208 
209  // Now build up the search path for .prc files.
210  _search_path.clear();
211 
212  // PRC_DIR_ENVVARS lists one or more environment variables separated by
213  // spaces. Pull them out, and each of those contains the name of a single
214  // directory to search. Add it to the search path.
215  string prc_dir_envvars = PRC_DIR_ENVVARS;
216  if (blobinfo != nullptr && blobinfo->prc_dir_envvars != nullptr) {
217  prc_dir_envvars = blobinfo->prc_dir_envvars;
218  }
219  if (!prc_dir_envvars.empty()) {
220  vector_string prc_dir_envvar_list;
221  ConfigDeclaration::extract_words(prc_dir_envvars, prc_dir_envvar_list);
222  for (size_t i = 0; i < prc_dir_envvar_list.size(); ++i) {
223  string prc_dir = ExecutionEnvironment::get_environment_variable(prc_dir_envvar_list[i]);
224  if (!prc_dir.empty()) {
225  Filename prc_dir_filename = Filename::from_os_specific(prc_dir);
226  prc_dir_filename.make_true_case();
227  if (scan_auto_prc_dir(prc_dir_filename)) {
228  _search_path.append_directory(prc_dir_filename);
229  }
230  }
231  }
232  }
233 
234  // PRC_PATH_ENVVARS lists one or more environment variables separated by
235  // spaces. Pull them out, and then each one of those contains a list of
236  // directories to search. Add each of those to the search path.
237  string prc_path_envvars = PRC_PATH_ENVVARS;
238  if (blobinfo != nullptr && blobinfo->prc_path_envvars != nullptr) {
239  prc_path_envvars = blobinfo->prc_path_envvars;
240  }
241  if (!prc_path_envvars.empty()) {
242  vector_string prc_path_envvar_list;
243  ConfigDeclaration::extract_words(prc_path_envvars, prc_path_envvar_list);
244  for (size_t i = 0; i < prc_path_envvar_list.size(); ++i) {
245  string path = ExecutionEnvironment::get_environment_variable(prc_path_envvar_list[i]);
246  size_t p = 0;
247  while (p < path.length()) {
248  size_t q = path.find_first_of(DEFAULT_PATHSEP, p);
249  if (q == string::npos) {
250  q = path.length();
251  }
252  Filename prc_dir_filename = Filename::from_os_specific(path.substr(p, q - p));
253  prc_dir_filename.make_true_case();
254  if (scan_auto_prc_dir(prc_dir_filename)) {
255  _search_path.append_directory(prc_dir_filename);
256  }
257  p = q + 1;
258  }
259  }
260  }
261 
262 /*
263  * PRC_PATH2_ENVVARS is a special variable that is rarely used; it exists
264  * primarily to support the Cygwin-based "ctattach" tools used by the Walt
265  * Disney VR Studio. This defines a set of environment variable(s) that
266  * define a search path, as above; except that the directory names on these
267  * search paths are Panda-style filenames, not Windows-style filenames; and
268  * the path separator is always a space character, regardless of
269  * DEFAULT_PATHSEP.
270  */
271  string prc_path2_envvars = PRC_PATH2_ENVVARS;
272  if (!prc_path2_envvars.empty() && blobinfo == nullptr) {
273  vector_string prc_path_envvar_list;
274  ConfigDeclaration::extract_words(prc_path2_envvars, prc_path_envvar_list);
275  for (size_t i = 0; i < prc_path_envvar_list.size(); ++i) {
276  string path = ExecutionEnvironment::get_environment_variable(prc_path_envvar_list[i]);
277  size_t p = 0;
278  while (p < path.length()) {
279  size_t q = path.find_first_of(' ', p);
280  if (q == string::npos) {
281  q = path.length();
282  }
283  Filename prc_dir_filename = path.substr(p, q - p);
284  if (scan_auto_prc_dir(prc_dir_filename)) {
285  _search_path.append_directory(prc_dir_filename);
286  }
287  p = q + 1;
288  }
289  }
290  }
291 
292  if (_search_path.is_empty()) {
293  // If nothing's on the search path (PRC_DIR and PRC_PATH were not
294  // defined), then use the DEFAULT_PRC_DIR.
295  string default_prc_dir = DEFAULT_PRC_DIR;
296  if (blobinfo != nullptr && blobinfo->default_prc_dir != nullptr) {
297  default_prc_dir = blobinfo->default_prc_dir;
298  }
299  if (!default_prc_dir.empty()) {
300  // It's already from-os-specific by ppremake.
301  Filename prc_dir_filename = default_prc_dir;
302  if (scan_auto_prc_dir(prc_dir_filename)) {
303  _search_path.append_directory(prc_dir_filename);
304  }
305  }
306  }
307 
308  // Now find all of the *.prc files (or whatever matches PRC_PATTERNS) on the
309  // path.
310  ConfigFiles config_files;
311 
312  // Use a set to ensure that we only visit each directory once, even if it
313  // appears multiple times (under different aliases!) in the path.
314  std::set<Filename> unique_dirnames;
315 
316  // We walk through the list of directories in forward order, so that the
317  // most important directories are visited first.
318  for (size_t di = 0; di < _search_path.get_num_directories(); ++di) {
319  const Filename &directory = _search_path.get_directory(di);
320  if (directory.is_directory()) {
321  Filename canonical(directory, ".");
322  canonical.make_canonical();
323  if (unique_dirnames.insert(canonical).second) {
324  vector_string files;
325  directory.scan_directory(files);
326 
327  // We walk through the directory's list of files in reverse
328  // alphabetical order, because for historical reasons, the most
329  // important file within a directory is the alphabetically last file
330  // of that directory, and we still want to visit the most important
331  // files first.
332  vector_string::reverse_iterator fi;
333  for (fi = files.rbegin(); fi != files.rend(); ++fi) {
334  int file_flags = 0;
335  Globs::const_iterator gi;
336  for (gi = _prc_patterns.begin();
337  gi != _prc_patterns.end();
338  ++gi) {
339  if ((*gi).matches(*fi)) {
340  file_flags |= FF_read;
341  break;
342  }
343  }
344  for (gi = _prc_encrypted_patterns.begin();
345  gi != _prc_encrypted_patterns.end();
346  ++gi) {
347  if ((*gi).matches(*fi)) {
348  file_flags |= FF_read | FF_decrypt;
349  break;
350  }
351  }
352  for (gi = _prc_executable_patterns.begin();
353  gi != _prc_executable_patterns.end();
354  ++gi) {
355  if ((*gi).matches(*fi)) {
356  file_flags |= FF_execute;
357  break;
358  }
359  }
360  if (file_flags != 0) {
361  ConfigFile file;
362  file._file_flags = file_flags;
363  file._filename = Filename(directory, (*fi));
364  config_files.push_back(file);
365  }
366  }
367  }
368  }
369  }
370 
371  int i = 1;
372 
373  // If prc_data is predefined, we load it as an implicit page.
374  if (blobinfo != nullptr && blobinfo->prc_data != nullptr) {
375  ConfigPage *page = new ConfigPage("builtin", true, i);
376  ++i;
377  _implicit_pages.push_back(page);
378  _pages_sorted = false;
379 
380  std::istringstream in(blobinfo->prc_data);
381  page->read_prc(in);
382  }
383 
384  // Now we have a list of filenames in order from most important to least
385  // important. Walk through the list in reverse order to load their
386  // contents, because we want the first file in the list (the most important)
387  // to be on the top of the stack.
388  ConfigFiles::reverse_iterator ci;
389  for (ci = config_files.rbegin(); ci != config_files.rend(); ++ci) {
390  const ConfigFile &file = (*ci);
391  Filename filename = file._filename;
392 
393  if ((file._file_flags & FF_execute) != 0 &&
394  filename.is_executable()) {
395  // Attempt to execute the file as a command.
396  string command = filename.to_os_specific();
397 
398  string envvar = PRC_EXECUTABLE_ARGS_ENVVAR;
399  if (blobinfo != nullptr && blobinfo->prc_executable_args_envvar != nullptr) {
400  envvar = blobinfo->prc_executable_args_envvar;
401  }
402  if (!envvar.empty()) {
404  if (!args.empty()) {
405  command += " ";
406  command += args;
407  }
408  }
409  IPipeStream ifs(command);
410 
411  ConfigPage *page = new ConfigPage(filename, true, i);
412  ++i;
413  _implicit_pages.push_back(page);
414  _pages_sorted = false;
415 
416  page->read_prc(ifs);
417 
418  } else if ((file._file_flags & FF_decrypt) != 0) {
419  // Read and decrypt the file.
420  filename.set_binary();
421 
422  pifstream in;
423  if (!filename.open_read(in)) {
424  prc_cat.error()
425  << "Unable to read " << filename << "\n";
426  } else {
427  ConfigPage *page = new ConfigPage(filename, true, i);
428  ++i;
429  _implicit_pages.push_back(page);
430  _pages_sorted = false;
431 
432  if (blobinfo != nullptr && blobinfo->prc_encryption_key != nullptr) {
433  page->read_encrypted_prc(in, blobinfo->prc_encryption_key);
434  } else {
435  page->read_encrypted_prc(in, PRC_ENCRYPTION_KEY);
436  }
437  }
438 
439  } else if ((file._file_flags & FF_read) != 0) {
440  // Just read the file.
441  filename.set_text();
442 
443  pifstream in;
444  if (!filename.open_read(in)) {
445  prc_cat.error()
446  << "Unable to read " << filename << "\n";
447  } else {
448  ConfigPage *page = new ConfigPage(filename, true, i);
449  ++i;
450  _implicit_pages.push_back(page);
451  _pages_sorted = false;
452 
453  page->read_prc(in);
454  }
455  }
456  }
457 
458  if (!_loaded_implicit) {
459  config_initialized();
460  _loaded_implicit = true;
461  }
462 
463  _currently_loading = false;
464  invalidate_cache();
465 
466 #ifdef USE_PANDAFILESTREAM
467  // Update this very low-level config variable here, for lack of any better
468  // place.
470  ("newline-mode", PandaFileStreamBuf::NM_native,
471  PRC_DESC("Controls how newlines are written by Panda applications writing "
472  "to a text file. The default, \"native\", means to write newlines "
473  "appropriate to the current platform. You may also specify \"binary\", "
474  "to avoid molesting the file data, or one of \"msdos\", \"unix\", "
475  "or \"mac\"."));
476  PandaFileStreamBuf::_newline_mode = newline_mode;
477 #endif // USE_PANDAFILESTREAM
478 
479 #ifdef WIN32
480  // We don't necessarily want an error dialog when we fail to load a .dll
481  // file. But sometimes it is useful for debugging.
482  ConfigVariableBool show_dll_error_dialog
483  ("show-dll-error-dialog", false,
484  PRC_DESC("Set this true to enable the Windows system dialog that pops "
485  "up when a DLL fails to load, or false to disable it. It is "
486  "normally false, but it may be useful to set it true to debug "
487  "why a DLL is not loading. (Note that this actually disables "
488  "*all* critical error messages, and that it's a global setting "
489  "that some other libraries might un-set.)"));
490  if (show_dll_error_dialog) {
491  SetErrorMode(0);
492  } else {
493  SetErrorMode(SEM_FAILCRITICALERRORS);
494  }
495 #endif
496 
497 }
498 
499 /**
500  * Creates and returns a new, empty ConfigPage. This page will be stacked on
501  * top of any pages that were created before; it may shadow variable
502  * declarations that are defined in previous pages.
503  */
505 make_explicit_page(const string &name) {
506  ConfigPage *page = new ConfigPage(name, false, _next_page_seq);
507  ++_next_page_seq;
508  _explicit_pages.push_back(page);
509  _pages_sorted = false;
510  invalidate_cache();
511  return page;
512 }
513 
514 /**
515  * Removes a previously-constructed ConfigPage from the set of active pages,
516  * and deletes it. The ConfigPage object is no longer valid after this call.
517  * Returns true if the page is successfully deleted, or false if it was
518  * unknown (which should never happen if the page was legitimately
519  * constructed).
520  */
523  Pages::iterator pi;
524  for (pi = _explicit_pages.begin(); pi != _explicit_pages.end(); ++pi) {
525  if ((*pi) == page) {
526  _explicit_pages.erase(pi);
527  delete page;
528  invalidate_cache();
529  return true;
530  }
531  }
532  return false;
533 }
534 
535 /**
536  *
537  */
538 void ConfigPageManager::
539 output(std::ostream &out) const {
540  out << "ConfigPageManager, "
541  << _explicit_pages.size() + _implicit_pages.size()
542  << " pages.";
543 }
544 
545 /**
546  *
547  */
548 void ConfigPageManager::
549 write(std::ostream &out) const {
550  check_sort_pages();
551  out << _explicit_pages.size() << " explicit pages:\n";
552 
553  Pages::const_iterator pi;
554  for (pi = _explicit_pages.begin(); pi != _explicit_pages.end(); ++pi) {
555  const ConfigPage *page = (*pi);
556  out << " " << page->get_name();
557  if (page->get_trust_level() > 0) {
558  out << " (signed " << page->get_trust_level() << ": ";
559  page->output_brief_signature(out);
560  out << ")\n";
561  } else if (!page->get_signature().empty()) {
562  out << " (invalid signature: ";
563  page->output_brief_signature(out);
564  out << ")\n";
565  } else {
566  out << "\n";
567  }
568  }
569 
570  out << "\n" << _implicit_pages.size() << " implicit pages:\n";
571  for (pi = _implicit_pages.begin(); pi != _implicit_pages.end(); ++pi) {
572  const ConfigPage *page = (*pi);
573  out << " " << page->get_name();
574  if (page->get_trust_level() > 0) {
575  out << " (signed " << page->get_trust_level() << ": ";
576  page->output_brief_signature(out);
577  out << ")\n";
578  } else if (!page->get_signature().empty()) {
579  out << " (invalid signature: ";
580  page->output_brief_signature(out);
581  out << ")\n";
582  } else {
583  out << "\n";
584  }
585  }
586 }
587 
588 /**
589  *
590  */
591 ConfigPageManager *ConfigPageManager::
592 get_global_ptr() {
593  if (_global_ptr == nullptr) {
594  _global_ptr = new ConfigPageManager;
595  }
596  return _global_ptr;
597 }
598 
599 // This class is used in sort_pages, below.
601 public:
602  bool operator () (const ConfigPage *a, const ConfigPage *b) const {
603  return (*a) < (*b);
604  }
605 };
606 
607 /**
608  * Sorts the list of pages into priority order, so that the page at the front
609  * of the list is the one that shadows all following pages.
610  */
611 void ConfigPageManager::
612 sort_pages() {
613  sort(_implicit_pages.begin(), _implicit_pages.end(), CompareConfigPages());
614  sort(_explicit_pages.begin(), _explicit_pages.end(), CompareConfigPages());
615 
616  _pages_sorted = true;
617 }
618 
619 /**
620  * Checks for the prefix "<auto>" in the value of the $PRC_DIR environment
621  * variable (or in the compiled-in DEFAULT_PRC_DIR value). If it is found,
622  * then the actual directory is determined by searching upward from the
623  * executable's starting directory, or from the current working directory,
624  * until at least one .prc file is found.
625  *
626  * Returns true if the prc_dir has been filled with a valid directory name,
627  * false if no good directory name was found.
628  */
629 bool ConfigPageManager::
630 scan_auto_prc_dir(Filename &prc_dir) const {
631  string prc_dir_string = prc_dir;
632  if (prc_dir_string.substr(0, 6) == "<auto>") {
633  Filename suffix = prc_dir_string.substr(6);
634 
635  // Start at the dtool directory.
637  Filename dir = dtool.get_dirname();
638 
639  if (scan_up_from(prc_dir, dir, suffix)) {
640  return true;
641  }
642 
643  // Try the program's directory.
645  if (scan_up_from(prc_dir, dir, suffix)) {
646  return true;
647  }
648 
649  // Didn't find it; too bad.
650  std::cerr << "Warning: unable to auto-locate config files in directory named by \""
651  << prc_dir << "\".\n";
652  return false;
653  }
654 
655  // The filename did not begin with "<auto>", so it stands unchanged.
656  return true;
657 }
658 
659 /**
660  * Used to implement scan_auto_prc_dir(), above, this scans upward from the
661  * indicated directory name until a directory is found that includes at least
662  * one .prc file, or the root directory is reached.
663  *
664  * If a match is found, puts it result and returns true; otherwise, returns
665  * false.
666  */
667 bool ConfigPageManager::
668 scan_up_from(Filename &result, const Filename &dir,
669  const Filename &suffix) const {
670  Filename consider(dir, suffix);
671 
672  vector_string files;
673  if (consider.is_directory()) {
674  if (consider.scan_directory(files)) {
675  vector_string::const_iterator fi;
676  for (fi = files.begin(); fi != files.end(); ++fi) {
677  Globs::const_iterator gi;
678  for (gi = _prc_patterns.begin();
679  gi != _prc_patterns.end();
680  ++gi) {
681  if ((*gi).matches(*fi)) {
682  result = consider;
683  return true;
684  }
685  }
686 
687  for (gi = _prc_executable_patterns.begin();
688  gi != _prc_executable_patterns.end();
689  ++gi) {
690  if ((*gi).matches(*fi)) {
691  result = consider;
692  return true;
693  }
694  }
695  }
696  }
697  }
698 
699  Filename parent = dir.get_dirname();
700 
701  if (dir == parent) {
702  // Too bad; couldn't find a match.
703  return false;
704  }
705 
706  // Recursively try again on the parent.
707  return scan_up_from(result, parent, suffix);
708 }
709 
710 /**
711  * This is called once, at startup, the first time that the config system has
712  * been initialized and is ready to read config variables. It's intended to
713  * be a place to initialize values that are defined at a lower level than the
714  * config system itself.
715  */
716 void ConfigPageManager::
717 config_initialized() {
719 
720 #ifndef NDEBUG
721  ConfigVariableString panda_package_version
722  ("panda-package-version", "local_dev",
723  PRC_DESC("This can be used to specify the value returned by "
724  "PandaSystem::get_package_version_str(), in development mode only, "
725  "and only if another value has not already been compiled in. This "
726  "is intended for developer convenience, to masquerade a development "
727  "build of Panda as a different runtime version. Use with caution."));
728  ConfigVariableString panda_package_host_url
729  ("panda-package-host-url", "",
730  PRC_DESC("This can be used to specify the value returned by "
731  "PandaSystem::get_package_host_url(), in development mode only, "
732  "and only if another value has not already been compiled in. This "
733  "is intended for developer convenience, to masquerade a development "
734  "build of Panda as a different runtime version. Use with caution."));
735 
737  panda_sys->set_package_version_string(panda_package_version);
738  panda_sys->set_package_host_url(panda_package_host_url);
739 #endif // NDEBUG
740 
741  // Also set up some other low-level things.
743  ("text-encoding", TextEncoder::E_utf8,
744  PRC_DESC("Specifies how international characters are represented in strings "
745  "of 8-byte characters presented to Panda. See TextEncoder::set_encoding()."));
746  TextEncoder::set_default_encoding(text_encoding);
747 
749  ("filesystem-encoding", TextEncoder::E_utf8,
750  PRC_DESC("Specifies the default encoding used for wide-character filenames."));
751  Filename::set_filesystem_encoding(filesystem_encoding);
752 
754 }
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
std::string get_dirname() const
Returns the directory part of the filename.
Definition: filename.I:358
get_name
Returns the name of the page.
Definition: configPage.h:43
static size_t extract_words(const std::string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
This class is used as a namespace to group several global properties of Panda.
Definition: pandaSystem.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_case_sensitive
Sets whether the match is case sensitive (true) or case insensitive (false).
Definition: globPattern.h:48
This is a convenience class to specialize ConfigVariable as a boolean type.
void clear()
Removes all the directories from the search list.
void set_binary()
Indicates that the filename represents a binary file.
Definition: filename.I:414
void set_text()
Indicates that the filename represents a text file.
Definition: filename.I:424
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
Definition: filename.cxx:1863
bool read_encrypted_prc(std::istream &in, const std::string &password)
Automatically decrypts and reads the stream, given the indicated password.
Definition: configPage.cxx:224
bool is_empty() const
Returns true if the search list is empty, false otherwise.
get_signature
Returns the raw binary signature that was found in the prc file, if any.
Definition: configPage.h:60
set_default_encoding
Specifies the default encoding to be used for all subsequently created TextEncoder objects...
Definition: textEncoder.h:54
bool make_canonical()
Converts this filename to a canonical name by replacing the directory part with the fully-qualified d...
Definition: filename.cxx:1011
bool make_true_case()
On a case-insensitive operating system (e.g.
Definition: filename.cxx:1053
get_dtool_name
Returns the name of the libdtool DLL that is used in this program, if it can be determined.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void append_directory(const Filename &directory)
Adds a new directory to the end of the search list.
static std::ostream & out()
A convenient way to get the ostream that should be written to for a Notify- type message.
Definition: notify.cxx:261
get_trust_level
Returns the trust level associated with this page.
Definition: configPage.h:59
bool read_prc(std::istream &in)
Reads the contents of a complete prc file, as returned by the indicated istream, into the current pag...
Definition: configPage.cxx:124
static Notify * ptr()
Returns the pointer to the global Notify object.
Definition: notify.cxx:289
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A global object that maintains the set of ConfigPages everywhere in the world, and keeps them in sort...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void set_filesystem_encoding(TextEncoder::Encoding encoding)
Specifies the default encoding to be used for all subsequent Filenames.
Definition: filename.I:630
get_num_directories
Returns the number of directories on the search list.
Definition: dSearchPath.h:76
bool is_executable() const
Returns true if the filename exists and is executable.
Definition: filename.cxx:1387
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
This is a convenience class to specialize ConfigVariable as a string type.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void reload_implicit_pages()
Searches the PRC_DIR and/or PRC_PATH directories for *.prc files and loads them in as pages...
ConfigPage * make_explicit_page(const std::string &name)
Creates and returns a new, empty ConfigPage.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class specializes ConfigVariable as an enumerated type.
A page of ConfigDeclarations that may be loaded or unloaded.
Definition: configPage.h:30
bool is_directory() const
Returns true if the filename exists and is a directory name, false otherwise.
Definition: filename.cxx:1359
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void config_initialized()
Intended to be called only by Config, this is a callback that indicates to Notify when Config has don...
Definition: notify.cxx:424
get_directory
Returns the nth directory on the search list.
Definition: dSearchPath.h:76
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool scan_directory(vector_string &contents) const
Attempts to open the named filename as if it were a directory and looks for the non-hidden files with...
Definition: filename.cxx:1718
static void set_notify_ptr(std::ostream *ptr)
Sets the ostream that is used to write error messages to.
set_environment_variable
Changes the definition of the indicated environment variable.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool delete_explicit_page(ConfigPage *page)
Removes a previously-constructed ConfigPage from the set of active pages, and deletes it...
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
Definition: filename.cxx:1123
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void output_brief_signature(std::ostream &out) const
Outputs the first few hex digits of the signature.
Definition: configPage.cxx:346
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).
Definition: filename.cxx:328
This class can be used to test for string matches against standard Unix- shell filename globbing conv...
Definition: globPattern.h:32
get_environment_variable
Returns the definition of the indicated environment variable, or the empty string if the variable is ...