/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Minoura Makoto.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
int
print_uchar(struct property *prop, char *str)
{
if (prop->modified)
snprintf(str, MAXVALUELEN,
"%d", prop->modified_value.byte[0]);
else {
if (!prop->value_valid)
prop->fill(prop);
snprintf(str, MAXVALUELEN, "%d",
prop->current_value.byte[0]);
}
return 0;
}
int
print_ucharh(struct property *prop, char *str)
{
if (prop->modified)
snprintf(str, MAXVALUELEN,
"0x%4.4x", prop->modified_value.byte[0]);
else {
if (!prop->value_valid)
prop->fill(prop);
snprintf(str, MAXVALUELEN,
"0x%4.4x", prop->current_value.byte[0]);
}
return 0;
}
int
print_ushorth(struct property *prop, char *str)
{
if (prop->modified)
snprintf(str, MAXVALUELEN,
"0x%4.4x", prop->modified_value.word[0]);
else {
if (!prop->value_valid)
prop->fill(prop);
snprintf(str, MAXVALUELEN,
"0x%4.4x", prop->current_value.word[0]);
}
return 0;
}
int
print_ulong(struct property *prop, char *str)
{
if (prop->modified)
snprintf(str, MAXVALUELEN,
"%ld", prop->modified_value.longword);
else {
if (!prop->value_valid)
prop->fill(prop);
snprintf(str, MAXVALUELEN,
"%ld", prop->current_value.longword);
}
return 0;
}
int
print_ulongh(struct property *prop, char *str)
{
if (prop->modified)
snprintf(str, MAXVALUELEN,
"0x%8.8lx", prop->modified_value.longword);
else {
if (!prop->value_valid)
prop->fill(prop);
snprintf(str, MAXVALUELEN,
"0x%8.8lx", prop->current_value.longword);
}
return 0;
}
int
print_magic(struct property *prop, char *str)
{
if (!prop->value_valid)
prop->fill(prop);
snprintf(str, MAXVALUELEN, "%c%c%c%c",
prop->current_value.byte[0],
prop->current_value.byte[1],
prop->current_value.byte[2],
prop->current_value.byte[3]);
return 0;
}
int
print_timesec(struct property *prop, char *str)
{
if (prop->modified)
snprintf(str, MAXVALUELEN,
"%ld second", prop->modified_value.longword);
else {
if (!prop->value_valid)
prop->fill(prop);
snprintf(str, MAXVALUELEN,
"%ld second", prop->current_value.longword);
}
return 0;
}
int
print_bootdev(struct property *prop, char *str)
{
unsigned int v;
if (prop->modified)
v = prop->modified_value.word[0];
else {
if (!prop->value_valid)
prop->fill(prop);
v = prop->current_value.word[0];
}
if (v == 0)
strcpy(str, "STD");
else if (v == 0xa000)
strcpy(str, "ROM");
else if (v == 0xb000)
strcpy(str, "RAM");
else if (v >= 0x8000 && v < 0x9000)
snprintf(str, MAXVALUELEN, "HD%d", (v & 0x0f00) >> 8);
else if (v >= 0x9000 && v < 0xa000)
snprintf(str, MAXVALUELEN, "FD%d", (v & 0x0f00) >> 8);
else
snprintf(str, MAXVALUELEN, "%8.8x", v);