Пример #1
0
static int analyze_args_exp(NODE* expp , FieldList * arg){
	NODE* exp = expp->child_head;
	int errno = 0;
	while(arg != NULL){
		if(exp != NULL && exp->name == nonterminal_name[Exp]){
			Type* ttype ;
			ttype = analyze_exp(exp) ;
			if(ttype->kind != arg->type->kind){
				error("unmatched argument type",9,exp->line);
				errno = 1;
			}else{
				if(ttype->kind == BASIC_TYPE){
					if(ttype->u.basic != ttype->u.basic){
						error("unmatched argument type:one is INT the other is FLOAT",9,exp->line);
						errno = 1 ;
					}
				}else if(ttype->kind == ARRAY_TYPE){
					errno = error_argument_array_struct(cmp_array(arg->type,ttype),exp->line) ;
				}else if(ttype->kind == STRUCTURE_TYPE){
					errno = error_argument_array_struct(cmp_array(arg->type,ttype),exp->line) ;
				}
			}
		}else{
			error("too few arguments in \'(\' \')\'",9,expp->line);
			errno = 1;
			break ;
		}
		if(arg = arg->tail ) {
			if((exp = exp->next_sister) && (exp = exp->next_sister) && (exp = exp->child_head)){
				continue ;
			}
			exp = NULL ;
		}
	}
	if(exp && (exp = exp->next_sister)&&(exp = exp->next_sister)&&(exp = exp->child_head)){
		error("too many arguments",9,exp->line);
	}
	return errno ;
}
int tests_SparseArray_copy(int test_number) {
    int n_tests = 8;

    // If test_number is out of range, then...
    if(test_number < 0 || test_number >= n_tests) {
        //return how many distinct test-cases we have.
        return n_tests; 
    }

    // Assume failure unless otherwise noted
    int success = FALSE;

    printf("Testing: SparseNode_copy(a%d)\n", test_number);
    SparseNode * orig_node = NULL;
    SparseNode * sol_node = NULL;
    SparseNode * stu_node = NULL;

    //build the array to be copied
    orig_node = make_array(test_number);

    printf("Built array a%d:\n", test_number);
    print_array(orig_node, 0);

    printf("Copy Node:\n");
    sol_node = SparseArray_copy_sol(orig_node);
    stu_node = SparseArray_copy(orig_node);
    printf("Student result after copy:\n");
    print_array(stu_node, 0);
    printf("Solution result after copy:\n");
    print_array(sol_node, 0);

    printf("Checking if result tree is the same...\n");
    if(cmp_array(stu_node, sol_node)) {
        success = TRUE;
    }

    // Cleanup
    if(orig_node) {
        SparseArray_destroy_sol(orig_node);
    }
    if(sol_node) {
        SparseArray_destroy_sol(sol_node);
    }
    if(stu_node) {
        SparseArray_destroy_sol(stu_node);
    }
    return success;
}
int tests_SparseArray_insert(int test_number) {
    const int indices[] = {4,1,0,40000,6,30,2,5,4};
    const int values[] = {30,22,100,3,5,-7,-30,0,20};

    int sparseArrayLen = sizeof(indices) / sizeof(int);

    // If test_number is out of range, then...
    if(test_number < 0 || test_number >= sparseArrayLen) {
        //return how many distinct test-cases we have.
        return sparseArrayLen; 
    }

    // Assume failure unless otherwise noted
    int success = FALSE;
    
    const int ind = indices[test_number];
    const int val = values[test_number];

    printf("Testing: SparseNode_insert(array, %d, %d)\n", ind, val);
    SparseNode * stu_node = NULL;
    SparseNode * sol_node = NULL;
    int i;
    for(i = 0; i < test_number+1; i++) {
        stu_node = SparseArray_insert(stu_node, indices[i], values[i]);
        sol_node = SparseArray_insert_sol(sol_node, indices[i], values[i]);
    }

    printf("Student result:\n");
    print_array(stu_node, 0);
    printf("Solution result:\n");
    print_array(sol_node, 0);

    if(cmp_array(stu_node, sol_node)){
        success = TRUE;
    }

    // Cleanup
    if(stu_node) {
        SparseArray_destroy_sol(stu_node);
    }
    if(sol_node) {
        SparseArray_destroy_sol(sol_node);
    }
    return success;
}
Пример #4
0
Файл: data.c Проект: amba/pdfout
int
pdfout_data_cmp (fz_context *ctx, pdfout_data *x, pdfout_data *y)
{
  if (x->type != y->type)
    return 1;
  if (x->type == ARRAY)
    return cmp_array (ctx, x, y);
  else if (x->type == HASH)
    return cmp_hash (ctx, x, y);

  data_scalar *a = to_scalar (ctx, x);
  data_scalar *b = to_scalar (ctx, y); 

  if (a->len == b->len && memcmp (a->value, b->value, a->len) == 0)
    return 0;
  else
    return 1;
}
Пример #5
0
SInt64 JSON::cmp_object(const JSON& a, const JSON& b)
{
	return cmp_array(a,b);
}
Пример #6
0
SInt64 JSON::comparef(const JSON& a, const JSON& b)
{
	switch (a.m_type)
	{
	case e_null: 
		switch (b.m_type)
		{
			case e_null: return cmp_null(a,b);
			case e_bool: return cmp_bool(a,b);
			case e_integer: return cmp_integer(a,b);
			case e_real: return cmp_real(a,b);
			case e_string: return cmp_string(a,b);
			case e_array: return cmp_array(a,b);
			case e_object: return cmp_object(a,b);
		}

	case e_bool:
		switch (b.m_type)
		{
			case e_null: return cmp_bool(a,b);
			case e_bool: return cmp_bool(a,b);
			case e_integer: return cmp_integer(a,b);
			case e_real: return cmp_real(a,b);
			case e_string: return cmp_string(a,b);
			case e_array: return cmp_array(a,b);
			case e_object: return cmp_object(a,b);
		}

	case e_integer:
		switch (b.m_type)
		{
			case e_null: return cmp_integer(a,b);
			case e_bool: return cmp_integer(a,b);
			case e_integer: return cmp_integer(a,b);
			case e_real: return cmp_real(a,b);
			case e_string: return cmp_string(a,b);
			case e_array: return cmp_array(a,b);
			case e_object: return cmp_object(a,b);
		}

	case e_real:
		switch (b.m_type)
		{
			case e_null: return cmp_real(a,b);
			case e_bool: return cmp_real(a,b);
			case e_integer: return cmp_real(a,b);
			case e_real: return cmp_real(a,b);
			case e_string: return cmp_string(a,b);
			case e_array: return cmp_array(a,b);
			case e_object: return cmp_object(a,b);
		}

	case e_string:
		switch (b.m_type)
		{
			case e_null: return cmp_string(a,b);
			case e_bool: return cmp_string(a,b);
			case e_integer: return cmp_string(a,b);
			case e_real: return cmp_string(a,b);
			case e_string: return cmp_string(a,b);
			case e_array: return cmp_array(a,b);
			case e_object: return cmp_object(a,b);
		}

	case e_array:
		switch (b.m_type)
		{
			case e_null: return cmp_array(a,b);
			case e_bool: return cmp_array(a,b);
			case e_integer: return cmp_array(a,b);
			case e_real: return cmp_array(a,b);
			case e_string: return cmp_array(a,b);
			case e_array: return cmp_array(a,b);
			case e_object: return cmp_object(a,b);
		}

	case e_object:
		switch (b.m_type)
		{
			case e_null: return cmp_object(a,b);
			case e_bool: return cmp_object(a,b);
			case e_integer: return cmp_object(a,b);
			case e_real: return cmp_object(a,b);
			case e_string: return cmp_object(a,b);
			case e_array: return cmp_object(a,b);
			case e_object: return cmp_object(a,b);
		}
	}

	Check();
	return -1;
}
Пример #7
0
Файл: mail.c Проект: wtj/formosa
/*
 * user can modify his list for grouply mail sending
 */
