comparison src/scriptfile.c @ 23580:dc3b7a31c29f v8.2.2332

patch 8.2.2332: Vim9: missing :endif not reported when using :windo Commit: https://github.com/vim/vim/commit/9567efa1b4a41baca9b2266f5903d5dda7ad1e88 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 11 22:16:30 2021 +0100 patch 8.2.2332: Vim9: missing :endif not reported when using :windo Problem: Vim9: missing :endif not reported when using :windo. Solution: Pass a getline function to do_cmdline(). (closes https://github.com/vim/vim/issues/7650)
author Bram Moolenaar <Bram@vim.org>
date Mon, 11 Jan 2021 22:30:06 +0100
parents 40f824f5c7c7
children eef0cffbdb94
comparison
equal deleted inserted replaced
23579:4569ede6f294 23580:dc3b7a31c29f
1017 #endif 1017 #endif
1018 1018
1019 /* 1019 /*
1020 * ":source" and associated commands. 1020 * ":source" and associated commands.
1021 */ 1021 */
1022 /*
1023 * Structure used to store info for each sourced file.
1024 * It is shared between do_source() and getsourceline().
1025 * This is required, because it needs to be handed to do_cmdline() and
1026 * sourcing can be done recursively.
1027 */
1028 struct source_cookie
1029 {
1030 FILE *fp; // opened file for sourcing
1031 char_u *nextline; // if not NULL: line that was read ahead
1032 linenr_T sourcing_lnum; // line number of the source file
1033 int finished; // ":finish" used
1034 #ifdef USE_CRNL
1035 int fileformat; // EOL_UNKNOWN, EOL_UNIX or EOL_DOS
1036 int error; // TRUE if LF found after CR-LF
1037 #endif
1038 #ifdef FEAT_EVAL
1039 linenr_T breakpoint; // next line with breakpoint or zero
1040 char_u *fname; // name of sourced file
1041 int dbg_tick; // debug_tick when breakpoint was set
1042 int level; // top nesting level of sourced file
1043 #endif
1044 vimconv_T conv; // type of conversion
1045 };
1046 1022
1047 #ifdef FEAT_EVAL 1023 #ifdef FEAT_EVAL
1048 /* 1024 /*
1049 * Return the address holding the next breakpoint line for a source cookie. 1025 * Return the address holding the next breakpoint line for a source cookie.
1050 */ 1026 */
1051 linenr_T * 1027 linenr_T *
1052 source_breakpoint(void *cookie) 1028 source_breakpoint(void *cookie)
1053 { 1029 {
1054 return &((struct source_cookie *)cookie)->breakpoint; 1030 return &((source_cookie_T *)cookie)->breakpoint;
1055 } 1031 }
1056 1032
1057 /* 1033 /*
1058 * Return the address holding the debug tick for a source cookie. 1034 * Return the address holding the debug tick for a source cookie.
1059 */ 1035 */
1060 int * 1036 int *
1061 source_dbg_tick(void *cookie) 1037 source_dbg_tick(void *cookie)
1062 { 1038 {
1063 return &((struct source_cookie *)cookie)->dbg_tick; 1039 return &((source_cookie_T *)cookie)->dbg_tick;
1064 } 1040 }
1065 1041
1066 /* 1042 /*
1067 * Return the nesting level for a source cookie. 1043 * Return the nesting level for a source cookie.
1068 */ 1044 */
1069 int 1045 int
1070 source_level(void *cookie) 1046 source_level(void *cookie)
1071 { 1047 {
1072 return ((struct source_cookie *)cookie)->level; 1048 return ((source_cookie_T *)cookie)->level;
1073 } 1049 }
1074 1050
1075 /* 1051 /*
1076 * Return the readahead line. Note that the pointer may become invalid when 1052 * Return the readahead line. Note that the pointer may become invalid when
1077 * getting the next line, if it's concatenated with the next one. 1053 * getting the next line, if it's concatenated with the next one.
1078 */ 1054 */
1079 char_u * 1055 char_u *
1080 source_nextline(void *cookie) 1056 source_nextline(void *cookie)
1081 { 1057 {
1082 return ((struct source_cookie *)cookie)->nextline; 1058 return ((source_cookie_T *)cookie)->nextline;
1083 } 1059 }
1084 #endif 1060 #endif
1085 1061
1086 #if (defined(MSWIN) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC) 1062 #if (defined(MSWIN) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC)
1087 # define USE_FOPEN_NOINH 1063 # define USE_FOPEN_NOINH
1128 char_u *fname, 1104 char_u *fname,
1129 int check_other, // check for .vimrc and _vimrc 1105 int check_other, // check for .vimrc and _vimrc
1130 int is_vimrc, // DOSO_ value 1106 int is_vimrc, // DOSO_ value
1131 int *ret_sid UNUSED) 1107 int *ret_sid UNUSED)
1132 { 1108 {
1133 struct source_cookie cookie; 1109 source_cookie_T cookie;
1134 char_u *p; 1110 char_u *p;
1135 char_u *fname_exp; 1111 char_u *fname_exp;
1136 char_u *firstline = NULL; 1112 char_u *firstline = NULL;
1137 int retval = FAIL; 1113 int retval = FAIL;
1138 sctx_T save_current_sctx; 1114 sctx_T save_current_sctx;
1611 get_sourced_lnum( 1587 get_sourced_lnum(
1612 char_u *(*fgetline)(int, void *, int, getline_opt_T), 1588 char_u *(*fgetline)(int, void *, int, getline_opt_T),
1613 void *cookie) 1589 void *cookie)
1614 { 1590 {
1615 return fgetline == getsourceline 1591 return fgetline == getsourceline
1616 ? ((struct source_cookie *)cookie)->sourcing_lnum 1592 ? ((source_cookie_T *)cookie)->sourcing_lnum
1617 : SOURCING_LNUM; 1593 : SOURCING_LNUM;
1618 } 1594 }
1619 1595
1620 static char_u * 1596 static char_u *
1621 get_one_sourceline(struct source_cookie *sp) 1597 get_one_sourceline(source_cookie_T *sp)
1622 { 1598 {
1623 garray_T ga; 1599 garray_T ga;
1624 int len; 1600 int len;
1625 int c; 1601 int c;
1626 char_u *buf; 1602 char_u *buf;
1734 int c UNUSED, 1710 int c UNUSED,
1735 void *cookie, 1711 void *cookie,
1736 int indent UNUSED, 1712 int indent UNUSED,
1737 getline_opt_T options) 1713 getline_opt_T options)
1738 { 1714 {
1739 struct source_cookie *sp = (struct source_cookie *)cookie; 1715 source_cookie_T *sp = (source_cookie_T *)cookie;
1740 char_u *line; 1716 char_u *line;
1741 char_u *p; 1717 char_u *p;
1742 int do_vim9_all = in_vim9script() 1718 int do_vim9_all = in_vim9script()
1743 && options == GETLINE_CONCAT_ALL; 1719 && options == GETLINE_CONCAT_ALL;
1744 int do_bar_cont = do_vim9_all 1720 int do_bar_cont = do_vim9_all
1759 1735
1760 // Set the current sourcing line number. 1736 // Set the current sourcing line number.
1761 SOURCING_LNUM = sp->sourcing_lnum + 1; 1737 SOURCING_LNUM = sp->sourcing_lnum + 1;
1762 1738
1763 // Get current line. If there is a read-ahead line, use it, otherwise get 1739 // Get current line. If there is a read-ahead line, use it, otherwise get
1764 // one now. 1740 // one now. "fp" is NULL if actually using a string.
1765 if (sp->finished) 1741 if (sp->finished || sp->fp == NULL)
1766 line = NULL; 1742 line = NULL;
1767 else if (sp->nextline == NULL) 1743 else if (sp->nextline == NULL)
1768 line = get_one_sourceline(sp); 1744 line = get_one_sourceline(sp);
1769 else 1745 else
1770 { 1746 {
1878 * ":scriptencoding": Set encoding conversion for a sourced script. 1854 * ":scriptencoding": Set encoding conversion for a sourced script.
1879 */ 1855 */
1880 void 1856 void
1881 ex_scriptencoding(exarg_T *eap) 1857 ex_scriptencoding(exarg_T *eap)
1882 { 1858 {
1883 struct source_cookie *sp; 1859 source_cookie_T *sp;
1884 char_u *name; 1860 char_u *name;
1885 1861
1886 if (!getline_equal(eap->getline, eap->cookie, getsourceline)) 1862 if (!getline_equal(eap->getline, eap->cookie, getsourceline))
1887 { 1863 {
1888 emsg(_("E167: :scriptencoding used outside of a sourced file")); 1864 emsg(_("E167: :scriptencoding used outside of a sourced file"));
1889 return; 1865 return;
1897 } 1873 }
1898 else 1874 else
1899 name = eap->arg; 1875 name = eap->arg;
1900 1876
1901 // Setup for conversion from the specified encoding to 'encoding'. 1877 // Setup for conversion from the specified encoding to 'encoding'.
1902 sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie); 1878 sp = (source_cookie_T *)getline_cookie(eap->getline, eap->cookie);
1903 convert_setup(&sp->conv, name, p_enc); 1879 convert_setup(&sp->conv, name, p_enc);
1904 1880
1905 if (name != eap->arg) 1881 if (name != eap->arg)
1906 vim_free(name); 1882 vim_free(name);
1907 } 1883 }
1961 do_finish(exarg_T *eap, int reanimate) 1937 do_finish(exarg_T *eap, int reanimate)
1962 { 1938 {
1963 int idx; 1939 int idx;
1964 1940
1965 if (reanimate) 1941 if (reanimate)
1966 ((struct source_cookie *)getline_cookie(eap->getline, 1942 ((source_cookie_T *)getline_cookie(eap->getline,
1967 eap->cookie))->finished = FALSE; 1943 eap->cookie))->finished = FALSE;
1968 1944
1969 // Cleanup (and inactivate) conditionals, but stop when a try conditional 1945 // Cleanup (and inactivate) conditionals, but stop when a try conditional
1970 // not in its finally clause (which then is to be executed next) is found. 1946 // not in its finally clause (which then is to be executed next) is found.
1971 // In this case, make the ":finish" pending for execution at the ":endtry". 1947 // In this case, make the ":finish" pending for execution at the ":endtry".
1975 { 1951 {
1976 eap->cstack->cs_pending[idx] = CSTP_FINISH; 1952 eap->cstack->cs_pending[idx] = CSTP_FINISH;
1977 report_make_pending(CSTP_FINISH, NULL); 1953 report_make_pending(CSTP_FINISH, NULL);
1978 } 1954 }
1979 else 1955 else
1980 ((struct source_cookie *)getline_cookie(eap->getline, 1956 ((source_cookie_T *)getline_cookie(eap->getline,
1981 eap->cookie))->finished = TRUE; 1957 eap->cookie))->finished = TRUE;
1982 } 1958 }
1983 1959
1984 1960
1985 /* 1961 /*
1991 source_finished( 1967 source_finished(
1992 char_u *(*fgetline)(int, void *, int, getline_opt_T), 1968 char_u *(*fgetline)(int, void *, int, getline_opt_T),
1993 void *cookie) 1969 void *cookie)
1994 { 1970 {
1995 return (getline_equal(fgetline, cookie, getsourceline) 1971 return (getline_equal(fgetline, cookie, getsourceline)
1996 && ((struct source_cookie *)getline_cookie( 1972 && ((source_cookie_T *)getline_cookie(
1997 fgetline, cookie))->finished); 1973 fgetline, cookie))->finished);
1998 } 1974 }
1999 1975
2000 /* 1976 /*
2001 * Return the autoload script name for a function or variable name. 1977 * Return the autoload script name for a function or variable name.