char *parse_header(char *input, struct MailHeader *mh) { static char *buf = NULL; static size_t buflen = BUF_LEN; char *next_line = NULL; int i; int (*cmpfun)(const char *, const char *, size_t); if (!input || !mh) return NULL; /* * Set default value */ memset(mh, 0, sizeof(struct MailHeader)); strcpy(mh->content_type, "text/plain"); strcpy(mh->charset, "iso-8859-1"); strcpy(mh->transenc, "7bit"); if (!buf) buf = (char *)malloc(buflen); if (!buf) return NULL; memset(buf, 0, buflen); next_line = cgetline(input, &buf, 0, &buflen); while (buf[0] && buf[0] != '\n') { for (i = 0 ; hh[i].header ; ++i) { cmpfun = (hh[i].casesence) ? strncmp : strncasecmp; if (!cmpfun(buf, hh[i].header, strlen(hh[i].header))) { if (hh[i].multiline) next_line = merge_input(next_line, &buf, &buflen); if (hh[i].hdl(buf + strlen(hh[i].header) + 1, mh)) { next_line = NULL; dbg("Error at %s %30.30s\n", hh[i].header, buf + strlen(hh[i].header) + 1); goto out; } break; } } next_line = cgetline(next_line, &buf, 0, &buflen); } out: return next_line; }
void TCOD_map_compute_fov_diamond_raycasting(TCOD_map_t map, int player_x, int player_y, int max_radius, bool light_walls) { map_t *m = (map_t *)map; TCOD_list_t perim=TCOD_list_allocate(m->nbcells); cell_t *c; ray_data_t **r; int nbcells; int r2=max_radius*max_radius; perimidx=0; raymap=(ray_data_t **)calloc(sizeof(ray_data_t*),m->nbcells); raymap2=(ray_data_t *)calloc(sizeof(ray_data_t),m->nbcells); origx=player_x; origy=player_y; expandPerimeterFrom(m,perim,new_ray(m,0,0)); while ( perimidx < TCOD_list_size(perim) ) { ray_data_t *ray=(ray_data_t *)TCOD_list_get(perim,perimidx); int distance = 0; if ( r2 > 0 ) distance = ((ray->xloc * ray->xloc) + (ray->yloc * ray->yloc)); perimidx++; if ( distance <= r2) { merge_input(m, ray); if ( !ray->ignore ) expandPerimeterFrom(m,perim,ray); } else ray->ignore=true; } // set fov data c=m->cells; r=raymap; nbcells=m->nbcells; while ( nbcells!= 0 ) { if ( *r == NULL || (*r)->ignore || ((*r)->xerr > 0 && (*r)->xerr <= (*r)->xob ) || ((*r)->yerr > 0 && (*r)->yerr <= (*r)->yob ) ) { c->fov=0; } else { c->fov=1; } c++; r++; nbcells--; } m->cells[origx+origy*m->width].fov=1; // light walls if ( light_walls ) { int xmin=0, ymin=0, xmax=m->width, ymax=m->height; if ( max_radius > 0 ) { xmin=MAX(0,player_x-max_radius); ymin=MAX(0,player_y-max_radius); xmax=MIN(m->width,player_x+max_radius+1); ymax=MIN(m->height,player_y+max_radius+1); } TCOD_map_postproc(m,xmin,ymin,player_x,player_y,-1,-1); TCOD_map_postproc(m,player_x,ymin,xmax-1,player_y,1,-1); TCOD_map_postproc(m,xmin,player_y,player_x,ymax-1,-1,1); TCOD_map_postproc(m,player_x,player_y,xmax-1,ymax-1,1,1); } free(raymap); free(raymap2); TCOD_list_delete(perim); }