static int
set_group()
{
	char strName[STRLEN];
	int num_send = 0;

	clear();

	prints(_msg_max_group, MAX_MAILGROUPS);

	for (;;)
	{
		/* show the list for grouply mail sending */
		show_array(mgatop);

		getdata(1, 0, _msg_ask_group_add, genbuf, 2, ECHONOSP | LOWCASE, NULL);
		switch (genbuf[0])
		{
		case 'a':
			if (num_send >= MAX_MAILGROUPS)
			{
				prints(_msg_mail_group_max_prompt, MAX_MAILGROUPS);
				getkey();
			}
			else
			{
				if (getdata(2, 0, _msg_receiver, strName, sizeof(strName),
					    ECHONOSP, NULL))
				{
#if EMAIL_LIMIT
					if (curuser.ident != 7 && strchr(strName, '@'))
					{
						prints("\n%s", _msg_sorry_email);
						clrtoeol();
						getkey();
					}
					else
#endif
					if (strchr(strName, '@') || get_passwd(NULL, strName) > 0)
					{
						if (!cmp_array(mgatop, strName, strcmp))
						{
							add_array(mgatop, strName, malloc_str);
							num_send++;
						}
					}
				}
			}
			break;
		case 'f':
			{
				int i;

				load_friend(&friend_cache, curuser.userid);

				for (i = 0; i < friend_cache->number; i++)
				{
					if (!friend_cache->datap[i])
						continue;

					if (num_send >= MAX_MAILGROUPS)
					{
						prints(_msg_mail_group_max_prompt, MAX_MAILGROUPS);
						getkey();
						break;
					}

					if (!cmp_array(mgatop, friend_cache->datap[i], strcmp))
					{
						add_array(mgatop, friend_cache->datap[i], malloc_str);
						num_send++;
					}
				}
			}
			break;
		case 'd':
			if (getdata(2, 0, _msg_delete, genbuf, IDLEN, ECHONOSP, NULL))
			{
				mgatop = cmpd_array(mgatop, genbuf, strcmp);
				num_send--;
			}
			break;
		case 'q':
			return -1;
		case 'e':
		default:
			if (num_send == 0)
				return -1;
			clrtobot();
			return 0;
		}
	}
}
Пример #8
0
int verify(){

	int i = 0;
	int errNo = 0;

	//key {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
	char expectedOutput[] = {
            0x12,0x29,0xbd,0x07,0xcb,0xa7,0x82,0xa4,0x6c,0x4c,0xb0,0x37,0x49,0x3d,0xbf,0x44,
            0x19,0x80,0x66,0xa7,0xa7,0x33,0x8d,0xd0,0x28,0x88,0x5e,0x20,0xfc,0xa0,0xfb,0x60,
            0xd2,0x2f,0x85,0x59,0x12,0x42,0xd7,0x22,0xdc,0x83,0x45,0x4f,0x3a,0xfa,0x7d,0xe0,
            0x56,0x07,0x03,0xd9,0xe8,0x21,0xe6,0xfe,0x84,0x5c,0x5a,0x49,0x2a,0x61,0xca,0x6b,
            0xa4,0xf7,0x1f,0xb0,0x78,0x5d,0x48,0x8c,0xb1,0x71,0x5a,0x83,0xc8,0xa7,0x4f,0x5d,
            0x8e,0x19,0xc0,0x51,0x14,0x81,0xca,0xad,0xd5,0x31,0xed,0x1c,0xb4,0xc7,0xf7,0x0a,
            0xbb,0xf5,0x82,0xba,0x30,0xda,0x1c,0xd9,0x73,0x27,0x51,0xd2,0xee,0x0a,0x50,0x87,
            0xc1,0x37,0x38,0xa3,0x91,0x30,0xe0,0x92,0x5a,0x2a,0x52,0xa8,0x93,0x20,0xa4,0x39,
            0xbb,0x26,0x78,0xb0,0x38,0x1a,0x31,0x30,0x2e,0x24,0x3a,0x92,0xca,0x99,0x81,0xb0,
            0xad,0xb9,0xf3,0x51,0x6b,0x7e,0x23,0x9f,0x18,0x75,0x5d,0x55,0xf2,0x87,0x8f,0xe0,
            0x82,0xa7,0xbc,0x12,0xb9,0x12,0x61,0xc8,0x38,0xe2,0x26,0x5f,0x2a,0x2d,0xb0,0x72,
            0x1e,0x51,0xed,0xec,0x9f,0xdd,0xfa,0x4e,0x1c,0x8c,0x91,0xcf,0x5e,0x1c,0xfa,0x54,
            0x5a,0xc9,0x95,0xcd,0x0f,0x93,0x6f,0x66,0x18,0xde,0x81,0x9f,0xa0,0x61,0x65,0xfa};

	
	UCHAR expandkey[BLOCK_SIZE * 11]= {
			0x16,0x15,0x7e,0x2b,0xa6,0xd2,0xae,0x28, 0x88,0x15,0xf7,0xab,0x3c,0x4f,0xcf,0x09,
			0xa8,0xf9,0x14,0xd0,0x89,0x25,0xee,0xc9, 0xc8,0x0c,0x3f,0xe1,0xa6,0x0c,0x63,0xb6,
			0x63,0x5a,0x7b,0x0c,0xfe,0xea,0x19,0x13, 0x90,0x88,0x39,0xb0,0xb4,0xfb,0x4c,0x66,
			0x5a,0x92,0x7d,0xdf,0x9d,0xb0,0x62,0x1f, 0x6e,0x62,0x20,0xa3,0x24,0x73,0x75,0xd6,
			0x47,0x76,0xc0,0x12,0xc7,0x22,0x1f,0xc0, 0xf3,0xd2,0x42,0xbc,0x4a,0x11,0x55,0x75,
			0x76,0xd8,0xfc,0x6e,0x80,0x54,0xdf,0xd2, 0x34,0xf0,0x5d,0x7c,0xb9,0xc3,0x17,0xc9,
			0xfc,0x0a,0xa3,0x6e,0xf6,0x8c,0x23,0xbc, 0xb4,0xa4,0x82,0xae,0x8d,0x33,0x4a,0xb5,
			0x13,0x44,0x88,0x90,0x0a,0x86,0x80,0xd2, 0x42,0x28,0xa1,0x12,0x39,0x97,0xc8,0x1b,
			0xf7,0x13,0x1f,0x7c,0x19,0xc2,0x08,0x42, 0x48,0xae,0x21,0xc0,0x7b,0xbf,0x69,0x09,
			0xeb,0x05,0x75,0xcc,0xee,0xd1,0x17,0x3e, 0x51,0x6c,0x29,0x82,0x33,0x11,0x48,0xc9,
			0xa7,0x08,0x37,0x2b,0x05,0xd4,0x62,0xf2, 0xbf,0xbd,0x3e,0xbc,0x62,0x7d,0x61,0x4b};

	UCHAR iv[BLOCK_SIZE]= {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};

	UCHAR input[BLOCK_SIZE * 13];
	UCHAR output[BLOCK_SIZE * 13];
	size_t length = BLOCK_SIZE * 13;

	for (i=0; i < length; i++) {
        input[i] = (UCHAR) ('a' + i % 26);
    }

    UCHAR newIV[BLOCK_SIZE];
    for (i = 0; i < BLOCK_SIZE; ++i) {
    	newIV[i] = iv[i];
    }
	int retLen = aes_cbc_decrypt_old(input, output, expandkey, newIV, length, 128);
	errNo = cmp_array(output, expectedOutput, length);

	if(!errNo) {
		printf("(old version) sanity test passed.\n");
	} else {
		printf("(old version) sanity test failed!\n");
		return errNo;
	}

	for (i = 0; i < BLOCK_SIZE; ++i) {
    	newIV[i] = iv[i];
    }
	aes_cbc_decrypt(input, output, expandkey, newIV, length, 128);
	errNo = cmp_array(output, expectedOutput, length);

	if(!errNo) {
		printf("(new version) sanity test passed.\n");
	} else {
		printf("(new version) sanity test failed!\n");
	}

	return errNo;
}
Пример #9
0
int main()
{
    cmp_array();
    cmp_vector();

}