rem: state = (drill_state_t *)malloc(sizeof(drill_state_t));
add: state = new_state(state);
context: parse_drillfile(FILE *fd){    drill_state_t *state = NULL;    drill_image_t *image = NULL;    drill_hole_t *curr_hole = NULL;    char read;    double x_scale, y_scale;    state = (drill_state_t *)malloc(sizeof(drill_state_t));    if (state == NULL)	err(1, "malloc state failed\n");    bzero((void *)state, sizeof(drill_state_t));    image = (drill_image_t *)malloc(sizeof(drill_image_t));    if (image == NULL)	err(1, "malloc image failed\n");    bzero((void *)image, sizeof(drill_image_t));    image->holes = (drill_hole_t *)malloc(sizeof(drill_hole_t));    if (image->holes == NULL)	err(1, "malloc image->hole failed\n");    bzero((void *)image->holes, sizeof(drill_hole_t));    curr_hole = image->holes;    image->info = (drill_image_info_t *)malloc(sizeof(drill_image_info_t));    if (image->info == NULL)	err(1, "malloc image->info failed\n");    bzero((void *)image->info, sizeof(drill_image_info_t));    image->info->min_x = HUGE_VAL;    image->info->min_y = HUGE_VAL;    image->info->max_x = -HUGE_VAL;    image->info->max_y = -HUGE_VAL;    image->format = (drill_format_t *)malloc(sizeof(drill_format_t));    if (image->format == NULL)	err(1, "malloc image->format failed\n");    bzero((void *)image->format, sizeof(drill_format_t));    while ((read = (char)fgetc(fd)) != EOF) {		switch (read) {	case ';' :	    /* Comment found. Eat rest of line */	    eat_line(fd);	    break;	case 'G':/*	    drill_parse_G_code(fd, state, image->format); */	    eat_line(fd);	    	    break;	case 'T':	    drill_parse_T_code(fd, state, image);	    break;	case 'M':	    switch(drill_parse_M_code(fd, image)) {	    case DRILL_M_HEADER :	    case DRILL_M_METRIC :	    case DRILL_M_IMPERIAL :	    case DRILL_M_NOT_IMPLEMENTED :	    case DRILL_M_ENDOFPATTERN :		break;	    case DRILL_M_END :		free(state);		return image;		break;	    default:		err(1, "Strange M code found.\n");	    }	    break;	case 'X':	case 'Y':	    /* Hole coordinate found. Do some parsing */	    drill_parse_coordinate(fd, read, state);	    curr_hole->next = (drill_hole_t *)malloc(sizeof(drill_hole_t));	    curr_hole = curr_hole->next;	    bzero((void *)curr_hole, sizeof(drill_hole_t));/*	    if (image && image->format ){		x_scale = pow(10.0, (double)image->format->x_dec);		y_scale = pow(10.0, (double)image->format->y_dec);	    }*//*	    curr_hole->x = (double)state->curr_x / x_scale;	    curr_hole->y = (double)state->curr_y / y_scale;*/	    curr_hole->x = (double)state->curr_x;	    curr_hole->y = (double)state->curr_y;	    curr_hole->tool_num = state->current_tool;	    /*	     * Find min and max of image	     */	    if (image->info->min_x == 0.0 || image->info->min_x > curr_hole->x)		image->info->min_x = curr_hole->x;	    if (image->info->min_y == 0.0 || image->info->min_y > curr_hole->y)		image->info->min_y = curr_hole->y;	    if (image->info->max_x < curr_hole->x)		image->info->max_x = curr_hole->x;	    if (image->info->max_y < curr_hole->x)		image->info->max_y = curr_hole->y;	    break;	case '%':	    printf("Found start of data segment\n");/*	    parse_drill(fd, state, image); */	    break;#if 0	case '*':/*			state->prev_x = state->curr_x;			state->prev_y = state->curr_y;*/	    break;#endif	case 10 :   /* White space */	case 13 :	case ' ' :	case '\t' :	    break;	default:	    fprintf(stderr, "Found unknown character (whitespace?) %c[%d]\n", read, read);	}    }    fprintf(stderr, "File is missing drill End-Of-File\n");    return image;} /* parse_drillfile */