/**
 * Main entry point
 */
int main( int argc, char **argv )
{
    FILE *output;
	int res = 0;
    if ( check_args(argc,argv) )
	{
		if ( !doing_help )
		{
            char *data,*text;
            int i,len;
            if ( file_list_load(text_file,0,&text,&len) )
            {
                master *hf = master_create( text, len );
                for ( i=0;i<file_list_size(markup_files);i++ )
                {
                    res = file_list_load(markup_files,i,&data,&len);
                    if ( res )
                    {
                        res = master_load_markup( hf, data, len, format_name );
                        free( data );
                        data = NULL;
                    }
                }
                if ( res )
                {
                    for ( i=0;i<file_list_size(css_files);i++ )
                    {
                        res = file_list_load(css_files,i,&data,&len);
                        if ( res )
                        {
                            res = master_load_css( hf, data, len );
                            free( data );
                            data = NULL;
                        }
                    }
                    output = fopen( html_file_name, "w" );
                    if ( output != NULL )
                    {
                        char *html = master_convert( hf );
                        fwrite( html, 1, master_get_html_len(hf), output );
                        fclose( output );
                    }
                }
                master_dispose( hf );
                free( text );
                text = NULL;
            }
            if ( css_files != NULL )
                file_list_delete( css_files );
            if ( markup_files != NULL )
                file_list_delete( markup_files );
            if ( text_file != NULL )
                file_list_delete( text_file );
        }
	}
	else
		usage();
#ifdef DEBUG_MEMORY
    memory_print();
#endif
	return res;
}
示例#2
0
文件: jni.c 项目: Ecdosis/calliope
/*
 * Class:     calliope_AeseFormatter
 * Method:    format
 * Signature: (Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;Lcalliope/json/JSONResponse;)I
 */
JNIEXPORT jint JNICALL Java_calliope_AeseFormatter_format
  (JNIEnv *env, jobject obj, jstring text, jobjectArray markup,
    jobjectArray css, jobject jsonHtml)
{
    int res=0;
    jsize i,len;
    UChar *html;
    jboolean isTextCopy=0;
    jchar *t_data = (jchar*)load_string(env, text, &isTextCopy);
    int t_len = u_strlen( t_data );
    if ( t_data != NULL && markup != NULL && css != NULL  )
    {
        jboolean isMarkupCopy;
        jni_report( "about to call master_create\n" );
        master *hf = master_create( t_data, t_len );
        if ( hf != NULL )
        {
            jni_report( "about to get markup array length\n" );
            len = (*env)->GetArrayLength(env, markup);
            for ( i=0;i<len;i++ )
            {
                res = 1;
                jni_report( "about to get markup str\n" );
                jstring markup_str = (jstring)(*env)->GetObjectArrayElement(
                    env, markup, i );
                jni_report( "about to load c string\n" );
                const char *markup_data = load_string_c(env, markup_str, 
                    &isMarkupCopy);
                if ( markup_data != NULL )
                {
                    res = master_load_markup( hf, markup_data,
                        (int)strlen(markup_data) );
                    unload_string_c( env, markup_str, markup_data,isMarkupCopy);
                }
                if ( !res )
                    break;
            }
            if ( res )
            {
                len = (*env)->GetArrayLength(env, css);
                for ( i=0;i<len;i++ )
                {
                    jboolean isCssCopy;
                    jstring css_str = (jstring)(*env)->GetObjectArrayElement(
                        env, css, i);
                    const char *css_data = load_string_c(env,css_str,&isCssCopy);
                    if ( css_data != NULL )
                    {
                        res = master_load_css( hf, css_data, (int)strlen(css_data) );
                        unload_string_c( env, css_str, css_data, isCssCopy );
                        if ( !res )
                            break;
                    }
                }
                if ( res )
                {
                    //jni_report( "about to call master_convert\n" );
                    html = master_convert( hf );
                    //jni_report( "finished calling master_convert\n" );
                    if ( html != NULL )
                    {
                        res = set_string_field( env, jsonHtml, "body", html );
                        if ( res == 0 )
                            jni_report("set string failed tried to write %d chars\n",u_strlen(html));
                    }
                }
            }
            master_dispose( hf );
        }
        unload_string(env,text,t_data,isTextCopy);
    }
#ifdef DEBUG_MEMORY
        memory_print();
#endif
    return res;
}