Beispiel #1
0
int main(int argc, char *argv[])
{
	// 这里简单处理参数,高级的处理自己百度 getopt 系列函数用法
	if (argc != 4 || strcmp(argv[2], "-t") != 0) {
		print_useage(argv[0]);
	} else {
		find_directory(argv[1], process_file, argv[3]);
		printf("Find Total : %d\n", file_count);
	}

	return EXIT_SUCCESS;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	long			i;
	enum {
		node_A,
		node_B,
		node_NONE
	}				which_node = node_NONE;
	int				retval = 1;
	haggle_handle_t	haggle_;
	
	// Check command line parameters to figure out which node this program is 
	// running on:
	for(i = 1; i < argc; i++)
	{
		if(strcmp(argv[i], "-A") == 0)
		{
			if(which_node == node_NONE)
				which_node = node_A;
			else{
				print_useage(
					(char *) "ERROR: do not supply more than one parameter "
					"to this program!",
					argv[0]);
				goto fail_param;
			}
		}else if(strcmp(argv[i], "-B") == 0)
		{
			if(which_node == node_NONE)
				which_node = node_B;
			else{
				print_useage(
					(char *) "ERROR: do not supply more than one parameter "
					"to this program!",
					argv[0]);
				goto fail_param;
			}
		}
	}
	
	if(which_node == node_NONE)
	{
		print_useage(
			(char *) "ERROR: You must supply one of the -A or -B command line "
			"parameters.\n",
			argv[0]);
		goto fail_param;
	}
	
	// Find Haggle:
	if(	haggle_handle_get("Haggle test 01 application", &haggle_) != 
			HAGGLE_NO_ERROR)
	{
		printf("ERROR: Haggle test application already running!\n");
		goto fail_haggle;
	}
	
	switch(which_node)
	{
		case node_A:
		{
			struct dataobject *dO;
			
			// Create a new data object:
			dO = haggle_dataobject_new();
			// Add the correct attribute:
			haggle_dataobject_add_attribute(dO, "Picture", "Bild1");
			// Make sure the data object is permanent:
			haggle_dataobject_set_flags(dO, DATAOBJECT_FLAG_PERSISTENT);
			// Put it into haggle:
			haggle_ipc_publish_dataobject(haggle_, dO);
		}
		break;
		
		case node_B:
			// Add the attribute to our interests:
			haggle_ipc_add_application_interest(
				haggle_, 
				"Picture", 
				"Bild1");
		break;
		
		default:
			printf("CODING ERROR: SHOULD NOT HAVE GOTTEN HERE!\n");
			goto fail_err;
		break;
	}
	
	// Make sure to return success:
	retval = 0;
	
fail_err:
	// Release the haggle handle:
	haggle_handle_free(haggle_);
fail_haggle:
fail_param:
	return retval;
}