ex_getln: Refactor script_get()

1. Use `char *` for strings.
2. Add `const` qualifiers.
3. Add attributes and documentation.
4. Handle skipping *inside*.
5. Handle non-heredoc argument also inside: deferring this to the caller is
   pointless because all callers need the same thing. Though new ex_lua caller
   may live without allocations in this case, allocating nevertheless produces
   cleaner code.
6. Note that all callers call script_get with `eap` and `eap->arg`. Thus second
   argument is useless in practice: it is one and the same always and can be
   reached through the first argument.
This commit is contained in:
ZyX
2017-01-29 03:36:47 +03:00
parent 3531d8c8ea
commit 3d48c35d6b
4 changed files with 58 additions and 38 deletions

View File

@@ -3695,19 +3695,18 @@ char_u *get_locales(expand_T *xp, int idx)
static void script_host_execute(char *name, exarg_T *eap)
{
uint8_t *script = script_get(eap, eap->arg);
size_t len;
char *const script = script_get(eap, &len);
if (!eap->skip) {
list_T *args = list_alloc();
if (script != NULL) {
list_T *const args = list_alloc();
// script
list_append_string(args, script ? script : eap->arg, -1);
list_append_allocated_string(args, script);
// current range
list_append_number(args, (int)eap->line1);
list_append_number(args, (int)eap->line2);
(void)eval_call_provider(name, "execute", args);
}
xfree(script);
}
static void script_host_execute_file(char *name, exarg_T *eap)