prg_preference_transform_arguments_get()

Abstract

Returns the arguments that were specified as part of the transformation in the Delta block as a list of strings.

Syntax

prg_preference_transform_arguments_get (data_ptr)
Argument Type Description
data_ptr PrgT_Preference_Transform_Data * Pointer to the applicable transformation being acted upon.

Return Type

PrgT_List *

Arguments specified in the delta block.

The returned list is owned by the function. It should not be modified or deallocated.

prg_env.h

Example

Example delta block for custom transformation function.

start_pref_delta
	preferences     : db.page_size, db.record_size
	transformation  : migration_example, rename_preference, db, database
end_pref_delta

Example code for custom transformation function.

This function should be defined in a library called "migration_example".

#include <math.h>
#include <stdlib.h>

#include "prg_env.h"
#include "prg_list_funcs.h"
#include "prg_mem_funcs.h"
#include "prg_string_funcs.h"

DLLEXPORT
PrgT_Preference_Transform_Status
rename_preference
		(PrgT_Preference_Transform_Data	* data_ptr)
	{
	PrgT_List		* source_values_lptr;
	PrgT_List		* arguments_lptr;
	const char		* search_string;
	const char		* replacement_string;
	const char		* source_tag;
	char			* destination_tag;
	const char		* search_string_loc;
	int			search_string_len;
	int			replacement_string_len;
	int			source_tag_len;
	int			destination_tag_len;
	int			size;
	char			* err_msg;

	/* Renames preferences based on the arguments */
	/* specified in a delta block.                */
	FIN (rename_preference);

	/* Get arguments specified in the delta block.    */
	/* First argument denotes the string to replaced, */
	/* the second one denotes the replacement string. */
	arguments_lptr =
	           prg_preference_transform_arguments_get (data_ptr);

	if (prg_list_size (arguments_lptr) < 2)
		{
		err_msg = prg_string_copy
			("Two arguments required for this transformation.");

		prg_preference_transform_error_message_set
			(data_ptr, err_msg);

		FRET (PrgC_Preference_Transform_Status_Failure);
		}

	search_string = prg_list_access (arguments_lptr, 0);
	replacement_string = prg_list_access (arguments_lptr, 1);
	source_tag = prg_preference_transform_tag_get (data_ptr);

	search_string_len = strlen (search_string);
	replacement_string_len = strlen (replacement_string);
	source_tag_len = strlen (source_tag);
	destination_tag_len =
	           source_tag_len - search_string_len + replacement_string_len;

	destination_tag = (char *) prg_mem_alloc (destination_tag_len + 1);

	if (destination_tag == PRGC_NIL)
		FRET (PrgC_Preference_Transform_Status_Failure);

	search_string_loc = strstr (source_tag, search_string);

	/* Rename the preference. */
	if (search_string_loc != NULL)
		{
		size = search_string_loc - source_tag;

		strncpy (destination_tag, source_tag, size);

		strncpy (destination_tag + size, replacement_string,
				replacement_string_len);

		size += replacement_string_len;
		strcpy (destination_tag + size,
				search_string_loc + search_string_len);

		prg_preference_transform_destination_tag_set
			(data_ptr, destination_tag);
		}

	/* Copy over the preference's value as-is. */
	source_values_lptr =
		prg_preference_transform_source_value_get (data_ptr);

	prg_preference_transform_destination_value_set
		(data_ptr, source_values_lptr);

	FRET (PrgC_Preference_Transform_Status_Success);
	}

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com