aboutsummaryrefslogtreecommitdiff
path: root/sc4pd/headers/lang/SC_LibraryConfig.h
blob: 5f7df3b91a16f1e3b6477dd4678cf467578ef109 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// emacs:		-*- c++ -*-
// file:		SC_LibraryConfig.h
// cvs:			$Id: SC_LibraryConfig.h,v 1.1.1.1 2004-07-14 16:21:24 timblech Exp $

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA

#ifndef SC_LIBRARYCONFIG_H_INCLUDED
#define SC_LIBRARYCONFIG_H_INCLUDED

#include <stdarg.h>
#include <stdio.h>

// =====================================================================
// SC_LibraryConfigFile
//    simple library configuration file parser
// =====================================================================

class SC_LibraryConfig;

class SC_LibraryConfigFile
{
public:
	typedef void (*ErrorFunc)(const char* fmt, ...);

public:
    SC_LibraryConfigFile(ErrorFunc errorFunc=0);

    bool open(const char* filePath);
    bool read(const char* fileName, SC_LibraryConfig* libConf);
    void close();

protected:
	enum State
	{
		kBegin,
		kAction,
		kPath,
		kEscape,
		kEnvVar,
		kEnvVarName,
		kEnd
	};

	enum
	{
		kMaxIncludeDepth = 10
	};

    bool read(int depth, const char* fileName, SC_LibraryConfig* libConf);
	bool parseLine(int depth, const char* fileName, int lineNumber, const char* line, SC_LibraryConfig* libConf);
	static void defaultErrorFunc(const char* fmt, ...);

private:
	ErrorFunc			mErrorFunc;
	FILE*				mFile;
};

// =====================================================================
// SC_LibraryConfig
//    library configuration management
// Copyright 2003 Maurizio Umberto Puxeddu
// =====================================================================

class SC_LibraryConfig
{
public:
	SC_LibraryConfig(void);
	virtual ~SC_LibraryConfig();
  
	char **includedDirectories(void);
	char **excludedDirectories(void);

	void postExcludedDirectories(void);
	bool forEachIncludedDirectory(bool (*func)(char *, int));

	bool pathIsExcluded(const char *path);

	void addIncludedDirectory(char *name);
	void addExcludedDirectory(char *name);

	// convenience functions to access the global library config
	static bool readLibraryConfig(SC_LibraryConfigFile& file, const char* fileName);
	static void freeLibraryConfig();

private:
	int m_nIncludedDirectories;
	char **m_includedDirectories;
	int m_nExcludedDirectories;
	char **m_excludedDirectories;
};

extern SC_LibraryConfig* gLibraryConfig;
extern char *unixStandardizePath(const char *path, char *newpath);

#endif // SC_LIBRARYCONFIG_H_INCLUDED