示例#1
0
文件: resio.c 项目: beoran/alithia
static char* rio_write_path(void)
{
    const char* writepath = arg_value("-writepath", NULL);
    const char* writename = arg_value("-writename", NULL);
    char* awdir = writepath ? strdup(writepath) : rio_system_write_path();
    char* fdir;
    char* dir;
    size_t i;

    if (writepath) {
        fdir = unipath(writepath);
        free(awdir);
        return fdir;
    }

    if (writename) {
        fdir = strdup(writename);
    } else {
        if (arg_value("-game", NULL)) {
            fdir = strdup(dirs->first->ptr);
        } else {
            fdir = strdup("");
        }
    }

    dir = malloc(strlen(awdir) + strlen(fdir) + 256);
    sprintf(dir, "%s%s", awdir, fdir);

    free(fdir);
    free(awdir);
    fdir = unipath(dir);
    free(dir);
    return fdir;
}
示例#2
0
文件: resio.c 项目: beoran/alithia
static char* rio_system_datapath(void)
{
    char* path = NULL;
    char* binpath = unipath(getApplicationDirectory());
    path = malloc(strlen(binpath) + 256);
    sprintf(path, "%s/Contents/Resources", binpath);
    free(binpath);
    return path;
}
示例#3
0
文件: resio.c 项目: beoran/alithia
list_t* rio_files(const char* path)
{
    list_t* files = list_new();
    char* upath = unipath(path);
    listitem_t* it;

    files->item_free = free;

    for (it=dirs->first; it; it=it->next) {
        const char* dir = it->ptr;
        char* tmpath = malloc(strlen(upath) + strlen(dir) + 1);
        sprintf(tmpath, "%s%s", dir, upath);
        rio_files_scandir(files, tmpath);
        free(tmpath);
    }

    free(upath);

    return files;
}
示例#4
0
int main(int argc, char **argv)
{
  static const char *defOutput = "a.out";
  // TODO: option for verbose mode, logging (VPMedia)
  bool targetPlayer = false;
  bool targetAIR = false;
  bool saveTemps = false;
  FILE *input = NULL;
  FILE *output = NULL;

  for(int i = 1; i < argc; i++)
  {
    std::string arg(argv[i]);

    if(arg == "-o")
    {
      if(i >= argc - 1)
        error("-o with no output file");
      if(output)
        error("Multiple output files specified");
      if(!(output = fopen(argv[++i], "wb+")))
        error("Failed to open %s for output", argv[i]);
    }
    else if(arg == "--")
    {
      if(input)
        error("Multiple input files specified");
      input = stdin;
    }
    else if(arg == "--target-player") 
    {
      targetPlayer = true;
    }
    else if(arg == "--target-air") 
    {
      targetAIR = true;
    }
    else if(arg == "--save-temps") 
    {
      saveTemps = true;
    }
    else
    {
      if(input)
        error("Multiple input files specified: %s", argv[i]);
      if(!(input = fopen(argv[i], "r")))
        error("Failed to open %s for input", argv[i]);
    }
  }
  if(!input)
    input = stdin;
  if(!output && !(output = fopen(defOutput, "wb+")))
    error("Failed to open %s for output", defOutput);

  std::string tmp1Path;
  FILE *tmp1 = tmpfile(&tmp1Path, ".as");

  if(!tmp1)
    error("Couldn't create temp file 1");

  Unlinker l1(tmp1Path);
  std::string tmp2Path;
  FILE *tmp2 = tmpfile(&tmp2Path, ".as");

  if(!tmp2)
    error("Couldn't create temp file 2");

  Unlinker l2(tmp2Path);
  FILE *cur = tmp1;

  for(;;)
  {
    std::string line;

    if(!readline(&line, input))
      break;

    if(line.at(0) == '#')
    {
      if(!line.compare(1, 8, "---SPLIT"))
      {
        if(cur == tmp2)
          error("Multiple split directives encountered");
        fclose(tmp1);
        tmp1 = NULL;
        cur = tmp2;
      }
    }
    else
    {
      size_t len = line.length();
      const char *data = line.data();

      while(len)
      {
        int written = fwrite(data, 1, len, cur);

        if(written <= 0)
          error("Failed to write to output file");

        len -= written;
        data += written;
      }
    }
  }
  if(tmp1)
    fclose(tmp1);
  fclose(tmp2);

  std::string outTmpPath;
  FILE *outTmp = tmpfile(&outTmpPath, ".abc");
  fclose(outTmp);

  if(!outTmp)
    error("Couldn't create temp file 2");

  Unlinker l3(outTmpPath);

  std::string libPath = SetFlasccSDKLocation("/../../");
  libPath = unipath(libPath + "/usr/lib");

  std::vector<std::string> jargs;

  jargs.push_back("java");
  jargs.push_back("-Xms512M");
  jargs.push_back("-Xmx2048M");
  jargs.push_back("-ea");
  jargs.push_back("-jar");
  jargs.push_back(libPath + "/asc2.jar");
  // merge the compiled source into a single output
  jargs.push_back("-merge");
  // emit metadata information into the bytecode
  jargs.push_back("-md");
  // turn on parallel generation of method bodies feature
  jargs.push_back("-parallel");
  // turn on the inlining of functions
  jargs.push_back("-inline");
  // future abc (?)
  jargs.push_back("-abcfuture");
  // use the AS3 class based object model
  jargs.push_back("-AS3");
  // make packages available for import
  jargs.push_back("-import");
  jargs.push_back(libPath + "/builtin.abc");
  jargs.push_back("-import");
  if(targetPlayer)
    jargs.push_back(libPath + "/playerglobal.abc");
  else if(targetAIR)
    jargs.push_back(libPath + "/airglobal.abc");
  else
    jargs.push_back(libPath + "/shell_toplevel.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/BinaryData.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/Exit.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/LongJmp.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/ISpecialFile.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/IBackingStore.abc");

  if(targetPlayer) {
    jargs.push_back("-import");
    jargs.push_back(libPath + "/InMemoryBackingStore.abc");
  }

  jargs.push_back("-import");
  jargs.push_back(libPath + "/IVFS.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/CModule.abc");

  jargs.push_back(unipath(tmp2Path));
  jargs.push_back(unipath(tmp1Path));

  jargs.push_back("-outdir");
  jargs.push_back(unipath(dirname(outTmpPath)));
  
  std::string outNoExt = basename(outTmpPath);

  outNoExt = outNoExt.substr(0, outNoExt.length() - 4); // trim the ".abc"! -- ugh!

  jargs.push_back("-out");
  jargs.push_back(outNoExt);

  std::string cmdoutput;
  if(runCmd(&cmdoutput, jargs))
    error("Failed to execute compiler: %s", cmdoutput.c_str());

  outTmp = fopen(outTmpPath.c_str(), "r");
  for(;;)
  {
    char buf[CHUNK];
    int nRead = fread(buf, 1, sizeof(buf), outTmp);

    if(nRead < 0)
      error("Failed to read from temporary output");
    if(nRead == 0)
      break;
    if(nRead != fwrite(buf, 1, nRead, output))
      error("Failed to write to final output");
  }
  fclose(output);
  fclose(outTmp);

  #ifdef _WIN32
    if(!saveTemps)
        DeleteFile(apptempdir);
  #endif
  
  return 0;
}
示例#5
0
int main(int argc, char **argv)
{
  static const char *defOutput = "a.out";

  bool targetPlayer = false;
  bool useLegacyAsc = false;
  FILE *input = NULL;
  FILE *output = NULL;

  for(int i = 1; i < argc; i++)
  {
    std::string arg(argv[i]);

    if(arg == "-o")
    {
      if(i >= argc - 1)
        error("-o with no output file");
      if(output)
        error("Multiple output files specified");
      if(!(output = fopen(argv[++i], "wb+")))
        error("Failed to open %s for output", argv[i]);
    }
    else if(arg == "--")
    {
      if(input)
        error("Multiple input files specified");
      input = stdin;
    }
    else if(arg == "--target-player")
      targetPlayer = true;
    else if(arg == "--use-legacy-asc")
      useLegacyAsc = true;
    else
    {
      if(input)
        error("Multiple input files specified: %s", argv[i]);
      if(!(input = fopen(argv[i], "r")))
        error("Failed to open %s for input", argv[i]);
    }
  }
  if(!input)
    input = stdin;
  if(!output && !(output = fopen(defOutput, "wb+")))
    error("Failed to open %s for output", defOutput);

  std::string tmp1Path;
  FILE *tmp1 = tmpfile(&tmp1Path, ".as");

  if(!tmp1)
    error("Couldn't create temp file 1");

  Unlinker l1(tmp1Path);
  std::string tmp2Path;
  FILE *tmp2 = tmpfile(&tmp2Path, ".as");

  if(!tmp2)
    error("Couldn't create temp file 2");

  Unlinker l2(tmp2Path);
  FILE *cur = tmp1;

  for(;;)
  {
    std::string line;

    if(!readline(&line, input))
      break;

    if(line.at(0) == '#')
    {
      if(!line.compare(1, 8, "---SPLIT"))
      {
        if(cur == tmp2)
          error("Multiple split directives encountered");
        fclose(tmp1);
        tmp1 = NULL;
        cur = tmp2;
      }
    }
    else
    {
      size_t len = line.length();
      const char *data = line.data();

      while(len)
      {
        int written = fwrite(data, 1, len, cur);

        if(written <= 0)
          error("Failed to write to output file");

        len -= written;
        data += written;
      }
    }
  }
  if(tmp1)
    fclose(tmp1);
  fclose(tmp2);

  std::string outTmpPath;
  FILE *outTmp = tmpfile(&outTmpPath, ".abc");
  fclose(outTmp);

  if(!outTmp)
    error("Couldn't create temp file 2");

  Unlinker l3(outTmpPath);

  std::string libPath = SetFlasccSDKLocation("/../../");
  libPath = unipath(libPath + "/usr/lib");

  std::vector<std::string> jargs;

  jargs.push_back("java");
  jargs.push_back("-Xms512M");
  jargs.push_back("-Xmx2048M");
  jargs.push_back("-ea");
  if(useLegacyAsc)
  {
    jargs.push_back("-classpath");
    jargs.push_back(libPath + "/asc.jar");
    jargs.push_back("macromedia.asc.embedding.ScriptCompiler");
  }
  else
  {
    jargs.push_back("-jar");
    jargs.push_back(libPath + "/asc2.jar");
    jargs.push_back("-merge");
    jargs.push_back("-md");
  }
  jargs.push_back("-abcfuture");
  jargs.push_back("-AS3");

  jargs.push_back("-import");
  jargs.push_back(libPath + "/builtin.abc");
  jargs.push_back("-import");
  if(targetPlayer)
    jargs.push_back(libPath + "/playerglobal.abc");
  else
    jargs.push_back(libPath + "/shell_toplevel.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/BinaryData.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/Exit.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/LongJmp.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/ISpecialFile.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/IBackingStore.abc");

  if(targetPlayer) {
    jargs.push_back("-import");
    jargs.push_back(libPath + "/InMemoryBackingStore.abc");
  }

  jargs.push_back("-import");
  jargs.push_back(libPath + "/IVFS.abc");
  jargs.push_back("-import");
  jargs.push_back(libPath + "/CModule.abc");

  if(useLegacyAsc) {
    jargs.push_back(unipath(tmp1Path));
    jargs.push_back(unipath(tmp2Path));
  } else {
    jargs.push_back(unipath(tmp2Path));
    jargs.push_back(unipath(tmp1Path));
  }

  jargs.push_back("-outdir");
  jargs.push_back(unipath(dirname(outTmpPath)));
  
  std::string outNoExt = basename(outTmpPath);

  outNoExt = outNoExt.substr(0, outNoExt.length() - 4); // trim the ".abc"! -- ugh!

  jargs.push_back("-out");
  jargs.push_back(outNoExt);

  std::string cmdoutput;
  if(runCmd(&cmdoutput, jargs))
    error("Failed to execute compiler: %s", cmdoutput.c_str());

  outTmp = fopen(outTmpPath.c_str(), "r");
  for(;;)
  {
    char buf[CHUNK];
    int nRead = fread(buf, 1, sizeof(buf), outTmp);

    if(nRead < 0)
      error("Failed to read from temporary output");
    if(nRead == 0)
      break;
    if(nRead != fwrite(buf, 1, nRead, output))
      error("Failed to write to final output");
  }
  fclose(output);
  fclose(outTmp);

  #ifdef _WIN32
    DeleteFile(apptempdir);
  #endif
  
  return 0;
}
示例#6
0
文件: resio.c 项目: beoran/alithia
void rio_mountdir(const char* path)
{
    list_add(dirs, unipath(path));
}
示例#7
0
文件: resio.c 项目: beoran/alithia
static char* rio_system_write_path(void)
{
    return unipath(getApplicationWriteDirectory(arg_value("-appname", GAME_TITLE)));
}