Annotation of quake2/solaris/sys_solaris.c, revision 1.1.1.2

1.1.1.2 ! root        1: /*
        !             2: Copyright (C) 1997-2001 Id Software, Inc.
        !             3: 
        !             4: This program is free software; you can redistribute it and/or
        !             5: modify it under the terms of the GNU General Public License
        !             6: as published by the Free Software Foundation; either version 2
        !             7: of the License, or (at your option) any later version.
        !             8: 
        !             9: This program is distributed in the hope that it will be useful,
        !            10: but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
        !            12: 
        !            13: See the GNU General Public License for more details.
        !            14: 
        !            15: You should have received a copy of the GNU General Public License
        !            16: along with this program; if not, write to the Free Software
        !            17: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
        !            18: 
        !            19: */
1.1       root       20: #include <unistd.h>
                     21: #include <signal.h>
                     22: #include <stdlib.h>
                     23: #include <limits.h>
                     24: #include <sys/time.h>
                     25: #include <sys/types.h>
                     26: #include <unistd.h>
                     27: #include <fcntl.h>
                     28: #include <stdarg.h>
                     29: #include <stdio.h>
                     30: #include <sys/ipc.h>
                     31: #include <sys/shm.h>
                     32: #include <sys/stat.h>
                     33: #include <string.h>
                     34: #include <ctype.h>
                     35: #include <sys/wait.h>
                     36: #include <sys/mman.h>
                     37: #include <errno.h>
                     38: #include <sys/file.h>
                     39: 
                     40: #include <dlfcn.h>
                     41: 
                     42: #include "../qcommon/qcommon.h"
                     43: 
                     44: cvar_t *nostdout;
                     45: 
                     46: unsigned       sys_frame_time;
                     47: 
                     48: qboolean stdin_active = true;
                     49: 
                     50: // =======================================================================
                     51: // General routines
                     52: // =======================================================================
                     53: 
                     54: void Sys_ConsoleOutput (char *string)
                     55: {
                     56:        if (nostdout && nostdout->value)
                     57:                return;
                     58: 
                     59:        fputs(string, stdout);
                     60: }
                     61: 
                     62: void Sys_Printf (char *fmt, ...)
                     63: {
                     64:        va_list         argptr;
                     65:        char            text[1024];
                     66:        unsigned char           *p;
                     67: 
                     68:        va_start (argptr,fmt);
                     69:        vsprintf (text,fmt,argptr);
                     70:        va_end (argptr);
                     71: 
                     72:        if (strlen(text) > sizeof(text))
                     73:                Sys_Error("memory overwrite in Sys_Printf");
                     74: 
                     75:     if (nostdout && nostdout->value)
                     76:         return;
                     77: 
                     78:        for (p = (unsigned char *)text; *p; p++) {
                     79:                *p &= 0x7f;
                     80:                if ((*p > 128 || *p < 32) && *p != 10 && *p != 13 && *p != 9)
                     81:                        printf("[%02x]", *p);
                     82:                else
                     83:                        putc(*p, stdout);
                     84:        }
                     85: }
                     86: 
                     87: void Sys_Quit (void)
                     88: {
                     89:        CL_Shutdown ();
                     90:        Qcommon_Shutdown ();
                     91:     fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
                     92:        _exit(0);
                     93: }
                     94: 
                     95: void Sys_Init(void)
                     96: {
                     97: #if id386
                     98: //     Sys_SetFPCW();
                     99: #endif
                    100: }
                    101: 
                    102: void Sys_Error (char *error, ...)
                    103: { 
                    104:     va_list     argptr;
                    105:     char        string[1024];
                    106: 
                    107: // change stdin to non blocking
                    108:     fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
                    109:     
                    110:     va_start (argptr,error);
                    111:     vsprintf (string,error,argptr);
                    112:     va_end (argptr);
                    113:        fprintf(stderr, "Error: %s\n", string);
                    114: 
                    115:        CL_Shutdown ();
                    116:        Qcommon_Shutdown ();
                    117:        _exit (1);
                    118: 
                    119: } 
                    120: 
                    121: void Sys_Warn (char *warning, ...)
                    122: { 
                    123:     va_list     argptr;
                    124:     char        string[1024];
                    125:     
                    126:     va_start (argptr,warning);
                    127:     vsprintf (string,warning,argptr);
                    128:     va_end (argptr);
                    129:        fprintf(stderr, "Warning: %s", string);
                    130: } 
                    131: 
                    132: /*
                    133: ============
                    134: Sys_FileTime
                    135: 
                    136: returns -1 if not present
                    137: ============
                    138: */
                    139: int    Sys_FileTime (char *path)
                    140: {
                    141:        struct  stat    buf;
                    142:        
                    143:        if (stat (path,&buf) == -1)
                    144:                return -1;
                    145:        
                    146:        return buf.st_mtime;
                    147: }
                    148: 
                    149: void floating_point_exception_handler(int whatever)
                    150: {
                    151: //     Sys_Warn("floating point exception\n");
                    152:        signal(SIGFPE, floating_point_exception_handler);
                    153: }
                    154: 
                    155: char *Sys_ConsoleInput(void)
                    156: {
                    157:     static char text[256];
                    158:     int     len;
                    159:        fd_set  fdset;
                    160:     struct timeval timeout;
                    161: 
                    162:        if (!dedicated || !dedicated->value)
                    163:                return NULL;
                    164: 
                    165:        if (!stdin_active)
                    166:                return NULL;
                    167: 
                    168:        FD_ZERO(&fdset);
                    169:        FD_SET(0, &fdset); // stdin
                    170:        timeout.tv_sec = 0;
                    171:        timeout.tv_usec = 0;
                    172:        if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
                    173:                return NULL;
                    174: 
                    175:        len = read (0, text, sizeof(text));
                    176:        if (len == 0) { // eof!
                    177:                stdin_active = false;
                    178:                return NULL;
                    179:        }
                    180:        if (len < 1)
                    181:                return NULL;
                    182:        text[len-1] = 0;    // rip off the /n and terminate
                    183: 
                    184:        return text;
                    185: }
                    186: 
                    187: /*****************************************************************************/
                    188: 
                    189: static void *game_library;
                    190: 
                    191: /*
                    192: =================
                    193: Sys_UnloadGame
                    194: =================
                    195: */
                    196: void Sys_UnloadGame (void)
                    197: {
                    198:        if (game_library) 
                    199:                dlclose (game_library);
                    200:        game_library = NULL;
                    201: }
                    202: 
                    203: /*
                    204: =================
                    205: Sys_GetGameAPI
                    206: 
                    207: Loads the game dll
                    208: =================
                    209: */
                    210: void *Sys_GetGameAPI (void *parms)
                    211: {
                    212:        void    *(*GetGameAPI) (void *);
                    213: 
                    214:        char    name[MAX_OSPATH];
                    215:        char    curpath[MAX_OSPATH];
                    216:        char    *path;
                    217: #ifdef __i386__
                    218:        const char *gamename = "gamei386.so";
                    219: #elif defined __sun__
                    220:        const char *gamename = "gamesparc.so";
                    221: #else
                    222: #error Unknown arch
                    223: #endif
                    224: 
                    225:        if (game_library)
                    226:                Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame");
                    227: 
                    228:        getcwd(curpath, sizeof(curpath));
                    229: 
                    230:        Com_Printf("------- Loading %s -------", gamename);
                    231: 
                    232:        // now run through the search paths
                    233:        path = NULL;
                    234:        while (1)
                    235:        {
                    236:                path = FS_NextPath (path);
                    237:                if (!path)
                    238:                        return NULL;            // couldn't find one anywhere
                    239:                sprintf (name, "%s/%s/%s", curpath, path, gamename);
                    240:                game_library = dlopen (name, RTLD_NOW );
                    241:                if (game_library)
                    242:                {
                    243:                        Com_DPrintf ("LoadLibrary (%s)\n",name);
                    244:                        break;
                    245:                } else
                    246:                        Com_Printf("error: %s\n", dlerror());
                    247:        }
                    248: 
                    249:        GetGameAPI = (void *)dlsym (game_library, "GetGameAPI");
                    250:        if (!GetGameAPI)
                    251:        {
                    252:                Sys_UnloadGame ();              
                    253:                return NULL;
                    254:        }
                    255: 
                    256:        return GetGameAPI (parms);
                    257: }
                    258: 
                    259: /*****************************************************************************/
                    260: 
                    261: void Sys_AppActivate (void)
                    262: {
                    263: }
                    264: 
                    265: void Sys_SendKeyEvents (void)
                    266: {
                    267:        // grab frame time 
                    268:        sys_frame_time = Sys_Milliseconds();
                    269: }
                    270: 
                    271: /*****************************************************************************/
                    272: 
                    273: char *Sys_GetClipboardData(void)
                    274: {
                    275:        return NULL;
                    276: }
                    277: 
                    278: int main (int argc, char **argv)
                    279: {
                    280:        int     time, oldtime, newtime;
                    281: 
                    282: #if 0
                    283:        int newargc;
                    284:        char **newargv;
                    285:        int i;
                    286: 
                    287:        // force dedicated
                    288:        newargc = argc;
                    289:        newargv = malloc((argc + 3) * sizeof(char *));
                    290:        newargv[0] = argv[0];
                    291:        newargv[1] = "+set";
                    292:        newargv[2] = "dedicated";
                    293:        newargv[3] = "1";
                    294:        for (i = 1; i < argc; i++)
                    295:                newargv[i + 3] = argv[i];
                    296:        newargc += 3;
                    297: 
                    298:        Qcommon_Init(newargc, newargv);
                    299: #else
                    300:        Qcommon_Init(argc, argv);
                    301: #endif
                    302: 
                    303:        fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
                    304: 
                    305:        nostdout = Cvar_Get("nostdout", "0", 0);
                    306: 
                    307:        if (!nostdout->value) {
                    308:                fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
                    309: //             printf ("Linux Quake -- Version %0.3f\n", LINUX_VERSION);
                    310:        }
                    311: 
                    312:     oldtime = Sys_Milliseconds ();
                    313:     while (1)
                    314:     {
                    315: // find time spent rendering last frame
                    316:                do {
                    317:                        newtime = Sys_Milliseconds ();
                    318:                        time = newtime - oldtime;
                    319:                } while (time < 1);
                    320:         Qcommon_Frame (time);
                    321:                oldtime = newtime;
                    322:     }
                    323: 
                    324: }
                    325: 
                    326: void Sys_CopyProtect(void)
                    327: {
                    328:        return;
                    329: }
                    330: 
                    331: #if 0
                    332: /*
                    333: ================
                    334: Sys_MakeCodeWriteable
                    335: ================
                    336: */
                    337: void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
                    338: {
                    339: 
                    340:        int r;
                    341:        unsigned long addr;
                    342:        int psize = getpagesize();
                    343: 
                    344:        addr = (startaddr & ~(psize-1)) - psize;
                    345: 
                    346: //     fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
                    347: //                     addr, startaddr+length, length);
                    348: 
                    349:        r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
                    350: 
                    351:        if (r < 0)
                    352:                Sys_Error("Protection change failed\n");
                    353: 
                    354: }
                    355: 
                    356: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.