Exemplo n.º 1
0
/**
    \fn cmd_apply_xsl
**/
inline void cmd_apply_xsl(Trie* trie) {
    debug("void apply_xsl(Trie* trie)");
    /**
        Тут важно помнить в каком порядке
        мы принимаем аргументы от адаптера
        Сначала xsl потом doc
    **/
    xsp_t xsl = get_xsl(trie);
    xdp_t doc = get_doc();
    apply(xsl, doc);
    free_xdp(doc);
}
Exemplo n.º 2
0
bool Entity::get_prototype(char *buf, int bufsz) {
	E_RETURN_VAL_IF_FAIL(name != NULL, false);
	E_RETURN_VAL_IF_FAIL(tp != ENTITY_NONE, false);

	String ret;
	if(args.empty()) {
		ret = "void ";
		ret += name;
		ret += " ()";
	} else {
		if(tp == ENTITY_PROPERTY) {
			/* we should only get single argument */
			if(args.size() != 1) {
				E_WARNING(E_STRLOC ": Property should have only one type, but got '%i'. Using first one only...\n", args.size());
			} else {

				ArgSignatureListIt it = args.begin();
				signature_to_readable((*it)->sig, ret);

				ret += ' ';
				ret += name;

				/* write kind of access */
				if((*it)->access) {
					ret += " access: ";
					ret += (*it)->access;
				}
			}
		} else {
			ArgSignatureListIt it = args.begin(), ite = args.end();

			/* default */
			ret = "void";

			/* return type */
			for(; it != ite; ++it) {
				if((*it)->direction == DIRECTION_OUT) {
					signature_to_readable((*it)->sig, ret);
					break;
				}
			}

			/* name */
			ret += ' ';
			ret += name;

			/* arguments */
			ret += "(";

			String tmp;
			bool   have_something = false;

			for(it = args.begin(); it != ite; ++it) {
				/* AFAIK only 'direction=out' is explicitly set */
				if((*it)->direction != DIRECTION_OUT) {
					/* so we can correctly watch adding commas */
					if(have_something) ret += ", ";

					signature_to_readable((*it)->sig, tmp);
					ret += tmp;
					ret += ' ';
					ret += (*it)->name;
					have_something = true;
				}
			}
			ret += ')';
		}
	}

	if(!ret.empty()) {
		/* append documentation if have */
		if(get_doc()) {
			ret += "\n";
			ret += get_doc();
		}

		edelib_strlcpy(buf, ret.c_str(), bufsz);
		return true;
	}

	return false;
}
Exemplo n.º 3
0
static int
run(int validate_utf8)
{
    long long times = 0; 
    double starttime;
    unsigned long long sumsize = 0;

    starttime = mygettime();

    /* allocate a parser */
    for (;;) {
		int i;
        {
            double now = mygettime();
            if (now - starttime >= PARSE_TIME_SECS) break;
        }

        for (i = 0; i < 100; i++) {
            yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
            yajl_status stat;        
            const char ** d;

            yajl_config(hand, yajl_dont_validate_strings, validate_utf8 ? 0 : 1);

            for (d = get_doc(times % num_docs()); *d; d++) {
                size_t size = strlen(*d);
                sumsize += size;
                stat = yajl_parse(hand, (unsigned char *) *d, size);
                if (stat != yajl_status_ok) break;
            }
            
            stat = yajl_complete_parse(hand);

            if (stat != yajl_status_ok) {
                unsigned char * str =
                    yajl_get_error(hand, 1,
                                   (unsigned char *) *d,
                                   (*d ? strlen(*d) : 0));
                fprintf(stderr, "%s", (const char *) str);
                yajl_free_error(hand, str);
                return 1;
            }
            yajl_free(hand);
            times++;
        }
    }

    /* parsed doc 'times' times */
    {
        double throughput;
        double now;
        const char * all_units[] = { "B/s", "KB/s", "MB/s", (char *) 0 };
        const char ** units = all_units;

        now = mygettime();

        throughput = sumsize / (now - starttime);
        
        while (*(units + 1) && throughput > 1024) {
            throughput /= 1024;
            units++;
        }
        
        printf("Parsing speed: %g %s\n", throughput, *units);
    }

    return 0;
}