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
+3 -3
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 -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. # You shouldn't need to change anything below here.
@@ -131,10 +131,10 @@ ifdef WANT_WIN_X11
endif endif
endif endif
CC=gcc -W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
# ~/Library/Preferences/NetHack Defaults # ~/Library/Preferences/NetHack Defaults
# OPTIONS=name:player,number_pad,menustyle:partial,!time,showexp # OPTIONS=name:player,number_pad,menustyle:partial,!time,showexp
# OPTIONS=hilite_pet,toptenwin,msghistory:200,windowtype:Qt # 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).
+6 -6
View File
@@ -70,7 +70,7 @@ void FDECL(init_yyout, (FILE *));
*/ */
extern YYSTYPE yylval; 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 char map[4096];
static int map_cnt = 0; static int map_cnt = 0;
@@ -92,14 +92,14 @@ static int map_cnt = 0;
int len = yyleng; int len = yyleng;
/* convert \r\n to \n */ /* convert \r\n to \n */
if (len >= 2 && yytext[len - 2] == '\r') len -= 1; if (len >= 2 && yytext[len - 2] == '\r') len -= 1;
line_number++; nh_line_number++;
(void) strncpy(map + map_cnt, yytext, len); (void) strncpy(map + map_cnt, yytext, len);
map_cnt += len; map_cnt += len;
map[map_cnt - 1] = '\n'; map[map_cnt - 1] = '\n';
map[map_cnt] = '\0'; map[map_cnt] = '\0';
} }
^#.*\n { line_number++; } ^#.*\n { nh_line_number++; }
: { colon_line_number = line_number; return ':'; } : { colon_line_number = nh_line_number; return ':'; }
MESSAGE return MESSAGE_ID; MESSAGE return MESSAGE_ID;
MAZE return MAZE_ID; MAZE return MAZE_ID;
NOMAP return NOMAP_ID; NOMAP return NOMAP_ID;
@@ -107,7 +107,7 @@ LEVEL return LEVEL_ID;
INIT_MAP return LEV_INIT_ID; INIT_MAP return LEV_INIT_ID;
FLAGS return FLAGS_ID; FLAGS return FLAGS_ID;
GEOMETRY return GEOMETRY_ID; GEOMETRY return GEOMETRY_ID;
^MAP\r?\n { BEGIN(MAPC); line_number++; } ^MAP\r?\n { BEGIN(MAPC); nh_line_number++; }
OBJECT return OBJECT_ID; OBJECT return OBJECT_ID;
CONTAINER return COBJECT_ID; CONTAINER return COBJECT_ID;
MONSTER return MONSTER_ID; MONSTER return MONSTER_ID;
@@ -206,7 +206,7 @@ shortsighted { yylval.i=SHORTSIGHTED; return FLAG_TYPE; }
yylval.map = (char *) alloc(strlen(yytext+1)+1); yylval.map = (char *) alloc(strlen(yytext+1)+1);
Strcpy(yylval.map, yytext+1); /* Discard the first \" */ Strcpy(yylval.map, yytext+1); /* Discard the first \" */
return STRING; } return STRING; }
\r?\n { line_number++; } \r?\n { nh_line_number++; }
[ \t]+ ; [ \t]+ ;
'\\.' { yylval.i = yytext[2]; return CHAR; } '\\.' { yylval.i = yytext[2]; return CHAR; }
'.' { yylval.i = yytext[1]; return CHAR; } '.' { yylval.i = yytext[1]; return CHAR; }
+3 -3
View File
@@ -209,7 +209,7 @@ extern unsigned int nfountain, npool, nsink;
extern unsigned int max_x_map, max_y_map; 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 int
main(argc, argv) main(argc, argv)
@@ -282,7 +282,7 @@ char **argv;
} else { } else {
init_yyin(fin); init_yyin(fin);
(void) yyparse(); (void) yyparse();
line_number = 1; nh_line_number = 1;
if (fatal_error > 0) { if (fatal_error > 0) {
errors_encountered = TRUE; errors_encountered = TRUE;
fatal_error = 0; fatal_error = 0;
@@ -308,7 +308,7 @@ yyerror(s)
const char *s; const char *s;
{ {
(void) fprintf(stderr, "%s: line %d : %s\n", fname, (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) { if (++fatal_error > MAX_ERRORS) {
(void) fprintf(stderr,"Too many errors, good bye!\n"); (void) fprintf(stderr,"Too many errors, good bye!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
+35 -11
View File
@@ -348,9 +348,16 @@ char *options;
static FILE *inputfp; static FILE *inputfp;
static FILE *outputfp; 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);
static void NDECL(do_grep_showvars); static void NDECL(do_grep_showvars);
static struct grep_var *FDECL(grepsearch, (char *));
static int grep_trace = 0; static int grep_trace = 0;
static void static void
@@ -403,7 +410,7 @@ do_ext_makedefs(int argc, char **argv){
Fprintf(stderr, "Can't do grep and something else.\n"); Fprintf(stderr, "Can't do grep and something else.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
todo = 1; todo = TODO_GREP;
CONTINUE; CONTINUE;
} }
IS_OPTION("grep-showvars"){ IS_OPTION("grep-showvars"){
@@ -414,11 +421,29 @@ do_ext_makedefs(int argc, char **argv){
grep_trace = 1; grep_trace = 1;
CONTINUE; CONTINUE;
} }
#ifdef notyet
IS_OPTION("grep-define"){ 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"){ 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"){ IS_OPTION("help"){
} }
#endif #endif
@@ -438,7 +463,7 @@ do_ext_makedefs(int argc, char **argv){
case 0: case 0:
Fprintf(stderr, "Nothing to do?\n"); Fprintf(stderr, "Nothing to do?\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
case 1: case TODO_GREP:
do_grep(); break; do_grep(); break;
} }
} }
@@ -473,7 +498,9 @@ do_ext_makedefs(int argc, char **argv){
*/ */
#define GREP_MAGIC '^' #define GREP_MAGIC '^'
#define GREP_STACK_SIZE 100 #define GREP_STACK_SIZE 100
#ifdef notyet
static int grep_rewrite = 0; /* need to (possibly) rewrite lines */ 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_writing = 1; /* need to copy lines to output */
static int grep_errors = 0; static int grep_errors = 0;
static int grep_sp = 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_stack[GREP_STACK_SIZE] = {ST_LD(1,0)};
static int grep_lineno = 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 static void
do_grep_showvars(){ do_grep_showvars(){
int x; int x;
@@ -627,6 +647,7 @@ do_grep_control(buf)
return NULL; return NULL;
} }
#ifdef notyet
static void static void
do_grep_rewrite(buf) do_grep_rewrite(buf)
char *buf; char *buf;
@@ -634,6 +655,7 @@ do_grep_rewrite(buf)
/* no language features use this yet */ /* no language features use this yet */
return; return;
} }
#endif
static void static void
do_grep(){ do_grep(){
@@ -670,8 +692,10 @@ do_grep(){
} else { } else {
buf1 = buf; buf1 = buf;
} }
#ifdef notyet
if(grep_rewrite) if(grep_rewrite)
do_grep_rewrite(buf1); do_grep_rewrite(buf1);
#endif
if(grep_writing) if(grep_writing)
Fprintf(outputfp, "%s\n", buf1); Fprintf(outputfp, "%s\n", buf1);
} }
+3
View File
@@ -264,4 +264,7 @@ static struct grep_var grep_vars[]={
#endif #endif
{0,0} {0,0}
}; };
/* Command ids */
#define TODO_GREP 1
/* End of file */ /* End of file */
+16
View File
@@ -3,6 +3,10 @@
# Copyright (c) Kenneth Lorber, Kensington, Maryland, 2008 # Copyright (c) Kenneth Lorber, Kensington, Maryland, 2008
# NetHack may be freely redistributed. See license for details. # NetHack may be freely redistributed. See license for details.
# MAKEDEFS:
@commands = qw/grep/;
# GREP:
# Operating Systems: # Operating Systems:
@os = qw/WIN32 MSDOS VMS UNIX TOS AMIGA MAC WINNT __BEOS__ WIN_CE OS2 @os = qw/WIN32 MSDOS VMS UNIX TOS AMIGA MAC WINNT __BEOS__ WIN_CE OS2
WIN_CE_SMARTPHONE WIN_CE_POCKETPC WIN_CE_PS2xx 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 { sub gen_file {
print OUT "static struct grep_var grep_vars[]={\n"; print OUT "static struct grep_var grep_vars[]={\n";
foreach(@_){ foreach(@_){
@@ -87,8 +93,18 @@ E_O_M
print OUT "\t{0,0}\n};\n"; 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; &start_file;
&gen_magic(0, @const_false); &gen_magic(0, @const_false);
&gen_magic(1, @const_true); &gen_magic(1, @const_true);
&gen_file(sort(@os,@win,@feature,@misc,@const_false,@const_true)); &gen_file(sort(@os,@win,@feature,@misc,@const_false,@const_true));
&gen_commands;
&end_file; &end_file;