Example #1
0
int run_script_auto (struct incbin * incbin, const void * data, const char * script_file, FILE * out) {
  char ** script_lines = NULL;
  char * error = NULL;
  FILE * script = fopen(script_file, "r");
  if (!script) goto error;
  script_lines = read_file_by_lines(script);
  fclose(script);
  char ** output_lines = execute_script(incbin, data, script_lines, &error);
  if (error) goto error;
  if (global_settings.insert_replacement_comment) write_header_comment(incbin, out);
  char ** line;
  char * indent;
  generate_initial_indented_line(&indent, NULL);
  for (line = output_lines; *line; line ++) {
    printf(">>>> %s%s\n", indent, *line);
    fprintf(out, "%s%s\n", indent, *line);
  }
  free(indent);
  destroy_string_array(output_lines);
  destroy_string_array(script_lines);
  return 0;
  error:
  destroy_string_array(script_lines);
  printf("err: %s\n", error);
  free(error);
  return 1;
}
Example #2
0
int handle_script_output (char ** output_lines, char * error, struct incbin * incbin, FILE * out) {
  if (error) {
    printf("err: %s\n", error);
    free(error);
    return 0;
  }
  if (global_settings.insert_replacement_comment) write_header_comment(incbin, out);
  char ** line;
  char * indent;
  generate_initial_indented_line(&indent, NULL);
  for (line = output_lines; *line; line ++) {
    printf(">>>> %s%s\n", indent, *line);
    fprintf(out, "%s%s\n", indent, *line);
  }
  free(indent);
  destroy_string_array(output_lines);
  return 1;
}
Example #3
0
void check_if_this_is_a_pentium (FILE *file)
{
  write_header_comment (file,"is this a pentium on a gcc-based platform?");
  write_to_file ("ctest.cpp",
		 "int main() {\n"
		 "  asm (\"mov $0,%%eax\\n cpuid\\n\" : : : \"%eax\");\n"
		 "  return 0;\n"
		 "}\n");
  delete_file ("ctest.exe");
  compile ("ctest.exe","ctest.cpp");
  if (file_exists ("ctest.exe")) {
    fprintf (file,"#define PENTIUM 1\n\n");
  }
  else {
    fprintf (file,"/* #define PENTIUM 1 -- not a pentium */\n\n");
  }

  delete_file ("ctest.cpp");
  delete_file ("ctest.exe");
}
Example #4
0
void get_ODE_integer_typedefs (FILE *file)
{
  write_header_comment (file,"integer types (we assume int >= 32 bits)");
  if (sizeof(char) != 1) fatal_error ("expecting sizeof(char) == 1");
  if (sizeof(int) < 4) fatal_error ("expecting sizeof(int) >= 4");
  fprintf (file,"typedef char int8;\ntypedef unsigned char uint8;\n");

  if (sizeof(short) == 2) {
    fprintf (file,"typedef short int16;\ntypedef unsigned short uint16;\n");
  }
  else {
    fatal_error ("can not find 2 byte integer type");
  }

  if (sizeof(short) == 4) {
    fprintf (file,"typedef short int32;\ntypedef unsigned short uint32;\n");
  }
  else if (sizeof(int) == 4) {
    fprintf (file,"typedef int int32;\ntypedef unsigned int uint32;\n");
  }
  else {
    fatal_error ("can not find 4 byte integer type");
  }

  fprintf (file,"\n"
	   "/* an integer type that we can safely cast a pointer to and\n"
	   " * from without loss of bits.\n"
	   " */\n");
  if (sizeof(short) == sizeof(void*)) {
    fprintf (file,"typedef unsigned short intP;\n");
  }
  else if (sizeof(int) == sizeof(void*)) {
    fprintf (file,"typedef unsigned int intP;\n");
  }
  else if (sizeof(long int) == sizeof(void*)) {
    fprintf (file,"typedef unsigned long int intP;\n");
  }

  fprintf (file,"\n");
}
Example #5
0
void get_available_functions (FILE *file)
{
	int i,j;
	char *fnames[FUNCTIONS_TO_TEST*3] = {
		/* statement to compile,	if it works,	if not */
		"sqrtf(1.0f);",			0,		"#define sqrtf sqrt",
		"sinf(1.0f);",			0,		"#define sinf sin",
		"cosf(1.0f);",			0,		"#define cosf cos",
		"fabsf(1.0f);",			0,		"#define fabsf fabs",
		"atan2f(1.0f,1.0f);",		0,		"#define atan2f atan2",
		"fmodf(1.0f,1.0f);",		0,		"#define fmodf fmod",
		"copysignf(1.0f,1.0f);",	0,		"#define copysignf copysign",
		/* to handle cygwin: */
		"copysign(1.0,1.0);",		0,		"#define copysign _copysign",
		"snprintf(\"\",0,\"\");",	0,		"#define snprintf _snprintf",
		"vsnprintf(\"\",0,\"\",0);",	0,		"#define vsnprintf _vsnprintf"
	};

	write_header_comment (file,"available functions");

	for (i=0; i < FUNCTIONS_TO_TEST; i++) {
		FILE *f = xfopen ("ctest.cpp","wt");
		for (j=0; j < NUM_HEADERS; j++) {
			if (header_used[j]) fprintf (f,"#include <%s>\n",header_files[j]);
		}
		fprintf (f,"int main() { %s return 0; }\n",fnames[i*3]);
		fclose (f);
		delete_file ("ctest.exe");
		compile ("ctest.exe","ctest.cpp");
		if (file_exists ("ctest.exe")) {
			if (fnames[i*3+1]) fprintf (file,"%s\n",fnames[i*3+1]);
		}
		else {
			if (fnames[i*3+2]) fprintf (file,"%s\n",fnames[i*3+2]);
		}
		delete_file ("ctest.cpp");
		delete_file ("ctest.exe");
	}
}
Example #6
0
void get_alloca_usage (FILE *file)
{
  int i,j;
  for (i=0; i<NUM_ALLOCA; i++) {
    FILE *f = xfopen ("ctest.cpp","wt");
    for (j=0; j < NUM_HEADERS; j++) {
      if (header_used[j]) fprintf (f,"#include <%s>\n",header_files[j]);
    }
    fprintf (f,"int main() { void *foo = %s (10); }\n",alloca_function[i]);
    fclose (f);
    delete_file ("ctest.exe");
    compile ("ctest.exe","ctest.cpp");
    if (file_exists ("ctest.exe")) {
      if (i > 0) {
	write_header_comment (file,"how to use alloca()");
	fprintf (file,"#define alloca %s\n\n",alloca_function[i]);
      }
      break;
    }
  }
  delete_file ("ctest.cpp");
  delete_file ("ctest.exe");
  if (i == NUM_ALLOCA) fatal_error ("i can't find a way to use alloca()");
}
Example #7
0
void get_ODE_float_stuff (FILE *file)
{
  char *suffix;
  int i,j;
  FILE *f;

  #define INFINITIES_TO_TEST 4
#ifdef dSINGLE
  char *decl[INFINITIES_TO_TEST] = {
    "#define dInfinity FLT_MAX",
    "#define dInfinity HUGE_VALF",
    "#define dInfinity 3.402823466e+38F",
    "#define dInfinity 1e20f"};
#else
  char *decl[INFINITIES_TO_TEST] = {
    "#define dInfinity DBL_MAX",
    "#define dInfinity HUGE_VAL",
    "#define dInfinity 1.7976931348623157e+308",
    "#define dInfinity 1e20"};
#endif

  write_header_comment (file,"select the base floating point type");
#ifdef dSINGLE
  fprintf (file,"#define dSINGLE 1\n\n");
  suffix = "f";
#else
  fprintf (file,"#define dDOUBLE 1\n\n");
  suffix = "";
#endif

  /* infinity */
  write_header_comment (file,"the floating point infinity");

  /* try the different infinity constants until one works */
  for (i=0; i < INFINITIES_TO_TEST; i++) {
    f = xfopen ("ctest.cpp","wt");
    for (j=0; j < NUM_HEADERS; j++) {
      if (header_used[j]) fprintf (f,"#include <%s>\n",header_files[j]);
    }
    fprintf (f,
	     "%s\n"
	     "int main() {\n"
	     "	if (dInfinity > 1e10%s && -dInfinity < -1e10%s &&\n"
	     "	    -dInfinity < dInfinity) {\n"
	     "	  FILE *f = fopen (\"data\",\"wt\");\n"
	     "	  fprintf (f,\"foo\\n\");\n"
	     "	  fclose (f);\n"
	     "	}\n"
	     "	return 0;\n"
	     "}\n"
	     ,decl[i],suffix,suffix);
    fclose (f);
    delete_file ("data");
    compile ("ctest.exe","ctest.cpp");
    run ("ctest.exe");
    if (file_exists ("data")) {
      fprintf (file,"%s\n\n",decl[i]);
      delete_file ("ctest.cpp");
      delete_file ("ctest.exe");
      delete_file ("data");
      return;
    }
  }

  fatal_error ("can't determine dInfinity constant");
}