/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* File:    rmensure.c
 * Purpose: ensuring a module is loaded
 * Author:  IDJ
 * History: 24-Jun-94: IDJ: created
 */


#include <stdio.h>
#include "kernel.h"
#include "swis.h"

#include "rmensure.h"
#include "macros.h"

_kernel_oserror *rmensure (char *module_name, char *file_name, char *module_version)
{
#ifndef ROM
    _kernel_swi_regs regs;
    _kernel_oserror *e;
    char command[256];

    /*
     * see if the module is there at all!
     */

    sprintf (command, "*RMEnsure %s %s *RMLoad System:modules.%s", module_name,
                                module_version, file_name);

    regs.r[0] = (int)command;
    if ((e = _kernel_swi (OS_CLI, &regs, &regs)) != NULL)
        return e;

    sprintf (command, "*RMEnsure %s %s", module_name, module_version);

    regs.r[0] = (int)command;
    if ((e = _kernel_swi (OS_CLI, &regs, &regs)) != NULL)
        return e;
#else
    IGNORE(module_name);
    IGNORE(file_name);
    IGNORE(module_version);
#endif

    return NULL;
}