Ejemplo n.º 1
0
int main(int argc, char * argv[]) {
  Gunderscript ginst;
  size_t stackSize = 100000;
  int callbacksSize = 55;
  int i = 0;

  /* process_arguments(argc, argv, &stackSize); */

  /* initialize gunderscript object */
  if(!gunderscript_new(&ginst, stackSize, callbacksSize)) {
    print_alloc_error();
    return 1;
  }

  /* check for proper number of arguments */
  if(argc < 2) {
    print_help();
    gunderscript_free(&ginst);
    return 1;
  }

  /* compile scripts one-by-one */
  for(i = 2; i < argc; i++) {
    size_t fileLen = 0;
    char * fileContents = load_file(argv[i], &fileLen);
    printf("File Length: %i chars\n", (int)fileLen);
    if(!gunderscript_build(&ginst, fileContents, fileLen)) {
      print_compile_error(&ginst);
      print_build_fail();
      return 1;
    }
    free(fileContents);
  }

  printf("Script output:\n\n");

  /* execute the desired entry point */
  if(!gunderscript_function(&ginst, argv[1], strlen(argv[1]))) {
    print_exec_error(&ginst);
    print_exec_fail();
    return 1;
  }

  printf("\n\n");

  gunderscript_free(&ginst);

  return 0;
}
Ejemplo n.º 2
0
int main(int argc, char * argv[]) {
  Gunderscript ginst;
  size_t stackSize = 100000;
  int callbacksSize = 55;
  int i = 0;

  /* initialize gunderscript object */
  if(!gunderscript_new(&ginst, stackSize, callbacksSize)) {
    print_alloc_error();
    return 1;
  }

  /* check for proper number of arguments */
  if(argc < 2) {
    print_help();
    gunderscript_free(&ginst);
    return 1;
  }

  /* compile scripts one-by-one */
  for(i = 2; i < argc; i++) {
    if(!gunderscript_build_file(&ginst, argv[i])) {
      print_compile_error(&ginst);
      print_build_fail();
      gunderscript_free(&ginst);
      return 1;
    }
  }

  /* execute the desired entry point */
  if(!gunderscript_function(&ginst, argv[1], strlen(argv[1]))) {
    print_exec_error(&ginst);
    print_exec_fail();
    gunderscript_free(&ginst);
    return 1;
  }

  gunderscript_free(&ginst);

  return 0;
}