File: cfdg.cpp

package info (click to toggle)
contextfree 2.2%2Bdfsg1-2.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,336 kB
  • sloc: cpp: 20,388; yacc: 507; objc: 494; ansic: 270; makefile: 113; lex: 92; xml: 24
file content (115 lines) | stat: -rw-r--r-- 2,593 bytes parent folder | download | duplicates (2)
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
109
110
111
112
113
114
115
/*
 *

 Context Free Design Grammar - version 0.2

 Copyright (C) 2005 Chris Coyne - ccoyne77@gmail.com
 Copyright (C) 2005 Mark Lentczner - markl@glyphic.com
 Copyright (C) 2005 John Horigan - john@glyphic.com

 [Send me anything cool you make with it or of it.]

 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

 *
 */


#include "cfdg.h"

#include <string>

#include "builder.h"
#include "cfdgimpl.h"
#include "yglue.h"
#include <string.h>
#include <math.h>

using namespace std;




AbstractSystem::~AbstractSystem() { }

void AbstractSystem::stats(const Stats&)
    { }

Canvas::~Canvas() { }

Renderer::~Renderer() { }



CFDG::~CFDG() { }


extern "C" {
    int yyparse();
}

Builder* builder = 0;

CFDG*
CFDG::ParseFile(const char* firstFile, AbstractSystem* system, int variation)
{
    Builder b(new CFDGImpl(system), variation);
    builder = &b;

    yg_Reset();
    
    b.m_filesToLoad.push(firstFile);

    while (!b.m_filesToLoad.empty()) {
        string fname = b.m_filesToLoad.front();
        b.m_filesToLoad.pop();
        
        b.m_input = system->openFileForRead(fname);
        if (!b.m_input || !b.m_input->good()) {
			delete b.m_input;
			b.m_input = 0;
            system->message(true, "Couldn't open rules file %s", fname.c_str());
            return 0;
        }
        
        b.m_currentPath = fname;
        system->message(false, "Reading rules file %s", fname.c_str());

        yg_ResetForNextFile();
        
        int yyresult = yyparse();

        if (b.m_input != &cin) delete b.m_input;
        b.m_input = 0;
        
        if (yyresult != 0)
            return 0;
    }
    
    if (b.m_CFDG->getInitialShape().mShapeType < 0) {
        system->message(true, "No startshape declared.");
        return 0;
    }

    b.m_CFDG->rulesLoaded();
    system->message(false, "%d rules loaded", b.m_CFDG->numRules());
    
    CFDG* result = b.m_CFDG;
    b.m_CFDG = 0;
    builder = 0;
    return result;
}