#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "kernel.h"
#include "veneers.h"
#include "swis.h"

int fscontrolv_handler(_kernel_swi_regs *r,void *pw)
{
  int object,filetype;

  if (r->r[0]!=4) return 1; // only interested in running files

  if (_swix(OS_File,_INR(0,1)|_OUT(0)|_OUT(6),23,r->r[1],&object,&filetype)) return 1;
  if (object!=1) return 1;

  if (filetype==0xfeb) {
    int length=0;
    char *ptr=(char *)r->r[1];
    while (*ptr>32) {
      length++;
      ptr++;
    }

    //  needs to be canonical....
    _swix(OS_SetVarVal,_INR(0,4),"Obey$File",r->r[1],length,0,4);
  }

  return 1;
}
