Commit dddb171b authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

vte: Beginning of an incremental API

parent 80d78148
......@@ -80,6 +80,7 @@ nobase_pkginclude_HEADERS += \
vsb.h \
vsha256.h \
vtcp.h \
vte.h \
vtim.h \
vtree.h \
vrnd.h
......
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2023 Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
struct vte;
struct vte *VTE_new(int maxfields, int width);
void VTE_destroy(struct vte **);
......@@ -37,13 +37,60 @@
#include "vdef.h"
#include "vqueue.h"
#include "miniobj.h"
#include "vas.h"
#include "vcli_serve.h"
#include "vsb.h"
#include "vte.h"
#define MAXCOL 10
struct vte {
unsigned magic;
#define VTE_MAGIC 0xedf42b97
struct vsb *vsb;
int c_off; /* input char offset */
int l_sz; /* input line size */
int l_maxsz; /* maximum input line size */
int o_sz; /* output sz */
int o_sep; /* output field separators */
int f_off; /* input field offset */
int f_sz; /* input field size */
int f_cnt; /* actual number of fields */
int f_maxcnt; /* maximum number of fields */
int f_maxsz[]; /* maximum size per field */
};
struct vte *
VTE_new(int maxfields, int width)
{
struct vte *vte;
assert(maxfields > 0);
assert(width > 0);
ALLOC_FLEX_OBJ(vte, f_maxsz, maxfields, VTE_MAGIC);
if (vte != NULL) {
vte->o_sz = width;
vte->f_maxcnt = maxfields;
vte->vsb = VSB_new_auto();
AN(vte->vsb);
}
return (vte);
}
void
VTE_destroy(struct vte **vtep)
{
struct vte *vte;
TAKE_OBJ_NOTNULL(vte, vtep, VTE_MAGIC);
AN(vte->vsb);
VSB_destroy(&vte->vsb);
FREE_OBJ(vte);
}
void
VCLI_VTE(struct cli *cli, struct vsb **src, int width)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment