学习mupdf的套路,集成libmobi系列
从入门到放弃~~~~~~~~~~~~~~~··
必遇 error (1):
error: 'for' loop initial declarations are only allowed in C99 mode
reson:
使用gcc编译代码是报出
error: 'for' loop initial declarations are only allowed in C99 mode
note: use option -std=c99 or -std=gnu99 to compile your code
错误,这是因为在gcc中直接在for循环中初始化了增量:
for(int i=0; i<len; i++) {
}
改成
int i;
for(i=0;i<len;i++){
}
这是因为gcc基于c89标准,换成C99标准就可以在for循环内定义i变量了:
gcc src.c -std=c99 -o src
二、核心部分
#include "cinread_jj_jniexample_JniTest.h"
#include "mobi.h"
#include "meta.h"
#include <android/log.h>
#include <string.h>
# include <stdio.h>
# include <stdlib.h>
#define JNI_FN(A) Java_cinread_jj_jniexample_JniTest_ ## A
#define LOG_TAG "mobi_cinread"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
char *a;
int b;
JNIEXPORT jstring JNICALL
JNI_FN(stringFromJNI)(JNIEnv *env, jobject instance) {
//char *string = "string A from JNI";
return (*env)->NewStringUTF(env, a);
}
JNIEXPORT int JNICALL
JNI_FN(lengthFromJNI)(JNIEnv *env, jobject instance) {
return b;
}
JNIEXPORT jobject JNICALL
JNI_FN(openFile)(JNIEnv *env, jobject instance, jstring filename_) {
//const char *filename = (*env)->GetStringUTFChars(env, filename_, 0);
char *string = (*env)->GetStringUTFChars(env, filename_, NULL);
//mobi's init
/* Initialize main MOBIData structure */
/* Must be deallocated with mobi_free() when not needed */
MOBIData *m = mobi_init();
MOBIRawml *rawml = mobi_init_rawml(m);
//necessary add
mobi_load_filename(m, string);
//mobi's name
a = mobi_meta_get_title(m);
LOGI("filename = %s\n", a);
char *description = mobi_meta_get_description(m);
LOGI("description = %s\n", description);
char *subject = mobi_meta_get_subject(m);
LOGI("subject = %s\n", subject);
mobi_parse_rawml(rawml, m);
LOGI("%d\n", rawml->flow->size);
unsigned char *data = rawml->flow->data;
char *c = (char *) data;
LOGI("typere:%d\n", rawml->resources->type);
LOGI("typere:%d\n", rawml->resources->next);
//type=6为jpg 资源
unsigned char *datars = rawml->resources-&