1 |
%{ |
2 |
/* |
3 |
* static char *reader_l = |
4 |
* "$Id$"; |
5 |
*/ |
6 |
|
7 |
/* |
8 |
CrossFire, A Multiplayer game for X-windows |
9 |
|
10 |
Copyright (C) 1994 Mark Wedel |
11 |
Copyright (C) 1992 Frank Tore Johansen |
12 |
|
13 |
This program is free software; you can redistribute it and/or modify |
14 |
it under the terms of the GNU General Public License as published by |
15 |
the Free Software Foundation; either version 2 of the License, or |
16 |
(at your option) any later version. |
17 |
|
18 |
This program is distributed in the hope that it will be useful, |
19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 |
GNU General Public License for more details. |
22 |
|
23 |
You should have received a copy of the GNU General Public License |
24 |
along with this program; if not, write to the Free Software |
25 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 |
|
27 |
The author can be reached via e-mail to mark@pyramid.com |
28 |
*/ |
29 |
|
30 |
|
31 |
|
32 |
#include <global.h> |
33 |
#include <loader.h> |
34 |
#include <newserver.h> |
35 |
#include <random_map.h> |
36 |
|
37 |
#define LO_REPEAT 0 |
38 |
#define LO_LINEMODE 1 |
39 |
#define LO_NEWFILE 2 |
40 |
#define LO_NOREAD 3 |
41 |
|
42 |
int yyerror(char *s) |
43 |
{ |
44 |
LOG(llevError, "%s: %s\n", s, yytext); |
45 |
return -1; |
46 |
} |
47 |
|
48 |
#define YY_DECL int rmap_lex_read(RMParms *RP) |
49 |
|
50 |
static char *rmap_yval(); |
51 |
|
52 |
static int rmap_lex_error; |
53 |
|
54 |
|
55 |
#define IVAL atoi(rmap_yval()) |
56 |
#define FVAL atof(rmap_yval()) |
57 |
|
58 |
%} |
59 |
|
60 |
|
61 |
|
62 |
S [ \t]+.+ |
63 |
WS [ \t]* |
64 |
|
65 |
%x MESSAGE |
66 |
|
67 |
/* Don't have to link with -lfl with this */ |
68 |
%option noyywrap |
69 |
|
70 |
/* need yy_push_state, yy_pop_state */ |
71 |
%option stack |
72 |
|
73 |
%% |
74 |
|
75 |
%{ |
76 |
/* Declare some local variables */ |
77 |
|
78 |
rmap_lex_error=0; |
79 |
|
80 |
%} |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
^wallstyle{S} strcpy(RP->wallstyle,rmap_yval()); |
86 |
^floorstyle{S} strcpy(RP->floorstyle,rmap_yval()); |
87 |
^monsterstyle{S} strcpy(RP->monsterstyle,rmap_yval()); |
88 |
^treasurestyle{S} strcpy(RP->treasurestyle,rmap_yval()); |
89 |
^layoutstyle{S} strcpy(RP->layoutstyle,rmap_yval()); |
90 |
^doorstyle{S} strcpy(RP->doorstyle,rmap_yval()); |
91 |
^decorstyle{S} strcpy(RP->decorstyle,rmap_yval()); |
92 |
^xsize{S} RP->Xsize = IVAL; |
93 |
^ysize{S} RP->Ysize = IVAL; |
94 |
^expand2x{S} RP->expand2x = IVAL; |
95 |
^layoutoptions1{S} RP->layoutoptions1 = IVAL; |
96 |
^layoutoptions2{S} RP->layoutoptions2 = IVAL; |
97 |
^layoutoptions3{S} RP->layoutoptions3 = IVAL; |
98 |
^symmetry{S} RP->symmetry = IVAL; |
99 |
^difficulty{S} RP->difficulty = IVAL; |
100 |
^difficulty_increase{S} RP->difficulty_increase = FVAL; |
101 |
^decoroptions{S} RP->decoroptions = IVAL; |
102 |
^exitstyle{S} strcpy(RP->exitstyle,rmap_yval()); |
103 |
^dungeon_level{S} RP->dungeon_level = IVAL; |
104 |
^dungeon_depth{S} RP->dungeon_depth = IVAL; |
105 |
^final_map{S} strcpy(RP->final_map,rmap_yval()); |
106 |
^orientation{S} RP-> orientation = IVAL; |
107 |
^origin_x{S} RP->origin_x = IVAL; |
108 |
^origin_y{S} RP-> origin_y = IVAL; |
109 |
^origin_map{S} strcpy(RP->origin_map,rmap_yval()); |
110 |
^random_seed{S} RP->random_seed = IVAL; |
111 |
^treasureoptions{S} RP->treasureoptions = IVAL; |
112 |
^exit_on_final_map{S} strcpy(RP->exit_on_final_map,rmap_yval()); |
113 |
|
114 |
<*>(^{WS}$)|\n {/* ignore empty lines, newlines we don't do above */} |
115 |
#.*\n {} |
116 |
|
117 |
<<EOF>> {/* If we got an error, return the error. Otherwise, return that we got EOF */ |
118 |
if (rmap_lex_error!=0) return rmap_lex_error; else return LL_EOF;} |
119 |
.* { yyerror( "Unrecognized string"); rmap_lex_error= -1; } |
120 |
%% |
121 |
|
122 |
/*int yyerror(char *s) |
123 |
{ |
124 |
return -1; |
125 |
} |
126 |
*/ |
127 |
|
128 |
/* Our save file syntax is very simple, so we can use a very simple |
129 |
* processing mechanism here instead using something like bison |
130 |
* This skips over the space and returns the value, or "" if no value |
131 |
* is found. |
132 |
*/ |
133 |
static char *rmap_yval() |
134 |
{ |
135 |
static char *em=""; |
136 |
char *cp; |
137 |
|
138 |
cp=strchr(yytext,' '); |
139 |
if (cp) return cp+1; |
140 |
else return em; |
141 |
} |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
int load_parameters(FILE *fp, int bufstate,RMParms *RP) { |
147 |
int retval; |
148 |
char inbuf[MAX_BUF]; |
149 |
|
150 |
if (bufstate==LO_NEWFILE || bufstate==LO_NOREAD) { |
151 |
yy_delete_buffer(YY_CURRENT_BUFFER); |
152 |
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); |
153 |
if (bufstate==LO_NOREAD) return LL_NORMAL; |
154 |
} |
155 |
if (bufstate==LO_LINEMODE) { |
156 |
YY_BUFFER_STATE yybufstate; |
157 |
while (fgets(inbuf, MAX_BUF-3, fp)) { |
158 |
yybufstate=yy_scan_string(inbuf); |
159 |
retval=rmap_lex_read(RP); |
160 |
yy_delete_buffer(yybufstate); |
161 |
if (retval==LL_NORMAL) return retval; |
162 |
} |
163 |
return LL_EOF; |
164 |
} |
165 |
|
166 |
retval=rmap_lex_read(RP); |
167 |
/* LOG(llevDebug," load completed, object=%s\n",op->name);*/ |
168 |
return retval; |
169 |
} |
170 |
|
171 |
|
172 |
/* This takes a buffer, scans it for variables, and sets those variables |
173 |
* as appropriate in op. |
174 |
* |
175 |
* This function appears to be used in only 2 places - in crossedit to |
176 |
* override values and in c_wiz to mutate values. |
177 |
*/ |
178 |
int set_random_map_variable(RMParms *rp,const char *buf) { |
179 |
YY_BUFFER_STATE yybufstate; |
180 |
int retval; |
181 |
|
182 |
yybufstate=yy_scan_string(buf); |
183 |
retval=rmap_lex_read(rp); |
184 |
yy_delete_buffer(yybufstate); |
185 |
return retval; |
186 |
} |