MCPcopy Create free account
hub / github.com/audeering/opensmile / openInput

Method openInput

src/core/configManager.cpp:1747–2125  ·  view source on GitHub ↗

TODO: cache config files which have already been loaded once (including all includes?) each instance has a header: [instname:type] followed by the lines with values */ including other config files can be done via the command: \{path/and/file_to.include} */

Source from the content-addressed store, hash-verified

1745/* each instance has a header: [instname:type] followed by the lines with values */
1746/* including other config files can be done via the command: \{path/and/file_to.include} */
1747int cFileConfigReader::openInput(const char*fname, int *idx0)
1748{
1749 FILE *in = NULL;
1750 char *localThisLevelFile = NULL;
1751 /*
1752 * check if config file already has been cached...
1753 */
1754 // 1. construct filename variants
1755 #define NFILENAMES 3
1756 char *filenames[NFILENAMES] = {NULL, NULL, NULL};
1757 int nFilenames = 3;
1758 // path relative to working directory or absolute
1759 if (fname == NULL) {
1760 filenames[0] = addAudExtensionIfNeeded(inputPath);
1761 nFilenames = 1;
1762 if (lastLevelFile != NULL)
1763 free(lastLevelFile);
1764 lastLevelFile = NULL;
1765 } else {
1766 filenames[0] = addAudExtensionIfNeeded(fname);
1767 }
1768 // try relative to inputPath next
1769 char * fname2 = strdup(inputPath);
1770 char * pt = strrchr(fname2, '/');
1771 if (pt == NULL)
1772 pt = strrchr(fname2, '\\');
1773 if ((pt != NULL) && (pt != fname)) {
1774 *pt = 0;
1775 }
1776 char * fullfilename = myvprint("%s/%s", fname2, fname);
1777 filenames[1] = addAudExtensionIfNeeded(fullfilename);
1778 free(fname2);
1779 free(fullfilename);
1780 // try relative to path of previously included file (if not same as inputPath)
1781 if (lastLevelFile != NULL && lastLevelFile != inputPath) {
1782 char * fname2b = strdup(lastLevelFile);
1783 char * ptb = strrchr(fname2b, '/');
1784 if (ptb == NULL) ptb = strrchr(fname2b, '\\');
1785 if ((ptb != NULL)&&(ptb != fname)) {
1786 *ptb = 0;
1787 }
1788 char * fullfilename2 = myvprint("%s/%s", fname2b, fname);
1789 filenames[2] = addAudExtensionIfNeeded(fullfilename2);
1790 free(fname2b);
1791 free(fullfilename2);
1792 }
1793
1794 // 2. try to find one of them in cache
1795 char *fbuffer = NULL;
1796 int fbufferSize = 0;
1797 const char *configFilename = NULL;
1798 for (int i = 0; i < nFilenames; i++) {
1799 if (filenames[i] != NULL) {
1800 fbuffer = getConfigFileBufferFromCache(filenames[i], &fbufferSize);
1801 if (fbuffer != NULL) {
1802 SMILE_MSG(3, "found config file '%s' in cache.", filenames[i]);
1803 configFilename = filenames[i];
1804 break;

Callers

nothing calls this directly

Calls 6

smile_getline_frombufferFunction · 0.85
optionExistsMethod · 0.80
addStrMethod · 0.80
myvprintFunction · 0.70
parseMethod · 0.45
getStrMethod · 0.45

Tested by

no test coverage detected