vere: factors common _mcut functions into ward

This commit is contained in:
Joe Bryan 2020-06-25 16:36:10 -07:00
parent 9177b3ea87
commit 5a3dbde218
5 changed files with 91 additions and 175 deletions

View File

@ -754,6 +754,26 @@
void
u3_ovum_free(u3_ovum *egg_u);
/* u3_mcut_char(): measure/cut character.
*/
c3_w
u3_mcut_char(c3_c* buf_c, c3_w len_w, c3_c chr_c);
/* u3_mcut_cord(): measure/cut cord.
*/
c3_w
u3_mcut_cord(c3_c* buf_c, c3_w len_w, u3_noun san);
/* u3_mcut_path(): measure/cut cord list.
*/
c3_w
u3_mcut_path(c3_c* buf_c, c3_w len_w, c3_c sep_c, u3_noun pax);
/* u3_mcut_host(): measure/cut host.
*/
c3_w
u3_mcut_host(c3_c* buf_c, c3_w len_w, u3_noun hot);
/** New vere
**/
/* u3_auto_init(): initialize all drivers.

View File

@ -494,62 +494,6 @@ _ames_io_start(u3_ames* sam_u)
u3z(who);
}
/* _cttp_mcut_char(): measure/cut character.
*/
static c3_w
_cttp_mcut_char(c3_c* buf_c, c3_w len_w, c3_c chr_c)
{
if ( buf_c ) {
buf_c[len_w] = chr_c;
}
return len_w + 1;
}
/* _cttp_mcut_cord(): measure/cut cord.
*/
static c3_w
_cttp_mcut_cord(c3_c* buf_c, c3_w len_w, u3_noun san)
{
c3_w ten_w = u3r_met(3, san);
if ( buf_c ) {
u3r_bytes(0, ten_w, (c3_y *)(buf_c + len_w), san);
}
u3z(san);
return (len_w + ten_w);
}
/* _cttp_mcut_path(): measure/cut cord list.
*/
static c3_w
_cttp_mcut_path(c3_c* buf_c, c3_w len_w, c3_c sep_c, u3_noun pax)
{
u3_noun axp = pax;
while ( u3_nul != axp ) {
u3_noun h_axp = u3h(axp);
len_w = _cttp_mcut_cord(buf_c, len_w, u3k(h_axp));
axp = u3t(axp);
if ( u3_nul != axp ) {
len_w = _cttp_mcut_char(buf_c, len_w, sep_c);
}
}
u3z(pax);
return len_w;
}
/* _cttp_mcut_host(): measure/cut host.
*/
static c3_w
_cttp_mcut_host(c3_c* buf_c, c3_w len_w, u3_noun hot)
{
len_w = _cttp_mcut_path(buf_c, len_w, '.', u3kb_flop(u3k(hot)));
u3z(hot);
return len_w;
}
/* _ames_ef_turf(): initialize ames I/O on domain(s).
*/
static void
@ -559,10 +503,10 @@ _ames_ef_turf(u3_ames* sam_u, u3_noun tuf)
// XX save all for fallback, not just first
//
u3_noun hot = u3k(u3h(tuf));
c3_w len_w = _cttp_mcut_host(0, 0, u3k(hot));
c3_w len_w = u3_mcut_host(0, 0, u3k(hot));
sam_u->dns_c = c3_malloc(1 + len_w);
_cttp_mcut_host(sam_u->dns_c, 0, hot);
u3_mcut_host(sam_u->dns_c, 0, hot);
sam_u->dns_c[len_w] = 0;
// XX invalidate sam_u->imp_w &c ?

View File

