Skip to content

Commit 81cde89

Browse files
author
Marek
committed
Fixes for Wokna ... part I
1 parent 00bdebb commit 81cde89

13 files changed

+156
-51
lines changed

blit.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ blit_screen(unsigned char ignore_bg)
268268
break;
269269
}
270270
/* draw bigger pieces to screen */
271-
line_buf[x] = sc[off = x + yof] ? : 32;
271+
line_buf[x] = sc[off = x + yof] ? sc[off = x + yof] : 32;
272272
for (s = x++; x < SCREEN_X && at[off = x + yof] == attribute &&
273273
at_old[off] == attribute_old; x++)
274-
line_buf[x] = sc[off] ? : 32;
274+
line_buf[x] = sc[off] ? sc[off] : 32;
275275
last_color = attribute;
276276
c_print_l(line_buf + s, x---s);
277277
}

bot.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ void parse_command_line(int argc,char **argv)
10421042
break;
10431043

10441044
case 'p':
1045-
port=strtoul(optarg,&e,10);
1045+
port=(unsigned short)strtoul(optarg,&e,10);
10461046
if (*e){ERROR("Error: Decimal number expected.\n");EXIT(1);}
10471047
break;
10481048
}
@@ -1099,11 +1099,7 @@ int main(int argc,char **argv)
10991099
ERROR("Initialization...\n");
11001100

11011101
last_obj=&objects;
1102-
#ifndef WIN32
11031102
srandom(get_time());
1104-
#else
1105-
srand(get_time());
1106-
#endif
11071103

11081104
const1=random()%50;
11091105
const2=random()%20;

cfg.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
#define DEFAULT_FONT_NAME "-misc-fixed-bold-r-normal-*-13-*-*-*-c-*-iso8859-*"
2323

24-
25-
#define DATA_PATH "data/"
2624
#define LEVEL_FILE "level.dat"
2725
#define GAME_SPRITES_FILE "sprites.dat"
2826
#define BANNER_FILE "banner.dat"
@@ -152,7 +150,11 @@ extern int tri_d;
152150
#define EXIT(a) {exit(a);}
153151
#endif
154152
#define random rand
153+
#define BASE_DIR "."
154+
#define DATA_PATH "data\\"
155155
#else
156+
#define DATA_PATH "data/"
157+
156158
#define long_long long long
157159
#ifdef CLIENT
158160
#define ERROR(a) {if (!console_ok)c_shutdown();fprintf(stderr,a);}

client.c

+19-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#ifndef WIN32
44
#include "config.h"
55
#endif
6-
76
#include <stdio.h>
87
#include <signal.h>
98
#include <math.h>
@@ -242,10 +241,11 @@ int load_cfg(struct config *cfg)
242241

243242
#ifndef WIN32
244243
snprintf(txt, sizeof(txt), "%s/%s",getenv("HOME"),CFG_FILE);
244+
stream=fopen(txt,"r");
245245
#else
246-
snprintf(txt, sizeof(txt), "./%s",CFG_FILE);
246+
snprintf(txt, sizeof(txt), "./%s", CFG_FILE);
247+
fopen_s(&stream, txt, "r");
247248
#endif
248-
stream=fopen(txt,"r");
249249
if (!stream)
250250
return load_default_cfg(cfg, 1);
251251

@@ -299,7 +299,11 @@ void save_cfg(struct config *cfg)
299299
dcfg.color = cfg->color;
300300
}
301301

