Beispiel #1
0
static int parse_input_file(const char *file_name, struct errors **top_error,
                            struct languages **top_lang)
{
    FILE *file;
    char *str, buff[1000];
    struct errors *current_error= 0, **tail_error= top_error;
    struct message current_message;
    int rcount= 0; /* Number of error codes in current section. */
    int ecount= 0; /* Number of error codes in total. */
    DBUG_ENTER("parse_input_file");

    *top_error= 0;
    *top_lang= 0;
    if (!(file= my_fopen(file_name, O_RDONLY | O_SHARE, MYF(MY_WME))))
        DBUG_RETURN(0);

    while ((str= fgets(buff, sizeof(buff), file)))
    {
        if (is_prefix(str, "language"))
        {
            if (!(*top_lang= parse_charset_string(str)))
            {
                fprintf(stderr, "Failed to parse the charset string!\n");
                DBUG_RETURN(0);
            }
            continue;
        }
        if (is_prefix(str, "start-error-number"))
        {
            if (!(er_offset= parse_error_offset(str)))
            {
                fprintf(stderr, "Failed to parse the error offset string!\n");
                DBUG_RETURN(0);
            }
            rcount= 0; /* Reset count if a fixed number is set. */
            continue;
        }
        if (is_prefix(str, "default-language"))
        {
            if (!(default_language= parse_default_language(str)))
            {
                DBUG_PRINT("info", ("default_slang: %s", default_language));
                fprintf(stderr,
                        "Failed to parse the default language line. Aborting\n");
                DBUG_RETURN(0);
            }
            continue;
        }

        if (*str == '\t' || *str == ' ')
        {
            /* New error message in another language for previous error */
            if (!current_error)
            {
                fprintf(stderr, "Error in the input file format\n");
                DBUG_RETURN(0);
            }
            if (!parse_message_string(&current_message, str))
            {
                fprintf(stderr, "Failed to parse message string for error '%s'",
                        current_error->er_name);
                DBUG_RETURN(0);
            }
            if (find_message(current_error, current_message.lang_short_name, TRUE))
            {
                fprintf(stderr, "Duplicate message string for error '%s'"
                        " in language '%s'\n",
                        current_error->er_name, current_message.lang_short_name);
                DBUG_RETURN(0);
            }
            if (check_message_format(current_error, current_message.text))
            {
                fprintf(stderr, "Wrong formatspecifier of error message string"
                        " for error '%s' in language '%s'\n",
                        current_error->er_name, current_message.lang_short_name);
                DBUG_RETURN(0);
            }
            if (insert_dynamic(&current_error->msg, &current_message))
                DBUG_RETURN(0);
            continue;
        }
        if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX))
        {
            if (!(current_error= parse_error_string(str, rcount)))
            {
                fprintf(stderr, "Failed to parse the error name string\n");
                DBUG_RETURN(0);
            }
            rcount++;
            ecount++;                         /* Count number of unique errors */

            /* add error to the list */
            *tail_error= current_error;
            tail_error= &current_error->next_error;
            continue;
        }
        if (*str == '#' || *str == '\n')
            continue;					/* skip comment or empty lines */

        fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str);
        DBUG_RETURN(0);
    }
    *tail_error= 0;				/* Mark end of list */

    my_fclose(file, MYF(0));
    DBUG_RETURN(ecount);
}
Beispiel #2
0
static int parse_input_file(const char *file_name, struct errors **top_error,
			    struct languages **top_lang)
{
  FILE *file;
  char *str, buff[1000];
  struct errors *current_error= 0, **tail_error= top_error;
  struct message current_message;
  uint rcount= 0;
  my_bool er_offset_found= 0;
  DBUG_ENTER("parse_input_file");

  *top_error= 0;
  *top_lang= 0;
  if (!(file= my_fopen(file_name, O_RDONLY | O_SHARE, MYF(MY_WME))))
    DBUG_RETURN(0);

  while ((str= fgets(buff, sizeof(buff), file)))
  {
    if (is_prefix(str, "language"))
    {
      if (!(*top_lang= parse_charset_string(str)))
      {
	fprintf(stderr, "Failed to parse the charset string!\n");
	DBUG_RETURN(0);
      }
      continue;
    }
    if (is_prefix(str, "start-error-number"))
    {
      uint tmp_er_offset;
      if (!(tmp_er_offset= parse_error_offset(str)))
      {
	fprintf(stderr, "Failed to parse the error offset string!\n");
	DBUG_RETURN(0);
      }
      if (!er_offset_found)
      {
        er_offset_found= 1;
        er_offset= tmp_er_offset;
      }
      else
      {
        /* Create empty error messages between er_offset and tmp_err_offset */
        if (tmp_er_offset < er_offset + rcount)
        {
          fprintf(stderr, "new start-error-number %u is smaller than current error message: %u\n", tmp_er_offset, er_offset + rcount);
          DBUG_RETURN(0);
        }
        for ( ; er_offset + rcount < tmp_er_offset ; rcount++)
        {
          current_error= generate_empty_message(er_offset + rcount);
          *tail_error= current_error;
          tail_error= &current_error->next_error;
        }
      }
      continue;
    }
    if (is_prefix(str, "default-language"))
    {
      if (!(default_language= parse_default_language(str)))
      {
	DBUG_PRINT("info", ("default_slang: %s", default_language));
	fprintf(stderr,
		"Failed to parse the default language line. Aborting\n");
	DBUG_RETURN(0);
      }
      continue;
    }

    if (*str == '\t' || *str == ' ')
    {
      /* New error message in another language for previous error */
      if (!current_error)
      {
	fprintf(stderr, "Error in the input file format\n");
	DBUG_RETURN(0);
      }
      if (!parse_message_string(&current_message, str))
      {
	fprintf(stderr, "Failed to parse message string for error '%s'",
		current_error->er_name);
	DBUG_RETURN(0);
      }
      if (find_message(current_error, current_message.lang_short_name, TRUE))
      {
	fprintf(stderr, "Duplicate message string for error '%s'"
                        " in language '%s'\n",
		current_error->er_name, current_message.lang_short_name);
	DBUG_RETURN(0);
      }
      if (check_message_format(current_error, current_message.text))
      {
	fprintf(stderr, "Wrong formatspecifier of error message string"
                        " for error '%s' in language '%s'\n",
		current_error->er_name, current_message.lang_short_name);
	DBUG_RETURN(0);
      }
      if (insert_dynamic(&current_error->msg, (uchar *) & current_message))
	DBUG_RETURN(0);
      continue;
    }
    if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX) ||
        is_prefix(str, ER_PREFIX2))
    {
      if (!(current_error= parse_error_string(str, rcount)))
      {
	fprintf(stderr, "Failed to parse the error name string\n");
	DBUG_RETURN(0);
      }
      rcount++;                         /* Count number of unique errors */

      /* add error to the list */
      *tail_error= current_error;
      tail_error= &current_error->next_error;
      continue;
    }
    if (*str == '#' || *str == '\n')
      continue;                      	/* skip comment or empty lines */

    fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str);
    DBUG_RETURN(0);
  }
  *tail_error= 0;			/* Mark end of list */

  my_fclose(file, MYF(0));
  DBUG_RETURN(rcount);
}