static gboolean l_check_if_number(LexerState* state) { MPNumber tmp; int count = 0; gchar* text = pl_get_marked_substring(state->prelexer); if(mp_set_from_string(text, state->parent->options->base, &tmp) == 0) { free(text); return TRUE; } else { /* Try to rollback several characters to see, if that yeilds any number. */ while(strlen (text) > 0) { if(mp_set_from_string(text, state->parent->options->base, &tmp) == 0) { free(text); return TRUE; } free(text); count++; pl_roll_back(state->prelexer); text = pl_get_marked_substring(state->prelexer); } /* Undo all rollbacks. */ while(count--) pl_get_next_token (state->prelexer); free(text); return FALSE; } }
static void registers_load(MathVariables *variables) { FILE *f; char line[1024]; f = fopen(variables->priv->file_name, "r"); if (!f) return; g_hash_table_remove_all(variables->priv->registers); while (fgets(line, 1024, f) != NULL) { char *name, *value; MPNumber *t; value = strchr(line, '='); if (!value) continue; *value = '\0'; value = value + 1; name = g_strstrip(line); value = g_strstrip(value); t = g_malloc(sizeof(MPNumber)); if (mp_set_from_string(value, 10, t) == 0) g_hash_table_insert(variables->priv->registers, g_strdup(name), t); else g_free(t); } fclose(f); }