Пример #1
0
void WorkerThread::run()
{
	if (content == nullptr) {
		return;
	}
	pmh_markdown_to_elements(content, pmh_EXT_NONE, &result);
}
int main(int argc, char * argv[])
{
	if (argc < 3) {
		printf("usage: %s [-s] [iterations] input_file\n", basename(argv[0]));
		printf("\n  -s = sort by position\n  Use - as input_file to read from stdin\n");
		return 0;
	}
	
	int iterations = atoi(argv[argc-2]);
	bool sort = (argc > 2 && strcmp(argv[1], "-s") == 0);
	
	FILE *stream = (strcmp(argv[argc-1], "-") == 0) ? stdin : fopen(argv[argc-1], "r");
	char *md_source = read_utf8(stream);
	
	double starttime = get_time();
	int i;
	for (i = 0; i < iterations; i++)
	{
		pmh_element **result;
		pmh_markdown_to_elements(md_source, pmh_EXT_NONE, &result);
		if (sort)
			pmh_sort_elements_by_pos(result);
	}
	double endtime = get_time();
	
	printf("%f\n", (endtime-starttime));
	
    return(0);
}
void *thread_run(void *arg)
{
    threadinfo *ti = (threadinfo *)arg;
    int i;
    for (i = 0; i < ti->iterations; i++)
    {
        int sleep_ms = (int)get_time() % 100;
        fprintf(stderr, "%s (iteration %i/%i, sleep %i ms after)\n",
                ti->name, i+1, ti->iterations, sleep_ms);
        
        pmh_element **result;
        pmh_markdown_to_elements(ti->md_content, pmh_EXT_NONE, &result);
        pmh_sort_elements_by_pos(result);
        
        char *this_results = elements_to_str(result);
        if (ti->results_str == NULL)
            ti->results_str = this_results;
        else
        {
            if (strcmp(this_results, ti->results_str) != 0)
            {
                fprintf(stderr, "ERROR! Thread %s results differ:\n\n"
                                "1st iteration results:\n%s\n"
                                "this iteration (#%i) results:\n%s\n",
                                ti->name, ti->results_str, i+1, this_results);
            }
            free(this_results);
        }
        
        pmh_free_elements(result);
        
        usleep(sleep_ms);
    }
    return NULL;
}
Пример #4
0
QVector<VElementRegion> VUtils::fetchImageRegionsUsingParser(const QString &p_content)
{
    Q_ASSERT(!p_content.isEmpty());
    QVector<VElementRegion> regs;

    QByteArray ba = p_content.toUtf8();
    const char *data = (const char *)ba.data();
    int len = ba.size();

    pmh_element **result = NULL;
    char *content = new char[len + 1];
    memcpy(content, data, len);
    content[len] = '\0';

    pmh_markdown_to_elements(content, pmh_EXT_NONE, &result);

    if (!result) {
        return regs;
    }

    pmh_element *elem = result[pmh_IMAGE];
    while (elem != NULL) {
        if (elem->end <= elem->pos) {
            elem = elem->next;
            continue;
        }

        regs.push_back(VElementRegion(elem->pos, elem->end));

        elem = elem->next;
    }

    pmh_free_elements(result);

    return regs;
}
void WorkerThread::run()
{
    if (content == NULL)
        return;
    pmh_markdown_to_elements(content, pmh_EXT_NONE, &result);
}