1 |
%{ |
2 |
/* |
3 |
* static char *reader_l = |
4 |
* "$Id: reader.l,v 1.9 2005/08/12 13:46:34 ryo_saeba Exp $"; |
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 |
|
38 |
#define YY_DECL int rmap_lex_read(RMParms *RP) |
39 |
|
40 |
static char *rmap_yval(); |
41 |
|
42 |
static int rmap_lex_error; |
43 |
|
44 |
|
45 |
#define IVAL atoi(rmap_yval()) |
46 |
#define FVAL atof(rmap_yval()) |
47 |
|
48 |
%} |
49 |
|
50 |
|
51 |
|
52 |
S [ \t]+.+ |
53 |
WS [ \t]* |
54 |
|
55 |
%x MESSAGE |
56 |
|
57 |
/* Don't have to link with -lfl with this */ |
58 |
%option noyywrap |
59 |
|
60 |
/* need yy_push_state, yy_pop_state */ |
61 |
%option stack |
62 |
|
63 |
%% |
64 |
|
65 |
%{ |
66 |
/* Declare some local variables */ |
67 |
|
68 |
rmap_lex_error=0; |
69 |
|
70 |
%} |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
^wallstyle{S} strcpy(RP->wallstyle,rmap_yval()); |
76 |
^floorstyle{S} strcpy(RP->floorstyle,rmap_yval()); |
77 |
^monsterstyle{S} strcpy(RP->monsterstyle,rmap_yval()); |
78 |
^treasurestyle{S} strcpy(RP->treasurestyle,rmap_yval()); |
79 |
^layoutstyle{S} strcpy(RP->layoutstyle,rmap_yval()); |
80 |
^doorstyle{S} strcpy(RP->doorstyle,rmap_yval()); |
81 |
^decorstyle{S} strcpy(RP->decorstyle,rmap_yval()); |
82 |
^xsize{S} RP->Xsize = IVAL; |
83 |
^ysize{S} RP->Ysize = IVAL; |
84 |
^expand2x{S} RP->expand2x = IVAL; |
85 |
^layoutoptions1{S} RP->layoutoptions1 = IVAL; |
86 |
^layoutoptions2{S} RP->layoutoptions2 = IVAL; |
87 |
^layoutoptions3{S} RP->layoutoptions3 = IVAL; |
88 |
^symmetry{S} RP->symmetry = IVAL; |
89 |
^difficulty{S} RP->difficulty = IVAL; |
90 |
^difficulty_increase{S} RP->difficulty_increase = FVAL; |
91 |
^decoroptions{S} RP->decoroptions = IVAL; |
92 |
^exitstyle{S} strcpy(RP->exitstyle,rmap_yval()); |
93 |
^dungeon_level{S} RP->dungeon_level = IVAL; |
94 |
^dungeon_depth{S} RP->dungeon_depth = IVAL; |
95 |
^final_map{S} strcpy(RP->final_map,rmap_yval()); |
96 |
^orientation{S} RP-> orientation = IVAL; |
97 |
^origin_x{S} RP->origin_x = IVAL; |
98 |
^origin_y{S} RP-> origin_y = IVAL; |
99 |
^origin_map{S} strcpy(RP->origin_map,rmap_yval()); |
100 |
^random_seed{S} RP->random_seed = IVAL; |
101 |
^treasureoptions{S} RP->treasureoptions = IVAL; |
102 |
^exit_on_final_map{S} strcpy(RP->exit_on_final_map,rmap_yval()); |
103 |
|
104 |
<*>(^{WS}$)|\n {/* ignore empty lines, newlines we don't do above */} |
105 |
#.*\n {} |
106 |
|
107 |
<<EOF>> {/* If we got an error, return the error. Otherwise, return that we got EOF */ |
108 |
if (rmap_lex_error!=0) return rmap_lex_error; else return LL_EOF;} |
109 |
.* { yyerror( "Unrecognized string"); rmap_lex_error= -1; } |
110 |
%% |
111 |
|
112 |
/*int yyerror(char *s) |
113 |
{ |
114 |
return -1; |
115 |
} |
116 |
*/ |
117 |
|
118 |
/* Our save file syntax is very simple, so we can use a very simple |
119 |
* processing mechanism here instead using something like bison |
120 |
* This skips over the space and returns the value, or "" if no value |
121 |
* is found. |
122 |
*/ |
123 |
static char *rmap_yval() |
124 |
{ |
125 |
static char *em=""; |
126 |
char *cp; |
127 |
|
128 |
cp=strchr(yytext,' '); |
129 |
if (cp) return cp+1; |
130 |
else return em; |
131 |
} |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
int load_parameters(FILE *fp, int bufstate,RMParms *RP) { |
137 |
int retval; |
138 |
char inbuf[MAX_BUF]; |
139 |
|
140 |
if (bufstate==LO_NEWFILE || bufstate==LO_NOREAD) { |
141 |
yy_delete_buffer(YY_CURRENT_BUFFER); |
142 |
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); |
143 |
if (bufstate==LO_NOREAD) return LL_NORMAL; |
144 |
} |
145 |
if (bufstate==LO_LINEMODE) { |
146 |
YY_BUFFER_STATE yybufstate; |
147 |
while (fgets(inbuf, MAX_BUF-3, fp)) { |
148 |
yybufstate=yy_scan_string(inbuf); |
149 |
retval=rmap_lex_read(RP); |
150 |
yy_delete_buffer(yybufstate); |
151 |
if (retval==LL_NORMAL) return retval; |
152 |
} |
153 |
return LL_EOF; |
154 |
} |
155 |
|
156 |
retval=rmap_lex_read(RP); |
157 |
/* LOG(llevDebug," load completed, object=%s\n",op->name);*/ |
158 |
return retval; |
159 |
} |
160 |
|
161 |
|
162 |
/* This takes a buffer, scans it for variables, and sets those variables |
163 |
* as appropriate in op. |
164 |
* |
165 |
* This function appears to be used in only 2 places - in crossedit to |
166 |
* override values and in c_wiz to mutate values. |
167 |
*/ |
168 |
int set_random_map_variable(RMParms *rp,const char *buf) { |
169 |
YY_BUFFER_STATE yybufstate; |
170 |
int retval; |
171 |
|
172 |
yybufstate=yy_scan_string(buf); |
173 |
retval=rmap_lex_read(rp); |
174 |
yy_delete_buffer(yybufstate); |
175 |
return retval; |
176 |
} |