static std::string get_entire_translation(const char *filename) { int sz; unsigned char *bytes = slurp_file(getResource("%s.utf8", filename), &sz); if (!bytes) { native_error("Load error.", filename); } ALLEGRO_FILE *f = al_open_memfile(bytes, sz, "rb"); ALLEGRO_USTR *ustr; std::string whole_translation; while ((ustr = al_fget_ustr(f)) != NULL) { // remove newline int size = (int)al_ustr_size(ustr); const char *cstr = al_cstr(ustr); int count = 0; if (cstr[strlen(cstr)-1] == 0xa) count++; if (cstr[strlen(cstr)-2] == 0xd) count++; if (count > 0) { al_ustr_remove_range(ustr, size-count, size); } ustr_replace_all(ustr, '^', '\n'); whole_translation += al_cstr(ustr); } al_fclose(f); delete[] bytes; return whole_translation; }
void load_translation_tags(void) { ALLEGRO_FILE *f = al_fopen(getResource("English.utf8"), "r"); if (!f) { native_error("Couldn't load English.utf8."); } char buf[5000]; while (al_fgets(f, buf, 5000) != NULL) { if (buf[strlen(buf)-1] == 0xa) buf[strlen(buf)-1] = 0; if (buf[strlen(buf)-1] == 0xd) buf[strlen(buf)-1] = 0; for (int i = 0; buf[i]; i++) { if (buf[i] == '^') buf[i] = '\n'; } pre_translated_strings.push_back(std::string(buf)); } al_fclose(f); }
void initialize_and_call(JNIEnv * env, jobject jobj, jdoubleArray args) { jdouble *double_array; int num_args; jfieldID fid; genv = env; if (test_object_handle_class == NULL) { test_object_handle_class = (*env)->GetObjectClass(env, jobj); if (test_object_handle_class == NULL) { native_error("could not get test object class (TestObject)"); } } if (trace_field_id == NULL) { trace_field_id = (*env)->GetFieldID(env, test_object_handle_class, "t", "Lorg/iguanatool/testobject/trace/Trace;"); if (trace_field_id == NULL) { native_error("could not get trace field ID of TestObject"); } } trace_object = (*env)->GetObjectField(env, jobj, trace_field_id); if (trace_object == NULL) { native_error("could not get trace field of TestObject instance (object not initialized?)"); } if (trace_class == NULL) { trace_class = (*env)->GetObjectClass(env, trace_object); if (trace_class == NULL) { native_error("could not get trace class (Trace)"); } node_method_id = (*genv)->GetMethodID(genv, trace_class, "node", "(IZ)Z"); if (node_method_id == NULL) { native_error("could not get Trace.node() method ID"); } is_true_method_id = (*genv)->GetMethodID(genv, trace_class, "isTrue", "(ID)Z"); if (is_true_method_id == NULL) { native_error("could not get Trace.isTrue() method ID"); } ref_equals_method_id = (*genv)->GetMethodID(genv, trace_class, "refEquals", "(IZ)Z"); if (ref_equals_method_id == NULL) { native_error("could not get Trace.refEquals() method ID"); } ref_not_equals_method_id = (*genv)->GetMethodID(genv, trace_class, "refNotEquals", "(IZ)Z"); if (ref_not_equals_method_id == NULL) { native_error("could not get Trace.refNotEquals() method ID"); } equals_method_id = (*genv)->GetMethodID(genv, trace_class, "equals", "(IDD)Z"); if (equals_method_id == NULL) { native_error("could not get Trace.equals() method ID"); } not_equals_method_id = (*genv)->GetMethodID(genv, trace_class, "notEquals", "(IDD)Z"); if (not_equals_method_id == NULL) { native_error("could not get Trace.notEquals() method ID"); } less_than_method_id = (*genv)->GetMethodID(genv, trace_class, "lessThan", "(IDD)Z"); if (less_than_method_id == NULL) { native_error("could not get Trace.lessThan() method ID"); } less_than_or_equal_method_id = (*genv)->GetMethodID(genv, trace_class, "lessThanOrEqual", "(IDD)Z"); if (less_than_or_equal_method_id == NULL) { native_error("could not get Trace.lessThanOrEqual() method ID"); } greater_than_method_id = (*genv)->GetMethodID(genv, trace_class, "greaterThan", "(IDD)Z"); if (greater_than_method_id == NULL) { native_error("could not get Trace.greaterThan() method ID"); } greater_than_or_equal_method_id = (*genv)->GetMethodID(genv, trace_class, "greaterThanOrEqual", "(IDD)Z"); if (greater_than_or_equal_method_id == NULL) { native_error("could not get Trace.greaterThanOrEqual() method ID"); } } double_array = (*env)->GetDoubleArrayElements(env, args, NULL); if (double_array == NULL) { native_error("could not convert test object arguments to native double array"); } num_args = (*env)->GetArrayLength(env, args); if (!setjmp(__ins_early_exit_temp)) { perform_call(double_array, num_args); } (*env)->ReleaseDoubleArrayElements(env, args, double_array, 0); }