Example #1
0
int main(int argc, char **argv)
{
    int i, j, f = 0, cc = 0, r;
    unsigned char uc;
    unsigned short matches;

    int ncp = sizeof(codepages)/(sizeof(unsigned short*));

    int lte = 0; // encoding via lookup-table, if true

    // Check if chars in font are used in any codepages
    check_used(cp_common);
    for (j=0; j<ncp; j++)
    {
        check_used(codepages[j]);
    }

    // make lookup-table, return number of distinct bytes in font data
    lte = (font_make_lookuptable() < 128);

    printf("#ifndef GET_FONT_COMPRESSION_MODE\n\n");
    printf("// This is a compressed version of font_8x16_uni.h produced by the tools/font_8x16_pack program\n\n");
    printf("// Format of each character is 'FontData' structure, followed by FontData.size bytes of character data.\n\n");
    printf("static unsigned char font_data[] = {\n");

    for (i=0; orig_font_data[i].charcode != -1; i++)
    {
        if (orig_font_data[i].isUsed > 0)
        {
            int top = 0;
            int bottom = 0;
            for (j=0; j<16 && orig_font_data[i].data[j] == 0; j++) { top++; }
            for (j=15; j>=top && orig_font_data[i].data[j] == 0; j--) { bottom++; }
            if (top == 16)  // Blank character
            {
                // Fix values to fit into 4 bits each (sorted out in draw_char function)
                top--;
                bottom++;
            }

            char_codes[cc] = orig_font_data[i].charcode;
            font_offsets[cc] = f;
            cc++;
            matches = font_find_matching_glyph(i);
            if (matches != 65535)
            {
                printf("/*%04x == %04x*/", orig_font_data[i].charcode, orig_font_data[matches].charcode);
                font_offsets[cc-1] = font_find_offset(orig_font_data[matches].charcode);
            }
            else
            {

                font_data[f++] = (top << 4) | bottom;

                printf("/*%04x*/ 0x%02x,", orig_font_data[i].charcode, (top << 4) | bottom);
                r = f;
                for (j=top; j<16-bottom; j++)
                {
                    if (!lte)
                    {
                        font_data[f++] = orig_font_data[i].data[j] & 0xFF;
                        printf(" 0x%02x,",orig_font_data[i].data[j] & 0xFF);
                    }
                    else
                    {
                        // lookup-table based encoding
                        uc = orig_font_data[i].data[j] & 0xFF;
                        font_data[f] = fdata_usage[uc]; // byte's index in lookup table
                        if ( (j > top) && (font_data[f] == font_data[f-1]) )
                        {
                            // repetition found inside glyph data, set bit7 of previous byte
                            font_data[f-1] = font_data[f-1] | 0x80;
                        }
                        else
                        {
                            f++;
                        }
                    }
                }
                if (lte)
                {
                    for (j=r; j<f; j++)
                    {
                        printf(" 0x%02x,",font_data[j]);
                    }
                }
            }
            printf("\n");
        }
    }

    char_codes[cc] = 0xFFFF;

    printf("};\n\n");
    printf("// font_data length: %d bytes\n", f);

    if (lte)
    {
        printf("unsigned char fontdata_lookup[] = {\n    ");
        for (i=0; i<fontdata_ltlength; i++)
        {
            printf("0x%02x,", fontdata_lookup[i]);
            if ( ((i+1) & 0xf) == 0 )
            {
                printf("\n    ");
            }
        }
        printf("};\n");
        printf("// lookup table length: %d bytes\n\n", fontdata_ltlength);
#if 0
        printf("    /* font data byte distribution\n    ");
        for (i=0; i<256; i++)
        {
            printf("0x%02x,", fdata_usage[i]);
            if ( ((i+1) & 0xf) == 0 )
            {
                printf("\n    ");
            }
        }
        printf("*/\n\n");
#endif
    }

    // Set up codepage entries, and save to file
    font_init_data(cp_common, 0, 128);

    printf("// Offsets to font character data stored in the font_data array.\n\n");
    printf("static unsigned short cp_common[] =\n{\n");
    for (i=0; i<128; i++)
    {
        if ((i & 15) == 0) printf("    ");
        printf("0x%04x,", cp_common[i]);
        if ((i & 15) == 15) printf("\n");
    }
    printf("};\n");

    for (j=0; j<ncp; j++)
    {
        font_init_data(codepages[j], 0, 128);
        printf("static unsigned short cp_win_%s[] =\n{\n", cp_names[j]);
        for (i=0; i<128; i++)
        {
            if ((i & 15) == 0) printf("    ");
            printf("0x%04x,", codepages[j][i]);
            if ((i & 15) == 15) printf("\n");
        }
        printf("};\n");
    }

    printf("\n// Array of pointers to codepage tables.\n\n");
    printf("static unsigned short* codepages[] =\n{\n");
    for (j=0; j<ncp; j++)
    {
        printf("    cp_win_%s,\n", cp_names[j]);
    }
    printf("};\n");

    printf("\n// Codepage names for menu UI in gui.c (gui_font_enum).\n\n");
    printf("int num_codepages = %d;\n",ncp);
    printf("char* codepage_names[] =\n{\n");
    for (j=0; j<ncp; j++)
    {
        printf("    \"Win%s\",\n", cp_names[j]);
    }
    printf("};\n\n");
    printf("#endif // !GET_FONT_COMPRESSION_MODE\n\n");

    if (lte)
    {
        printf("#define BUILTIN_FONT_RLE_COMPRESSED 1\n\n");
    }

    return 0;
}
Example #2
0
int main(void)
{
	unsigned long long before;
	struct sigevent sevt;
	pthread_mutex_t mutex;
	pthread_cond_t cond;
	int fd, failed = 0;
	pthread_t thread;
	sem_t sem, *psem;
	timer_t tm;
	__maybe_unused pid_t child;

	mlockall(MCL_CURRENT|MCL_FUTURE);

	fprintf(stderr, "Checking for leaks in posix skin objects\n");
	before = get_used();
	check_pthread(pthread_create(&thread, NULL, empty, NULL));
	check_pthread(pthread_join(thread, NULL));
	sleep(1);		/* Leave some time for xnheap
				 * deferred free */
	check_used("thread", before, failed);

	before = get_used();
	check_pthread(pthread_mutex_init(&mutex, NULL));
	check_pthread(pthread_mutex_destroy(&mutex));
	check_used("mutex", before, failed);

	before = get_used();
	check_pthread(pthread_cond_init(&cond, NULL));
	check_pthread(pthread_cond_destroy(&cond));
	check_used("cond", before, failed);

	before = get_used();
	check_unix(sem_init(&sem, 0, 0));
	check_unix(sem_destroy(&sem));
	check_used("sem", before, failed);

	before = get_used();
	check_unix(-!(psem = sem_open(SEM_NAME, O_CREAT, 0644, 1)));
	check_unix(sem_close(psem));
	check_unix(sem_unlink(SEM_NAME));
	check_used("named sem", before, failed);

	before = get_used();
	sevt.sigev_notify = SIGEV_THREAD_ID;
	sevt.sigev_signo = SIGALRM;
	sevt.sigev_notify_thread_id = syscall(__NR_gettid);
	check_unix(timer_create(CLOCK_MONOTONIC, &sevt, &tm));
	check_unix(timer_delete(tm));
	check_used("timer", before, failed);

	before = get_used();
	check_unix(fd = mq_open(MQ_NAME, O_RDWR | O_CREAT, 0644, NULL));
	check_unix(mq_close(fd));
	check_unix(mq_unlink(MQ_NAME));
	check_used("mq", before, failed);

#ifdef HAVE_FORK
	before = get_used();
	check_unix(child = fork());
	if (!child) {
		subprocess_leak();
		return EXIT_SUCCESS;
	}
	while (waitpid(child, NULL, 0) == -1 && errno == EINTR);
	sleep(1);		/* Leave some time for xnheap
				 * deferred free */
	check_unix(sem_unlink(SEM_NAME));
	check_unix(mq_unlink(MQ_NAME));
	check_used("fork", before, failed);
#endif

	return failed ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #3
0
int main(void)
{
	unsigned long long before;
	struct sigevent sevt;
	pthread_mutex_t mutex;
	pthread_cond_t cond;
	int fd, failed = 0;
	pthread_t thread;
	sem_t sem, *psem;
	timer_t tm;
	void *shm;

	mlockall(MCL_CURRENT|MCL_FUTURE);

	fprintf(stderr, "Checking for leaks in posix skin objects\n");
	before = get_used();
	check_pthread(pthread_create(&thread, NULL, empty, NULL));
	check_pthread(pthread_join(thread, NULL));
	sleep(1);		/* Leave some time for xnheap
				 * deferred free */
	check_used("thread", before, failed);

	before = get_used();
	check_pthread(pthread_mutex_init(&mutex, NULL));
	check_pthread(pthread_mutex_destroy(&mutex));
	check_used("mutex", before, failed);

	before = get_used();
	check_pthread(pthread_cond_init(&cond, NULL));
	check_pthread(pthread_cond_destroy(&cond));
	check_used("cond", before, failed);

	before = get_used();
	check_unix(sem_init(&sem, 0, 0));
	check_unix(sem_destroy(&sem));
	check_used("sem", before, failed);

	before = get_used();
	check_unix(-!(psem = sem_open(SEM_NAME, O_CREAT, 0644, 1)));
	check_unix(sem_close(psem));
	check_unix(sem_unlink(SEM_NAME));
	check_used("named sem", before, failed);

	before = get_used();
	sevt.sigev_notify = SIGEV_SIGNAL;
	sevt.sigev_signo = SIGALRM;
	check_unix(timer_create(CLOCK_MONOTONIC, &sevt, &tm));
	check_unix(timer_delete(tm));
	check_used("timer", before, failed);

	before = get_used();
	check_unix(fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, 0644));
	check_unix(ftruncate(fd, SHM_SZ));
	shm = mmap(NULL, SHM_SZ, PROT_READ, MAP_SHARED, fd, 0);
	check_unix(shm == MAP_FAILED ? -1 : 0);
	check_unix(munmap(shm, SHM_SZ));
	check_unix(close(fd));
	check_unix(shm_unlink(SHM_NAME));
	check_used("shm", before, failed);

	before = get_used();
	check_unix(fd = mq_open(MQ_NAME, O_RDWR | O_CREAT, 0644, NULL));
	check_unix(mq_close(fd));
	check_unix(mq_unlink(MQ_NAME));
	check_used("mq", before, failed);

	return failed ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #4
0
int main(void)
{
	unsigned long long before;
	RT_ALARM nalrm;
	RT_BUFFER nbuf;
	RT_COND ncond;
	RT_EVENT nevt;
	RT_HEAP nheap;
	RT_MUTEX nmtx;
	RT_PIPE npipe;
	RT_QUEUE nq;
	RT_SEM nsem;
	RT_TASK ntsk;
	int failed = 0;

	mlockall(MCL_CURRENT|MCL_FUTURE);

	rt_print_auto_init(1);

	rt_fprintf(stderr, "Checking for leaks in native skin services\n");
	before = get_used();
	check_native(rt_alarm_create(&nalrm, NULL));
	check_native(rt_alarm_delete(&nalrm));
	check_used("alarm", before, failed);

	before = get_used();
	check_native(rt_buffer_create(&nbuf, NULL, 16384, B_PRIO));
	check_native(rt_buffer_delete(&nbuf));
	check_used("buffer", before, failed);

	before = get_used();
	check_native(rt_cond_create(&ncond, NULL));
	check_native(rt_cond_delete(&ncond));
	check_used("cond", before, failed);

	before = get_used();
	check_native(rt_event_create(&nevt, NULL, 0, EV_PRIO));
	check_native(rt_event_delete(&nevt));
	check_used("event", before, failed);

	before = get_used();
	check_native(rt_heap_create(&nheap, "heap", 16384, H_PRIO | H_SHARED));
	check_native(rt_heap_delete(&nheap));
	check_used("heap", before, failed);

	before = get_used();
	check_native(rt_mutex_create(&nmtx, NULL));
	check_native(rt_mutex_delete(&nmtx));
	check_used("mutex", before, failed);

	before = get_used();
	check_native(rt_pipe_create(&npipe, NULL, P_MINOR_AUTO, 0));
	check_native(rt_pipe_delete(&npipe));
	check_used("pipe", before, failed);

	before = get_used();
	check_native(rt_queue_create(&nq, "queue", 16384, Q_UNLIMITED, Q_PRIO));
	check_native(rt_queue_delete(&nq));
	check_used("queue", before, failed);

	before = get_used();
	check_native(rt_sem_create(&nsem, NULL, 0, S_PRIO));
	check_native(rt_sem_delete(&nsem));
	check_used("sem", before, failed);

	before = get_used();
	check_native(rt_task_spawn(&ntsk, NULL, 0, 1, T_JOINABLE, empty, NULL));
	check_native(rt_task_join(&ntsk));
	sleep(1);		/* Leave some time for xnheap
				 * deferred free */
	check_used("task", before, failed);

	return failed ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #5
0
int main(int argc, char **argv)
{
    int i, j, f = 0, cc = 0;

    int ncp = sizeof(codepages)/(sizeof(unsigned short*));
    
    // Check if chars in font are used in any codepages
    check_used(cp_common);
    for (j=0; j<ncp; j++)
    {
        check_used(codepages[j]);
    }

    printf("// This is a compressed version of font_8x16_uni.h produced by the tools/font_8x16_pack program\n\n");
    printf("// Format of each character is 'FontData' structure, followed by FontData.size bytes of character data.\n\n");
    printf("static unsigned char font_data[] = {\n");

    for (i=0; orig_font_data[i].charcode != -1; i++)
    {
        if (orig_font_data[i].isUsed > 0)
        {
            int top = 0;
            int bottom = 0;
            for (j=0; j<16 && orig_font_data[i].data[j] == 0; j++) { top++; }
            for (j=15; j>=top && orig_font_data[i].data[j] == 0; j--) { bottom++; }
            if (top == 16)  // Blank character
            {
                // Fix values to fit into 4 bits each (sorted out in draw_char function)
                top--;
                bottom++;
            }

            char_codes[cc] = orig_font_data[i].charcode;
            font_offsets[cc] = f;
            cc++;

            font_data[f++] = (top << 4) | bottom;

            printf("/*%04x*/ 0x%02x,", orig_font_data[i].charcode, (top << 4) | bottom);
            for (j=top; j<16-bottom; j++)
            {
                font_data[f++] = orig_font_data[i].data[j] & 0xFF;
                printf(" 0x%02x,",orig_font_data[i].data[j] & 0xFF);
            }
            printf("\n");
        }
    }

    char_codes[cc] = 0xFFFF;

    printf("};\n\n");

    // Set up codepage entries, and save to file
    font_init_data(cp_common, 0, 128);

    printf("// Offsets to font character data stored in the font_data array.\n\n");
    printf("static unsigned short cp_common[] =\n{\n");
    for (i=0; i<128; i++)
    {
        if ((i & 15) == 0) printf("    ");
        printf("0x%04x,", cp_common[i]);
        if ((i & 15) == 15) printf("\n");
    }
    printf("};\n");

    for (j=0; j<ncp; j++)
    {
        font_init_data(codepages[j], 0, 128);
        printf("static unsigned short cp_win_%s[] =\n{\n", cp_names[j]);
        for (i=0; i<128; i++)
        {
            if ((i & 15) == 0) printf("    ");
            printf("0x%04x,", codepages[j][i]);
            if ((i & 15) == 15) printf("\n");
        }
        printf("};\n");
    }

    printf("\n// Array of pointers to codepage tables.\n\n");
    printf("static unsigned short* codepages[] =\n{\n");
    for (j=0; j<ncp; j++)
    {
        printf("    cp_win_%s,\n", cp_names[j]);
    }
    printf("};\n");

    printf("\n// Codepage names for menu UI in gui.c (gui_font_enum).\n\n");
    printf("int num_codepages = %d;\n",ncp);
    printf("char* codepage_names[] =\n{\n");
    for (j=0; j<ncp; j++)
    {
        printf("    \"Win%s\",\n", cp_names[j]);
    }
    printf("};\n");

    return 0;
}