--- deliantra/server/common/image.C 2006/08/13 17:16:00 1.1 +++ deliantra/server/common/image.C 2006/09/08 16:51:42 1.5 @@ -1,6 +1,6 @@ /* * static char *rcsid_image_c = - * "$Id: image.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; + * "$Id: image.C,v 1.5 2006/09/08 16:51:42 root Exp $"; */ /* @@ -44,11 +44,14 @@ * the bmaps file is created in a sorted order. */ -struct bmappair { - char *name; - unsigned int number; +struct bmappair +{ + char *name; + unsigned int number; }; +void free (bmappair *); // guard to catch free when delete should be used + static struct bmappair *xbm=NULL; /* Following can just as easily be pointers, but @@ -73,11 +76,14 @@ /** * id is the face to smooth, smooth is the 16x2 face used to smooth id. */ -struct smoothing { +struct smoothing : zero_initialised +{ uint16 id; uint16 smooth; }; +void free (smoothing *); // guard to catch free when delete should be used + /** * Contains all defined smoothing entries. smooth is an array of nrofsmooth * entries. It is sorted by smooth[].id. @@ -147,51 +153,51 @@ sprintf(buf,"%s/faces", settings.datadir); LOG(llevDebug,"Reading faces from %s...",buf); if ((fp=fopen(buf,"r"))==NULL) { - LOG(llevError, "Cannot open faces file %s: %s\n", buf, strerror_local(errno)); - exit(-1); + LOG(llevError, "Cannot open faces file %s: %s\n", buf, strerror(errno)); + exit(-1); } while (fgets(buf, MAX_BUF, fp)!=NULL) { - if (*buf=='#') continue; - if (!strncmp(buf,"end",3)) { - on_face = NULL; - } - else if (!strncmp(buf,"face",4)) { - int tmp; - - cp = buf + 5; - cp[strlen(cp)-1] = '\0'; /* remove newline */ - - if ((tmp=FindFace(cp,-1))==-1) { - LOG(llevError,"Could not find face %s\n", cp); - continue; - } - on_face = &new_faces[tmp]; - on_face->visibility=0; - } - else if (on_face==NULL) { - LOG(llevError,"Got line with no face set: %s\n", buf); - } - else if (!strncmp(buf,"color_fg",8)) { - cp = buf + 9; - cp[strlen(cp)-1] = '\0'; - if (on_face->magicmap==255) on_face->magicmap=find_color(cp); - } - else if (!strncmp(buf,"color_bg",8)) { - /* ignore it */ - } - else if (!strncmp(buf,"visibility",10)) { - on_face->visibility = atoi(buf + 11); - } - else if (!strncmp(buf,"magicmap",8)) { - cp=buf+9; - cp[strlen(cp)-1] = '\0'; - on_face->magicmap=find_color(cp); - } - else if (!strncmp(buf,"is_floor",8)) { - int value = atoi(buf+9); - if (value) on_face->magicmap |= FACE_FLOOR; - } - else LOG(llevDebug,"Got unknown line in faces file: %s\n", buf); + if (*buf=='#') continue; + if (!strncmp(buf,"end",3)) { + on_face = NULL; + } + else if (!strncmp(buf,"face",4)) { + int tmp; + + cp = buf + 5; + cp[strlen(cp)-1] = '\0'; /* remove newline */ + + if ((tmp=FindFace(cp,-1))==-1) { + LOG(llevError,"Could not find face %s\n", cp); + continue; + } + on_face = &new_faces[tmp]; + on_face->visibility=0; + } + else if (on_face==NULL) { + LOG(llevError,"Got line with no face set: %s\n", buf); + } + else if (!strncmp(buf,"color_fg",8)) { + cp = buf + 9; + cp[strlen(cp)-1] = '\0'; + if (on_face->magicmap==255) on_face->magicmap=find_color(cp); + } + else if (!strncmp(buf,"color_bg",8)) { + /* ignore it */ + } + else if (!strncmp(buf,"visibility",10)) { + on_face->visibility = atoi(buf + 11); + } + else if (!strncmp(buf,"magicmap",8)) { + cp=buf+9; + cp[strlen(cp)-1] = '\0'; + on_face->magicmap=find_color(cp); + } + else if (!strncmp(buf,"is_floor",8)) { + int value = atoi(buf+9); + if (value) on_face->magicmap |= FACE_FLOOR; + } + else LOG(llevDebug,"Got unknown line in faces file: %s\n", buf); } LOG(llevDebug,"done\n"); fclose(fp); @@ -213,83 +219,84 @@ sprintf (buf,"%s/bmaps", settings.datadir); LOG(llevDebug,"Reading bmaps from %s...",buf); if ((fp=fopen(buf,"r"))==NULL) { - LOG(llevError, "Cannot open bmaps file %s: %s\n", buf, strerror_local(errno)); - exit(-1); + LOG(llevError, "Cannot open bmaps file %s: %s\n", buf, strerror(errno)); + exit(-1); } /* First count how many bitmaps we have, so we can allocate correctly */ while (fgets (buf, MAX_BUF, fp)!=NULL) - if(buf[0] != '#' && buf[0] != '\n' ) - nrofbmaps++; + if(buf[0] != '#' && buf[0] != '\n' ) + nrofbmaps++; rewind(fp); - xbm = (struct bmappair *) malloc(sizeof(struct bmappair) * nrofbmaps); + xbm = new bmappair [nrofbmaps]; memset (xbm, 0, sizeof (struct bmappair) * nrofbmaps); while(nroffiles < nrofbmaps && fgets (buf, MAX_BUF, fp) != NULL) { - if (*buf == '#') - continue; - - p = (*buf == '\\') ? (buf + 1): buf; - if (!(p = strtok (p , " \t")) || !(q = strtok (NULL , " \t\n"))) { - LOG(llevDebug,"Warning, syntax error: %s\n", buf); - continue; - } - value = atoi (p); - xbm[nroffiles].name = strdup_local(q); - - /* We need to calculate the checksum of the bmaps file - * name->number mapping to send to the client. This does not - * need to match what sum or other utility may come up with - - * as long as we get the same results on the same real file - * data, it does the job as it lets the client know if - * the file has the same data or not. - */ - ROTATE_RIGHT(bmaps_checksum); - bmaps_checksum += value & 0xff; - bmaps_checksum &= 0xffffffff; - - ROTATE_RIGHT(bmaps_checksum); - bmaps_checksum += (value >> 8) & 0xff; - bmaps_checksum &= 0xffffffff; - for (l=0; l= nrofpixmaps) - nrofpixmaps = value+1; + if (*buf == '#') + continue; + + p = (*buf == '\\') ? (buf + 1): buf; + if (!(p = strtok (p , " \t")) || !(q = strtok (NULL , " \t\n"))) { + LOG(llevDebug,"Warning, syntax error: %s\n", buf); + continue; + } + value = atoi (p); + xbm[nroffiles].name = strdup_local(q); + + /* We need to calculate the checksum of the bmaps file + * name->number mapping to send to the client. This does not + * need to match what sum or other utility may come up with - + * as long as we get the same results on the same real file + * data, it does the job as it lets the client know if + * the file has the same data or not. + */ + ROTATE_RIGHT(bmaps_checksum); + bmaps_checksum += value & 0xff; + bmaps_checksum &= 0xffffffff; + + ROTATE_RIGHT(bmaps_checksum); + bmaps_checksum += (value >> 8) & 0xff; + bmaps_checksum &= 0xffffffff; + for (l=0; l= nrofpixmaps) + nrofpixmaps = value+1; } fclose(fp); LOG(llevDebug,"done (got %d/%d/%d)\n",nrofpixmaps,nrofbmaps,nroffiles); - new_faces = (New_Face *)malloc(sizeof(New_Face) * nrofpixmaps); + new_faces = new New_Face [nrofpixmaps]; for (i = 0; i < nrofpixmaps; i++) { - new_faces[i].name = ""; - new_faces[i].number = i; - new_faces[i].visibility=0; - new_faces[i].magicmap=255; + new_faces[i].name = ""; + new_faces[i].number = i; + new_faces[i].visibility=0; + new_faces[i].magicmap=255; } for (i = 0; i < nroffiles; i++) { - new_faces[xbm[i].number].name = xbm[i].name; + new_faces[xbm[i].number].name = xbm[i].name; } + // non-pod datatype, likely not allowed qsort (xbm, nroffiles, sizeof(struct bmappair), (int (*)(const void*, const void*))compar); ReadFaceData(); for (i = 0; i < nrofpixmaps; i++) { - if (new_faces[i].magicmap==255) { + if (new_faces[i].magicmap==255) { #if 0 /* Useful for initial debugging, not needed now */ - LOG(llevDebug,"Face %s still had default magicmap, resetting to black\n", - new_faces[i].name); + LOG(llevDebug,"Face %s still had default magicmap, resetting to black\n", + new_faces[i].name); #endif - new_faces[i].magicmap=0; - } + new_faces[i].magicmap=0; + } } /* Actually forcefully setting the colors here probably should not * be done - it could easily create confusion. @@ -323,12 +330,15 @@ struct bmappair *bp, tmp; char *p; + if (!name) + return error; + if ((p = strchr (name, '\n'))) - *p = '\0'; + *p = '\0'; tmp.name = (char *)name; bp = (struct bmappair *)bsearch - (&tmp, xbm, nroffiles, sizeof(struct bmappair), (int (*)(const void*, const void*))compar); + (&tmp, xbm, nroffiles, sizeof(struct bmappair), (int (*)(const void*, const void*))compar); return bp ? bp->number : error; } @@ -349,18 +359,17 @@ sprintf (buf,"%s/smooth", settings.datadir); LOG(llevDebug,"Reading smooth from %s...",buf); if ((fp=fopen(buf,"r"))==NULL) { - LOG(llevError, "Cannot open smooth file %s: %s\n", strerror_local(errno)); - exit(-1); + LOG(llevError, "Cannot open smooth file %s: %s\n", strerror(errno)); + exit(-1); } /* First count how many smooth we have, so we can allocate correctly */ while (fgets (buf, MAX_BUF, fp)!=NULL) - if(buf[0] != '#' && buf[0] != '\n' ) - smoothcount++; + if(buf[0] != '#' && buf[0] != '\n' ) + smoothcount++; rewind(fp); - smooth = (struct smoothing *) malloc(sizeof(struct smoothing) * (smoothcount)); - memset (smooth, 0, sizeof (struct smoothing) * (smoothcount)); + smooth = new smoothing [smoothcount]; while(nrofsmooth < smoothcount && fgets (buf, MAX_BUF, fp)!=NULL) { if (*buf == '#') @@ -411,8 +420,9 @@ int i; for (i=0; i