+/*
+ * Find the "first" floor object with the given "tag".
+ *
+ * A "tag" is a numeral "n" appearing as "@n" anywhere in the
+ * inscription of an object. Alphabetical characters don't work as a
+ * tag in this form.
+ *
+ * Also, the tag "@xn" will work as well, where "n" is a any tag-char,
+ * and "x" is the "current" command_cmd code.
+ */
+static bool get_tag_floor(int *cp, char tag, int floor_list[], int floor_num)
+{
+ int i;
+ cptr s;
+
+ /**** Find a tag in the form of {@x#} (allow alphabet tag) ***/
+
+ /* Check every object in the grid */
+ for (i = 0; i < floor_num && i < 23; i++)
+ {
+ object_type *o_ptr = &o_list[floor_list[i]];
+
+ /* Skip empty inscriptions */
+ if (!o_ptr->inscription) continue;
+
+ /* Find a '@' */
+ s = strchr(quark_str(o_ptr->inscription), '@');
+
+ /* Process all tags */
+ while (s)
+ {
+ /* Check the special tags */
+ if ((s[1] == command_cmd) && (s[2] == tag))
+ {
+ /* Save the actual floor object ID */
+ *cp = i;
+
+ /* Success */
+ return (TRUE);
+ }
+
+ /* Find another '@' */
+ s = strchr(s + 1, '@');
+ }
+ }
+
+
+ /**** Find a tag in the form of {@#} (allows only numerals) ***/
+
+ /* Don't allow {@#} with '#' being alphabet */
+ if (tag < '0' || '9' < tag)
+ {
+ /* No such tag */
+ return FALSE;
+ }
+
+ /* Check every object in the grid */
+ for (i = 0; i < floor_num && i < 23; i++)
+ {
+ object_type *o_ptr = &o_list[floor_list[i]];
+
+ /* Skip empty inscriptions */
+ if (!o_ptr->inscription) continue;
+
+ /* Find a '@' */
+ s = strchr(quark_str(o_ptr->inscription), '@');
+
+ /* Process all tags */
+ while (s)
+ {
+ /* Check the normal tags */
+ if (s[1] == tag)
+ {
+ /* Save the floor object ID */
+ *cp = i;
+
+ /* Success */
+ return (TRUE);
+ }
+
+ /* Find another '@' */
+ s = strchr(s + 1, '@');
+ }
+ }
+
+ /* No such tag */
+ return (FALSE);
+}
+
+
+/*
+ * Move around label characters with correspond tags
+ */
+static void prepare_label_string(char *label, int mode)
+{
+ cptr alphabet_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ int offset = (mode == USE_EQUIP) ? INVEN_RARM : 0;
+ int i;
+
+ /* Prepare normal labels */
+ strcpy(label, alphabet_chars);
+
+ /* Move each label */
+ for (i = 0; i < 52 + 10; i++)
+ {
+ int index;
+ char c = alphabet_chars[i];
+
+ /* Find a tag with this label */
+ if (get_tag(&index, c, mode))
+ {
+ /* Delete the overwritten label */
+ if (label[i] == c) label[i] = ' ';
+
+ /* Move the label to the place of corresponding tag */
+ label[index - offset] = c;
+ }
+ }
+}
+
+
+/*
+ * Move around label characters with correspond tags (floor version)
+ */
+static void prepare_label_string_floor(char *label, int floor_list[], int floor_num)
+{
+ cptr alphabet_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ int i;
+
+ /* Prepare normal labels */
+ strcpy(label, alphabet_chars);
+
+ /* Move each label */
+ for (i = 0; i < 52 + 10; i++)
+ {
+ int index;
+ char c = alphabet_chars[i];
+
+ /* Find a tag with this label */
+ if (get_tag_floor(&index, c, floor_list, floor_num))
+ {
+ /* Delete the overwritten label */
+ if (label[i] == c) label[i] = ' ';
+
+ /* Move the label to the place of corresponding tag */
+ label[index] = c;
+ }
+ }
+}
+