more warning cleanup, makedefs grep bits (trunk only)

drop -Wcast-qual
warning cleanup (lev_comp)
comment bits
makedefs grep cleanup: drop magic constant, add --grep-define, --grep-undef,
 #ifdef out code not needed yet, update mdgrep.h, mdgrep.pl
This commit is contained in:
keni
2008-04-22 23:20:44 +00:00
parent 7b2fb4d0b5
commit c7858a6d37
6 changed files with 66 additions and 23 deletions

View File

@@ -45,7 +45,7 @@ GAMEGRP = $(GAMEUID)
#CC=gcc -W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
CC=gcc -Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
CC=gcc -Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN
#
# You shouldn't need to change anything below here.
@@ -131,10 +131,10 @@ ifdef WANT_WIN_X11
endif
endif
CC=gcc -W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
# ~/Library/Preferences/NetHack Defaults
# OPTIONS=name:player,number_pad,menustyle:partial,!time,showexp
# OPTIONS=hilite_pet,toptenwin,msghistory:200,windowtype:Qt
#
# Install.Qt mentions a patch for macos - it's not there.
# Install.Qt mentions a patch for macos - it's not there (it seems to be in the Qt binary
# package under the docs directory).

View File

@@ -70,7 +70,7 @@ void FDECL(init_yyout, (FILE *));
*/
extern YYSTYPE yylval;
int line_number = 1, colon_line_number = 1;
int nh_line_number = 1, colon_line_number = 1;
static char map[4096];
static int map_cnt = 0;
@@ -92,14 +92,14 @@ static int map_cnt = 0;
int len = yyleng;
/* convert \r\n to \n */
if (len >= 2 && yytext[len - 2] == '\r') len -= 1;
line_number++;
nh_line_number++;
(void) strncpy(map + map_cnt, yytext, len);
map_cnt += len;
map[map_cnt - 1] = '\n';
map[map_cnt] = '\0';
}
^#.*\n { line_number++; }
: { colon_line_number = line_number; return ':'; }
^#.*\n { nh_line_number++; }
: { colon_line_number = nh_line_number; return ':'; }
MESSAGE return MESSAGE_ID;
MAZE return MAZE_ID;
NOMAP return NOMAP_ID;
@@ -107,7 +107,7 @@ LEVEL return LEVEL_ID;
INIT_MAP return LEV_INIT_ID;
FLAGS return FLAGS_ID;
GEOMETRY return GEOMETRY_ID;
^MAP\r?\n { BEGIN(MAPC); line_number++; }
^MAP\r?\n { BEGIN(MAPC); nh_line_number++; }
OBJECT return OBJECT_ID;
CONTAINER return COBJECT_ID;
MONSTER return MONSTER_ID;
@@ -206,7 +206,7 @@ shortsighted { yylval.i=SHORTSIGHTED; return FLAG_TYPE; }
yylval.map = (char *) alloc(strlen(yytext+1)+1);
Strcpy(yylval.map, yytext+1); /* Discard the first \" */
return STRING; }
\r?\n { line_number++; }
\r?\n { nh_line_number++; }
[ \t]+ ;
'\\.' { yylval.i = yytext[2]; return CHAR; }
'.' { yylval.i = yytext[1]; return CHAR; }

View File

