void load_header( void ) { Group group; load_group( &group ); while( strcmp( group.value, "ENDSEC" ) ) { if( strcmp( group.value, "$CECOLOR" ) == 0 ) set_entity_color(); else if( strcmp( group.value, "$EXTMAX" ) == 0 ) set_extent_max(); else if( strcmp( group.value, "$EXTMIN" ) == 0 ) set_extent_min(); else if( strcmp( group.value, "$SHADEEDGE" ) == 0 ) set_face_shading(); else if( strcmp( group.value, "$UCSORG" ) == 0 ) set_ucs_origin(); else if( strcmp( group.value, "$UCSXDIR" ) == 0 ) set_ucs_x_dir(); else if( strcmp( group.value, "$UCSYDIR" ) == 0 ) set_ucs_y_dir(); else if( setup.verbose && IS_VARIABLE( group ) ) message( " Skipping unsupported variable: %s", group.value ); load_group( &group ); } }
EXPRESSION expression_generate(char *original) { int i, length, offset; char *string = (char *)malloc(MAX_STRING * sizeof(char)); strcpy(string,original); // remove whitespace offset = 0; length = strlen(string); for(i = 0; i < length; i ++) { if(string[i + offset] == ' ') { offset ++; length --; } string[i] = string[i + offset]; } string[i] = '\0'; // convert multiple expressions into just one length = strlen(string); int n_name, n_expr; char *name = (char *)malloc(MAX_STRING * sizeof(char)); char *expr = (char *)malloc(MAX_STRING * sizeof(char)); char *temp = (char *)malloc(MAX_STRING * sizeof(char)); if(name == NULL || expr == NULL || temp == NULL) return NULL; while(IS_VARIABLE(string[0])) { i = 0; do name[i] = string[i]; while(string[++i] != EQUALITY); n_name = i; name[n_name] = '\0'; i ++; do expr[i - n_name - 1] = string[i]; while(string[++i] != SEPERATOR); n_expr = i - n_name - 1; expr[n_expr] = '\0'; i ++; while(string[i] == ';') i ++; sprintf(temp,"%s",&string[i]); strcpy(string,temp); i = 0; do { if(strncmp(&string[i],name,n_name) == 0 && (!IS_VARIABLE(string[i+n_name]) || string[i+n_name] == '\0')) { string[i] = '\0'; sprintf(temp,"%s%c%s%c%s",string,LEFTBRACE,expr,RIGHTBRACE,&string[i + n_name]); strcpy(string,temp); } i ++; } while(i < strlen(string)); } free(name); free(expr); free(temp); // convert the infix string into lists of postfix/RPN operations length = strlen(string); int o = 0; int *operator = (int *)malloc(MAX_ELEMENTS * sizeof(int)); if(operator == NULL) return NULL; int e = 0; EXPRESSION expression = (EXPRESSION)malloc(MAX_ELEMENTS * sizeof(struct s_EXPRESSION)); if(expression == NULL) return NULL; int index; i = 0; do { if(string[i] == LEFTBRACE) { operator[o++] = LEFTBRACE; i ++; } else if(string[i] == RIGHTBRACE) { while(operator[o-1] != LEFTBRACE) { expression[e++].type = operator[--o]; if(!o) return NULL; } i ++; o --; } else if(IS_OPERATOR(string[i])) { while(o > 0) if(precedence[(int)string[i]] <= precedence[operator[o-1]]) expression[e++].type = operator[--o]; else break; operator[o++] = string[i++]; } else if(IS_VALUE(string[i])) { sscanf(&string[i],"%lf",&expression[e].value); expression[e++].type = VALUE; while((i < length) && ((!IS_OPERATOR(string[i]) && !IS_CONTROL(string[i])) || ((string[i] == MINUS || string[i] == PLUS) && (string[i-(i>0)] == 'e' || string[i-(i>0)] == 'E')))) i ++; } else if(string[i] == SUBSTITUTE) { sscanf(&string[++i],"%i",&index); expression[e++].type = SUBSTITUTE_ZERO + index; while(IS_VALUE(string[i])) i ++; } else return NULL; } while(i < length); while(o) expression[e++].type = operator[--o]; expression[e].type = END; // simplify the expression as much as possible expression_simplify(expression); // clean up and return free(string); free(operator); e = 0; while(expression[e].type != END) e ++; return (EXPRESSION)realloc(expression, (e + 1) * sizeof(struct s_EXPRESSION)); }