302+
#ifndef WIN32
302303
stream=fopen(txt,"w");
304+
#else
305+
fopen_s(&stream, txt, "w");
306+
#endif
303307
if (!stream)
304308
return;
305309
fprintf(stream, "%s\n%s\n%d\n%d\n", dcfg.host, dcfg.name,
@@ -1056,9 +1060,9 @@ void change_level(void)
10561060
reinit_area();
10571061

10581062
LEVEL=load_level(level_number);
1059-
snprintf(txt,256,"%s%s%s",DATA_PATH,LEVEL,LEVEL_SPRITES_SUFFIX);
1063+
snprintf(txt,sizeof(txt),"%s%s%s",DATA_PATH,LEVEL,LEVEL_SPRITES_SUFFIX);
10601064
load_sprites(txt);
1061-
snprintf(txt,256,"%s%s%s",DATA_PATH,LEVEL,STATIC_DATA_SUFFIX);
1065+
snprintf(txt,sizeof(txt),"%s%s%s",DATA_PATH,LEVEL,STATIC_DATA_SUFFIX);
10621066
load_data(txt);
10631067
mem_free(LEVEL);
10641068
}
@@ -1309,8 +1313,7 @@ int process_packet(char *packet,int l)
13091313
a=get_int(packet+1);
13101314
if (level_number==a)goto level_changed;
13111315
level_number=a;
1312-
snprintf(txt,256, "Trying to change level to number %d",
1313-
level_number);
1316+
snprintf(txt, sizeof(txt), "Trying to change level to number %d", level_number);
13141317
add_message(txt, M_INFO);
13151318
name=load_level(level_number);
13161319
if (!name) {
@@ -1617,7 +1620,11 @@ void load_banner(char **banner)
16171620
char line[1025];
16181621
int a,b;
16191622

1623+
#ifndef WIN32
16201624
s=fopen(DATA_PATH BANNER_FILE,"r");
1625+
#else
1626+
fopen_s(&s,DATA_PATH BANNER_FILE,"r");
1627+
#endif
16211628
if (!s){shut_down(0);ERROR("Error: Can't load file \""DATA_PATH BANNER_FILE"\".\n");EXIT(1);}
16221629
*banner=mem_alloc(1);
16231630
**banner=0;
@@ -2243,7 +2250,12 @@ int main(int argc,char **argv)
22432250
if (!set_size)c_get_size(&SCREEN_X,&SCREEN_Y);
22442251
init_sprites();
22452252
init_area();
2253+
#ifndef WIN32
22462254
load_sprites(DATA_PATH GAME_SPRITES_FILE);
2255+
#else
2256+
snprintf(txt,sizeof(txt),"%s\\data\\sprites.dat",_getcwd(NULL, 0));
2257+
load_sprites(txt);
2258+
#endif
22472259
/* sprites are stored in memory in this order: game sprites (players,
22482260
* bullets, corpses, blood, meat...) followed by level sprites
22492261
*/

data.c

+43-10
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ void load_data(char * filename)
190190
int n,x,y;
191191
int t;
192192

193+
#ifndef WIN32
193194
if (!(stream=fopen(filename,"rb")))
195+
#else
196+
if (!fopen_s(&stream,filename,"rb"))
197+
#endif
194198
{
195199
char msg[256];
196200
snprintf(msg,256,"Can't open file \"%s\"!\n",filename);
@@ -234,12 +238,17 @@ void load_data(char * filename)
234238
void load_sprites(char * filename)
235239
{
236240
FILE *stream;
237-
static char line[1024];
241+
char line[1024];
238242
char *p,*q;
239243
int l;
240244

241-
stream=fopen(filename,"rb");
242-
if (!stream)
245+
#ifndef WIN32
246+
if(!(stream=fopen(filename,"rb")))
247+
#else
248+
int err;
249+
char r[1024];
250+
if((err = fopen_s(&stream,filename,"rb")) != 0)
251+
#endif
243252
{
244253
char msg[256];
245254
snprintf(msg,256,"Can't open file \"%s\"!\n",filename);
@@ -263,7 +272,13 @@ void load_sprites(char * filename)
263272
if (!sprite_names[n_sprites-1]){ERROR("Memory allocation error!\n");EXIT(1);}
264273
memcpy(sprite_names[n_sprites-1],q,l+1);
265274
_skip_ws(&p);
266-
for (q=p;(*p)!=' '&&(*p)!=9&&(*p)!=10&&(*p);p++);
275+
for (q=p;(*p)!=' '&&(*p)!=9&&(*p)!=10&&(*p);p++)
276+
#ifdef WIN32
277+
if (*p == '/')
278+
*p = '\\';
279+
snprintf(r, sizeof(r), "%s\\%s", _getcwd(NULL, 0), q)
280+
#endif
281+
;
267282
*p=0;p++;
268283
load_sprite(q,sprites+(n_sprites-1));
269284
}
@@ -297,8 +312,14 @@ char *load_level(int level_num)
297312
int a;
298313
FILE *f;
299314

300-
f=fopen(DATA_PATH LEVEL_FILE,"r");
301-
if (!f)return NULL;
315+
#ifndef WIN32
316+
if(!(f=fopen(DATA_PATH LEVEL_FILE,"r")))
317+
#else
318+
int err;
319+
snprintf(txt,sizeof(txt),"%s\\data\\level.dat",_getcwd(NULL, 0));
320+
if((err = fopen_s(&f, txt, "r")) != 0)
321+
#endif
322+
return NULL;
302323

303324
for (a=0;a<=level_num;)
304325
{
@@ -607,8 +628,15 @@ char* md5_level(int level_num)
607628
{
608629
FILE *f;
609630

610-
f=fopen(p,"r");
611-
if (!f){mem_free(result);return NULL;}
631+
#ifndef WIN32
632+
if(!(f=fopen(p,"r")))
633+
#else
634+
if(!fopen_s(&f, p, "r"))
635+
#endif
636+
{
637+
mem_free(result);
638+
return NULL;
639+
}
612640
while (fgets(p,2048,f))
613641
{
614642
if (p[strlen(p)-1]==13)p[strlen(p)-1]=0;
@@ -635,8 +663,13 @@ static int r_access(const char *filename)
635663
#ifdef HAVE_ACCESS
636664
return !access(filename, R_OK);
637665
#else
638-
FILE *f = fopen(filename, "r");
639-
if (f) {
666+
FILE *f;
667+
#ifndef WIN32
668+
if(f = fopen(filename, "r"))
669+
#else
670+
if(fopen_s(&f, filename, "r"))
671+
#endif
672+
{
640673
fclose(f);
641674
return 1;
642675
}

data.h

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33

44
#ifndef WIN32
55
#include "config.h"
6+
#else
7+
/* rezim kompatibility s woknama ... */
8+
#include <direct.h>
9+
#define snprintf(t, s, ...) _snprintf_s(t, s, s, __VA_ARGS__)
10+
#define close(...) while(0);
11+
#define chdir(...) _chdir(__VA_ARGS__)
12+
#define random rand
13+
#define srandom(x) srand((unsigned int)x)
14+
#define sleep(x) Sleep(x)
15+
#define strcat(d, s) strcat_s(d, sizeof(s), s)
616
#endif
717
#include "cfg.h"
818
#include "sprite.h"

error.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
#include <string.h>
66
#include <stdio.h>
77
#include <stdarg.h>
8+
#ifndef WIN32
89
#include <unistd.h>
9-
1010
#include "config.h"
11+
#endif
12+
1113
#include "cfg.h"
1214
#include "error.h"
15+
#include "data.h"
1316

1417
struct memory_list {
1518
int n;
@@ -128,12 +131,14 @@ void er(int b, char *m, va_list l)
128131
sleep(1);
129132
}
130133

134+
#ifndef WIN32
131135
void error(char *m, ...)
132136
{
133137
va_list l;
134138
va_start(l, m);
135139
er(1, m, l);
136140
}
141+
#endif
137142

138143
int errline;
139144
unsigned char *errfile;

error.h

+8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@
55

66

77
#include "cfg.h"
8+
#ifndef WIN32
89
#include "config.h"
10+
#else
11+
#define inline __inline
12+
#endif
913
#include <string.h>
1014

1115
#define DUMMY ((void *)-1L)
1216

1317
void do_not_optimize_here(void *p);
1418
void check_memory_leaks(void);
19+
#ifndef WIN32
1520
void error(char *, ...);
21+
#else
22+
#define error(...) while(0);
23+
#endif
1624
void debug_msg(char *, ...);
1725
void int_error(char *, ...);
1826
extern int errline;

md5hl.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
#include <sys/types.h>
1414
#include <fcntl.h>
15+
#ifndef WIN32
1516
#include <unistd.h>
17+
#endif
1618

1719
#include <errno.h>
1820
#include <stdio.h>
@@ -46,16 +48,23 @@ MD5File (const char *filename, char *buf)
4648
{
4749
unsigned char buffer[BUFSIZ];
4850
MD5_CTX ctx;
49-
int f,i,j;
51+
int i,j;
52+
FILE *f;
5053

5154
MD5Init(&ctx);
52-
f = open(filename,O_RDONLY);
53-
if (f < 0) return 0;
54-
while ((i = read(f,buffer,sizeof buffer)) > 0) {
55+
56+
#ifndef WIN32
57+
if (!(f = fopen(filename, "r")))
58+
#else
59+
printf("%s\n", filename);for(;;);
60+
if (fopen_s(&f, filename, "r") != 0) /* tady to hnije .. */
61+
#endif
62+
return 0;
63+
while ((i = fread(buffer,sizeof buffer,1,f)) > 0) {
5564
MD5Update(&ctx,buffer,i);
5665
}
5766
j = errno;
58-
close(f);
67+
fclose(f);
5968
errno = j;
6069
if (i < 0) return 0;
6170
return MD5End(&ctx, buf);

0 commit comments

Comments
 (0)