lev_comp update for older Unix system
Increase the lex paramaters in lev_comp.l and replace use of snprintf with sprintf in lev_comp.y and lev_main.c. Also some reformatting for lev_comp.y, but I gave up pretty quickly: some early tab replacement and adjusting of the spacing for casts.
This commit is contained in:
103
util/lev_comp.y
103
util/lev_comp.y
@@ -1,6 +1,6 @@
|
||||
%{
|
||||
/* NetHack 3.6 lev_comp.y $NHDT-Date: 1448074095 2015/11/21 02:48:15 $ $NHDT-Branch: master $:$NHDT-Revision: 1.18 $ */
|
||||
/* Copyright (c) 1989 by Jean-Christophe Collet */
|
||||
/* Copyright (c) 1989 by Jean-Christophe Collet */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
/*
|
||||
@@ -18,27 +18,27 @@
|
||||
* and AIX will still see the directive.
|
||||
*/
|
||||
#ifdef _AIX
|
||||
#pragma alloca /* keep leading space! */
|
||||
#pragma alloca /* keep leading space! */
|
||||
#endif
|
||||
|
||||
#define SPEC_LEV /* for USE_OLDARGS (sp_lev.h) */
|
||||
#include "hack.h"
|
||||
#include "sp_lev.h"
|
||||
|
||||
#define ERR (-1)
|
||||
#define ERR (-1)
|
||||
/* many types of things are put in chars for transference to NetHack.
|
||||
* since some systems will use signed chars, limit everybody to the
|
||||
* same number for portability.
|
||||
*/
|
||||
#define MAX_OF_TYPE 128
|
||||
#define MAX_OF_TYPE 128
|
||||
|
||||
#define MAX_NESTED_IFS 20
|
||||
#define MAX_NESTED_IFS 20
|
||||
#define MAX_SWITCH_CASES 20
|
||||
|
||||
#define New(type) \
|
||||
(type *) memset((genericptr_t)alloc(sizeof(type)), 0, sizeof(type))
|
||||
#define NewTab(type, size) (type **) alloc(sizeof(type *) * size)
|
||||
#define Free(ptr) free((genericptr_t)ptr)
|
||||
#define New(type) \
|
||||
(type *) memset((genericptr_t) alloc(sizeof (type)), 0, sizeof (type))
|
||||
#define NewTab(type, size) (type **) alloc(sizeof (type *) * size)
|
||||
#define Free(ptr) free((genericptr_t) ptr)
|
||||
|
||||
extern void VDECL(lc_error, (const char *, ...));
|
||||
extern void VDECL(lc_warning, (const char *, ...));
|
||||
@@ -58,22 +58,24 @@ extern char FDECL(what_map_char, (CHAR_P));
|
||||
extern void FDECL(scan_map, (char *, sp_lev *));
|
||||
extern void FDECL(add_opcode, (sp_lev *, int, genericptr_t));
|
||||
extern genericptr_t FDECL(get_last_opcode_data1, (sp_lev *, int));
|
||||
extern genericptr_t FDECL(get_last_opcode_data2, (sp_lev *, int,int));
|
||||
extern genericptr_t FDECL(get_last_opcode_data2, (sp_lev *, int, int));
|
||||
extern boolean FDECL(check_subrooms, (sp_lev *));
|
||||
extern boolean FDECL(write_level_file, (char *,sp_lev *));
|
||||
extern struct opvar *FDECL(set_opvar_int, (struct opvar *, long));
|
||||
extern void VDECL(add_opvars, (sp_lev *, const char *, ...));
|
||||
extern void FDECL(start_level_def, (sp_lev * *, char *));
|
||||
|
||||
extern struct lc_funcdefs *FDECL(funcdef_new,(long,char *));
|
||||
extern void FDECL(funcdef_free_all,(struct lc_funcdefs *));
|
||||
extern struct lc_funcdefs *FDECL(funcdef_defined,(struct lc_funcdefs *,char *, int));
|
||||
extern struct lc_funcdefs *FDECL(funcdef_new, (long,char *));
|
||||
extern void FDECL(funcdef_free_all, (struct lc_funcdefs *));
|
||||
extern struct lc_funcdefs *FDECL(funcdef_defined, (struct lc_funcdefs *,
|
||||
char *, int));
|
||||
extern char *FDECL(funcdef_paramtypes, (struct lc_funcdefs *));
|
||||
extern char *FDECL(decode_parm_str, (char *));
|
||||
|
||||
extern struct lc_vardefs *FDECL(vardef_new,(long,char *));
|
||||
extern void FDECL(vardef_free_all,(struct lc_vardefs *));
|
||||
extern struct lc_vardefs *FDECL(vardef_defined,(struct lc_vardefs *,char *, int));
|
||||
extern struct lc_vardefs *FDECL(vardef_new, (long,char *));
|
||||
extern void FDECL(vardef_free_all, (struct lc_vardefs *));
|
||||
extern struct lc_vardefs *FDECL(vardef_defined, (struct lc_vardefs *,
|
||||
char *, int));
|
||||
|
||||
extern void NDECL(break_stmt_start);
|
||||
extern void FDECL(break_stmt_end, (sp_lev *));
|
||||
@@ -83,13 +85,14 @@ extern void FDECL(splev_add_from, (sp_lev *, sp_lev *));
|
||||
|
||||
extern void FDECL(check_vardef_type, (struct lc_vardefs *, char *, long));
|
||||
extern void FDECL(vardef_used, (struct lc_vardefs *, char *));
|
||||
extern struct lc_vardefs *FDECL(add_vardef_type, (struct lc_vardefs *, char *, long));
|
||||
extern struct lc_vardefs *FDECL(add_vardef_type, (struct lc_vardefs *,
|
||||
char *, long));
|
||||
|
||||
extern int FDECL(reverse_jmp_opcode, (int));
|
||||
|
||||
struct coord {
|
||||
long x;
|
||||
long y;
|
||||
long x;
|
||||
long y;
|
||||
};
|
||||
|
||||
struct forloopdef {
|
||||
@@ -979,7 +982,7 @@ forstmt_start : FOR_ID any_var_or_unk '=' math_expr_var for_to_span math_expr_va
|
||||
}
|
||||
|
||||
/* first, define a variable for the for-loop end value */
|
||||
snprintf(buf, 255, "%s end", $2);
|
||||
Sprintf(buf, "%s end", $2);
|
||||
/* the value of which is already in stack (the 2nd math_expr) */
|
||||
add_opvars(splev, "iso", VA_PASS3(0, buf, SPO_VAR_INIT));
|
||||
|
||||
@@ -989,7 +992,7 @@ forstmt_start : FOR_ID any_var_or_unk '=' math_expr_var for_to_span math_expr_va
|
||||
add_opvars(splev, "iso", VA_PASS3(0, $2, SPO_VAR_INIT));
|
||||
|
||||
/* calculate value for the loop "step" variable */
|
||||
snprintf(buf2, 255, "%s step", $2);
|
||||
Sprintf(buf2, "%s step", $2);
|
||||
/* end - start */
|
||||
add_opvars(splev, "vvo",
|
||||
VA_PASS3(buf, $2, SPO_MATH_SUB));
|
||||
@@ -1015,9 +1018,10 @@ forstatement : forstmt_start
|
||||
stmt_block
|
||||
{
|
||||
char buf[256], buf2[256];
|
||||
|
||||
n_forloops--;
|
||||
snprintf(buf, 255, "%s step", forloop_list[n_forloops].varname);
|
||||
snprintf(buf2, 255, "%s end", forloop_list[n_forloops].varname);
|
||||
Sprintf(buf, "%s step", forloop_list[n_forloops].varname);
|
||||
Sprintf(buf2, "%s end", forloop_list[n_forloops].varname);
|
||||
/* compare for-loop var to end value */
|
||||
add_opvars(splev, "vvo",
|
||||
VA_PASS3(forloop_list[n_forloops].varname,
|
||||
@@ -1747,8 +1751,8 @@ stair_region : STAIR_ID ':' lev_region ',' lev_region ',' UP_OR_DOWN
|
||||
add_opvars(splev, "iiiii iiiii iiso",
|
||||
VA_PASS14($3.x1, $3.y1, $3.x2, $3.y2, $3.area,
|
||||
$5.x1, $5.y1, $5.x2, $5.y2, $5.area,
|
||||
(long)(($7) ? LR_UPSTAIR : LR_DOWNSTAIR),
|
||||
0, (char *)0, SPO_LEVREGION));
|
||||
(long) (($7) ? LR_UPSTAIR : LR_DOWNSTAIR),
|
||||
0, (char *) 0, SPO_LEVREGION));
|
||||
}
|
||||
;
|
||||
|
||||
@@ -1782,8 +1786,8 @@ branch_region : BRANCH_ID ':' lev_region ',' lev_region
|
||||
add_opvars(splev, "iiiii iiiii iiso",
|
||||
VA_PASS14($3.x1, $3.y1, $3.x2, $3.y2, $3.area,
|
||||
$5.x1, $5.y1, $5.x2, $5.y2, $5.area,
|
||||
(long)LR_BRANCH, 0,
|
||||
(char *)0, SPO_LEVREGION));
|
||||
(long) LR_BRANCH, 0,
|
||||
(char *) 0, SPO_LEVREGION));
|
||||
}
|
||||
;
|
||||
|
||||
@@ -2207,7 +2211,8 @@ encodemonster : STRING
|
||||
lc_error("Unknown monster \"%s\"!", $1);
|
||||
$$ = -1;
|
||||
} else
|
||||
$$ = SP_MONST_PACK(m, def_monsyms[(int)mons[m].mlet].sym);
|
||||
$$ = SP_MONST_PACK(m,
|
||||
def_monsyms[(int) mons[m].mlet].sym);
|
||||
Free($1);
|
||||
}
|
||||
| CHAR
|
||||
@@ -2423,7 +2428,7 @@ func_call_param_list : func_call_param_part
|
||||
| func_call_param_list ',' func_call_param_part
|
||||
{
|
||||
long len = strlen( $1 );
|
||||
char *tmp = (char *)alloc(len + 2);
|
||||
char *tmp = (char *) alloc(len + 2);
|
||||
sprintf(tmp, "%c%s", (char) $3, $1 );
|
||||
Free( $1 );
|
||||
$$ = tmp;
|
||||
@@ -2593,13 +2598,21 @@ lev_region : region
|
||||
| LEV '(' INTEGER ',' INTEGER ',' INTEGER ',' INTEGER ')'
|
||||
{
|
||||
if ($3 <= 0 || $3 >= COLNO)
|
||||
lc_error("Region (%li,%li,%li,%li) out of level range (x1)!", $3, $5, $7, $9);
|
||||
lc_error(
|
||||
"Region (%ld,%ld,%ld,%ld) out of level range (x1)!",
|
||||
$3, $5, $7, $9);
|
||||
else if ($5 < 0 || $5 >= ROWNO)
|
||||
lc_error("Region (%li,%li,%li,%li) out of level range (y1)!", $3, $5, $7, $9);
|
||||
lc_error(
|
||||
"Region (%ld,%ld,%ld,%ld) out of level range (y1)!",
|
||||
$3, $5, $7, $9);
|
||||
else if ($7 <= 0 || $7 >= COLNO)
|
||||
lc_error("Region (%li,%li,%li,%li) out of level range (x2)!", $3, $5, $7, $9);
|
||||
lc_error(
|
||||
"Region (%ld,%ld,%ld,%ld) out of level range (x2)!",
|
||||
$3, $5, $7, $9);
|
||||
else if ($9 < 0 || $9 >= ROWNO)
|
||||
lc_error("Region (%li,%li,%li,%li) out of level range (y2)!", $3, $5, $7, $9);
|
||||
lc_error(
|
||||
"Region (%ld,%ld,%ld,%ld) out of level range (y2)!",
|
||||
$3, $5, $7, $9);
|
||||
$$.x1 = $3;
|
||||
$$.y1 = $5;
|
||||
$$.x2 = $7;
|
||||
@@ -2612,14 +2625,22 @@ region : '(' INTEGER ',' INTEGER ',' INTEGER ',' INTEGER ')'
|
||||
{
|
||||
/* This series of if statements is a hack for MSC 5.1. It seems that its
|
||||
tiny little brain cannot compile if these are all one big if statement. */
|
||||
if ($2 < 0 || $2 > (int)max_x_map)
|
||||
lc_error("Region (%li,%li,%li,%li) out of map range (x1)!", $2, $4, $6, $8);
|
||||
else if ($4 < 0 || $4 > (int)max_y_map)
|
||||
lc_error("Region (%li,%li,%li,%li) out of map range (y1)!", $2, $4, $6, $8);
|
||||
else if ($6 < 0 || $6 > (int)max_x_map)
|
||||
lc_error("Region (%li,%li,%li,%li) out of map range (x2)!", $2, $4, $6, $8);
|
||||
else if ($8 < 0 || $8 > (int)max_y_map)
|
||||
lc_error("Region (%li,%li,%li,%li) out of map range (y2)!", $2, $4, $6, $8);
|
||||
if ($2 < 0 || $2 > (int) max_x_map)
|
||||
lc_error(
|
||||
"Region (%ld,%ld,%ld,%ld) out of map range (x1)!",
|
||||
$2, $4, $6, $8);
|
||||
else if ($4 < 0 || $4 > (int) max_y_map)
|
||||
lc_error(
|
||||
"Region (%ld,%ld,%ld,%ld) out of map range (y1)!",
|
||||
$2, $4, $6, $8);
|
||||
else if ($6 < 0 || $6 > (int) max_x_map)
|
||||
lc_error(
|
||||
"Region (%ld,%ld,%ld,%ld) out of map range (x2)!",
|
||||
$2, $4, $6, $8);
|
||||
else if ($8 < 0 || $8 > (int) max_y_map)
|
||||
lc_error(
|
||||
"Region (%ld,%ld,%ld,%ld) out of map range (y2)!",
|
||||
$2, $4, $6, $8);
|
||||
$$.area = 0;
|
||||
$$.x1 = $2;
|
||||
$$.y1 = $4;
|
||||
|
||||
Reference in New Issue
Block a user