"Post Window" -> "Post window" prevents it being seen as two separate
[supercollider.git] / include / lang / SC_LibraryConfig.h
blob0cb4502992554fefd61796146295129f68bd7b79
1 /*
2 * Copyright 2003 Maurizio Umberto Puxeddu <umbpux@tin.it>
3 * Copyright 2011 Jakob Leben
5 * This file is part of SuperCollider.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20 * USA
24 #ifndef SC_LIBRARYCONFIG_H_INCLUDED
25 #define SC_LIBRARYCONFIG_H_INCLUDED
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <vector>
30 #include <string>
32 // =====================================================================
33 // SC_LibraryConfigFile
34 // simple library configuration file parser
35 // =====================================================================
37 class SC_LanguageConfig;
39 class SC_LibraryConfigFile
41 public:
42 typedef void (*ErrorFunc)(const char* fmt, ...);
44 public:
45 SC_LibraryConfigFile(ErrorFunc errorFunc=0);
47 bool open(const char* filePath);
48 bool read(const char* fileName, SC_LanguageConfig* libConf);
49 void close();
51 protected:
52 enum State
54 kBegin,
55 kAction,
56 kPath,
57 kEscape,
58 kEnvVar,
59 kEnvVarName,
60 kEnd
63 enum
65 kMaxIncludeDepth = 10
68 bool read(int depth, const char* fileName, SC_LanguageConfig* libConf);
69 bool parseLine(int depth, const char* fileName, int lineNumber, const char* line, SC_LanguageConfig* libConf);
70 static void defaultErrorFunc(const char* fmt, ...);
72 private:
73 ErrorFunc mErrorFunc;
74 FILE* mFile;
77 class SC_LanguageConfig
79 public:
80 typedef std::vector<std::string> DirVector;
82 const DirVector& includedDirectories() { return mIncludedDirectories; }
83 const DirVector& excludedDirectories() { return mExcludedDirectories; }
85 void postExcludedDirectories(void);
86 bool forEachIncludedDirectory(bool (*func)(const char *, int));
88 bool pathIsExcluded(const char *path);
90 void addIncludedDirectory(const char *name);
91 void addExcludedDirectory(const char *name);
92 void removeIncludedDirectory(const char *name);
93 void removeExcludedDirectory(const char *name);
95 // convenience functions to access the global library config
96 static bool readLibraryConfig(const char* fileName);
97 static bool readLibraryConfigYAML(const char* fileName);
98 static bool writeLibraryConfigYAML(const char* fileName);
99 static void freeLibraryConfig();
100 static bool defaultLibraryConfig(void);
101 static bool readDefaultLibraryConfig();
103 private:
104 DirVector mIncludedDirectories;
105 DirVector mExcludedDirectories;
108 extern SC_LanguageConfig* gLibraryConfig;
110 #endif // SC_LIBRARYCONFIG_H_INCLUDED