@ -340,62 +340,6 @@ _cttp_cres_fire_body(u3_cres* res_u, u3_hbod* bod_u)
}
}
/* _cttp_mcut_char(): measure/cut character.
*/
static c3_w
_cttp_mcut_char(c3_c* buf_c, c3_w len_w, c3_c chr_c)
{
if ( buf_c ) {
buf_c[len_w] = chr_c;
}
return len_w + 1;
}
/* _cttp_mcut_cord(): measure/cut cord.
*/
static c3_w
_cttp_mcut_cord(c3_c* buf_c, c3_w len_w, u3_noun san)
{
c3_w ten_w = u3r_met(3, san);
if ( buf_c ) {
u3r_bytes(0, ten_w, (c3_y *)(buf_c + len_w), san);
}
u3z(san);
return (len_w + ten_w);
}
/* _cttp_mcut_path(): measure/cut cord list.
*/
static c3_w
_cttp_mcut_path(c3_c* buf_c, c3_w len_w, c3_c sep_c, u3_noun pax)
{
u3_noun axp = pax;
while ( u3_nul != axp ) {
u3_noun h_axp = u3h(axp);
len_w = _cttp_mcut_cord(buf_c, len_w, u3k(h_axp));
axp = u3t(axp);
if ( u3_nul != axp ) {
len_w = _cttp_mcut_char(buf_c, len_w, sep_c);
}
}
u3z(pax);
return len_w;
}
/* _cttp_mcut_host(): measure/cut host.
*/
static c3_w
_cttp_mcut_host(c3_c* buf_c, c3_w len_w, u3_noun hot)
{
len_w = _cttp_mcut_path(buf_c, len_w, '.', u3kb_flop(u3k(hot)));
u3z(hot);
return len_w;
}
/* _cttp_mcut_pork(): measure/cut path/extension.
*/
static c3_w
@ -404,10 +348,10 @@ _cttp_mcut_pork(c3_c* buf_c, c3_w len_w, u3_noun pok)
u3_noun h_pok = u3h(pok);
u3_noun t_pok = u3t(pok);
len_w = _cttp_mcut_path(buf_c, len_w, '/', u3k(t_pok));
len_w = u3_mcut_path(buf_c, len_w, '/', u3k(t_pok));
if ( u3_nul != h_pok ) {
len_w = _cttp_mcut_char(buf_c, len_w, '.');
len_w = _cttp_mcut_cord(buf_c, len_w, u3k(u3t(h_pok)));
len_w = u3_mcut_char(buf_c, len_w, '.');
len_w = u3_mcut_cord(buf_c, len_w, u3k(u3t(h_pok)));
}
u3z(pok);
return len_w;
@ -423,11 +367,11 @@ _cttp_mcut_quay(c3_c* buf_c, c3_w len_w, u3_noun quy)
while ( u3_nul != quy ) {
if ( c3y == fir_o ) {
len_w = _cttp_mcut_char(buf_c, len_w, '?');
len_w = u3_mcut_char(buf_c, len_w, '?');
fir_o = c3n;
}
else {
len_w = _cttp_mcut_char(buf_c, len_w, '&');
len_w = u3_mcut_char(buf_c, len_w, '&');
}
{
@ -436,9 +380,9 @@ _cttp_mcut_quay(c3_c* buf_c, c3_w len_w, u3_noun quy)
u3x_cell(quy, &i_quy, &t_quy);
u3x_cell(i_quy, &pi_quy, &qi_quy);
len_w = _cttp_mcut_cord(buf_c, len_w, u3k(pi_quy));
len_w = _cttp_mcut_char(buf_c, len_w, '=');
len_w = _cttp_mcut_cord(buf_c, len_w, u3k(qi_quy));
len_w = u3_mcut_cord(buf_c, len_w, u3k(pi_quy));
len_w = u3_mcut_char(buf_c, len_w, '=');
len_w = u3_mcut_cord(buf_c, len_w, u3k(qi_quy));
quy = t_quy;
}
@ -456,7 +400,7 @@ _cttp_mcut_url(c3_c* buf_c, c3_w len_w, u3_noun pul)
u3_noun q_pul = u3h(u3t(pul));
u3_noun r_pul = u3t(u3t(pul));
len_w = _cttp_mcut_char(buf_c, len_w, '/');
len_w = u3_mcut_char(buf_c, len_w, '/');
len_w = _cttp_mcut_pork(buf_c, len_w, u3k(q_pul));
if ( u3_nul != r_pul ) {
@ -495,10 +439,10 @@ _cttp_creq_url(u3_noun pul)
static c3_c*
_cttp_creq_host(u3_noun hot)
{
c3_w len_w = _cttp_mcut_host(0, 0, u3k(hot));
c3_w len_w = u3_mcut_host(0, 0, u3k(hot));
c3_c* hot_c = c3_malloc(1 + len_w);
_cttp_mcut_host(hot_c, 0, hot);
u3_mcut_host(hot_c, 0, hot);
hot_c[len_w] = 0;
return hot_c;

View File

@ -1325,61 +1325,13 @@ _http_serv_start(u3_http* htp_u)
}
}
//XX deduplicate these with cttp
/* _cttp_mcut_char(): measure/cut character.
*/
static c3_w
_cttp_mcut_char(c3_c* buf_c, c3_w len_w, c3_c chr_c)
{
if ( buf_c ) {
buf_c[len_w] = chr_c;
}
return len_w + 1;
}
/* _cttp_mcut_cord(): measure/cut cord.
*/
static c3_w
_cttp_mcut_cord(c3_c* buf_c, c3_w len_w, u3_noun san)
{
c3_w ten_w = u3r_met(3, san);
if ( buf_c ) {
u3r_bytes(0, ten_w, (c3_y *)(buf_c + len_w), san);
}
u3z(san);
return (len_w + ten_w);
}
/* _cttp_mcut_path(): measure/cut cord list.
*/
static c3_w
_cttp_mcut_path(c3_c* buf_c, c3_w len_w, c3_c sep_c, u3_noun pax)
{
u3_noun axp = pax;
while ( u3_nul != axp ) {
u3_noun h_axp = u3h(axp);
len_w = _cttp_mcut_cord(buf_c, len_w, u3k(h_axp));
axp = u3t(axp);
if ( u3_nul != axp ) {
len_w = _cttp_mcut_char(buf_c, len_w, sep_c);
}
}
u3z(pax);
return len_w;
}
static uv_buf_t
_http_wain_to_buf(u3_noun wan)
{
c3_w len_w = _cttp_mcut_path(0, 0, (c3_c)10, u3k(wan));
c3_w len_w = u3_mcut_path(0, 0, (c3_c)10, u3k(wan));
c3_c* buf_c = c3_malloc(1 + len_w);
_cttp_mcut_path(buf_c, 0, (c3_c)10, wan);
u3_mcut_path(buf_c, 0, (c3_c)10, wan);
buf_c[len_w] = 0;
return uv_buf_init(buf_c, len_w);

View File

@ -166,3 +166,59 @@ u3_ovum_free(u3_ovum *egg_u)
c3_free(egg_u);
}
/* u3_mcut_char(): measure/cut character.
*/
c3_w
u3_mcut_char(c3_c* buf_c, c3_w len_w, c3_c chr_c)
{
if ( buf_c ) {
buf_c[len_w] = chr_c;
}
return len_w + 1;
}
/* u3_mcut_cord(): measure/cut cord.
*/
c3_w
u3_mcut_cord(c3_c* buf_c, c3_w len_w, u3_noun san)
{
c3_w ten_w = u3r_met(3, san);
if ( buf_c ) {
u3r_bytes(0, ten_w, (c3_y *)(buf_c + len_w), san);
}
u3z(san);
return (len_w + ten_w);
}
/* u3_mcut_path(): measure/cut cord list.
*/
c3_w
u3_mcut_path(c3_c* buf_c, c3_w len_w, c3_c sep_c, u3_noun pax)
{
u3_noun axp = pax;
while ( u3_nul != axp ) {
u3_noun h_axp = u3h(axp);
len_w = u3_mcut_cord(buf_c, len_w, u3k(h_axp));
axp = u3t(axp);
if ( u3_nul != axp ) {
len_w = u3_mcut_char(buf_c, len_w, sep_c);
}
}
u3z(pax);
return len_w;
}
/* u3_mcut_host(): measure/cut host.
*/
c3_w
u3_mcut_host(c3_c* buf_c, c3_w len_w, u3_noun hot)
{
len_w = u3_mcut_path(buf_c, len_w, '.', u3kb_flop(u3k(hot)));
u3z(hot);
return len_w;
}