~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to cpp/src/slice2cs/Main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// **********************************************************************
2
2
//
3
 
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
4
4
//
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
9
9
 
10
10
#include <IceUtil/Options.h>
11
11
#include <IceUtil/CtrlCHandler.h>
12
 
#include <IceUtil/StaticMutex.h>
 
12
#include <IceUtil/Mutex.h>
 
13
#include <IceUtil/MutexPtrLock.h>
13
14
#include <Slice/Preprocessor.h>
14
15
#include <Slice/FileTracker.h>
15
16
#include <Slice/Util.h>
18
19
using namespace std;
19
20
using namespace Slice;
20
21
 
21
 
static IceUtil::StaticMutex _mutex = ICE_STATIC_MUTEX_INITIALIZER;
22
 
static bool _interrupted = false;
 
22
namespace
 
23
{
 
24
 
 
25
IceUtil::Mutex* mutex = 0;
 
26
bool interrupted = false;
 
27
 
 
28
class Init
 
29
{
 
30
public:
 
31
 
 
32
    Init()
 
33
    {
 
34
        mutex = new IceUtil::Mutex;
 
35
    }
 
36
 
 
37
    ~Init()
 
38
    {
 
39
        delete mutex;
 
40
        mutex = 0;
 
41
    }
 
42
};
 
43
 
 
44
Init init;
 
45
 
 
46
}
23
47
 
24
48
void
25
49
interruptedCallback(int signal)
26
50
{
27
 
    IceUtil::StaticMutex::Lock lock(_mutex);
 
51
    IceUtilInternal::MutexPtrLock<IceUtil::Mutex> sync(mutex);
28
52
 
29
 
    _interrupted = true;
 
53
    interrupted = true;
30
54
}
31
55
 
32
56
void
33
57
usage(const char* n)
34
58
{
35
 
    cerr << "Usage: " << n << " [options] slice-files...\n";
36
 
    cerr <<        
 
59
    getErrorStream() << "Usage: " << n << " [options] slice-files...\n";
 
60
    getErrorStream() <<        
37
61
        "Options:\n"
38
62
        "-h, --help              Show this message.\n"
39
63
        "-v, --version           Display the Ice version.\n"
48
72
        "--impl-tie              Generate sample TIE implementations.\n"
49
73
        "--depend                Generate Makefile dependencies.\n"
50
74
        "-d, --debug             Print debug messages.\n"
51
 
        "--ice                   Permit `Ice' prefix (for building Ice source code only)\n"
 
75
        "--ice                   Permit `Ice' prefix (for building Ice source code only).\n"
 
76
        "--underscore            Permit underscores in Slice identifiers.\n"
52
77
        "--checksum              Generate checksums for Slice definitions.\n"
53
78
        "--stream                Generate marshaling support for public stream API.\n"
54
79
        ;
55
 
    // Note: --case-sensitive is intentionally not shown here!
56
80
}
57
81
 
58
82
int
59
 
main(int argc, char* argv[])
 
