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

#include "Popcorn:h.Popcorn"

#ifdef DESKLIB
#include "DeskLib:h.File"
#include "DeskLib:h.Str"
#else
#include "Popfiles.h"
#endif

_kernel_oserror ERROR_MEMORY = {0, "Not enough memory to load group"};

_kernel_oserror *Popcorn_LoadGroup(int group) {
  int c = 0;
  _kernel_oserror *err;

  while (c != resource_free) {
    if (resource[c]->group == group && resource[c]->addr == NULL) {
      resource[c]->addr = malloc(resource[c]->size);
      if (resource[c]->addr == NULL) return &ERROR_MEMORY;
      err = file_load(resource[c]->file, resource[c]->addr);
      if (err != NULL) return err;
      /* printf("Loading %X %s\n", resource[c]->addr, resource[c]->file); */
    }
    c++;
  }

  return NULL;
}
