void SC_LanguageClient::initRuntime(const Options& opt) { // start virtual machine if (!mHiddenClient->mRunning) { #ifdef __linux__ char deprecatedSupportDirectory[PATH_MAX]; sc_GetUserHomeDirectory(deprecatedSupportDirectory, PATH_MAX); sc_AppendToPath(deprecatedSupportDirectory, PATH_MAX, "share/SuperCollider"); if (sc_DirectoryExists(deprecatedSupportDirectory)) { char supportDirectory[PATH_MAX]; sc_GetUserAppSupportDirectory(supportDirectory, PATH_MAX); postfl("WARNING: Deprecated support directory detected: %s\n" "Extensions and other contents in this directory will not be available until you move them to the new support directory:\n" "%s\n" "Quarks will need to be reinstalled due to broken symbolic links.\n\n", deprecatedSupportDirectory, supportDirectory); } #endif mHiddenClient->mRunning = true; if (opt.mRuntimeDir) { int err = chdir(opt.mRuntimeDir); if (err) error("Cannot change to runtime directory: %s", strerror(errno)); } pyr_init_mem_pools(opt.mMemSpace, opt.mMemGrow); init_OSC(opt.mPort); schedInit(); onInitRuntime(); } }
GraphDef* GraphDef_LoadDir(World *inWorld, char *dirname, GraphDef *inList) { SC_DirHandle *dir = sc_OpenDir(dirname); if (!dir) { scprintf("*** ERROR: open directory failed '%s'\n", dirname); return inList; } for (;;) { char diritem[MAXPATHLEN]; bool skipItem = false; bool validItem = sc_ReadDir(dir, dirname, diritem, skipItem); if (!validItem) break; if (skipItem) continue; if (sc_DirectoryExists(diritem)) { inList = GraphDef_LoadDir(inWorld, diritem, inList); } else { int dnamelen = strlen(diritem); if (strncmp(diritem+dnamelen-9, ".scsyndef", 9) == 0) { inList = GraphDef_Load(inWorld, diritem, inList); } } } sc_CloseDir(dir); return inList; }
static bool passOne_ProcessDir(const char *dirname, int level) { if (!sc_DirectoryExists(dirname)) return true; if (compiledDirectories.find(std::string(dirname)) != compiledDirectories.end()) // already compiled return true; bool success = true; if (gLanguageConfig && gLanguageConfig->pathIsExcluded(dirname)) { post("\texcluding dir: '%s'\n", dirname); return success; } if (level == 0) post("\tcompiling dir: '%s'\n", dirname); SC_DirHandle *dir = sc_OpenDir(dirname); if (!dir) { error("open directory failed '%s'\n", dirname); fflush(stdout); return false; } for (;;) { char diritem[MAXPATHLEN]; bool skipItem = true; bool validItem = sc_ReadDir(dir, dirname, diritem, skipItem); if (!validItem) break; if (skipItem) continue; if (sc_DirectoryExists(diritem)) { success = passOne_ProcessDir(diritem, level + 1); } else { success = passOne_ProcessOneFile(diritem, level + 1); } if (!success) break; } compiledDirectories.insert(std::string(dirname)); sc_CloseDir(dir); return success; }
bool PlugIn_LoadDir(const char *dirname, bool reportError) { #ifndef NDEBUG scprintf("PlugIn_LoadDir(%s)\n", dirname); #endif bool success = true; SC_DirHandle *dir = sc_OpenDir(dirname); if (!dir) { if (reportError) { scprintf("*** ERROR: open directory failed '%s'\n", dirname); fflush(stdout); } return false; } int firstCharOffset = strlen(dirname)+1; for (;;) { char diritem[MAXPATHLEN]; bool skipItem = true; bool validItem = sc_ReadDir(dir, dirname, diritem, skipItem); if (!validItem) break; if (skipItem || (*(diritem+firstCharOffset) == '.')) continue; // skip files+folders whose first char is a dot if (sc_DirectoryExists(diritem)) { success = PlugIn_LoadDir(diritem, reportError); } else { int dnamelen = strlen(diritem); int extlen = strlen(SC_PLUGIN_EXT); char *extptr = diritem+dnamelen-extlen; if (strncmp(extptr, SC_PLUGIN_EXT, extlen) == 0) { success = PlugIn_Load(diritem); } } if (!success) continue; } sc_CloseDir(dir); return success; }
// sekhar's replacement bool passOne_ProcessOneFile(const char * filenamearg, int level) { bool success = true; bool isAlias = false; char filename[MAXPATHLEN]; int status = sc_ResolveIfAlias(filenamearg, filename, isAlias, MAXPATHLEN); if (status<0) { printf("WARNING: skipping invalid symbolic link: %s\n", filenamearg); return success; } if (gLanguageConfig && gLanguageConfig->pathIsExcluded(filename)) { post("\texcluding file: '%s'\n", filename); return success; } if (isValidSourceFileName(filename)) { gNumCompiledFiles++; PyrSymbol * fileSym = getsym(filename); fileSym->u.source = NULL; if (startLexer(fileSym, -1, -1, -1)) { while (parseOneClass(fileSym)) { }; finiLexer(); } else { error("file '%s' open failed\n", filename); success = false; } } else { if (sc_DirectoryExists(filename)) success = passOne_ProcessDir(filename, level); } return success; }
void initialize_library(const char *uGensPluginPath) { gCmdLib = new HashTable<SC_LibCmd, Malloc>(&gMalloc, 64, true); gUnitDefLib = new HashTable<UnitDef, Malloc>(&gMalloc, 512, true); gBufGenLib = new HashTable<BufGen, Malloc>(&gMalloc, 512, true); gPlugInCmds = new HashTable<PlugInCmd, Malloc>(&gMalloc, 64, true); initMiscCommands(); #ifdef STATIC_PLUGINS IO_Load(&gInterfaceTable); Osc_Load(&gInterfaceTable); Delay_Load(&gInterfaceTable); BinaryOp_Load(&gInterfaceTable); Filter_Load(&gInterfaceTable); Gendyn_Load(&gInterfaceTable); LF_Load(&gInterfaceTable); Noise_Load(&gInterfaceTable); MulAdd_Load(&gInterfaceTable); Grain_Load(&gInterfaceTable); Pan_Load(&gInterfaceTable); Reverb_Load(&gInterfaceTable); Trigger_Load(&gInterfaceTable); UnaryOp_Load(&gInterfaceTable); DiskIO_Load(&gInterfaceTable); PhysicalModeling_Load(&gInterfaceTable); Test_Load(&gInterfaceTable); Demand_Load(&gInterfaceTable); DynNoise_Load(&gInterfaceTable); #if defined(SC_IPHONE) && !TARGET_IPHONE_SIMULATOR iPhone_Load(&gInterfaceTable); #endif return; #endif // If uGensPluginPath is supplied, it is exclusive. bool loadUGensExtDirs = true; if(uGensPluginPath){ loadUGensExtDirs = false; SC_StringParser sp(uGensPluginPath, SC_STRPARSE_PATHDELIMITER); while (!sp.AtEnd()) { PlugIn_LoadDir(const_cast<char *>(sp.NextToken()), true); } } if(loadUGensExtDirs) { #ifdef SC_PLUGIN_DIR // load globally installed plugins if (sc_DirectoryExists(SC_PLUGIN_DIR)) { PlugIn_LoadDir(SC_PLUGIN_DIR, true); } #endif // load default plugin directory char pluginDir[MAXPATHLEN]; sc_GetResourceDirectory(pluginDir, MAXPATHLEN); sc_AppendToPath(pluginDir, SC_PLUGIN_DIR_NAME); if (sc_DirectoryExists(pluginDir)) { PlugIn_LoadDir(pluginDir, true); } } // get extension directories char extensionDir[MAXPATHLEN]; if (!sc_IsStandAlone() && loadUGensExtDirs) { // load system extension plugins sc_GetSystemExtensionDirectory(extensionDir, MAXPATHLEN); PlugIn_LoadDir(extensionDir, false); // load user extension plugins sc_GetUserExtensionDirectory(extensionDir, MAXPATHLEN); PlugIn_LoadDir(extensionDir, false); // load user plugin directories SC_StringParser sp(getenv("SC_PLUGIN_PATH"), SC_STRPARSE_PATHDELIMITER); while (!sp.AtEnd()) { PlugIn_LoadDir(const_cast<char *>(sp.NextToken()), true); } } #ifdef SC_DARWIN /* on darwin plugins are lazily loaded (dlopen uses mmap internally), which can produce audible glitches when UGens have to be paged-in. to work around this we preload all the plugins by iterating through their memory space. */ unsigned long images = _dyld_image_count(); for(unsigned long i = 0; i < images; i++) { const mach_header *hdr = _dyld_get_image_header(i); unsigned long slide = _dyld_get_image_vmaddr_slide(i); const char *name = _dyld_get_image_name(i); uint32_t size; char *sect; if(!strcmp(name + (strlen(name) - 4), ".scx")) { read_section(hdr, slide, "__TEXT", "__text"); read_section(hdr, slide, "__TEXT", "__const"); read_section(hdr, slide, "__TEXT", "__cstring"); read_section(hdr, slide, "__TEXT", "__picsymbol_stub"); read_section(hdr, slide, "__TEXT", "__symbol_stub"); read_section(hdr, slide, "__TEXT", "__const"); read_section(hdr, slide, "__TEXT", "__literal4"); read_section(hdr, slide, "__TEXT", "__literal8"); read_section(hdr, slide, "__DATA", "__data"); read_section(hdr, slide, "__DATA", "__la_symbol_ptr"); read_section(hdr, slide, "__DATA", "__nl_symbol_ptr"); read_section(hdr, slide, "__DATA", "__dyld"); read_section(hdr, slide, "__DATA", "__const"); read_section(hdr, slide, "__DATA", "__mod_init_func"); read_section(hdr, slide, "__DATA", "__bss"); read_section(hdr, slide, "__DATA", "__common"); read_section(hdr, slide, "__IMPORT", "__jump_table"); read_section(hdr, slide, "__IMPORT", "__pointers"); } } #endif }
int prFileOpen(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b, *c; char filename[PATH_MAX]; char mode[12]; PyrFile *pfile; FILE *file; a = g->sp - 2; b = g->sp - 1; c = g->sp; if (NotObj(c) || !isKindOf(slotRawObject(c), class_string) || NotObj(b) || !isKindOf(slotRawObject(b), class_string)) return errWrongType; if (slotRawObject(b)->size > PATH_MAX - 1) return errFailed; if (slotRawObject(c)->size > 11) return errFailed; pfile = (PyrFile*)slotRawObject(a); memcpy(filename, slotRawString(b)->s, slotRawObject(b)->size); filename[slotRawString(b)->size] = 0; memcpy(mode, slotRawString(c)->s, slotRawObject(c)->size); mode[slotRawString(c)->size] = 0; #ifdef SC_WIN32 win32_ReplaceCharInString(filename,PATH_MAX,'/','\\'); if(strcmp(mode,"w") == 0) strcpy(mode,"wb"); if(strcmp(mode,"r") == 0) strcpy(mode,"rb"); #endif //SC_WIN32 file = fopen(filename, mode); if (file) { SetPtr(&pfile->fileptr, file); SetTrue(a); } else { #ifdef SC_WIN32 // check if directory exisits // create a temporary file (somewhere) for a handle // the file is deleted automatically when closed if (sc_DirectoryExists(filename)) { int err; #ifdef _MSC_VER err = tmpfile_s(&file); if (!err) { SetPtr(&pfile->fileptr, file); SetTrue(a); return errNone; } #elif defined(__MINGW32__) file = tmpfile(); if (file) { SetPtr(&pfile->fileptr, file); SetTrue(a); return errNone; } #else #error compiler unsupported #endif } #endif SetNil(a); SetFalse(a); } return errNone; }