Example #1
0
void
cu5_pennpy_functions(void)
{
    function_add("PYCALL", cu5_pennpy_fun_pycall, 1, INT_MAX, FN_REG);
    function_add("PYEVAL", cu5_pennpy_fun_pyeval, 1, 1, FN_REG);
    function_add("PYRUN", cu5_pennpy_fun_pyrun, 1, 1, FN_REG);
}
Example #2
0
void
local_functions(void)
{
#ifdef EXAMPLE
  function_add("SILLY", local_fun_silly, 1, 1, FN_REG);
#endif
}
Example #3
0
    void CHSInterface::SetupInterfaceCommands()
{
#ifdef PENNMUSH

#ifdef CAN_TAKE_ARGS_IN_FP
    command_add("man", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0, NULL,
                cmd_hs_man);
    command_add("unman", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL, cmd_hs_unman);
    command_add("board", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL, cmd_hs_board);
    command_add("disembark", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL, cmd_hs_disembark);
    command_add("@SPACE", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL, cmd_hs_space);
    command_add("@NAV", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL, cmd_hs_nav);
    command_add("@CONSOLE", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL, cmd_hs_console);
    command_add("@ENG", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL, cmd_hs_eng);
#else
    command_add("man", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0, NULL,
                cmd_hs_man);
    command_add("unman", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL,  cmd_hs_unman);
    command_add("board", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL,  cmd_hs_board);
    command_add("disembark", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL,  cmd_hs_disembark);
    command_add("@SPACE", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL,  cmd_hs_space);
    command_add("@NAV", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL,  cmd_hs_nav);
    command_add("@CONSOLE", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL,  cmd_hs_console);
    command_add("@ENG", CMD_T_ANY | CMD_T_SWITCHES | CMD_T_EQSPLIT, 0, 0,
                NULL,  cmd_hs_eng);
#endif

    function_add("HS_GET_ATTR", hs_get_attr, 2, 2, FN_REG);
    function_add("HS_GET_MISSILE", hs_get_missile, 2, 2, FN_REG);
    function_add("HS_SET_MISSILE", hs_set_missile, 3, 3, FN_REG);
    function_add("HS_DECAY_MSG", hs_decay_msg, 2, 2, FN_REG);
    function_add("XYANG", hs_xyangle, 4, 4, FN_REG);
    function_add("ZANG", hs_zangle, 6, 6, FN_REG);
    function_add("HS_SPACEMSG", hs_spacemsg, 2, 7, FN_REG);
    function_add("HS_ENG_SYS", hs_eng_sys, 1, 1, FN_REG);
    function_add("HS_SET_ATTR", hs_set_attr, 2, 2, FN_REG);
    function_add("HS_SREP", hs_srep, 2, 2, FN_REG);
    function_add("HS_ADD_WEAPON", hs_add_weapon, 2, 2, FN_REG);
    function_add("HS_DEL_WEAPON", hs_del_weapon, 2, 2, FN_REG);
    function_add("HS_WEAPON_ATTR", hs_weapon_attr, 2, 2, FN_REG);
    function_add("HS_SYS_ATTR", hs_sys_attr, 2, 3, FN_REG);
    function_add("HS_SYSSET", hs_sysset, 2, 2, FN_REG);
    function_add("HS_DELSYS", hs_delsys, 2, 2, FN_REG);
    function_add("HS_ADDSYS", hs_addsys, 2, 2, FN_REG);
    function_add("HS_COMM_MSG", hs_comm_msg, 8, 8, FN_REG);
    function_add("HS_CLONE", hs_clone, 1, 1, FN_REG);
    function_add("HS_NEARBY", hs_nearby, 5, 5, FN_REG);
    function_add("HS_LIST", hs_list, 3, 3, FN_REG);
    function_add("HS_EXPLODE", hs_explode, 6, 6, FN_REG);
    function_add("HS_CONWEAP", hs_conweap, 2, 2, FN_REG);
    function_add("HS_COMMAND", hs_command, 2, 4, FN_REG);

    struct pennmush_flag_info *pFlagInfo;
    for (pFlagInfo = hspace_flag_table; pFlagInfo->name; pFlagInfo++)
    {
        add_flag(pFlagInfo->name, pFlagInfo->letter, pFlagInfo->type,
                 pFlagInfo->perms, pFlagInfo->negate_perms);
    }

#endif

}
Example #4
0
/// Define a function. Calls into `function.cpp` to perform the heavy lifting of defining a
/// function.
int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args,
                     const wcstring &contents, int definition_line_offset) {
    // The wgetopt function expects 'function' as the first argument. Make a new wcstring_list with
    // that property. This is needed because this builtin has a different signature than the other
    // builtins.
    wcstring_list_t args = {L"function"};
    args.insert(args.end(), c_args.begin(), c_args.end());

    // Hackish const_cast matches the one in builtin_run.
    const null_terminated_array_t<wchar_t> argv_array(args);
    wchar_t **argv = const_cast<wchar_t **>(argv_array.get());
    wchar_t *cmd = argv[0];
    int argc = builtin_count_args(argv);

    // A valid function name has to be the first argument.
    wcstring function_name;
    int retval = validate_function_name(argc, argv, function_name, cmd, streams);
    if (retval != STATUS_CMD_OK) return retval;
    argv++;
    argc--;

    function_cmd_opts_t opts;
    int optind;
    retval = parse_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, streams.err);
        return STATUS_CMD_OK;
    }

    if (argc != optind) {
        if (opts.named_arguments.size()) {
            for (int i = optind; i < argc; i++) {
                opts.named_arguments.push_back(argv[i]);
            }
        } else {
            streams.err.append_format(_(L"%ls: Unexpected positional argument '%ls'"), cmd,
                                      argv[optind]);
            return STATUS_INVALID_ARGS;
        }
    }

    // We have what we need to actually define the function.
    function_data_t d;
    d.name = function_name;
    if (!opts.description.empty()) d.description = opts.description;
    // d.description = opts.description;
    d.events.swap(opts.events);
    d.shadow_scope = opts.shadow_scope;
    d.named_arguments.swap(opts.named_arguments);
    d.inherit_vars.swap(opts.inherit_vars);

    for (size_t i = 0; i < d.events.size(); i++) {
        event_t &e = d.events.at(i);
        e.function_name = d.name;
    }

    d.definition = contents.c_str();
    function_add(d, parser, definition_line_offset);

    // Handle wrap targets by creating the appropriate completions.
    for (size_t w = 0; w < opts.wrap_targets.size(); w++) {
        complete_add_wrapper(function_name, opts.wrap_targets.at(w));
    }

    return STATUS_CMD_OK;
}
Example #5
0
/// Define a function. Calls into `function.cpp` to perform the heavy lifting of defining a
/// function.
int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args,
                     const parsed_source_ref_t &source, tnode_t<grammar::job_list> body) {
    assert(source && "Missing source in builtin_function");
    // The wgetopt function expects 'function' as the first argument. Make a new wcstring_list with
    // that property. This is needed because this builtin has a different signature than the other
    // builtins.
    wcstring_list_t args = {L"function"};
    args.insert(args.end(), c_args.begin(), c_args.end());

    null_terminated_array_t<wchar_t> argv_array(args);
    wchar_t **argv = argv_array.get();
    wchar_t *cmd = argv[0];
    int argc = builtin_count_args(argv);

    // A valid function name has to be the first argument.
    wcstring function_name;
    int retval = validate_function_name(argc, argv, function_name, cmd, streams);
    if (retval != STATUS_CMD_OK) return retval;
    argv++;
    argc--;

    function_cmd_opts_t opts;
    int optind;
    retval = parse_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, streams.err);
        return STATUS_CMD_OK;
    }

    if (argc != optind) {
        if (opts.named_arguments.size()) {
            for (int i = optind; i < argc; i++) {
                opts.named_arguments.push_back(argv[i]);
            }
        } else {
            streams.err.append_format(_(L"%ls: Unexpected positional argument '%ls'"), cmd,
                                      argv[optind]);
            return STATUS_INVALID_ARGS;
        }
    }

    // We have what we need to actually define the function.
    function_data_t d;
    d.name = function_name;
    if (!opts.description.empty()) d.description = opts.description;
    // d.description = opts.description;
    d.events.swap(opts.events);
    d.props.shadow_scope = opts.shadow_scope;
    d.props.named_arguments = std::move(opts.named_arguments);
    d.inherit_vars = std::move(opts.inherit_vars);

    for (size_t i = 0; i < d.events.size(); i++) {
        event_t &e = d.events.at(i);
        e.function_name = d.name;
    }

    d.props.parsed_source = source;
    d.props.body_node = body;
    function_add(std::move(d), parser);

    // Handle wrap targets by creating the appropriate completions.
    for (const wcstring &wt : opts.wrap_targets) complete_add_wrapper(function_name, wt);
    return STATUS_CMD_OK;
}