Exemple #1
0
void interpret_file(struct byte_array *path,
                    struct byte_array *args)
{
    struct byte_array *program;

    if (NULL != args)
    {
        struct byte_array *source = read_file(path, 0, 0);
        if (NULL == source)
            return;

        byte_array_append(args, source);
        program = build_string(args, path);
    }
    else
    {
        program = build_file(path);
    }

#ifdef DEBUG
    //display_program(program);
#endif

    execute(program);
    byte_array_del(program);
}
Exemple #2
0
//{{{void test_byte_array(void)
void test_byte_array(void)
{
    struct byte_array *ba = byte_array_init(3 * sizeof(uint32_t));
    TEST_ASSERT_EQUAL(0, ba->num);
    TEST_ASSERT_EQUAL(3 * sizeof(uint32_t), ba->size);

    uint64_t A[3] = {2,4,6};
    uint32_t B[3] = {1,2,3};

    byte_array_append(ba, A, 3*sizeof(uint64_t));
    TEST_ASSERT_EQUAL(3*sizeof(uint64_t), ba->num);

    byte_array_append(ba, B, 3*sizeof(uint32_t));
    TEST_ASSERT_EQUAL(3*sizeof(uint64_t) + 3*sizeof(uint32_t), ba->num);

    uint64_t *A_r = (uint64_t *)(ba->data);
    TEST_ASSERT_EQUAL(A[0], A_r[0]);
    TEST_ASSERT_EQUAL(A[1], A_r[1]);
    TEST_ASSERT_EQUAL(A[2], A_r[2]);

    uint32_t *B_r = (uint32_t *)(ba->data + 3*sizeof(uint64_t));
    TEST_ASSERT_EQUAL(B[0], B_r[0]);
    TEST_ASSERT_EQUAL(B[1], B_r[1]);
    TEST_ASSERT_EQUAL(B[2], B_r[2]);

    byte_array_append_zeros(ba, 5*sizeof(uint32_t));
    byte_array_append(ba, B, 3*sizeof(uint32_t));
    B_r = (uint32_t *)(ba->data + 3*sizeof(uint64_t));
    TEST_ASSERT_EQUAL(0,  B_r[3]);
    TEST_ASSERT_EQUAL(0,  B_r[4]);
    TEST_ASSERT_EQUAL(0,  B_r[5]);
    TEST_ASSERT_EQUAL(0,  B_r[6]);
    TEST_ASSERT_EQUAL(0,  B_r[7]);
    TEST_ASSERT_EQUAL(B[0], B_r[8]);
    TEST_ASSERT_EQUAL(B[1], B_r[9]);
    TEST_ASSERT_EQUAL(B[2], B_r[10]);

    byte_array_destory(&ba);
    TEST_ASSERT_EQUAL(NULL, ba);
}
Exemple #3
0
struct byte_array *byte_array_concatenate(int n, const struct byte_array* ba, ...)
{
    struct byte_array* result = byte_array_copy(ba);

    va_list argp;
    for(va_start(argp, ba); --n;) {
        struct byte_array* parameter = va_arg(argp, struct byte_array* );
        if (parameter == NULL)
            continue;
        assert_message(result->length + parameter->length < BYTE_ARRAY_MAX_LEN, ERROR_BYTE_ARRAY_LEN);
        byte_array_append(result, parameter);
    }

    va_end(argp);

    if (result)
        result->current = result->data + result->length;
    return result;
}
Exemple #4
0
void byte_array_push(struct byte_array *b, char ch)
{
    byte_array_append(b, &ch, 1);
}