~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpinstall/wizard/libxpnet/GUSI/include/GUSIConfig.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 
2
// % Project    :       GUSI                            -       Grand Unified Socket Interface                    
 
3
// % File               :       GUSIConfig.nw           -       Configuration settings                       
 
4
// % Author     :       Matthias Neeracher                                           
 
5
// % Language   :       C++                                                        
 
6
// %                                                                       
 
7
// % $Log: GUSIConfig.h,v $
 
8
// % Revision 1.1  2001/03/11 22:33:34  sgehani%netscape.com
 
9
// % First Checked In.
 
10
// %                                               
 
11
// % Revision 1.18  2001/01/22 04:31:11  neeri                             
 
12
// % Last minute changes for 2.1.5                                         
 
13
// %                                                                       
 
14
// % Revision 1.17  2001/01/17 08:40:17  neeri                             
 
15
// % Prevent inlining of overridable functions                             
 
16
// %                                                                       
 
17
// % Revision 1.16  2000/05/23 06:54:39  neeri                             
 
18
// % Improve formatting, update to latest universal headers                
 
19
// %                                                                       
 
20
// % Revision 1.15  2000/03/15 07:10:29  neeri                             
 
21
// % Fix suffix searching code                                             
 
22
// %                                                                       
 
23
// % Revision 1.14  2000/03/06 06:24:34  neeri                             
 
24
// % Fix plausibility tests for A5                                         
 
25
// %                                                                       
 
26
// % Revision 1.13  1999/09/26 03:56:44  neeri                             
 
27
// % Sanity check for A5                                                   
 
28
// %                                                                       
 
29
// % Revision 1.12  1999/08/26 05:44:59  neeri                             
 
30
// % Fixes for literate edition of source code                             
 
31
// %                                                                       
 
32
// % Revision 1.11  1999/06/28 05:57:03  neeri                             
 
33
// % Support SIGINT generation                                             
 
34
// %                                                                       
 
35
// % Revision 1.10  1999/05/29 06:26:41  neeri                             
 
36
// % Fixed header guards                                                   
 
37
// %                                                                       
 
38
// % Revision 1.9  1999/03/29 09:51:28  neeri                              
 
39
// % New configuration system with support for hardcoded configurations.   
 
40
// %                                                                       
 
41
// % Revision 1.8  1999/03/17 09:05:05  neeri                              
 
42
// % Added GUSITimer, expanded docs                                        
 
43
// %                                                                       
 
44
// % Revision 1.7  1998/10/11 16:45:10  neeri                              
 
45
// % Ready to release 2.0a2                                                
 
46
// %                                                                       
 
47
// % Revision 1.6  1998/08/01 21:32:01  neeri                              
 
48
// % About ready for 2.0a1                                                 
 
49
// %                                                                       
 
50
// % Revision 1.5  1998/01/25 20:53:52  neeri                              
 
51
// % Engine implemented, except for signals & scheduling                   
 
52
// %                                                                       
 
53
// % Revision 1.4  1997/11/13 21:12:10  neeri                              
 
54
// % Fall 1997                                                             
 
55
// %                                                                       
 
56
// % Revision 1.3  1996/11/24  13:00:27  neeri                             
 
57
// % Fix comment leaders                                                   
 
58
// %                                                                       
 
59
// % Revision 1.2  1996/11/24  12:52:06  neeri                             
 
60
// % Added GUSIPipeSockets                                                 
 
61
// %                                                                       
 
62
// % Revision 1.1.1.1  1996/11/03  02:43:32  neeri                         
 
63
// % Imported into CVS                                                     
 
64
// %                                                                       
 
65
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 
66
//                                                                         
 
67
// \chapter{GUSI Configuration settings}                                   
 
68
//                                                                         
 
69
// GUSI stores its global configuration settings in the [[GUSIConfiguration]] 
 
70
// singleton class. To create the instance, GUSI calls the [[GUSISetupConfig]]
 
71
// hook.                                                                   
 
72
//                                                                         
 
73
// <GUSIConfig.h>=                                                         
 
74
#ifndef _GUSIConfig_
 
75
#define _GUSIConfig_
 
76
 
 
77
#ifdef GUSI_SOURCE
 
78
 
 
79
#include "GUSIFileSpec.h"
 
80
 
 
81
#include <ConditionalMacros.h>
 
82
 
 
83
#if PRAGMA_STRUCT_ALIGN
 
84
#pragma options align=native
 
85
#endif
 
86
 
 
87
// \section{Definition of configuration settings}                          
 
88
//                                                                         
 
89
// The GUSIConfiguration has a single instance with read only access, accessible
 
90
// with the static [[Instance]] member function.                           
 
91
//                                                                         
 
92
// <Definition of class [[GUSIConfiguration]]>=                            
 
