示例#1
0
/*
 * Initialize the units(3) package.
 */
int
utInit(
    const char	*path)
{
    int status;

    (void)ut_set_error_message_handler(ut_ignore);
    if (unitSystem != NULL) {
	ut_free_system(unitSystem);
	unitSystem = NULL;
    }
    unitSystem = ut_read_xml(NULL);
    if (unitSystem == NULL) {
	status = ut_get_status() == UT_PARSE
	    ? UT_ESYNTAX
	    : UT_EIO;
    }
    else {
	second = ut_get_unit_by_name(unitSystem, "second");
	encodedTimeUnit =
	    ut_offset_by_time(second, ut_encode_time(2001, 1, 1, 0, 0, 0.0));
	buffer = malloc(buflen);
	if (buffer == NULL) {
	    buflen = 0;
	    status = UT_EALLOC;
	}
	else {
	    status = 0;
	}
    }
    return status;
}
示例#2
0
/*!
 * Returns the UdUnit to which \a name maps from this unit-system or an invalid
 * UdUnit if no such unit exists ot if this unit-system is invalid.
 * Name comparisons are case-sensitive.
 * \sa UdUnitSystem::isValid(), UdUnit::isValid()
 */
UdUnit UdUnitSystem::unitByName(const QString &name) const
{
    ut_set_status(UT_SUCCESS);
    ut_unit *unit = ut_get_unit_by_name(m_system, name.toLocal8Bit().constData());
    int status = ut_get_status();
    return UdUnit(unit, status);
}