unofficial version 0.8: chat, code cleanup
[netris.git] / util.c
diff --git a/util.c b/util.c
index 2f7c2e5d7ad346b1f30562fbd43417c49763afe1..a55aeb0abc825fd1b64ec43198ebd7922ff049a3 100644 (file)
--- a/util.c
+++ b/util.c
@@ -28,6 +28,9 @@
 #include <sys/time.h>
 #include <netdb.h>
 #include <errno.h>
+#include <setjmp.h>
+
+#include "util.h"
 
 static MyEventType AlarmGenFunc(EventGenRec *gen, MyEvent *event);
 static EventGenRec alarmGen =
@@ -38,7 +41,8 @@ static int myRandSeed = 1;
 
 static long baseTimeval;
 
-ExtFunc void AtExit(void (*handler)(void))
+
+void AtExit(void (*handler)(void))
 {
 #ifdef HAS_ON_EXIT
        on_exit((void *)handler, NULL);
@@ -49,7 +53,7 @@ ExtFunc void AtExit(void (*handler)(void))
 
 ///////////// HELP MESSAGES /////////////
 
-ExtFunc void Header(void)
+void Header(void)
 {
        fprintf(stderr,
          "NETRIS %s\t(c) 1994-1996,1999 Mark H. Weaver <mhw@netris.org>\n"
@@ -57,7 +61,7 @@ ExtFunc void Header(void)
          version_string);
 } //Header
 
-ExtFunc void Usage(void)
+void Usage(void)
 {
        Header();
        fprintf(stderr,
@@ -85,7 +89,7 @@ ExtFunc void Usage(void)
          "\n", DEFAULT_PORT, DEFAULT_KEYS);
 }
 
-ExtFunc void DistInfo(void)
+void DistInfo(void)
 {
        Header();
        fprintf(stderr,
@@ -105,7 +109,7 @@ ExtFunc void DistInfo(void)
          "\n");
 } //DistInfo
 
-ExtFunc void Rules(void)
+void Rules(void)
 {
        Header();
        fprintf(stderr,
@@ -135,13 +139,13 @@ ExtFunc void Rules(void)
  * My really crappy random number generator follows
  * Should be more than sufficient for our purposes though
  */
-ExtFunc void SRandom(int seed)
+void SRandom(int seed)
 {
        Game.seed = seed;
        myRandSeed = seed % 31751 + 1;
 } //SRandom
 
-ExtFunc int Random(int min, int max1)
+int Random(int min, int max1)
 { //return a random value
        myRandSeed = (myRandSeed * 31751 + 15437) % 32767;
        return myRandSeed % (max1 - min) + min;
@@ -149,7 +153,7 @@ ExtFunc int Random(int min, int max1)
 
 ///////////// I/O /////////////
 
-ExtFunc int MyRead(int fd, void *data, int len)
+int MyRead(int fd, void *data, int len)
 {
        int result, left;
 
@@ -166,7 +170,7 @@ ExtFunc int MyRead(int fd, void *data, int len)
        return len;
 } //MyRead
 
-ExtFunc int MyWrite(int fd, void *data, int len)
+int MyWrite(int fd, void *data, int len)
 {
        int result, left;
 
@@ -185,7 +189,7 @@ ExtFunc int MyWrite(int fd, void *data, int len)
 
 ///////////// TIME /////////////
 
-ExtFunc void NormalizeTime(struct timeval *tv)
+void NormalizeTime(struct timeval *tv)
 {
        tv->tv_sec += tv->tv_usec / 1000000;
        tv->tv_usec %= 1000000;
@@ -195,7 +199,7 @@ ExtFunc void NormalizeTime(struct timeval *tv)
        }
 }
 
-ExtFunc void CatchAlarm(int sig)
+void CatchAlarm(int sig)
 {
        alarmGen.ready = 1;
        signal(SIGALRM, CatchAlarm);
@@ -206,18 +210,18 @@ static MyEventType AlarmGenFunc(EventGenRec *gen, MyEvent *event)
        return E_alarm;
 }
 
-ExtFunc void SetTimeval(struct timeval *tv, long usec)
+void SetTimeval(struct timeval *tv, long usec)
 {
        tv->tv_sec = usec / 1000000;
        tv->tv_usec = usec % 1000000;
 } //SetTimeval
 
-ExtFunc long GetTimeval(struct timeval *tv)
+long GetTimeval(struct timeval *tv)
 {
        return tv->tv_sec * 1000000 + tv->tv_usec;
 } //GetTimeval
 
-ExtFunc long AbsTimeval(void)
+long AbsTimeval(void)
 {
        struct timeval tv;
 
@@ -225,22 +229,22 @@ ExtFunc long AbsTimeval(void)
        return GetTimeval(&tv);
 } //CurTimeval
 
-ExtFunc void ResetBaseTime(void)
-{
+void ResetBaseTime(void)
+{ //Reset the timer
        baseTimeval = AbsTimeval();
 } //ResetBaseTime
 
-ExtFunc void PauseTime(void)
-{
+void PauseTime(void)
+{ //Pause the timer
        baseTimeval -= AbsTimeval();
 } //PauseTime
 
-ExtFunc void ResumeTime(void)
-{
+void ResumeTime(void)
+{ //Unpause timer
        baseTimeval += AbsTimeval();
 } //ResumeTime
 
-ExtFunc long CurTimeval(void)
+long CurTimeval(void)
 {
        struct timeval tv;
 
@@ -260,7 +264,7 @@ static long SetITimer1(long interval, long value)
        return GetTimeval(&old.it_value);
 }
 
-ExtFunc long SetITimer(long interval, long value)
+long SetITimer(long interval, long value)
 {
        long old;
 
@@ -272,19 +276,19 @@ ExtFunc long SetITimer(long interval, long value)
 
 ///////////// ... /////////////
 
-ExtFunc volatile void die(char *msg)
+volatile void die(char *msg)
 {
        perror(msg);
        exit(1);
 }
 
-ExtFunc volatile void fatal(char *msg)
+volatile void fatal(char *msg)
 {
        fprintf(stderr, "%s\n", msg);
        exit(1);
 } //fatal
 
-ExtFunc void BlockSignals(MySigSet *saved, ...)
+void BlockSignals(MySigSet *saved, ...)
 {
        MySigSet set;
        va_list args;
@@ -311,7 +315,7 @@ ExtFunc void BlockSignals(MySigSet *saved, ...)
        va_end(args);
 } //BlockSignals
 
-ExtFunc void RestoreSignals(MySigSet *saved, MySigSet *set)
+void RestoreSignals(MySigSet *saved, MySigSet *set)
 {
 #ifdef HAS_SIGPROCMASK
        sigprocmask(SIG_SETMASK, set, saved);
@@ -325,14 +329,14 @@ ExtFunc void RestoreSignals(MySigSet *saved, MySigSet *set)
 
 ///////////// EVENTS /////////////
 
-ExtFunc void AddEventGen(EventGenRec *gen)
+void AddEventGen(EventGenRec *gen)
 {
        assert(gen->next == NULL);
        gen->next = nextGen->next;
        nextGen->next = gen;
 } //AddEventGen
 
-ExtFunc void RemoveEventGen(EventGenRec *gen)
+void RemoveEventGen(EventGenRec *gen)
 {
        // assert(gen->next != NULL);   /* Be more forgiving, for SIGINTs */
        if (gen->next) {
@@ -343,7 +347,7 @@ ExtFunc void RemoveEventGen(EventGenRec *gen)
        }
 } //RemoveEventGen
 
-ExtFunc MyEventType WaitMyEvent(MyEvent *event, int mask)
+MyEventType WaitMyEvent(MyEvent *event, int mask)
 { //poll
        int i, retry = 0;
        fd_set fds[FT_len];