93
class GUSIConfiguration {
 
94
public:
 
95
        enum { kNoResource = -1, kDefaultResourceID = 10240 };
 
96
        
 
97
        static GUSIConfiguration *      Instance();
 
98
        static GUSIConfiguration *      CreateInstance(short resourceID = kDefaultResourceID);
 
99
        
 
100
        // To determine the file type and creator of a newly created file, we first try 
 
101
 // to match one of the [[FileSuffix]] suffices.                            
 
102
 //                                                                         
 
103
 // <Type and creator rules for newly created files>=                       
 
104
 struct FileSuffix {
 
105
        char    suffix[4];
 
106
        OSType  suffType;
 
107
        OSType  suffCreator;
 
108
 };
 
109
 short                  fNumSuffices;
 
110
 FileSuffix *   fSuffices;
 
111
 
 
112
 void ConfigureSuffices(short numSuffices, FileSuffix * suffices);
 
113
 // If none of the suffices matches, we apply the default type and creator. These
 
114
 // rules are applied with [[SetDefaultFType]].                             
 
115
 //                                                                         
 
116
 // <Type and creator rules for newly created files>=                       
 
117
 OSType         fDefaultType;
 
118
 OSType         fDefaultCreator;
 
119
 
 
120
 void ConfigureDefaultTypeCreator(OSType defaultType, OSType defaultCreator);
 
121
 void SetDefaultFType(const GUSIFileSpec & name) const;
 
122
        // To simplify Macintosh friendly ports of simple, I/O bound programs it is 
 
123
 // possible to specify automatic yielding on read() and write() calls.     
 
124
 // [[AutoSpin]] will spin a cursor and/or yield the CPU if desired.        
 
125
 //                                                                         
 
126
 // <Automatic cursor spin>=                                                
 
127
 bool fAutoSpin;
 
128
 
 
129
 void ConfigureAutoSpin(bool autoSpin);
 
130
 void AutoSpin() const;
 
131
        // GUSI applications can crash hard if QuickDraw is not initialized. Therefore, we
 
132
 // offer to initialize it automatically with the [[fAutoInitGraf]] feature.
 
133
 //                                                                         
 
134
 // <Automatic initialization of QuickDraw>=                                
 
135
 bool fAutoInitGraf;
 
136
 
 
137
 void ConfigureAutoInitGraf(bool autoInitGraf);
 
138
 void AutoInitGraf();
 
139
        // Due to the organization of a UNIX filesystem, it is fairly easy to find 
 
140
 // out how many subdirectories a given directory has, since the [[nlink]] field of 
 
141
 // its inode will automatically contain the number of subdirectories[[+2]]. Therefore,
 
142
 // some UNIX derived code depends on this behaviour. When [[fAccurateStat]] is set, 
 
143
 // GUSI emulates this behaviour, but be warned that this makes [[stat]] on 
 
144
 // directories a much more expensive operation. If [[fAccurateStat]] is not set,
 
145
 // stat() gives the total number of entries in the directory[[+2]] as a conservative 
 
146
 // estimate.                                                               
 
147
 //                                                                         
 
148
 // <Various flags>=                                                        
 
149
 bool fAccurateStat;
 
150
 
 
151
 void ConfigureAccurateStat(bool accurateState);
 
152
 // The [[fSigPipe]] feature causes a signal [[SIGPIPE]] to be raised if an attempt
 
153
 // is made to write to a broken pipe.                                      
 
154
 //                                                                         
 
155
 // <Various flags>=                                                        
 
156
 bool           fSigPipe;
 
157
 
 
158
 void ConfigureSigPipe(bool sigPipe);
 
159
 void BrokenPipe();
 
160
 // The [[fSigInt]] feature causes a signal [[SIGINT]] to be raised if the user presses
 
161
 // command-period.                                                         
 
162
 //                                                                         
 
163
 // <Various flags>=                                                        
 
164
 bool           fSigInt;
 
165
 
 
166
 void ConfigureSigInt(bool sigInt);
 
167
 void CheckInterrupt();
 
168
 // If [[fSharedOpen]] is set, open() opens files with shared read/write permission.
 
169
 //                                                                         
 
170
 // <Various flags>=                                                        
 
171
 bool           fSharedOpen;
 
172
 
 
173
 void ConfigureSharedOpen(bool sharedOpen);
 
174
 // If [[fHandleAppleEvents]] is set, GUSI automatically handles AppleEvents in its 
 
175
 // event handling routine.                                                 
 
176
 //                                                                         
 
177
 // <Various flags>=                                                        
 
178
 bool           fHandleAppleEvents;
 
179
 
 
180
 void ConfigureHandleAppleEvents(bool handleAppleEvents);
 
181
protected:
 
182
        GUSIConfiguration(short resourceID = kDefaultResourceID);
 
183
private:
 
184
        // \section{Implementation of configuration settings}                      
 
185
 //                                                                         
 
186
 // The sole instance of [[GUSIConfiguration]] is created on demand.        
 
187
 //                                                                         
 
188
 // <Privatissima of [[GUSIConfiguration]]>=                                
 
189
 static GUSIConfiguration * sInstance;
 
190
 // [[ConfigureSuffices]] sets up the suffix table.                         
 
191
 //                                                                         
 
192
 // <Privatissima of [[GUSIConfiguration]]>=                                
 
193
 bool fWeOwnSuffices;
 
194
 // [[AutoSpin]] tests the flag inline, but performs the actual spinning out of
 
195
 // line.                                                                   
 
196
 //                                                                         
 
197
 // <Privatissima of [[GUSIConfiguration]]>=                                
 
198
 void DoAutoSpin() const;
 
199
 // [[AutoInitGraf]] works rather similarly to [[AutoSpin]].                
 
200
 //                                                                         
 
201
 // <Privatissima of [[GUSIConfiguration]]>=                                
 
202
 void DoAutoInitGraf();
 
203
 // [[CheckInterrupt]] raises a [[SIGINT]] signal if desired.               
 
204
 //                                                                         
 
205
 // <Privatissima of [[GUSIConfiguration]]>=                                
 
206
 bool CmdPeriod(const EventRecord * event);
 
207
};
 
