Update of /cvsroot/galaxyng/NG/lib In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv22013 Modified Files: Tag: Refactor_Baseline globals.c list.c loadNGConfig.c lockFile.c logging.c mail.c randomize.c strutl.c util.c Log Message: list.c works again. removed dead code. Index: loadNGConfig.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/loadNGConfig.c,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -C2 -d -r1.7 -r1.7.2.1 *** loadNGConfig.c 20 Oct 2004 13:15:43 -0000 1.7 --- loadNGConfig.c 22 Jun 2007 22:28:38 -0000 1.7.2.1 *************** *** 16,147 **** void ! initServerOptions(game* aGame) { ! /* initialize values */ ! aGame->serverOptions.sendmail = NULL; ! aGame->serverOptions.encode = NULL; ! aGame->serverOptions.compress = NULL; ! aGame->serverOptions.GMemail = NULL; ! aGame->serverOptions.GMname = NULL; ! aGame->serverOptions.GMpassword = NULL; ! aGame->serverOptions.SERVERemail = NULL; ! aGame->serverOptions.SERVERname = NULL; ! aGame->serverOptions.ReplyTo = NULL; ! aGame->serverOptions.fontpath = NULL; ! aGame->serverOptions.due = NULL; ! aGame->serverOptions.tick_interval = NULL; } ! void readDefaults(game *aGame, FILE * f) { ! char* isRead; /* to check for EOF */ ! char* key; /* the key part of the name/value pair */ ! ! for (isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f); ! isRead; isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f)) { ! ! key = getstr(lineBuffer); ! if (key[0] != '\0') { ! if (noCaseStrcmp("GMemail", key) == 0) { ! if (aGame->serverOptions.GMemail) ! free(aGame->serverOptions.GMemail); ! aGame->serverOptions.GMemail = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("GMname", key) == 0) { ! if (aGame->serverOptions.GMname) ! free(aGame->serverOptions.GMname); ! aGame->serverOptions.GMname = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("GMpassword", key) == 0) { ! if (aGame->serverOptions.GMpassword) ! free(aGame->serverOptions.GMpassword); ! aGame->serverOptions.GMpassword = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("SERVERemail", key) == 0) { ! if (aGame->serverOptions.SERVERemail) ! free(aGame->serverOptions.SERVERemail); ! aGame->serverOptions.SERVERemail = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("SERVERname", key) == 0) { ! if (aGame->serverOptions.SERVERname) ! free(aGame->serverOptions.SERVERname); ! aGame->serverOptions.SERVERname = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("ReplyTo", key) == 0) { ! if (aGame->serverOptions.ReplyTo) ! free(aGame->serverOptions.ReplyTo); ! aGame->serverOptions.ReplyTo = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("compress", key) == 0) { ! if (aGame->serverOptions.compress) ! free(aGame->serverOptions.compress); ! aGame->serverOptions.compress = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("encode", key) == 0) { ! if (aGame->serverOptions.encode) ! free(aGame->serverOptions.encode); ! aGame->serverOptions.encode = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("sendmail", key) == 0) { ! if (aGame->serverOptions.sendmail) ! free(aGame->serverOptions.sendmail); ! aGame->serverOptions.sendmail = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("starttime", key) == 0) { ! if (aGame->starttime) ! free(aGame->starttime); ! aGame->starttime = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("fontpath", key) == 0) { ! if (aGame->serverOptions.fontpath) ! free(aGame->serverOptions.fontpath); ! aGame->serverOptions.fontpath = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("due", key) == 0) { ! if (aGame->serverOptions.due) ! free(aGame->serverOptions.due); ! aGame->serverOptions.due = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("tick", key) == 0) { ! if (aGame->serverOptions.tick_interval) ! free(aGame->serverOptions.tick_interval); ! aGame->serverOptions.tick_interval = strdup(getstr(0)); ! } ! else { ! printf("Unknown key \"%s\"\n", key); ! } } - } - - if (aGame->serverOptions.due == NULL) - aGame->serverOptions.due = strdup("soon"); - - if (aGame->serverOptions.tick_interval == NULL) - aGame->serverOptions.tick_interval = strdup("48"); - - if (aGame->serverOptions.SERVERemail == NULL) { - char* logfile = createString("%s/Games/log/%s", galaxynghome, aGame->name); - FILE* logfp = fopen(logfile, "+w"); - fprintf(stderr, "SERVERemail is a required entry in your .galaxyngrc\n"); - fprintf(logfp, "SERVERemail is a required entry in your .galaxyngrc\n"); - fclose(logfp); - exit(EXIT_FAILURE); - } ! if (aGame->serverOptions.SERVERname == NULL) ! aGame->serverOptions.SERVERname = strdup("GalaxyNG Server"); ! if (aGame->serverOptions.GMemail == NULL) ! aGame->serverOptions.GMemail = ! strdup(aGame->serverOptions.SERVERemail); ! ! if (aGame->serverOptions.GMname == NULL) ! aGame->serverOptions.GMname = strdup("GalaxyNG GM"); ! if (aGame->serverOptions.ReplyTo == NULL) ! aGame->serverOptions.ReplyTo = ! strdup(aGame->serverOptions.SERVERemail); ! ! if (aGame->serverOptions.GMpassword == NULL) ! aGame->serverOptions.GMpassword = strdup(""); } --- 16,139 ---- void ! initServerOptions( game *aGame ) { ! /* initialize values */ ! aGame->serverOptions.sendmail = NULL; ! aGame->serverOptions.encode = NULL; ! aGame->serverOptions.compress = NULL; ! aGame->serverOptions.GMemail = NULL; ! aGame->serverOptions.GMname = NULL; ! aGame->serverOptions.GMpassword = NULL; ! aGame->serverOptions.SERVERemail = NULL; ! aGame->serverOptions.SERVERname = NULL; ! aGame->serverOptions.ReplyTo = NULL; ! aGame->serverOptions.fontpath = NULL; ! aGame->serverOptions.due = NULL; ! aGame->serverOptions.tick_interval = NULL; } ! void ! readDefaults( game *aGame, FILE *f ) ! { ! char *isRead; /* to check for EOF */ ! char *key; /* the key part of the name/value pair */ ! ! for ( isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, f ); ! isRead; isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, f ) ) { ! ! key = getstr( lineBuffer ); ! if ( key[0] != '\0' ) { ! if ( noCaseStrcmp( "GMemail", key ) == 0 ) { ! if ( aGame->serverOptions.GMemail ) ! free( aGame->serverOptions.GMemail ); ! aGame->serverOptions.GMemail = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "GMname", key ) == 0 ) { ! if ( aGame->serverOptions.GMname ) ! free( aGame->serverOptions.GMname ); ! aGame->serverOptions.GMname = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "GMpassword", key ) == 0 ) { ! if ( aGame->serverOptions.GMpassword ) ! free( aGame->serverOptions.GMpassword ); ! aGame->serverOptions.GMpassword = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "SERVERemail", key ) == 0 ) { ! if ( aGame->serverOptions.SERVERemail ) ! free( aGame->serverOptions.SERVERemail ); ! aGame->serverOptions.SERVERemail = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "SERVERname", key ) == 0 ) { ! if ( aGame->serverOptions.SERVERname ) ! free( aGame->serverOptions.SERVERname ); ! aGame->serverOptions.SERVERname = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "ReplyTo", key ) == 0 ) { ! if ( aGame->serverOptions.ReplyTo ) ! free( aGame->serverOptions.ReplyTo ); ! aGame->serverOptions.ReplyTo = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "compress", key ) == 0 ) { ! if ( aGame->serverOptions.compress ) ! free( aGame->serverOptions.compress ); ! aGame->serverOptions.compress = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "encode", key ) == 0 ) { ! if ( aGame->serverOptions.encode ) ! free( aGame->serverOptions.encode ); ! aGame->serverOptions.encode = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "sendmail", key ) == 0 ) { ! if ( aGame->serverOptions.sendmail ) ! free( aGame->serverOptions.sendmail ); ! aGame->serverOptions.sendmail = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "starttime", key ) == 0 ) { ! if ( aGame->starttime ) ! free( aGame->starttime ); ! aGame->starttime = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "fontpath", key ) == 0 ) { ! if ( aGame->serverOptions.fontpath ) ! free( aGame->serverOptions.fontpath ); ! aGame->serverOptions.fontpath = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "due", key ) == 0 ) { ! if ( aGame->serverOptions.due ) ! free( aGame->serverOptions.due ); ! aGame->serverOptions.due = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "tick", key ) == 0 ) { ! if ( aGame->serverOptions.tick_interval ) ! free( aGame->serverOptions.tick_interval ); ! aGame->serverOptions.tick_interval = strdup( getstr( 0 ) ); ! } else { ! printf( "Unknown key \"%s\"\n", key ); ! } ! } } ! if ( aGame->serverOptions.due == NULL ) ! aGame->serverOptions.due = strdup( "soon" ); ! if ( aGame->serverOptions.tick_interval == NULL ) ! aGame->serverOptions.tick_interval = strdup( "48" ); ! if ( aGame->serverOptions.SERVERemail == NULL ) { ! char *logfile = ! createString( "%s/Games/log/%s", galaxynghome, aGame->name ); ! FILE *logfp = fopen( logfile, "+w" ); ! fprintf( stderr, ! "SERVERemail is a required entry in your .galaxyngrc\n" ); ! fprintf( logfp, ! "SERVERemail is a required entry in your .galaxyngrc\n" ); ! fclose( logfp ); ! exit( EXIT_FAILURE ); ! } ! ! if ( aGame->serverOptions.SERVERname == NULL ) ! aGame->serverOptions.SERVERname = strdup( "GalaxyNG Server" ); ! ! if ( aGame->serverOptions.GMemail == NULL ) ! aGame->serverOptions.GMemail = ! strdup( aGame->serverOptions.SERVERemail ); ! ! if ( aGame->serverOptions.GMname == NULL ) ! aGame->serverOptions.GMname = strdup( "GalaxyNG GM" ); ! ! if ( aGame->serverOptions.ReplyTo == NULL ) ! aGame->serverOptions.ReplyTo = ! strdup( aGame->serverOptions.SERVERemail ); ! ! if ( aGame->serverOptions.GMpassword == NULL ) ! aGame->serverOptions.GMpassword = strdup( "" ); } *************** *** 156,176 **** void ! loadNGConfig(game *aGame) { ! FILE *f; ! initServerOptions(aGame); ! sprintf(lineBuffer, "%s/.galaxyngrc", galaxynghome); ! if ((f = fopen(lineBuffer, "r"))) { ! readDefaults(aGame, f); ! fclose(f); ! } ! sprintf(lineBuffer, "%s/data/%s/.galaxyngrc", galaxynghome, aGame->name); ! if ((f = fopen(lineBuffer, "r"))) { ! readDefaults(aGame, f); ! fclose(f); ! } } - - --- 148,168 ---- void ! loadNGConfig( game *aGame ) ! { ! FILE *f; ! initServerOptions( aGame ); ! sprintf( lineBuffer, "%s/.galaxyngrc", galaxynghome ); ! if ( ( f = fopen( lineBuffer, "r" ) ) ) { ! readDefaults( aGame, f ); ! fclose( f ); ! } ! sprintf( lineBuffer, "%s/data/%s/.galaxyngrc", galaxynghome, ! aGame->name ); ! if ( ( f = fopen( lineBuffer, "r" ) ) ) { ! readDefaults( aGame, f ); ! fclose( f ); ! } } Index: strutl.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/strutl.c,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** strutl.c 5 Aug 2004 20:51:43 -0000 1.4 --- strutl.c 22 Jun 2007 22:28:39 -0000 1.4.2.1 *************** *** 134,157 **** */ ! strlist* makestrlist(char* ns) { ! strlist* s; ! strlist* cur; - char* tmp; - char* sPtr; - char* ePtr; - char* sep; - cur = NULL; ! sPtr = tmp = strdup(ns); ! sep = ePtr = strpbrk(sPtr, "\n\r"); - if (ePtr == NULL) { - cur = (strlist*)allocStruct(strlist); - cur->str = tmp; - return cur; - } - do { if ( cur ) { --- 134,159 ---- */ ! strlist * ! makestrlist( char *ns ) ! { ! strlist *s; ! strlist *cur; ! ! char *tmp; ! char *sPtr; ! char *ePtr; ! char *sep; cur = NULL; ! sPtr = tmp = strdup( ns ); ! sep = ePtr = strpbrk( sPtr, "\n\r" ); ! ! if ( ePtr == NULL ) { ! cur = ( strlist * ) allocStruct( strlist ); ! cur->str = tmp; ! return cur; ! } do { if ( cur ) { *************** *** 161,180 **** s = cur = ( strlist * ) allocStruct( strlist ); ! *ePtr = '\0'; cur->str = strdup( sPtr ); ! if (*sep == '\n' && *(ePtr+1) == '\r') ! sPtr = ePtr + 2; ! else ! sPtr = ePtr + 1; ! } while ((sep = ePtr = strpbrk(sPtr, "\n\r")) != NULL); - if (*sPtr != '\0') { - cur->next = ( strlist * ) allocStruct( strlist ); - cur = cur->next; - cur->str = strdup(sPtr); - } - free( tmp ); --- 163,182 ---- s = cur = ( strlist * ) allocStruct( strlist ); ! *ePtr = '\0'; cur->str = strdup( sPtr ); ! if ( *sep == '\n' && *( ePtr + 1 ) == '\r' ) ! sPtr = ePtr + 2; ! else ! sPtr = ePtr + 1; ! } while ( ( sep = ePtr = strpbrk( sPtr, "\n\r" ) ) != NULL ); ! ! if ( *sPtr != '\0' ) { ! cur->next = ( strlist * ) allocStruct( strlist ); ! cur = cur->next; ! cur->str = strdup( sPtr ); ! } free( tmp ); *************** *** 214,221 **** void ! dumpstrlist(strlist *aStrlist) { ! for (; aStrlist; aStrlist = aStrlist->next) { ! printf("%s\n", aStrlist->str); } } --- 216,223 ---- void ! dumpstrlist( strlist *aStrlist ) { ! for ( ; aStrlist; aStrlist = aStrlist->next ) { ! printf( "%s\n", aStrlist->str ); } } *************** *** 237,246 **** int ! noCaseStrcmp(const char *s, const char *t) { ! for (; tolower(*s) == tolower(*t); s++, t++) ! if (*s == '\0') ! return 0; ! return (int) (tolower(*s) - tolower(*t)); } --- 239,248 ---- int ! noCaseStrcmp( const char *s, const char *t ) { ! for ( ; tolower( *s ) == tolower( *t ); s++, t++ ) ! if ( *s == '\0' ) ! return 0; ! return ( int ) ( tolower( *s ) - tolower( *t ) ); } *************** *** 264,273 **** int ! noCaseStrncmp(const char *s, const char *t, int n) { ! for (n--; (tolower(*s) == tolower(*t)) && (n > 0); s++, t++, n--) ! if (*s == '\0') ! return 0; ! return (int) (tolower(*s) - tolower(*t)); } --- 266,276 ---- int ! noCaseStrncmp( const char *s, const char *t, int n ) { ! for ( n--; ( tolower( *s ) == tolower( *t ) ) && ( n > 0 ); ! s++, t++, n-- ) ! if ( *s == '\0' ) ! return 0; ! return ( int ) ( tolower( *s ) - tolower( *t ) ); } *************** *** 276,288 **** ! char* strlwr(char* str) { ! char* ptr = str; ! while (*ptr) { ! if (isupper(*ptr)) ! *ptr = tolower(*ptr); ! ptr++; ! } ! return str; } --- 279,293 ---- ! char * ! strlwr( char *str ) ! { ! char *ptr = str; ! while ( *ptr ) { ! if ( isupper( *ptr ) ) ! *ptr = tolower( *ptr ); ! ptr++; ! } ! return str; } Index: list.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/list.c,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -C2 -d -r1.8 -r1.8.2.1 *** list.c 19 Jun 2007 08:00:10 -0000 1.8 --- list.c 22 Jun 2007 22:28:38 -0000 1.8.2.1 *************** *** 17,30 **** int ! numberOfElementsF(list *aList) { ! list *el; ! int noEl; ! noEl = 0; ! if (aList) ! for (el = aList; el; el = el->next) ! noEl++; ! return noEl; } --- 17,30 ---- int ! numberOfElementsF( list *aList ) { ! list *el; ! int noEl; ! noEl = 0; ! if ( aList ) ! for ( el = aList; el; el = el->next ) ! noEl++; ! return noEl; } *************** *** 36,43 **** void ! add2ListF(list **aList, list *anElement) { ! anElement->next = *aList; ! *aList = anElement; } --- 36,43 ---- void ! add2ListF( list **aList, list *anElement ) { ! anElement->next = *aList; ! *aList = anElement; } *************** *** 50,67 **** void ! freelist(void *base) { ! list *p, *p2; ! pdebug(DFULL2, "freelist"); ! p = base; ! while (p) { ! p2 = p->next; ! free(p->name); ! free(p); ! p = p2; ! pdebug(DFULL2, "."); ! } ! pdebug(DFULL2, "\n"); } --- 50,67 ---- void ! freelist( void *base ) { ! list *p, *p2; ! pdebug( DFULL2, "freelist" ); ! p = base; ! while ( p ) { ! p2 = p->next; ! free( p->name ); ! free( p ); ! p = p2; ! pdebug( DFULL2, "." ); ! } ! pdebug( DFULL2, "\n" ); } *************** *** 73,90 **** ****** */ ! void ! addListF(list **aList, list *anElement) { ! list *curElement; ! if (*aList == NULL) { ! *aList = anElement; ! } else { ! for (curElement = *aList; ! curElement->next; ! curElement = curElement->next); ! curElement->next = anElement; ! } } --- 73,89 ---- ****** */ ! void ! addListF( list **aList, list *anElement ) { ! list *curElement; ! if ( *aList == NULL ) { ! *aList = anElement; ! } else { ! for ( curElement = *aList; ! curElement->next; curElement = curElement->next ); ! curElement->next = anElement; ! } } *************** *** 95,123 **** ****** */ ! void ! insertListF(list **aList, list* where, list *anElement) { ! list *curElement; ! list *listEnd; ! if (*aList == NULL) { ! *aList = anElement; ! } ! else { ! for (curElement = *aList; curElement->next; ! curElement = curElement->next) { ! if (curElement == where) { ! break; ! } ! } ! for (listEnd = anElement; listEnd->next; listEnd = listEnd->next) ! ; ! listEnd->next = curElement->next; ! curElement->next = anElement; ! } } --- 94,120 ---- ****** */ ! void ! insertListF( list **aList, list *where, list *anElement ) { ! list *curElement; ! list *listEnd; ! if ( *aList == NULL ) { ! *aList = anElement; ! } else { ! for ( curElement = *aList; curElement->next; ! curElement = curElement->next ) { ! if ( curElement == where ) { ! break; ! } ! } ! for ( listEnd = anElement; listEnd->next; listEnd = listEnd->next ); ! listEnd->next = curElement->next; ! curElement->next = anElement; ! } } *************** *** 140,155 **** */ ! list* ! findElementF(list *aList, char *name) { ! list *anElement; ! for (anElement = aList; ! anElement; ! anElement = anElement->next) { ! if (!noCaseStrcmp(anElement->name, name)) ! break; ! } ! return anElement; } --- 137,150 ---- */ ! list * ! findElementF( list *aList, char *name ) { ! list *anElement; ! for ( anElement = aList; anElement; anElement = anElement->next ) { ! if ( !noCaseStrcmp( anElement->name, name ) ) ! break; ! } ! return anElement; } *************** *** 169,189 **** void ! removeListF(list **aList, list *anElement) { ! list *prevElement; ! assert(anElement != NULL); ! if (*aList == anElement) ! *aList = anElement->next; ! else { ! for (prevElement = *aList; ! prevElement->next != anElement; ! prevElement = prevElement->next) { ! assert(prevElement != NULL); } ! prevElement->next = anElement->next; ! } ! free(anElement); } --- 164,184 ---- void ! removeListF( list **aList, list *anElement ) { ! list *prevElement; ! assert( anElement != NULL ); ! if ( *aList == anElement ) ! *aList = anElement->next; ! else { ! for ( prevElement = *aList; ! prevElement->next != anElement; ! prevElement = prevElement->next ) { ! assert( prevElement != NULL ); ! } ! prevElement->next = anElement->next; } ! free( anElement ); } *************** *** 207,219 **** int ! ptonum(void *base, void *target) { ! list *p; ! int i; ! for (p = base, i = 1; p; p = p->next, i++) ! if (p == target) ! return i; ! return 0; } --- 202,214 ---- int ! ptonum( void *base, void *target ) { ! list *p; ! int i; ! for ( p = base, i = 1; p; p = p->next, i++ ) ! if ( p == target ) ! return i; ! return 0; } *************** *** 235,250 **** void * ! numtop(void *base, int n) { ! list *p; ! int i; ! i = 0; ! for (p = base; p; p = p->next) { ! i++; ! if (i == n) ! return p; ! } ! return 0; } --- 230,245 ---- void * ! numtop( void *base, int n ) { ! list *p; ! int i; ! i = 0; ! for ( p = base; p; p = p->next ) { ! i++; ! if ( i == n ) ! return p; ! } ! return 0; } *************** *** 265,283 **** void ! setNameF(list *anElement, const char *name) { ! free(anElement->name); ! anElement->name = strdup(name); } void ! dumpList(char* label, list* aList, void* callback(void*)) { ! list* curElement; ! fprintf(stderr, "*** %s ***\n", label); ! for (curElement = aList; curElement; curElement=curElement->next) { ! fprintf(stderr, "%lX: %s\n", curElement->cookie, curElement->name); ! callback((void*)curElement); } } --- 260,278 ---- void ! setNameF( list *anElement, const char *name ) { ! free( anElement->name ); ! anElement->name = strdup( name ); } void ! dumpList( char *label, list *aList, void *callback( void * ) ) { ! list *curElement; ! fprintf( stderr, "*** %s ***\n", label ); ! for ( curElement = aList; curElement; curElement = curElement->next ) { ! fprintf( stderr, "%lX: %s\n", curElement->cookie, curElement->name ); ! callback( ( void * ) curElement ); } } *************** *** 288,321 **** void ! dumpRandList(char* label, list* aList, void* callback(void*)) { ! list* curElement; /* TODO */ #if 0 ! fprintf(stderr, "*** %s ***\n", label); assert( 0 ); ! for (curElement = aList; curElement; curElement=curElement->randNext) { ! fprintf(stderr, "%lX: %s\n", curElement->cookie, curElement->name); ! callback((void*)curElement); } #endif } ! void* ! allocStructF(unsigned int n, long cookie) { ! list *p; ! ! p = calloc(1, n); ! if (p == 0) { ! pdebug(DERR, "Out of memory, aborting program.\n"); ! exit(1); ! } ! p->cookie = cookie; ! p->name = NULL; ! p->next = NULL; ! /* TODO p->randNext = NULL; */ ! return (void *) p; ! } --- 283,314 ---- void ! dumpRandList( char *label, list *aList, void *callback( void * ) ) { ! list *curElement; /* TODO */ #if 0 ! fprintf( stderr, "*** %s ***\n", label ); assert( 0 ); ! for ( curElement = aList; curElement; curElement = curElement->randNext ) { ! fprintf( stderr, "%lX: %s\n", curElement->cookie, curElement->name ); ! callback( ( void * ) curElement ); } #endif } ! void * ! allocStructF( unsigned int n, long cookie ) { ! list *p; ! p = calloc( 1, n ); ! if ( p == 0 ) { ! pdebug( DERR, "Out of memory, aborting program.\n" ); ! exit( 1 ); ! } ! p->cookie = cookie; ! p->name = NULL; ! p->next = NULL; + return ( void * ) p; + } Index: lockFile.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/lockFile.c,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** lockFile.c 25 Jun 2004 11:44:59 -0000 1.1 --- lockFile.c 22 Jun 2007 22:28:38 -0000 1.1.2.1 *************** *** 8,99 **** #include <signal.h> ! static int readData(int fd, void* buf, size_t nbrBytes) { ! size_t toRead; ! size_t nbrRead = 0; ! ssize_t result; ! do { ! if (nbrBytes - nbrRead > SSIZE_MAX) ! toRead = SSIZE_MAX; ! else ! toRead = nbrBytes - nbrRead; ! if ((result = read(fd, (char*)buf+nbrRead, toRead)) >= 0) ! nbrRead += result; ! else if (errno != EINTR) ! return 0; ! } while (nbrRead < nbrBytes); ! return 1; } ! static int writeData(int fd, const void* buf, size_t nbrBytes) { ! size_t toWrite; ! size_t written = 0; ! ssize_t result; ! do { ! if (nbrBytes - written > SSIZE_MAX) ! toWrite = SSIZE_MAX; ! else ! toWrite = nbrBytes - written; ! if ((result = write(fd, (const char*)buf + written, toWrite)) >= 0) ! written += result; ! else if (errno != EINTR) ! return 0; ! } while (written < nbrBytes); ! return 1; } ! int spcLockFile(const char* lfpath) { ! int attempt; ! int fd; ! int result; ! pid_t pid; ! /* try 3 times, if we fail, we lose */ ! for (attempt = 0; attempt < 3; attempt++) { ! if ((fd = open(lfpath, O_RDWR|O_CREAT|O_EXCL, S_IRWXU)) == -1) { ! if (errno != EEXIST) ! return -1; ! if ((fd = open(lfpath, O_RDONLY)) == -1) ! return -1; ! result = readData(fd, &pid, sizeof(pid)); ! close(fd); ! if (result) { ! if (pid == getpid()) ! return 1; ! if (kill(pid, 0) == -1) { ! if (errno != ESRCH) ! return -1; ! attempt--; ! unlink(lfpath); ! continue; ! } ! } ! sleep(1); ! continue; ! } ! pid = getpid(); ! if (!writeData(fd, &pid, sizeof(pid))) { ! close(fd); ! return -1; ! } ! close(fd); ! attempt--; ! } ! /* If we've made it to here, three attempts have been made and the ! * lock could not be obtained. Return an error code indicating ! * failure to obtain the requested lock. ! */ ! return 0; } --- 8,107 ---- #include <signal.h> ! static int ! readData( int fd, void *buf, size_t nbrBytes ) ! { ! size_t toRead; ! size_t nbrRead = 0; ! ssize_t result; ! do { ! if ( nbrBytes - nbrRead > SSIZE_MAX ) ! toRead = SSIZE_MAX; ! else ! toRead = nbrBytes - nbrRead; ! if ( ( result = read( fd, ( char * ) buf + nbrRead, toRead ) ) >= 0 ) ! nbrRead += result; ! else if ( errno != EINTR ) ! return 0; ! } while ( nbrRead < nbrBytes ); ! return 1; } ! static int ! writeData( int fd, const void *buf, size_t nbrBytes ) ! { ! size_t toWrite; ! size_t written = 0; ! ssize_t result; ! do { ! if ( nbrBytes - written > SSIZE_MAX ) ! toWrite = SSIZE_MAX; ! else ! toWrite = nbrBytes - written; ! if ( ( result = ! write( fd, ( const char * ) buf + written, toWrite ) ) >= 0 ) ! written += result; ! else if ( errno != EINTR ) ! return 0; ! } while ( written < nbrBytes ); ! return 1; } ! int ! spcLockFile( const char *lfpath ) ! { ! int attempt; ! int fd; ! int result; ! pid_t pid; ! /* try 3 times, if we fail, we lose */ ! for ( attempt = 0; attempt < 3; attempt++ ) { ! if ( ( fd = ! open( lfpath, O_RDWR | O_CREAT | O_EXCL, S_IRWXU ) ) == -1 ) { ! if ( errno != EEXIST ) ! return -1; ! if ( ( fd = open( lfpath, O_RDONLY ) ) == -1 ) ! return -1; ! result = readData( fd, &pid, sizeof( pid ) ); ! close( fd ); ! if ( result ) { ! if ( pid == getpid( ) ) ! return 1; ! if ( kill( pid, 0 ) == -1 ) { ! if ( errno != ESRCH ) ! return -1; ! attempt--; ! unlink( lfpath ); ! continue; ! } ! } ! sleep( 1 ); ! continue; ! } ! pid = getpid( ); ! if ( !writeData( fd, &pid, sizeof( pid ) ) ) { ! close( fd ); ! return -1; ! } ! close( fd ); ! attempt--; ! } ! /* If we've made it to here, three attempts have been made and the ! * lock could not be obtained. Return an error code indicating ! * failure to obtain the requested lock. ! */ ! return 0; } Index: mail.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/mail.c,v retrieving revision 1.18 retrieving revision 1.18.2.1 diff -C2 -d -r1.18 -r1.18.2.1 *** mail.c 16 Jan 2005 19:39:26 -0000 1.18 --- mail.c 22 Jun 2007 22:28:38 -0000 1.18.2.1 *************** *** 15,44 **** ! void createMailToAllHeader(game *aGame) { ! player* aPlayer; ! int state; ! if (aGame->serverOptions.SERVERemail) { ! if (aGame->serverOptions.SERVERname) { ! printf("From: %s <%s>\n", aGame->serverOptions.SERVERname, aGame->serverOptions.SERVERemail); ! } else { ! prin... [truncated message content] |