Init
This commit is contained in:
67
usr.lib/libsunwindow/attr/Makefile
Normal file
67
usr.lib/libsunwindow/attr/Makefile
Normal file
@@ -0,0 +1,67 @@
|
||||
#
|
||||
# @(#)Makefile 94/10/31 1.1 SMI
|
||||
#
|
||||
WHOAMI= attr
|
||||
#HDRSPUBLIC= attr.h
|
||||
#HDRSPRIVATE = attr_impl.h
|
||||
CFILESLIB= attr.c attr_copy.c attr_cu.c attr_util.c
|
||||
SPCFILESLIB= attr.c
|
||||
OBJS = $(CFILESLIB:%.c=$(VARIANT)/%.o)
|
||||
TAGFILESALL= ${FULLPATH}/attr.c ${FULLPATH}/attr_copy.c \
|
||||
${FULLPATH}/attr_cu.c ${FULLPATH}/attr.h \
|
||||
${FULLPATH}/attr_util.c
|
||||
|
||||
all: xall
|
||||
|
||||
#include common stuff from ../Makefile.master
|
||||
include ../Makefile.master
|
||||
|
||||
xall : $$(LIBS)
|
||||
$(LIBS): $$(VARIANT) $(HDRSPUBLIC) $(HDRSPRIVATE) $$(OBJS)
|
||||
|
||||
$(SPCFILESLIB:%.c=obj/%.o) \
|
||||
$(SPCFILESLIB:%.c=obj_p/%.o) \
|
||||
$(SPCFILESLIB:%.c=shared/%.o) := ROI_DATA =
|
||||
|
||||
attr.o: attr.c /usr/include/stdio.h attr_impl.h \
|
||||
${INCLUDE}/sys/types.h \
|
||||
${INCLUDE}/sys/sysmacros.h \
|
||||
/usr/include/varargs.h \
|
||||
${INCLUDE}/sunwindow/attr.h \
|
||||
${INCLUDE}/sunwindow/sun.h
|
||||
attr_copy.o: attr_copy.c ${INCLUDE}/sys/types.h \
|
||||
${INCLUDE}/sys/sysmacros.h \
|
||||
${INCLUDE}/sunwindow/attr.h
|
||||
attr_cu.o: attr_cu.c \
|
||||
${INCLUDE}/pixrect/pixrect_hs.h \
|
||||
${INCLUDE}/sys/types.h \
|
||||
${INCLUDE}/sys/sysmacros.h \
|
||||
${INCLUDE}/pixrect/pixrect.h \
|
||||
${INCLUDE}/pixrect/pr_planegroups.h \
|
||||
${INCLUDE}/pixrect/pr_util.h \
|
||||
${INCLUDE}/pixrect/bw1var.h \
|
||||
${INCLUDE}/pixrect/cg1var.h \
|
||||
${INCLUDE}/pixrect/bw2var.h \
|
||||
${INCLUDE}/pixrect/cg2var.h \
|
||||
${INCLUDE}/pixrect/gp1var.h \
|
||||
${INCLUDE}/pixrect/cg4var.h \
|
||||
${INCLUDE}/pixrect/memvar.h \
|
||||
${INCLUDE}/pixrect/pixfont.h \
|
||||
${INCLUDE}/pixrect/traprop.h \
|
||||
${INCLUDE}/pixrect/pr_line.h \
|
||||
${INCLUDE}/rasterfile.h \
|
||||
${INCLUDE}/pixrect/pr_io.h \
|
||||
${INCLUDE}/sunwindow/attr.h \
|
||||
${INCLUDE}/sunwindow/sun.h \
|
||||
/usr/include/stdio.h
|
||||
attr_portable.o: attr_portable.c attr_impl.h \
|
||||
${INCLUDE}/sys/types.h \
|
||||
${INCLUDE}/sys/sysmacros.h \
|
||||
/usr/include/varargs.h \
|
||||
${INCLUDE}/sunwindow/attr.h
|
||||
attr_util.o: attr_util.c ${INCLUDE}/sys/types.h \
|
||||
${INCLUDE}/sys/sysmacros.h \
|
||||
/usr/include/varargs.h \
|
||||
${INCLUDE}/sunwindow/attr.h
|
||||
|
||||
clean: master.clean
|
||||
411
usr.lib/libsunwindow/attr/attr.c
Normal file
411
usr.lib/libsunwindow/attr/attr.c
Normal file
@@ -0,0 +1,411 @@
|
||||
#ifndef lint
|
||||
#ifdef sccs
|
||||
static char sccsid[] = "@(#)attr.c 1.1 94/10/31";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright (c) 1986 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sunwindow/attr_impl.h>
|
||||
#include <sunwindow/sun.h>
|
||||
#include <sunwindow/sv_malloc.h>
|
||||
|
||||
/* Note that changes to the basic attribute-value traversal
|
||||
* should also be made in attr_portable.c for portable implmentations.
|
||||
*/
|
||||
|
||||
|
||||
/* attr_create creates an avlist from the VARARGS passed
|
||||
* on the stack.
|
||||
*/
|
||||
/*VARARGS2*/
|
||||
Attr_avlist
|
||||
attr_create(listhead, listlen, va_alist)
|
||||
caddr_t *listhead;
|
||||
int listlen;
|
||||
va_dcl
|
||||
{
|
||||
Attr_avlist avlist;
|
||||
va_list valist;
|
||||
|
||||
va_start(valist);
|
||||
avlist = attr_make(listhead, listlen, valist);
|
||||
va_end(valist);
|
||||
return avlist;
|
||||
}
|
||||
|
||||
|
||||
/* attr_make copies the attribute-value list pointed to by valist to
|
||||
* the storage pointed to by listhead, or some new storage if that is
|
||||
* null. If listhead is not null, then the list must be less than or equal
|
||||
* to listlen ATTR_SIZE byte chunks; if not 0 is returned.
|
||||
* The count of the avlist is returned in *count_ptr, if count_ptr is
|
||||
* not NULL.
|
||||
*/
|
||||
Attr_avlist
|
||||
attr_make_count(listhead, listlen, valist, count_ptr)
|
||||
Attr_avlist listhead;
|
||||
int listlen;
|
||||
va_list valist;
|
||||
int *count_ptr;
|
||||
{
|
||||
u_int count;
|
||||
|
||||
#ifdef NON_PORTABLE
|
||||
count = (u_int) (LINT_CAST(attr_count((Attr_avlist) valist)));
|
||||
#else
|
||||
count = (u_int) (LINT_CAST(valist_count(valist)));
|
||||
#endif
|
||||
/* if the user supplied storage space for attributes is not big enough
|
||||
* for the attributes in the attribute list, then exit!
|
||||
*/
|
||||
if (listhead) {
|
||||
if (count > listlen) {
|
||||
printf("Number of attributes(%d) in the attr list exceeds\n",count);
|
||||
printf("the maximum number(%d) specified. Exit!\n",listlen);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
listhead = (Attr_avlist) (LINT_CAST(sv_malloc((ATTR_SIZE * count)+1)));
|
||||
}
|
||||
#ifdef NON_PORTABLE
|
||||
(void) attr_copy_avlist(listhead, (Attr_avlist) (LINT_CAST(valist)));
|
||||
#else
|
||||
(void) attr_copy_valist(listhead, valist);
|
||||
#endif
|
||||
|
||||
if (count_ptr)
|
||||
*count_ptr = count;
|
||||
return(listhead);
|
||||
}
|
||||
|
||||
|
||||
#define avlist_get(avlist) *(avlist)++
|
||||
|
||||
/* Copy count elements from list to dest.
|
||||
* Advance both list and dest to the next element after
|
||||
* the last one copied.
|
||||
*/
|
||||
#define avlist_copy(avlist, dest, count) \
|
||||
{ \
|
||||
bcopy((char *) avlist, (char *) dest, (int)(count * ATTR_SIZE)); \
|
||||
avlist += count; \
|
||||
dest += count; \
|
||||
}
|
||||
|
||||
|
||||
/* A macro to copy attribute values
|
||||
* count is the number of caddr_t size chunks to copy.
|
||||
*/
|
||||
#define avlist_copy_values(avlist, dest, count) \
|
||||
if (count == 1) \
|
||||
*dest++ = avlist_get(avlist); \
|
||||
else { \
|
||||
avlist_copy(avlist, dest, count); \
|
||||
}
|
||||
|
||||
|
||||
/* attr_copy_avlist copies the attribute-value list from
|
||||
* avlist to dest. Recursive lists are collapsed into dest.
|
||||
*/
|
||||
|
||||
Attr_avlist
|
||||
attr_copy_avlist(dest, avlist)
|
||||
register Attr_avlist dest;
|
||||
register Attr_avlist avlist;
|
||||
{
|
||||
register Attr_attribute attr;
|
||||
register u_int cardinality;
|
||||
|
||||
while (attr = (Attr_attribute) avlist_get(avlist)) {
|
||||
cardinality = ATTR_CARDINALITY(attr);
|
||||
switch(ATTR_LIST_TYPE(attr)) {
|
||||
case ATTR_NONE: /* not a list */
|
||||
*dest++ = (caddr_t) attr;
|
||||
avlist_copy_values(avlist, dest, cardinality);
|
||||
break;
|
||||
|
||||
case ATTR_NULL: /* null terminated list */
|
||||
*dest++ = (caddr_t) attr;
|
||||
switch (ATTR_LIST_PTR_TYPE(attr)) {
|
||||
case ATTR_LIST_IS_INLINE:
|
||||
/* Note that this only checks the first four bytes
|
||||
* for the null termination.
|
||||
* Copy each value element until we have copied the
|
||||
* null termination.
|
||||
*/
|
||||
do {
|
||||
avlist_copy_values(avlist, dest, cardinality);
|
||||
} while (*(dest - 1));
|
||||
break;
|
||||
|
||||
case ATTR_LIST_IS_PTR:
|
||||
*dest++ = avlist_get(avlist);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ATTR_COUNTED: /* counted list */
|
||||
*dest++ = (caddr_t) attr;
|
||||
switch (ATTR_LIST_PTR_TYPE(attr)) {
|
||||
case ATTR_LIST_IS_INLINE: {
|
||||
register u_int count;
|
||||
|
||||
*dest = avlist_get(avlist); /* copy the count */
|
||||
count = ((u_int) *dest++) * cardinality;
|
||||
avlist_copy_values(avlist, dest, count);
|
||||
}
|
||||
break;
|
||||
|
||||
case ATTR_LIST_IS_PTR:
|
||||
*dest++ = avlist_get(avlist);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ATTR_RECURSIVE: /* recursive attribute-value list */
|
||||
if (cardinality != 0) /* don't strip it */
|
||||
*dest++ = (caddr_t) attr;
|
||||
|
||||
switch (ATTR_LIST_PTR_TYPE(attr)) {
|
||||
case ATTR_LIST_IS_INLINE:
|
||||
dest = attr_copy_avlist(dest, avlist);
|
||||
if (cardinality != 0) /* don't strip it */
|
||||
dest++; /* move past the null terminator */
|
||||
avlist = attr_skip(attr, avlist);
|
||||
break;
|
||||
|
||||
case ATTR_LIST_IS_PTR:
|
||||
if (cardinality != 0) /* don't collapse inline */
|
||||
*dest++ = avlist_get(avlist);
|
||||
else {
|
||||
Attr_avlist new_avlist = (Attr_avlist)
|
||||
(LINT_CAST(avlist_get(avlist)));
|
||||
if (new_avlist)
|
||||
/* Copy the list inline -- don't
|
||||
* move past the null termintor.
|
||||
* Here both the attribute and null
|
||||
* terminator will be stripped away.
|
||||
*/
|
||||
dest = attr_copy_avlist(dest, new_avlist);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
*dest = 0;
|
||||
return(dest);
|
||||
}
|
||||
|
||||
|
||||
/* attr_count counts the number of slots in the av-list avlist.
|
||||
* Recursive lists are counted as being collapsed inline.
|
||||
*/
|
||||
int
|
||||
attr_count(avlist)
|
||||
Attr_avlist avlist;
|
||||
{
|
||||
/* count the null termination */
|
||||
return(attr_count_avlist(avlist, 0) + 1);
|
||||
}
|
||||
|
||||
static char *attr_names[ATTR_PKG_LAST-ATTR_PKG_FIRST+1] = {
|
||||
"Generic",
|
||||
"Panel",
|
||||
"Scrollbar",
|
||||
"Cursor",
|
||||
"Menu",
|
||||
"Textsw",
|
||||
"Tool",
|
||||
"Seln_base",
|
||||
"Entity",
|
||||
"Image",
|
||||
"Win",
|
||||
"Frame",
|
||||
"Canvas",
|
||||
"Tty",
|
||||
"Icon",
|
||||
"NOP",
|
||||
"Pixwin",
|
||||
"Alert",
|
||||
"Help"
|
||||
};
|
||||
|
||||
|
||||
char *
|
||||
attr_sprint(s, attr)
|
||||
char *s;
|
||||
register Attr_attribute attr;
|
||||
{
|
||||
static char msgbuf[100];
|
||||
extern char *sprintf();
|
||||
|
||||
if (!s) s = msgbuf;
|
||||
if (((int) ATTR_PKG(attr)) >= ((int) ATTR_PKG_FIRST) &&
|
||||
((int) ATTR_PKG(attr)) <= ((int) ATTR_PKG_LAST)) {
|
||||
char *name = attr_names[((int) ATTR_PKG(attr)) - ((int)ATTR_PKG_FIRST)];
|
||||
|
||||
if (!name) name = "Syspkg";
|
||||
(void) sprintf(s, "Attr pkg= %s, id= %d, cardinality= %d (0x%x)",
|
||||
name, ATTR_ORDINAL(attr), ATTR_CARDINALITY(attr), attr);
|
||||
} else {
|
||||
(void) sprintf(s, "Attr pkg= %s, id= %d, cardinality= %d (0x%x)",
|
||||
ATTR_PKG(attr), ATTR_ORDINAL(attr), ATTR_CARDINALITY(attr), attr);
|
||||
}
|
||||
return(s);
|
||||
}
|
||||
|
||||
void
|
||||
attr_check_pkg(last_attr, attr)
|
||||
Attr_attribute last_attr, attr;
|
||||
{
|
||||
if (!ATTR_VALID_PKG_ID(attr)) {
|
||||
char expand_attr[100];
|
||||
|
||||
(void) fprintf(stderr,
|
||||
"Malformed or non-terminated attribute-value list.\n");
|
||||
(void) fprintf(stderr, "Last valid attribute was %s.\n",
|
||||
attr_sprint(expand_attr, last_attr));
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
attr_count_avlist(avlist, last_attr)
|
||||
register Attr_avlist avlist;
|
||||
register Attr_attribute last_attr;
|
||||
{
|
||||
register Attr_attribute attr;
|
||||
register u_int count = 0;
|
||||
register u_int num;
|
||||
register u_int cardinality;
|
||||
|
||||
while (attr = (Attr_attribute) *avlist++) {
|
||||
count++; /* count the attribute */
|
||||
cardinality = ATTR_CARDINALITY(attr);
|
||||
attr_check_pkg(last_attr, attr);
|
||||
last_attr = attr;
|
||||
switch(ATTR_LIST_TYPE(attr)) {
|
||||
case ATTR_NONE: /* not a list */
|
||||
count += cardinality;
|
||||
avlist += cardinality;
|
||||
break;
|
||||
|
||||
case ATTR_NULL: /* null terminated list */
|
||||
switch (ATTR_LIST_PTR_TYPE(attr)) {
|
||||
case ATTR_LIST_IS_INLINE:
|
||||
/* Note that this only checks the first four bytes
|
||||
* for the null termination.
|
||||
*/
|
||||
while (*avlist++)
|
||||
count++;
|
||||
count++; /* count the null terminator */
|
||||
break;
|
||||
|
||||
case ATTR_LIST_IS_PTR:
|
||||
count++;
|
||||
avlist++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ATTR_COUNTED: /* counted list */
|
||||
switch (ATTR_LIST_PTR_TYPE(attr)) {
|
||||
case ATTR_LIST_IS_INLINE:
|
||||
num = ((u_int)(*avlist)) * cardinality + 1;
|
||||
count += num;
|
||||
avlist += num;
|
||||
break;
|
||||
case ATTR_LIST_IS_PTR:
|
||||
count++;
|
||||
avlist++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ATTR_RECURSIVE: /* recursive attribute-value list */
|
||||
if (cardinality == 0) /* don't include the attribute */
|
||||
count--;
|
||||
|
||||
switch (ATTR_LIST_PTR_TYPE(attr)) {
|
||||
case ATTR_LIST_IS_INLINE:
|
||||
count += attr_count_avlist(avlist, attr);
|
||||
if (cardinality != 0) /* count the null terminator */
|
||||
count++;
|
||||
avlist = attr_skip(attr, avlist);
|
||||
break;
|
||||
|
||||
case ATTR_LIST_IS_PTR:
|
||||
if (cardinality != 0) { /* don't collapse inline */
|
||||
count++;
|
||||
avlist++;
|
||||
} else if (*avlist)
|
||||
/* Here we count the elements of the
|
||||
* recursive list as being inline.
|
||||
* Don't count the null terminator.
|
||||
*/
|
||||
count += attr_count_avlist((Attr_avlist) (LINT_CAST
|
||||
(*avlist++)), attr);
|
||||
else
|
||||
avlist++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/* attr_skip_value returns a pointer to the attribute after
|
||||
* the value pointed to by avlist. attr should be the
|
||||
* attribute which describes the value at avlist.
|
||||
*/
|
||||
Attr_avlist
|
||||
attr_skip_value(attr, avlist)
|
||||
register Attr_attribute attr;
|
||||
register Attr_avlist avlist;
|
||||
{
|
||||
switch (ATTR_LIST_TYPE(attr)) {
|
||||
case ATTR_NULL:
|
||||
if (ATTR_LIST_PTR_TYPE(attr) == ATTR_LIST_IS_PTR)
|
||||
avlist++;
|
||||
else
|
||||
while (*avlist++);
|
||||
break;
|
||||
|
||||
case ATTR_RECURSIVE:
|
||||
if (ATTR_LIST_PTR_TYPE(attr) == ATTR_LIST_IS_PTR)
|
||||
avlist++;
|
||||
else
|
||||
while (attr = (Attr_attribute) *avlist++)
|
||||
avlist = attr_skip_value(attr, avlist);
|
||||
break;
|
||||
|
||||
case ATTR_COUNTED:
|
||||
if (ATTR_LIST_PTR_TYPE(attr) == ATTR_LIST_IS_PTR)
|
||||
avlist++;
|
||||
else
|
||||
avlist += ((int) *avlist) * ATTR_CARDINALITY(attr) + 1;
|
||||
break;
|
||||
|
||||
case ATTR_NONE:
|
||||
avlist += ATTR_CARDINALITY(attr);
|
||||
break;
|
||||
}
|
||||
return avlist;
|
||||
}
|
||||
|
||||
/* attr_free frees the attribute-value list
|
||||
*/
|
||||
void
|
||||
attr_free(avlist)
|
||||
Attr_avlist avlist;
|
||||
{
|
||||
free((char *) avlist);
|
||||
}
|
||||
130
usr.lib/libsunwindow/attr/attr_copy.c
Normal file
130
usr.lib/libsunwindow/attr/attr_copy.c
Normal file
@@ -0,0 +1,130 @@
|
||||
#ifndef lint
|
||||
#ifdef sccs
|
||||
static char sccsid[] = "@(#)attr_copy.c 1.1 94/10/31 Copyr 1985 Sun Micro";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sunwindow/attr.h>
|
||||
|
||||
/*
|
||||
* attr_copy: copy an attribute list, returning the size in bytes
|
||||
*/
|
||||
int
|
||||
attr_copy(source, dest)
|
||||
Attr_attribute **source, **dest;
|
||||
{
|
||||
unsigned attr;
|
||||
unsigned result, size;
|
||||
|
||||
size = 0;
|
||||
do {
|
||||
attr = **source;
|
||||
result = copy_1_attr(attr, source, dest);
|
||||
if (result == -1)
|
||||
return -1;
|
||||
size += result;
|
||||
} while (attr != 0);
|
||||
return size;
|
||||
}
|
||||
|
||||
static int
|
||||
copy_1_attr(attr, source, dest)
|
||||
Attr_attribute attr, **source, **dest;
|
||||
{
|
||||
int result, size;
|
||||
|
||||
*source += 1;
|
||||
**dest = attr;
|
||||
*dest += 1;
|
||||
size = sizeof attr;
|
||||
if (attr == 0 || ATTR_BASE_TYPE(attr) == ATTR_BASE_NO_VALUE)
|
||||
return size;
|
||||
|
||||
switch (ATTR_LIST_TYPE(attr)) {
|
||||
case ATTR_NONE:
|
||||
result = copy_singleton(attr, source, dest);
|
||||
break;
|
||||
case ATTR_NULL:
|
||||
result = copy_null_list(attr, source, dest);
|
||||
break;
|
||||
case ATTR_COUNTED:
|
||||
result = copy_counted_list(attr, source, dest);
|
||||
break;
|
||||
case ATTR_RECURSIVE:
|
||||
result = attr_copy(source, dest);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
if (result == -1)
|
||||
return -1;
|
||||
else
|
||||
return size + result;
|
||||
}
|
||||
|
||||
static int
|
||||
copy_counted_list(attr, source, dest)
|
||||
Attr_attribute attr, **source, **dest;
|
||||
{
|
||||
register unsigned count, n;
|
||||
register Attr_attribute *srcp, *destp;
|
||||
|
||||
(void)ATTR_CARDINALITY(attr);
|
||||
srcp = *source;
|
||||
destp = *dest;
|
||||
count = *srcp++;
|
||||
*destp++ = count;
|
||||
for (n = count; n--;) {
|
||||
*destp++ = *srcp++;
|
||||
}
|
||||
*source = srcp;
|
||||
*dest = destp;
|
||||
return count + 1;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
copy_singleton(attr, source, dest)
|
||||
Attr_attribute attr, **source, **dest;
|
||||
{
|
||||
register int count, size;
|
||||
register Attr_attribute *srcp, *destp;
|
||||
|
||||
count = ATTR_CARDINALITY(attr);
|
||||
size = count * 4;
|
||||
srcp = *source;
|
||||
destp = *dest;
|
||||
while (count-- > 0) {
|
||||
*destp++ = *srcp++;
|
||||
}
|
||||
*source = srcp;
|
||||
*dest = destp;
|
||||
return size;
|
||||
}
|
||||
|
||||
static int
|
||||
copy_null_list(attr, source, dest)
|
||||
Attr_attribute attr, **source, **dest;
|
||||
{
|
||||
register int count, size;
|
||||
register Attr_attribute *srcp, *destp;
|
||||
|
||||
count = 0;
|
||||
size = ATTR_CARDINALITY(attr);
|
||||
srcp = *source;
|
||||
destp = *dest;
|
||||
while (*srcp != 0) {
|
||||
register int i;
|
||||
|
||||
for (i = size; i--;) {
|
||||
*destp++ = *srcp++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
*destp++ = *srcp++;
|
||||
count++;
|
||||
*source = srcp;
|
||||
*dest = destp;
|
||||
return count * sizeof attr;
|
||||
}
|
||||
281
usr.lib/libsunwindow/attr/attr_cu.c
Normal file
281
usr.lib/libsunwindow/attr/attr_cu.c
Normal file
@@ -0,0 +1,281 @@
|
||||
#ifndef lint
|
||||
#ifdef sccs
|
||||
static char sccsid[] = "@(#)attr_cu.c 1.1 94/10/31 Copyr 1984 Sun Micro";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright (c) 1985 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include <pixrect/pixrect_hs.h>
|
||||
#include <sunwindow/attr.h>
|
||||
#include <sunwindow/sun.h>
|
||||
|
||||
/* attr_decode_cu decodes the encoded character row & pixel
|
||||
* value in encoded_value.
|
||||
*/
|
||||
static int
|
||||
attr_decode_cu(encoded_value, char_part, pixel_part)
|
||||
register u_int encoded_value;
|
||||
int *char_part;
|
||||
int *pixel_part;
|
||||
{
|
||||
short char_bits, pixel_bits;
|
||||
|
||||
char_bits = (short) ( (encoded_value >> 16) & 0x1FFF );
|
||||
/* sign extend if negative */
|
||||
if (char_bits & 0x1000)
|
||||
char_bits |= 0xE000;
|
||||
pixel_bits = ( (short) encoded_value) - ATTR_PIXEL_OFFSET;
|
||||
*char_part = (int) char_bits;
|
||||
*pixel_part = (int) pixel_bits;
|
||||
}
|
||||
|
||||
/* attr_cu_to_y converts the encoded character row & pixel
|
||||
* value in encoded_value to a pixel value.
|
||||
*/
|
||||
#undef attr_cu_to_y
|
||||
int
|
||||
attr_cu_to_y(encoded_value, font, top_margin, row_gap)
|
||||
u_int encoded_value;
|
||||
struct pixfont *font;
|
||||
int top_margin;
|
||||
int row_gap;
|
||||
{
|
||||
return attr_rc_unit_to_y(encoded_value, font->pf_defaultsize.y, top_margin, row_gap);
|
||||
}
|
||||
|
||||
int
|
||||
attr_rc_unit_to_y(encoded_value, row_height, top_margin, row_gap)
|
||||
u_int encoded_value;
|
||||
int row_height;
|
||||
int top_margin;
|
||||
int row_gap;
|
||||
{
|
||||
int char_part, pixel_part;
|
||||
int length;
|
||||
|
||||
if (!attr_is_cu(encoded_value))
|
||||
return (int) encoded_value;
|
||||
|
||||
attr_decode_cu(encoded_value, &char_part, &pixel_part);
|
||||
length = pixel_part + char_part * (row_height + row_gap);
|
||||
|
||||
switch (ATTR_CU_TYPE(encoded_value)) {
|
||||
case ATTR_CU_POSITION:
|
||||
return (top_margin + length);
|
||||
|
||||
case ATTR_CU_LENGTH:
|
||||
default:
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
/* attr_cu_to_x converts the encoded character column & pixel
|
||||
* value in encoded_value to a pixel value.
|
||||
*/
|
||||
#undef attr_cu_to_x
|
||||
int
|
||||
attr_cu_to_x(encoded_value, font, left_margin)
|
||||
u_int encoded_value;
|
||||
struct pixfont *font;
|
||||
int left_margin;
|
||||
{
|
||||
return attr_rc_unit_to_x(encoded_value, font->pf_defaultsize.x,
|
||||
left_margin, 0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
attr_rc_unit_to_x(encoded_value, col_width, left_margin, col_gap)
|
||||
u_int encoded_value;
|
||||
int col_width;
|
||||
int left_margin, col_gap;
|
||||
{
|
||||
int char_part, pixel_part;
|
||||
int length;
|
||||
|
||||
if (!attr_is_cu(encoded_value))
|
||||
return (int) encoded_value;
|
||||
|
||||
attr_decode_cu(encoded_value, &char_part, &pixel_part);
|
||||
length = pixel_part + char_part * (col_width + col_gap);
|
||||
|
||||
switch (ATTR_CU_TYPE(encoded_value)) {
|
||||
case ATTR_CU_POSITION:
|
||||
return (left_margin + length);
|
||||
|
||||
case ATTR_CU_LENGTH:
|
||||
default:
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* attr_replace_cu_value converts the value for attr (pointed to by avlist)
|
||||
* from character units to pixel units.
|
||||
*/
|
||||
static Attr_avlist
|
||||
attr_rc_unit_to_pixel(base_type, avlist, col_width, row_height,
|
||||
left_margin, top_margin, col_gap, row_gap)
|
||||
Attr_base_type base_type;
|
||||
register Attr_avlist avlist;
|
||||
int col_width, row_height;
|
||||
int left_margin, top_margin;
|
||||
int col_gap, row_gap;
|
||||
{
|
||||
switch (base_type) {
|
||||
case ATTR_BASE_INDEX_X: /* index, x-coordinate */
|
||||
avlist++; /* skip the index */
|
||||
/* and fall through ... */
|
||||
case ATTR_BASE_X: /* single x-coordinate */
|
||||
*avlist = (caddr_t)
|
||||
attr_rc_unit_to_x((u_int)*avlist, col_width, left_margin, col_gap);
|
||||
avlist++;
|
||||
break;
|
||||
|
||||
case ATTR_BASE_INDEX_Y: /* index, y-coordinate */
|
||||
avlist++; /* skip the index */
|
||||
/* and fall through ... */
|
||||
case ATTR_BASE_Y: /* single y-coordinate */
|
||||
*avlist = (caddr_t)
|
||||
attr_rc_unit_to_y((u_int)*avlist, row_height, top_margin, row_gap);
|
||||
avlist++;
|
||||
break;
|
||||
|
||||
case ATTR_BASE_INDEX_XY:/* index, x-coordinate, y-coordinate */
|
||||
avlist++; /* skip the index */
|
||||
/* and fall through ... */
|
||||
case ATTR_BASE_XY:
|
||||
*avlist = (caddr_t)
|
||||
attr_rc_unit_to_x((u_int)*avlist, col_width, left_margin, col_gap);
|
||||
avlist++;
|
||||
*avlist = (caddr_t)
|
||||
attr_rc_unit_to_y((u_int)*avlist, row_height, top_margin, row_gap);
|
||||
avlist++;
|
||||
break;
|
||||
|
||||
default: /* some other base type */
|
||||
/* we should complain here */
|
||||
break;
|
||||
}
|
||||
return avlist;
|
||||
}
|
||||
|
||||
|
||||
/* attr_replace_cu replaces any character unit values in avlist with
|
||||
* the corresponding pixel unit.
|
||||
*/
|
||||
#undef attr_replace_cu
|
||||
void
|
||||
attr_replace_cu(avlist, font, left_margin, top_margin, row_gap)
|
||||
register Attr_avlist avlist;
|
||||
struct pixfont *font;
|
||||
int left_margin;
|
||||
int top_margin;
|
||||
int row_gap;
|
||||
{
|
||||
attr_rc_units_to_pixels(avlist, font->pf_defaultsize.x,
|
||||
font->pf_defaultsize.y, left_margin, top_margin, 0, row_gap);
|
||||
}
|
||||
|
||||
void
|
||||
attr_rc_units_to_pixels(avlist, col_width, row_height, left_margin, top_margin,
|
||||
col_gap, row_gap)
|
||||
register Attr_avlist avlist;
|
||||
int col_width, row_height;
|
||||
int left_margin, top_margin;
|
||||
int col_gap, row_gap;
|
||||
{
|
||||
register Attr_attribute attr;
|
||||
register Attr_base_type base_type;
|
||||
register caddr_t *value_list;
|
||||
register short is_ptr;
|
||||
register int count;
|
||||
|
||||
/*
|
||||
* The goal is to convert all CU arguments (e.g., ATTR_X, ATTR_Y). ATTR_BASE_AV
|
||||
* needs to be recursively traversed to check for embedded CU types. As such,
|
||||
* unless an attribute's base type a) can take a CU value or b) can take an embedded
|
||||
* list that might contain a CU value its value can be ignored (skipped).
|
||||
*/
|
||||
|
||||
while (attr = (Attr_attribute) *avlist++) {
|
||||
switch (base_type = ATTR_BASE_TYPE(attr)) {
|
||||
default:
|
||||
avlist = attr_skip(attr, avlist);
|
||||
break;
|
||||
|
||||
case ATTR_BASE_AV:
|
||||
attr_rc_units_to_pixels(avlist, col_width, row_height,
|
||||
left_margin, top_margin, col_gap, row_gap);
|
||||
avlist = attr_skip(attr, avlist);
|
||||
break;
|
||||
|
||||
case ATTR_BASE_X:
|
||||
case ATTR_BASE_INDEX_X:
|
||||
case ATTR_BASE_Y:
|
||||
case ATTR_BASE_INDEX_Y:
|
||||
case ATTR_BASE_XY:
|
||||
case ATTR_BASE_INDEX_XY:
|
||||
is_ptr = ATTR_LIST_PTR_TYPE(attr) == ATTR_LIST_IS_PTR;
|
||||
switch (ATTR_LIST_TYPE(attr)) {
|
||||
case ATTR_NONE:
|
||||
avlist = attr_rc_unit_to_pixel(base_type, avlist,
|
||||
col_width, row_height, left_margin, top_margin,
|
||||
col_gap, row_gap);
|
||||
break;
|
||||
|
||||
case ATTR_NULL:
|
||||
if (is_ptr)
|
||||
value_list = (caddr_t *) (LINT_CAST(*avlist));
|
||||
else
|
||||
value_list = avlist;
|
||||
|
||||
while (*value_list)
|
||||
value_list = attr_rc_unit_to_pixel(base_type,
|
||||
value_list, col_width, row_height,
|
||||
left_margin, top_margin, col_gap, row_gap);
|
||||
|
||||
if (is_ptr)
|
||||
avlist++;
|
||||
else
|
||||
avlist = value_list + 1;
|
||||
break;
|
||||
|
||||
case ATTR_COUNTED:
|
||||
if (is_ptr)
|
||||
value_list = (caddr_t *) (LINT_CAST(*avlist));
|
||||
else
|
||||
value_list = avlist;
|
||||
|
||||
for (count = (int) *value_list++; count; count--)
|
||||
value_list = attr_rc_unit_to_pixel(base_type,
|
||||
value_list, col_width, row_height,
|
||||
left_margin, top_margin, col_gap, row_gap);
|
||||
|
||||
if (is_ptr)
|
||||
avlist++;
|
||||
else
|
||||
avlist = value_list;
|
||||
break;
|
||||
|
||||
case ATTR_RECURSIVE:
|
||||
if (is_ptr)
|
||||
attr_rc_units_to_pixels((Attr_avlist)
|
||||
(LINT_CAST(*avlist++)),
|
||||
col_width, row_height, left_margin,
|
||||
top_margin, col_gap, row_gap);
|
||||
else {
|
||||
attr_rc_units_to_pixels(avlist,
|
||||
col_width, row_height, left_margin,
|
||||
top_margin, col_gap, row_gap);
|
||||
avlist = attr_skip(attr, avlist);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
usr.lib/libsunwindow/attr/attr_util.c
Normal file
44
usr.lib/libsunwindow/attr/attr_util.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef lint
|
||||
#ifdef sccs
|
||||
static char sccsid[] = "@(#)attr_util.c 1.1 94/10/31";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright (c) 1986 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <varargs.h>
|
||||
#include <sunwindow/attr.h>
|
||||
|
||||
/* attr_create_list creates an avlist from the VARARGS passed
|
||||
* on the stack. The storage is always allocated.
|
||||
*/
|
||||
/*VARARGS*/
|
||||
Attr_avlist
|
||||
attr_create_list(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
va_list valist;
|
||||
Attr_avlist avlist;
|
||||
|
||||
va_start(valist);
|
||||
avlist = attr_make((char **)0, 0, valist);
|
||||
va_end(valist);
|
||||
return avlist;
|
||||
}
|
||||
|
||||
/* attr_find searches and avlist for the first occurrence of
|
||||
* a specified attribute.
|
||||
*/
|
||||
Attr_avlist
|
||||
attr_find(attrs, attr)
|
||||
register Attr_avlist attrs;
|
||||
register Attr_attribute attr;
|
||||
{
|
||||
for (; *attrs; attrs = attr_next(attrs)) {
|
||||
if (*attrs == (caddr_t)attr) break;
|
||||
}
|
||||
return(attrs);
|
||||
}
|
||||
Reference in New Issue
Block a user