83
compile(int argc, char* argv[])
60
84
{
61
85
    IceUtilInternal::Options opts;
62
86
    opts.addOpt("h", "help");
72
96
    opts.addOpt("", "depend");
73
97
    opts.addOpt("d", "debug");
74
98
    opts.addOpt("", "ice");
 
99
    opts.addOpt("", "underscore");
75
100
    opts.addOpt("", "checksum");
76
101
    opts.addOpt("", "stream");
77
 
    opts.addOpt("", "case-sensitive");
78
102
 
79
103
    vector<string> args;
80
104
    try
81
105
    {
82
 
#if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600)
83
 
        IceUtil::DummyBCC dummy;
84
 
#endif
85
106
        args = opts.parse(argc, (const char**)argv);
86
107
    }
87
108
    catch(const IceUtilInternal::BadOptException& e)
88
109
    {
89
 
        cerr << argv[0] << ": error: " << e.reason << endl;
 
110
        getErrorStream() << argv[0] << ": error: " << e.reason << endl;
90
111
        usage(argv[0]);
91
112
        return EXIT_FAILURE;
92
113
    }
99
120
 
100
121
    if(opts.isSet("version"))
101
122
    {
102
 
        cerr << ICE_STRING_VERSION << endl;
 
123
        getErrorStream() << ICE_STRING_VERSION << endl;
103
124
        return EXIT_SUCCESS;
104
125
    }
105
126
 
139
160
 
140
161
    bool ice = opts.isSet("ice");
141
162
 
 
163
    bool underscore = opts.isSet("underscore");
 
164
 
142
165
    bool checksum = opts.isSet("checksum");
143
166
 
144
167
    bool stream = opts.isSet("stream");
145
168
 
146
 
    bool caseSensitive = opts.isSet("case-sensitive");
147
 
 
148
169
    if(args.empty())
149
170
    {
150
171
        getErrorStream() << argv[0] << ": error: no input file" << endl;
166
187
 
167
188
    for(i = args.begin(); i != args.end(); ++i)
168
189
    {
 
190
        //
 
191
        // Ignore duplicates.
 
192
        //
 
193
        vector<string>::iterator p = find(args.begin(), args.end(), *i);
 
194
        if(p != i)
 
195
        {
 
196
            continue;
 
197
        }
 
198
 
169
199
        if(depend)
170
200
        {
171
 
            Preprocessor icecpp(argv[0], *i, cppArgs);
172
 
            if(!icecpp.printMakefileDependencies(Preprocessor::CSharp, includePaths))
 
201
            PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs);
 
202
            FILE* cppHandle = icecpp->preprocess(false);
 
203
 
 
204
            if(cppHandle == 0)
 
205
            {
 
206
                return EXIT_FAILURE;
 
207
            }
 
208
 
 
209
            UnitPtr u = Unit::createUnit(false, false, ice, underscore);
 
210
            int parseStatus = u->parse(*i, cppHandle, debug);
 
211
            u->destroy();
 
212
 
 
213
            if(parseStatus == EXIT_FAILURE)
 
214
            {
 
215
                return EXIT_FAILURE;
 
216
            }
 
217
 
 
218
            if(!icecpp->printMakefileDependencies(Preprocessor::CSharp, includePaths))
 
219
            {
 
220
                return EXIT_FAILURE;
 
221
            }
 
222
 
 
223
            if(!icecpp->close())
173
224
            {
174
225
                return EXIT_FAILURE;
175
226
            }
176
227
        }
177
228
        else
178
229
        {
179
 
            Preprocessor icecpp(argv[0], *i, cppArgs);
180
 
            FILE* cppHandle = icecpp.preprocess(false);
 
230
            PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs);
 
231
            FILE* cppHandle = icecpp->preprocess(true);
181
232
 
182
233
            if(cppHandle == 0)
183
234
            {
193
244
                        return EXIT_FAILURE;
194
245
                    }
195
246
                }
196
 
                if(!icecpp.close())
 
247
                if(!icecpp->close())
197
248
                {
198
249
                    return EXIT_FAILURE;
199
250
                }           
200
251
            }
201
252
            else
202
253
            {
203
 
                UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive);
 
254
                UnitPtr p = Unit::createUnit(false, false, ice, underscore);
204
255
                int parseStatus = p->parse(*i, cppHandle, debug);
205
256
 
206
 
                if(!icecpp.close())
 
257
                if(!icecpp->close())
207
258
                {
208
259
                    p->destroy();
209
260
                    return EXIT_FAILURE;
217
268
                {
218
269
                    try
219
270
                    {
220
 
                        Gen gen(icecpp.getBaseName(), includePaths, output, impl, implTie, stream);
 
271
                        Gen gen(icecpp->getBaseName(), includePaths, output, impl, implTie, stream);
221
272
                        gen.generate(p);
222
273
                        if(tie)
223
274
                        {
252
303
        }
253
304
 
254
305
        {
255
 
            IceUtil::StaticMutex::Lock lock(_mutex);
 
306
            IceUtilInternal::MutexPtrLock<IceUtil::Mutex> sync(mutex);
256
307
 
257
 
            if(_interrupted)
 
308
            if(interrupted)
258
309
            {
259
310
                FileTracker::instance()->cleanup();
260
311
                return EXIT_FAILURE;
264
315
 
265
316
    return status;
266
317
}
 
318
 
 
319
int
 
320
main(int argc, char* argv[])
 
321
{
 
322
    try
 
323
    {
 
324
        return compile(argc, argv);
 
325
    }
 
326
    catch(const std::exception& ex)
 
327
    {
 
328
        getErrorStream() << argv[0] << ": error:" << ex.what() << endl;
 
329
        return EXIT_FAILURE;
 
330
    }
 
331
    catch(const std::string& msg)
 
332
    {
 
333
        getErrorStream() << argv[0] << ": error:" << msg << endl;
 
334
        return EXIT_FAILURE;
 
335
    }
 
336
    catch(const char* msg)
 
337
    {
 
338
        getErrorStream() << argv[0] << ": error:" << msg << endl;
 
339
        return EXIT_FAILURE;
 
340
    }
 
341
    catch(...)
 
342
    {
 
343
        getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl;
 
344
        return EXIT_FAILURE;
 
345
    }
 
346
}