Beispiel #1
0
static ALLEGRO_USTR *create_filter_string(const ALLEGRO_USTR *patterns)
{
   ALLEGRO_USTR *filter = al_ustr_new("");
   bool filter_all = false;
   int start, end;

   if (0 == strcmp(al_cstr(patterns), "*.*")) {
      filter_all = true;
   }
   else {
      al_ustr_append_cstr(filter, "All Supported Files");
      al_ustr_append_chr(filter, '\0');
      start = al_ustr_size(filter);
      al_ustr_append(filter, patterns);

      /* Remove all instances of "*.*", which will be added separately. */
      for (;;) {
         int pos = al_ustr_find_cstr(filter, start, "*.*;");
         if (pos == -1)
            break;
         if (pos == start || al_ustr_get(filter, pos - 1) == ';') {
            filter_all = true;
            al_ustr_remove_range(filter, pos, pos + 4);
            start = pos;
         }
         else {
            start = pos + 4;
         }
      }
      while (al_ustr_has_suffix_cstr(filter, ";*.*")) {
         filter_all = true;
         end = al_ustr_size(filter);
         al_ustr_remove_range(filter, end - 4, end);
      }

      al_ustr_append_chr(filter, '\0');
   }

   if (filter_all) {
      al_ustr_append_cstr(filter, "All Files");
      al_ustr_append_chr(filter, '\0');
      al_ustr_append_cstr(filter, "*.*");
      al_ustr_append_chr(filter, '\0');
   }

   al_ustr_append_chr(filter, '\0');
   return filter;
}
Beispiel #2
0
static std::string get_entire_translation(const char *filename)
{
	int sz;
	unsigned char *bytes = slurp_file(getResource("%s.utf8", filename), &sz);
	if (!bytes) {
		native_error("Load error.", filename);
	}

	ALLEGRO_FILE *f = al_open_memfile(bytes, sz, "rb");

	ALLEGRO_USTR *ustr;

	std::string whole_translation;

	while ((ustr = al_fget_ustr(f)) != NULL) {
		// remove newline
		int size = (int)al_ustr_size(ustr);
		const char *cstr = al_cstr(ustr);
		int count = 0;
		if (cstr[strlen(cstr)-1] == 0xa)
			count++;
		if (cstr[strlen(cstr)-2] == 0xd)
			count++;
		if (count > 0) {
			al_ustr_remove_range(ustr, size-count, size);
		}
		ustr_replace_all(ustr, '^', '\n');
		whole_translation += al_cstr(ustr);
	}

	al_fclose(f);
	delete[] bytes;

	return whole_translation;
}
Beispiel #3
0
/* Test al_ustr_remove_range. */
static void t13(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("aábdðeéfghiíjkprstuúvxyýþæö");

   /* Remove from middle of string. */
   CHECK(al_ustr_remove_range(us1, 5, 30));
   CHECK(0 == strcmp(al_cstr(us1), "aábdþæö"));

   /* Removing past end. */
   CHECK(al_ustr_remove_range(us1, 100, 120));
   CHECK(0 == strcmp(al_cstr(us1), "aábdþæö"));

   /* Start > End. */
   CHECK(! al_ustr_remove_range(us1, 3, 0));
   CHECK(0 == strcmp(al_cstr(us1), "aábdþæö"));

   al_ustr_free(us1);
}
Beispiel #4
0
/* An ALLEGRO_MENU_INFO structure represents a heirarchy of menus. This function 
 * recursively steps through it and builds the entire menu.
 */
static ALLEGRO_MENU_INFO *parse_menu_info(ALLEGRO_MENU *parent, ALLEGRO_MENU_INFO *info)
{
   ASSERT(parent);
   ASSERT(info);

   /* The end of the menu is marked by a NULL caption and an id of 0. */
   while (info->caption || info->id) {
      if (!info->caption) {
         /* A separator */
         al_append_menu_item(parent, NULL, 0, 0, NULL, NULL);
         ++info;
      }
      else if (strlen(info->caption) > 2 &&
         !strncmp("->", info->caption + strlen(info->caption) - 2, 2)) {
         /* An item with a sub-menu has a -> marker as part of its caption.
          * (e.g., "File->"). 
          */
         ALLEGRO_MENU *menu = al_create_menu();
         if (menu) {
            /* Strip the -> mark off the end. */
            ALLEGRO_USTR *s = al_ustr_new(info->caption);
            al_ustr_remove_range(s, al_ustr_size(s) - 2, al_ustr_size(s));
            al_append_menu_item(parent, al_cstr(s), info->id, 0, NULL, menu);
            info = parse_menu_info(menu, info + 1);
            al_ustr_free(s);
         }
      }
      else {
         /* Just ar regular item */
         al_append_menu_item(parent, info->caption, info->id, info->flags, info->icon, NULL);
         ++info;
      }
   }

   return info + 1;
}