/* * --ATTENTION-- * we DO NOT use lcm API to set cursor, 'cause cursor * implement internal LCM. if you don't know how cursor * work, do NOT use it. */ int set_cursor_off(int row, int col) { int ret; /* set cursor off, blink off*/ ret = lcm_set_cursor(row, col, OFF, OFF); if (ret < 0) display_err_msg(ret, "设置光标出错!"); return ret; }
/* * --ATTENTION-- * we DO NOT use lcm API to set cursor, 'cause cursor * implement internal LCM. if you don't know how cursor * work, do NOT use it. */ int set_cursor_on(int row, int col) { int ret; /* set cursor on, blink on*/ ret = lcm_set_cursor(row, col, ON, ON); if (ret < 0) display_err_msg(ret, "设置光标出错!"); return ret; }
/* * Get the parameter values from the superconductor materials library ``sc_materials.txt'' */ superconductor *get_sc_parameters(char *material) { FILE *file; char *data, *data0, *excep, ch; node *new_err_msg, *node_aux; superconductor *sc[10], *sc_aux = malloc(sizeof(superconductor)); unsigned lin = 0, col; unsigned short i, j, ns = 0; bool is_comment, still_data_to_read, between_parentheses, reading_data, data_read, found_material; file = fopen(sc_library, "rt"); if (file == NULL) { display_err_msg(7, "No se encuentra el archivo ``sc_materials.txt''"); printf("\n\n"); exit(1); } /* Data size is set to longest IUPAC name length (titin)*/ data = malloc(31); data0 = data; new_err_msg = NULL; /* A sentinel node is added as the list head */ add_node(&new_err_msg, NULL, 0, 0); node_aux = new_err_msg; sc_aux->temp_c = NULL; while (ch != EOF) { /* Line start */ i = j = col = 0; lin++; is_comment = still_data_to_read = between_parentheses = reading_data = data_read = found_material = false; do { ch = fgetc(file); col++; if ((ch != ' ') && (ch != '\r') && (ch != '\n')) still_data_to_read = true; if ((!is_comment) && (still_data_to_read)) { excep = NULL; switch (ch) { case ' ': if (reading_data) { if (between_parentheses) { if ((i > 2) && (j < sc_aux->bands_number - 1)) excep = "Error de sintaxis: datos incompletos."; else if ((i == 2) && (j < sc_aux->bands_number)) excep = "Error de sintaxis: por favor, revise la(s) temperatura(s) crítica(s) del compuesto. Recuerde definir la temperatura crítica del sistema."; } reading_data = false; } break; case '(': if ((i > 1) && (sc_aux->bands_number < 2)) excep = "Error de sintaxis: no debe emplearse paréntesis en materiales de una sola banda."; else if (i < 2) excep = "Error de sintaxis: uso incorrecto del paréntesis."; else if (between_parentheses) excep = "Error de sintaxis: no se ha cerrado un paréntesis anterior."; between_parentheses = true; reading_data = false; break; case ')': if ((i > 1) && (sc_aux->bands_number < 2)) excep = "Error de sintaxis: no debe emplearse paréntesis en materiales de una sola banda."; else if (i < 2) excep = "Error de sintaxis: uso incorrecto del paréntesis."; else if (!between_parentheses) excep = "Error de sintaxis: paréntesis de cierre sin su paréntesis de apertura correspondiente."; between_parentheses = false; reading_data = false; break; case ',': if (!reading_data) excep = "Error de sintaxis."; else if (!between_parentheses) excep = "Error de sintaxis: emplee el caracter ',' sólo para separar los datos que se encuentran entre paréntesis."; else if ((i > 2) && (j == sc_aux->bands_number - 1)) excep = "Error de sintaxis: se definieron más datos de los requeridos."; else if ((i == 2) && (j == sc_aux->bands_number)) excep = "Error de sintaxis: se definieron más datos de los requeridos."; reading_data = false; break; case '#': is_comment = true; case '\n': case EOF: if (((i > 3) && (data == data0)) || ((i < 4) && ((reading_data) || (data_read)))) excep = "Error de sintaxis: datos incompletos."; reading_data = false; break; default: if (i < 5) { if (!reading_data) { reading_data = true; data_read = false; } *data++ = ch; } else excep = "Error de sintaxis: se definieron más datos de los requeridos."; break; } if ((!reading_data) && (!data_read) && (i < 5)) { *data = '\0'; data = data0; switch (i) { case 0: if (strcmp(material, data) == 0) { found_material = true; if (ns > 0) excep = "Advertencia: se encontró más de una definición para este compuesto. Se seleccionarán los datos de la primera definición encontrada."; } break; case 1: if (sc_aux->bands_number != atoi(data)) { sc_aux->bands_number = atoi(data); /* Deallocating memory no longer needed */ sc_aux->temp_c = malloc((sc_aux->bands_number + 1)*sizeof(*sc_aux->temp_c)); /* One memory space is added to include temp_c */ } break; case 2: sc_aux->temp_c[j] = atof(data); break; case 3: sc_aux->w = atof(data); break; case 4: sc_aux->gamma_a = atof(data); break; default: printf("\n%d\n", i); break; } if ((i == 2) && (sc_aux->bands_number > 1) && (j < sc_aux->bands_number)) j++; else { j = 0; i++; } data_read = true; } if (excep != NULL) add_node(&new_err_msg, excep, lin, col); } } while ((ch != '\n') && (ch != EOF)); /* Blank lines are discarded */ if (found_material) { sc[ns++] = sc_aux; sc_aux = malloc(sizeof(superconductor)); } } free(data); free(sc_aux->temp_c); free(sc_aux); /* Printing syntax error and/or warning messages about library ``sc_materials.txt'' */ new_err_msg = node_aux; if (new_err_msg->next != NULL) printf("\nErrores y/o advertencias:"); while ((new_err_msg = new_err_msg->next) != NULL) { free(node_aux); printf("\n(lín: %d, col: %d) -> %s", new_err_msg->lin, new_err_msg->col, new_err_msg->msg); node_aux = new_err_msg; } free(node_aux); if (ns > 0) return *sc; else return NULL; }