+static int
+frame_name_fnn_p (str, len)
+ char *str;
+ int len;
+{
+ if (len > 1 && str[0] == 'F')
+ {
+ char *end_ptr;
+
+ strtol (str + 1, &end_ptr, 10);
+
+ if (end_ptr == str + len)
+ return 1;
+ }
+ return 0;
+}
+
+/* Set the name of the terminal frame. Also used by MSDOS frames.
+ Modeled after x_set_name which is used for WINDOW frames. */
+
+void
+set_term_frame_name (f, name)
+ struct frame *f;
+ Lisp_Object name;
+{
+ f->explicit_name = ! NILP (name);
+
+ /* If NAME is nil, set the name to F<num>. */
+ if (NILP (name))
+ {
+ char namebuf[20];
+
+ /* Check for no change needed in this very common case
+ before we do any consing. */
+ if (frame_name_fnn_p (XSTRING (f->name)->data,
+ STRING_BYTES (XSTRING (f->name))))
+ return;
+
+ terminal_frame_count++;
+ sprintf (namebuf, "F%d", terminal_frame_count);
+ name = build_string (namebuf);
+ }
+ else
+ {
+ CHECK_STRING (name, 0);
+
+ /* Don't change the name if it's already NAME. */
+ if (! NILP (Fstring_equal (name, f->name)))
+ return;
+
+ /* Don't allow the user to set the frame name to F<num>, so it
+ doesn't clash with the names we generate for terminal frames. */
+ if (frame_name_fnn_p (XSTRING (name)->data, STRING_BYTES (XSTRING (name))))
+ error ("Frame names of the form F<num> are usurped by Emacs");
+ }
+
+ f->name = name;
+ update_mode_lines = 1;
+}
+