Mercurial > emacs
comparison src/xfns.c @ 11353:9e3da029f921
(x_window): Copy the frame name to non-Lisp string.
(defined_color): Fix typo (duplicate +).
(validate_x_resource_name): Change invalid chars to `_'.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 10 Apr 1995 07:55:29 +0000 |
parents | e6bdaaa6ce1b |
children | a5b136d16356 |
comparison
equal
deleted
inserted
replaced
11352:800e56de3795 | 11353:9e3da029f921 |
---|---|
1023 { | 1023 { |
1024 trial_delta = ((((color_def->red >> 8) - (cells[x].red >> 8)) | 1024 trial_delta = ((((color_def->red >> 8) - (cells[x].red >> 8)) |
1025 * ((color_def->red >> 8) - (cells[x].red >> 8))) | 1025 * ((color_def->red >> 8) - (cells[x].red >> 8))) |
1026 + | 1026 + |
1027 (((color_def->green >> 8) - (cells[x].green >> 8)) | 1027 (((color_def->green >> 8) - (cells[x].green >> 8)) |
1028 * ((color_def->green >> 8) - (cells[x].green >> 8))) + | 1028 * ((color_def->green >> 8) - (cells[x].green >> 8))) |
1029 + | 1029 + |
1030 (((color_def->blue >> 8) - (cells[x].blue >> 8)) | 1030 (((color_def->blue >> 8) - (cells[x].blue >> 8)) |
1031 * ((color_def->blue >> 8) - (cells[x].blue >> 8)))); | 1031 * ((color_def->blue >> 8) - (cells[x].blue >> 8)))); |
1032 if (trial_delta < nearest_delta) | 1032 if (trial_delta < nearest_delta) |
1033 { | 1033 { |
1758 | 1758 |
1759 /* Make sure that Vx_resource_name is set to a reasonable value. */ | 1759 /* Make sure that Vx_resource_name is set to a reasonable value. */ |
1760 static void | 1760 static void |
1761 validate_x_resource_name () | 1761 validate_x_resource_name () |
1762 { | 1762 { |
1763 int len; | |
1764 /* Number of valid characters in the resource name. */ | |
1765 int good_count = 0; | |
1766 /* Number of invalid characters in the resource name. */ | |
1767 int bad_count = 0; | |
1768 Lisp_Object new; | |
1769 int i; | |
1770 | |
1763 if (STRINGP (Vx_resource_name)) | 1771 if (STRINGP (Vx_resource_name)) |
1764 { | 1772 { |
1765 int len = XSTRING (Vx_resource_name)->size; | |
1766 unsigned char *p = XSTRING (Vx_resource_name)->data; | 1773 unsigned char *p = XSTRING (Vx_resource_name)->data; |
1767 int i; | 1774 int i; |
1768 | 1775 |
1769 /* Allow only letters, digits, - and _, | 1776 len = XSTRING (Vx_resource_name)->size; |
1770 because those are all that X allows. */ | 1777 |
1778 /* Only letters, digits, - and _ are valid in resource names. | |
1779 Count the valid characters and count the invalid ones. */ | |
1771 for (i = 0; i < len; i++) | 1780 for (i = 0; i < len; i++) |
1772 { | 1781 { |
1773 int c = p[i]; | 1782 int c = p[i]; |
1774 if (! ((c >= 'a' && c <= 'z') | 1783 if (! ((c >= 'a' && c <= 'z') |
1775 || (c >= 'A' && c <= 'Z') | 1784 || (c >= 'A' && c <= 'Z') |
1776 || (c >= '0' && c <= '9') | 1785 || (c >= '0' && c <= '9') |
1777 || c == '-' || c == '_')) | 1786 || c == '-' || c == '_')) |
1778 goto fail; | 1787 bad_count++; |
1788 else | |
1789 good_count++; | |
1779 } | 1790 } |
1780 } | 1791 } |
1781 else | 1792 else |
1782 fail: | 1793 /* Not a string => completely invalid. */ |
1783 Vx_resource_name = make_string ("emacs", 5); | 1794 bad_count = 5, good_count = 0; |
1795 | |
1796 /* If name is valid already, return. */ | |
1797 if (bad_count == 0) | |
1798 return; | |
1799 | |
1800 /* If name is entirely invalid, or nearly so, use `emacs'. */ | |
1801 if (good_count == 0 | |
1802 || (good_count == 1 && bad_count > 0)) | |
1803 { | |
1804 Vx_resource_name = make_string ("emacs", 5); | |
1805 return; | |
1806 } | |
1807 | |
1808 /* Name is partly valid. Copy it and replace the invalid characters | |
1809 with underscores. */ | |
1810 | |
1811 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name); | |
1812 | |
1813 for (i = 0; i < len; i++) | |
1814 { | |
1815 int c = XSTRING (new)->data[i]; | |
1816 if (! ((c >= 'a' && c <= 'z') | |
1817 || (c >= 'A' && c <= 'Z') | |
1818 || (c >= '0' && c <= '9') | |
1819 || c == '-' || c == '_')) | |
1820 XSTRING (new)->data[i] = '_'; | |
1821 } | |
1784 } | 1822 } |
1785 | 1823 |
1786 | 1824 |
1787 extern char *x_get_string_resource (); | 1825 extern char *x_get_string_resource (); |
1788 | 1826 |
2290 int ac; | 2328 int ac; |
2291 | 2329 |
2292 BLOCK_INPUT; | 2330 BLOCK_INPUT; |
2293 | 2331 |
2294 if (STRINGP (f->name)) | 2332 if (STRINGP (f->name)) |
2295 name = (char*) XSTRING (f->name)->data; | 2333 { |
2334 /* This is a storage leak, but unless people create | |
2335 thousands of frames, that's ok. | |
2336 Fix it later by making a new slot in the frame to hold this. */ | |
2337 name = (char *) xmalloc (XSTRING (f->name)->size + 1); | |
2338 bcopy (XSTRING (f->name)->data, name, XSTRING (f->name)->size + 1); | |
2339 } | |
2296 else | 2340 else |
2297 name = "emacs"; | 2341 name = "emacs"; |
2298 | 2342 |
2299 ac = 0; | 2343 ac = 0; |
2300 XtSetArg (al[ac], XtNallowShellResize, 1); ac++; | 2344 XtSetArg (al[ac], XtNallowShellResize, 1); ac++; |