208
 
 
209
#if PRAGMA_STRUCT_ALIGN
 
210
#pragma options align=reset
 
211
#endif
 
212
 
 
213
// To create the sole instance of [[GUSIConfiguration]], we call [[GUSISetupConfig]]
 
214
// which has to call [[GUSIConfiguration::CreateInstance]].                
 
215
//                                                                         
 
216
// <Definition of [[GUSISetupConfig]] hook>=                               
 
217
#ifdef __MRC__
 
218
#pragma noinline_func GUSISetupConfig
 
219
#endif
 
220
 
 
221
extern "C" void GUSISetupConfig();
 
222
// <Inline member functions for class [[GUSIConfiguration]]>=              
 
223
inline GUSIConfiguration * GUSIConfiguration::Instance()
 
224
{
 
225
        if (!sInstance)
 
226
                GUSISetupConfig();
 
227
        if (!sInstance)
 
228
                sInstance = new GUSIConfiguration();
 
229
        
 
230
        return sInstance;
 
231
}
 
232
 
 
233
inline GUSIConfiguration * GUSIConfiguration::CreateInstance(short resourceID)
 
234
{
 
235
        if (!sInstance)
 
236
                sInstance = new GUSIConfiguration(resourceID);
 
237
        
 
238
        return sInstance;
 
239
}
 
240
// <Inline member functions for class [[GUSIConfiguration]]>=              
 
241
inline void GUSIConfiguration::ConfigureDefaultTypeCreator(OSType defaultType, OSType defaultCreator)
 
242
{
 
243
        fDefaultType    = defaultType;
 
244
        fDefaultCreator = defaultCreator;
 
245
}
 
246
// <Inline member functions for class [[GUSIConfiguration]]>=              
 
247
inline void GUSIConfiguration::ConfigureAutoSpin(bool autoSpin)
 
248
{
 
249
        fAutoSpin = autoSpin;
 
250
}
 
251
// <Inline member functions for class [[GUSIConfiguration]]>=              
 
252
inline void GUSIConfiguration::AutoSpin() const
 
253
{
 
254
        if (fAutoSpin)
 
255
                DoAutoSpin();
 
256
}
 
257
// <Inline member functions for class [[GUSIConfiguration]]>=              
 
258
inline void GUSIConfiguration::ConfigureAutoInitGraf(bool autoInitGraf)
 
259
{
 
260
        fAutoInitGraf   = autoInitGraf;
 
261
}
 
262
// <Inline member functions for class [[GUSIConfiguration]]>=              
 
263
inline void GUSIConfiguration::AutoInitGraf()
 
264
{
 
265
        if (fAutoInitGraf)
 
266
                DoAutoInitGraf();
 
267
}
 
268
// <Inline member functions for class [[GUSIConfiguration]]>=              
 
269
inline void GUSIConfiguration::ConfigureSigPipe(bool sigPipe)
 
270
{
 
271
        fSigPipe        = sigPipe;
 
272
}
 
273
// <Inline member functions for class [[GUSIConfiguration]]>=              
 
274
inline void GUSIConfiguration::ConfigureSigInt(bool sigInt)
 
275
{
 
276
        fSigInt         = sigInt;
 
277
}
 
278
// <Inline member functions for class [[GUSIConfiguration]]>=              
 
279
inline void GUSIConfiguration::ConfigureAccurateStat(bool accurateStat)
 
280
{
 
281
        fAccurateStat   = accurateStat;
 
282
}
 
283
inline void GUSIConfiguration::ConfigureSharedOpen(bool sharedOpen)
 
284
{
 
285
        fSharedOpen     = sharedOpen;
 
286
}
 
287
#endif /* GUSI_SOURCE */
 
288
 
 
289
#endif /* _GUSIConfig_ */