> 1) - asprintf(&res_str, "0x%jx-0x%jx", res->dr_start, end); + printf("0x%jx-0x%jx", res->dr_start, end); else - asprintf(&res_str, "0x%jx", res->dr_start); + printf("0x%jx", res->dr_start); } else { if (res->dr_size > 1) - asprintf(&res_str, "%ju-%ju", res->dr_start, end); + printf("%ju-%ju", res->dr_start, end); else - asprintf(&res_str, "%ju", res->dr_start); - } - - xo_emit("{P: }"); - - if (last_res == NULL) { - // First resource - xo_open_list(res_str); - } else if (strcmp(res_str, last_res) != 0) { - // We can't repeat json keys. So we keep an - // open list from the last iteration and only - // create a new list when see a new resource. - xo_close_list(last_res); - xo_open_list(res_str); + printf("%ju", res->dr_start); } dev = devinfo_handle_to_device(res->dr_device); if (dev != NULL) { if (dev->dd_name[0] != 0) { printf(" (%s)", dev->dd_name); - asprintf(&entry, "{el:%s}{D:%s} {D:(%s)}\n", - res_str, res_str, dev->dd_name); - xo_emit(entry, dev->dd_name); } else { printf(" (unknown)"); if (vflag && *dev->dd_pnpinfo) @@ -350,11 +247,9 @@ print_rman_resource(struct devinfo_res *res, void *arg __unused) printf(" at %s", dev->dd_location); } } else { - asprintf(&entry, "{el:%s}{D:%s} {D:----}\n", res_str, res_str); - xo_emit(entry, "----"); + printf(" ----"); } - free(entry); - last_res = res_str; + printf("\n"); return(0); } @@ -364,16 +259,8 @@ print_rman_resource(struct devinfo_res *res, void *arg __unused) int print_rman(struct devinfo_rman *rman, void *arg __unused) { - char* safe_desc = xml_safe_string(rman->dm_desc); - - xo_emit("<{:description/%s}\n>", rman->dm_desc); - xo_open_container(safe_desc); - + printf("%s:\n", rman->dm_desc); devinfo_foreach_rman_resource(rman, print_rman_resource, 0); - - xo_close_list(last_res); - xo_close_container(safe_desc); - free(safe_desc); return(0); } @@ -382,17 +269,12 @@ print_device_path_entry(struct devinfo_dev *dev) { const char *devname = dev->dd_name[0] ? dev->dd_name : "unknown"; - xo_open_container(devname); - open_tag_count++; - xo_emit("{:devicename/%s} ", devname); + printf("%s", devname); print_device_props(dev); if (vflag) - xo_emit("\n"); + printf("\n"); } -/* - * Recurse until we find the right dev. On the way up we print path. - */ static int print_device_path(struct devinfo_dev *dev, void *xname) { @@ -406,7 +288,7 @@ print_device_path(struct devinfo_dev *dev, void *xname) rv = devinfo_foreach_device_child(dev, print_device_path, xname); if (rv == 1) { - xo_emit("{P: }"); + printf(" "); print_device_path_entry(dev); } return (rv); @@ -415,26 +297,19 @@ print_device_path(struct devinfo_dev *dev, void *xname) static void print_path(struct devinfo_dev *root, char *path) { - open_tag_count = 0; - if (devinfo_foreach_device_child(root, print_device_path, - (void *)path) == 0) - xo_errx(1, "%s: Not found", path); + if (devinfo_foreach_device_child(root, print_device_path, (void *)path) == 0) + errx(1, "%s: Not found", path); if (!vflag) - xo_emit("\n"); - - while (open_tag_count > 0) { - xo_close_container_d(); - open_tag_count--; - } + printf("\n"); } static void __dead2 usage(void) { - xo_error( - "usage: devinfo [-rv]\n", - " devinfo -u [-v]\n", - " devinfo -p dev [-v]\n"); + fprintf(stderr, "%s\n%s\n%s\n", + "usage: devinfo [-rv]", + " devinfo -u [-v]", + " devinfo -p dev [-v]"); exit(1); } @@ -446,11 +321,6 @@ main(int argc, char *argv[]) bool uflag; char *path = NULL; - argc = xo_parse_args(argc, argv); - if (argc < 0) { - exit(1); - } - uflag = false; while ((c = getopt(argc, argv, "p:ruv")) != -1) { switch(c) { @@ -476,32 +346,20 @@ main(int argc, char *argv[]) if ((rv = devinfo_init()) != 0) { errno = rv; - xo_err(1, "devinfo_init"); + err(1, "devinfo_init"); } if ((root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL) - xo_errx(1, "can't find root device"); + errx(1, "can't find root device"); if (path) { - xo_set_flags(NULL, XOF_DTRT); - xo_open_container("device-path"); print_path(root, path); - xo_close_container("device-path"); } else if (uflag) { /* print resource usage? */ - xo_set_flags(NULL, XOF_DTRT); - xo_open_container("device-resources"); devinfo_foreach_rman(print_rman, NULL); - xo_close_container("device-resources"); } else { /* print device hierarchy */ - xo_open_container("device-information"); devinfo_foreach_device_child(root, print_device, (void *)0); - xo_close_container("device-information"); - } - - if (xo_finish() < 0) { - exit(1); } return(0); }