@@ -209,7 +209,7 @@ extern unsigned int nfountain, npool, nsink;
extern unsigned int max_x_map, max_y_map;
extern int line_number, colon_line_number;
extern int nh_line_number, colon_line_number;
int
main(argc, argv)
@@ -282,7 +282,7 @@ char **argv;
} else {
init_yyin(fin);
(void) yyparse();
line_number = 1;
nh_line_number = 1;
if (fatal_error > 0) {
errors_encountered = TRUE;
fatal_error = 0;
@@ -308,7 +308,7 @@ yyerror(s)
const char *s;
{
(void) fprintf(stderr, "%s: line %d : %s\n", fname,
(*s >= 'A' && *s <= 'Z') ? colon_line_number : line_number, s);
(*s >= 'A' && *s <= 'Z') ? colon_line_number : nh_line_number, s);
if (++fatal_error > MAX_ERRORS) {
(void) fprintf(stderr,"Too many errors, good bye!\n");
exit(EXIT_FAILURE);

View File

@@ -348,9 +348,16 @@ char *options;
static FILE *inputfp;
static FILE *outputfp;
#define TODO_GREP 1;
struct grep_var {
const char *name;
int is_defined; /* 0 undef; 1 defined */
};
/* struct grep_var grep_vars[] and TODO_* constants in include file: */
#include "mdgrep.h"
static void NDECL(do_grep);
static void NDECL(do_grep_showvars);
static struct grep_var *FDECL(grepsearch, (char *));
static int grep_trace = 0;
static void
@@ -403,7 +410,7 @@ do_ext_makedefs(int argc, char **argv){
Fprintf(stderr, "Can't do grep and something else.\n");
exit(EXIT_FAILURE);
}
todo = 1;
todo = TODO_GREP;
CONTINUE;
}
IS_OPTION("grep-showvars"){
@@ -414,11 +421,29 @@ do_ext_makedefs(int argc, char **argv){
grep_trace = 1;
CONTINUE;
}
#ifdef notyet
IS_OPTION("grep-define"){
CONSUME;
struct grep_var *p = grepsearch(argv[0]);
if(p){
p->is_defined = 1;
} else {
Fprintf(stderr, "Unknown symbol '%s'\n", argv[0]);
exit(EXIT_FAILURE);
}
CONTINUE;
}
IS_OPTION("grep-undef"){
CONSUME;
struct grep_var *p = grepsearch(argv[0]);
if(p){
p->is_defined = 0;
} else {
Fprintf(stderr, "Unknown symbol '%s'\n", argv[0]);
exit(EXIT_FAILURE);
}
CONTINUE;
}
#ifdef notyet
IS_OPTION("help"){
}
#endif
@@ -438,7 +463,7 @@ do_ext_makedefs(int argc, char **argv){
case 0:
Fprintf(stderr, "Nothing to do?\n");
exit(EXIT_FAILURE);
case 1:
case TODO_GREP:
do_grep(); break;
}
}
@@ -473,7 +498,9 @@ do_ext_makedefs(int argc, char **argv){
*/
#define GREP_MAGIC '^'
#define GREP_STACK_SIZE 100
#ifdef notyet
static int grep_rewrite = 0; /* need to (possibly) rewrite lines */
#endif
static int grep_writing = 1; /* need to copy lines to output */
static int grep_errors = 0;
static int grep_sp = 0;
@@ -484,13 +511,6 @@ static int grep_sp = 0;
static int grep_stack[GREP_STACK_SIZE] = {ST_LD(1,0)};
static int grep_lineno = 0;
struct grep_var {
const char *name;
int is_defined; /* 0 undef; 1 defined */
};
/* struct grep_var grep_vars[] in include file: */
#include "mdgrep.h"
static void
do_grep_showvars(){
int x;
@@ -627,6 +647,7 @@ do_grep_control(buf)
return NULL;
}
#ifdef notyet
static void
do_grep_rewrite(buf)
char *buf;
@@ -634,6 +655,7 @@ do_grep_rewrite(buf)
/* no language features use this yet */
return;
}
#endif
static void
do_grep(){
@@ -670,8 +692,10 @@ do_grep(){
} else {
buf1 = buf;
}
#ifdef notyet
if(grep_rewrite)
do_grep_rewrite(buf1);
#endif
if(grep_writing)
Fprintf(outputfp, "%s\n", buf1);
}

View File

@@ -264,4 +264,7 @@ static struct grep_var grep_vars[]={
#endif
{0,0}
};
/* Command ids */
#define TODO_GREP 1
/* End of file */

View File

@@ -3,6 +3,10 @@
# Copyright (c) Kenneth Lorber, Kensington, Maryland, 2008
# NetHack may be freely redistributed. See license for details.
# MAKEDEFS:
@commands = qw/grep/;
# GREP:
# Operating Systems:
@os = qw/WIN32 MSDOS VMS UNIX TOS AMIGA MAC WINNT __BEOS__ WIN_CE OS2
WIN_CE_SMARTPHONE WIN_CE_POCKETPC WIN_CE_PS2xx
@@ -67,6 +71,8 @@ sub gen_magic {
}
}
# NB: Do NOT make grep_vars const - it needs to be writable for some debugging
# options.
sub gen_file {
print OUT "static struct grep_var grep_vars[]={\n";
foreach(@_){
@@ -87,8 +93,18 @@ E_O_M
print OUT "\t{0,0}\n};\n";
}
sub gen_commands {
local($x) = 1;
print OUT "\n/* Command ids */\n";
foreach(@commands){
print OUT "#define TODO_\U$_\E $x\n";
}
print OUT "\n";
}
&start_file;
&gen_magic(0, @const_false);
&gen_magic(1, @const_true);
&gen_file(sort(@os,@win,@feature,@misc,@const_false,@const_true));
&gen_commands;
&end_file;