vere: supports --loom for all relevant subcommands

This commit is contained in:
Joe Bryan 2022-11-17 20:42:48 -05:00
parent a7de786d01
commit 255c08f53d

View File

@ -1333,25 +1333,56 @@ _cw_grab(c3_i argc, c3_c* argv[])
static void static void
_cw_cram(c3_i argc, c3_c* argv[]) _cw_cram(c3_i argc, c3_c* argv[])
{ {
switch ( argc ) { c3_i ch_i, lid_i;
case 2: { c3_w arg_w;
if ( !(u3_Host.dir_c = _main_pier_run(argv[0])) ) {
fprintf(stderr, "unable to find pier\r\n"); static struct option lop_u[] = {
{ "loom", required_argument, NULL, c3__loom },
{ NULL, 0, NULL, 0 }
};
u3_Host.dir_c = _main_pier_run(argv[0]);
while ( -1 != (ch_i=getopt_long(argc, argv, "", lop_u, &lid_i)) ) {
switch ( ch_i ) {
case c3__loom: {
c3_w lom_w;
c3_o res_o = _main_readw(optarg, u3a_bits + 3, &lom_w);
if ( (c3n == res_o) || (lom_w < 20) ) {
fprintf(stderr, "error: --loom must be >= 20 and <= %u\r\n", u3a_bits + 2);
exit(1); exit(1);
} }
u3_Host.ops_u.lom_y = lom_w;
} break; } break;
case 3: { case '?': {
u3_Host.dir_c = argv[2]; fprintf(stderr, "invalid argument\r\n");
exit(1);
} break; } break;
}
}
default: { // argv[optind] is always "cram"
//
if ( !u3_Host.dir_c ) {
if ( optind + 1 < argc ) {
u3_Host.dir_c = argv[optind + 1];
}
else {
fprintf(stderr, "invalid command, pier required\r\n");
exit(1);
}
optind++;
}
if ( optind + 1 != argc ) {
fprintf(stderr, "invalid command\r\n"); fprintf(stderr, "invalid command\r\n");
exit(1); exit(1);
} break;
} }
c3_d eve_d = u3m_boot(u3_Host.dir_c, u3a_bytes); c3_d eve_d = u3m_boot(u3_Host.dir_c, (size_t)1 << u3_Host.ops_u.lom_y);
u3_disk* log_u = _cw_disk_init(u3_Host.dir_c); // XX s/b try_aquire lock u3_disk* log_u = _cw_disk_init(u3_Host.dir_c); // XX s/b try_aquire lock
c3_o ret_o; c3_o ret_o;
@ -1381,29 +1412,58 @@ _cw_cram(c3_i argc, c3_c* argv[])
static void static void
_cw_queu(c3_i argc, c3_c* argv[]) _cw_queu(c3_i argc, c3_c* argv[])
{ {
c3_c* eve_c; c3_i ch_i, lid_i;
c3_d eve_d; c3_w arg_w;
switch ( argc ) { static struct option lop_u[] = {
case 3: { { "loom", required_argument, NULL, c3__loom },
if ( !(u3_Host.dir_c = _main_pier_run(argv[0])) ) { { NULL, 0, NULL, 0 }
fprintf(stderr, "unable to find pier\r\n"); };
u3_Host.dir_c = _main_pier_run(argv[0]);
while ( -1 != (ch_i=getopt_long(argc, argv, "", lop_u, &lid_i)) ) {
switch ( ch_i ) {
case c3__loom: {
c3_w lom_w;
c3_o res_o = _main_readw(optarg, u3a_bits + 3, &lom_w);
if ( (c3n == res_o) || (lom_w < 20) ) {
fprintf(stderr, "error: --loom must be >= 20 and <= %u\r\n", u3a_bits + 2);
exit(1); exit(1);
} }
eve_c = argv[2]; u3_Host.ops_u.lom_y = lom_w;
} break; } break;
case 4: { case '?': {
u3_Host.dir_c = argv[2]; fprintf(stderr, "invalid argument\r\n");
eve_c = argv[3]; exit(1);
} break; } break;
}
}
default: { // argv[optind] is always "queu"
//
if ( !u3_Host.dir_c ) {
if ( optind + 1 < argc ) {
u3_Host.dir_c = argv[optind + 1];
}
else {
fprintf(stderr, "invalid command, pier required\r\n");
exit(1);
}
optind++;
}
if ( optind + 1 != argc ) {
fprintf(stderr, "invalid command\r\n"); fprintf(stderr, "invalid command\r\n");
exit(1); exit(1);
} break;
} }
c3_c* eve_c;
c3_d eve_d;
if ( 1 != sscanf(eve_c, "%" PRIu64 "", &eve_d) ) { if ( 1 != sscanf(eve_c, "%" PRIu64 "", &eve_d) ) {
fprintf(stderr, "urbit: queu: invalid number '%s'\r\n", eve_c); fprintf(stderr, "urbit: queu: invalid number '%s'\r\n", eve_c);
exit(1); exit(1);
@ -1413,7 +1473,7 @@ _cw_queu(c3_i argc, c3_c* argv[])
fprintf(stderr, "urbit: queu: preparing\r\n"); fprintf(stderr, "urbit: queu: preparing\r\n");
u3m_boot(u3_Host.dir_c, u3a_bytes); u3m_boot(u3_Host.dir_c, (size_t)1 << u3_Host.ops_u.lom_y);
// XX can spuriously fail do to corrupt memory-image checkpoint, // XX can spuriously fail do to corrupt memory-image checkpoint,
// need a u3m_half_boot equivalent // need a u3m_half_boot equivalent
@ -1437,29 +1497,60 @@ _cw_queu(c3_i argc, c3_c* argv[])
static void static void
_cw_meld(c3_i argc, c3_c* argv[]) _cw_meld(c3_i argc, c3_c* argv[])
{ {
switch ( argc ) { c3_i ch_i, lid_i;
case 2: { c3_w arg_w;
if ( !(u3_Host.dir_c = _main_pier_run(argv[0])) ) {
fprintf(stderr, "unable to find pier\r\n"); static struct option lop_u[] = {
{ "loom", required_argument, NULL, c3__loom },
{ NULL, 0, NULL, 0 }
};
u3_Host.dir_c = _main_pier_run(argv[0]);
while ( -1 != (ch_i=getopt_long(argc, argv, "", lop_u, &lid_i)) ) {
switch ( ch_i ) {
case c3__loom: {
c3_w lom_w;
c3_o res_o = _main_readw(optarg, u3a_bits + 3, &lom_w);
if ( (c3n == res_o) || (lom_w < 20) ) {
fprintf(stderr, "error: --loom must be >= 20 and <= %u\r\n", u3a_bits + 2);
exit(1); exit(1);
} }
u3_Host.ops_u.lom_y = lom_w;
} break; } break;
case 3: { case '?': {
u3_Host.dir_c = argv[2]; fprintf(stderr, "invalid argument\r\n");
} break;
default: {
fprintf(stderr, "invalid command\r\n");
exit(1); exit(1);
} break; } break;
} }
}
// argv[optind] is always "meld"
//
if ( !u3_Host.dir_c ) {
if ( optind + 1 < argc ) {
u3_Host.dir_c = argv[optind + 1];
}
else {
fprintf(stderr, "invalid command, pier required\r\n");
exit(1);
}
optind++;
}
if ( optind + 1 != argc ) {
fprintf(stderr, "invalid command\r\n");
exit(1);
}
u3_disk* log_u = _cw_disk_init(u3_Host.dir_c); // XX s/b try_aquire lock u3_disk* log_u = _cw_disk_init(u3_Host.dir_c); // XX s/b try_aquire lock
c3_w pre_w; c3_w pre_w;
u3C.wag_w |= u3o_hashless; u3C.wag_w |= u3o_hashless;
u3m_boot(u3_Host.dir_c, u3a_bytes); u3m_boot(u3_Host.dir_c, (size_t)1 << u3_Host.ops_u.lom_y);
pre_w = u3a_open(u3R); pre_w = u3a_open(u3R);
u3u_meld(); u3u_meld();
@ -1480,6 +1571,7 @@ _cw_next(c3_i argc, c3_c* argv[])
static struct option lop_u[] = { static struct option lop_u[] = {
{ "arch", required_argument, NULL, 'a' }, { "arch", required_argument, NULL, 'a' },
{ "loom", required_argument, NULL, c3__loom },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
@ -1491,7 +1583,18 @@ _cw_next(c3_i argc, c3_c* argv[])
u3_Host.arc_c = strdup(optarg); u3_Host.arc_c = strdup(optarg);
} break; } break;
case c3__loom: {
c3_w lom_w;
c3_o res_o = _main_readw(optarg, u3a_bits + 3, &lom_w);
if ( (c3n == res_o) || (lom_w < 20) ) {
fprintf(stderr, "error: --loom must be >= 20 and <= %u\r\n", u3a_bits + 2);
exit(1);
}
u3_Host.ops_u.lom_y = lom_w;
} break;
case '?': { case '?': {
fprintf(stderr, "invalid argument\r\n");
exit(1); exit(1);
} break; } break;
} }
@ -1527,27 +1630,58 @@ _cw_next(c3_i argc, c3_c* argv[])
static void static void
_cw_pack(c3_i argc, c3_c* argv[]) _cw_pack(c3_i argc, c3_c* argv[])
{ {
switch ( argc ) { c3_i ch_i, lid_i;
case 2: { c3_w arg_w;
if ( !(u3_Host.dir_c = _main_pier_run(argv[0])) ) {
fprintf(stderr, "unable to find pier\r\n"); static struct option lop_u[] = {
{ "loom", required_argument, NULL, c3__loom },
{ NULL, 0, NULL, 0 }
};
u3_Host.dir_c = _main_pier_run(argv[0]);
while ( -1 != (ch_i=getopt_long(argc, argv, "", lop_u, &lid_i)) ) {
switch ( ch_i ) {
case c3__loom: {
c3_w lom_w;
c3_o res_o = _main_readw(optarg, u3a_bits + 3, &lom_w);
if ( (c3n == res_o) || (lom_w < 20) ) {
fprintf(stderr, "error: --loom must be >= 20 and <= %u\r\n", u3a_bits + 2);
exit(1); exit(1);
} }
u3_Host.ops_u.lom_y = lom_w;
} break; } break;
case 3: { case '?': {
u3_Host.dir_c = argv[2]; fprintf(stderr, "invalid argument\r\n");
} break;
default: {
fprintf(stderr, "invalid command\r\n");
exit(1); exit(1);
} break; } break;
} }
}
// argv[optind] is always "pack"
//
if ( !u3_Host.dir_c ) {
if ( optind + 1 < argc ) {
u3_Host.dir_c = argv[optind + 1];
}
else {
fprintf(stderr, "invalid command, pier required\r\n");
exit(1);
}
optind++;
}
if ( optind + 1 != argc ) {
fprintf(stderr, "invalid command\r\n");
exit(1);
}
u3_disk* log_u = _cw_disk_init(u3_Host.dir_c); // XX s/b try_aquire lock u3_disk* log_u = _cw_disk_init(u3_Host.dir_c); // XX s/b try_aquire lock
u3m_boot(u3_Host.dir_c, u3a_bytes); u3m_boot(u3_Host.dir_c, (size_t)1 << u3_Host.ops_u.lom_y);
u3a_print_memory(stderr, "urbit: pack: gained", u3m_pack()); u3a_print_memory(stderr, "urbit: pack: gained", u3m_pack());
u3e_save(); u3e_save();
@ -1560,23 +1694,54 @@ _cw_pack(c3_i argc, c3_c* argv[])
static void static void
_cw_prep(c3_i argc, c3_c* argv[]) _cw_prep(c3_i argc, c3_c* argv[])
{ {
switch ( argc ) { c3_i ch_i, lid_i;
case 2: { c3_w arg_w;
if ( !(u3_Host.dir_c = _main_pier_run(argv[0])) ) {
fprintf(stderr, "unable to find pier\r\n"); static struct option lop_u[] = {
{ "loom", required_argument, NULL, c3__loom },
{ NULL, 0, NULL, 0 }
};
u3_Host.dir_c = _main_pier_run(argv[0]);
while ( -1 != (ch_i=getopt_long(argc, argv, "", lop_u, &lid_i)) ) {
switch ( ch_i ) {
case c3__loom: {
c3_w lom_w;
c3_o res_o = _main_readw(optarg, u3a_bits + 3, &lom_w);
if ( (c3n == res_o) || (lom_w < 20) ) {
fprintf(stderr, "error: --loom must be >= 20 and <= %u\r\n", u3a_bits + 2);
exit(1); exit(1);
} }
u3_Host.ops_u.lom_y = lom_w;
} break; } break;
case 3: { case '?': {
u3_Host.dir_c = argv[2]; fprintf(stderr, "invalid argument\r\n");
} break;
default: {
fprintf(stderr, "invalid command\r\n");
exit(1); exit(1);
} break; } break;
} }
}
// argv[optind] is always "prep"
//
if ( !u3_Host.dir_c ) {
if ( optind + 1 < argc ) {
u3_Host.dir_c = argv[optind + 1];
}
else {
fprintf(stderr, "invalid command, pier required\r\n");
exit(1);
}
optind++;
}
if ( optind + 1 != argc ) {
fprintf(stderr, "invalid command\r\n");
exit(1);
}
u3_Host.pep_o = c3y; u3_Host.pep_o = c3y;
u3_Host.ops_u.tem = c3y; u3_Host.ops_u.tem = c3y;
@ -1700,27 +1865,58 @@ _cw_vere(c3_i argc, c3_c* argv[])
static void static void
_cw_vile(c3_i argc, c3_c* argv[]) _cw_vile(c3_i argc, c3_c* argv[])
{ {
switch ( argc ) { c3_i ch_i, lid_i;
case 2: { c3_w arg_w;
if ( !(u3_Host.dir_c = _main_pier_run(argv[0])) ) {
fprintf(stderr, "unable to find pier\r\n"); static struct option lop_u[] = {
{ "loom", required_argument, NULL, c3__loom },
{ NULL, 0, NULL, 0 }
};
u3_Host.dir_c = _main_pier_run(argv[0]);
while ( -1 != (ch_i=getopt_long(argc, argv, "", lop_u, &lid_i)) ) {
switch ( ch_i ) {
case c3__loom: {
c3_w lom_w;
c3_o res_o = _main_readw(optarg, u3a_bits + 3, &lom_w);
if ( (c3n == res_o) || (lom_w < 20) ) {
fprintf(stderr, "error: --loom must be >= 20 and <= %u\r\n", u3a_bits + 2);
exit(1); exit(1);
} }
u3_Host.ops_u.lom_y = lom_w;
} break; } break;
case 3: { case '?': {
u3_Host.dir_c = argv[2]; fprintf(stderr, "invalid argument\r\n");
} break;
default: {
fprintf(stderr, "invalid command\r\n");
exit(1); exit(1);
} break; } break;
} }
}
// argv[optind] is always "vile"
//
if ( !u3_Host.dir_c ) {
if ( optind + 1 < argc ) {
u3_Host.dir_c = argv[optind + 1];
}
else {
fprintf(stderr, "invalid command, pier required\r\n");
exit(1);
}
optind++;
}
if ( optind + 1 != argc ) {
fprintf(stderr, "invalid command\r\n");
exit(1);
}
// XX check if snapshot is stale? // XX check if snapshot is stale?
// //
c3_d eve_d = u3m_boot(u3_Host.dir_c, u3a_bytes); c3_d eve_d = u3m_boot(u3_Host.dir_c, (size_t)1 << u3_Host.ops_u.lom_y);
u3_noun sam = u3nc(u3nc(u3_nul, u3_nul), u3_noun sam = u3nc(u3nc(u3_nul, u3_nul),
u3nc(c3n, u3nq(c3__once, 'j', c3__vile, u3_nul))); u3nc(c3n, u3nq(c3__once, 'j', c3__vile, u3_nul)));
u3_noun res = u3v_soft_peek(0, sam); u3_noun res = u3v_soft_peek(0, sam);