/** RM_date - print any portion of the **/
/** "Time" message in any specified    **/
/** format using SYS &C1 (see PRM)     **/
/** Made in England by Dec McSweeney   **/
/** Converted to a module Feb 1991     **/

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

int print_date(char *fmt)
{
char pblock[5];
char outstring[150];
_kernel_swi_regs r;

r.r[0]=14;
r.r[1]=(int)pblock;
pblock[0] = 3;
_kernel_swi(OS_Word, &r, &r);

r.r[0]=r.r[1];
r.r[1]=(int)outstring;
r.r[2]=150;
r.r[3]=(int)fmt;
_kernel_swi(OS_ConvertDateAndTime, &r, &r);

printf("%s\n", outstring);
return 0;
}

_kernel_oserror *RM_date_cmd(char *arg_string, int argc, int cmd_no, void *reg_12)
{
char *s = arg_string;

/** remove the quotes surrounding our one argument and convert **/
/** carriage return terminator from control code to zero byte. **/
/** argc will always be 1 because of the cmhg line describing  **/
/** the function, with the clauses min-args:1, max-args:1      **/

if(*s == '"'){
   while(*(++s) != '"' && *s >= ' ')
      ;
   *s='\0';
   s=arg_string + 1;
}
else{
   while(*(s++) >= ' ')
      ;
   *s='\0';
   s=arg_string;
}

print_date(s);
return 0;
}

int RM_date_init(char *cmd_tail, int podule_base, void *reg_12)
{
printf("initialising :");
return 0;
}

int main(int argc, char *argv[])
{
    printf("%s: Loading RMA\n", argv[0]);
    return 0;
}
