add: if (((state->unit == UNIT_UNKNOWN) && (image->info->unit == MM)) || state->unit == MM) { x_scale *= 25.4; y_scale *= 25.4; }
context: parse_gerb(gerb_file_t *fd){    gerb_state_t *state = NULL;    gerb_image_t *image = NULL;    gerb_net_t *curr_net = NULL;    int read;    double x_scale = 0.0, y_scale = 0.0;    double delta_cp_x = 0.0, delta_cp_y = 0.0;    double aperture_size;        state = (gerb_state_t *)malloc(sizeof(gerb_state_t));    if (state == NULL)	GERB_FATAL_ERROR("malloc state failed\n");    /*     * Set some defaults     */    memset((void *)state, 0, sizeof(gerb_state_t));    state->layer_polarity = DARK;    /*      * Create new image     */    image = new_gerb_image(image);    if (image == NULL)	GERB_FATAL_ERROR("malloc image failed\n");    curr_net = image->netlist;    /*     * Start parsing     */    while ((read = gerb_fgetc(fd)) != EOF) {	switch ((char)(read & 0xff)) {	case 'G':	    parse_G_code(fd, state, image->format);	    break;	case 'D':	    parse_D_code(fd, state);	    break;	case 'M':	    switch(parse_M_code(fd)) {	    case 1 :	    case 2 :	    case 3 :		free(state);		return image;		break;	    default:		GERB_FATAL_ERROR("Strange M code found.\n");	    }	    break;	case 'X':	    state->curr_x = gerb_fgetint(fd);	    state->changed = 1;	    break;	case 'Y':	    state->curr_y = gerb_fgetint(fd);	    state->changed = 1;	    break;	case 'I':	    state->delta_cp_x = gerb_fgetint(fd);	    state->changed = 1;	    break;	case 'J':	    state->delta_cp_y = gerb_fgetint(fd);	    state->changed = 1;	    break;	case '%':	    parse_rs274x(fd, image, state);	    while (gerb_fgetc(fd) != '%');	    break;	case '*':	    if (state->changed == 0) break;	    state->changed = 0;	    curr_net->next = (gerb_net_t *)malloc(sizeof(gerb_net_t));	    curr_net = curr_net->next;	    memset((void *)curr_net, 0, sizeof(gerb_net_t));	    	    /*	     * Scale to given coordinate format	     * XXX only "omit leading zeros".	     */	    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_net->start_x = (double)state->prev_x / x_scale;	    curr_net->start_y = (double)state->prev_y / y_scale;	    curr_net->stop_x = (double)state->curr_x / x_scale;	    curr_net->stop_y = (double)state->curr_y / y_scale;	    delta_cp_x = (double)state->delta_cp_x / x_scale;	    delta_cp_y = (double)state->delta_cp_y / y_scale;	    switch (state->interpolation) {	    case CW_CIRCULAR :		curr_net->cirseg = (gerb_cirseg_t *)malloc(sizeof(gerb_cirseg_t));		memset((void *)curr_net->cirseg, 0, sizeof(gerb_cirseg_t));		if (state->mq_on)		    calc_cirseg_mq(curr_net, 1, delta_cp_x, delta_cp_y);		else		    calc_cirseg_sq(curr_net, 1, delta_cp_x, delta_cp_y);		break;	    case CCW_CIRCULAR :		curr_net->cirseg = (gerb_cirseg_t *)malloc(sizeof(gerb_cirseg_t));		memset((void *)curr_net->cirseg, 0, sizeof(gerb_cirseg_t));		if (state->mq_on)		    calc_cirseg_mq(curr_net, 0, delta_cp_x, delta_cp_y);		else		    calc_cirseg_sq(curr_net, 0, delta_cp_x, delta_cp_y);		break;	    case PAREA_START :		/* 		 * To be able to get back and fill in number of polygon corners		 */		state->parea_start_node = curr_net;		state->in_parea_fill = 1;		break;	    case PAREA_END :		state->parea_start_node = NULL;		state->in_parea_fill = 0;		break;	    default :		break;	    }	    /* 	     * Count number of points in Polygon Area 	     */	    if (state->in_parea_fill && state->parea_start_node) 		state->parea_start_node->nuf_pcorners++;	    curr_net->interpolation = state->interpolation;	    /*	     * If we detected the end of Polygon Area Fill we go back to	     * the interpolation we had before that.	     * Also if we detected any of the quadrant flags, since some	     * gerbers don't reset the interpolation (EagleCad again).	     */	    if ((state->interpolation == PAREA_START) ||		(state->interpolation == PAREA_END) ||		(state->interpolation == MQ_START) ||		(state->interpolation == MQ_END))		state->interpolation = state->prev_interpolation;	    /*	     * Save layer polarity	     */	    curr_net->layer_polarity = state->layer_polarity;	    state->delta_cp_x = 0.0;	    state->delta_cp_y = 0.0;	    curr_net->aperture = state->curr_aperture;	    curr_net->aperture_state = state->aperture_state;	    /* 	     * Make sure we don't hit any undefined aperture	     * In macros the first parameter could be basically anything	     */	    if ((curr_net->aperture != 0) && 		(image->aperture[curr_net->aperture] != NULL) &&		(image->aperture[curr_net->aperture]->type != MACRO))		aperture_size = image->aperture[curr_net->aperture]->parameter[0];	    else 		aperture_size = 0.0;	    /*	     * Find min and max of image	     */	    if (image->info->min_x == 0.0 || 		image->info->min_x > curr_net->stop_x)		image->info->min_x = curr_net->stop_x - aperture_size;	    if (image->info->min_y == 0.0 || 		image->info->min_y > curr_net->stop_y)		image->info->min_y = curr_net->stop_y - aperture_size;	    if (image->info->max_x < curr_net->stop_x)		image->info->max_x = curr_net->stop_x + aperture_size;	    if (image->info->max_y < curr_net->stop_y)		image->info->max_y = curr_net->stop_y + aperture_size;	    	    state->prev_x = state->curr_x;	    state->prev_y = state->curr_y;	    	    break;	case 10 :   /* White space */	case 13 :	case ' ' :	case '\t' :	    break;	default:	    GERB_COMPILE_ERROR("Found unknown character (whitespace?) %c[%d]\n", read, read);	}    }        GERB_COMPILE_ERROR("File is missing gerber End-Of-File\n");        return image;} /* parse_gerb */