fish-shell/src/builtin_emit.cpp
ridiculousfish e0e4b11dbd Make arguments to builtins const
Prior to this change, builtins would take their arguments as `wchar_t **`.
This implies that the order of the arguments may be changed (which is
true, `wgetopter` does so) but also that the strings themselves may be
changed, which no builtin should do.

Switch them all to take `const wchar_t **` instead: now the arguments may
be rearranged but their contents may no longer be modified.
2021-03-28 15:31:25 -07:00

38 lines
1.1 KiB
C++

// Implementation of the emit builtin.
#include "config.h" // IWYU pragma: keep
#include "builtin_emit.h"
#include "builtin.h"
#include "common.h"
#include "event.h"
#include "fallback.h" // IWYU pragma: keep
#include "io.h"
#include "wutil.h" // IWYU pragma: keep
/// Implementation of the builtin emit command, used to create events.
maybe_t<int> builtin_emit(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
help_only_cmd_opts_t opts;
int optind;
int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {
builtin_print_help(parser, streams, cmd);
return STATUS_CMD_OK;
}
if (!argv[optind]) {
streams.err.append_format(L"%ls: expected event name\n", cmd);
return STATUS_INVALID_ARGS;
}
const wchar_t *eventname = argv[optind];
wcstring_list_t args(argv + optind + 1, argv + argc);
event_fire_generic(parser, eventname, &args);
return STATUS_CMD_OK;
}