Mercurial > hg > early-roguelike
comparison arogue7/main.c @ 219:f9ef86cf22b2
Advanced Rogue 7: convert to ANSI-style function declarations.
Almost 1500 lines of compiler warnings remain, and the GCC developers
are already working on a new version with even more warnings turned on
by default.
| author | John "Elwin" Edwards | 
|---|---|
| date | Fri, 19 Feb 2016 21:02:28 -0500 | 
| parents | cadff8f047a1 | 
| children | e1cd27c5464f | 
   comparison
  equal
  deleted
  inserted
  replaced
| 218:56e748983fa8 | 219:f9ef86cf22b2 | 
|---|---|
| 30 extern struct uwdata wdata, oldwin; | 30 extern struct uwdata wdata, oldwin; | 
| 31 extern char oldtext[WTXTNUM][WTXTLEN]; | 31 extern char oldtext[WTXTNUM][WTXTLEN]; | 
| 32 #endif | 32 #endif | 
| 33 | 33 | 
| 34 void open_records(void); | 34 void open_records(void); | 
| 35 | 35 bool too_much(void); | 
| 36 main(argc, argv, envp) | 36 bool author(void); | 
| 37 char **argv; | 37 void chmsg(char *fmt, int arg); | 
| 38 char **envp; | 38 #ifdef MAXPROCESSES | 
| 39 int loadav(void); | |
| 40 #endif | |
| 41 #ifdef MAXUSERS | |
| 42 int ucount(void); | |
| 43 #endif | |
| 44 bool holiday(void); | |
| 45 | |
| 46 int | |
| 47 main(int argc, char *argv[], char *envp[]) | |
| 39 { | 48 { | 
| 40 register char *env; | 49 register char *env; | 
| 41 int lowtime; | 50 int lowtime; | 
| 42 time_t now; | 51 time_t now; | 
| 43 #ifdef PC7300 | 52 #ifdef PC7300 | 
| 417 * endit: | 426 * endit: | 
| 418 * Exit the program abnormally. | 427 * Exit the program abnormally. | 
| 419 */ | 428 */ | 
| 420 | 429 | 
| 421 void | 430 void | 
| 422 endit(sig) | 431 endit(int sig) | 
| 423 int sig; | |
| 424 { | 432 { | 
| 425 fatal("Ok, if you want to exit that badly, I'll have to allow it\n"); | 433 fatal("Ok, if you want to exit that badly, I'll have to allow it\n"); | 
| 426 } | 434 } | 
| 427 | 435 | 
| 428 /* | 436 /* | 
| 429 * fatal: | 437 * fatal: | 
| 430 * Exit the program, printing a message. | 438 * Exit the program, printing a message. | 
| 431 */ | 439 */ | 
| 432 | 440 | 
| 433 fatal(s) | 441 void | 
| 434 char *s; | 442 fatal(char *s) | 
| 435 { | 443 { | 
| 436 clear(); | 444 clear(); | 
| 437 move(lines-2, 0); | 445 move(lines-2, 0); | 
| 438 printw("%s", s); | 446 printw("%s", s); | 
| 439 draw(stdscr); | 447 draw(stdscr); | 
| 447 | 455 | 
| 448 /* | 456 /* | 
| 449 * rnd: | 457 * rnd: | 
| 450 * Pick a very random number. | 458 * Pick a very random number. | 
| 451 */ | 459 */ | 
| 452 rnd(range) | 460 int | 
| 453 register int range; | 461 rnd(int range) | 
| 454 { | 462 { | 
| 455 return(range <= 0 ? 0 : md_rand() % range); | 463 return(range <= 0 ? 0 : md_rand() % range); | 
| 456 } | 464 } | 
| 457 | 465 | 
| 458 /* | 466 /* | 
| 459 * roll: | 467 * roll: | 
| 460 * roll a number of dice | 468 * roll a number of dice | 
| 461 */ | 469 */ | 
| 462 | 470 | 
| 463 roll(number, sides) | 471 int | 
| 464 register int number, sides; | 472 roll(int number, int sides) | 
| 465 { | 473 { | 
| 466 register int dtotal = 0; | 474 register int dtotal = 0; | 
| 467 | 475 | 
| 468 while(number--) | 476 while(number--) | 
| 469 dtotal += rnd(sides)+1; | 477 dtotal += rnd(sides)+1; | 
| 472 # ifdef SIGTSTP | 480 # ifdef SIGTSTP | 
| 473 /* | 481 /* | 
| 474 * handle stop and start signals | 482 * handle stop and start signals | 
| 475 */ | 483 */ | 
| 476 void | 484 void | 
| 477 tstp(sig) | 485 tstp(int sig) | 
| 478 int sig; | |
| 479 { | 486 { | 
| 480 mvcur(0, cols - 1, lines - 1, 0); | 487 mvcur(0, cols - 1, lines - 1, 0); | 
| 481 endwin(); | 488 endwin(); | 
| 482 fflush(stdout); | 489 fflush(stdout); | 
| 483 kill(0, SIGTSTP); | 490 kill(0, SIGTSTP); | 
| 491 draw(cw); | 498 draw(cw); | 
| 492 md_flushinp(); | 499 md_flushinp(); | 
| 493 } | 500 } | 
| 494 # endif | 501 # endif | 
| 495 | 502 | 
| 496 setup() | 503 void | 
| 504 setup(void) | |
| 497 { | 505 { | 
| 498 #ifdef CHECKTIME | 506 #ifdef CHECKTIME | 
| 499 int checkout(); | 507 int checkout(); | 
| 500 | 508 | 
| 501 if (!author()) { | 509 if (!author()) { | 
| 561 * playit: | 569 * playit: | 
| 562 * The main loop of the program. Loop until the game is over, | 570 * The main loop of the program. Loop until the game is over, | 
| 563 * refreshing things and looking at the proper times. | 571 * refreshing things and looking at the proper times. | 
| 564 */ | 572 */ | 
| 565 | 573 | 
| 566 playit() | 574 void | 
| 575 playit(void) | |
| 567 { | 576 { | 
| 568 register char *opts; | 577 register char *opts; | 
| 569 | 578 | 
| 570 | 579 | 
| 571 /* | 580 /* | 
| 583 } | 592 } | 
| 584 | 593 | 
| 585 /* | 594 /* | 
| 586 * see if the system is being used too much for this game | 595 * see if the system is being used too much for this game | 
| 587 */ | 596 */ | 
| 588 too_much() | 597 bool | 
| 598 too_much(void) | |
| 589 { | 599 { | 
| 590 #if MAXPROCESSES | 600 #if MAXPROCESSES | 
| 591 if (loadav() > MAXPROCESSES) | 601 if (loadav() > MAXPROCESSES) | 
| 592 return(TRUE); | 602 return(TRUE); | 
| 593 #endif | 603 #endif | 
| 600 | 610 | 
| 601 /* | 611 /* | 
| 602 * author: | 612 * author: | 
| 603 * See if a user is an author of the program | 613 * See if a user is an author of the program | 
| 604 */ | 614 */ | 
| 605 author() | 615 bool | 
| 616 author(void) | |
| 606 { | 617 { | 
| 607 switch (md_getuid()) { | 618 switch (md_getuid()) { | 
| 608 #if AUTHOR | 619 #if AUTHOR | 
| 609 case AUTHOR: | 620 case AUTHOR: | 
| 610 #endif | 621 #endif | 
| 651 | 662 | 
| 652 /* | 663 /* | 
| 653 * checkout()'s version of msg. If we are in the middle of a shell, do a | 664 * checkout()'s version of msg. If we are in the middle of a shell, do a | 
| 654 * printf instead of a msg to avoid the refresh. | 665 * printf instead of a msg to avoid the refresh. | 
| 655 */ | 666 */ | 
| 656 chmsg(fmt, arg) | 667 void | 
| 657 char *fmt; | 668 chmsg(char *fmt, int arg) | 
| 658 int arg; | |
| 659 { | 669 { | 
| 660 if (in_shell) { | 670 if (in_shell) { | 
| 661 printf(fmt, arg); | 671 printf(fmt, arg); | 
| 662 putchar('\n'); | 672 putchar('\n'); | 
| 663 fflush(stdout); | 673 fflush(stdout); | 
| 669 | 679 | 
| 670 #ifdef MAXPROCESSES | 680 #ifdef MAXPROCESSES | 
| 671 | 681 | 
| 672 #include <fcntl.h> | 682 #include <fcntl.h> | 
| 673 | 683 | 
| 674 loadav() | 684 int | 
| 685 loadav(void) | |
| 675 { | 686 { | 
| 676 char *sarcmd = "sar -v | cut -c17-20 | tail -2"; | 687 char *sarcmd = "sar -v | cut -c17-20 | tail -2"; | 
| 677 char *gettycmd = "grep getty /etc/inittab | wc -l"; | 688 char *gettycmd = "grep getty /etc/inittab | wc -l"; | 
| 678 char sysbuffer[BUFSIZ]; | 689 char sysbuffer[BUFSIZ]; | 
| 679 char tempfile[50]; | 690 char tempfile[50]; | 
| 722 * Count the number of people on the system | 733 * Count the number of people on the system | 
| 723 */ | 734 */ | 
| 724 #include <sys/types.h> | 735 #include <sys/types.h> | 
| 725 #include <utmp.h> | 736 #include <utmp.h> | 
| 726 struct utmp buf; | 737 struct utmp buf; | 
| 727 ucount() | 738 | 
| 739 int | |
| 740 ucount(void) | |
| 728 { | 741 { | 
| 729 reg struct utmp *up; | 742 reg struct utmp *up; | 
| 730 reg FILE *utmp; | 743 reg FILE *utmp; | 
| 731 reg int count; | 744 reg int count; | 
| 732 | 745 | 
| 749 | 762 | 
| 750 /* | 763 /* | 
| 751 * holiday: | 764 * holiday: | 
| 752 * Returns TRUE when it is a good time to play rogue | 765 * Returns TRUE when it is a good time to play rogue | 
| 753 */ | 766 */ | 
| 754 holiday() | 767 bool | 
| 768 holiday(void) | |
| 755 { | 769 { | 
| 756 #ifdef CHECKTIME | 770 #ifdef CHECKTIME | 
| 757 long now; | 771 long now; | 
| 758 struct tm *localtime(); | 772 struct tm *localtime(); | 
| 759 reg struct tm *ntime; | 773 reg struct tm *ntime; | 
