int main(int argc, char *argv[]) { int c, i, rc, verbose = 0, oflg = ODTBL_FLG_RDONLY, tflg = ODTBL_OPT_CRC; struct pfl_odt *t; char *p, *fn; pfl_init(); pscthr_init(0, NULL, 0, "odtable"); while ((c = getopt(argc, argv, "CcdF:n:osvX:z:")) != -1) switch (c) { case 'C': create_table = 1; break; case 'c': tflg |= ODTBL_OPT_CRC; break; case 'd': dump = 1; break; case 'F': num_free = atoi(optarg); oflg &= ~ODTBL_FLG_RDONLY; break; case 'n': num_puts = atoi(optarg); oflg &= ~ODTBL_FLG_RDONLY; break; case 'o': overwrite = 1; break; case 's': item_size = atoi(optarg); break; case 'v': verbose = 1; break; case 'X': fmt = optarg; break; case 'z': nitems = atoi(optarg); break; default: usage(); } argc -= optind; argv += optind; if (argc != 1) usage(); fn = argv[0]; if (create_table) { rc = pfl_odt_create(fn, nitems, item_size, overwrite, ODT_ITEM_START, 0, tflg); if (!rc && verbose) warnx("created od-table %s " "(elemsize=%zu, nitems=%zu)", fn, item_size, nitems); exit(0); } pfl_odt_load(&t, &pfl_odtops, oflg, fn, "%s", fn); pfl_odt_check(t, visit, &t); for (i = 0; i < num_puts; i++) { size_t elem; elem = pfl_odt_allocslot(t); pfl_odt_allocitem(t, (void **)&p); snprintf(p, item_size, "... put_number=%d ...", i); pfl_odt_putitem(t, elem, p, 1); PSCFREE(p); } /* XXX find in-use slot to free */ for (i = 0; i < num_free; i++) pfl_odt_freeitem(t, i); pfl_odt_release(t); exit(0); }
int main(int argc, char *argv[]) { int c, i, verbose = 0, oflg = ODTBL_FLG_RDONLY, tflg = ODTBL_OPT_CRC; struct pfl_odt_receipt *r; struct pfl_odt *t; char *p, *fn; pfl_init(); progname = argv[0]; while ((c = getopt(argc, argv, "CcDe:F:n:osvX:Zz:")) != -1) switch (c) { case 'C': create_table = 1; break; case 'c': tflg |= ODTBL_OPT_CRC; break; case 'e': elem_size = atoi(optarg); break; case 'F': num_free = atoi(optarg); oflg &= ~ODTBL_FLG_RDONLY; break; case 'n': num_puts = atoi(optarg); oflg &= ~ODTBL_FLG_RDONLY; break; case 'o': overwrite = 1; break; case 's': show = 1; break; case 'v': verbose = 1; break; case 'X': fmt = optarg; break; case 'Z': tflg |= ODTBL_OPT_SYNC; break; case 'z': nelems = atoi(optarg); break; default: usage(); } argc -= optind; argv += optind; if (argc != 1) usage(); fn = argv[0]; if (create_table) { pfl_odt_create(fn, nelems, elem_size, overwrite, 0x1000, 0, tflg); if (verbose) warnx("created od-table %s " "(elemsize=%zu, nelems=%zu)", fn, elem_size, nelems); exit(0); } pfl_odt_load(&t, &pfl_odtops_mmap, oflg, fn, "%s", fn); pfl_odt_check(t, visit, &t); for (i = 0; i < num_puts; i++) { size_t elem; elem = pfl_odt_allocslot(t); pfl_odt_mapitem(t, elem, &p); snprintf(p, elem_size, "... put_number=%d ...", i); pfl_odt_putitem(t, elem, p); pfl_odt_freebuf(t, p, NULL); } DYNARRAY_FOREACH(r, i, &rcpts) pfl_odt_freeitem(t, r); pfl_odt_release(t); psc_dynarray_free(&rcpts); exit(0); }