[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-dev] [Approve?] Add 'Extensions' directories to compiler path.
This patch:
1) Adds "/Library/Application Support/SuperCollider/Extensions" and
"~/Library/Application Support/SuperCollider/Extensions" to the
compiler search path. It is not an error if a directory does not
exist.
2) Makes the compiler skip directories that case insensitively match
"help" and "test".
It is tested under OSX. The locations of the 'Extensions' directory
under Linux and Windows needs to be decided. Under Linux perhaps
'/usr/local/share/SuperCollider/Extensions' and
'~/share/SuperCollider/Extensions'.
Looking over these files it seems like it should be possible for the
OSX version of sclang to also use SC_TerminalClient, which would make
the SC_LibraryConfig system available there also. The 'Extensions'
directories could then be added as initial entries in that system.
Some other comments (mainly related to #ifdef):
1) libraryConfig.cpp and libraryConfig.h seem not to be used.
SC_LibraryConfig is used instead. These files could perhaps be
removed.
2) With three platforms supported now perhaps various of the platform
switches could be moved into a 'platform' file or directory. The
procedures sc_DirectoryExists, sc_GetUserHomeDirectory and
sc_AppendToPath could go there, also bzero, vsnprintf, closesocket,
socklen_t, nanosleep and sc_StandardizePath.
3) Perhaps the special case for fopen "rb" is not neccessary
(ie. under unices "r" and "rb" are equivalent).
4) The ENABLE_LIBRARY_CONFIGURATOR switch is not required as
gLibraryConfig is otherwise NULL.
5) Perhaps as gInternalSynthServer.mWorld is initialize to NULL the
#ifdef is not required.
I could do work in these directions if people think any of them a good
idea.
Regards,
Rohan
Other possible entries at 'platform':
#ifdef SC_WIN32
inline void bzero(void *b, size_t len)
{
memset(ptr, 0, count);
}
#endif
#ifndef SC_WIN32
int closesocket(int fd)
{
return close(fd);
}
#endif
#ifdef SC_WIN32
typedef int socklen_t;
#endif
#ifdef SC_WIN32
#define vsnprintf _vsnprintf
#endif
--- SuperCollider3.cvs/source/lang/LangSource/PyrLexer.cpp Wed Sep 29 18:56:31 2004
+++ SuperCollider3.build/source/lang/LangSource/PyrLexer.cpp Sun Dec 19 21:17:07 2004
@@ -96,6 +96,8 @@
PyrSymbol *gCompilingFileSym = 0;
VMGlobals *gCompilingVMGlobals = 0;
char gCompileDir[MAXPATHLEN];
+char gSystemExtensionDir[MAXPATHLEN];
+char gUserExtensionDir[MAXPATHLEN];
//#define DEBUGLEX 1
bool gDebugLexer = false;
@@ -1922,6 +1924,31 @@
//postfl("<-finiPassOne\n");
}
+// Returns TRUE iff dirname is an existing directory.
+
+bool sc_DirectoryExists(const char *dirname);
+bool sc_DirectoryExists(const char *dirname)
+{
+#ifndef SC_WIN32
+ struct stat buf;
+ int err = stat(dirname, &buf);
+ return (err == 0) && (buf.st_mode & S_IFDIR);
+#else
+ return 0;
+#endif
+}
+
+// Returns TRUE iff 'name' is to be ignored during compilation.
+
+static bool sc_SkipDirectory(const char *name);
+static bool sc_SkipDirectory(const char *name)
+{
+ return ((strcmp(name, ".") == 0) ||
+ (strcmp(name, "..") == 0) ||
+ (strcasecmp(name, "help") == 0) ||
+ (strcasecmp(name, "test") == 0));
+}
+
bool passOne_ProcessDir(char *dirname, int level);
#ifndef SC_WIN32
bool passOne_ProcessDir(char *dirname, int level)
@@ -1949,7 +1976,8 @@
de = readdir(dir);
if (!de) break;
- if ((strcmp(de->d_name, ".") == 0) || (strcmp(de->d_name, "..") == 0)) continue;
+ if (sc_SkipDirectory(de->d_name)) continue;
+
char *entrypathname = (char*)malloc(strlen(dirname) + strlen((char*)de->d_name) + 2);
strcpy(entrypathname, dirname);
//strcat(entrypathname, ":");
@@ -1964,9 +1992,7 @@
#ifdef SC_LINUX
{
struct stat stat_buf;
- isDirectory =
- (stat(entrypathname, &stat_buf) == 0)
- && S_ISDIR(stat_buf.st_mode);
+ isDirectory = sc_DirectoryExists(entrypathname);
}
#endif // SC_LINUX
@@ -2008,9 +2034,8 @@
}
do {
- if ((strcmp(findData.cFileName, ".") == 0) || (strcmp(findData.cFileName, "..") == 0))
- continue;
-
+ if (sc_SkipDirectory(findData.cFileName)) continue;
+
char *entrypathname = (char*)malloc(strlen(dirname) + strlen(findData.cFileName) + 2);
strcpy(entrypathname, dirname);
strcat(entrypathname, "\\");
@@ -2035,6 +2060,56 @@
# include <sys/param.h>
#endif
+// Get the Users home directory.
+
+#if SC_WIN32
+# include "win32_utils.h"
+#endif
+
+void sc_GetUserHomeDirectory(char *str, int size);
+void sc_GetUserHomeDirectory(char *str, int size)
+{
+#ifndef SC_WIN32
+ char *home = getenv("HOME");
+ strncpy(str, home, size);
+#else
+ win32_GetHomeFolder(str,size);
+#endif
+}
+
+// Add a component to a path.
+
+void sc_AppendToPath(char *path, const char *component);
+void sc_AppendToPath(char *path, const char *component)
+{
+#ifndef SC_WIN32
+ strcat(path, "/");
+#else
+ strcat(path, "\\");
+#endif
+ strcat(path, component);
+}
+
+// Locate directories to compile.
+
+static void sc_InitCompileDirectories(void);
+static void sc_InitCompileDirectories(void)
+{
+ getcwd(gCompileDir, MAXPATHLEN-32);
+ sc_AppendToPath(gCompileDir,"SCClassLibrary");
+
+ snprintf(gSystemExtensionDir,
+ MAXPATHLEN,
+ "/Library/Application Support/SuperCollider/Extensions");
+
+ char home[MAXPATHLEN];
+ sc_GetUserHomeDirectory(home, MAXPATHLEN);
+ snprintf(gUserExtensionDir,
+ MAXPATHLEN,
+ "%s/Library/Application Support/SuperCollider/Extensions",
+ home);
+}
+
bool passOne()
{
bool success;
@@ -2042,16 +2117,22 @@
// This function must be provided by the host environment.
// It should choose a directory to scan recursively and call
// passOne_ProcessOneFile(char *filename) for each file
-
+
if (!gLibraryConfig) {
- getcwd(gCompileDir, MAXPATHLEN-32);
-#ifndef SC_WIN32
- strcat(gCompileDir, "/SCClassLibrary");
-#else
- strcat(gCompileDir, "\\SCClassLibrary");
-#endif
+ sc_InitCompileDirectories();
+
success = passOne_ProcessDir(gCompileDir, 0);
if (!success) return false;
+
+ if(sc_DirectoryExists(gSystemExtensionDir)) {
+ success = passOne_ProcessDir(gSystemExtensionDir,0);
+ if (!success) return false;
+ }
+
+ if(sc_DirectoryExists(gUserExtensionDir)) {
+ success = passOne_ProcessDir(gUserExtensionDir,0);
+ if (!success) return false;
+ }
} else {
#ifdef ENABLE_LIBRARY_CONFIGURATOR
success = gLibraryConfig->forEachIncludedDirectory(passOne_ProcessDir);