layout_object_getvalue 子例程

用途

查询 LayoutObject 结构的当前布局值。

布局库 (libi18n.a)

语法

#include <sys/lc_layout.h> 
int layout_object_getvalue( layout_object,  values,  index)
LayoutObject layout_object;
LayoutValues values;
int *index;

描述

layout_object_getvalue 子例程查询 LayoutObject 结构中布局值的当前设置。 layout_object 参数指定由 layout_object_create 子例程创建的 LayoutObject 结构。

LayoutValues 结构的名称字段包含要查询的布局值的名称。 值字段是存储布局值的指针。 从 LayoutObject 结构查询值并表示其当前状态。

例如,如果要查询的布局值为类型 T ,那么 value 参数必须为类型 T*。 如果 T 本身是指针,那么 layout_object_getvalue 子例程分配空间以存储实际数据。 调用者必须通过使用返回的指针调用 free (T) 子例程来释放此数据。

设置值字段时,存在使用 layout_object_setvalue 参数不存在的额外的 indirection 级别。 设置类型为 T 的布局值时,值字段包含 T。 However, when querying the same layout value, the value field contains &T.

注: 如果要开发可能支持多字节语言环境的国际化应用程序,请参阅常规编程概念: 编写和调试程序 中的 使用 libcur 包

参数

描述
layout_object 指定由 layout_object_create 子例程创建的 LayoutObject 结构。
指定要在LayoutObject结构中查询的LayoutValueRec类型布局值数组。 数组的结尾由以下各项指示:name=0.
INDEX 指定要查询的布局值。 如果无法查询该值,那么将返回导致错误的 index 参数,并且子例程将返回非零值。

返回值

成功完成时, layout_object_getvalue 子例程返回值 0。 已成功查询所有布局值。

错误代码

如果 layout_object_getvalue 子例程失败,它将返回以下值:

描述
LAYOUT_EINVAL index 参数指定的布局值未知或 layout_object 参数无效。
LAYOUT_EMOMEM 存储空间不足。

示例

以下示例查询语言环境是否是双向的,并获取inout方向。

#include <sys/lc_layout.h>
#include <locale.h>
main()
{
LayoutObject plh;
int RC=0;
LayoutValues layout;
LayoutTextDescriptor Descr;
int index;

RC=layout_object_create(setlocale(LC_CTYPE,""),&plh); /* create object */
if (RC) {printf("Create error !!\n"); exit(0);}

layout=malloc(3*sizeof(LayoutValueRec));
                                         /* allocate layout array */
layout[0].name=ActiveBidirection;        /* set name */
layout[1].name=Orientation;              /* set name */
layout[1].value=(caddr_t)&Descr;
            /* send address of memory to be allocated by function */

layout[2].name=0;                     /* indicate end of array */
RC=layout_object_getvalue(plh,layout,&index);
if (RC) {printf("Getvalue error at %d !!\n",index); exit(0);}
printf("ActiveBidirection = %d \n",*(layout[0].value));
                                                    /*print output*/
printf("Orientation in = %x  out = %x \n", Descr->>in, Descr->>out);

free(layout);                        /* free layout array */
free (Descr);             /* free memory allocated by function */
RC=layout_object_free(plh);         /* free layout object */
if (RC) printf("Free error !!\n");
}