/*
 *   Scan a variable 
 */
void CTcLibParser::scan_var(const char *name, const char *val)
{
    /* call the appropriate routine based on the variable name */
    if (stricmp(name, "name") == 0)
        scan_name(val);
    else if (stricmp(name, "source") == 0)
        scan_source(val);
    else if (stricmp(name, "library") == 0)
        scan_library(val);
    else if (stricmp(name, "resource") == 0)
        scan_resource(val);
    else if (stricmp(name, "needmacro") == 0)
        scan_needmacro(val);
    else
        err_unknown_var(name, val);
}
示例#2
0
/**
 * The main entry point
 * @param argc number of commandline args+1
 * @param argv array of arguments, first is program name
 * @return 0 to the system
 */
int main( int argc, char **argv )
{
    stripper *s = stripper_create();
    if ( s != NULL )
    {
        int res = 1;
        if ( check_args(argc,argv,s) )
		{
            recipe *rules;
            if ( s->recipe_file == NULL )
                rules = recipe_new();
            else
            {
                int rlen;
                const char *rdata = read_file( s->recipe_file, &rlen );
                if ( rdata != NULL )
                {
                    rules = recipe_load(rdata, rlen);
                    free( (char*)rdata );
                }
            }
            if ( rules != NULL )
            {
                hh_exceptions *hhe = hh_exceptions_create( s->hh_except_string );
                s->user_data = userdata_create( s->language, s->barefile, 
                    rules, &formats[s->selected_format], hhe );
                if ( s->user_data == NULL )
                {
                    fprintf(stderr,"stripper: failed to initialise userdata\n");
                    res = 0;
                }
                if ( res && !s->doing_help )
                {
                    int i=0;
                    userdata *u = s->user_data;
                    while ( userdata_markup_dest(u,i) )
                    {
                        res = formats[s->selected_format].hfunc( NULL, 
                            dest_file_dst(userdata_markup_dest(u,i)), s->style );
                        i++;
                    }
                    // parse XML, prepare body for writing
                    if ( res )
                    {
                        int len;
                        const char *data = read_file( s->src, &len );
                        if ( data != NULL )
                        {
                            res = scan_source( data, len, s );
                            free( (char*)data );
                        }
                    }
                }
                // save the files in a separate step
                userdata_write_files( s->user_data );
            }
        }
        else
            usage();
        stripper_dispose( s );
    }
	return 0;
}
示例#3
0
/*
 * Class:     calliope_AeseStripper
 * Method:    strip
 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLcalliope/json/JSONResponse;Lcalliope/json/JSONResponse;)I
 */
JNIEXPORT jint JNICALL Java_calliope_AeseStripper_strip
  (JNIEnv *env, jobject obj, jstring xml, jstring rules, jstring format, jstring style, jstring language, jstring hexcepts, jboolean html, jobject text, jobject markup)
{
	int res = 1;
    jboolean x_copied,r_copied=JNI_FALSE,f_copied,s_copied,h_copied,l_copied=JNI_FALSE;
    const char *x_str = load_string( env, xml, &x_copied );
    //fprintf(stderr,"x_str=%s r_str\n",x_str);
    const char *r_str = (rules!=NULL)?load_string(env,rules,&r_copied):NULL;
    //fprintf(stderr,"r_str=%s\n",r_str);
    const char *f_str = load_string( env, format, &f_copied );
    //fprintf(stderr,"f_str=%s\n",f_str);
    const char *s_str = load_string( env, style, &s_copied );
    //fprintf(stderr,"s_str=%s\n",s_str);
    const char *l_str = (language==NULL)?"en_GB"
        :load_string( env, language, &l_copied );
    //fprintf(stderr,"l_str=%s\n",l_str);
    const char *h_str = (hexcepts==NULL)?NULL
        :load_string( env, hexcepts, &h_copied );
    //fprintf(stderr,"h_str=%s\n",h_str);
    stripper *s = stripper_create();
    if ( s != NULL )
    {
        recipe *ruleset;
        s->hh_except_string = (h_str==NULL)?NULL:strdup(h_str);
        s->selected_format = lookup_format( f_str );
        // load or initialise rule set
        if ( rules == NULL )
            ruleset = recipe_new();
        else
            ruleset = recipe_load(r_str,strlen(r_str));
        hh_exceptions *hhe = hh_exceptions_create( s->hh_except_string );
        if ( hhe != NULL )
        {
            s->user_data = userdata_create( s->language, s->barefile, 
                ruleset, &formats[s->selected_format], hhe );
            if ( s->user_data != NULL )
            {
                // write header
                int i=0;
                while ( res && userdata_markup_dest(s->user_data,i)!= NULL )
                {
                    res = formats[s->selected_format].hfunc( NULL, 
                        dest_file_dst(
                            userdata_markup_dest(s->user_data,i)), s_str );
                    i++;
                }
                // parse XML
                if ( res )
                {
                    int xlen = strlen( x_str );
                    res = scan_source( x_str, xlen, s );
                    if ( res )
                        userdata_write_files( env, s->user_data, text, markup );
                }
                else
                    tmplog("write header failed\n");
            }
        }
        stripper_dispose( s );
        unload_string( env, xml, x_str, x_copied );
        unload_string( env, rules, r_str, r_copied );
        unload_string( env, format, f_str, f_copied );
        unload_string( env, style, s_str, s_copied );
        unload_string( env, language, l_str, l_copied );
        if ( h_str != NULL )
            unload_string( env, hexcepts, h_str, h_copied );
    }
    return res;
}