Index: Makefile =================================================================== --- Makefile (revision 319792) +++ Makefile (working copy) @@ -4,6 +4,4 @@ SRCS= sesutil.c eltsub.c MAN= sesutil.8 -LIBADD= sbuf - .include Index: eltsub.c =================================================================== --- eltsub.c (revision 320267) +++ eltsub.c (working copy) @@ -32,9 +32,7 @@ * mjacob@feral.com */ -#include #include -#include #include #include @@ -143,52 +141,3 @@ return (rbuf); } } - -struct sbuf * -stat2sbuf(int eletype, u_char *cstat) -{ - struct sbuf *buf; - - buf = sbuf_new_auto(); - if (buf == NULL) - err(EXIT_FAILURE, "sbuf_new_auto()"); - - if (cstat[0] & 0x40) - sbuf_printf(buf, "\t\t- Predicted Failure\n"); - if (cstat[0] & 0x20) - sbuf_printf(buf, "\t\t- Disabled\n"); - if (cstat[0] & 0x10) - sbuf_printf(buf, "\t\t- Swapped\n"); - switch (eletype) { - case ELMTYP_DEVICE: - if (cstat[2] & 0x02) - sbuf_printf(buf, "\t\t- LED=locate\n"); - if (cstat[2] & 0x20) - sbuf_printf(buf, "\t\t- LED=fault\n"); - break; - case ELMTYP_ARRAY_DEV: - if (cstat[2] & 0x02) - sbuf_printf(buf, "\t\t- LED=locate\n"); - if (cstat[2] & 0x20) - sbuf_printf(buf, "\t\t- LED=fault\n"); - break; - case ELMTYP_FAN: - sbuf_printf(buf, "\t\t- Speed: %d rpm\n", - (((0x7 & cstat[1]) << 8) + cstat[2]) * 10); - break; - case ELMTYP_THERM: - if (cstat[2]) { - sbuf_printf(buf, "\t\t- Temperature: %d C\n", - cstat[2] - TEMPERATURE_OFFSET); - } else { - sbuf_printf(buf, "\t\t- Temperature: -reserved-\n"); - } - break; - case ELMTYP_VOM: - sbuf_printf(buf, "\t\t- Voltage: %.2f V\n", - be16dec(cstat + 2) / 100.0); - break; - } - sbuf_finish(buf); - return (buf); -} Index: eltsub.h =================================================================== --- eltsub.h (revision 320267) +++ eltsub.h (working copy) @@ -34,4 +34,3 @@ const char *geteltnm(int); const char *scode2ascii(u_char); -struct sbuf *stat2sbuf(int, u_char *); Index: sesutil.c =================================================================== --- sesutil.c (revision 319792) +++ sesutil.c (working copy) @@ -29,10 +29,10 @@ #include __FBSDID("$FreeBSD$"); +#include #include #include #include -#include #include #include @@ -303,10 +303,62 @@ return (sesled(argc, argv, true)); } +#define TEMPERATURE_OFFSET 20 +#define print if (!title) { printf("\t\tExtra status:\n"); title = true; } printf +static void +print_extra_status(int eletype, u_char *cstat) +{ + bool title = false; + + if (cstat[0] & 0x40) { + print("\t\t- Predicted Failure\n"); + } + if (cstat[0] & 0x20) { + print("\t\t- Disabled\n"); + } + if (cstat[0] & 0x10) { + print("\t\t- Swapped\n"); + } + switch (eletype) { + case ELMTYP_DEVICE: + if (cstat[2] & 0x02) { + print("\t\t- LED=locate\n"); + } + if (cstat[2] & 0x20) { + print("\t\t- LED=fault\n"); + } + break; + case ELMTYP_ARRAY_DEV: + if (cstat[2] & 0x02) { + print("\t\t- LED=locate\n"); + } + if (cstat[2] & 0x20) { + print("\t\t- LED=fault\n"); + } + break; + case ELMTYP_FAN: + print("\t\t- Speed: %d rpm\n", + (((0x7 & cstat[1]) << 8) + cstat[2]) * 10); + break; + case ELMTYP_THERM: + if (cstat[2]) { + print("\t\t- Temperature: %d C\n", + cstat[2] - TEMPERATURE_OFFSET); + } else { + print("\t\t- Temperature: -reserved-\n"); + } + break; + case ELMTYP_VOM: + print("\t\t- Voltage: %.2f V\n", + be16dec(cstat + 2) / 100.0); + break; + } +} +#undef print + static int objmap(int argc, char **argv __unused) { - struct sbuf *extra; encioc_string_t stri; encioc_elm_devnames_t e_devname; encioc_elm_status_t e_status; @@ -422,12 +474,7 @@ printf("\t\tDevice Names: %s\n", e_devname.elm_devnames); } - extra = stat2sbuf(e_ptr[j].elm_type, e_status.cstat); - if (sbuf_len(extra) > 0) { - printf("\t\tExtra status:\n%s", - sbuf_data(extra)); - } - sbuf_delete(extra); + print_extra_status(e_ptr[j].elm_type, e_status.cstat); free(e_devname.elm_devnames); } free(e_ptr);