| 1891 | |
| 1892 | #ifndef SFCTOOL |
| 1893 | void |
| 1894 | rcfile(void) |
| 1895 | { |
| 1896 | char *opts = 0, *xtraopts = 0; |
| 1897 | const char *envname, *namesrc, *nameval; |
| 1898 | |
| 1899 | go.opt_phase = environ_opt; |
| 1900 | /* getenv() instead of nhgetenv(): let total length of options be long; |
| 1901 | parseoptions() will check each individually */ |
| 1902 | envname = "NETHACKOPTIONS"; |
| 1903 | opts = getenv(envname); |
| 1904 | if (!opts) { |
| 1905 | /* fall back to original name; discouraged */ |
| 1906 | envname = "HACKOPTIONS"; |
| 1907 | opts = getenv(envname); |
| 1908 | } |
| 1909 | |
| 1910 | if (gc.cmdline_rcfile) { |
| 1911 | namesrc = "command line"; |
| 1912 | nameval = gc.cmdline_rcfile; |
| 1913 | xtraopts = opts; |
| 1914 | if (opts && (*opts == '/' || *opts == '\\' || *opts == '@')) |
| 1915 | xtraopts = 0; /* NETHACKOPTIONS is a file name; ignore it */ |
| 1916 | } else if (opts && (*opts == '/' || *opts == '\\' || *opts == '@')) { |
| 1917 | /* NETHACKOPTIONS is a file name; use that instead of the default */ |
| 1918 | if (*opts == '@') |
| 1919 | ++opts; /* @filename */ |
| 1920 | namesrc = envname; |
| 1921 | nameval = opts; |
| 1922 | xtraopts = 0; |
| 1923 | } else { |
| 1924 | /* either no NETHACKOPTIONS or it wasn't a file name; |
| 1925 | read the default configuration file */ |
| 1926 | nameval = namesrc = 0; |
| 1927 | xtraopts = opts; |
| 1928 | } |
| 1929 | |
| 1930 | go.opt_phase = rc_file_opt; |
| 1931 | /* seemingly arbitrary name length restriction is to prevent error |
| 1932 | messages, if any were to be delivered while accessing the file, |
| 1933 | from potentially overflowing buffers */ |
| 1934 | if (nameval && (int) strlen(nameval) >= BUFSZ / 2) { |
| 1935 | config_error_init(TRUE, namesrc, FALSE); |
| 1936 | config_error_add( |
| 1937 | "nethackrc file name \"%.40s\"... too long; using default", |
| 1938 | nameval); |
| 1939 | config_error_done(); |
| 1940 | nameval = namesrc = 0; /* revert to default nethackrc */ |
| 1941 | } |
| 1942 | |
| 1943 | config_error_init(TRUE, nameval, nameval ? CONFIG_ERROR_SECURE : FALSE); |
| 1944 | (void) read_config_file(nameval, set_in_config); |
| 1945 | config_error_done(); |
| 1946 | if (xtraopts) { |
| 1947 | /* NETHACKOPTIONS is present and not a file name */ |
| 1948 | go.opt_phase = environ_opt; |
| 1949 | config_error_init(FALSE, envname, FALSE); |
| 1950 | (void) parseoptions(xtraopts, TRUE, FALSE); |
no test coverage detected