/* vi:set ts=8 sts=4 sw=4 noet: * * VIM - Vi IMproved by Bram Moolenaar * * Do ":help uganda" in Vim to read copying and usage conditions. * Do ":help credits" in Vim to see a list of people who contributed. * See README.txt for an overview of the Vim source code. */ /* * scriptfile.c: functions for dealing with the runtime directories/files */ #include "vim.h" #if defined(FEAT_EVAL) || defined(PROTO) // The names of packages that once were loaded are remembered. static garray_T ga_loaded = {0, 0, sizeof(char_u *), 4, NULL}; #endif // last used sequence number for sourcing scripts (current_sctx.sc_seq) #ifdef FEAT_EVAL static int last_current_SID_seq = 0; #endif static int do_source_ext(char_u *fname, int check_other, int is_vimrc, int *ret_sid, exarg_T *eap, int clearvars); /* * Initialize the execution stack. */ void estack_init(void) { estack_T *entry; if (ga_grow(&exestack, 10) == FAIL) mch_exit(0); entry = ((estack_T *)exestack.ga_data) + exestack.ga_len; entry->es_type = ETYPE_TOP; entry->es_name = NULL; entry->es_lnum = 0; #ifdef FEAT_EVAL entry->es_info.ufunc = NULL; #endif ++exestack.ga_len; } /* * Add an item to the execution stack. * Returns the new entry or NULL when out of memory. */ estack_T * estack_push(etype_T type, char_u *name, long lnum) { estack_T *entry; // If memory allocation fails then we'll pop more than we push, eventually // at the top level it will be OK again. if (ga_grow(&exestack, 1) == FAIL) return NULL; entry = ((estack_T *)exestack.ga_data) + exestack.ga_len; entry->es_type = type; entry->es_name = name; entry->es_lnum = lnum; #ifdef FEAT_EVAL entry->es_info.ufunc = NULL; #endif ++exestack.ga_len; return entry; } #if defined(FEAT_EVAL) || defined(PROTO) /* * Add a user function to the execution stack. */ estack_T * estack_push_ufunc(ufunc_T *ufunc, long lnum) { estack_T *entry = estack_push(ETYPE_UFUNC, ufunc->uf_name_exp != NULL ? ufunc->uf_name_exp : ufunc->uf_name, lnum); if (entry != NULL) entry->es_info.ufunc = ufunc; return entry; } /* * Return TRUE if "ufunc" with "lnum" is already at the top of the exe stack. */ int estack_top_is_ufunc(ufunc_T *ufunc, long lnum) { estack_T *entry; if (exestack.ga_len == 0) return FALSE; entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; return entry->es_type == ETYPE_UFUNC && STRCMP( entry->es_name, ufunc->uf_name_exp != NULL ? ufunc->uf_name_exp : ufunc->uf_name) == 0 && entry->es_lnum == lnum; } #endif /* * Take an item off of the execution stack and return it. */ estack_T * estack_pop(void) { if (exestack.ga_len == 0) return NULL; --exestack.ga_len; return ((estack_T *)exestack.ga_data) + exestack.ga_len; } /* * Get the current value for "which" in allocated memory. * "which" is ESTACK_SFILE for , ESTACK_STACK for or * ESTACK_SCRIPT for