comparison xrogue/state.c @ 220:f54901b9c39b

XRogue: convert to ANSI-style function declarations.
author John "Elwin" Edwards
date Wed, 02 Mar 2016 21:13:26 -0500
parents 3def5e487faa
children 7c1cb43f346e
comparison
equal deleted inserted replaced
219:f9ef86cf22b2 220:f54901b9c39b
95 int format_error = FALSE; 95 int format_error = FALSE;
96 96
97 int save_debug = FALSE; 97 int save_debug = FALSE;
98 #define DBG(x) {if (save_debug) rsPrintf x;} 98 #define DBG(x) {if (save_debug) rsPrintf x;}
99 99
100 bool rs_read_new_string(int inf, char **s);
101 int find_list_ptr(struct linked_list *l, void *ptr);
102 bool rs_write_coord_list(FILE *savef, struct linked_list *l);
103 bool rs_read_coord_list(int inf, struct linked_list **list);
104 int list_size(struct linked_list *l);
105 bool rs_write_object_list(FILE *savef, struct linked_list *l);
106 bool rs_read_object_list(int inf, struct linked_list **list);
107
100 int 108 int
101 rsPrintf(char *fmt, ...) 109 rsPrintf(char *fmt, ...)
102 { 110 {
103 va_list ap; 111 va_list ap;
104 112
126 } 134 }
127 135
128 return(NULL); 136 return(NULL);
129 } 137 }
130 138
139 bool
131 rs_write(FILE *savef, void *ptr, size_t size) 140 rs_write(FILE *savef, void *ptr, size_t size)
132 { 141 {
133 size_t i = 0; 142 size_t i = 0;
134 143
135 if (!write_error) 144 if (!write_error)
141 return(WRITESTAT); 150 return(WRITESTAT);
142 } 151 }
143 152
144 int end_of_file = FALSE; 153 int end_of_file = FALSE;
145 154
155 bool
146 rs_read(int inf, void *ptr, size_t size) 156 rs_read(int inf, void *ptr, size_t size)
147 { 157 {
148 int actual; 158 int actual;
149 end_of_file =FALSE; 159 end_of_file =FALSE;
150 if (!read_error && !format_error) 160 if (!read_error && !format_error)
163 return(READSTAT); 173 return(READSTAT);
164 } 174 }
165 175
166 int big_endian = 0; 176 int big_endian = 0;
167 177
178 bool
168 rs_write_uint(FILE *savef, unsigned int c) 179 rs_write_uint(FILE *savef, unsigned int c)
169 { 180 {
170 char bytes[4]; 181 char bytes[4];
171 char *buf = (char *) &c; 182 char *buf = (char *) &c;
172 183
182 rs_write(savef, buf, 4); 193 rs_write(savef, buf, 4);
183 194
184 return(WRITESTAT); 195 return(WRITESTAT);
185 } 196 }
186 197
198 bool
187 rs_write_int(FILE *savef, int c) 199 rs_write_int(FILE *savef, int c)
188 { 200 {
189 char bytes[4]; 201 char bytes[4];
190 char *buf = (char *) &c; 202 char *buf = (char *) &c;
191 203
201 rs_write(savef, buf, 4); 213 rs_write(savef, buf, 4);
202 214
203 return(WRITESTAT); 215 return(WRITESTAT);
204 } 216 }
205 217
218 bool
206 rs_write_ulong(FILE *savef, unsigned long c) 219 rs_write_ulong(FILE *savef, unsigned long c)
207 { 220 {
208 unsigned int c2; 221 unsigned int c2;
209 char bytes[4]; 222 char bytes[4];
210 char *buf = (char *)&c; 223 char *buf = (char *)&c;
227 rs_write(savef, buf, 4); 240 rs_write(savef, buf, 4);
228 241
229 return(WRITESTAT); 242 return(WRITESTAT);
230 } 243 }
231 244
245 bool
232 rs_write_long(FILE *savef, long c) 246 rs_write_long(FILE *savef, long c)
233 { 247 {
234 int c2; 248 int c2;
235 char bytes[4]; 249 char bytes[4];
236 char *buf = (char *)&c; 250 char *buf = (char *)&c;
253 rs_write(savef, buf, 4); 267 rs_write(savef, buf, 4);
254 268
255 return(WRITESTAT); 269 return(WRITESTAT);
256 } 270 }
257 271
272 bool
258 rs_write_boolean(FILE *savef, bool c) 273 rs_write_boolean(FILE *savef, bool c)
259 { 274 {
260 char buf; 275 char buf;
261 276
262 if (c == 0) 277 if (c == 0)
267 rs_write(savef, &buf, 1); 282 rs_write(savef, &buf, 1);
268 283
269 return(WRITESTAT); 284 return(WRITESTAT);
270 } 285 }
271 286
287 bool
272 rs_read_int(int inf, int *i) 288 rs_read_int(int inf, int *i)
273 { 289 {
274 char bytes[4]; 290 char bytes[4];
275 int input; 291 int input;
276 char *buf = (char *)&input; 292 char *buf = (char *)&input;
289 *i = *((int *) buf); 305 *i = *((int *) buf);
290 306
291 return(READSTAT); 307 return(READSTAT);
292 } 308 }
293 309
310 bool
294 rs_read_uint(int inf, unsigned int *i) 311 rs_read_uint(int inf, unsigned int *i)
295 { 312 {
296 char bytes[4]; 313 char bytes[4];
297 int input; 314 int input;
298 char *buf = (char *)&input; 315 char *buf = (char *)&input;
311 *i = *((int *) buf); 328 *i = *((int *) buf);
312 329
313 return(READSTAT); 330 return(READSTAT);
314 } 331 }
315 332
333 bool
316 rs_read_ulong(int inf, unsigned long *i) 334 rs_read_ulong(int inf, unsigned long *i)
317 { 335 {
318 char bytes[4]; 336 char bytes[4];
319 unsigned long input; 337 unsigned long input;
320 char *buf = (char *) &input; 338 char *buf = (char *) &input;
335 else 353 else
336 *i = *((unsigned long *) buf); 354 *i = *((unsigned long *) buf);
337 return(READSTAT); 355 return(READSTAT);
338 } 356 }
339 357
358 bool
340 rs_read_long(int inf, long *i) 359 rs_read_long(int inf, long *i)
341 { 360 {
342 char bytes[4]; 361 char bytes[4];
343 long input; 362 long input;
344 char *buf = (char *) &input; 363 char *buf = (char *) &input;
359 else 378 else
360 *i = *((long *) buf); 379 *i = *((long *) buf);
361 return(READSTAT); 380 return(READSTAT);
362 } 381 }
363 382
383 bool
364 rs_read_boolean(int inf, bool *i) 384 rs_read_boolean(int inf, bool *i)
365 { 385 {
366 char buf; 386 char buf;
367 387
368 rs_read(inf, &buf, 1); 388 rs_read(inf, &buf, 1);
370 *i = buf; 390 *i = buf;
371 391
372 return(READSTAT); 392 return(READSTAT);
373 } 393 }
374 394
395 bool
375 rs_write_ints(FILE *savef, int *c, int count) 396 rs_write_ints(FILE *savef, int *c, int count)
376 { 397 {
377 int n=0; 398 int n=0;
378 399
379 rs_write_int(savef,count); 400 rs_write_int(savef,count);
382 rs_write_int(savef,c[n]); 403 rs_write_int(savef,c[n]);
383 404
384 return(WRITESTAT); 405 return(WRITESTAT);
385 } 406 }
386 407
408 bool
387 rs_write_short(FILE *savef, short c) 409 rs_write_short(FILE *savef, short c)
388 { 410 {
389 char bytes[2]; 411 char bytes[2];
390 char *buf = (char *) &c; 412 char *buf = (char *) &c;
391 413
399 rs_write(savef, buf, 2); 421 rs_write(savef, buf, 2);
400 422
401 return(WRITESTAT); 423 return(WRITESTAT);
402 } 424 }
403 425
426 bool
404 rs_read_short(int inf, short *s) 427 rs_read_short(int inf, short *s)
405 { 428 {
406 char bytes[2]; 429 char bytes[2];
407 short input; 430 short input;
408 char *buf = (char *)&input; 431 char *buf = (char *)&input;
419 *s = *((short *) buf); 442 *s = *((short *) buf);
420 return(READSTAT); 443 return(READSTAT);
421 } 444 }
422 445
423 446
447 bool
424 rs_write_shorts(FILE *savef, short *c, int count) 448 rs_write_shorts(FILE *savef, short *c, int count)
425 { 449 {
426 int n=0; 450 int n=0;
427 451
428 rs_write_int(savef,count); 452 rs_write_int(savef,count);
431 rs_write_short(savef,c[n]); 455 rs_write_short(savef,c[n]);
432 456
433 return(WRITESTAT); 457 return(WRITESTAT);
434 } 458 }
435 459
460 bool
436 rs_write_longs(FILE *savef, long *c, int count) 461 rs_write_longs(FILE *savef, long *c, int count)
437 { 462 {
438 int n=0; 463 int n=0;
439 464
440 rs_write_int(savef,count); 465 rs_write_int(savef,count);
443 rs_write_long(savef,c[n]); 468 rs_write_long(savef,c[n]);
444 469
445 return(WRITESTAT); 470 return(WRITESTAT);
446 } 471 }
447 472
473 bool
448 rs_write_ulongs(FILE *savef, unsigned long *c, int count) 474 rs_write_ulongs(FILE *savef, unsigned long *c, int count)
449 { 475 {
450 int n=0; 476 int n=0;
451 477
452 rs_write_int(savef,count); 478 rs_write_int(savef,count);
455 rs_write_ulong(savef,c[n]); 481 rs_write_ulong(savef,c[n]);
456 482
457 return(WRITESTAT); 483 return(WRITESTAT);
458 } 484 }
459 485
486 bool
460 rs_write_booleans(FILE *savef, bool *c, int count) 487 rs_write_booleans(FILE *savef, bool *c, int count)
461 { 488 {
462 int n=0; 489 int n=0;
463 490
464 rs_write_int(savef,count); 491 rs_write_int(savef,count);
467 rs_write_boolean(savef,c[n]); 494 rs_write_boolean(savef,c[n]);
468 495
469 return(WRITESTAT); 496 return(WRITESTAT);
470 } 497 }
471 498
499 bool
472 rs_read_ints(int inf, int *i, int count) 500 rs_read_ints(int inf, int *i, int count)
473 { 501 {
474 int n=0,value=0; 502 int n=0,value=0;
475 503
476 if (rs_read_int(inf,&value) != 0) 504 if (rs_read_int(inf,&value) != 0)
485 } 513 }
486 514
487 return(READSTAT); 515 return(READSTAT);
488 } 516 }
489 517
518 bool
490 rs_read_shorts(int inf, short *i, int count) 519 rs_read_shorts(int inf, short *i, int count)
491 { 520 {
492 int n=0,value=0; 521 int n=0,value=0;
493 522
494 if (rs_read_int(inf,&value) != 0) 523 if (rs_read_int(inf,&value) != 0)
503 } 532 }
504 533
505 return(READSTAT); 534 return(READSTAT);
506 } 535 }
507 536
537 bool
508 rs_read_longs(int inf, long *i, int count) 538 rs_read_longs(int inf, long *i, int count)
509 { 539 {
510 int n=0,value=0; 540 int n=0,value=0;
511 541
512 if (rs_read_int(inf,&value) != 0) 542 if (rs_read_int(inf,&value) != 0)
521 } 551 }
522 552
523 return(READSTAT); 553 return(READSTAT);
524 } 554 }
525 555
556 bool
526 rs_read_ulongs(int inf, unsigned long *i, int count) 557 rs_read_ulongs(int inf, unsigned long *i, int count)
527 { 558 {
528 int n=0,value=0; 559 int n=0,value=0;
529 560
530 if (rs_read_int(inf,&value) != 0) 561 if (rs_read_int(inf,&value) != 0)
539 } 570 }
540 571
541 return(READSTAT); 572 return(READSTAT);
542 } 573 }
543 574
575 bool
544 rs_read_booleans(int inf, bool *i, int count) 576 rs_read_booleans(int inf, bool *i, int count)
545 { 577 {
546 int n=0,value=0; 578 int n=0,value=0;
547 579
548 if (rs_read_int(inf,&value) != 0) 580 if (rs_read_int(inf,&value) != 0)
557 } 589 }
558 590
559 return(READSTAT); 591 return(READSTAT);
560 } 592 }
561 593
594 bool
562 rs_write_levtype(FILE *savef, LEVTYPE c) 595 rs_write_levtype(FILE *savef, LEVTYPE c)
563 { 596 {
564 int lt; 597 int lt;
565 598
566 switch(c) 599 switch(c)
576 rs_write_int(savef,lt); 609 rs_write_int(savef,lt);
577 610
578 return(WRITESTAT); 611 return(WRITESTAT);
579 } 612 }
580 613
614 bool
581 rs_read_levtype(int inf, LEVTYPE *l) 615 rs_read_levtype(int inf, LEVTYPE *l)
582 { 616 {
583 int lt; 617 int lt;
584 618
585 rs_read_int(inf, &lt); 619 rs_read_int(inf, &lt);
595 } 629 }
596 630
597 return(READSTAT); 631 return(READSTAT);
598 } 632 }
599 633
634 bool
600 rs_write_char(FILE *savef, char c) 635 rs_write_char(FILE *savef, char c)
601 { 636 {
602 rs_write(savef, &c, 1); 637 rs_write(savef, &c, 1);
603 DBG(("%c",c)); 638 DBG(("%c",c));
604 639
605 return(WRITESTAT); 640 return(WRITESTAT);
606 } 641 }
607 642
643 bool
608 rs_read_char(int inf, char *c) 644 rs_read_char(int inf, char *c)
609 { 645 {
610 rs_read(inf, c, 1); 646 rs_read(inf, c, 1);
611 647
612 return(READSTAT); 648 return(READSTAT);
613 } 649 }
614 650
651 bool
615 rs_write_uchar(FILE *savef, unsigned char c) 652 rs_write_uchar(FILE *savef, unsigned char c)
616 { 653 {
617 rs_write(savef, &c, 1); 654 rs_write(savef, &c, 1);
618 DBG(("%c",c)); 655 DBG(("%c",c));
619 656
620 return(WRITESTAT); 657 return(WRITESTAT);
621 } 658 }
622 659
660 bool
623 rs_read_uchar(int inf, unsigned char *c) 661 rs_read_uchar(int inf, unsigned char *c)
624 { 662 {
625 rs_read(inf, c, 1); 663 rs_read(inf, c, 1);
626 664
627 return(READSTAT); 665 return(READSTAT);
628 } 666 }
629 667
668 bool
630 rs_write_string(FILE *savef, char *s) 669 rs_write_string(FILE *savef, char *s)
631 { 670 {
632 int len = 0;