void Blitters_Init() { ConsolePrint(Msg_Get(MSG_Blitters_Loading)); Blitters.list = NULL; Blitters.current = NULL; // Open and read file t_tfile * tf; if ((tf = tfile_read (Blitters.filename)) == NULL) Quit_Msg("%s", meka_strerror()); ConsolePrint("\n"); // Parse each line int line_cnt = 0; for (t_list* lines = tf->data_lines; lines; lines = lines->next) { const char* line = (char*)lines->elem; line_cnt += 1; int i, j; char s1 [256], s2 [256]; for (i = 0, j = 0; line [i] != 0 && line [i] != ';'; i ++) if ((line [0] == '[') || (line [i] != ' ' && line [i] != '\t')) s2 [j ++] = line [i]; s2 [j] = 0; if (StrIsNull (s2)) continue; strcpy(s1, s2); StrLower(s1); switch (Blitters_Parse_Line (s1, s2)) { case MEKA_ERR_UNKNOWN: tfile_free(tf); Quit_Msg(Msg_Get(MSG_Blitters_Error_Unrecognized), line_cnt); case MEKA_ERR_MISSING: tfile_free(tf); Quit_Msg(Msg_Get(MSG_Blitters_Error_Missing), line_cnt); case MEKA_ERR_VALUE_INCORRECT: tfile_free(tf); Quit_Msg(Msg_Get(MSG_Blitters_Error_Incorrect_Value), line_cnt); } } // Free file data tfile_free(tf); // Requires at least 1 blitter if (Blitters.count == 0) Quit_Msg("%s", Msg_Get(MSG_Blitters_Error_Not_Enough)); // Current blitter if (Blitters.blitter_configuration_name != NULL) Blitters.current = Blitters_FindBlitterByName(Blitters.blitter_configuration_name); if (Blitters.current == NULL) Blitters.current = (t_blitter*)Blitters.list->elem; // first }
//----------------------------------------------------------------------------- // DB_Load (const char *filename) // Initialize and load given Meka DB file //----------------------------------------------------------------------------- void DB_Load (const char *filename) { t_tfile * tf; t_list * lines; char * line; int line_cnt; ConsolePrint (Msg_Get (MSG_DB_Loading)); // Open and read file tf = tfile_read (filename); if (tf == NULL) { ConsolePrintf ("%s\n", meka_strerror()); return; } // Ok ConsolePrint ("\n"); // Parse each line line_cnt = 0; for (lines = tf->data_lines; lines; lines = lines->next) { line_cnt += 1; line = lines->elem; // Strip comments // FIXME // Trim spaces? // FIXME // Skip empty lines //if (line[0] == EOSTR) // continue; if (DB_Load_Line (line) == 0) { tfile_free (tf); Quit_Msg (Msg_Get (MSG_DB_SyntaxError), line_cnt); } } // Free file data tfile_free(tf); // FIXME - Uncomment for counting progress of DB transition //ConsolePrintf ("ENTRIES NEW = %d, OLD = %d\n", DB.entries_counter_format_new, DB.entries_counter_format_old); //Quit(); }
//----------------------------------------------------------------------------- // VLFN_DataBase_Load (void) // Load VLFN database from MEKA.FDB file. //----------------------------------------------------------------------------- void VLFN_DataBase_Load (void) { t_tfile * tf; t_list * lines; char * line; int line_cnt; ConsolePrint (Msg_Get (MSG_FDB_Loading)); // Open and read file tf = tfile_read (VLFN_DataBase.filename); if (tf == NULL) { ConsolePrintf ("%s\n", meka_strerror()); return; } // Ok ConsolePrint ("\n"); // Parse each line line_cnt = 0; for (lines = tf->data_lines; lines; lines = lines->next) { char * w; line_cnt += 1; line = lines->elem; w = parse_getword(NULL, 0, &line, "/", ';', 0); if (w == NULL) continue; else { char buf[1024]; char * file_name; u32 crc_crc32; t_meka_crc crc_mekacrc; // Save allocated filename file_name = w; // Get CRCs crc_crc32 = 0; crc_mekacrc.v[0] = crc_mekacrc.v[1] = 0; while ((w = parse_getword(buf, 1024, &line, "/", ';', 0)) != NULL) { if (!strncmp(w, "MEKACRC:", 8)) { if (sscanf(w + 8, "%08X%08X", &crc_mekacrc.v[0], &crc_mekacrc.v[1]) != 2) continue; // Syntax error } else if (!strncmp(w, "CRC32:", 6)) { if (sscanf(w + 6, "%08x", &crc_crc32) != 1) continue; // Syntax error } } // Requires at least MekaCRC // (to be changed by CRC32 when MekaCRC is dropped) if (crc_mekacrc.v[0] == 0 && crc_mekacrc.v[1] == 0) continue; { // Find DB entry t_db_entry *db_entry = DB_Entry_Find (crc_crc32, &crc_mekacrc); if (db_entry) { // Create VLFN entry t_vlfn_entry * entry; entry = VLFN_Entry_New (file_name, db_entry); list_add (&VLFN_DataBase.entries, entry); } } } } // Free file data tfile_free (tf); }
void Load_Inputs_Src_List (void) { int i; char w[256]; t_input_src * input_src = NULL; t_tfile * tf; t_list * lines; int line_cnt; // Open and read file ConsolePrint (Msg_Get (MSG_Inputs_Src_Loading)); tf = tfile_read (Inputs.FileName); if (tf == NULL) Quit_Msg (meka_strerror()); ConsolePrint ("\n"); // Parse each line line_cnt = 0; for (lines = tf->data_lines; lines; lines = lines->next) { char *line; line_cnt += 1; line = lines->elem; if (StrNull(line)) continue; if (line[0] == '[' && line[strlen(line) - 1] == ']') { input_src = Inputs_Sources_Add (StrNDup (line + 1, strlen(line) - 2)); // ConsolePrintf ("new source --> %s <--\n", CurSrc->Name); continue; } strlwr(line); if (!parse_getword(w, sizeof(w), &line, "=", ';', PARSE_FLAGS_NONE)) continue; for (i = 0; Inputs_Src_List_KeyWords[i]; i++) if (strcmp(w, Inputs_Src_List_KeyWords[i]) == 0) { // FIXME: this is ugly if (input_src == NULL && strcmp (w, "joy_driver") != 0 && strcmp (w, "mouse_speed_x") != 0 && strcmp (w, "mouse_speed_y") != 0 && strcmp (w, "cabinet_mode") != 0) { tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Missing), line_cnt); } parse_skip_spaces(&line); if (!parse_getword(w, sizeof(w), &line, "", ';', PARSE_FLAGS_NONE)) { tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Equal), line_cnt); } switch (Load_Inputs_Src_Parse_Var(i, w, input_src)) { case MEKA_ERR_SYNTAX: tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Syntax_Param), line_cnt); case MEKA_ERR_INCOHERENT : tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Inconsistency), line_cnt); break; // FIXME: EMPTY is not handled there } break; } if (!Inputs_Src_List_KeyWords [i]) { tfile_free(tf); Quit_Msg (Msg_Get (MSG_Inputs_Src_Unrecognized), line_cnt, w); } } // Free file data tfile_free(tf); // Verify that we have enough inputs sources if (Inputs.Sources_Max == 0) Quit_Msg (Msg_Get (MSG_Inputs_Src_Not_Enough)); }
// Load messages from MEKA.MSG file (path given in structure) // Return a MEKA_ERR_xxx code int Messages_Init (void) { t_tfile * tf; t_list * lines; int line_cnt; char * p; Messages.Lang_Cur = Messages.Lang_Default = NULL; Messages.Langs = NULL; // Note: this is one of the few cases were the string has to be hardcoded. // That is of course because the messages/localization system is not // initialized as of yet.. ConsolePrint("Loading MEKA.MSG (messages).. "); // Open and read file -------------------------------------------------------- tf = tfile_read (Messages.FileName); if (tf == NULL) Quit_Msg("MISSING!\nTry re-installing your version of Meka."); ConsolePrint("\n"); // Parse each line ----------------------------------------------------------- line_cnt = 0; for (lines = tf->data_lines; lines; lines = lines->next) { char *line = (char*)lines->elem; line_cnt += 1; // Cut Comments p = strchr (line, ';'); if (p != NULL) *p = EOSTR; StrTrim (line); if (StrIsNull (line)) continue; // Parse Line and handle errors // ConsolePrintf ("%d: %s--\n", line_cnt, line); switch (Messages_Init_Parse_Line(line)) { case MEKA_ERR_MISSING: ConsolePrintf ("On line %d: No language defined for storing message !", line_cnt); tfile_free(tf); Quit(); break; case MEKA_ERR_UNKNOWN: ConsolePrintf ("On line %d: Unknown message \"%s\", skipping it.\n", line_cnt, line); // tfile_free(tf); // Quit(); break; case MEKA_ERR_SYNTAX: ConsolePrintf ("On line %d: Syntax error.\n%s\n", line_cnt, line); tfile_free(tf); Quit(); break; } } // Free file data tfile_free(tf); // Verify language completion { if (Messages.Lang_Cur == NULL) Quit_Msg("No language defined. Try re-installing your version of Meka."); Messages.Lang_Cur = Messages.Lang_Default; for (t_list* langs = Messages.Langs; langs; langs = langs->next) { t_lang* lang = (t_lang*)langs->elem; if (Lang_Post_Check (lang) != MEKA_ERR_OK) if (lang == Messages.Lang_Default) Quit_Msg("This is the default language, so we need to abort."); } } // Ok return (MEKA_ERR_OK); }