Пример #1
0
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
}
Пример #2
0
//-----------------------------------------------------------------------------
// 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();
}
static void
tfile_open (const char *arg, int from_tty)
{
  char *temp;
  struct cleanup *old_chain;
  int flags;
  int scratch_chan;
  char header[TRACE_HEADER_SIZE];
  char linebuf[1000]; /* Should be max remote packet size or so.  */
  gdb_byte byte;
  int bytes, i;
  struct trace_status *ts;
  struct uploaded_tp *uploaded_tps = NULL;
  struct uploaded_tsv *uploaded_tsvs = NULL;
  char *filename;

  target_preopen (from_tty);
  if (!arg)
    error (_("No trace file specified."));

  filename = tilde_expand (arg);
  if (!IS_ABSOLUTE_PATH(filename))
    {
      temp = concat (current_directory, "/", filename, (char *) NULL);
      xfree (filename);
      filename = temp;
    }

  old_chain = make_cleanup (xfree, filename);

  flags = O_BINARY | O_LARGEFILE;
  flags |= O_RDONLY;
  scratch_chan = gdb_open_cloexec (filename, flags, 0);
  if (scratch_chan < 0)
    perror_with_name (filename);

  /* Looks semi-reasonable.  Toss the old trace file and work on the new.  */

  discard_cleanups (old_chain);	/* Don't free filename any more.  */
  unpush_target (&tfile_ops);

  trace_filename = xstrdup (filename);
  trace_fd = scratch_chan;

  /* Make sure this is clear.  */
  buffer_free (&trace_tdesc);

  bytes = 0;
  /* Read the file header and test for validity.  */
  tfile_read ((gdb_byte *) &header, TRACE_HEADER_SIZE);

  bytes += TRACE_HEADER_SIZE;
  if (!(header[0] == 0x7f
	&& (startswith (header + 1, "TRACE0\n"))))
    error (_("File is not a valid trace file."));

  push_target (&tfile_ops);

  trace_regblock_size = 0;
  ts = current_trace_status ();
  /* We know we're working with a file.  Record its name.  */
  ts->filename = trace_filename;
  /* Set defaults in case there is no status line.  */
  ts->running_known = 0;
  ts->stop_reason = trace_stop_reason_unknown;
  ts->traceframe_count = -1;
  ts->buffer_free = 0;
  ts->disconnected_tracing = 0;
  ts->circular_buffer = 0;

  TRY
    {
      /* Read through a section of newline-terminated lines that
	 define things like tracepoints.  */
      i = 0;
      while (1)
	{
	  tfile_read (&byte, 1);

	  ++bytes;
	  if (byte == '\n')
	    {
	      /* Empty line marks end of the definition section.  */
	      if (i == 0)
		break;
	      linebuf[i] = '\0';
	      i = 0;
	      tfile_interp_line (linebuf, &uploaded_tps, &uploaded_tsvs);
	    }
	  else
	    linebuf[i++] = byte;
	  if (i >= 1000)
	    error (_("Excessively long lines in trace file"));
	}

      /* By now, tdesc lines have been read from tfile - let's parse them.  */
      target_find_description ();

      /* Record the starting offset of the binary trace data.  */
      trace_frames_offset = bytes;

      /* If we don't have a blocksize, we can't interpret the
	 traceframes.  */
      if (trace_regblock_size == 0)
	error (_("No register block size recorded in trace file"));
    }
  CATCH (ex, RETURN_MASK_ALL)
    {
      /* Remove the partially set up target.  */
      unpush_target (&tfile_ops);
      throw_exception (ex);
    }
Пример #4
0
//-----------------------------------------------------------------------------
// 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);
}
Пример #5
0
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));
}
Пример #6
0
// 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);
}